summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2008-11-23 14:17:41 +0000
committerfrosch <frosch@openttd.org>2008-11-23 14:17:41 +0000
commit3d467cabe5ff086a76ecee1c9ae91da3f3caf35d (patch)
treef40e12e3b8552cbd2e88bf34163d9d6bd7504306 /src
parent2277a1ff9ccd2e5a5acca1e815f628f054c84491 (diff)
downloadopenttd-3d467cabe5ff086a76ecee1c9ae91da3f3caf35d.tar.xz
(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.
Diffstat (limited to 'src')
-rw-r--r--src/date.cpp2
-rw-r--r--src/newgrf_house.cpp2
-rw-r--r--src/openttd.cpp7
-rw-r--r--src/town_cmd.cpp13
-rw-r--r--src/town_map.h27
5 files changed, 38 insertions, 13 deletions
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;
}
/**