OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
10 #include "../stdafx.h"
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;
208 static 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) {
size_t GetNumCargo() const
Get the number of cargoes used by this savegame version.
#define SLEG_CONDSTRUCTLIST(name, handler, from, to)
Storage of a list of structs in some savegame versions.
@ MP_HOUSE
A house by a town.
Default handler for saving/loading an object to/from disk.
HouseID GetCleanHouseType(Tile t)
Get the type of this house, which is an index into the house spec array without doing any NewGRF rela...
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
#define SLE_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
#define SLE_CONDVARNAME(base, variable, name, type, from, to)
Storage of a variable in some savegame versions.
#define SLE_CONDARR(base, variable, type, length, from, to)
Storage of a fixed-size array of SL_VAR elements in some savegame versions.
@ SL_MIN_VERSION
First savegame version.
void UpdateHousesAndTowns()
Check and update town and house values.
Tindex index
Index of this pool item.
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
TileIndexDiff GetHouseNorthPart(HouseID &house)
Determines if a given HouseID is part of a multitile house.
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
void Save() const override
Save the chunk.
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
Handlers and description of chunk.
void UpdateTownRadius(Town *t)
Update the cached town zone radii of a town, based on the number of houses.
void SetHouseType(Tile t, HouseID house_id)
Set the house type.
const SaveLoadCompat _town_acceptance_matrix_sl_compat[]
Original field order for SlTownAcceptanceMatrix.
void RebuildTownCaches()
Rebuild all the cached variables of towns.
Compatibility struct with just enough of TileMatrix to facilitate loading.
TransportedCargoStat< uint32_t > supplied[NUM_CARGO]
Cargo statistics about supplied cargo.
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
BuildingFlags building_flags
some flags that describe the house (size, stadium etc...)
Represents the covered area of e.g.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
@ SLV_SAVELOAD_LIST_LENGTH
293 PR#9374 Consistency in list length with SL_STRUCT / SL_STRUCTLIST / SL_DEQUE / SL_REFLIST.
@ REF_STORAGE
Load/save a reference to a persistent storage.
uint16_t GetSubstituteID(uint16_t entity_id) const
Gives the substitute of the entity, as specified by the grf file.
uint8_t population
population (Zero on other tiles in multi tile house.)
@ SL_MAX_VERSION
Highest possible saveload version.
@ TAE_END
End of town effects.
const SaveLoadCompat _town_supplied_sl_compat[]
Original field order for SlTownSupplied.
HouseID GetHouseType(Tile t)
Get the type of this house, which is an index into the house spec array.
@ 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
void Load() const override
Load the chunk.
void FixPointers() const override
Fix the pointers.
@ NUM_TAE
Amount of town effects.
@ Town
Source/destination is a town.
size_t SlGetStructListLength(size_t limit)
Get the length of this list; if it exceeds the limit, error out.
uint32_t population
Current population of people.
const SaveLoadCompat _town_sl_compat[]
Original field order for town_desc.
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
const SaveLoadCompat _town_received_sl_compat[]
Original field order for SlTownReceived.
static debug_inline uint Size()
Get the size of the map.
void IncreaseBuildingCount(Town *t, HouseID house_id)
IncreaseBuildingCount() Increase the count of a building when it has been added by a town.
static HouseSpec * Get(size_t house_id)
Get the spec for a house ID.
SaveLoadTable GetDescription() const override
@ SLV_2
2.0 0.3.0 2.1 0.3.1, 0.3.2
TownCache cache
Container for all cacheable data.
bool IsHouseCompleted(Tile t)
Get the completion of this house.
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
void SlSkipBytes(size_t length)
Read in bytes from the file/data structure but don't do anything with them, discarding them in effect...
uint16_t HouseID
OpenTTD ID of house types.
#define SLE_CONDREFLIST(base, variable, type, from, to)
Storage of a list of SL_REF elements in some savegame versions.
uint32_t num_houses
Amount of houses.
@ SLV_REMOVE_TOWN_CARGO_CACHE
219 PR#8258 Remove town cargo acceptance and production caches.
@ TAE_WATER
Cargo behaves water-like.
TransportedCargoStat< uint16_t > received[NUM_TAE]
Cargo statistics about received cargotypes.
@ SLV_EXTEND_CARGOTYPES
199 PR#6802 Extend cargotypes to 64
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
@ MAX_COMPANIES
Maximum number of companies.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
StringTab GetStringTab(StringID str)
Extract the StringTab from a StringID.
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
void SlSetStructListLength(size_t length)
Set the length of this list.
void InitializeBuildingCounts(Town *t)
Initialise building counts for a town.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
@ TAE_FOOD
Cargo behaves food/fizzy-drinks-like.