|
OpenTTD Source
14.0-beta3
|
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"
21 #include "../tilematrix_type.hpp"
23 #include "../safeguards.h"
32 InitializeBuildingCounts();
37 town->cache.population = 0;
38 town->cache.num_houses = 0;
45 Town *town = Town::GetByTile(t);
87 if (t == north_tile) {
88 const HouseSpec *hs = HouseSpec::Get(house_type);
89 bool valid_house =
true;
107 if (!valid_house) DoClearSquare(t);
120 inline static const SaveLoad description[] = {
140 void Save(
Town *t)
const override
143 for (
auto &supplied : t->
supplied) {
148 void Load(
Town *t)
const override
151 for (
size_t i = 0; i < num_cargo; i++) {
159 inline static const SaveLoad description[] = {
167 void Save(
Town *t)
const override
170 for (
auto &received : t->
received) {
175 void Load(
Town *t)
const override
178 for (
size_t i = 0; i < length; i++) {
186 inline static const SaveLoad description[] = {
193 void Load(
Town *)
const override
198 if (dummy.
area.
w != 0) {
199 uint arr_len = dummy.
area.
w / AcceptanceMatrix::GRID * dummy.
area.
h / AcceptanceMatrix::GRID;
205 static const SaveLoad _town_desc[] = {
288 SlSetArrayIndex(t->
index);
303 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...
@ TAE_FOOD
Cargo behaves food/fizzy-drinks-like.
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.
A simple matrix that stores one value per N*N square of the map.
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.
TileArea area
Area covered by the matrix.
void SetHouseType(Tile t, HouseID house_id)
Set the house type.
uint16_t h
The height of the area.
const SaveLoadCompat _town_acceptance_matrix_sl_compat[]
Original field order for SlTownAcceptanceMatrix.
void RebuildTownCaches()
Rebuild all the cached variables of towns.
TransportedCargoStat< uint32_t > supplied[NUM_CARGO]
Cargo statistics about supplied cargo.
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
BuildingFlags building_flags
some flags that describe the house (size, stadium etc...)
@ NUM_TAE
Amount of town effects.
TileIndexDiff TileDiffXY(int x, int y)
Calculates an offset for the given coordinate(-offset).
@ MAX_COMPANIES
Maximum number of companies.
@ 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.
@ SL_MAX_VERSION
Highest possible saveload version.
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.
byte population
population (Zero on other tiles in multi tile house.)
@ 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.
SaveLoadTable GetDescription() const override
@ TAE_WATER
Cargo behaves water-like.
@ 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.
uint16_t w
The width of the area.
@ SLV_REMOVE_TOWN_CARGO_CACHE
219 PR#8258 Remove town cargo acceptance and production caches.
@ TAE_END
End of town effects.
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.
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.
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.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.