summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2012-04-25 20:50:13 +0000
committerrubidium <rubidium@openttd.org>2012-04-25 20:50:13 +0000
commit41e5c839e08bfc811b1e8d7272996567776b788f (patch)
treeeb8a74437dd42a7a57e157c6218e96b9df7fbd87
parentcd50c862944098753c959cc272d62a2ddc212ca8 (diff)
downloadopenttd-41e5c839e08bfc811b1e8d7272996567776b788f.tar.xz
(svn r24179) -Codechange: move some variables of Town to TownCache
-rw-r--r--src/industry_cmd.cpp2
-rw-r--r--src/newgrf_house.cpp21
-rw-r--r--src/newgrf_town.cpp26
-rw-r--r--src/road_cmd.cpp2
-rw-r--r--src/saveload/town_sl.cpp8
-rw-r--r--src/script/api/script_town.cpp10
-rw-r--r--src/smallmap_gui.cpp6
-rw-r--r--src/subsidy.cpp14
-rw-r--r--src/town.h25
-rw-r--r--src/town_cmd.cpp70
-rw-r--r--src/town_gui.cpp16
-rw-r--r--src/tunnelbridge_cmd.cpp4
-rw-r--r--src/viewport.cpp6
13 files changed, 108 insertions, 102 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 128f231f8..8a5d7e36c 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1449,7 +1449,7 @@ static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTil
*/
static CommandCost CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t)
{
- if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_TOWN1200_MORE) && t->population < 1200) {
+ if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_TOWN1200_MORE) && t->cache.population < 1200) {
return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS_WITH_POPULATION_OF_1200);
}
diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp
index 760b392e8..08f198c62 100644
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -49,6 +49,11 @@ HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid)
void InitializeBuildingCounts()
{
memset(&_building_counts, 0, sizeof(_building_counts));
+
+ Town *t;
+ FOR_ALL_TOWNS(t) {
+ memset(&t->cache.building_counts, 0, sizeof(t->cache.building_counts));
+ }
}
/**
@@ -63,12 +68,12 @@ void IncreaseBuildingCount(Town *t, HouseID house_id)
if (!_loaded_newgrf_features.has_newhouses) return;
- t->building_counts.id_count[house_id]++;
+ t->cache.building_counts.id_count[house_id]++;
_building_counts.id_count[house_id]++;
if (class_id == HOUSE_NO_CLASS) return;
- t->building_counts.class_count[class_id]++;
+ t->cache.building_counts.class_count[class_id]++;
_building_counts.class_count[class_id]++;
}
@@ -84,13 +89,13 @@ void DecreaseBuildingCount(Town *t, HouseID house_id)
if (!_loaded_newgrf_features.has_newhouses) return;
- if (t->building_counts.id_count[house_id] > 0) t->building_counts.id_count[house_id]--;
- if (_building_counts.id_count[house_id] > 0) _building_counts.id_count[house_id]--;
+ if (t->cache.building_counts.id_count[house_id] > 0) t->cache.building_counts.id_count[house_id]--;
+ if (_building_counts.id_count[house_id] > 0) _building_counts.id_count[house_id]--;
if (class_id == HOUSE_NO_CLASS) return;
- if (t->building_counts.class_count[class_id] > 0) t->building_counts.class_count[class_id]--;
- if (_building_counts.class_count[class_id] > 0) _building_counts.class_count[class_id]--;
+ if (t->cache.building_counts.class_count[class_id] > 0) t->cache.building_counts.class_count[class_id]--;
+ if (_building_counts.class_count[class_id] > 0) _building_counts.class_count[class_id]--;
}
static uint32 HouseGetRandomBits(const ResolverObject *object)
@@ -123,8 +128,8 @@ static uint32 GetNumHouses(HouseID house_id, const Town *town)
map_id_count = ClampU(_building_counts.id_count[house_id], 0, 255);
map_class_count = ClampU(_building_counts.class_count[class_id], 0, 255);
- town_id_count = ClampU(town->building_counts.id_count[house_id], 0, 255);
- town_class_count = ClampU(town->building_counts.class_count[class_id], 0, 255);
+ town_id_count = ClampU(town->cache.building_counts.id_count[house_id], 0, 255);
+ town_class_count = ClampU(town->cache.building_counts.class_count[class_id], 0, 255);
return map_class_count << 24 | town_class_count << 16 | map_id_count << 8 | town_id_count;
}
diff --git a/src/newgrf_town.cpp b/src/newgrf_town.cpp
index bb67803d7..5017dcec4 100644
--- a/src/newgrf_town.cpp
+++ b/src/newgrf_town.cpp
@@ -55,21 +55,21 @@ uint32 TownGetVariable(byte variable, uint32 parameter, bool *available, Town *t
/* Town properties */
case 0x80: return t->xy;
case 0x81: return GB(t->xy, 8, 8);
- case 0x82: return ClampToU16(t->population);
- case 0x83: return GB(ClampToU16(t->population), 8, 8);
+ case 0x82: return ClampToU16(t->cache.population);
+ case 0x83: return GB(ClampToU16(t->cache.population), 8, 8);
case 0x8A: return t->grow_counter;
case 0x92: return t->flags; // In original game, 0x92 and 0x93 are really one word. Since flags is a byte, this is to adjust
case 0x93: return 0;
- case 0x94: return ClampToU16(t->squared_town_zone_radius[0]);
- case 0x95: return GB(ClampToU16(t->squared_town_zone_radius[0]), 8, 8);
- case 0x96: return ClampToU16(t->squared_town_zone_radius[1]);
- case 0x97: return GB(ClampToU16(t->squared_town_zone_radius[1]), 8, 8);
- case 0x98: return ClampToU16(t->squared_town_zone_radius[2]);
- case 0x99: return GB(ClampToU16(t->squared_town_zone_radius[2]), 8, 8);
- case 0x9A: return ClampToU16(t->squared_town_zone_radius[3]);
- case 0x9B: return GB(ClampToU16(t->squared_town_zone_radius[3]), 8, 8);
- case 0x9C: return ClampToU16(t->squared_town_zone_radius[4]);
- case 0x9D: return GB(ClampToU16(t->squared_town_zone_radius[4]), 8, 8);
+ case 0x94: return ClampToU16(t->cache.squared_town_zone_radius[0]);
+ case 0x95: return GB(ClampToU16(t->cache.squared_town_zone_radius[0]), 8, 8);
+ case 0x96: return ClampToU16(t->cache.squared_town_zone_radius[1]);
+ case 0x97: return GB(ClampToU16(t->cache.squared_town_zone_radius[1]), 8, 8);
+ case 0x98: return ClampToU16(t->cache.squared_town_zone_radius[2]);
+ case 0x99: return GB(ClampToU16(t->cache.squared_town_zone_radius[2]), 8, 8);
+ case 0x9A: return ClampToU16(t->cache.squared_town_zone_radius[3]);
+ case 0x9B: return GB(ClampToU16(t->cache.squared_town_zone_radius[3]), 8, 8);
+ case 0x9C: return ClampToU16(t->cache.squared_town_zone_radius[4]);
+ case 0x9D: return GB(ClampToU16(t->cache.squared_town_zone_radius[4]), 8, 8);
case 0x9E: return t->ratings[0];
case 0x9F: return GB(t->ratings[0], 8, 8);
case 0xA0: return t->ratings[1];
@@ -88,7 +88,7 @@ uint32 TownGetVariable(byte variable, uint32 parameter, bool *available, Town *t
case 0xAD: return GB(t->ratings[7], 8, 8);
case 0xAE: return t->have_ratings;
case 0xB2: return t->statues;
- case 0xB6: return ClampToU16(t->num_houses);
+ case 0xB6: return ClampToU16(t->cache.num_houses);
case 0xB9: return t->growth_rate & (~TOWN_GROW_RATE_CUSTOM);
case 0xBA: return ClampToU16(t->supplied[CT_PASSENGERS].new_max);
case 0xBB: return GB(ClampToU16(t->supplied[CT_PASSENGERS].new_max), 8, 8);
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index c20daa5a8..0930d2ace 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -493,7 +493,7 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
company = OWNER_TOWN;
/* If we are not within a town, we are not owned by the town */
- if (town == NULL || DistanceSquare(tile, town->xy) > town->squared_town_zone_radius[HZB_TOWN_EDGE]) {
+ if (town == NULL || DistanceSquare(tile, town->xy) > town->cache.squared_town_zone_radius[HZB_TOWN_EDGE]) {
company = OWNER_NONE;
}
}
diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp
index 8ef8068c9..07043bc0a 100644
--- a/src/saveload/town_sl.cpp
+++ b/src/saveload/town_sl.cpp
@@ -32,8 +32,8 @@ void UpdateHousesAndTowns()
/* Reset town population and num_houses */
FOR_ALL_TOWNS(town) {
- town->population = 0;
- town->num_houses = 0;
+ town->cache.population = 0;
+ town->cache.num_houses = 0;
}
for (TileIndex t = 0; t < MapSize(); t++) {
@@ -88,10 +88,10 @@ void UpdateHousesAndTowns()
HouseID house_id = GetCleanHouseType(t);
town = Town::GetByTile(t);
IncreaseBuildingCount(town, house_id);
- if (IsHouseCompleted(t)) town->population += HouseSpec::Get(house_id)->population;
+ if (IsHouseCompleted(t)) town->cache.population += HouseSpec::Get(house_id)->population;
/* Increase the number of houses for every house, but only once. */
- if (GetHouseNorthPart(house_id) == 0) town->num_houses++;
+ if (GetHouseNorthPart(house_id) == 0) town->cache.num_houses++;
}
/* Update the population and num_house dependant values */
diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp
index 331b98891..0e16e905f 100644
--- a/src/script/api/script_town.cpp
+++ b/src/script/api/script_town.cpp
@@ -52,14 +52,14 @@
{
if (!IsValidTown(town_id)) return -1;
const Town *t = ::Town::Get(town_id);
- return t->population;
+ return t->cache.population;
}
/* static */ int32 ScriptTown::GetHouseCount(TownID town_id)
{
if (!IsValidTown(town_id)) return -1;
const Town *t = ::Town::Get(town_id);
- return t->num_houses;
+ return t->cache.num_houses;
}
/* static */ TileIndex ScriptTown::GetLocation(TownID town_id)
@@ -125,11 +125,11 @@
switch (t->goal[towneffect_id]) {
case TOWN_GROWTH_WINTER:
- if (TileHeight(t->xy) >= GetSnowLine() && t->population > 90) return 1;
+ if (TileHeight(t->xy) >= GetSnowLine() && t->cache.population > 90) return 1;
return 0;
case TOWN_GROWTH_DESERT:
- if (GetTropicZone(t->xy) == TROPICZONE_DESERT && t->population > 60) return 1;
+ if (GetTropicZone(t->xy) == TROPICZONE_DESERT && t->cache.population > 60) return 1;
return 0;
default: return t->goal[towneffect_id];
@@ -170,7 +170,7 @@
if (!IsValidTown(town_id)) return false;
const Town *t = ::Town::Get(town_id);
- return ((uint32)GetDistanceSquareToTile(town_id, tile) <= t->squared_town_zone_radius[0]);
+ return ((uint32)GetDistanceSquareToTile(town_id, tile) <= t->cache.squared_town_zone_radius[0]);
}
/* static */ bool ScriptTown::HasStatue(TownID town_id)
diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp
index b3786310d..e80cb63d2 100644
--- a/src/smallmap_gui.cpp
+++ b/src/smallmap_gui.cpp
@@ -879,17 +879,17 @@ class SmallMapWindow : public Window {
FOR_ALL_TOWNS(t) {
/* Remap the town coordinate */
Point pt = this->RemapTile(TileX(t->xy), TileY(t->xy));
- int x = pt.x - this->subscroll - (t->sign.width_small >> 1);
+ int x = pt.x - this->subscroll - (t->cache.sign.width_small >> 1);
int y = pt.y;
/* Check if the town sign is within bounds */
- if (x + t->sign.width_small > dpi->left &&
+ if (x + t->cache.sign.width_small > dpi->left &&
x < dpi->left + dpi->width &&
y + FONT_HEIGHT_SMALL > dpi->top &&
y < dpi->top + dpi->height) {
/* And draw it. */
SetDParam(0, t->index);
- DrawString(x, x + t->sign.width_small, y, STR_SMALLMAP_TOWN);
+ DrawString(x, x + t->cache.sign.width_small, y, STR_SMALLMAP_TOWN);
}
}
}
diff --git a/src/subsidy.cpp b/src/subsidy.cpp
index d4a102f46..d6ad2666d 100644
--- a/src/subsidy.cpp
+++ b/src/subsidy.cpp
@@ -121,7 +121,7 @@ static inline void SetPartOfSubsidyFlag(SourceType type, SourceID index, PartOfS
{
switch (type) {
case ST_INDUSTRY: Industry::Get(index)->part_of_subsidy |= flag; return;
- case ST_TOWN: Town::Get(index)->part_of_subsidy |= flag; return;
+ case ST_TOWN: Town::Get(index)->cache.part_of_subsidy |= flag; return;
default: NOT_REACHED();
}
}
@@ -130,7 +130,7 @@ static inline void SetPartOfSubsidyFlag(SourceType type, SourceID index, PartOfS
void RebuildSubsidisedSourceAndDestinationCache()
{
Town *t;
- FOR_ALL_TOWNS(t) t->part_of_subsidy = POS_NONE;
+ FOR_ALL_TOWNS(t) t->cache.part_of_subsidy = POS_NONE;
Industry *i;
FOR_ALL_INDUSTRIES(i) i->part_of_subsidy = POS_NONE;
@@ -297,13 +297,13 @@ bool FindSubsidyPassengerRoute()
if (!Subsidy::CanAllocateItem()) return false;
const Town *src = Town::GetRandom();
- if (src->population < SUBSIDY_PAX_MIN_POPULATION ||
+ if (src->cache.population < SUBSIDY_PAX_MIN_POPULATION ||
src->GetPercentTransported(CT_PASSENGERS) > SUBSIDY_MAX_PCT_TRANSPORTED) {
return false;
}
const Town *dst = Town::GetRandom();
- if (dst->population < SUBSIDY_PAX_MIN_POPULATION || src == dst) {
+ if (dst->cache.population < SUBSIDY_PAX_MIN_POPULATION || src == dst) {
return false;
}
@@ -534,7 +534,7 @@ bool CheckSubsidised(CargoID cargo_type, CompanyID company, SourceType src_type,
if (!(Industry::Get(src)->part_of_subsidy & POS_SRC)) return false;
break;
case ST_TOWN:
- if (!( Town::Get(src)->part_of_subsidy & POS_SRC)) return false;
+ if (!(Town::Get(src)->cache.part_of_subsidy & POS_SRC)) return false;
break;
default: return false;
}
@@ -557,7 +557,7 @@ bool CheckSubsidised(CargoID cargo_type, CompanyID company, SourceType src_type,
TileIndex tile = TileXY(x, y);
if (!IsTileType(tile, MP_HOUSE)) continue;
const Town *t = Town::GetByTile(tile);
- if (t->part_of_subsidy & POS_DST) towns_near.Include(t);
+ if (t->cache.part_of_subsidy & POS_DST) towns_near.Include(t);
}
}
break;
@@ -584,7 +584,7 @@ bool CheckSubsidised(CargoID cargo_type, CompanyID company, SourceType src_type,
case ST_TOWN:
for (const Town * const *tp = towns_near.Begin(); tp != towns_near.End(); tp++) {
if (s->dst == (*tp)->index) {
- assert((*tp)->part_of_subsidy & POS_DST);
+ assert((*tp)->cache.part_of_subsidy & POS_DST);
subsidised = true;
if (!s->IsAwarded()) s->AwardTo(company);
}
diff --git a/src/town.h b/src/town.h
index ad299c859..2bb1fa95f 100644
--- a/src/town.h
+++ b/src/town.h
@@ -40,12 +40,21 @@ static const uint16 TOWN_GROW_RATE_CUSTOM = 0x8000; ///< If this mask is applied
typedef Pool<Town, TownID, 64, 64000> TownPool;
extern TownPool _town_pool;
+/** Data structure with cached data of towns. */
+struct TownCache {
+ uint32 num_houses; ///< Amount of houses
+ uint32 population; ///< Current population of people
+ ViewportSign sign; ///< Location of name sign, UpdateVirtCoord updates this
+ PartOfSubsidyByte part_of_subsidy; ///< Is this town a source/destination of a subsidy?
+ uint32 squared_town_zone_radius[HZB_END]; ///< UpdateTownRadius updates this given the house count
+ BuildingCounts<uint16> building_counts; ///< The number of each type of building in the town
+};
+
/** Town data structure. */
struct Town : TownPool::PoolItem<&_town_pool> {
TileIndex xy; ///< town center tile
- uint32 num_houses; ///< amount of houses
- uint32 population; ///< current population of people
+ TownCache cache; ///< Container for all cacheable data.
/* Town name */
uint32 townnamegrfid;
@@ -53,8 +62,6 @@ struct Town : TownPool::PoolItem<&_town_pool> {
uint32 townnameparts;
char *name;
- ViewportSign sign; ///< NOSAVE: Location of name sign, UpdateVirtCoord updates this
-
/* Makes sure we don't build certain house types twice.
* bit 0 = Building funds received
* bit 1 = CHURCH
@@ -98,12 +105,6 @@ struct Town : TownPool::PoolItem<&_town_pool> {
std::list<PersistentStorage *> psa_list;
- PartOfSubsidyByte part_of_subsidy; ///< NOSAVE: is this town a source/destination of a subsidy?
-
- uint32 squared_town_zone_radius[HZB_END]; ///< NOSAVE: UpdateTownRadius updates this given the house count
-
- BuildingCounts<uint16> building_counts; ///< NOSAVE: the number of each type of building in the town
-
/**
* Creates a new town.
* @param tile center tile of the town
@@ -123,10 +124,10 @@ struct Town : TownPool::PoolItem<&_town_pool> {
*/
inline uint16 MaxTownNoise() const
{
- if (this->population == 0) return 0; // no population? no noise
+ if (this->cache.population == 0) return 0; // no population? no noise
/* 3 is added (the noise of the lowest airport), so the user can at least build a small airfield. */
- return (this->population / _settings_game.economy.town_noise_population[_settings_game.difficulty.town_council_tolerance]) + 3;
+ return (this->cache.population / _settings_game.economy.town_noise_population[_settings_game.difficulty.town_council_tolerance]) + 3;
}
void UpdateVirtCoord();
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 4ad07ea98..efe91c1ac 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -355,8 +355,8 @@ void Town::UpdateVirtCoord()
{
Point pt = RemapCoords2(TileX(this->xy) * TILE_SIZE, TileY(this->xy) * TILE_SIZE);
SetDParam(0, this->index);
- SetDParam(1, this->population);
- this->sign.UpdatePosition(pt.x, pt.y - 24 * ZOOM_LVL_BASE,
+ SetDParam(1, this->cache.population);
+ this->cache.sign.UpdatePosition(pt.x, pt.y - 24 * ZOOM_LVL_BASE,
_settings_client.gui.population_in_label ? STR_VIEWPORT_TOWN_POP : STR_VIEWPORT_TOWN);
SetWindowDirty(WC_TOWN_VIEW, this->index);
@@ -379,7 +379,7 @@ void UpdateAllTownVirtCoords()
*/
static void ChangePopulation(Town *t, int mod)
{
- t->population += mod;
+ t->cache.population += mod;
InvalidateWindowData(WC_TOWN_VIEW, t->index); // Cargo requirements may appear/vanish for small populations
t->UpdateVirtCoord();
@@ -396,7 +396,7 @@ uint32 GetWorldPopulation()
uint32 pop = 0;
const Town *t;
- FOR_ALL_TOWNS(t) pop += t->population;
+ FOR_ALL_TOWNS(t) pop += t->cache.population;
return pop;
}
@@ -1295,16 +1295,16 @@ static int GrowTownAtRoad(Town *t, TileIndex tile)
* them a little handicap. */
switch (t->layout) {
case TL_BETTER_ROADS:
- _grow_town_result = 10 + t->num_houses * 2 / 9;
+ _grow_town_result = 10 + t->cache.num_houses * 2 / 9;
break;
case TL_3X3_GRID:
case TL_2X2_GRID:
- _grow_town_result = 10 + t->num_houses * 1 / 9;
+ _grow_town_result = 10 + t->cache.num_houses * 1 / 9;
break;
default:
- _grow_town_result = 10 + t->num_houses * 4 / 9;
+ _grow_town_result = 10 + t->cache.num_houses * 4 / 9;
break;
}
@@ -1453,25 +1453,25 @@ void UpdateTownRadius(Town *t)
{121, 81, 0, 49, 36}, // 88
};
- if (t->num_houses < 92) {
- memcpy(t->squared_town_zone_radius, _town_squared_town_zone_radius_data[t->num_houses / 4], sizeof(t->squared_town_zone_radius));
+ if (t->cache.num_houses < 92) {
+ memcpy(t->cache.squared_town_zone_radius, _town_squared_town_zone_radius_data[t->cache.num_houses / 4], sizeof(t->cache.squared_town_zone_radius));
} else {
- int mass = t->num_houses / 8;
+ int mass = t->cache.num_houses / 8;
/* Actually we are proportional to sqrt() but that's right because we are covering an area.
* The offsets are to make sure the radii do not decrease in size when going from the table
* to the calculated value.*/
- t->squared_town_zone_radius[0] = mass * 15 - 40;
- t->squared_town_zone_radius[1] = mass * 9 - 15;
- t->squared_town_zone_radius[2] = 0;
- t->squared_town_zone_radius[3] = mass * 5 - 5;
- t->squared_town_zone_radius[4] = mass * 3 + 5;
+ t->cache.squared_town_zone_radius[0] = mass * 15 - 40;
+ t->cache.squared_town_zone_radius[1] = mass * 9 - 15;
+ t->cache.squared_town_zone_radius[2] = 0;
+ t->cache.squared_town_zone_radius[3] = mass * 5 - 5;
+ t->cache.squared_town_zone_radius[4] = mass * 3 + 5;
}
}
void UpdateTownMaxPass(Town *t)
{
- t->supplied[CT_PASSENGERS].old_max = t->population >> 3;
- t->supplied[CT_MAIL].old_max = t->population >> 4;
+ t->supplied[CT_PASSENGERS].old_max = t->cache.population >> 3;
+ t->supplied[CT_MAIL].old_max = t->cache.population >> 4;
}
/**
@@ -1488,11 +1488,11 @@ void UpdateTownMaxPass(Town *t)
static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize size, bool city, TownLayout layout, bool manual)
{
t->xy = tile;
- t->num_houses = 0;
+ t->cache.num_houses = 0;
t->time_until_rebuild = 10;
UpdateTownRadius(t);
t->flags = 0;
- t->population = 0;
+ t->cache.population = 0;
t->grow_counter = 0;
t->growth_rate = 250;
@@ -1541,7 +1541,7 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize
/* Don't create huge cities when founding town in-game */
if (city && (!manual || _game_mode == GM_EDITOR)) x *= _settings_game.economy.initial_city_size;
- t->num_houses += x;
+ t->cache.num_houses += x;
UpdateTownRadius(t);
int i = x * 4;
@@ -1549,7 +1549,7 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize
GrowTown(t);
} while (--i);
- t->num_houses -= x;
+ t->cache.num_houses -= x;
UpdateTownRadius(t);
UpdateTownMaxPass(t);
UpdateAirportsNoise();
@@ -1845,7 +1845,7 @@ static Town *CreateRandomTown(uint attempts, uint32 townnameparts, TownSize size
/* if the population is still 0 at the point, then the
* placement is so bad it couldn't grow at all */
- if (t->population > 0) return t;
+ if (t->cache.population > 0) return t;
CommandCost rc = DoCommand(t->xy, t->index, 0, DC_EXEC, CMD_DELETE_TOWN);
assert(rc.Succeeded());
@@ -1921,7 +1921,7 @@ HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
HouseZonesBits smallest = HZB_TOWN_EDGE;
for (HouseZonesBits i = HZB_BEGIN; i < HZB_END; i++) {
- if (dist < t->squared_town_zone_radius[i]) smallest = i;
+ if (dist < t->cache.squared_town_zone_radius[i]) smallest = i;
}
return smallest;
@@ -2202,10 +2202,10 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
/* Don't let these counters overflow. Global counters are 32bit, there will never be that many houses. */
if (hs->class_id != HOUSE_NO_CLASS) {
/* id_count is always <= class_count, so it doesn't need to be checked */
- if (t->building_counts.class_count[hs->class_id] == UINT16_MAX) continue;
+ if (t->cache.building_counts.class_count[hs->class_id] == UINT16_MAX) continue;
} else {
/* If the house has no class, check id_count instead */
- if (t->building_counts.id_count[i] == UINT16_MAX) continue;
+ if (t->cache.building_counts.id_count[i] == UINT16_MAX) continue;
}
/* Without NewHouses, all houses have probability '1' */
@@ -2282,7 +2282,7 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
}
/* build the house */
- t->num_houses++;
+ t->cache.num_houses++;
/* Special houses that there can be only one of. */
t->flags |= oneof;
@@ -2371,7 +2371,7 @@ void ClearTownHouse(Town *t, TileIndex tile)
ChangePopulation(t, -hs->population);
}
- t->num_houses--;
+ t->cache.num_houses--;
/* Clear flags for houses that only may exist once/town. */
if (hs->building_flags & BUILDING_IS_CHURCH) {
@@ -2543,14 +2543,14 @@ CommandCost CmdExpandTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
if (flags & DC_EXEC) {
/* The more houses, the faster we grow */
if (p2 == 0) {
- uint amount = RandomRange(ClampToU16(t->num_houses / 10)) + 3;
- t->num_houses += amount;
+ uint amount = RandomRange(ClampToU16(t->cache.num_houses / 10)) + 3;
+ t->cache.num_houses += amount;
UpdateTownRadius(t);
uint n = amount * 10;
do GrowTown(t); while (--n);
- t->num_houses -= amount;
+ t->cache.num_houses -= amount;
} else {
for (; p2 > 0; p2--) {
/* Try several times to grow, as we are really suppose to grow */
@@ -2962,7 +2962,7 @@ static void UpdateTownRating(Town *t)
const Station *st;
FOR_ALL_STATIONS(st) {
- if (DistanceSquare(st->xy, t->xy) <= t->squared_town_zone_radius[0]) {
+ if (DistanceSquare(st->xy, t->xy) <= t->cache.squared_town_zone_radius[0]) {
if (st->time_since_load <= 20 || st->time_since_unload <= 20) {
if (Company::IsValidID(st->owner)) {
int new_rating = t->ratings[st->owner] + RATING_STATION_UP_STEP;
@@ -2997,10 +2997,10 @@ static void UpdateTownGrowRate(Town *t)
for (int i = TE_BEGIN; i < TE_END; i++) {
switch (t->goal[i]) {
case TOWN_GROWTH_WINTER:
- if (TileHeight(t->xy) >= GetSnowLine() && t->received[i].old_act == 0 && t->population > 90) return;
+ if (TileHeight(t->xy) >= GetSnowLine() && t->received[i].old_act == 0 && t->cache.population > 90) return;
break;
case TOWN_GROWTH_DESERT:
- if (GetTropicZone(t->xy) == TROPICZONE_DESERT && t->received[i].old_act == 0 && t->population > 60) return;
+ if (GetTropicZone(t->xy) == TROPICZONE_DESERT && t->received[i].old_act == 0 && t->cache.population > 60) return;
break;
default:
if (t->goal[i] > t->received[i].old_act) return;
@@ -3028,7 +3028,7 @@ static void UpdateTownGrowRate(Town *t)
const Station *st;
FOR_ALL_STATIONS(st) {
- if (DistanceSquare(st->xy, t->xy) <= t->squared_town_zone_radius[0]) {
+ if (DistanceSquare(st->xy, t->xy) <= t->cache.squared_town_zone_radius[0]) {
if (st->time_since_load <= 20 || st->time_since_unload <= 20) {
n++;
}
@@ -3051,7 +3051,7 @@ static void UpdateTownGrowRate(Town *t)
m >>= growth_multiplier;
if (t->larger_town) m /= 2;
- t->growth_rate = m / (t->num_houses / 50 + 1);
+ t->growth_rate = m / (t->cache.num_houses / 50 + 1);
if (m <= t->grow_counter) {
t->grow_counter = m;
}
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index 36b74a52b..bd8d44087 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -328,8 +328,8 @@ public:
uint y = r.top + WD_FRAMERECT_TOP;
- SetDParam(0, this->town->population);
- SetDParam(1, this->town->num_houses);
+ SetDParam(0, this->town->cache.population);
+ SetDParam(1, this->town->cache.num_houses);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y, STR_TOWN_VIEW_POPULATION_HOUSES);
SetDParam(0, this->town->supplied[CT_PASSENGERS].old_act);
@@ -343,8 +343,8 @@ public:
bool first = true;
for (int i = TE_BEGIN; i < TE_END; i++) {
if (this->town->goal[i] == 0) continue;
- if (this->town->goal[i] == TOWN_GROWTH_WINTER && (TileHeight(this->town->xy) < LowestSnowLine() || this->town->population <= 90)) continue;
- if (this->town->goal[i] == TOWN_GROWTH_DESERT && (GetTropicZone(this->town->xy) != TROPICZONE_DESERT || this->town->population <= 60)) continue;
+ if (this->town->goal[i] == TOWN_GROWTH_WINTER && (TileHeight(this->town->xy) < LowestSnowLine() || this->town->cache.population <= 90)) continue;
+ if (this->town->goal[i] == TOWN_GROWTH_DESERT && (GetTropicZone(this->town->xy) != TROPICZONE_DESERT || this->town->cache.population <= 60)) continue;
if (first) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH);
@@ -465,8 +465,8 @@ public:
bool first = true;
for (int i = TE_BEGIN; i < TE_END; i++) {
if (this->town->goal[i] == 0) continue;
- if (this->town->goal[i] == TOWN_GROWTH_WINTER && (TileHeight(this->town->xy) < LowestSnowLine() || this->town->population <= 90)) continue;
- if (this->town->goal[i] == TOWN_GROWTH_DESERT && (GetTropicZone(this->town->xy) != TROPICZONE_DESERT || this->town->population <= 60)) continue;
+ if (this->town->goal[i] == TOWN_GROWTH_WINTER && (TileHeight(this->town->xy) < LowestSnowLine() || this->town->cache.population <= 90)) continue;
+ if (this->town->goal[i] == TOWN_GROWTH_DESERT && (GetTropicZone(this->town->xy) != TROPICZONE_DESERT || this->town->cache.population <= 60)) continue;
if (first) {
aimed_height += FONT_HEIGHT_NORMAL;
@@ -681,7 +681,7 @@ private:
/** Sort by population */
static int CDECL TownPopulationSorter(const Town * const *a, const Town * const *b)
{
- return (*a)->population - (*b)->population;
+ return (*a)->cache.population - (*b)->cache.population;
}
public:
@@ -750,7 +750,7 @@ public:
}
SetDParam(0, t->index);
- SetDParam(1, t->population);
+ SetDParam(1, t->cache.population);
DrawString(text_left, text_right, y + (this->resize.step_height - FONT_HEIGHT_NORMAL) / 2, STR_TOWN_DIRECTORY_TOWN);
y += this->resize.step_height;
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index 945563fb5..1fd812134 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -251,7 +251,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
company = OWNER_TOWN;
/* If we are not within a town, we are not owned by the town */
- if (town == NULL || DistanceSquare(tile_start, town->xy) > town->squared_town_zone_radius[HZB_TOWN_EDGE]) {
+ if (town == NULL || DistanceSquare(tile_start, town->xy) > town->cache.squared_town_zone_radius[HZB_TOWN_EDGE]) {
company = OWNER_NONE;
}
}
@@ -560,7 +560,7 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1,
company = OWNER_TOWN;
/* If we are not within a town, we are not owned by the town */
- if (town == NULL || DistanceSquare(start_tile, town->xy) > town->squared_town_zone_radius[HZB_TOWN_EDGE]) {
+ if (town == NULL || DistanceSquare(start_tile, town->xy) > town->cache.squared_town_zone_radius[HZB_TOWN_EDGE]) {
company = OWNER_NONE;
}
}
diff --git a/src/viewport.cpp b/src/viewport.cpp
index 527de40a5..011064f2a 100644
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -1171,10 +1171,10 @@ static void ViewportAddTownNames(DrawPixelInfo *dpi)
const Town *t;
FOR_ALL_TOWNS(t) {
- ViewportAddString(dpi, ZOOM_LVL_OUT_16X, &t->sign,
+ ViewportAddString(dpi, ZOOM_LVL_OUT_16X, &t->cache.sign,
_settings_client.gui.population_in_label ? STR_VIEWPORT_TOWN_POP : STR_VIEWPORT_TOWN,
STR_VIEWPORT_TOWN_TINY_WHITE, STR_VIEWPORT_TOWN_TINY_BLACK,
- t->index, t->population);
+ t->index, t->cache.population);
}
}
@@ -1865,7 +1865,7 @@ static bool CheckClickOnTown(const ViewPort *vp, int x, int y)
const Town *t;
FOR_ALL_TOWNS(t) {
- if (CheckClickOnViewportSign(vp, x, y, &t->sign)) {
+ if (CheckClickOnViewportSign(vp, x, y, &t->cache.sign)) {
ShowTownViewWindow(t->index);
return true;
}