equal
deleted
inserted
replaced
31 |
31 |
32 HouseOverrideManager _house_mngr(NEW_HOUSE_OFFSET, HOUSE_MAX, INVALID_HOUSE_ID); |
32 HouseOverrideManager _house_mngr(NEW_HOUSE_OFFSET, HOUSE_MAX, INVALID_HOUSE_ID); |
33 |
33 |
34 void CheckHouseIDs() |
34 void CheckHouseIDs() |
35 { |
35 { |
|
36 Town *town; |
36 InitializeBuildingCounts(); |
37 InitializeBuildingCounts(); |
|
38 |
|
39 /* Reset town population */ |
|
40 FOR_ALL_TOWNS(town) town->population = 0; |
37 |
41 |
38 for (TileIndex t = 0; t < MapSize(); t++) { |
42 for (TileIndex t = 0; t < MapSize(); t++) { |
39 HouseID house_id; |
43 HouseID house_id; |
40 |
44 |
41 if (!IsTileType(t, MP_HOUSE)) continue; |
45 if (!IsTileType(t, MP_HOUSE)) continue; |
45 /* The specs for this type of house are not available any more, so |
49 /* The specs for this type of house are not available any more, so |
46 * replace it with the substitute original house type. */ |
50 * replace it with the substitute original house type. */ |
47 house_id = _house_mngr.GetSubstituteID(house_id); |
51 house_id = _house_mngr.GetSubstituteID(house_id); |
48 SetHouseType(t, house_id); |
52 SetHouseType(t, house_id); |
49 } |
53 } |
50 IncreaseBuildingCount(GetTownByTile(t), house_id); |
54 town = GetTownByTile(t); |
|
55 IncreaseBuildingCount(town, house_id); |
|
56 if (IsHouseCompleted(t)) town->population += GetHouseSpecs(house_id)->population; |
51 } |
57 } |
52 } |
58 } |
53 |
59 |
54 HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid) |
60 HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid) |
55 { |
61 { |
119 if (class_id == HOUSE_NO_CLASS) return; |
125 if (class_id == HOUSE_NO_CLASS) return; |
120 |
126 |
121 if (t->building_counts.class_count[class_id] > 0) t->building_counts.class_count[class_id]--; |
127 if (t->building_counts.class_count[class_id] > 0) t->building_counts.class_count[class_id]--; |
122 if (_building_counts.class_count[class_id] > 0) _building_counts.class_count[class_id]--; |
128 if (_building_counts.class_count[class_id] > 0) _building_counts.class_count[class_id]--; |
123 } |
129 } |
124 |
|
125 /** |
|
126 * AfterLoadCountBuildings() |
|
127 * |
|
128 * After a savegame has been loaded, count the number of buildings on the map. |
|
129 */ |
|
130 void AfterLoadCountBuildings() |
|
131 { |
|
132 if (!_loaded_newgrf_features.has_newhouses) return; |
|
133 |
|
134 for (TileIndex t = 0; t < MapSize(); t++) { |
|
135 if (!IsTileType(t, MP_HOUSE)) continue; |
|
136 IncreaseBuildingCount(GetTownByTile(t), GetHouseType(t)); |
|
137 } |
|
138 } |
|
139 |
|
140 |
130 |
141 static uint32 HouseGetRandomBits(const ResolverObject *object) |
131 static uint32 HouseGetRandomBits(const ResolverObject *object) |
142 { |
132 { |
143 const TileIndex tile = object->u.house.tile; |
133 const TileIndex tile = object->u.house.tile; |
144 return (tile == INVALID_TILE || !IsTileType(tile, MP_HOUSE)) ? 0 : GetHouseRandomBits(tile); |
134 return (tile == INVALID_TILE || !IsTileType(tile, MP_HOUSE)) ? 0 : GetHouseRandomBits(tile); |