(svn r17107) -Codechange: store type of subsidy source and destination in the Subsidy struct instead of determining it every time it's needed

This commit is contained in:
smatz
2009-08-07 22:23:34 +00:00
parent 39e145e586
commit 74d3382b94
13 changed files with 157 additions and 171 deletions

View File

@@ -1850,36 +1850,6 @@ bool AfterLoadGame()
i++;
}
}
/* Delete invalid subsidies possibly present in old versions (but converted to new savegame) */
Subsidy *s;
FOR_ALL_SUBSIDIES(s) {
if (s->IsAwarded()) {
/* Station -> Station */
const Station *from = Station::GetIfValid(s->from);
const Station *to = Station::GetIfValid(s->to);
if (from != NULL && to != NULL && from->owner == to->owner && Company::IsValidID(from->owner)) continue;
} else {
const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
switch (cs->town_effect) {
case TE_PASSENGERS:
case TE_MAIL:
/* Town -> Town */
if (Town::IsValidID(s->from) && Town::IsValidID(s->to)) continue;
break;
case TE_GOODS:
case TE_FOOD:
/* Industry -> Town */
if (Industry::IsValidID(s->from) && Town::IsValidID(s->to)) continue;
break;
default:
/* Industry -> Industry */
if (Industry::IsValidID(s->from) && Industry::IsValidID(s->to)) continue;
break;
}
}
s->cargo_type = CT_INVALID;
}
}
if (CheckSavegameVersion(124)) {
@@ -1898,6 +1868,43 @@ bool AfterLoadGame()
}
}
{
/* Delete invalid subsidies possibly present in old versions (but converted to new savegame) */
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 {
const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
switch (cs->town_effect) {
case TE_PASSENGERS:
case TE_MAIL:
/* Town -> Town */
s->src_type = s->dst_type = ST_TOWN;
if (Town::IsValidID(s->src) && Town::IsValidID(s->dst)) continue;
break;
case TE_GOODS:
case TE_FOOD:
/* Industry -> Town */
s->src_type = ST_INDUSTRY;
s->dst_type = ST_TOWN;
if (Industry::IsValidID(s->src) && Town::IsValidID(s->dst)) continue;
break;
default:
/* Industry -> Industry */
s->src_type = s->dst_type = ST_INDUSTRY;
if (Industry::IsValidID(s->src) && Industry::IsValidID(s->dst)) continue;
break;
}
}
s->cargo_type = CT_INVALID;
}
}
AfterLoadLabelMaps();
GamelogPrintDebug(1);

View File

@@ -1469,8 +1469,8 @@ 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_FILE_U8 | OC_VAR_U16, Subsidy, from ),
OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Subsidy, to ),
OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Subsidy, src ),
OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Subsidy, dst ),
OCL_END()
};

View File

@@ -10,10 +10,10 @@
static const SaveLoad _subsidies_desc[] = {
SLE_VAR(Subsidy, cargo_type, SLE_UINT8),
SLE_VAR(Subsidy, age, SLE_UINT8),
SLE_CONDVAR(Subsidy, from, SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
SLE_CONDVAR(Subsidy, from, SLE_UINT16, 5, SL_MAX_VERSION),
SLE_CONDVAR(Subsidy, to, SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
SLE_CONDVAR(Subsidy, to, SLE_UINT16, 5, 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()
};