diff options
-rw-r--r-- | docs/landscape.html | 2 | ||||
-rw-r--r-- | src/date.cpp | 2 | ||||
-rw-r--r-- | src/newgrf_house.cpp | 2 | ||||
-rw-r--r-- | src/openttd.cpp | 7 | ||||
-rw-r--r-- | src/town_cmd.cpp | 13 | ||||
-rw-r--r-- | src/town_map.h | 27 |
6 files changed, 39 insertions, 14 deletions
diff --git a/docs/landscape.html b/docs/landscape.html index 99f4bee58..bee6e994d 100644 --- a/docs/landscape.html +++ b/docs/landscape.html @@ -680,7 +680,7 @@ <ul> <li> set : House is complete <ul> - <li>m5 : year of house construction (relative to 1920); clamped to 0..255 (1920..2175)</li> + <li>m5 : Age of house in years, clamped at 255</li> </ul> </li> <li> clear : House is in construction diff --git a/src/date.cpp b/src/date.cpp index d477b7359..4b4b94bb0 100644 --- a/src/date.cpp +++ b/src/date.cpp @@ -171,6 +171,7 @@ extern void TrainsYearlyLoop(); extern void RoadVehiclesYearlyLoop(); extern void AircraftYearlyLoop(); extern void ShipsYearlyLoop(); +extern void TownsYearlyLoop(); extern void ShowEndGameChart(); @@ -275,6 +276,7 @@ void IncreaseDate() RoadVehiclesYearlyLoop(); AircraftYearlyLoop(); ShipsYearlyLoop(); + TownsYearlyLoop(); #ifdef ENABLE_NETWORK if (_network_server) NetworkServerYearlyLoop(); #endif /* ENABLE_NETWORK */ diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index f112936f0..ce7558f97 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -316,7 +316,7 @@ static uint32 HouseGetVariable(const ResolverObject *object, byte variable, byte case 0x40: return (IsTileType(tile, MP_HOUSE) ? GetHouseBuildingStage(tile) : 0) | TileHash2Bit(TileX(tile), TileY(tile)) << 2; /* Building age. */ - case 0x41: return Clamp(_cur_year - GetHouseConstructionYear(tile), 0, 0xFF); + case 0x41: return GetHouseAge(tile); /* Town zone */ case 0x42: return GetTownRadiusGroup(town, tile); diff --git a/src/openttd.cpp b/src/openttd.cpp index c79b68014..c4c39cf9a 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -2477,8 +2477,8 @@ bool AfterLoadGame() } if (CheckSavegameVersion(99)) { - /* Set newly introduced WaterClass of industry tiles */ for (TileIndex t = 0; t < map_size; t++) { + /* Set newly introduced WaterClass of industry tiles */ if (IsTileType(t, MP_STATION) && IsOilRig(t)) { SetWaterClassDependingOnSurroundings(t, true); } @@ -2489,6 +2489,11 @@ bool AfterLoadGame() SetWaterClass(t, WATER_CLASS_INVALID); } } + + /* Replace "house construction year" with "house age" */ + if (IsTileType(t, MP_HOUSE) && IsHouseCompleted(t)) { + _m[t].m5 = Clamp(_cur_year - (_m[t].m5 + ORIGINAL_BASE_YEAR), 0, 0xFF); + } } } diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index a2411f7ce..19cc2ec05 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -404,7 +404,7 @@ static void MakeSingleHouseBigger(TileIndex tile) /* Now that construction is complete, we can add the population of the * building to the town. */ ChangePopulation(GetTownByTile(tile), hs->population); - SetHouseConstructionYear(tile, _cur_year); + ResetHouseAge(tile); } MarkTileDirtyByTile(tile); } @@ -505,7 +505,7 @@ static void TileLoop_Town(TileIndex tile) if (hs->building_flags & BUILDING_HAS_1_TILE && HasBit(t->flags12, TOWN_IS_FUNDED) && CanDeleteHouse(tile) && - max(_cur_year - GetHouseConstructionYear(tile), 0) >= hs->minimum_life && + GetHouseAge(tile) >= hs->minimum_life && --t->time_until_rebuild == 0) { t->time_until_rebuild = GB(r, 16, 8) + 192; @@ -2608,6 +2608,15 @@ void TownsMonthlyLoop() } } +void TownsYearlyLoop() +{ + /* Increment house ages */ + for (TileIndex t = 0; t < MapSize(); t++) { + if (!IsTileType(t, MP_HOUSE)) continue; + IncrementHouseAge(t); + } +} + void InitializeTowns() { /* Clean the town pool and create 1 block in it */ diff --git a/src/town_map.h b/src/town_map.h index e5f55c12b..b0653a1cd 100644 --- a/src/town_map.h +++ b/src/town_map.h @@ -6,8 +6,6 @@ #define TOWN_MAP_H #include "town.h" -#include "date_type.h" -#include "date_func.h" #include "tile_map.h" /** @@ -266,27 +264,38 @@ static inline void IncHouseConstructionTick(TileIndex t) } /** - * Set the year that this house was constructed. + * Sets the age of the house to zero. + * Needs to be called after the house is completed. During construction stages the map space is used otherwise. * @param t the tile of this house - * @param year the year to set * @pre IsTileType(t, MP_HOUSE) && IsHouseCompleted(t) */ -static inline void SetHouseConstructionYear(TileIndex t, Year year) +static inline void ResetHouseAge(TileIndex t) { assert(IsTileType(t, MP_HOUSE) && IsHouseCompleted(t)); - _m[t].m5 = Clamp(year - GetHouseSpecs(GetHouseType(t))->min_year, 0, 0xFF); + _m[t].m5 = 0; } /** - * Get the year that this house was constructed. + * Increments the age of the house. + * @param t the tile of this house + * @pre IsTileType(t, MP_HOUSE) + */ +static inline void IncrementHouseAge(TileIndex t) +{ + assert(IsTileType(t, MP_HOUSE)); + if (IsHouseCompleted(t) && _m[t].m5 < 0xFF) _m[t].m5++; +} + +/** + * Get the age of the house * @param t the tile of this house * @pre IsTileType(t, MP_HOUSE) * @return year */ -static inline Year GetHouseConstructionYear(TileIndex t) +static inline Year GetHouseAge(TileIndex t) { assert(IsTileType(t, MP_HOUSE)); - return IsHouseCompleted(t) ? _m[t].m5 + GetHouseSpecs(GetHouseType(t))->min_year : _cur_year; + return IsHouseCompleted(t) ? _m[t].m5 : 0; } /** |