16#include "../newgrf_house.h"
18#include "../landscape.h"
19#include "../subsidy_func.h"
20#include "../strings_func.h"
22#include "../safeguards.h"
34 town->cache.population = 0;
35 town->cache.num_houses = 0;
42 Town *town = Town::GetByTile(t);
84 if (t == north_tile) {
86 bool valid_house =
true;
104 if (!valid_house) DoClearSquare(t);
117 inline static const SaveLoad description[] = {
137 void Save(
Town *t)
const override
140 for (
auto &supplied : t->supplied) {
145 void Load(
Town *t)
const override
148 for (
size_t i = 0; i < num_cargo; i++) {
156 inline static const SaveLoad description[] = {
164 void Save(
Town *t)
const override
167 for (
auto &received : t->
received) {
172 void Load(
Town *t)
const override
175 for (
size_t i = 0; i < length; i++) {
186 static const uint GRID = 4;
189 inline static const SaveLoad description[] = {
196 void Load(
Town *)
const override
199 AcceptanceMatrix dummy;
201 if (dummy.area.w != 0) {
202 uint arr_len = dummy.area.w / AcceptanceMatrix::GRID * dummy.area.h / AcceptanceMatrix::GRID;
208static const SaveLoad _town_desc[] = {
291 SlSetArrayIndex(t->
index);
306 if (t->townnamegrfid == 0 && !
IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1) &&
GetStringTab(t->townnametype) != TEXT_TAB_OLD_CUSTOM) {
static const CargoID 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.
Default handler for saving/loading an object to/from disk.
SaveLoadTable GetDescription() const override
uint16_t GetSubstituteID(uint16_t entity_id) const
Gives the substitute of the entity, as specified by the grf file.
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
size_t GetNumCargo() const
Get the number of cargoes used by this savegame version.
@ MAX_COMPANIES
Maximum number of companies.
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
uint16_t HouseID
OpenTTD ID of house types.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
constexpr bool IsInsideMM(const 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.
Code handling saving and loading of NewGRF mappings.
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 SLE_CONDREFVECTOR(base, variable, type, from, to)
Storage of a vector of SL_REF elements 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.
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_REMOVE_TOWN_CARGO_CACHE
219 PR#8258 Remove town cargo acceptance and production caches.
@ REF_STORAGE
Load/save a reference to a persistent storage.
#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.
StringTab GetStringTab(StringID str)
Extract the StringTab from a StringID.
void FixPointers() const override
Fix the pointers.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
Handlers and description of 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.
Represents the covered area of e.g.
Tindex index
Index of this pool item.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Compatibility struct with just enough of TileMatrix to facilitate loading.
uint32_t population
Current population of people.
uint32_t num_houses
Amount of houses.
TransportedCargoStat< uint32_t > supplied[NUM_CARGO]
Cargo statistics about supplied cargo.
TransportedCargoStat< uint16_t > received[NUM_TAE]
Cargo statistics about received cargotypes.
TownCache cache
Container for all cacheable data.
Store the maximum and actually transported cargo amount for the current and the last month.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
@ MP_HOUSE
A house by a town.
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.