(svn r14611) -Fix (r13437)[FS#2421]: Store the age of a house in the map array instead of the construction year.
Note: Savegames from r13437 to now are broken and have a age of 255 years for a lot houses.
--- a/docs/landscape.html Sun Nov 23 13:42:05 2008 +0000
+++ b/docs/landscape.html Sun Nov 23 14:17:41 2008 +0000
@@ -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
--- a/src/date.cpp Sun Nov 23 13:42:05 2008 +0000
+++ b/src/date.cpp Sun Nov 23 14:17:41 2008 +0000
@@ -171,6 +171,7 @@
extern void RoadVehiclesYearlyLoop();
extern void AircraftYearlyLoop();
extern void ShipsYearlyLoop();
+extern void TownsYearlyLoop();
extern void ShowEndGameChart();
@@ -275,6 +276,7 @@
RoadVehiclesYearlyLoop();
AircraftYearlyLoop();
ShipsYearlyLoop();
+ TownsYearlyLoop();
#ifdef ENABLE_NETWORK
if (_network_server) NetworkServerYearlyLoop();
#endif /* ENABLE_NETWORK */
--- a/src/newgrf_house.cpp Sun Nov 23 13:42:05 2008 +0000
+++ b/src/newgrf_house.cpp Sun Nov 23 14:17:41 2008 +0000
@@ -316,7 +316,7 @@
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);
--- a/src/openttd.cpp Sun Nov 23 13:42:05 2008 +0000
+++ b/src/openttd.cpp Sun Nov 23 14:17:41 2008 +0000
@@ -2477,8 +2477,8 @@
}
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 @@
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);
+ }
}
}
--- a/src/town_cmd.cpp Sun Nov 23 13:42:05 2008 +0000
+++ b/src/town_cmd.cpp Sun Nov 23 14:17:41 2008 +0000
@@ -404,7 +404,7 @@
/* 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 @@
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 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 */
--- a/src/town_map.h Sun Nov 23 13:42:05 2008 +0000
+++ b/src/town_map.h Sun Nov 23 14:17:41 2008 +0000
@@ -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 @@
}
/**
- * 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;
}
/**