OpenTTD Source: src/saveload/town_sl.cpp Source File

OpenTTD Source 15.3

town_sl.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "../stdafx.h"
11
12#include "saveload.h"
13#include "compat/town_sl_compat.h"
14
15#include "newgrf_sl.h"
16#include "../newgrf_house.h"
17#include "../town.h"
18#include "../landscape.h"
19#include "../subsidy_func.h"
20#include "../strings_func.h"
21#include "../misc/history_func.hpp"
22
23#include "../safeguards.h"
24
28 void RebuildTownCaches()
29{
30 InitializeBuildingCounts();
31 RebuildTownKdtree();
32
33 /* Reset town population and num_houses */
34 for (Town *town : Town::Iterate()) {
35 town->cache.population = 0;
36 town->cache.num_houses = 0;
37 }
38
39 for (const auto t : Map::Iterate()) {
40 if (!IsTileType(t, MP_HOUSE)) continue;
41
42 HouseID house_id = GetHouseType(t);
43 Town *town = Town::GetByTile(t);
44 IncreaseBuildingCount(town, house_id);
45 if (IsHouseCompleted(t)) town->cache.population += HouseSpec::Get(house_id)->population;
46
47 /* Increase the number of houses for every house, but only once. */
48 if (GetHouseNorthPart(house_id) == TileDiffXY(0, 0)) town->cache.num_houses++;
49 }
50
51 /* Update the population and num_house dependent values */
52 for (Town *town : Town::Iterate()) {
53 UpdateTownRadius(town);
54 }
55}
56
65 void UpdateHousesAndTowns()
66{
67 for (const auto t : Map::Iterate()) {
68 if (!IsTileType(t, MP_HOUSE)) continue;
69
70 HouseID house_id = GetCleanHouseType(t);
71 if (!HouseSpec::Get(house_id)->enabled && house_id >= NEW_HOUSE_OFFSET) {
72 /* The specs for this type of house are not available any more, so
73 * replace it with the substitute original house type. */
74 house_id = _house_mngr.GetSubstituteID(house_id);
75 SetHouseType(t, house_id);
76 }
77 }
78
79 /* Check for cases when a NewGRF has set a wrong house substitute type. */
80 for (const TileIndex &t : Map::Iterate()) {
81 if (!IsTileType(t, MP_HOUSE)) continue;
82
83 HouseID house_type = GetCleanHouseType(t);
84 TileIndex north_tile = t + GetHouseNorthPart(house_type); // modifies 'house_type'!
85 if (t == north_tile) {
86 const HouseSpec *hs = HouseSpec::Get(house_type);
87 bool valid_house = true;
88 if (hs->building_flags.Test(BuildingFlag::Size2x1)) {
89 TileIndex tile = t + TileDiffXY(1, 0);
90 if (!IsTileType(tile, MP_HOUSE) || GetCleanHouseType(tile) != house_type + 1) valid_house = false;
91 } else if (hs->building_flags.Test(BuildingFlag::Size1x2)) {
92 TileIndex tile = t + TileDiffXY(0, 1);
93 if (!IsTileType(tile, MP_HOUSE) || GetCleanHouseType(tile) != house_type + 1) valid_house = false;
94 } else if (hs->building_flags.Test(BuildingFlag::Size2x2)) {
95 TileIndex tile = t + TileDiffXY(0, 1);
96 if (!IsTileType(tile, MP_HOUSE) || GetCleanHouseType(tile) != house_type + 1) valid_house = false;
97 tile = t + TileDiffXY(1, 0);
98 if (!IsTileType(tile, MP_HOUSE) || GetCleanHouseType(tile) != house_type + 2) valid_house = false;
99 tile = t + TileDiffXY(1, 1);
100 if (!IsTileType(tile, MP_HOUSE) || GetCleanHouseType(tile) != house_type + 3) valid_house = false;
101 }
102 /* If not all tiles of this house are present remove the house.
103 * The other tiles will get removed later in this loop because
104 * their north tile is not the correct type anymore. */
105 if (!valid_house) DoClearSquare(t);
106 } else if (!IsTileType(north_tile, MP_HOUSE) || GetCleanHouseType(north_tile) != house_type) {
107 /* This tile should be part of a multi-tile building but the
108 * north tile of this house isn't on the map. */
109 DoClearSquare(t);
110 }
111 }
112
113 RebuildTownCaches();
114}
115
116
117 class SlTownOldSupplied : public DefaultSaveLoadHandler<SlTownOldSupplied, Town> {
118public:
119 static inline const SaveLoad description[] = {
120 SLE_CONDVAR(TransportedCargoStat<uint32_t>, old_max, SLE_UINT32, SLV_165, SL_MAX_VERSION),
121 SLE_CONDVAR(TransportedCargoStat<uint32_t>, new_max, SLE_UINT32, SLV_165, SL_MAX_VERSION),
122 SLE_CONDVAR(TransportedCargoStat<uint32_t>, old_act, SLE_UINT32, SLV_165, SL_MAX_VERSION),
123 SLE_CONDVAR(TransportedCargoStat<uint32_t>, new_act, SLE_UINT32, SLV_165, SL_MAX_VERSION),
124 };
125 static inline const SaveLoadCompatTable compat_description = _town_supplied_sl_compat;
126
131 size_t GetNumCargo() const
132 {
133 if (IsSavegameVersionBefore(SLV_EXTEND_CARGOTYPES)) return 32;
134 if (IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH)) return NUM_CARGO;
135 /* Read from the savegame how long the list is. */
136 return SlGetStructListLength(NUM_CARGO);
137 }
138
139 void Load(Town *t) const override
140 {
141 size_t num_cargo = this->GetNumCargo();
142 for (size_t i = 0; i < num_cargo; i++) {
143 TransportedCargoStat<uint32_t> cargo_stat;
144 SlObject(&cargo_stat, this->GetLoadDescription());
145
146 /* Ignore empty statistics. */
147 if (cargo_stat.new_act == 0 && cargo_stat.new_max == 0 && cargo_stat.old_act == 0 && cargo_stat.old_max == 0) continue;
148
149 auto &s = t->supplied.emplace_back(static_cast<CargoType>(i));
150 s.history[LAST_MONTH].production = cargo_stat.old_max;
151 s.history[LAST_MONTH].transported = cargo_stat.old_act;
152 s.history[THIS_MONTH].production = cargo_stat.new_max;
153 s.history[THIS_MONTH].transported = cargo_stat.new_act;
154 }
155 }
156};
157
158 class SlTownSuppliedHistory : public DefaultSaveLoadHandler<SlTownSuppliedHistory, Town::SuppliedCargo> {
159public:
160 static inline const SaveLoad description[] = {
161 SLE_VAR(Town::SuppliedHistory, production, SLE_UINT32),
162 SLE_VAR(Town::SuppliedHistory, transported, SLE_UINT32),
163 };
164 static inline const SaveLoadCompatTable compat_description = {};
165
166 void Save(Town::SuppliedCargo *p) const override
167 {
168 SlSetStructListLength(p->history.size());
169
170 for (auto &h : p->history) {
171 SlObject(&h, this->GetDescription());
172 }
173 }
174
175 void Load(Town::SuppliedCargo *p) const override
176 {
177 size_t len = SlGetStructListLength(p->history.size());
178
179 for (auto &h : p->history) {
180 if (--len > p->history.size()) break; // unsigned so wraps after hitting zero.
181 SlObject(&h, this->GetLoadDescription());
182 }
183 }
184};
185
186 class SlTownSupplied : public VectorSaveLoadHandler<SlTownSupplied, Town, Town::SuppliedCargo> {
187public:
188 inline static const SaveLoad description[] = {
189 SLE_VAR(Town::SuppliedCargo, cargo, SLE_UINT8),
190 SLEG_STRUCTLIST("history", SlTownSuppliedHistory),
191 };
192 inline const static SaveLoadCompatTable compat_description = {};
193
194 std::vector<Town::SuppliedCargo> &GetVector(Town *t) const override { return t->supplied; }
195};
196
197 class SlTownReceived : public DefaultSaveLoadHandler<SlTownReceived, Town> {
198public:
199 static inline const SaveLoad description[] = {
200 SLE_CONDVAR(TransportedCargoStat<uint16_t>, old_max, SLE_UINT16, SLV_165, SL_MAX_VERSION),
201 SLE_CONDVAR(TransportedCargoStat<uint16_t>, new_max, SLE_UINT16, SLV_165, SL_MAX_VERSION),
202 SLE_CONDVAR(TransportedCargoStat<uint16_t>, old_act, SLE_UINT16, SLV_165, SL_MAX_VERSION),
203 SLE_CONDVAR(TransportedCargoStat<uint16_t>, new_act, SLE_UINT16, SLV_165, SL_MAX_VERSION),
204 };
205 static inline const SaveLoadCompatTable compat_description = _town_received_sl_compat;
206
207 void Save(Town *t) const override
208 {
209 SlSetStructListLength(std::size(t->received));
210 for (auto &received : t->received) {
211 SlObject(&received, this->GetDescription());
212 }
213 }
214
215 void Load(Town *t) const override
216 {
217 size_t length = IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) ? static_cast<size_t>(TAE_END) : SlGetStructListLength(TAE_END);
218 for (size_t i = 0; i < length; i++) {
219 SlObject(&t->received[i], this->GetLoadDescription());
220 }
221 }
222};
223
224 class SlTownAcceptanceMatrix : public DefaultSaveLoadHandler<SlTownAcceptanceMatrix, Town> {
225private:
227 struct AcceptanceMatrix {
228 TileArea area;
229 static const uint GRID = 4;
230 };
231public:
232 static inline const SaveLoad description[] = {
233 SLE_VAR(AcceptanceMatrix, area.tile, SLE_UINT32),
234 SLE_VAR(AcceptanceMatrix, area.w, SLE_UINT16),
235 SLE_VAR(AcceptanceMatrix, area.h, SLE_UINT16),
236 };
237 static inline const SaveLoadCompatTable compat_description = _town_acceptance_matrix_sl_compat;
238
239 void Load(Town *) const override
240 {
241 /* Discard now unused acceptance matrix. */
242 AcceptanceMatrix dummy;
243 SlObject(&dummy, this->GetLoadDescription());
244 if (dummy.area.w != 0) {
245 uint arr_len = dummy.area.w / AcceptanceMatrix::GRID * dummy.area.h / AcceptanceMatrix::GRID;
246 SlSkipBytes(4 * arr_len);
247 }
248 }
249};
250
251static std::array<Town::SuppliedHistory, 2> _old_pass_supplied{};
252static std::array<Town::SuppliedHistory, 2> _old_mail_supplied{};
253
254static const SaveLoad _town_desc[] = {
255 SLE_CONDVAR(Town, xy, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
256 SLE_CONDVAR(Town, xy, SLE_UINT32, SLV_6, SL_MAX_VERSION),
257
258 SLE_CONDVAR(Town, townnamegrfid, SLE_UINT32, SLV_66, SL_MAX_VERSION),
259 SLE_VAR(Town, townnametype, SLE_UINT16),
260 SLE_VAR(Town, townnameparts, SLE_UINT32),
261 SLE_CONDSSTR(Town, name, SLE_STR | SLF_ALLOW_CONTROL, SLV_84, SL_MAX_VERSION),
262
263 SLE_VAR(Town, flags, SLE_UINT8),
264 SLE_CONDVAR(Town, statues, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_104),
265 SLE_CONDVAR(Town, statues, SLE_UINT16, SLV_104, SL_MAX_VERSION),
266
267 SLE_CONDVAR(Town, have_ratings, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_104),
268 SLE_CONDVAR(Town, have_ratings, SLE_UINT16, SLV_104, SL_MAX_VERSION),
269 SLE_CONDARR(Town, ratings, SLE_INT16, 8, SL_MIN_VERSION, SLV_104),
270 SLE_CONDARR(Town, ratings, SLE_INT16, MAX_COMPANIES, SLV_104, SL_MAX_VERSION),
271 SLE_CONDARR(Town, unwanted, SLE_INT8, 8, SLV_4, SLV_104),
272 SLE_CONDARR(Town, unwanted, SLE_INT8, MAX_COMPANIES, SLV_104, SL_MAX_VERSION),
273
274 /* Slots 0 and 2 are passengers and mail respectively for old saves. */
275 SLEG_CONDVAR("supplied[CT_PASSENGERS].old_max", _old_pass_supplied[LAST_MONTH].production, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9),
276 SLEG_CONDVAR("supplied[CT_PASSENGERS].old_max", _old_pass_supplied[LAST_MONTH].production, SLE_UINT32, SLV_9, SLV_165),
277 SLEG_CONDVAR( "supplied[CT_MAIL].old_max", _old_mail_supplied[LAST_MONTH].production, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9),
278 SLEG_CONDVAR( "supplied[CT_MAIL].old_max", _old_mail_supplied[LAST_MONTH].production, SLE_UINT32, SLV_9, SLV_165),
279 SLEG_CONDVAR("supplied[CT_PASSENGERS].new_max", _old_pass_supplied[THIS_MONTH].production, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9),
280 SLEG_CONDVAR("supplied[CT_PASSENGERS].new_max", _old_pass_supplied[THIS_MONTH].production, SLE_UINT32, SLV_9, SLV_165),
281 SLEG_CONDVAR( "supplied[CT_MAIL].new_max", _old_mail_supplied[THIS_MONTH].production, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9),
282 SLEG_CONDVAR( "supplied[CT_MAIL].new_max", _old_mail_supplied[THIS_MONTH].production, SLE_UINT32, SLV_9, SLV_165),
283 SLEG_CONDVAR("supplied[CT_PASSENGERS].old_act", _old_pass_supplied[LAST_MONTH].transported, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9),
284 SLEG_CONDVAR("supplied[CT_PASSENGERS].old_act", _old_pass_supplied[LAST_MONTH].transported, SLE_UINT32, SLV_9, SLV_165),
285 SLEG_CONDVAR( "supplied[CT_MAIL].old_act", _old_mail_supplied[LAST_MONTH].transported, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9),
286 SLEG_CONDVAR( "supplied[CT_MAIL].old_act", _old_mail_supplied[LAST_MONTH].transported, SLE_UINT32, SLV_9, SLV_165),
287 SLEG_CONDVAR("supplied[CT_PASSENGERS].new_act", _old_pass_supplied[THIS_MONTH].transported, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9),
288 SLEG_CONDVAR("supplied[CT_PASSENGERS].new_act", _old_pass_supplied[THIS_MONTH].transported, SLE_UINT32, SLV_9, SLV_165),
289 SLEG_CONDVAR( "supplied[CT_MAIL].new_act", _old_mail_supplied[THIS_MONTH].transported, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_9),
290 SLEG_CONDVAR( "supplied[CT_MAIL].new_act", _old_mail_supplied[THIS_MONTH].transported, SLE_UINT32, SLV_9, SLV_165),
291
292 SLE_CONDVARNAME(Town, received[TAE_FOOD].old_act, "received[TE_FOOD].old_act", SLE_UINT16, SL_MIN_VERSION, SLV_165),
293 SLE_CONDVARNAME(Town, received[TAE_WATER].old_act, "received[TE_WATER].old_act", SLE_UINT16, SL_MIN_VERSION, SLV_165),
294 SLE_CONDVARNAME(Town, received[TAE_FOOD].new_act, "received[TE_FOOD].new_act", SLE_UINT16, SL_MIN_VERSION, SLV_165),
295 SLE_CONDVARNAME(Town, received[TAE_WATER].new_act, "received[TE_WATER].new_act", SLE_UINT16, SL_MIN_VERSION, SLV_165),
296
297 SLE_CONDARR(Town, goal, SLE_UINT32, NUM_TAE, SLV_165, SL_MAX_VERSION),
298
299 SLE_CONDSSTR(Town, text, SLE_STR | SLF_ALLOW_CONTROL, SLV_168, SL_MAX_VERSION),
300
301 SLE_CONDVAR(Town, time_until_rebuild, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_54),
302 SLE_CONDVAR(Town, time_until_rebuild, SLE_UINT16, SLV_54, SL_MAX_VERSION),
303 SLE_CONDVAR(Town, grow_counter, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_54),
304 SLE_CONDVAR(Town, grow_counter, SLE_UINT16, SLV_54, SL_MAX_VERSION),
305 SLE_CONDVAR(Town, growth_rate, SLE_FILE_U8 | SLE_VAR_I16, SL_MIN_VERSION, SLV_54),
306 SLE_CONDVAR(Town, growth_rate, SLE_FILE_I16 | SLE_VAR_U16, SLV_54, SLV_165),
307 SLE_CONDVAR(Town, growth_rate, SLE_UINT16, SLV_165, SL_MAX_VERSION),
308
309 SLE_VAR(Town, fund_buildings_months, SLE_UINT8),
310 SLE_VAR(Town, road_build_months, SLE_UINT8),
311
312 SLE_CONDVAR(Town, exclusivity, SLE_UINT8, SLV_2, SL_MAX_VERSION),
313 SLE_CONDVAR(Town, exclusive_counter, SLE_UINT8, SLV_2, SL_MAX_VERSION),
314
315 SLE_CONDVAR(Town, larger_town, SLE_BOOL, SLV_56, SL_MAX_VERSION),
316 SLE_CONDVAR(Town, layout, SLE_UINT8, SLV_113, SL_MAX_VERSION),
317 SLE_CONDVAR(Town, valid_history, SLE_UINT64, SLV_TOWN_SUPPLY_HISTORY, SL_MAX_VERSION),
318
319 SLE_CONDREFVECTOR(Town, psa_list, REF_STORAGE, SLV_161, SL_MAX_VERSION),
320
321 SLEG_CONDSTRUCTLIST("supplied", SlTownOldSupplied, SLV_165, SLV_TOWN_SUPPLY_HISTORY),
322 SLEG_CONDSTRUCTLIST("supplied", SlTownSupplied, SLV_TOWN_SUPPLY_HISTORY, SL_MAX_VERSION),
323 SLEG_CONDSTRUCTLIST("received", SlTownReceived, SLV_165, SL_MAX_VERSION),
324 SLEG_CONDSTRUCTLIST("acceptance_matrix", SlTownAcceptanceMatrix, SLV_166, SLV_REMOVE_TOWN_CARGO_CACHE),
325};
326
327 struct HIDSChunkHandler : NewGRFMappingChunkHandler {
328 HIDSChunkHandler() : NewGRFMappingChunkHandler('HIDS', _house_mngr) {}
329};
330
331 struct CITYChunkHandler : ChunkHandler {
332 CITYChunkHandler() : ChunkHandler('CITY', CH_TABLE) {}
333
334 void Save() const override
335 {
336 SlTableHeader(_town_desc);
337
338 for (Town *t : Town::Iterate()) {
339 SlSetArrayIndex(t->index);
340 SlObject(t, _town_desc);
341 }
342 }
343
344 void Load() const override
345 {
346 const std::vector<SaveLoad> slt = SlCompatTableHeader(_town_desc, _town_sl_compat);
347
348 int index;
349
350 while ((index = SlIterateArray()) != -1) {
351 Town *t = new (TownID(index)) Town();
352 SlObject(t, slt);
353
354 if (IsSavegameVersionBefore(SLV_165)) {
355 /* Passengers and mail were always treated as slots 0 and 2 in older saves. */
356 auto &pass = t->supplied.emplace_back(0);
357 pass.history[LAST_MONTH] = _old_pass_supplied[LAST_MONTH];
358 pass.history[THIS_MONTH] = _old_pass_supplied[THIS_MONTH];
359 auto &mail = t->supplied.emplace_back(2);
360 mail.history[LAST_MONTH] = _old_mail_supplied[LAST_MONTH];
361 mail.history[THIS_MONTH] = _old_mail_supplied[THIS_MONTH];
362 }
363
364 if (IsSavegameVersionBefore(SLV_TOWN_SUPPLY_HISTORY)) {
365 t->valid_history = 1U << LAST_MONTH;
366 }
367
368 if (t->townnamegrfid == 0 && !IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_END) && GetStringTab(t->townnametype) != TEXT_TAB_OLD_CUSTOM) {
369 SlErrorCorrupt("Invalid town name generator");
370 }
371 }
372 }
373
374 void FixPointers() const override
375 {
376 if (IsSavegameVersionBefore(SLV_161)) return;
377
378 for (Town *t : Town::Iterate()) {
379 SlObject(t, _town_desc);
380 }
381 }
382};
383
384static const HIDSChunkHandler HIDS;
385static const CITYChunkHandler CITY;
386static const ChunkHandlerRef town_chunk_handlers[] = {
387 HIDS,
388 CITY,
389};
390
391extern const ChunkHandlerTable _town_chunk_handlers(town_chunk_handlers);
CargoType
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
NUM_CARGO
static const CargoType NUM_CARGO
Maximum number of cargo types in a game.
Definition cargo_type.h:73
NUM_TAE
@ NUM_TAE
Amount of town effects.
Definition cargotype.h:31
TAE_END
@ TAE_END
End of town effects.
Definition cargotype.h:30
TAE_FOOD
@ TAE_FOOD
Cargo behaves food/fizzy-drinks-like.
Definition cargotype.h:29
TAE_WATER
@ TAE_WATER
Cargo behaves water-like.
Definition cargotype.h:28
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
DefaultSaveLoadHandler
Default handler for saving/loading an object to/from disk.
Definition saveload.h:596
DefaultSaveLoadHandler< SlTownSuppliedHistory, Town::SuppliedCargo >::GetDescription
SaveLoadTable GetDescription() const override
Definition saveload.h:598
OverrideManagerBase::GetSubstituteID
uint16_t GetSubstituteID(uint16_t entity_id) const
Gives the substitute of the entity, as specified by the grf file.
Definition newgrf_commons.cpp:150
SaveLoadHandler::GetLoadDescription
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
Definition saveload.cpp:3444
SlTownAcceptanceMatrix
Definition town_sl.cpp:224
SlTownOldSupplied
Definition town_sl.cpp:117
SlTownOldSupplied::GetNumCargo
size_t GetNumCargo() const
Get the number of cargoes used by this savegame version.
Definition town_sl.cpp:131
SlTownReceived
Definition town_sl.cpp:197
SlTownSuppliedHistory
Definition town_sl.cpp:158
SlTownSupplied
Definition town_sl.cpp:186
SlTownSupplied::GetVector
std::vector< Town::SuppliedCargo > & GetVector(Town *t) const override
Get instance of vector to load/save.
Definition town_sl.cpp:194
VectorSaveLoadHandler
Default handler for saving/loading a vector to/from disk.
Definition saveload.h:1382
NEW_HOUSE_OFFSET
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
Definition house.h:28
HouseID
uint16_t HouseID
OpenTTD ID of house types.
Definition house_type.h:15
TileDiffXY
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition map_func.h:401
IsInsideMM
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition math_func.hpp:267
IncreaseBuildingCount
void IncreaseBuildingCount(Town *t, HouseID house_id)
IncreaseBuildingCount() Increase the count of a building when it has been added by a town.
Definition newgrf_house.cpp:191
InitializeBuildingCounts
void InitializeBuildingCounts()
Initialise global building counts and all town building counts.
Definition newgrf_house.cpp:164
newgrf_sl.h
Code handling saving and loading of NewGRF mappings.
SlCompatTableHeader
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
Definition saveload.cpp:2037
SlGetStructListLength
size_t SlGetStructListLength(size_t limit)
Get the length of this list; if it exceeds the limit, error out.
Definition saveload.cpp:1833
SlIterateArray
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition saveload.cpp:677
SlErrorCorrupt
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
Definition saveload.cpp:369
SlObject
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
Definition saveload.cpp:1846
SlTableHeader
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
Definition saveload.cpp:1899
SlSetStructListLength
void SlSetStructListLength(size_t length)
Set the length of this list.
Definition saveload.cpp:1817
saveload.h
Functions/types related to saving and loading games.
SLEG_STRUCTLIST
#define SLEG_STRUCTLIST(name, handler)
Storage of a list of structs in every savegame version.
Definition saveload.h:1256
SLE_CONDREFVECTOR
#define SLE_CONDREFVECTOR(base, variable, type, from, to)
Storage of a vector of SL_REF elements in some savegame versions.
Definition saveload.h:979
SLEG_CONDVAR
#define SLEG_CONDVAR(name, variable, type, from, to)
Storage of a global variable in some savegame versions.
Definition saveload.h:1124
SLF_ALLOW_CONTROL
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
Definition saveload.h:702
SlSkipBytes
void SlSkipBytes(size_t length)
Read in bytes from the file/data structure but don't do anything with them, discarding them in effect...
Definition saveload.h:1362
ChunkHandlerRef
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
Definition saveload.h:524
REF_STORAGE
@ REF_STORAGE
Load/save a reference to a persistent storage.
Definition saveload.h:624
ChunkHandlerTable
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
Definition saveload.h:527
SLE_CONDARR
#define SLE_CONDARR(base, variable, type, length, from, to)
Storage of a fixed-size array of SL_VAR elements in some savegame versions.
Definition saveload.h:915
SaveLoadCompatTable
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
Definition saveload.h:533
SLE_CONDSSTR
#define SLE_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
Definition saveload.h:948
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition saveload.h:883
IsSavegameVersionBefore
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
Definition saveload.h:1278
SLV_66
@ SLV_66
66 10211
Definition saveload.h:122
SLV_84
@ SLV_84
84 11822
Definition saveload.h:143
SLV_168
@ SLV_168
168 23637
Definition saveload.h:244
SLV_4
@ SLV_4
4.0 1 4.1 122 0.3.3, 0.3.4 4.2 1222 0.3.5 4.3 1417 4.4 1426
Definition saveload.h:37
SLV_6
@ SLV_6
6.0 1721 6.1 1768
Definition saveload.h:46
SLV_EXTEND_CARGOTYPES
@ SLV_EXTEND_CARGOTYPES
199 PR#6802 Extend cargotypes to 64
Definition saveload.h:282
SLV_SAVELOAD_LIST_LENGTH
@ SLV_SAVELOAD_LIST_LENGTH
293 PR#9374 Consistency in list length with SL_STRUCT / SL_STRUCTLIST / SL_DEQUE / SL_REFLIST.
Definition saveload.h:331
SLV_166
@ SLV_166
166 23415
Definition saveload.h:242
SL_MAX_VERSION
@ SL_MAX_VERSION
Highest possible saveload version.
Definition saveload.h:416
SL_MIN_VERSION
@ SL_MIN_VERSION
First savegame version.
Definition saveload.h:31
SLV_104
@ SLV_104
104 14735
Definition saveload.h:167
SLV_165
@ SLV_165
165 23304
Definition saveload.h:241
SLV_2
@ SLV_2
2.0 0.3.0 2.1 0.3.1, 0.3.2
Definition saveload.h:34
SLV_TOWN_SUPPLY_HISTORY
@ SLV_TOWN_SUPPLY_HISTORY
358 PR#14461 Town supply history.
Definition saveload.h:409
SLV_113
@ SLV_113
113 15340
Definition saveload.h:178
SLV_161
@ SLV_161
161 22567
Definition saveload.h:236
SLV_54
@ SLV_54
54 9613
Definition saveload.h:107
SLV_56
@ SLV_56
56 9667
Definition saveload.h:110
SLV_REMOVE_TOWN_CARGO_CACHE
@ SLV_REMOVE_TOWN_CARGO_CACHE
219 PR#8258 Remove town cargo acceptance and production caches.
Definition saveload.h:306
SLV_9
@ SLV_9
9.0 1909
Definition saveload.h:50
SLEG_CONDSTRUCTLIST
#define SLEG_CONDSTRUCTLIST(name, handler, from, to)
Storage of a list of structs in some savegame versions.
Definition saveload.h:1193
SLE_VAR
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition saveload.h:1017
SLE_CONDVARNAME
#define SLE_CONDVARNAME(base, variable, name, type, from, to)
Storage of a variable in some savegame versions.
Definition saveload.h:894
GetStringTab
StringTab GetStringTab(StringID str)
Extract the StringTab from a StringID.
Definition strings_func.h:22
SPECSTR_TOWNNAME_START
static constexpr StringID SPECSTR_TOWNNAME_START
Special strings for town names.
Definition strings_type.h:64
CITYChunkHandler
Definition town_sl.cpp:331
CITYChunkHandler::FixPointers
void FixPointers() const override
Fix the pointers.
Definition town_sl.cpp:374
CITYChunkHandler::Load
void Load() const override
Load the chunk.
Definition town_sl.cpp:344
CITYChunkHandler::Save
void Save() const override
Save the chunk.
Definition town_sl.cpp:334
ChunkHandler
Handlers and description of chunk.
Definition saveload.h:478
HIDSChunkHandler
Definition town_sl.cpp:327
HouseSpec
Definition house.h:98
HouseSpec::Get
static HouseSpec * Get(size_t house_id)
Get the spec for a house ID.
Definition newgrf_house.cpp:70
HouseSpec::building_flags
BuildingFlags building_flags
some flags that describe the house (size, stadium etc...)
Definition house.h:109
HouseSpec::population
uint8_t population
population (Zero on other tiles in multi tile house.)
Definition house.h:102
Map::Iterate
static IterateWrapper Iterate()
Returns an iterable ensemble of all Tiles.
Definition map_func.h:375
NewGRFMappingChunkHandler
Definition newgrf_sl.h:16
OrthogonalTileArea
Represents the covered area of e.g.
Definition tilearea_type.h:18
PoolID< uint16_t, struct TownIDTag, 64000, 0xFFFF >
Pool::PoolItem<&_town_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition pool_type.hpp:436
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
SaveLoad
SaveLoad type struct.
Definition saveload.h:732
SlTownAcceptanceMatrix::AcceptanceMatrix
Compatibility struct with just enough of TileMatrix to facilitate loading.
Definition town_sl.cpp:227
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
TownCache::population
uint32_t population
Current population of people.
Definition town.h:53
TownCache::num_houses
uint32_t num_houses
Amount of houses.
Definition town.h:52
Town::SuppliedCargo
Definition town.h:99
Town::SuppliedHistory
Definition town.h:88
Town
Town data structure.
Definition town.h:63
Town::supplied
SuppliedCargoes supplied
Cargo statistics about supplied cargo.
Definition town.h:109
Town::cache
TownCache cache
Container for all cacheable data.
Definition town.h:66
Town::valid_history
ValidHistoryMask valid_history
Mask of valid history records.
Definition town.h:112
Town::received
std::array< TransportedCargoStat< uint16_t >, NUM_TAE > received
Cargo statistics about received cargotypes.
Definition town.h:110
TransportedCargoStat
Store the maximum and actually transported cargo amount for the current and the last month.
Definition town_type.h:123
TransportedCargoStat::new_max
Tstorage new_max
Maximum amount this month.
Definition town_type.h:125
TransportedCargoStat::old_max
Tstorage old_max
Maximum amount last month.
Definition town_type.h:124
TransportedCargoStat::old_act
Tstorage old_act
Actually transported last month.
Definition town_type.h:126
TransportedCargoStat::new_act
Tstorage new_act
Actually transported this month.
Definition town_type.h:127
IsTileType
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
MP_HOUSE
@ MP_HOUSE
A house by a town.
Definition tile_type.h:51
GetHouseNorthPart
TileIndexDiff GetHouseNorthPart(HouseID &house)
Determines if a given HouseID is part of a multitile house.
Definition town_cmd.cpp:3025
UpdateTownRadius
void UpdateTownRadius(Town *t)
Update the cached town zone radii of a town, based on the number of houses.
Definition town_cmd.cpp:1956
GetHouseType
HouseID GetHouseType(Tile t)
Get the type of this house, which is an index into the house spec array.
Definition town_map.h:60
GetCleanHouseType
HouseID GetCleanHouseType(Tile t)
Get the type of this house, which is an index into the house spec array without doing any NewGRF rela...
Definition town_map.h:48
SetHouseType
void SetHouseType(Tile t, HouseID house_id)
Set the house type.
Definition town_map.h:71
IsHouseCompleted
bool IsHouseCompleted(Tile t)
Get the completion of this house.
Definition town_map.h:167
RebuildTownCaches
void RebuildTownCaches()
Rebuild all the cached variables of towns.
Definition town_sl.cpp:28
UpdateHousesAndTowns
void UpdateHousesAndTowns()
Check and update town and house values.
Definition town_sl.cpp:65
town_sl_compat.h
Loading of town chunks before table headers were added.
_town_supplied_sl_compat
const SaveLoadCompat _town_supplied_sl_compat[]
Original field order for SlTownSupplied.
Definition town_sl_compat.h:16
_town_received_sl_compat
const SaveLoadCompat _town_received_sl_compat[]
Original field order for SlTownReceived.
Definition town_sl_compat.h:24
_town_sl_compat
const SaveLoadCompat _town_sl_compat[]
Original field order for town_desc.
Definition town_sl_compat.h:39
_town_acceptance_matrix_sl_compat
const SaveLoadCompat _town_acceptance_matrix_sl_compat[]
Original field order for SlTownAcceptanceMatrix.
Definition town_sl_compat.h:32