mirror of https://github.com/OpenTTD/OpenTTD.git
(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:
parent
2277a1ff9c
commit
3d467cabe5
|
@ -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
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue