35 town->cache.population = 0;
36 town->cache.num_houses = 0;
43 Town *town = Town::GetByTile(t);
74 house_id = _house_mngr.GetSubstituteID(house_id);
85 if (t == north_tile) {
87 bool valid_house =
true;
105 if (!valid_house) DoClearSquare(t);
119 static inline const SaveLoad description[] = {
142 for (
size_t i = 0; i < num_cargo; 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;
160 static inline const SaveLoad description[] = {
170 for (
auto &h : p->history) {
179 for (
auto &h : p->history) {
180 if (--len > p->history.size())
break;
188 inline static const SaveLoad description[] = {
221 if (--len > p->
history.size())
break;
243 static inline const SaveLoad description[] = {
254 for (
auto &received : t->
received) {
262 for (
size_t i = 0; i < length; i++) {
273 static const uint GRID = 4;
276 static inline const SaveLoad description[] = {
288 if (dummy.area.
w != 0) {
289 uint arr_len = dummy.area.
w / AcceptanceMatrix::GRID * dummy.area.
h / AcceptanceMatrix::GRID;
295static std::array<Town::SuppliedHistory, 2> _old_pass_supplied{};
296static std::array<Town::SuppliedHistory, 2> _old_mail_supplied{};
298static const SaveLoad _town_desc[] = {
320 SLEG_CONDVAR(
"supplied[CT_PASSENGERS].old_max", _old_pass_supplied[LAST_MONTH].production, SLE_UINT32,
SLV_9,
SLV_165),
324 SLEG_CONDVAR(
"supplied[CT_PASSENGERS].new_max", _old_pass_supplied[THIS_MONTH].production, SLE_UINT32,
SLV_9,
SLV_165),
328 SLEG_CONDVAR(
"supplied[CT_PASSENGERS].old_act", _old_pass_supplied[LAST_MONTH].transported, SLE_UINT32,
SLV_9,
SLV_165),
332 SLEG_CONDVAR(
"supplied[CT_PASSENGERS].new_act", _old_pass_supplied[THIS_MONTH].transported, SLE_UINT32,
SLV_9,
SLV_165),
372struct HIDSChunkHandler : NewGRFMappingChunkHandler {
373 HIDSChunkHandler() : NewGRFMappingChunkHandler(
'HIDS', _house_mngr) {}
376struct CITYChunkHandler : ChunkHandler {
377 CITYChunkHandler() : ChunkHandler(
'CITY', CH_TABLE) {}
384 SlSetArrayIndex(t->index);
401 auto &pass = t->
supplied.emplace_back(0);
402 pass.history[LAST_MONTH] = _old_pass_supplied[LAST_MONTH];
403 pass.history[THIS_MONTH] = _old_pass_supplied[THIS_MONTH];
404 auto &mail = t->
supplied.emplace_back(2);
405 mail.history[LAST_MONTH] = _old_mail_supplied[LAST_MONTH];
406 mail.history[THIS_MONTH] = _old_mail_supplied[THIS_MONTH];
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
static const CargoType NUM_CARGO
Maximum number of cargo types in a game.
@ NUM_TAE
Amount of town effects.
@ TAE_END
End of town effects.
@ TAE_FOOD
Cargo behaves food/fizzy-drinks-like.
@ TAE_WATER
Cargo behaves water-like.
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.
SaveLoadTable GetDescription() const override
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
void Load(Town *) const override
Load the object from disk.
Saveload handler for town accepted cargo history entries.
void Load(Town::AcceptedCargo *p) const override
Load the object from disk.
void Save(Town::AcceptedCargo *p) const override
Save the object to disk.
static const SaveLoadCompatTable compat_description
Compatibility saveload description for handler.
static const SaveLoad description[]
Saveload description for handler.
Saveload handler for town accepted cargo history.
static const SaveLoadCompatTable compat_description
Compatibility saveload description for handler.
static const SaveLoad description[]
Saveload description for handler.
std::vector< Town::AcceptedCargo > & GetVector(Town *t) const override
Get instance of vector to load/save.
size_t GetNumCargo() const
Get the number of cargoes used by this savegame version.
void Load(Town *t) const override
Load the object from disk.
void Save(Town *t) const override
Save the object to disk.
void Load(Town *t) const override
Load the object from disk.
void Load(Town::SuppliedCargo *p) const override
Load the object from disk.
void Save(Town::SuppliedCargo *p) const override
Save the object to disk.
std::vector< Town::SuppliedCargo > & GetVector(Town *t) const override
Get instance of vector to load/save.
Default handler for saving/loading a vector to/from disk.
Functions for storing historical data.
@ Size2x2
The building is 2x2 tiles.
@ Size2x1
The building is 2x1 tiles, i.e. wider on the X-axis.
@ Size1x2
The building is 1x2 tiles, i.e. wider on the Y-axis.
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
uint16_t HouseID
OpenTTD ID of house types.
Functions related to OTTD's landscape.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
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.
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
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 SLEG_STRUCTLIST(name, handler)
Storage of a list of structs in every savegame version.
#define SLE_CONDREFVECTOR(base, variable, type, from, to)
Storage of a vector of SL_REF elements in some savegame versions.
#define SLEG_CONDVAR(name, variable, type, from, to)
Storage of a global variable in some savegame versions.
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
void SlSkipBytes(size_t length)
Read in bytes from the file/data structure but don't do anything with them, discarding them in effect...
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
@ REF_STORAGE
Load/save a reference to a persistent storage.
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
#define SLE_CONDARR(base, variable, type, length, from, to)
Storage of a fixed-size array of SL_VAR elements in some savegame versions.
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
#define SLE_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
@ 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
@ SLV_EXTEND_CARGOTYPES
199 PR#6802 Extend cargotypes to 64
@ SLV_SAVELOAD_LIST_LENGTH
293 PR#9374 Consistency in list length with SL_STRUCT / SL_STRUCTLIST / SL_DEQUE / SL_REFLIST.
@ SL_MAX_VERSION
Highest possible saveload version.
@ SL_MIN_VERSION
First savegame version.
@ SLV_2
2.0 0.3.0 2.1 0.3.1, 0.3.2
@ SLV_TOWN_SUPPLY_HISTORY
358 PR#14461 Town supply history.
@ SLV_REMOVE_TOWN_CARGO_CACHE
219 PR#8258 Remove town cargo acceptance and production caches.
#define SLEG_CONDSTRUCTLIST(name, handler, from, to)
Storage of a list of structs in some savegame versions.
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
#define SLE_CONDVARNAME(base, variable, name, type, from, to)
Storage of a variable in some savegame versions.
Definition of base types and functions in a cross-platform compatible way.
Functions related to OTTD's strings.
StringTab GetStringTab(StringID str)
Extract the StringTab from a StringID.
static constexpr StringID SPECSTR_TOWNNAME_START
Special strings for town names.
void FixPointers() const override
Fix the pointers.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
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...)
uint8_t population
population (Zero on other tiles in multi tile house.)
static IterateWrapper Iterate()
Returns an iterable ensemble of all Tiles.
uint16_t w
The width of the area.
uint16_t h
The height of the area.
static Pool::IterateWrapper< Town > Iterate(size_t from=0)
static T * CreateAtIndex(TownID index, Targs &&... args)
Compatibility struct with just enough of TileMatrix to facilitate loading.
uint32_t population
Current population of people.
uint32_t num_houses
Amount of houses.
Storage for accepted cargo history.
HistoryData< AcceptedHistory > history
Histor data of accepted cargo.
Individual data point for accepted cargo history.
SuppliedCargoes supplied
Cargo statistics about supplied cargo.
TownCache cache
Container for all cacheable data.
ValidHistoryMask valid_history
Mask of valid history records.
AcceptedCargoes accepted
Cargo statistics about accepted cargo.
uint32_t townnamegrfid
Custom town name. If empty, the town was not renamed and uses the generated name.
uint16_t townnametype
Custom town name. If empty, the town was not renamed and uses the generated name.
std::array< TransportedCargoStat< uint16_t >, NUM_TAE > received
Cargo statistics about received cargotypes.
Store the maximum and actually transported cargo amount for the current and the last month.
Tstorage new_max
Maximum amount this month.
Tstorage old_max
Maximum amount last month.
Tstorage old_act
Actually transported last month.
Tstorage new_act
Actually transported this month.
Functions related to subsidies.
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
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.
@ House
A house by a town.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
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.
HouseID GetCleanHouseType(Tile t)
Get the type of this house, which is an index into the house spec array without doing any NewGRF rela...
void SetHouseType(Tile t, HouseID house_id)
Set the house type.
bool IsHouseCompleted(Tile t)
Get the completion of this house.
void RebuildTownCaches()
Rebuild all the cached variables of towns.
void UpdateHousesAndTowns()
Check and update town and house values.
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.