OpenTTD Source 20261129-master-g72a8bdc861
company_sl.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "../stdafx.h"
11
12#include "saveload.h"
13#include "saveload_error.hpp"
14#include "saveload_internal.h"
16
17#include "../company_func.h"
19#include "../fios.h"
20#include "../tunnelbridge_map.h"
21#include "../tunnelbridge.h"
22#include "../station_base.h"
23#include "../strings_func.h"
24
25#include "table/strings.h"
26
27#include "../safeguards.h"
28
36static const FaceVar *FindFaceVar(FaceVars style, FaceVarType type, StringID name)
37{
38 auto it = std::ranges::find_if(style, [type, name](const FaceVar &facevar) { return facevar.type == type && facevar.name == name; });
39 if (it != std::end(style)) return &*it;
40 return nullptr;
41}
42
62{
64
65 if (HasBit(face, 31)) cmf.style += 1;
66 if (HasBit(face, 27) && (HasBit(face, 26) == HasBit(face, 19))) cmf.style += 2;
67
68 const FaceSpec *spec = GetCompanyManagerFaceSpec(cmf.style);
69 FaceVars vars = spec->GetFaceVars();
70
71 cmf.style_label = spec->label;
72
73 if (auto var = FindFaceVar(vars, FaceVarType::Toggle, STR_FACE_GLASSES); var != nullptr) var->SetBits(cmf, GB(face, 28, 3) <= 1);
74 if (auto var = FindFaceVar(vars, FaceVarType::Palette, STR_FACE_EYECOLOUR); var != nullptr) var->SetBits(cmf, ClampU(GB(face, 20, 3), 5, 7) - 5);
75 if (auto var = FindFaceVar(vars, FaceVarType::Sprite, STR_FACE_CHIN); var != nullptr) var->SetBits(cmf, var->ScaleBits(GB(face, 4, 2)));
76 if (auto var = FindFaceVar(vars, FaceVarType::Sprite, STR_FACE_EYEBROWS); var != nullptr) var->SetBits(cmf, var->ScaleBits(GB(face, 6, 4)));
77 if (auto var = FindFaceVar(vars, FaceVarType::Sprite, STR_FACE_HAIR); var != nullptr) var->SetBits(cmf, var->ScaleBits(GB(face, 16, 4)));
78 if (auto var = FindFaceVar(vars, FaceVarType::Sprite, STR_FACE_JACKET); var != nullptr) var->SetBits(cmf, var->ScaleBits(GB(face, 20, 2)));
79 if (auto var = FindFaceVar(vars, FaceVarType::Sprite, STR_FACE_COLLAR); var != nullptr) var->SetBits(cmf, var->ScaleBits(GB(face, 22, 2)));
80 if (auto var = FindFaceVar(vars, FaceVarType::Sprite, STR_FACE_GLASSES); var != nullptr) var->SetBits(cmf, GB(face, 28, 1));
81
82 uint lips = GB(face, 10, 4);
83 if (cmf.style != 1 && cmf.style != 3 && lips < 4) {
84 if (auto var = FindFaceVar(vars, FaceVarType::Toggle, STR_FACE_MOUSTACHE); var != nullptr) var->SetBits(cmf, true);
85 if (auto var = FindFaceVar(vars, FaceVarType::Sprite, STR_FACE_MOUSTACHE); var != nullptr) var->SetBits(cmf, std::max(lips, 1U) - 1);
86 } else {
87 if (auto var = FindFaceVar(vars, FaceVarType::Sprite, STR_FACE_LIPS); var != nullptr) {
88 if (cmf.style == 0 || cmf.style == 2) {
89 lips = lips * 15 / 16;
90 lips -= 3;
91 if (cmf.style == 2 && lips > 8) lips = 0;
92 } else {
93 lips = var->ScaleBits(lips);
94 }
95 var->SetBits(cmf, lips);
96 }
97
98 if (auto var = FindFaceVar(vars, FaceVarType::Sprite, STR_FACE_NOSE); var != nullptr) {
99 uint nose = GB(face, 13, 3);
100 if (cmf.style == 1) {
101 nose = (nose * 3 >> 3) * 3 >> 2; // There is 'hole' in the nose sprites for women
102 } else {
103 nose = var->ScaleBits(nose);
104 }
105 var->SetBits(cmf, nose);
106 }
107 }
108
109 if (auto var = FindFaceVar(vars, FaceVarType::Sprite, STR_FACE_TIE); var != nullptr) {
110 uint tie = GB(face, 24, 4);
111 var->SetBits(cmf, var->ScaleBits(tie / 2));
112 }
113
114 if (auto var = FindFaceVar(vars, FaceVarType::Sprite, STR_FACE_EARRING); var != nullptr) {
115 uint earring = GB(face, 24, 4);
116 if (earring < 3) { // Not all women have an earring
117 if (auto has_earring = FindFaceVar(vars, FaceVarType::Toggle, STR_FACE_EARRING)) {
118 has_earring->SetBits(cmf, true);
119 var->SetBits(cmf, earring);
120 }
121 }
122 }
123
124 return cmf;
125}
126
129{
130 /* Reset infrastructure statistics to zero. */
131 for (Company *c : Company::Iterate()) c->infrastructure = {};
132
133 /* Collect airport count. */
134 for (const Station *st : Station::Iterate()) {
135 if (st->facilities.Test(StationFacility::Airport) && Company::IsValidID(st->owner)) {
136 Company::Get(st->owner)->infrastructure.airport++;
137 }
138 }
139
140 Company *c;
141 for (const auto tile : Map::Iterate()) {
142 switch (GetTileType(tile)) {
145 if (c != nullptr) {
146 uint pieces = 1;
147 if (IsPlainRail(tile)) {
148 TrackBits bits = GetTrackBits(tile);
149 pieces = bits.Count();
150 if (TracksOverlap(bits)) pieces *= pieces;
151 }
152 c->infrastructure.rail[GetRailType(tile)] += pieces;
153
155 }
156 break;
157
158 case TileType::Road: {
159 if (IsLevelCrossing(tile)) {
161 if (c != nullptr) c->infrastructure.rail[GetRailType(tile)] += LEVELCROSSING_TRACKBIT_FACTOR;
162 }
163
164 /* Iterate all present road types as each can have a different owner. */
165 for (RoadTramType rtt : ROADTRAMTYPES_ALL) {
166 RoadType rt = GetRoadType(tile, rtt);
167 if (rt == INVALID_ROADTYPE) continue;
168 c = Company::GetIfValid(IsRoadDepot(tile) ? GetTileOwner(tile) : GetRoadOwner(tile, rtt));
169 /* A level crossings and depots have two road bits. */
170 if (c != nullptr) c->infrastructure.road[rt] += IsNormalRoad(tile) ? GetRoadBits(tile, rtt).Count() : 2;
171 }
172 break;
173 }
174
177 if (c != nullptr && GetStationType(tile) != StationType::Airport && !IsBuoy(tile)) c->infrastructure.station++;
178
179 switch (GetStationType(tile)) {
182 if (c != nullptr && !IsStationTileBlocked(tile)) c->infrastructure.rail[GetRailType(tile)]++;
183 break;
184
185 case StationType::Bus:
188 /* Iterate all present road types as each can have a different owner. */
189 for (RoadTramType rtt : ROADTRAMTYPES_ALL) {
190 RoadType rt = GetRoadType(tile, rtt);
191 if (rt == INVALID_ROADTYPE) continue;
192 c = Company::GetIfValid(GetRoadOwner(tile, rtt));
193 if (c != nullptr) c->infrastructure.road[rt] += 2; // A road stop has two road bits.
194 }
195 break;
196 }
197
200 if (GetWaterClass(tile) == WaterClass::Canal) {
201 if (c != nullptr) c->infrastructure.water++;
202 }
203 break;
204
205 default:
206 break;
207 }
208 break;
209
210 case TileType::Water:
211 if (IsShipDepot(tile) || IsLock(tile)) {
213 if (c != nullptr) {
215 if (IsLock(tile) && GetLockPart(tile) == LockPart::Middle) {
216 /* The middle tile specifies the owner of the lock. */
217 c->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // the middle tile specifies the owner of the
218 break; // do not count the middle tile as canal
219 }
220 }
221 }
222 [[fallthrough]];
223
224 case TileType::Object:
225 if (GetWaterClass(tile) == WaterClass::Canal) {
227 if (c != nullptr) c->infrastructure.water++;
228 }
229 break;
230
232 /* Only count the tunnel/bridge if we're on the northern end tile. */
233 TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
234 if (tile < other_end) {
235 /* Count each tunnel/bridge TUNNELBRIDGE_TRACKBIT_FACTOR times to simulate
236 * the higher structural maintenance needs, and don't forget the end tiles. */
237 uint len = (GetTunnelBridgeLength(tile, other_end) + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
238
239 switch (GetTunnelBridgeTransportType(tile)) {
242 if (c != nullptr) c->infrastructure.rail[GetRailType(tile)] += len;
243 break;
244
245 case TransportType::Road: {
246 /* Iterate all present road types as each can have a different owner. */
247 for (RoadTramType rtt : ROADTRAMTYPES_ALL) {
248 RoadType rt = GetRoadType(tile, rtt);
249 if (rt == INVALID_ROADTYPE) continue;
250 c = Company::GetIfValid(GetRoadOwner(tile, rtt));
251 if (c != nullptr) c->infrastructure.road[rt] += len * 2; // A full diagonal road has two road bits.
252 }
253 break;
254 }
255
258 if (c != nullptr) c->infrastructure.water += len;
259 break;
260
261 default:
262 break;
263 }
264 }
265 break;
266 }
267
268 default:
269 break;
270 }
271 }
272}
273
276 uint8_t num_build_rec;
277};
278
279class SlCompanyOldAIBuildRec : public DefaultSaveLoadHandler<SlCompanyOldAIBuildRec, CompanyOldAI> {
280public:
281 static inline const SaveLoad description[] = {{}};
282 static inline const SaveLoadCompatTable compat_description = _company_old_ai_buildrec_compat;
283
284 SaveLoadTable GetDescription() const override { return {}; }
285
286 void Load(CompanyOldAI *old_ai) const override
287 {
288 for (int i = 0; i != old_ai->num_build_rec; i++) {
289 SlObject(nullptr, this->GetLoadDescription());
290 }
291 }
292
293 void LoadCheck(CompanyOldAI *old_ai) const override { this->Load(old_ai); }
294};
295
296class SlCompanyOldAI : public DefaultSaveLoadHandler<SlCompanyOldAI, CompanyProperties> {
297public:
298 static inline const SaveLoad description[] = {
301 };
302 static inline const SaveLoadCompatTable compat_description = _company_old_ai_compat;
303
304 void Load(CompanyProperties *c) const override
305 {
306 if (!c->is_ai) return;
307
308 CompanyOldAI old_ai;
309 SlObject(&old_ai, this->GetLoadDescription());
310 }
311
312 void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
313};
314
315class SlCompanySettings : public DefaultSaveLoadHandler<SlCompanySettings, CompanyProperties> {
316public:
317 static inline const SaveLoad description[] = {
318 /* Engine renewal settings */
325
326 /* Default vehicle settings */
332 };
333 static inline const SaveLoadCompatTable compat_description = _company_settings_compat;
334
335 void Save(CompanyProperties *c) const override
336 {
337 SlObject(c, this->GetDescription());
338 }
339
340 void Load(CompanyProperties *c) const override
341 {
342 SlObject(c, this->GetLoadDescription());
343 }
344
345 void FixPointers(CompanyProperties *c) const override
346 {
347 SlObject(c, this->GetDescription());
348
350 /* Migrate engine renews for this company. */
351 _old_engine_renew_saveload_pool.TransformItems(c->old_engine_renew_index, [&c](const auto &item) {
352 if (item.group_id == ALL_GROUP) c->all_engine_renew_list.emplace_back(item);
353 if (item.group_id == DEFAULT_GROUP) c->ungrouped_engine_renew_list.emplace_back(item);
354 });
355 /* Sort by from-engine as lookups use binary-search. */
356 std::ranges::sort(c->all_engine_renew_list, std::less{}, &EngineRenew::from);
357 std::ranges::sort(c->ungrouped_engine_renew_list, std::less{}, &EngineRenew::from);
358 }
359 }
360
361 void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
362};
363
364class SlCompanyEconomy : public DefaultSaveLoadHandler<SlCompanyEconomy, CompanyProperties> {
365public:
366 static inline const SaveLoad description[] = {
373
377 SaveLoad::Variable<VarFileType::I32>("performance_history", SLE_OBJECT_ADDRESS(CompanyEconomyEntry, performance_history)),
378 };
379 static inline const SaveLoadCompatTable compat_description = _company_economy_compat;
380
381 void Save(CompanyProperties *c) const override
382 {
383 SlObject(&c->cur_economy, this->GetDescription());
384 }
385
386 void Load(CompanyProperties *c) const override
387 {
388 SlObject(&c->cur_economy, this->GetLoadDescription());
389 }
390
391 void FixPointers(CompanyProperties *c) const override
392 {
393 SlObject(&c->cur_economy, this->GetDescription());
394 }
395
396 void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
397};
398
400public:
401 void Save(CompanyProperties *c) const override
402 {
404 for (int i = 0; i < c->num_valid_stat_ent; i++) {
405 SlObject(&c->old_economy[i], this->GetDescription());
406 }
407 }
408
409 void Load(CompanyProperties *c) const override
410 {
412 c->num_valid_stat_ent = (uint8_t)SlGetStructListLength(UINT8_MAX);
413 }
414 if (c->num_valid_stat_ent > std::size(c->old_economy)) SlErrorCorrupt("Too many old economy entries");
415
416 for (int i = 0; i < c->num_valid_stat_ent; i++) {
417 SlObject(&c->old_economy[i], this->GetLoadDescription());
418 }
419 }
420
421 void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
422};
423
424class SlCompanyLiveries : public DefaultSaveLoadHandler<SlCompanyLiveries, CompanyProperties> {
425public:
426 static inline const SaveLoad description[] = {
430 };
431 static inline const SaveLoadCompatTable compat_description = _company_liveries_compat;
432
445
446 void Save(CompanyProperties *c) const override
447 {
449 for (auto &livery : c->livery) {
450 SlObject(&livery, this->GetDescription());
451 }
452 }
453
454 void Load(CompanyProperties *c) const override
455 {
456 size_t num_liveries = this->GetNumLiveries();
458
459 for (size_t i = 0; i < num_liveries; i++) {
460 Livery &livery = c->livery[static_cast<LiveryScheme>(i)];
461 SlObject(&livery, this->GetLoadDescription());
462 if (update_in_use && i != 0) {
463 if (!livery.in_use.Any({Livery::Flag::Primary, Livery::Flag::Secondary})) {
464 livery.colour1 = c->livery[LiveryScheme::Default].colour1;
465 livery.colour2 = c->livery[LiveryScheme::Default].colour2;
466 } else {
468 }
469 }
470 }
471
473 /* We want to insert some liveries somewhere in between. This means some have to be moved. */
474 std::move_backward(std::begin(c->livery) + to_underlying(LiveryScheme::FreightWagon) - 2, std::end(c->livery) - 2, std::end(c->livery));
477 }
478
480 /* Copy bus/truck liveries over to trams */
481 c->livery[LiveryScheme::PassengerTram] = c->livery[LiveryScheme::Bus];
482 c->livery[LiveryScheme::FreightTram] = c->livery[LiveryScheme::Truck];
483 }
484 }
485
486 void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
487};
488
490class SlCompanyEngineRenews : public VectorSaveLoadHandler<SlCompanyEngineRenews, CompanyProperties, EngineRenew> {
491public:
498
499 static inline const SaveLoadCompatTable compat_description = {};
500
501 void LoadCheck(CompanyProperties *cp) const override { this->Load(cp); }
502};
503
506public:
507 std::vector<EngineRenew> &GetVector(CompanyProperties *cp) const override { return cp->all_engine_renew_list; };
508};
509
512public:
513 std::vector<EngineRenew> &GetVector(CompanyProperties *cp) const override { return cp->ungrouped_engine_renew_list; };
514};
515
516class SlAllowListData : public VectorSaveLoadHandler<SlAllowListData, CompanyProperties, std::string> {
517public:
518 struct KeyWrapper {
519 std::string key;
520 };
521
522 static inline const SaveLoad description[] = {
524 };
525 static inline const SaveLoadCompatTable compat_description = {};
526
527 std::vector<std::string> &GetVector(CompanyProperties *cprops) const override { return cprops->allow_list; }
528
529 void LoadCheck(CompanyProperties *cprops) const override { this->Load(cprops); }
530};
531
533static const SaveLoad _company_desc[] = {
537
539 SaveLoad::Variable<VarFileType::U32>("president_name_2", SLE_OBJECT_ADDRESS(CompanyProperties, president_name_2)),
541
545
548
549 /* money was changed to a 64 bit field in savegame version 1. */
552
556
560
568
570
571 SaveLoad::Variable<VarFileType::U8>("months_of_bankruptcy", SLE_OBJECT_ADDRESS(CompanyProperties, months_of_bankruptcy)),
574 SaveLoad::Variable<VarFileType::I16>("bankrupt_timeout", SLE_OBJECT_ADDRESS(CompanyProperties, bankrupt_timeout)),
577
578 /* yearly expenses was changed to 64-bit in savegame version 2. */
581
583
594};
595
596struct PLYRChunkHandler : ChunkHandler {
597 PLYRChunkHandler() : ChunkHandler("PLYR", ChunkType::Table) {}
598
599 void Save() const override
600 {
602
603 for (Company *c : Company::Iterate()) {
604 SlSetArrayIndex(c->index);
606 }
607 }
608
609 void Load() const override
610 {
611 const std::vector<SaveLoad> slt = SlCompatTableHeader(_company_desc, _company_sl_compat);
612
613 int index;
614 while ((index = SlIterateArray()) != -1) {
615 Company *c = Company::CreateAtIndex(CompanyID(index));
616 SlObject(c, slt);
617 _company_colours[c->index] = c->colour;
618 }
619 }
620
621
622 void LoadCheck(size_t) const override
623 {
624 const std::vector<SaveLoad> slt = SlCompatTableHeader(_company_desc, _company_sl_compat);
625
626 int index;
627 while ((index = SlIterateArray()) != -1) {
628 std::unique_ptr<CompanyProperties> cprops = std::make_unique<CompanyProperties>();
629 SlObject(cprops.get(), slt);
630
631 /* We do not load old custom names */
633 if (GetStringTab(cprops->name_1) == TEXT_TAB_OLD_CUSTOM) {
634 cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
635 }
636
637 if (GetStringTab(cprops->president_name_1) == TEXT_TAB_OLD_CUSTOM) {
638 cprops->president_name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
639 }
640 }
641
642 if (cprops->name.empty() && !IsInsideMM(cprops->name_1, SPECSTR_COMPANY_NAME_START, SPECSTR_COMPANY_NAME_END) &&
643 cprops->name_1 != STR_GAME_SAVELOAD_NOT_AVAILABLE && cprops->name_1 != STR_SV_UNNAMED &&
644 cprops->name_1 != SPECSTR_ANDCO_NAME && cprops->name_1 != SPECSTR_PRESIDENT_NAME &&
645 cprops->name_1 != SPECSTR_SILLY_NAME) {
646 cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
647 }
648
649 if (_load_check_data.companies.count(index) == 0) {
650 _load_check_data.companies[index] = std::move(cprops);
651 }
652 }
653 }
654
655 void FixPointers() const override
656 {
657 for (Company *c : Company::Iterate()) {
659 }
660 }
661};
662
663static const PLYRChunkHandler PLYR;
664static const ChunkHandlerRef company_chunk_handlers[] = {
665 PLYR,
666};
667
668extern const ChunkHandlerTable _company_chunk_handlers(company_chunk_handlers);
OldEngineRenewPool _old_engine_renew_saveload_pool
Temporary storage for conversion from old engine renew pool.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr uint CountBits(T value)
Counts the number of set bits in a variable.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
static constexpr CargoType NUM_CARGO
Maximum number of cargo types in a game.
Definition cargo_type.h:77
uint Count() const
Count the number of set bits.
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
Default handler for saving/loading an object to/from disk.
Definition saveload.h:585
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
void LoadCheck(CompanyProperties *cprops) const override
Similar to load, but used only to validate savegames.
std::vector< std::string > & GetVector(CompanyProperties *cprops) const override
Get instance of vector to load/save.
void Save(CompanyProperties *c) const override
Save the object to disk.
void Load(CompanyProperties *c) const override
Load the object from disk.
void FixPointers(CompanyProperties *c) const override
A post-load callback to fix SaveLoadType::Reference integers into pointers.
void LoadCheck(CompanyProperties *c) const override
Similar to load, but used only to validate savegames.
Saveload handler for company engine renew "all" entries.
std::vector< EngineRenew > & GetVector(CompanyProperties *cp) const override
Get instance of vector to load/save.
Saveload handler for company engine renew "ungrouped" entries.
std::vector< EngineRenew > & GetVector(CompanyProperties *cp) const override
Get instance of vector to load/save.
Saveload handler for company engine renew entries.
static const SaveLoadCompatTable compat_description
Compatibility saveload description for handler.
static const SaveLoad description[]
Saveload description for handler.
void LoadCheck(CompanyProperties *cp) const override
Similar to load, but used only to validate savegames.
size_t GetNumLiveries() const
Get the number of liveries used by this savegame version.
void Load(CompanyProperties *c) const override
Load the object from disk.
void LoadCheck(CompanyProperties *c) const override
Similar to load, but used only to validate savegames.
void Save(CompanyProperties *c) const override
Save the object to disk.
void Load(CompanyOldAI *old_ai) const override
Load the object from disk.
SaveLoadTable GetDescription() const override
Get the description of the fields in the savegame.
void LoadCheck(CompanyOldAI *old_ai) const override
Similar to load, but used only to validate savegames.
static const SaveLoad description[]
Needed to keep DefaultSaveLoadHandler happy.
void LoadCheck(CompanyProperties *c) const override
Similar to load, but used only to validate savegames.
void Load(CompanyProperties *c) const override
Load the object from disk.
void Save(CompanyProperties *c) const override
Save the object to disk.
void Load(CompanyProperties *c) const override
Load the object from disk.
void LoadCheck(CompanyProperties *c) const override
Similar to load, but used only to validate savegames.
void Save(CompanyProperties *c) const override
Save the object to disk.
void LoadCheck(CompanyProperties *c) const override
Similar to load, but used only to validate savegames.
void Load(CompanyProperties *c) const override
Load the object from disk.
void FixPointers(CompanyProperties *c) const override
A post-load callback to fix SaveLoadType::Reference integers into pointers.
Default handler for saving/loading a vector to/from disk.
Definition saveload.h:1338
const FaceSpec * GetCompanyManagerFaceSpec(uint style_index)
Get the definition of a company manager face style.
TypedIndexContainer< std::array< Colours, MAX_COMPANIES >, CompanyID > _company_colours
NOSAVE: can be determined from company structs.
Functions related to companies.
static WindowDesc _company_desc(WindowPosition::Automatic, "company", 0, 0, WindowClass::Company, WindowClass::None, {}, _nested_company_widgets)
Window definition for the company window.
Functionality related to the company manager's face.
FaceVarType
Ways a FaceVar should be interpreted.
@ Palette
FaceVar describes a palette to apply to the given parts bitmask.
@ Sprite
FaceVar describes an offset to the given SpriteID.
@ Toggle
FaceVar describes which other FaceVars should be turned off.
static const FaceVar * FindFaceVar(FaceVars style, FaceVarType type, StringID name)
Search for a face variable by type and name.
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.
static const SaveLoad _company_desc[]
Save/load of companies.
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.
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.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:21
Declarations for savegames operations.
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Definition fios_gui.cpp:42
fluid_settings_t * settings
FluidSynth settings handle.
LiveryScheme
List of different livery schemes.
Definition livery.h:22
@ PassengerTram
Passenger trams.
Definition livery.h:55
@ PassengerWagonMaglev
Passenger wagons attached to maglev engines.
Definition livery.h:38
@ Maglev
Maglev engines.
Definition livery.h:31
@ Bus
Buses.
Definition livery.h:42
@ Truck
Trucks.
Definition livery.h:43
@ Default
Default scheme.
Definition livery.h:24
@ End
End marker.
Definition livery.h:58
@ PassengerWagonMonorail
Passenger wagons attached to monorail engines.
Definition livery.h:37
@ Monorail
Monorail engines.
Definition livery.h:30
@ FreightTram
Freight trams.
Definition livery.h:56
@ FreightWagon
Freight wagons.
Definition livery.h:39
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
constexpr uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
static bool IsPlainRail(Tile t)
Returns whether this is plain rails, with or without signals.
Definition rail_map.h:49
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Definition rail_map.h:115
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
Definition rail_map.h:136
uint GetPresentSignals(Tile tile)
Get whether the given signals are present (Along/AgainstTrackDir).
Definition rail_map.h:451
bool HasSignals(Tile t)
Checks if a rail tile has signals.
Definition rail_map.h:72
RoadBits GetRoadBits(Tile t, RoadTramType rtt)
Get the present road bits for a specific road type.
Definition road_map.h:112
static bool IsRoadDepot(Tile t)
Return whether a tile is a road depot.
Definition road_map.h:90
RoadType GetRoadType(Tile t, RoadTramType rtt)
Get the road type for the given RoadTramType.
Definition road_map.h:175
Owner GetRoadOwner(Tile t, RoadTramType rtt)
Get the owner of a specific road type.
Definition road_map.h:244
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
Definition road_map.h:69
static bool IsNormalRoad(Tile t)
Return whether a tile is a normal road.
Definition road_map.h:48
static constexpr RoadTramTypes ROADTRAMTYPES_ALL
All possible RoadTramTypes.
Definition road_type.h:49
RoadType
The different roadtypes we support.
Definition road_type.h:24
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition road_type.h:29
RoadTramType
The different types of road type.
Definition road_type.h:38
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.
Definition saveload.cpp:747
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
Definition saveload.cpp:371
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_OBJECT_ADDRESS(base, variable)
Macro to be able to pass the variable type and construct the SaveLoad::AddressFunction given a base c...
Definition saveload.h:752
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
Definition saveload.h:512
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
Definition saveload.h:515
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
Definition saveload.h:518
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
Definition saveload.h:1223
@ BigDates
Saveload version: 31, SVN revision: 5999 Change date from 1920 - 2090 to 0 - 5 000 000.
Definition saveload.h:85
@ ExtendCargotypes
Saveload version: 199, GitHub pull request: 6802 Extend cargotypes to 64.
Definition saveload.h:286
@ CompanyInauguratedPeriodV2
Saveload version: 349, GitHub pull request: 13448 Fix savegame storage for company inaugurated year ...
Definition saveload.h:402
@ BigCurrency
Saveload version: 1.0, releases: 0.1.x, 0.2.x Change currency from 32 to 64 bits.
Definition saveload.h:37
@ UnifyCurrency
Saveload version: 65, SVN revision: 10210 Make all variables related to currency 64 bits.
Definition saveload.h:126
@ ReplaceCustomNameArray
Saveload version: 84, SVN revision: 11822 Replace single fixed size array of custom names,...
Definition saveload.h:148
@ VehicleCurrencyStationChanges
Saveload version: 2.0, release: 0.3.0 Adding vehicle state, larger currency size for statistics,...
Definition saveload.h:38
@ CountIndividualCargoes
Saveload version: 170, SVN revision: 23826 Store the count of individual cargo delivery for a period...
Definition saveload.h:252
@ MaxLoanForCompany
Saveload version: 330, GitHub pull request: 11224 Separate max loan for each company.
Definition saveload.h:380
@ MaglevMonorailPaxWagonLivery
Saveload version: 85, SVN revision: 11874 Add livery for maglev/monorail passenger wagons.
Definition saveload.h:150
@ EngineRenewPool
Saveload version: 19, SVN revision: 3396 Engine renews are now stored in a pool.
Definition saveload.h:70
@ GroupLiveries
Saveload version: 205, GitHub pull request: 7108 Livery storage change and group liveries.
Definition saveload.h:294
@ MoreCargoPackets
Saveload version: 69, SVN revision: 10319 Allow more than ~65k cargo packets.
Definition saveload.h:130
@ MoreCompanies
Saveload version: 104, SVN revision: 14735 Increase maximum number of companies to 15.
Definition saveload.h:172
@ MultipleRoadStops
Saveload version: 6.0, SVN revision: 1721 Multi tile road stops, and some map size related fixes.
Definition saveload.h:51
@ AutoreplaceWhenOldTreeLimit
Saveload version: 175, SVN revision: 24136 Autoreplace vehicle only when they are old,...
Definition saveload.h:258
@ CompanyAllowListV2
Saveload version: 341, GitHub pull request: 12908 Fixed savegame format for saving of list of client...
Definition saveload.h:393
@ CompanyServiceIntervals
Saveload version: 120, SVN revision: 16439 Make service intervals configurable per company.
Definition saveload.h:192
@ EngineRenewsOwnership
Saveload version: 369, GitHub pull request: 16186 Engine renews are now owned by company or group in...
Definition saveload.h:426
@ MinVersion
First savegame version.
Definition saveload.h:35
@ CompanyAllowList
Saveload version: 335, GitHub pull request: 12337 Saving of list of client keys that are allowed to ...
Definition saveload.h:386
@ EngineRenew
Saveload version: 16.0, SVN revision: 2817 Automatic replacing/renewing of vehicles.
Definition saveload.h:65
@ SaveloadListLength
Saveload version: 293, GitHub pull request: 9374 Consistency in list length with SaveLoadType::Struc...
Definition saveload.h:335
@ Liveries
Saveload version: 34, SVN revision: 6455 Liveries and two company colours (2cc).
Definition saveload.h:88
@ FaceStyles
Saveload version: 355, GitHub pull request: 14319 Addition of face styles, replacing gender and ethn...
Definition saveload.h:410
@ TerraformLimits
Saveload version: 156, SVN revision: 21728 Introduce limits for terraforming and clearing times.
Definition saveload.h:235
@ NoAI
Saveload version: 107, SVN revision: 15027 Replace built in cheating AI with framework for externall...
Definition saveload.h:176
@ TramLivery
Saveload version: 63, SVN revision: 9956 Add separate livery for trams.
Definition saveload.h:123
@ Table
An Array with a header describing the elements.
Definition saveload.h:449
Functions/types related to errors from savegames.
Declaration of functions used in more save/load files.
std::span< const struct SaveLoad > SaveLoadTable
A table of SaveLoad entries.
Base classes/functions for stations.
StationType GetStationType(Tile t)
Get the station type of this tile.
Definition station_map.h:42
bool IsBuoy(Tile t)
Is tile t a buoy tile?
bool IsStationTileBlocked(Tile t)
Is tile t a blocked tile?
@ Airport
Station with an airport.
@ Dock
Ship port.
@ Rail
Railways/train station.
@ Bus
Road stop for busses.
@ Truck
Road stop for trucks.
@ RailWaypoint
Waypoint for trains.
@ Buoy
Waypoint for ships.
@ RoadWaypoint
Waypoint for trucks and busses.
@ Airport
Airports and heliports, excluding the ones on oil rigs.
Definition of base types and functions in a cross-platform compatible way.
@ AllowControlCode
Allow the special control codes.
Definition string_type.h:47
Functions related to OTTD's strings.
StringTab GetStringTab(StringID str)
Extract the StringTab from a StringID.
static constexpr StringID SPECSTR_COMPANY_NAME_START
Special strings for company names on the form "TownName transport".
static constexpr StringID SPECSTR_SILLY_NAME
Special string for silly company names.
static constexpr StringID SPECSTR_ANDCO_NAME
Special string for Surname & Co company names.
static constexpr StringID SPECSTR_PRESIDENT_NAME
Special string for the president's name.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
ChunkHandler(ChunkId id, ChunkType type)
Create this ChunkHandler.
Definition saveload.h:469
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.
uint style
Company manager face style.
std::string style_label
Face style label.
We do need to read this single value, as the bigger it gets, the more data is stored.
Statically loadable part of Company pool item.
NetworkAuthorizedKeys allow_list
Public keys of clients that are allowed to join this company.
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.
EngineRenewList all_engine_renew_list
Engine renewals of this company for all vehicles.
Colours colour
Company colour.
std::array< CompanyEconomyEntry, MAX_HISTORY_QUARTERS > old_economy
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
uint16_t old_engine_renew_index
Index of first item in old engine renew pool, required for old savegame conversion.
EngineRenewList ungrouped_engine_renew_list
Engine renewals of this company for ungrouped vehicles.
uint8_t num_valid_stat_ent
Number of valid statistical entries in old_economy.
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Information about engine autorenews and autoreplacements.
EngineID from
Engine to replace from.
Information about the valid values of CompanyManagerFace bitgroups as well as the sprites to draw.
FaceVarType type
Type of variable.
StringID name
Name of the configurable component of the face.
Information about a particular livery.
Definition livery.h:82
Flags in_use
Livery flags.
Definition livery.h:92
Colours colour2
Second colour, for vehicles with 2CC support.
Definition livery.h:94
Colours colour1
First colour, for all vehicles.
Definition livery.h:93
@ Primary
Primary colour is set.
Definition livery.h:85
@ Secondary
Secondary colour is set.
Definition livery.h:86
static IterateWrapper Iterate()
Returns an iterable ensemble of all Tiles.
Definition map_func.h:366
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 Pool::IterateWrapper< Company > Iterate(size_t from=0)
static T * CreateAtIndex(CompanyID index, Targs &&... args)
static Company * Get(auto index)
static Company * GetIfValid(auto index)
SaveLoad type struct.
Definition saveload.h:762
static SaveLoad StructList(std::string name, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion)
Storage of a list of structs, optionally in some savegame versions.
Definition saveload.h:1100
static SaveLoad Variable(std::string name, AddressFunction< T > address_func, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion, size_t extra=0)
Storage of a variable in some savegame versions.
Definition saveload.h:923
static SaveLoad Array(std::string name, AddressFunction< T > address_func, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion, size_t extra=0)
Storage of an array in some savegame versions.
Definition saveload.h:1023
static SaveLoad Vector(std::string name, AddressFunction< T > address_func, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion)
Storage of a vector in some savegame versions.
Definition saveload.h:1050
static SaveLoad Struct(std::string name, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion)
Storage of a structs, optionally in some savegame versions.
Definition saveload.h:998
static SaveLoad String(std::string name, AddressFunction< T > address_func, StringValidationSettings string_validation_settings={}, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion, size_t extra=0)
Storage of a string in some savegame versions.
Definition saveload.h:974
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Station data structure.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
static TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition tile_map.h:96
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.
Definition tile_type.h:92
@ TunnelBridge
Tunnel entry/exit and bridge heads.
Definition tile_type.h:58
@ Water
Water tile.
Definition tile_type.h:55
@ Station
A tile of a station or airport.
Definition tile_type.h:54
@ Object
Contains objects such as transmitters and owned land.
Definition tile_type.h:59
@ Railway
A tile with railway.
Definition tile_type.h:50
@ Road
A tile with road and/or tram tracks.
Definition tile_type.h:51
bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
Definition track_func.h:540
EnumBitSet< Track, uint8_t > TrackBits
Bitset of Track elements.
Definition track_type.h:43
@ Water
Transport over water.
@ Rail
Transport by train.
@ Road
Transport by road vehicle.
Header file for things common for tunnels and bridges.
uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles).
Functions that have tunnels and bridges in common.
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?
Definition water_map.h:227
@ Canal
Canal.
Definition water_map.h:43
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
Definition water_map.h:116
@ Middle
Middle part of a lock.
Definition water_map.h:68
bool IsLock(Tile t)
Is there a lock on a given water tile?
Definition water_map.h:308
LockPart GetLockPart(Tile t)
Get the part of a lock.
Definition water_map.h:331