Mercurial > hg > openttd
changeset 18099:73132c970152 draft
(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
author | yexo <yexo@openttd.org> |
---|---|
date | Sun, 11 Sep 2011 11:47:18 +0000 |
parents | 2b072edcd664 |
children | 05a2b40c0df9 |
files | src/ai/api/ai_town.cpp src/newgrf_town.cpp src/saveload/oldloader_sl.cpp src/saveload/town_sl.cpp src/subsidy.cpp src/town.h src/town_cmd.cpp |
diffstat | 7 files changed, 12 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- 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; } }
--- a/src/newgrf_town.cpp +++ b/src/newgrf_town.cpp @@ -107,8 +107,8 @@ 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;
--- a/src/saveload/oldloader_sl.cpp +++ b/src/saveload/oldloader_sl.cpp @@ -577,8 +577,7 @@ 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 ),
--- a/src/saveload/town_sl.cpp +++ b/src/saveload/town_sl.cpp @@ -146,8 +146,7 @@ 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),
--- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -170,7 +170,7 @@ 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; }
--- a/src/town.h +++ b/src/town.h @@ -75,8 +75,11 @@ 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
--- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1431,8 +1431,6 @@ 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 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;