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[] = {
372struct HIDSChunkHandler : NewGRFMappingChunkHandler {
373 HIDSChunkHandler() : NewGRFMappingChunkHandler(
'HIDS', _house_mngr) {}
376struct CITYChunkHandler : ChunkHandler {
384 SlSetArrayIndex(t->index);
402 pass.history[LAST_MONTH] = _old_pass_supplied[LAST_MONTH];
403 pass.history[THIS_MONTH] = _old_pass_supplied[THIS_MONTH];
405 mail.history[LAST_MONTH] = _old_mail_supplied[LAST_MONTH];
406 mail.history[THIS_MONTH] = _old_mail_supplied[THIS_MONTH];
static constexpr CargoType NUM_CARGO
Maximum number of cargo types in a game.
CargoType
Cargo slots to indicate a cargo type within a game.
TownAcceptanceEffect
Town growth effect when delivering cargo.
@ Food
Cargo behaves food/fizzy-drinks-like.
@ Water
Cargo behaves water-like.
@ End
End of town effects.
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.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
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.
@ I16
A 16 bit signed int.
@ U32
A 32 bit unsigned int.
@ U16
A 16 bit unsigned int.
@ U8
A 8 bit unsigned int.
@ I16
A 16 bit signed int.
@ U16
A 16 bit unsigned int.
#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 SaveLoadType::Reference elements in some savegame versions.
#define SLEG_CONDVAR(name, variable, type, from, to)
Storage of a global variable in some savegame versions.
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.
@ 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 SaveLoadType::Variable 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.
@ LargerTownCargoStatistics
Saveload version: 9.0, SVN revision: 1909 Increase size of passenger/mail production of this and pre...
@ ExtendCargotypes
Saveload version: 199, GitHub pull request: 6802 Extend cargotypes to 64.
@ InfrastructureMaintenanceCosts
Saveload version: 166, SVN revision: 23415 Infrastructure can now cost some periodic fee.
@ ReplaceCustomNameArray
Saveload version: 84, SVN revision: 11822 Replace single fixed size array of custom names,...
@ RoadLayoutPerTown
Saveload version: 113, SVN revision: 15340 Allow for different road layouts for each of the towns.
@ VehicleCurrencyStationChanges
Saveload version: 2.0, release: 0.3.0 Adding vehicle state, larger currency size for statistics,...
@ TownTolerancePauseMode
Saveload version: 4.0, SVN revision: 1 Town council tolerance and pause mode.
@ RemoveTownCargoCache
Saveload version: 219, GitHub pull request: 8258 Remove town cargo acceptance and production caches.
@ NewGRFTownNames
Saveload version: 66, SVN revision: 10211 NewGRF provided town names.
@ TownGrowthControl
Saveload version: 54, SVN revision: 9613 Give the player control over the town growth.
@ MoreCompanies
Saveload version: 104, SVN revision: 14735 Increase maximum number of companies to 15.
@ MultipleRoadStops
Saveload version: 6.0, SVN revision: 1721 Multi tile road stops, and some map size related fixes.
@ TownSupplyHistory
Saveload version: 358, GitHub pull request: 14461 Town supply history.
@ MinVersion
First savegame version.
@ SaveloadListLength
Saveload version: 293, GitHub pull request: 9374 Consistency in list length with SaveLoadType::Struc...
@ MaxVersion
Highest possible saveload version.
@ ScriptTownGrowth
Saveload version: 165, SVN revision: 23304 Storage of cargo statistics for use by game scripts.
@ PersistentStoragePool
Saveload version: 161, SVN revision: 22567 Store persistent storage in a pool.
@ ScriptTownText
Saveload version: 168, SVN revision: 23637 Game scripts can put a text in the town window.
@ Cities
Saveload version: 56, SVN revision: 9667 Cities that start bigger and grow faster.
#define SLEG_CONDSTRUCTLIST(name, handler, from, to)
Storage of a list of structs in some savegame versions.
@ Table
An Array with a header describing the elements.
#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.
@ AllowControlCode
Allow the special control codes.
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.
GrfID townnamegrfid
NewGRF id that contains the name. O is not used.
TownCache cache
Container for all cacheable data.
ValidHistoryMask valid_history
Mask of valid history records.
EnumIndexArray< TransportedCargoStat< uint16_t >, TownAcceptanceEffect, TownAcceptanceEffect::End > received
Cargo statistics about received cargotypes.
AcceptedCargoes accepted
Cargo statistics about accepted cargo.
uint16_t townnametype
The style of the name.
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.
static constexpr VarType U16
Store a 16 bits unsigned int.
static constexpr VarType U8
Store a 8 bits unsigned int.
static constexpr VarType STR
Store string.
static constexpr VarType I16
Store a 16 bits signed int.
static constexpr VarType U64
Store a 64 bits unsigned int.
static constexpr VarType I8
Store a 8 bits signed int.
static constexpr VarType U32
Store a 32 bits unsigned int.
static constexpr VarType BOOL
Store a boolean (as int8).
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.