(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.
This commit is contained in:
frosch 2008-11-23 14:17:41 +00:00
parent 2277a1ff9c
commit 3d467cabe5
6 changed files with 39 additions and 14 deletions

View File

@ -680,7 +680,7 @@
<ul> <ul>
<li> set : House is complete <li> set : House is complete
<ul> <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> </ul>
</li> </li>
<li> clear : House is in construction <li> clear : House is in construction

View File

@ -171,6 +171,7 @@ extern void TrainsYearlyLoop();
extern void RoadVehiclesYearlyLoop(); extern void RoadVehiclesYearlyLoop();
extern void AircraftYearlyLoop(); extern void AircraftYearlyLoop();
extern void ShipsYearlyLoop(); extern void ShipsYearlyLoop();
extern void TownsYearlyLoop();
extern void ShowEndGameChart(); extern void ShowEndGameChart();
@ -275,6 +276,7 @@ void IncreaseDate()
RoadVehiclesYearlyLoop(); RoadVehiclesYearlyLoop();
AircraftYearlyLoop(); AircraftYearlyLoop();
ShipsYearlyLoop(); ShipsYearlyLoop();
TownsYearlyLoop();
#ifdef ENABLE_NETWORK #ifdef ENABLE_NETWORK
if (_network_server) NetworkServerYearlyLoop(); if (_network_server) NetworkServerYearlyLoop();
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */

View File

@ -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; case 0x40: return (IsTileType(tile, MP_HOUSE) ? GetHouseBuildingStage(tile) : 0) | TileHash2Bit(TileX(tile), TileY(tile)) << 2;
/* Building age. */ /* Building age. */
case 0x41: return Clamp(_cur_year - GetHouseConstructionYear(tile), 0, 0xFF); case 0x41: return GetHouseAge(tile);
/* Town zone */ /* Town zone */
case 0x42: return GetTownRadiusGroup(town, tile); case 0x42: return GetTownRadiusGroup(town, tile);

View File

@ -2477,8 +2477,8 @@ bool AfterLoadGame()
} }
if (CheckSavegameVersion(99)) { if (CheckSavegameVersion(99)) {
/* Set newly introduced WaterClass of industry tiles */
for (TileIndex t = 0; t < map_size; t++) { for (TileIndex t = 0; t < map_size; t++) {
/* Set newly introduced WaterClass of industry tiles */
if (IsTileType(t, MP_STATION) && IsOilRig(t)) { if (IsTileType(t, MP_STATION) && IsOilRig(t)) {
SetWaterClassDependingOnSurroundings(t, true); SetWaterClassDependingOnSurroundings(t, true);
} }
@ -2489,6 +2489,11 @@ bool AfterLoadGame()
SetWaterClass(t, WATER_CLASS_INVALID); 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);
}
} }
} }

View File

@ -404,7 +404,7 @@ static void MakeSingleHouseBigger(TileIndex tile)
/* Now that construction is complete, we can add the population of the /* Now that construction is complete, we can add the population of the
* building to the town. */ * building to the town. */
ChangePopulation(GetTownByTile(tile), hs->population); ChangePopulation(GetTownByTile(tile), hs->population);
SetHouseConstructionYear(tile, _cur_year); ResetHouseAge(tile);
} }
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }
@ -505,7 +505,7 @@ static void TileLoop_Town(TileIndex tile)
if (hs->building_flags & BUILDING_HAS_1_TILE && if (hs->building_flags & BUILDING_HAS_1_TILE &&
HasBit(t->flags12, TOWN_IS_FUNDED) && HasBit(t->flags12, TOWN_IS_FUNDED) &&
CanDeleteHouse(tile) && 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 == 0) {
t->time_until_rebuild = GB(r, 16, 8) + 192; 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() void InitializeTowns()
{ {
/* Clean the town pool and create 1 block in it */ /* Clean the town pool and create 1 block in it */

View File

@ -6,8 +6,6 @@
#define TOWN_MAP_H #define TOWN_MAP_H
#include "town.h" #include "town.h"
#include "date_type.h"
#include "date_func.h"
#include "tile_map.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 t the tile of this house
* @param year the year to set
* @pre IsTileType(t, MP_HOUSE) && IsHouseCompleted(t) * @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)); 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 * @param t the tile of this house
* @pre IsTileType(t, MP_HOUSE) * @pre IsTileType(t, MP_HOUSE)
* @return year * @return year
*/ */
static inline Year GetHouseConstructionYear(TileIndex t) static inline Year GetHouseAge(TileIndex t)
{ {
assert(IsTileType(t, MP_HOUSE)); 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;
} }
/** /**