(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
This commit is contained in:
smatz
2009-08-08 16:42:55 +00:00
parent eff8cb8390
commit 2a430d981f
29 changed files with 312 additions and 180 deletions

View File

@@ -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;
}
}

View File

@@ -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),

View File

@@ -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 ),

View File

@@ -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

View File

@@ -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()
};