From 2a430d981f680485b9d4f9e5fab8bc642952b9bf Mon Sep 17 00:00:00 2001 From: smatz Date: Sat, 8 Aug 2009 16:42:55 +0000 Subject: (svn r17113) -Change [FS#265][FS#2094][FS#2589]: apply the subsidy when subsidy's destination is in station's catchment area and cargo packets originate from subsidy's source -Change [FS#1134]: subsidies aren't bound to stations after awarding anymore, they still apply to town or industry, no matter what station is used for loading and unloading. Awarded subsidies from older savegames are lost -Change [NoAI]: due to these changes, AISubsidy::GetSource and AISubsidy::GetDestination now return STATION_INVALID for awarded subsidies --- src/saveload/afterload.cpp | 19 ++++++++++--------- src/saveload/cargopacket_sl.cpp | 2 ++ src/saveload/oldloader_sl.cpp | 2 +- src/saveload/saveload.cpp | 2 +- src/saveload/subsidy_sl.cpp | 13 ++++++++----- 5 files changed, 22 insertions(+), 16 deletions(-) (limited to 'src/saveload') diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index fa772cac1..0331feed7 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -32,6 +32,7 @@ #include "../economy_base.h" #include "../animated_tile_func.h" #include "../subsidy_base.h" +#include "../subsidy_func.h" #include "table/strings.h" @@ -230,6 +231,7 @@ static bool InitializeWindowsAndCaches() SetCachedEngineCounts(); Station::RecomputeIndustriesNearForAll(); + RebuildSubsidisedSourceAndDestinationCache(); /* Towns have a noise controlled number of airports system * So each airport's noise value must be added to the town->noise_reached value @@ -1868,17 +1870,15 @@ bool AfterLoadGame() } } - { - /* Delete invalid subsidies possibly present in old versions (but converted to new savegame) */ + if (CheckSavegameVersion(125)) { + /* Convert old subsidies */ Subsidy *s; FOR_ALL_SUBSIDIES(s) { - if (s->IsAwarded()) { - /* Station -> Station */ - const Station *from = Station::GetIfValid(s->src); - const Station *to = Station::GetIfValid(s->dst); - s->src_type = s->dst_type = ST_STATION; - if (from != NULL && to != NULL && from->owner == to->owner && Company::IsValidID(from->owner)) continue; - } else { + /* Convert only nonawarded subsidies. The original source and destination town/industry + * anymore for awarded subsidies, so invalidate them. */ + if (s->remaining < 12) { + s->remaining = 12 - s->remaining; // convert "age" to "remaining" + s->awarded = INVALID_COMPANY; // not awarded to anyone const CargoSpec *cs = CargoSpec::Get(s->cargo_type); switch (cs->town_effect) { case TE_PASSENGERS: @@ -1901,6 +1901,7 @@ bool AfterLoadGame() break; } } + /* Awarded subsidy or invalid source/destination, invalidate */ s->cargo_type = CT_INVALID; } } diff --git a/src/saveload/cargopacket_sl.cpp b/src/saveload/cargopacket_sl.cpp index d0a7783b8..7a6a1c812 100644 --- a/src/saveload/cargopacket_sl.cpp +++ b/src/saveload/cargopacket_sl.cpp @@ -14,6 +14,8 @@ static const SaveLoad _cargopacket_desc[] = { SLE_VAR(CargoPacket, count, SLE_UINT16), SLE_VAR(CargoPacket, days_in_transit, SLE_UINT8), SLE_VAR(CargoPacket, feeder_share, SLE_INT64), + SLE_CONDVAR(CargoPacket, source_type, SLE_UINT8, 125, SL_MAX_VERSION), + SLE_CONDVAR(CargoPacket, source_id, SLE_UINT16, 125, SL_MAX_VERSION), /* Used to be paid_for, but that got changed. */ SLE_CONDNULL(1, 0, 120), diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp index f8fc0b777..14db853bf 100644 --- a/src/saveload/oldloader_sl.cpp +++ b/src/saveload/oldloader_sl.cpp @@ -1468,7 +1468,7 @@ static bool LoadOldEngineName(LoadgameState *ls, int num) static const OldChunks subsidy_chunk[] = { OCL_SVAR( OC_UINT8, Subsidy, cargo_type ), - OCL_SVAR( OC_UINT8, Subsidy, age ), + OCL_SVAR( OC_UINT8, Subsidy, remaining ), OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Subsidy, src ), OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Subsidy, dst ), diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 731679dc5..ddb374dd0 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -41,7 +41,7 @@ #include "saveload_internal.h" -extern const uint16 SAVEGAME_VERSION = 124; +extern const uint16 SAVEGAME_VERSION = 125; SavegameType _savegame_type; ///< type of savegame we are loading diff --git a/src/saveload/subsidy_sl.cpp b/src/saveload/subsidy_sl.cpp index b1e889e8f..163a9ce8c 100644 --- a/src/saveload/subsidy_sl.cpp +++ b/src/saveload/subsidy_sl.cpp @@ -9,11 +9,14 @@ static const SaveLoad _subsidies_desc[] = { SLE_VAR(Subsidy, cargo_type, SLE_UINT8), - SLE_VAR(Subsidy, age, SLE_UINT8), - SLE_CONDVAR(Subsidy, src, SLE_FILE_U8 | SLE_VAR_U16, 0, 4), - SLE_CONDVAR(Subsidy, src, SLE_UINT16, 5, SL_MAX_VERSION), - SLE_CONDVAR(Subsidy, dst, SLE_FILE_U8 | SLE_VAR_U16, 0, 4), - SLE_CONDVAR(Subsidy, dst, SLE_UINT16, 5, SL_MAX_VERSION), + SLE_VAR(Subsidy, remaining, SLE_UINT8), + SLE_CONDVAR(Subsidy, awarded, SLE_UINT8, 125, SL_MAX_VERSION), + SLE_CONDVAR(Subsidy, src_type, SLE_UINT8, 125, SL_MAX_VERSION), + SLE_CONDVAR(Subsidy, dst_type, SLE_UINT8, 125, SL_MAX_VERSION), + SLE_CONDVAR(Subsidy, src, SLE_FILE_U8 | SLE_VAR_U16, 0, 4), + SLE_CONDVAR(Subsidy, src, SLE_UINT16, 5, SL_MAX_VERSION), + SLE_CONDVAR(Subsidy, dst, SLE_FILE_U8 | SLE_VAR_U16, 0, 4), + SLE_CONDVAR(Subsidy, dst, SLE_UINT16, 5, SL_MAX_VERSION), SLE_END() }; -- cgit v1.2.3-70-g09d2