diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ai/api/ai_town.cpp | 4 | ||||
-rw-r--r-- | src/newgrf_town.cpp | 4 | ||||
-rw-r--r-- | src/saveload/oldloader_sl.cpp | 3 | ||||
-rw-r--r-- | src/saveload/town_sl.cpp | 3 | ||||
-rw-r--r-- | src/subsidy.cpp | 2 | ||||
-rw-r--r-- | src/town.h | 7 | ||||
-rw-r--r-- | src/town_cmd.cpp | 7 |
7 files changed, 12 insertions, 18 deletions
diff --git a/src/ai/api/ai_town.cpp b/src/ai/api/ai_town.cpp index 6ad9401de..51dbc37c5 100644 --- a/src/ai/api/ai_town.cpp +++ b/src/ai/api/ai_town.cpp @@ -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; } } diff --git a/src/newgrf_town.cpp b/src/newgrf_town.cpp index 5f379766b..5fa180444 100644 --- a/src/newgrf_town.cpp +++ b/src/newgrf_town.cpp @@ -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; diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp index d4ff3758a..d8a54b6e8 100644 --- a/src/saveload/oldloader_sl.cpp +++ b/src/saveload/oldloader_sl.cpp @@ -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 ), diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp index 06b70d074..c0b48c6ba 100644 --- a/src/saveload/town_sl.cpp +++ b/src/saveload/town_sl.cpp @@ -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), diff --git a/src/subsidy.cpp b/src/subsidy.cpp index d4e701298..04573daa0 100644 --- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -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; } diff --git a/src/town.h b/src/town.h index e124e2600..f60b026bf 100644 --- a/src/town.h +++ b/src/town.h @@ -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 diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 0c080246c..c76ca9fff 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -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; |