Changeset - r8291:f082c9a42b1f
[Not reviewed]
master
0 4 0
glx - 16 years ago 2008-01-15 00:03:48
glx@openttd.org
(svn r11855) -Fix [FS#1335]: recompute town population when removing a 'newhouses' grf, or when loading a game with missing 'newhouses' grfs
4 files changed with 11 insertions and 23 deletions:
0 comments (0 inline, 0 general)
src/newgrf_house.cpp
Show inline comments
 
@@ -30,27 +30,33 @@ static BuildingCounts    _building_count
 
static HouseClassMapping _class_mapping[HOUSE_CLASS_MAX];
 

	
 
HouseOverrideManager _house_mngr(NEW_HOUSE_OFFSET, HOUSE_MAX, INVALID_HOUSE_ID);
 

	
 
void CheckHouseIDs()
 
{
 
	Town *town;
 
	InitializeBuildingCounts();
 

	
 
	/* Reset town population */
 
	FOR_ALL_TOWNS(town) town->population = 0;
 

	
 
	for (TileIndex t = 0; t < MapSize(); t++) {
 
		HouseID house_id;
 

	
 
		if (!IsTileType(t, MP_HOUSE)) continue;
 

	
 
		house_id = GetHouseType(t);
 
		if (!GetHouseSpecs(house_id)->enabled && house_id >= NEW_HOUSE_OFFSET) {
 
			/* The specs for this type of house are not available any more, so
 
			 * replace it with the substitute original house type. */
 
			house_id = _house_mngr.GetSubstituteID(house_id);
 
			SetHouseType(t, house_id);
 
		}
 
		IncreaseBuildingCount(GetTownByTile(t), house_id);
 
		town = GetTownByTile(t);
 
		IncreaseBuildingCount(town, house_id);
 
		if (IsHouseCompleted(t)) town->population += GetHouseSpecs(house_id)->population;
 
	}
 
}
 

	
 
HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid)
 
{
 
	/* Start from 1 because 0 means that no class has been assigned. */
 
@@ -119,28 +125,12 @@ void DecreaseBuildingCount(Town *t, Hous
 
	if (class_id == HOUSE_NO_CLASS) return;
 

	
 
	if (t->building_counts.class_count[class_id] > 0) t->building_counts.class_count[class_id]--;
 
	if (_building_counts.class_count[class_id] > 0)   _building_counts.class_count[class_id]--;
 
}
 

	
 
/**
 
 * AfterLoadCountBuildings()
 
 *
 
 * After a savegame has been loaded, count the number of buildings on the map.
 
 */
 
void AfterLoadCountBuildings()
 
{
 
	if (!_loaded_newgrf_features.has_newhouses) return;
 

	
 
	for (TileIndex t = 0; t < MapSize(); t++) {
 
		if (!IsTileType(t, MP_HOUSE)) continue;
 
		IncreaseBuildingCount(GetTownByTile(t), GetHouseType(t));
 
	}
 
}
 

	
 

	
 
static uint32 HouseGetRandomBits(const ResolverObject *object)
 
{
 
	const TileIndex tile = object->u.house.tile;
 
	return (tile == INVALID_TILE || !IsTileType(tile, MP_HOUSE)) ? 0 : GetHouseRandomBits(tile);
 
}
 

	
src/newgrf_house.h
Show inline comments
 
@@ -30,13 +30,12 @@ void CheckHouseIDs();
 

	
 
HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid);
 

	
 
void InitializeBuildingCounts();
 
void IncreaseBuildingCount(Town *t, HouseID house_id);
 
void DecreaseBuildingCount(Town *t, HouseID house_id);
 
void AfterLoadCountBuildings();
 

	
 
void DrawNewHouseTile(TileInfo *ti, HouseID house_id);
 
void AnimateNewHouseTile(TileIndex tile);
 
void ChangeHouseAnimationFrame(TileIndex tile, uint16 callback_result);
 

	
 
uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile);
src/openttd.cpp
Show inline comments
 
@@ -2015,14 +2015,14 @@ bool AfterLoadGame()
 
					SetHouseCompleted(t, true);
 
				}
 
			}
 
		}
 
	}
 

	
 
	/* Count the buildings after updating the map array. */
 
	AfterLoadCountBuildings();
 
	/* Check that house ids are still valid. */
 
	CheckHouseIDs();
 

	
 
	if (CheckSavegameVersion(43)) {
 
		for (TileIndex t = 0; t < map_size; t++) {
 
			if (IsTileType(t, MP_INDUSTRY)) {
 
				switch (GetIndustryGfx(t)) {
 
					case GFX_POWERPLANT_SPARKS:
src/town_cmd.cpp
Show inline comments
 
@@ -2408,15 +2408,14 @@ extern const TileTypeProcs _tile_type_to
 

	
 
/** Save and load of towns. */
 
static const SaveLoad _town_desc[] = {
 
	SLE_CONDVAR(Town, xy,                    SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
 
	SLE_CONDVAR(Town, xy,                    SLE_UINT32,                 6, SL_MAX_VERSION),
 

	
 
	SLE_CONDVAR(Town, population,            SLE_FILE_U16 | SLE_VAR_U32, 0, 2),
 
	SLE_CONDVAR(Town, population,            SLE_UINT32,                 3, SL_MAX_VERSION),
 

	
 
	SLE_CONDNULL(2, 0, 2),
 
	SLE_CONDNULL(4, 3, 84),
 

	
 
	    SLE_VAR(Town, num_houses,            SLE_UINT16),
 
	SLE_CONDVAR(Town, townnamegrfid,         SLE_UINT32, 66, SL_MAX_VERSION),
 
	    SLE_VAR(Town, townnametype,          SLE_UINT16),
 
	    SLE_VAR(Town, townnameparts,         SLE_UINT32),
 
	SLE_CONDSTR(Town, name,                  SLE_STR, 0, 84, SL_MAX_VERSION),
0 comments (0 inline, 0 general)