(svn r22920) -Cleanup: replace two very old town variables taht were rarely used by small functions that compute there value on-the-fly when necessary

This commit is contained in:
yexo 2011-09-11 11:47:18 +00:00
parent 07077dc56e
commit 40d5419cd2
7 changed files with 12 additions and 18 deletions

View File

@ -99,8 +99,8 @@
const Town *t = ::Town::Get(town_id);
switch (AICargo::GetTownEffect(cargo_id)) {
case AICargo::TE_PASSENGERS: return ::ToPercent8(t->pct_pass_transported);
case AICargo::TE_MAIL: return ::ToPercent8(t->pct_mail_transported);
case AICargo::TE_PASSENGERS: return ::ToPercent8(t->GetPercentPassTransported());
case AICargo::TE_MAIL: return ::ToPercent8(t->GetPercentMailTransported());
default: return -1;
}
}

View File

@ -107,8 +107,8 @@ uint32 TownGetVariable(byte variable, byte parameter, bool *available, Town *t,
case 0xC7: return GB(ClampToU16(t->act_pass), 8, 8);
case 0xC8: return ClampToU16(t->act_mail);
case 0xC9: return GB(ClampToU16(t->act_mail), 8, 8);
case 0xCA: return t->pct_pass_transported;
case 0xCB: return t->pct_mail_transported;
case 0xCA: return t->GetPercentPassTransported();
case 0xCB: return t->GetPercentMailTransported();
case 0xCC: return t->new_act_food;
case 0xCD: return GB(t->new_act_food, 8, 8);
case 0xCE: return t->new_act_water;

View File

@ -577,8 +577,7 @@ static const OldChunks town_chunk[] = {
OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Town, act_pass ),
OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Town, act_mail ),
OCL_SVAR( OC_UINT8, Town, pct_pass_transported ),
OCL_SVAR( OC_UINT8, Town, pct_mail_transported ),
OCL_NULL( 2 ), ///< pct_pass_transported / pct_mail_transported, now computed on the fly
OCL_SVAR( OC_TTD | OC_UINT16, Town, new_act_food ),
OCL_SVAR( OC_TTD | OC_UINT16, Town, new_act_water ),

View File

@ -146,8 +146,7 @@ static const SaveLoad _town_desc[] = {
SLE_CONDVAR(Town, new_act_pass, SLE_UINT32, 9, SL_MAX_VERSION),
SLE_CONDVAR(Town, new_act_mail, SLE_UINT32, 9, SL_MAX_VERSION),
SLE_VAR(Town, pct_pass_transported, SLE_UINT8),
SLE_VAR(Town, pct_mail_transported, SLE_UINT8),
SLE_CONDNULL(2, 0, 163), ///< pct_pass_transported / pct_mail_transported, now computed on the fly
SLE_VAR(Town, act_food, SLE_UINT16),
SLE_VAR(Town, act_water, SLE_UINT16),

View File

@ -170,7 +170,7 @@ static Subsidy *FindSubsidyPassengerRoute()
const Town *src = Town::GetRandom();
if (src->population < SUBSIDY_PAX_MIN_POPULATION ||
src->pct_pass_transported > SUBSIDY_MAX_PCT_TRANSPORTED) {
src->GetPercentPassTransported() > SUBSIDY_MAX_PCT_TRANSPORTED) {
return NULL;
}

View File

@ -75,8 +75,11 @@ struct Town : TownPool::PoolItem<&_town_pool> {
uint32 new_act_pass;
uint32 new_act_mail;
byte pct_pass_transported; ///< amount of passengers that were transported
byte pct_mail_transported; ///< amount of mail that was transported
/** Percentage of passengers transported last month (0xFF=100%) */
inline byte GetPercentPassTransported() const { return this->act_pass * 256 / (this->max_pass + 1); }
/** Percentage of mail transported last month (0xFF=100%) */
inline byte GetPercentMailTransported() const { return this->act_mail * 256 / (this->max_mail + 1); }
uint16 act_food; ///< amount of food that was transported
uint16 act_water; ///< amount of water that was transported

View File

@ -1431,8 +1431,6 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize
t->act_pass = 0;
t->act_mail = 0;
t->pct_pass_transported = 0;
t->pct_mail_transported = 0;
t->fund_buildings_months = 0;
t->new_act_food = 0;
t->new_act_water = 0;
@ -2804,16 +2802,11 @@ static void UpdateTownGrowRate(Town *t)
static void UpdateTownAmounts(Town *t)
{
/* Using +1 here to prevent overflow and division by zero */
t->pct_pass_transported = t->new_act_pass * 256 / (t->new_max_pass + 1);
t->max_pass = t->new_max_pass; t->new_max_pass = 0;
t->act_pass = t->new_act_pass; t->new_act_pass = 0;
t->act_food = t->new_act_food; t->new_act_food = 0;
t->act_water = t->new_act_water; t->new_act_water = 0;
/* Using +1 here to prevent overflow and division by zero */
t->pct_mail_transported = t->new_act_mail * 256 / (t->new_max_mail + 1);
t->max_mail = t->new_max_mail; t->new_max_mail = 0;
t->act_mail = t->new_act_mail; t->new_act_mail = 0;