OpenTTD Source 20261112-master-gbcbec5e63f
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
9
10#include "../stdafx.h"
11
12#include "saveload.h"
13#include "saveload_error.hpp"
15
16#include "newgrf_sl.h"
17#include "../newgrf_house.h"
18#include "../town.h"
19#include "../landscape.h"
20#include "../strings_func.h"
21
22#include "../safeguards.h"
23
28{
30 RebuildTownKdtree();
31
32 /* Reset town population and num_houses */
33 for (Town *town : Town::Iterate()) {
34 town->cache.population = 0;
35 town->cache.num_houses = 0;
36 }
37
38 for (const auto t : Map::Iterate()) {
39 if (!IsTileType(t, TileType::House)) continue;
40
41 HouseID house_id = GetHouseType(t);
42 Town *town = Town::GetByTile(t);
43 IncreaseBuildingCount(town, house_id);
44 if (IsHouseCompleted(t)) town->cache.population += HouseSpec::Get(house_id)->population;
45
46 /* Increase the number of houses for every house, but only once. */
47 if (GetHouseNorthPart(house_id) == TileDiffXY(0, 0)) town->cache.num_houses++;
48 }
49
50 /* Update the population and num_house dependent values */
51 for (Town *town : Town::Iterate()) {
52 UpdateTownRadius(town);
53 }
54}
55
65{
66 for (const auto t : Map::Iterate()) {
67 if (!IsTileType(t, TileType::House)) continue;
68
69 HouseID house_id = GetCleanHouseType(t);
70 if (!HouseSpec::Get(house_id)->enabled && house_id >= NEW_HOUSE_OFFSET) {
71 /* The specs for this type of house are not available any more, so
72 * replace it with the substitute original house type. */
73 house_id = _house_mngr.GetSubstituteID(house_id);
74 SetHouseType(t, house_id);
75 }
76 }
77
78 /* Check for cases when a NewGRF has set a wrong house substitute type. */
79 for (const TileIndex &t : Map::Iterate()) {
80 if (!IsTileType(t, TileType::House)) continue;
81
82 HouseID house_type = GetCleanHouseType(t);
83 TileIndex north_tile = t + GetHouseNorthPart(house_type); // modifies 'house_type'!
84 if (t == north_tile) {
85 const HouseSpec *hs = HouseSpec::Get(house_type);
86 bool valid_house = true;
88 TileIndex tile = t + TileDiffXY(1, 0);
89 if (!IsTileType(tile, TileType::House) || GetCleanHouseType(tile) != house_type + 1) valid_house = false;
91 TileIndex tile = t + TileDiffXY(0, 1);
92 if (!IsTileType(tile, TileType::House) || GetCleanHouseType(tile) != house_type + 1) valid_house = false;
94 TileIndex tile = t + TileDiffXY(0, 1);
95 if (!IsTileType(tile, TileType::House) || GetCleanHouseType(tile) != house_type + 1) valid_house = false;
96 tile = t + TileDiffXY(1, 0);
97 if (!IsTileType(tile, TileType::House) || GetCleanHouseType(tile) != house_type + 2) valid_house = false;
98 tile = t + TileDiffXY(1, 1);
99 if (!IsTileType(tile, TileType::House) || GetCleanHouseType(tile) != house_type + 3) valid_house = false;
100 }
101 /* If not all tiles of this house are present remove the house.
102 * The other tiles will get removed later in this loop because
103 * their north tile is not the correct type anymore. */
104 if (!valid_house) DoClearSquare(t);
105 } else if (!IsTileType(north_tile, TileType::House) || GetCleanHouseType(north_tile) != house_type) {
106 /* This tile should be part of a multi-tile building but the
107 * north tile of this house isn't on the map. */
108 DoClearSquare(t);
109 }
110 }
111
113}
114
115
116class SlTownOldSupplied : public DefaultSaveLoadHandler<SlTownOldSupplied, Town> {
117public:
118 static inline const SaveLoad description[] = {
123 };
124 static inline const SaveLoadCompatTable compat_description = _town_supplied_sl_compat;
125
130 size_t GetNumCargo() const
131 {
134 /* Read from the savegame how long the list is. */
136 }
137
138 void Load(Town *t) const override
139 {
140 size_t num_cargo = this->GetNumCargo();
141 for (size_t i = 0; i < num_cargo; i++) {
143 SlObject(&cargo_stat, this->GetLoadDescription());
144
145 /* Ignore empty statistics. */
146 if (cargo_stat.new_act == 0 && cargo_stat.new_max == 0 && cargo_stat.old_act == 0 && cargo_stat.old_max == 0) continue;
147
148 auto &s = t->supplied.emplace_back(static_cast<CargoType>(i));
149 s.history[LAST_MONTH].production = cargo_stat.old_max;
150 s.history[LAST_MONTH].transported = cargo_stat.old_act;
151 s.history[THIS_MONTH].production = cargo_stat.new_max;
152 s.history[THIS_MONTH].transported = cargo_stat.new_act;
153 }
154 }
155};
156
157class SlTownSuppliedHistory : public DefaultSaveLoadHandler<SlTownSuppliedHistory, Town::SuppliedCargo> {
158public:
159 static inline const SaveLoad description[] = {
162 };
163 static inline const SaveLoadCompatTable compat_description = {};
164
165 void Save(Town::SuppliedCargo *p) const override
166 {
167 SlSetStructListLength(p->history.size());
168
169 for (auto &h : p->history) {
170 SlObject(&h, this->GetDescription());
171 }
172 }
173
174 void Load(Town::SuppliedCargo *p) const override
175 {
176 size_t len = SlGetStructListLength(p->history.size());
177
178 for (auto &h : p->history) {
179 if (--len > p->history.size()) break; // unsigned so wraps after hitting zero.
180 SlObject(&h, this->GetLoadDescription());
181 }
182 }
183};
184
185class SlTownSupplied : public VectorSaveLoadHandler<SlTownSupplied, Town, Town::SuppliedCargo> {
186public:
187 static inline const SaveLoad description[] = {
190 };
191 inline const static SaveLoadCompatTable compat_description = {};
192
193 std::vector<Town::SuppliedCargo> &GetVector(Town *t) const override { return t->supplied; }
194};
195
197class SlTownAcceptedHistory : public DefaultSaveLoadHandler<SlTownAcceptedHistory, Town::AcceptedCargo> {
198public:
200 static inline const SaveLoad description[] = {
202 };
203
204 static inline const SaveLoadCompatTable compat_description = {};
205
206 void Save(Town::AcceptedCargo *p) const override
207 {
209
210 for (auto &h : p->history) {
211 SlObject(&h, this->GetDescription());
212 }
213 }
214
215 void Load(Town::AcceptedCargo *p) const override
216 {
217 size_t len = SlGetStructListLength(p->history.size());
218
219 for (auto &h : p->history) {
220 if (--len > p->history.size()) break; // unsigned so wraps after hitting zero.
221 SlObject(&h, this->GetLoadDescription());
222 }
223 }
224};
225
227class SlTownAccepted : public VectorSaveLoadHandler<SlTownAccepted, Town, Town::AcceptedCargo> {
228public:
234
235 inline const static SaveLoadCompatTable compat_description = {};
236
237 std::vector<Town::AcceptedCargo> &GetVector(Town *t) const override { return t->accepted; }
238};
239
240class SlTownReceived : public DefaultSaveLoadHandler<SlTownReceived, Town> {
241public:
242 static inline const SaveLoad description[] = {
247 };
248 static inline const SaveLoadCompatTable compat_description = _town_received_sl_compat;
249
250 void Save(Town *t) const override
251 {
252 SlSetStructListLength(std::size(t->received));
253 for (auto &received : t->received) {
254 SlObject(&received, this->GetDescription());
255 }
256 }
257
258 void Load(Town *t) const override
259 {
261 for (size_t i = 0; i < length; i++) {
262 SlObject(&t->received[static_cast<TownAcceptanceEffect>(i)], this->GetLoadDescription());
263 }
264 }
265};
266
267class SlTownAcceptanceMatrix : public DefaultSaveLoadHandler<SlTownAcceptanceMatrix, Town> {
268private:
271 TileArea area;
272 static const uint GRID = 4;
273 };
274public:
275 static inline const SaveLoad description[] = {
279 };
280 static inline const SaveLoadCompatTable compat_description = _town_acceptance_matrix_sl_compat;
281
282 void Load(Town *) const override
283 {
284 /* Discard now unused acceptance matrix. */
285 AcceptanceMatrix dummy;
286 SlObject(&dummy, this->GetLoadDescription());
287 if (dummy.area.w != 0) {
288 uint arr_len = dummy.area.w / AcceptanceMatrix::GRID * dummy.area.h / AcceptanceMatrix::GRID;
289 SlSkipBytes(4 * arr_len);
290 }
291 }
292};
293
294static std::array<Town::SuppliedHistory, 2> _old_pass_supplied{};
295static std::array<Town::SuppliedHistory, 2> _old_mail_supplied{};
296
297static const SaveLoad _town_desc[] = {
300
302 SaveLoad::Variable<VarFileType::U16>("townnametype", SLE_OBJECT_ADDRESS(Town, townnametype)),
303 SaveLoad::Variable<VarFileType::U32>("townnameparts", SLE_OBJECT_ADDRESS(Town, townnameparts)),
305
309
316
317 /* Slots 0 and 2 are passengers and mail respectively for old saves. */
318 SaveLoad::Variable<VarFileType::U16>("supplied[CT_PASSENGERS].old_max", SLE_GLOBAL_ADDRESS(_old_pass_supplied[LAST_MONTH].production), SaveLoadVersion::MinVersion, SaveLoadVersion::LargerTownCargoStatistics),
319 SaveLoad::Variable<VarFileType::U32>("supplied[CT_PASSENGERS].old_max", SLE_GLOBAL_ADDRESS(_old_pass_supplied[LAST_MONTH].production), SaveLoadVersion::LargerTownCargoStatistics, SaveLoadVersion::ScriptTownGrowth),
320 SaveLoad::Variable<VarFileType::U16>("supplied[CT_MAIL].old_max", SLE_GLOBAL_ADDRESS(_old_mail_supplied[LAST_MONTH].production), SaveLoadVersion::MinVersion, SaveLoadVersion::LargerTownCargoStatistics),
322 SaveLoad::Variable<VarFileType::U16>("supplied[CT_PASSENGERS].new_max", SLE_GLOBAL_ADDRESS(_old_pass_supplied[THIS_MONTH].production), SaveLoadVersion::MinVersion, SaveLoadVersion::LargerTownCargoStatistics),
323 SaveLoad::Variable<VarFileType::U32>("supplied[CT_PASSENGERS].new_max", SLE_GLOBAL_ADDRESS(_old_pass_supplied[THIS_MONTH].production), SaveLoadVersion::LargerTownCargoStatistics, SaveLoadVersion::ScriptTownGrowth),
324 SaveLoad::Variable<VarFileType::U16>("supplied[CT_MAIL].new_max", SLE_GLOBAL_ADDRESS(_old_mail_supplied[THIS_MONTH].production), SaveLoadVersion::MinVersion, SaveLoadVersion::LargerTownCargoStatistics),
326 SaveLoad::Variable<VarFileType::U16>("supplied[CT_PASSENGERS].old_act", SLE_GLOBAL_ADDRESS(_old_pass_supplied[LAST_MONTH].transported), SaveLoadVersion::MinVersion, SaveLoadVersion::LargerTownCargoStatistics),
327 SaveLoad::Variable<VarFileType::U32>("supplied[CT_PASSENGERS].old_act", SLE_GLOBAL_ADDRESS(_old_pass_supplied[LAST_MONTH].transported), SaveLoadVersion::LargerTownCargoStatistics, SaveLoadVersion::ScriptTownGrowth),
328 SaveLoad::Variable<VarFileType::U16>("supplied[CT_MAIL].old_act", SLE_GLOBAL_ADDRESS(_old_mail_supplied[LAST_MONTH].transported), SaveLoadVersion::MinVersion, SaveLoadVersion::LargerTownCargoStatistics),
330 SaveLoad::Variable<VarFileType::U16>("supplied[CT_PASSENGERS].new_act", SLE_GLOBAL_ADDRESS(_old_pass_supplied[THIS_MONTH].transported), SaveLoadVersion::MinVersion, SaveLoadVersion::LargerTownCargoStatistics),
331 SaveLoad::Variable<VarFileType::U32>("supplied[CT_PASSENGERS].new_act", SLE_GLOBAL_ADDRESS(_old_pass_supplied[THIS_MONTH].transported), SaveLoadVersion::LargerTownCargoStatistics, SaveLoadVersion::ScriptTownGrowth),
332 SaveLoad::Variable<VarFileType::U16>("supplied[CT_MAIL].new_act", SLE_GLOBAL_ADDRESS(_old_mail_supplied[THIS_MONTH].transported), SaveLoadVersion::MinVersion, SaveLoadVersion::LargerTownCargoStatistics),
334
339
341
343
351
352 SaveLoad::Variable<VarFileType::U8>("fund_buildings_months", SLE_OBJECT_ADDRESS(Town, fund_buildings_months)),
353 SaveLoad::Variable<VarFileType::U8>("road_build_months", SLE_OBJECT_ADDRESS(Town, road_build_months)),
354
357
361
363
369};
370
371struct HIDSChunkHandler : NewGRFMappingChunkHandler {
372 HIDSChunkHandler() : NewGRFMappingChunkHandler("HIDS", _house_mngr) {}
373};
374
375struct CITYChunkHandler : ChunkHandler {
376 CITYChunkHandler() : ChunkHandler("CITY", ChunkType::Table) {}
377
378 void Save() const override
379 {
380 SlTableHeader(_town_desc);
381
382 for (Town *t : Town::Iterate()) {
383 SlSetArrayIndex(t->index);
384 SlObject(t, _town_desc);
385 }
386 }
387
388 void Load() const override
389 {
390 const std::vector<SaveLoad> slt = SlCompatTableHeader(_town_desc, _town_sl_compat);
391
392 int index;
393
394 while ((index = SlIterateArray()) != -1) {
395 Town *t = Town::CreateAtIndex(TownID(index));
396 SlObject(t, slt);
397
399 /* Passengers and mail were always treated as slots 0 and 2 in older saves. */
400 auto &pass = t->supplied.emplace_back(CargoType{0});
401 pass.history[LAST_MONTH] = _old_pass_supplied[LAST_MONTH];
402 pass.history[THIS_MONTH] = _old_pass_supplied[THIS_MONTH];
403 auto &mail = t->supplied.emplace_back(CargoType{2});
404 mail.history[LAST_MONTH] = _old_mail_supplied[LAST_MONTH];
405 mail.history[THIS_MONTH] = _old_mail_supplied[THIS_MONTH];
406 }
407
409 t->valid_history = 1U << LAST_MONTH;
410 }
411
412 if (t->townnamegrfid.Empty() && !IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_END) && GetStringTab(static_cast<StringID>(t->townnametype)) != TEXT_TAB_OLD_CUSTOM) {
413 SlErrorCorrupt("Invalid town name generator");
414 }
415 }
416 }
417
418 void FixPointers() const override
419 {
421
422 for (Town *t : Town::Iterate()) {
423 SlObject(t, _town_desc);
424 }
425 }
426};
427
428static const HIDSChunkHandler HIDS;
429static const CITYChunkHandler CITY;
430static const ChunkHandlerRef town_chunk_handlers[] = {
431 HIDS,
432 CITY,
433};
434
435extern const ChunkHandlerTable _town_chunk_handlers(town_chunk_handlers);
static constexpr CargoType NUM_CARGO
Maximum number of cargo types in a game.
Definition cargo_type.h:77
CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:22
TownAcceptanceEffect
Town growth effect when delivering cargo.
Definition cargotype.h:21
@ Food
Cargo behaves food/fizzy-drinks-like.
Definition cargotype.h:28
@ Water
Cargo behaves water-like.
Definition cargotype.h:27
@ End
End of town effects.
Definition cargotype.h:29
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Default handler for saving/loading an object to/from disk.
Definition saveload.h:585
uint16_t w
The width of the area.
uint16_t h
The height of the area.
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
void Load(Town *) const override
Load the object from disk.
Definition town_sl.cpp:282
Saveload handler for town accepted cargo history entries.
Definition town_sl.cpp:197
void Load(Town::AcceptedCargo *p) const override
Load the object from disk.
Definition town_sl.cpp:215
void Save(Town::AcceptedCargo *p) const override
Save the object to disk.
Definition town_sl.cpp:206
static const SaveLoadCompatTable compat_description
Compatibility saveload description for handler.
Definition town_sl.cpp:204
static const SaveLoad description[]
Saveload description for handler.
Definition town_sl.cpp:200
Saveload handler for town accepted cargo history.
Definition town_sl.cpp:227
static const SaveLoadCompatTable compat_description
Compatibility saveload description for handler.
Definition town_sl.cpp:235
static const SaveLoad description[]
Saveload description for handler.
Definition town_sl.cpp:230
std::vector< Town::AcceptedCargo > & GetVector(Town *t) const override
Get instance of vector to load/save.
Definition town_sl.cpp:237
size_t GetNumCargo() const
Get the number of cargoes used by this savegame version.
Definition town_sl.cpp:130
void Load(Town *t) const override
Load the object from disk.
Definition town_sl.cpp:138
void Save(Town *t) const override
Save the object to disk.
Definition town_sl.cpp:250
void Load(Town *t) const override
Load the object from disk.
Definition town_sl.cpp:258
void Load(Town::SuppliedCargo *p) const override
Load the object from disk.
Definition town_sl.cpp:174
void Save(Town::SuppliedCargo *p) const override
Save the object to disk.
Definition town_sl.cpp:165
std::vector< Town::SuppliedCargo > & GetVector(Town *t) const override
Get instance of vector to load/save.
Definition town_sl.cpp:193
Default handler for saving/loading a vector to/from disk.
Definition saveload.h:1340
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:21
@ Size2x2
The building is 2x2 tiles.
Definition house.h:43
@ Size2x1
The building is 2x1 tiles, i.e. wider on the X-axis.
Definition house.h:41
@ Size1x2
The building is 1x2 tiles, i.e. wider on the Y-axis.
Definition house.h:42
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
Definition house.h:28
uint16_t HouseID
OpenTTD ID of house types.
Definition house_type.h:15
Functions related to OTTD's landscape.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
Definition map_func.h:392
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
void IncreaseBuildingCount(Town *t, HouseID house_id)
IncreaseBuildingCount() Increase the count of a building when it has been added by a town.
void InitializeBuildingCounts()
Initialise global building counts and all town building counts.
Functions related to NewGRF houses.
Code handling saving and loading of NewGRF mappings.
A number of safeguards to prevent using unsafe methods.
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
size_t SlGetStructListLength(size_t limit)
Get the length of this list; if it exceeds the limit, error out.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition saveload.cpp:748
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
Definition saveload.cpp:372
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
void SlSetStructListLength(size_t length)
Set the length of this list.
Functions/types related to saving and loading games.
#define SLE_OBJECT_ADDRESS(base, variable)
Macro to be able to pass the variable type and construct the SaveLoad::AddressFunction given a base c...
Definition saveload.h:753
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:1323
#define SLE_GLOBAL_ADDRESS(variable)
Macro to be able to pass the variable type and construct the SaveLoad::AddressFunction given a global...
Definition saveload.h:760
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
Definition saveload.h:512
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
Definition saveload.h:515
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
Definition saveload.h:518
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
Definition saveload.h:1225
@ LargerTownCargoStatistics
Saveload version: 9.0, SVN revision: 1909 Increase size of passenger/mail production of this and pre...
Definition saveload.h:56
@ ExtendCargotypes
Saveload version: 199, GitHub pull request: 6802 Extend cargotypes to 64.
Definition saveload.h:287
@ InfrastructureMaintenanceCosts
Saveload version: 166, SVN revision: 23415 Infrastructure can now cost some periodic fee.
Definition saveload.h:248
@ ReplaceCustomNameArray
Saveload version: 84, SVN revision: 11822 Replace single fixed size array of custom names,...
Definition saveload.h:149
@ RoadLayoutPerTown
Saveload version: 113, SVN revision: 15340 Allow for different road layouts for each of the towns.
Definition saveload.h:184
@ VehicleCurrencyStationChanges
Saveload version: 2.0, release: 0.3.0 Adding vehicle state, larger currency size for statistics,...
Definition saveload.h:39
@ TownTolerancePauseMode
Saveload version: 4.0, SVN revision: 1 Town council tolerance and pause mode.
Definition saveload.h:43
@ RemoveTownCargoCache
Saveload version: 219, GitHub pull request: 8258 Remove town cargo acceptance and production caches.
Definition saveload.h:311
@ NewGRFTownNames
Saveload version: 66, SVN revision: 10211 NewGRF provided town names.
Definition saveload.h:128
@ TownGrowthControl
Saveload version: 54, SVN revision: 9613 Give the player control over the town growth.
Definition saveload.h:113
@ MoreCompanies
Saveload version: 104, SVN revision: 14735 Increase maximum number of companies to 15.
Definition saveload.h:173
@ MultipleRoadStops
Saveload version: 6.0, SVN revision: 1721 Multi tile road stops, and some map size related fixes.
Definition saveload.h:52
@ TownSupplyHistory
Saveload version: 358, GitHub pull request: 14461 Town supply history.
Definition saveload.h:414
@ MinVersion
First savegame version.
Definition saveload.h:36
@ SaveloadListLength
Saveload version: 293, GitHub pull request: 9374 Consistency in list length with SaveLoadType::Struc...
Definition saveload.h:336
@ ScriptTownGrowth
Saveload version: 165, SVN revision: 23304 Storage of cargo statistics for use by game scripts.
Definition saveload.h:247
@ PersistentStoragePool
Saveload version: 161, SVN revision: 22567 Store persistent storage in a pool.
Definition saveload.h:242
@ ScriptTownText
Saveload version: 168, SVN revision: 23637 Game scripts can put a text in the town window.
Definition saveload.h:250
@ Cities
Saveload version: 56, SVN revision: 9667 Cities that start bigger and grow faster.
Definition saveload.h:116
@ Table
An Array with a header describing the elements.
Definition saveload.h:449
Functions/types related to errors from savegames.
Definition of base types and functions in a cross-platform compatible way.
@ AllowControlCode
Allow the special control codes.
Definition string_type.h:47
Functions related to OTTD's strings.
StringTab GetStringTab(StringID str)
Extract the StringTab from a StringID.
static constexpr uint16_t SPECSTR_TOWNNAME_START
Special strings for town names.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
constexpr bool Empty() const
Check whether the label is empty.
void FixPointers() const override
Fix the pointers.
Definition town_sl.cpp:418
void Load() const override
Load the chunk.
Definition town_sl.cpp:388
void Save() const override
Save the chunk.
Definition town_sl.cpp:378
ChunkHandler(ChunkId id, ChunkType type)
Create this ChunkHandler.
Definition saveload.h:469
static HouseSpec * Get(size_t house_id)
Get the spec for a house ID.
BuildingFlags building_flags
some flags that describe the house (size, stadium etc...)
Definition house.h:117
uint8_t population
population (Zero on other tiles in multi tile house.)
Definition house.h:110
static IterateWrapper Iterate()
Returns an iterable ensemble of all Tiles.
Definition map_func.h:366
NewGRFMappingChunkHandler(ChunkId id, OverrideManagerBase &mapping)
Create the handler.
Definition newgrf_sl.h:25
static Pool::IterateWrapper< Town > Iterate(size_t from=0)
static T * CreateAtIndex(TownID index, Targs &&... args)
SaveLoad type struct.
Definition saveload.h:763
static SaveLoad StructList(std::string name, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion)
Storage of a list of structs, optionally in some savegame versions.
Definition saveload.h:1102
static SaveLoad Variable(std::string name, AddressFunction< T > address_func, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion, size_t extra=0)
Storage of a variable in some savegame versions.
Definition saveload.h:925
static SaveLoad Array(std::string name, AddressFunction< T > address_func, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion, size_t extra=0)
Storage of an array in some savegame versions.
Definition saveload.h:1025
static SaveLoad ReferenceVector(std::string name, AddressFunction< T > address_func, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion)
Storage of a vector of references to pool elements in some savegame versions.
Definition saveload.h:1148
static SaveLoad String(std::string name, AddressFunction< T > address_func, StringValidationSettings string_validation_settings={}, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion, size_t extra=0)
Storage of a string in some savegame versions.
Definition saveload.h:976
Compatibility struct with just enough of TileMatrix to facilitate loading.
Definition town_sl.cpp:270
uint32_t population
Current population of people.
Definition town.h:54
uint32_t num_houses
Amount of houses.
Definition town.h:53
Storage for accepted cargo history.
Definition town.h:116
HistoryData< AcceptedHistory > history
Histor data of accepted cargo.
Definition town.h:118
Individual data point for accepted cargo history.
Definition town.h:111
Town data structure.
Definition town.h:64
SuppliedCargoes supplied
Cargo statistics about supplied cargo.
Definition town.h:131
GrfID townnamegrfid
NewGRF id that contains the name. O is not used.
Definition town.h:71
TownCache cache
Container for all cacheable data.
Definition town.h:67
ValidHistoryMask valid_history
Mask of valid history records.
Definition town.h:135
EnumIndexArray< TransportedCargoStat< uint16_t >, TownAcceptanceEffect, TownAcceptanceEffect::End > received
Cargo statistics about received cargotypes.
Definition town.h:133
AcceptedCargoes accepted
Cargo statistics about accepted cargo.
Definition town.h:132
uint16_t townnametype
The style of the name.
Definition town.h:72
Store the maximum and actually transported cargo amount for the current and the last month.
Definition town_type.h:120
Tstorage new_max
Maximum amount this month.
Definition town_type.h:122
Tstorage old_max
Maximum amount last month.
Definition town_type.h:121
Tstorage old_act
Actually transported last month.
Definition town_type.h:123
Tstorage new_act
Actually transported this month.
Definition town_type.h:124
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
@ House
A house by a town.
Definition tile_type.h:52
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Base of the town class.
TileIndexDiff GetHouseNorthPart(HouseID &house)
Determines if a given HouseID is part of a multitile house.
void UpdateTownRadius(Town *t)
Update the cached town zone radii of a town, based on the number of houses.
HouseID GetHouseType(Tile t)
Get the type of this house, which is an index into the house spec array.
Definition town_map.h:60
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
void SetHouseType(Tile t, HouseID house_id)
Set the house type.
Definition town_map.h:71
bool IsHouseCompleted(Tile t)
Get the completion of this house.
Definition town_map.h:167
void RebuildTownCaches()
Rebuild all the cached variables of towns.
Definition town_sl.cpp:27
void UpdateHousesAndTowns()
Check and update town and house values.
Definition town_sl.cpp:64
Loading of town chunks before table headers were added.
const SaveLoadCompat _town_supplied_sl_compat[]
Original field order for SlTownSupplied.
const SaveLoadCompat _town_received_sl_compat[]
Original field order for SlTownReceived.
const SaveLoadCompat _town_sl_compat[]
Original field order for town_desc.
const SaveLoadCompat _town_acceptance_matrix_sl_compat[]
Original field order for SlTownAcceptanceMatrix.