15#include "../company_func.h"
16#include "../company_manager_face.h"
18#include "../tunnelbridge_map.h"
19#include "../tunnelbridge.h"
20#include "../station_base.h"
21#include "../strings_func.h"
23#include "table/strings.h"
25#include "../safeguards.h"
63 uint lips =
GB(face, 10, 4);
69 lips = lips * 15 / 16;
77 uint nose =
GB(face, 13, 3);
79 nose = (nose * 3 >> 3) * 3 >> 2;
86 uint tie_earring =
GB(face, 24, 4);
109 for (
const auto tile :
Map::Iterate()) {
133 for (RoadTramType rtt : _roadtramtypes) {
134 RoadType rt = GetRoadType(tile, rtt);
149 case STATION_WAYPOINT:
155 case STATION_ROADWAYPOINT: {
157 for (RoadTramType rtt : _roadtramtypes) {
158 RoadType rt = GetRoadType(tile, rtt);
202 if (tile < other_end) {
215 for (RoadTramType rtt : _roadtramtypes) {
216 RoadType rt = GetRoadType(tile, rtt);
244 uint8_t num_build_rec;
249 inline static const SaveLoad description[] = {{}};
256 for (
int i = 0; i != old_ai->num_build_rec; i++) {
261 void LoadCheck(
CompanyOldAI *old_ai)
const override { this->Load(old_ai); }
266 inline static const SaveLoad description[] = {
274 if (!c->
is_ai)
return;
285 inline static const SaveLoad description[] = {
322 inline static const SaveLoad description[] = {
382 inline static const SaveLoad description[] = {
405 for (
int i = 0; i < LS_END; i++) {
406 SlObject(&c->livery[i], this->GetDescription());
415 for (
size_t i = 0; i < num_liveries; i++) {
416 SlObject(&c->livery[i], this->GetLoadDescription());
417 if (update_in_use && i != LS_DEFAULT) {
418 if (c->livery[i].
in_use == 0) {
429 memmove(&c->livery[LS_FREIGHT_WAGON], &c->livery[LS_PASSENGER_WAGON_MONORAIL], (LS_END - LS_FREIGHT_WAGON) *
sizeof(c->livery[0]));
430 c->livery[LS_PASSENGER_WAGON_MONORAIL] = c->livery[LS_MONORAIL];
431 c->livery[LS_PASSENGER_WAGON_MAGLEV] = c->livery[LS_MAGLEV];
436 c->livery[LS_PASSENGER_TRAM] = c->livery[LS_BUS];
437 c->livery[LS_FREIGHT_TRAM] = c->livery[LS_TRUCK];
450 inline static const SaveLoad description[] = {
461static const SaveLoad _company_desc[] = {
527 SlSetArrayIndex(c->index);
551 std::unique_ptr<CompanyProperties> cprops = std::make_unique<CompanyProperties>();
556 if (
GetStringTab(cprops->name_1) == TEXT_TAB_OLD_CUSTOM) {
557 cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
560 if (
GetStringTab(cprops->president_name_1) == TEXT_TAB_OLD_CUSTOM) {
561 cprops->president_name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
565 if (cprops->name.empty() && !
IsInsideMM(cprops->name_1, SPECSTR_COMPANY_NAME_START, SPECSTR_COMPANY_NAME_LAST + 1) &&
566 cprops->name_1 != STR_GAME_SAVELOAD_NOT_AVAILABLE && cprops->name_1 != STR_SV_UNNAMED &&
567 cprops->name_1 != SPECSTR_ANDCO_NAME && cprops->name_1 != SPECSTR_PRESIDENT_NAME &&
568 cprops->name_1 != SPECSTR_SILLY_NAME) {
569 cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr uint CountBits(T value)
Counts the number of set bits in a variable.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
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.
std::vector< std::string > & GetVector(CompanyProperties *cprops) const override
Get instance of vector to load/save.
size_t GetNumLiveries() const
Get the number of liveries used by this savegame version.
SaveLoadTable GetDescription() const override
Get the description of the fields in the savegame.
Default handler for saving/loading a vector to/from disk.
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
GenderEthnicity
The gender/race combinations that we have faces for.
@ GE_WF
A female of Caucasian origin (white)
@ GE_WM
A male of Caucasian origin (white)
@ ETHNICITY_BLACK
This bit set means black, otherwise white.
@ GENDER_FEMALE
This bit set means a female, otherwise male.
void SetCompanyManagerFaceBits(CompanyManagerFace &cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge, uint val)
Sets the company manager's face bits for the given company manager's face variable.
uint ScaleCompanyManagerFaceValue(CompanyManagerFaceVariable cmfv, GenderEthnicity ge, uint val)
Scales a company manager's face bits variable to the correct scope.
void AfterLoadCompanyStats()
Rebuilding of company statistics after loading a savegame.
CompanyManagerFace ConvertFromOldCompanyManagerFace(uint32_t face)
Converts an old company manager's face format to the new company manager's face format.
Loading of company chunks before table headers were added.
const SaveLoadCompat _company_liveries_compat[]
Original field order for SlCompanyLiveries.
const SaveLoadCompat _company_old_ai_compat[]
Original field order for SlCompanyOldAI.
const SaveLoadCompat _company_old_ai_buildrec_compat[]
Original field order for SlCompanyOldAIBuildRec.
const SaveLoadCompat _company_economy_compat[]
Original field order for SlCompanyEconomy.
const SaveLoadCompat _company_sl_compat[]
Original field order for company_desc.
const SaveLoadCompat _company_settings_compat[]
Original field order for SlCompanySettings.
uint32_t CompanyManagerFace
Company manager face bits, info see in company_manager_face.h.
static const uint LOCK_DEPOT_TILE_FACTOR
Multiplier for how many regular tiles a lock counts.
static const uint LEVELCROSSING_TRACKBIT_FACTOR
Multiplier for how many regular track bits a level crossing counts.
static const uint TUNNELBRIDGE_TRACKBIT_FACTOR
Multiplier for how many regular track bits a tunnel/bridge counts.
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
fluid_settings_t * settings
FluidSynth settings handle.
constexpr uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
uint GetPresentSignals(Tile tile)
Get whether the given signals are present (Along/AgainstTrackDir)
static debug_inline bool IsPlainRail(Tile t)
Returns whether this is plain rails, with or without signals.
bool HasSignals(Tile t)
Checks if a rail tile has signals.
static debug_inline bool IsRoadDepot(Tile t)
Return whether a tile is a road depot.
RoadBits GetRoadBits(Tile t, RoadTramType rtt)
Get the present road bits for a specific road type.
Owner GetRoadOwner(Tile t, RoadTramType rtt)
Get the owner of a specific road type.
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
static debug_inline bool IsNormalRoad(Tile t)
Return whether a tile is a normal road.
RoadType
The different roadtypes we support.
@ INVALID_ROADTYPE
flag for invalid roadtype
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.
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
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 SLEG_STRUCT(name, handler)
Storage of a structs in every savegame version.
#define SLEG_CONDSTRUCT(name, handler, from, to)
Storage of a structs in some savegame versions.
#define SLE_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
#define SLE_CONDVECTOR(base, variable, type, from, to)
Storage of a vector of SL_VAR elements 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.
#define SLE_SSTR(base, variable, type)
Storage of a std::string in every savegame version.
@ SLV_16
16.0 2817 16.1 3155
@ 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_GROUP_LIVERIES
205 PR#7108 Livery storage change and group liveries.
@ SLV_COMPANY_ALLOW_LIST_V2
341 PR#12908 Fixed savegame format for saving of list of client keys that are allowed to join this co...
@ SLV_COMPANY_ALLOW_LIST
335 PR#12337 Saving of list of client keys that are allowed to join this company.
@ SLV_MAX_LOAN_FOR_COMPANY
330 PR#11224 Separate max loan for each company.
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
@ REF_ENGINE_RENEWS
Load/save a reference to an engine renewal (autoreplace).
std::span< const struct SaveLoad > SaveLoadTable
A table of SaveLoad entries.
#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.
StationType GetStationType(Tile t)
Get the station type of this tile.
bool IsBuoy(Tile t)
Is tile t a buoy tile?
bool IsStationTileBlocked(Tile t)
Is tile t a blocked tile?
@ FACIL_AIRPORT
Station with an airport.
#define lengthof(array)
Return the length of an fixed size array.
StringTab GetStringTab(StringID str)
Extract the StringTab from a StringID.
Handlers and description of chunk.
Statistics about the economy.
std::array< uint32_t, ROADTYPE_END > road
Count of company owned track bits for each road type.
uint32_t station
Count of company owned station tiles.
uint32_t signal
Count of company owned signals.
std::array< uint32_t, RAILTYPE_END > rail
Count of company owned track bits for each rail type.
uint32_t water
Count of company owned track bits for canals.
Statically loadable part of Company pool item.
NetworkAuthorizedKeys allow_list
Public keys of clients that are allowed to join this company.
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
CompanyEconomyEntry cur_economy
Economic data of the company of this quarter.
Colours colour
Company colour.
uint8_t num_valid_stat_ent
Number of valid statistical entries in old_economy.
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Information about a particular livery.
Colours colour2
Second colour, for vehicles with 2CC support.
Colours colour1
First colour, for all vehicles.
uint8_t in_use
Bit 0 set if this livery should override the default livery first colour, Bit 1 for the second colour...
CompanyPropertiesMap companies
Company information.
Size related data of the map.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
void FixPointers() const override
Fix the pointers.
void LoadCheck(size_t) const override
Load the chunk for game preview.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static Titem * Get(size_t index)
Returns Titem with given index.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
@ MP_ROAD
A tile with road (or tram tracks)
@ MP_STATION
A tile of a station.
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
@ MP_OBJECT
Contains objects such as transmitters and owned land.
bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
TrackBits
Allow incrementing of Track variables.
@ TRANSPORT_RAIL
Transport by train.
@ TRANSPORT_ROAD
Transport by road vehicle.
@ TRANSPORT_WATER
Transport over water.
uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
TransportType GetTunnelBridgeTransportType(Tile t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
TileIndex GetOtherTunnelBridgeEnd(Tile t)
Determines type of the wormhole and returns its other end.
bool IsShipDepot(Tile t)
Is it a water tile with a ship depot on it?
@ WATER_CLASS_CANAL
Canal.
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
uint8_t GetLockPart(Tile t)
Get the part of a lock.
bool IsLock(Tile t)
Is there a lock on a given water tile?
@ LOCK_PART_MIDDLE
Middle part of a lock.