OpenTTD Source: src/saveload/company_sl.cpp Source File

OpenTTD Source 15.0-beta1

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 <http://www.gnu.org/licenses/>.
6 */
7
10#include "../stdafx.h"
11
12#include "saveload.h"
13#include "compat/company_sl_compat.h"
14
15#include "../company_func.h"
16#include "../company_manager_face.h"
17#include "../fios.h"
18#include "../tunnelbridge_map.h"
19#include "../tunnelbridge.h"
20#include "../station_base.h"
21#include "../strings_func.h"
22
23#include "table/strings.h"
24
25#include "../safeguards.h"
26
45 CompanyManagerFace ConvertFromOldCompanyManagerFace(uint32_t face)
46{
47 CompanyManagerFace cmf = 0;
48 GenderEthnicity ge = GE_WM;
49
50 if (HasBit(face, 31)) SetBit(ge, GENDER_FEMALE);
51 if (HasBit(face, 27) && (HasBit(face, 26) == HasBit(face, 19))) SetBit(ge, ETHNICITY_BLACK);
52
53 SetCompanyManagerFaceBits(cmf, CMFV_GEN_ETHN, ge, ge);
54 SetCompanyManagerFaceBits(cmf, CMFV_HAS_GLASSES, ge, GB(face, 28, 3) <= 1);
55 SetCompanyManagerFaceBits(cmf, CMFV_EYE_COLOUR, ge, HasBit(ge, ETHNICITY_BLACK) ? 0 : ClampU(GB(face, 20, 3), 5, 7) - 5);
56 SetCompanyManagerFaceBits(cmf, CMFV_CHIN, ge, ScaleCompanyManagerFaceValue(CMFV_CHIN, ge, GB(face, 4, 2)));
57 SetCompanyManagerFaceBits(cmf, CMFV_EYEBROWS, ge, ScaleCompanyManagerFaceValue(CMFV_EYEBROWS, ge, GB(face, 6, 4)));
58 SetCompanyManagerFaceBits(cmf, CMFV_HAIR, ge, ScaleCompanyManagerFaceValue(CMFV_HAIR, ge, GB(face, 16, 4)));
59 SetCompanyManagerFaceBits(cmf, CMFV_JACKET, ge, ScaleCompanyManagerFaceValue(CMFV_JACKET, ge, GB(face, 20, 2)));
60 SetCompanyManagerFaceBits(cmf, CMFV_COLLAR, ge, ScaleCompanyManagerFaceValue(CMFV_COLLAR, ge, GB(face, 22, 2)));
61 SetCompanyManagerFaceBits(cmf, CMFV_GLASSES, ge, GB(face, 28, 1));
62
63 uint lips = GB(face, 10, 4);
64 if (!HasBit(ge, GENDER_FEMALE) && lips < 4) {
65 SetCompanyManagerFaceBits(cmf, CMFV_HAS_MOUSTACHE, ge, true);
66 SetCompanyManagerFaceBits(cmf, CMFV_MOUSTACHE, ge, std::max(lips, 1U) - 1);
67 } else {
68 if (!HasBit(ge, GENDER_FEMALE)) {
69 lips = lips * 15 / 16;
70 lips -= 3;
71 if (HasBit(ge, ETHNICITY_BLACK) && lips > 8) lips = 0;
72 } else {
73 lips = ScaleCompanyManagerFaceValue(CMFV_LIPS, ge, lips);
74 }
75 SetCompanyManagerFaceBits(cmf, CMFV_LIPS, ge, lips);
76
77 uint nose = GB(face, 13, 3);
78 if (ge == GE_WF) {
79 nose = (nose * 3 >> 3) * 3 >> 2; // There is 'hole' in the nose sprites for females
80 } else {
81 nose = ScaleCompanyManagerFaceValue(CMFV_NOSE, ge, nose);
82 }
83 SetCompanyManagerFaceBits(cmf, CMFV_NOSE, ge, nose);
84 }
85
86 uint tie_earring = GB(face, 24, 4);
87 if (!HasBit(ge, GENDER_FEMALE) || tie_earring < 3) { // Not all females have an earring
88 if (HasBit(ge, GENDER_FEMALE)) SetCompanyManagerFaceBits(cmf, CMFV_HAS_TIE_EARRING, ge, true);
89 SetCompanyManagerFaceBits(cmf, CMFV_TIE_EARRING, ge, HasBit(ge, GENDER_FEMALE) ? tie_earring : ScaleCompanyManagerFaceValue(CMFV_TIE_EARRING, ge, tie_earring / 2));
90 }
91
92 return cmf;
93}
94
96 void AfterLoadCompanyStats()
97{
98 /* Reset infrastructure statistics to zero. */
99 for (Company *c : Company::Iterate()) c->infrastructure = {};
100
101 /* Collect airport count. */
102 for (const Station *st : Station::Iterate()) {
103 if ((st->facilities & FACIL_AIRPORT) && Company::IsValidID(st->owner)) {
104 Company::Get(st->owner)->infrastructure.airport++;
105 }
106 }
107
108 Company *c;
109 for (const auto tile : Map::Iterate()) {
110 switch (GetTileType(tile)) {
111 case MP_RAILWAY:
112 c = Company::GetIfValid(GetTileOwner(tile));
113 if (c != nullptr) {
114 uint pieces = 1;
115 if (IsPlainRail(tile)) {
116 TrackBits bits = GetTrackBits(tile);
117 pieces = CountBits(bits);
118 if (TracksOverlap(bits)) pieces *= pieces;
119 }
120 c->infrastructure.rail[GetRailType(tile)] += pieces;
121
122 if (HasSignals(tile)) c->infrastructure.signal += CountBits(GetPresentSignals(tile));
123 }
124 break;
125
126 case MP_ROAD: {
127 if (IsLevelCrossing(tile)) {
128 c = Company::GetIfValid(GetTileOwner(tile));
129 if (c != nullptr) c->infrastructure.rail[GetRailType(tile)] += LEVELCROSSING_TRACKBIT_FACTOR;
130 }
131
132 /* Iterate all present road types as each can have a different owner. */
133 for (RoadTramType rtt : _roadtramtypes) {
134 RoadType rt = GetRoadType(tile, rtt);
135 if (rt == INVALID_ROADTYPE) continue;
136 c = Company::GetIfValid(IsRoadDepot(tile) ? GetTileOwner(tile) : GetRoadOwner(tile, rtt));
137 /* A level crossings and depots have two road bits. */
138 if (c != nullptr) c->infrastructure.road[rt] += IsNormalRoad(tile) ? CountBits(GetRoadBits(tile, rtt)) : 2;
139 }
140 break;
141 }
142
143 case MP_STATION:
144 c = Company::GetIfValid(GetTileOwner(tile));
145 if (c != nullptr && GetStationType(tile) != STATION_AIRPORT && !IsBuoy(tile)) c->infrastructure.station++;
146
147 switch (GetStationType(tile)) {
148 case STATION_RAIL:
149 case STATION_WAYPOINT:
150 if (c != nullptr && !IsStationTileBlocked(tile)) c->infrastructure.rail[GetRailType(tile)]++;
151 break;
152
153 case STATION_BUS:
154 case STATION_TRUCK:
155 case STATION_ROADWAYPOINT: {
156 /* Iterate all present road types as each can have a different owner. */
157 for (RoadTramType rtt : _roadtramtypes) {
158 RoadType rt = GetRoadType(tile, rtt);
159 if (rt == INVALID_ROADTYPE) continue;
160 c = Company::GetIfValid(GetRoadOwner(tile, rtt));
161 if (c != nullptr) c->infrastructure.road[rt] += 2; // A road stop has two road bits.
162 }
163 break;
164 }
165
166 case STATION_DOCK:
167 case STATION_BUOY:
168 if (GetWaterClass(tile) == WATER_CLASS_CANAL) {
169 if (c != nullptr) c->infrastructure.water++;
170 }
171 break;
172
173 default:
174 break;
175 }
176 break;
177
178 case MP_WATER:
179 if (IsShipDepot(tile) || IsLock(tile)) {
180 c = Company::GetIfValid(GetTileOwner(tile));
181 if (c != nullptr) {
182 if (IsShipDepot(tile)) c->infrastructure.water += LOCK_DEPOT_TILE_FACTOR;
183 if (IsLock(tile) && GetLockPart(tile) == LOCK_PART_MIDDLE) {
184 /* The middle tile specifies the owner of the lock. */
185 c->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // the middle tile specifies the owner of the
186 break; // do not count the middle tile as canal
187 }
188 }
189 }
190 [[fallthrough]];
191
192 case MP_OBJECT:
193 if (GetWaterClass(tile) == WATER_CLASS_CANAL) {
194 c = Company::GetIfValid(GetTileOwner(tile));
195 if (c != nullptr) c->infrastructure.water++;
196 }
197 break;
198
199 case MP_TUNNELBRIDGE: {
200 /* Only count the tunnel/bridge if we're on the northern end tile. */
201 TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
202 if (tile < other_end) {
203 /* Count each tunnel/bridge TUNNELBRIDGE_TRACKBIT_FACTOR times to simulate
204 * the higher structural maintenance needs, and don't forget the end tiles. */
205 uint len = (GetTunnelBridgeLength(tile, other_end) + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
206
207 switch (GetTunnelBridgeTransportType(tile)) {
208 case TRANSPORT_RAIL:
209 c = Company::GetIfValid(GetTileOwner(tile));
210 if (c != nullptr) c->infrastructure.rail[GetRailType(tile)] += len;
211 break;
212
213 case TRANSPORT_ROAD: {
214 /* Iterate all present road types as each can have a different owner. */
215 for (RoadTramType rtt : _roadtramtypes) {
216 RoadType rt = GetRoadType(tile, rtt);
217 if (rt == INVALID_ROADTYPE) continue;
218 c = Company::GetIfValid(GetRoadOwner(tile, rtt));
219 if (c != nullptr) c->infrastructure.road[rt] += len * 2; // A full diagonal road has two road bits.
220 }
221 break;
222 }
223
224 case TRANSPORT_WATER:
225 c = Company::GetIfValid(GetTileOwner(tile));
226 if (c != nullptr) c->infrastructure.water += len;
227 break;
228
229 default:
230 break;
231 }
232 }
233 break;
234 }
235
236 default:
237 break;
238 }
239 }
240}
241
242/* We do need to read this single value, as the bigger it gets, the more data is stored */
243 struct CompanyOldAI {
244 uint8_t num_build_rec;
245};
246
247 class SlCompanyOldAIBuildRec : public DefaultSaveLoadHandler<SlCompanyOldAIBuildRec, CompanyOldAI> {
248public:
249 inline static const SaveLoad description[] = {{}}; // Needed to keep DefaultSaveLoadHandler happy.
250 inline const static SaveLoadCompatTable compat_description = _company_old_ai_buildrec_compat;
251
252 SaveLoadTable GetDescription() const override { return {}; }
253
254 void Load(CompanyOldAI *old_ai) const override
255 {
256 for (int i = 0; i != old_ai->num_build_rec; i++) {
257 SlObject(nullptr, this->GetLoadDescription());
258 }
259 }
260
261 void LoadCheck(CompanyOldAI *old_ai) const override { this->Load(old_ai); }
262};
263
264 class SlCompanyOldAI : public DefaultSaveLoadHandler<SlCompanyOldAI, CompanyProperties> {
265public:
266 inline static const SaveLoad description[] = {
267 SLE_CONDVAR(CompanyOldAI, num_build_rec, SLE_UINT8, SL_MIN_VERSION, SLV_107),
268 SLEG_STRUCTLIST("buildrec", SlCompanyOldAIBuildRec),
269 };
270 inline const static SaveLoadCompatTable compat_description = _company_old_ai_compat;
271
272 void Load(CompanyProperties *c) const override
273 {
274 if (!c->is_ai) return;
275
276 CompanyOldAI old_ai;
277 SlObject(&old_ai, this->GetLoadDescription());
278 }
279
280 void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
281};
282
283 class SlCompanySettings : public DefaultSaveLoadHandler<SlCompanySettings, CompanyProperties> {
284public:
285 inline static const SaveLoad description[] = {
286 /* Engine renewal settings */
287 SLE_CONDREF(CompanyProperties, engine_renew_list, REF_ENGINE_RENEWS, SLV_19, SL_MAX_VERSION),
288 SLE_CONDVAR(CompanyProperties, settings.engine_renew, SLE_BOOL, SLV_16, SL_MAX_VERSION),
289 SLE_CONDVAR(CompanyProperties, settings.engine_renew_months, SLE_INT16, SLV_16, SL_MAX_VERSION),
290 SLE_CONDVAR(CompanyProperties, settings.engine_renew_money, SLE_UINT32, SLV_16, SL_MAX_VERSION),
291 SLE_CONDVAR(CompanyProperties, settings.renew_keep_length, SLE_BOOL, SLV_2, SL_MAX_VERSION),
292
293 /* Default vehicle settings */
294 SLE_CONDVAR(CompanyProperties, settings.vehicle.servint_ispercent, SLE_BOOL, SLV_120, SL_MAX_VERSION),
295 SLE_CONDVAR(CompanyProperties, settings.vehicle.servint_trains, SLE_UINT16, SLV_120, SL_MAX_VERSION),
296 SLE_CONDVAR(CompanyProperties, settings.vehicle.servint_roadveh, SLE_UINT16, SLV_120, SL_MAX_VERSION),
297 SLE_CONDVAR(CompanyProperties, settings.vehicle.servint_aircraft, SLE_UINT16, SLV_120, SL_MAX_VERSION),
298 SLE_CONDVAR(CompanyProperties, settings.vehicle.servint_ships, SLE_UINT16, SLV_120, SL_MAX_VERSION),
299 };
300 inline const static SaveLoadCompatTable compat_description = _company_settings_compat;
301
302 void Save(CompanyProperties *c) const override
303 {
304 SlObject(c, this->GetDescription());
305 }
306
307 void Load(CompanyProperties *c) const override
308 {
309 SlObject(c, this->GetLoadDescription());
310 }
311
312 void FixPointers(CompanyProperties *c) const override
313 {
314 SlObject(c, this->GetDescription());
315 }
316
317 void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
318};
319
320 class SlCompanyEconomy : public DefaultSaveLoadHandler<SlCompanyEconomy, CompanyProperties> {
321public:
322 inline static const SaveLoad description[] = {
323 SLE_CONDVAR(CompanyEconomyEntry, income, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_2),
324 SLE_CONDVAR(CompanyEconomyEntry, income, SLE_INT64, SLV_2, SL_MAX_VERSION),
325 SLE_CONDVAR(CompanyEconomyEntry, expenses, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_2),
326 SLE_CONDVAR(CompanyEconomyEntry, expenses, SLE_INT64, SLV_2, SL_MAX_VERSION),
327 SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_2),
328 SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_INT64, SLV_2, SL_MAX_VERSION),
329
330 SLE_CONDVAR(CompanyEconomyEntry, delivered_cargo[NUM_CARGO - 1], SLE_INT32, SL_MIN_VERSION, SLV_170),
331 SLE_CONDARR(CompanyEconomyEntry, delivered_cargo, SLE_UINT32, 32, SLV_170, SLV_EXTEND_CARGOTYPES),
332 SLE_CONDARR(CompanyEconomyEntry, delivered_cargo, SLE_UINT32, NUM_CARGO, SLV_EXTEND_CARGOTYPES, SL_MAX_VERSION),
333 SLE_VAR(CompanyEconomyEntry, performance_history, SLE_INT32),
334 };
335 inline const static SaveLoadCompatTable compat_description = _company_economy_compat;
336
337 void Save(CompanyProperties *c) const override
338 {
339 SlObject(&c->cur_economy, this->GetDescription());
340 }
341
342 void Load(CompanyProperties *c) const override
343 {
344 SlObject(&c->cur_economy, this->GetLoadDescription());
345 }
346
347 void FixPointers(CompanyProperties *c) const override
348 {
349 SlObject(&c->cur_economy, this->GetDescription());
350 }
351
352 void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
353};
354
355 class SlCompanyOldEconomy : public SlCompanyEconomy {
356public:
357 void Save(CompanyProperties *c) const override
358 {
359 SlSetStructListLength(c->num_valid_stat_ent);
360 for (int i = 0; i < c->num_valid_stat_ent; i++) {
361 SlObject(&c->old_economy[i], this->GetDescription());
362 }
363 }
364
365 void Load(CompanyProperties *c) const override
366 {
367 if (!IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH)) {
368 c->num_valid_stat_ent = (uint8_t)SlGetStructListLength(UINT8_MAX);
369 }
370 if (c->num_valid_stat_ent > lengthof(c->old_economy)) SlErrorCorrupt("Too many old economy entries");
371
372 for (int i = 0; i < c->num_valid_stat_ent; i++) {
373 SlObject(&c->old_economy[i], this->GetLoadDescription());
374 }
375 }
376
377 void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
378};
379
380 class SlCompanyLiveries : public DefaultSaveLoadHandler<SlCompanyLiveries, CompanyProperties> {
381public:
382 inline static const SaveLoad description[] = {
383 SLE_CONDVAR(Livery, in_use, SLE_UINT8, SLV_34, SL_MAX_VERSION),
384 SLE_CONDVAR(Livery, colour1, SLE_UINT8, SLV_34, SL_MAX_VERSION),
385 SLE_CONDVAR(Livery, colour2, SLE_UINT8, SLV_34, SL_MAX_VERSION),
386 };
387 inline const static SaveLoadCompatTable compat_description = _company_liveries_compat;
388
393 size_t GetNumLiveries() const
394 {
395 if (IsSavegameVersionBefore(SLV_63)) return LS_END - 4;
396 if (IsSavegameVersionBefore(SLV_85)) return LS_END - 2;
397 if (IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH)) return LS_END;
398 /* Read from the savegame how long the list is. */
399 return SlGetStructListLength(LS_END);
400 }
401
402 void Save(CompanyProperties *c) const override
403 {
404 SlSetStructListLength(LS_END);
405 for (int i = 0; i < LS_END; i++) {
406 SlObject(&c->livery[i], this->GetDescription());
407 }
408 }
409
410 void Load(CompanyProperties *c) const override
411 {
412 size_t num_liveries = this->GetNumLiveries();
413 bool update_in_use = IsSavegameVersionBefore(SLV_GROUP_LIVERIES);
414
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) {
419 c->livery[i].colour1 = c->livery[LS_DEFAULT].colour1;
420 c->livery[i].colour2 = c->livery[LS_DEFAULT].colour2;
421 } else {
422 c->livery[i].in_use = 3;
423 }
424 }
425 }
426
427 if (IsSavegameVersionBefore(SLV_85)) {
428 /* We want to insert some liveries somewhere in between. This means some have to be moved. */
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];
432 }
433
434 if (IsSavegameVersionBefore(SLV_63)) {
435 /* Copy bus/truck liveries over to trams */
436 c->livery[LS_PASSENGER_TRAM] = c->livery[LS_BUS];
437 c->livery[LS_FREIGHT_TRAM] = c->livery[LS_TRUCK];
438 }
439 }
440
441 void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
442};
443
444 class SlAllowListData : public VectorSaveLoadHandler<SlAllowListData, CompanyProperties, std::string> {
445public:
446 struct KeyWrapper {
447 std::string key;
448 };
449
450 inline static const SaveLoad description[] = {
451 SLE_SSTR(KeyWrapper, key, SLE_STR),
452 };
453 inline const static SaveLoadCompatTable compat_description = {};
454
455 std::vector<std::string> &GetVector(CompanyProperties *cprops) const override { return cprops->allow_list; }
456
457 void LoadCheck(CompanyProperties *cprops) const override { this->Load(cprops); }
458};
459
460/* Save/load of companies */
461static const SaveLoad _company_desc[] = {
462 SLE_VAR(CompanyProperties, name_2, SLE_UINT32),
463 SLE_VAR(CompanyProperties, name_1, SLE_STRINGID),
464 SLE_CONDSSTR(CompanyProperties, name, SLE_STR | SLF_ALLOW_CONTROL, SLV_84, SL_MAX_VERSION),
465
466 SLE_VAR(CompanyProperties, president_name_1, SLE_STRINGID),
467 SLE_VAR(CompanyProperties, president_name_2, SLE_UINT32),
468 SLE_CONDSSTR(CompanyProperties, president_name, SLE_STR | SLF_ALLOW_CONTROL, SLV_84, SL_MAX_VERSION),
469
470 SLE_CONDVECTOR(CompanyProperties, allow_list, SLE_STR, SLV_COMPANY_ALLOW_LIST, SLV_COMPANY_ALLOW_LIST_V2),
471 SLEG_CONDSTRUCTLIST("allow_list", SlAllowListData, SLV_COMPANY_ALLOW_LIST_V2, SL_MAX_VERSION),
472
473 SLE_VAR(CompanyProperties, face, SLE_UINT32),
474
475 /* money was changed to a 64 bit field in savegame version 1. */
476 SLE_CONDVAR(CompanyProperties, money, SLE_VAR_I64 | SLE_FILE_I32, SL_MIN_VERSION, SLV_1),
477 SLE_CONDVAR(CompanyProperties, money, SLE_INT64, SLV_1, SL_MAX_VERSION),
478
479 SLE_CONDVAR(CompanyProperties, current_loan, SLE_VAR_I64 | SLE_FILE_I32, SL_MIN_VERSION, SLV_65),
480 SLE_CONDVAR(CompanyProperties, current_loan, SLE_INT64, SLV_65, SL_MAX_VERSION),
481 SLE_CONDVAR(CompanyProperties, max_loan, SLE_INT64, SLV_MAX_LOAN_FOR_COMPANY, SL_MAX_VERSION),
482
483 SLE_VAR(CompanyProperties, colour, SLE_UINT8),
484 SLE_VAR(CompanyProperties, money_fraction, SLE_UINT8),
485 SLE_VAR(CompanyProperties, block_preview, SLE_UINT8),
486
487 SLE_CONDVAR(CompanyProperties, location_of_HQ, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
488 SLE_CONDVAR(CompanyProperties, location_of_HQ, SLE_UINT32, SLV_6, SL_MAX_VERSION),
489 SLE_CONDVAR(CompanyProperties, last_build_coordinate, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
490 SLE_CONDVAR(CompanyProperties, last_build_coordinate, SLE_UINT32, SLV_6, SL_MAX_VERSION),
491 SLE_CONDVAR(CompanyProperties, inaugurated_year, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
492 SLE_CONDVAR(CompanyProperties, inaugurated_year, SLE_INT32, SLV_31, SL_MAX_VERSION),
493
494 SLE_CONDVAR(CompanyProperties, num_valid_stat_ent, SLE_UINT8, SL_MIN_VERSION, SLV_SAVELOAD_LIST_LENGTH),
495
496 SLE_VAR(CompanyProperties, months_of_bankruptcy, SLE_UINT8),
497 SLE_CONDVAR(CompanyProperties, bankrupt_asked, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_104),
498 SLE_CONDVAR(CompanyProperties, bankrupt_asked, SLE_UINT16, SLV_104, SL_MAX_VERSION),
499 SLE_VAR(CompanyProperties, bankrupt_timeout, SLE_INT16),
500 SLE_CONDVAR(CompanyProperties, bankrupt_value, SLE_VAR_I64 | SLE_FILE_I32, SL_MIN_VERSION, SLV_65),
501 SLE_CONDVAR(CompanyProperties, bankrupt_value, SLE_INT64, SLV_65, SL_MAX_VERSION),
502
503 /* yearly expenses was changed to 64-bit in savegame version 2. */
504 SLE_CONDARR(CompanyProperties, yearly_expenses, SLE_FILE_I32 | SLE_VAR_I64, 3 * 13, SL_MIN_VERSION, SLV_2),
505 SLE_CONDARR(CompanyProperties, yearly_expenses, SLE_INT64, 3 * 13, SLV_2, SL_MAX_VERSION),
506
507 SLE_CONDVAR(CompanyProperties, is_ai, SLE_BOOL, SLV_2, SL_MAX_VERSION),
508
509 SLE_CONDVAR(CompanyProperties, terraform_limit, SLE_UINT32, SLV_156, SL_MAX_VERSION),
510 SLE_CONDVAR(CompanyProperties, clear_limit, SLE_UINT32, SLV_156, SL_MAX_VERSION),
511 SLE_CONDVAR(CompanyProperties, tree_limit, SLE_UINT32, SLV_175, SL_MAX_VERSION),
512 SLEG_STRUCT("settings", SlCompanySettings),
513 SLEG_CONDSTRUCT("old_ai", SlCompanyOldAI, SL_MIN_VERSION, SLV_107),
514 SLEG_STRUCT("cur_economy", SlCompanyEconomy),
515 SLEG_STRUCTLIST("old_economy", SlCompanyOldEconomy),
516 SLEG_CONDSTRUCTLIST("liveries", SlCompanyLiveries, SLV_34, SL_MAX_VERSION),
517};
518
519 struct PLYRChunkHandler : ChunkHandler {
520 PLYRChunkHandler() : ChunkHandler('PLYR', CH_TABLE) {}
521
522 void Save() const override
523 {
524 SlTableHeader(_company_desc);
525
526 for (Company *c : Company::Iterate()) {
527 SlSetArrayIndex(c->index);
528 SlObject(c, _company_desc);
529 }
530 }
531
532 void Load() const override
533 {
534 const std::vector<SaveLoad> slt = SlCompatTableHeader(_company_desc, _company_sl_compat);
535
536 int index;
537 while ((index = SlIterateArray()) != -1) {
538 Company *c = new (index) Company();
539 SlObject(c, slt);
540 _company_colours[index] = c->colour;
541 }
542 }
543
544
545 void LoadCheck(size_t) const override
546 {
547 const std::vector<SaveLoad> slt = SlCompatTableHeader(_company_desc, _company_sl_compat);
548
549 int index;
550 while ((index = SlIterateArray()) != -1) {
551 std::unique_ptr<CompanyProperties> cprops = std::make_unique<CompanyProperties>();
552 SlObject(cprops.get(), slt);
553
554 /* We do not load old custom names */
555 if (IsSavegameVersionBefore(SLV_84)) {
556 if (GetStringTab(cprops->name_1) == TEXT_TAB_OLD_CUSTOM) {
557 cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
558 }
559
560 if (GetStringTab(cprops->president_name_1) == TEXT_TAB_OLD_CUSTOM) {
561 cprops->president_name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
562 }
563 }
564
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;
570 }
571
572 if (_load_check_data.companies.count(index) == 0) {
573 _load_check_data.companies[index] = std::move(cprops);
574 }
575 }
576 }
577
578 void FixPointers() const override
579 {
580 for (Company *c : Company::Iterate()) {
581 SlObject(c, _company_desc);
582 }
583 }
584};
585
586static const PLYRChunkHandler PLYR;
587static const ChunkHandlerRef company_chunk_handlers[] = {
588 PLYR,
589};
590
591extern const ChunkHandlerTable _company_chunk_handlers(company_chunk_handlers);
HasBit
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition bitmath_func.hpp:121
CountBits
constexpr uint CountBits(T value)
Counts the number of set bits in a variable.
Definition bitmath_func.hpp:262
GB
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.
Definition bitmath_func.hpp:32
NUM_CARGO
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
Definition cargo_type.h:74
DefaultSaveLoadHandler
Default handler for saving/loading an object to/from disk.
Definition saveload.h:581
DefaultSaveLoadHandler< SlCompanySettings, CompanyProperties >::GetDescription
SaveLoadTable GetDescription() const override
Definition saveload.h:583
SaveLoadHandler::GetLoadDescription
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
Definition saveload.cpp:3324
SlAllowListData
Definition company_sl.cpp:444
SlAllowListData::GetVector
std::vector< std::string > & GetVector(CompanyProperties *cprops) const override
Get instance of vector to load/save.
Definition company_sl.cpp:455
SlCompanyEconomy
Definition company_sl.cpp:320
SlCompanyLiveries
Definition company_sl.cpp:380
SlCompanyLiveries::GetNumLiveries
size_t GetNumLiveries() const
Get the number of liveries used by this savegame version.
Definition company_sl.cpp:393
SlCompanyOldAIBuildRec
Definition company_sl.cpp:247
SlCompanyOldAIBuildRec::GetDescription
SaveLoadTable GetDescription() const override
Get the description of the fields in the savegame.
Definition company_sl.cpp:252
SlCompanyOldAI
Definition company_sl.cpp:264
SlCompanyOldEconomy
Definition company_sl.cpp:355
SlCompanySettings
Definition company_sl.cpp:283
VectorSaveLoadHandler
Default handler for saving/loading a vector to/from disk.
Definition saveload.h:1365
_company_colours
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
Definition company_cmd.cpp:54
GenderEthnicity
GenderEthnicity
The gender/race combinations that we have faces for.
Definition company_manager_face.h:19
GE_WF
@ GE_WF
A female of Caucasian origin (white)
Definition company_manager_face.h:24
GE_WM
@ GE_WM
A male of Caucasian origin (white)
Definition company_manager_face.h:23
ETHNICITY_BLACK
@ ETHNICITY_BLACK
This bit set means black, otherwise white.
Definition company_manager_face.h:21
GENDER_FEMALE
@ GENDER_FEMALE
This bit set means a female, otherwise male.
Definition company_manager_face.h:20
SetCompanyManagerFaceBits
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.
Definition company_manager_face.h:111
ScaleCompanyManagerFaceValue
uint ScaleCompanyManagerFaceValue(CompanyManagerFaceVariable cmfv, GenderEthnicity ge, uint val)
Scales a company manager's face bits variable to the correct scope.
Definition company_manager_face.h:164
AfterLoadCompanyStats
void AfterLoadCompanyStats()
Rebuilding of company statistics after loading a savegame.
Definition company_sl.cpp:96
ConvertFromOldCompanyManagerFace
CompanyManagerFace ConvertFromOldCompanyManagerFace(uint32_t face)
Converts an old company manager's face format to the new company manager's face format.
Definition company_sl.cpp:45
company_sl_compat.h
Loading of company chunks before table headers were added.
_company_liveries_compat
const SaveLoadCompat _company_liveries_compat[]
Original field order for SlCompanyLiveries.
Definition company_sl_compat.h:83
_company_old_ai_compat
const SaveLoadCompat _company_old_ai_compat[]
Original field order for SlCompanyOldAI.
Definition company_sl_compat.h:25
_company_old_ai_buildrec_compat
const SaveLoadCompat _company_old_ai_buildrec_compat[]
Original field order for SlCompanyOldAIBuildRec.
Definition company_sl_compat.h:16
_company_economy_compat
const SaveLoadCompat _company_economy_compat[]
Original field order for SlCompanyEconomy.
Definition company_sl_compat.h:73
_company_sl_compat
const SaveLoadCompat _company_sl_compat[]
Original field order for company_desc.
Definition company_sl_compat.h:90
_company_settings_compat
const SaveLoadCompat _company_settings_compat[]
Original field order for SlCompanySettings.
Definition company_sl_compat.h:57
CompanyManagerFace
uint32_t CompanyManagerFace
Company manager face bits, info see in company_manager_face.h.
Definition company_type.h:53
LOCK_DEPOT_TILE_FACTOR
static const uint LOCK_DEPOT_TILE_FACTOR
Multiplier for how many regular tiles a lock counts.
Definition economy_type.h:249
LEVELCROSSING_TRACKBIT_FACTOR
static const uint LEVELCROSSING_TRACKBIT_FACTOR
Multiplier for how many regular track bits a level crossing counts.
Definition economy_type.h:243
TUNNELBRIDGE_TRACKBIT_FACTOR
static const uint TUNNELBRIDGE_TRACKBIT_FACTOR
Multiplier for how many regular track bits a tunnel/bridge counts.
Definition economy_type.h:241
_load_check_data
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Definition fios_gui.cpp:41
settings
fluid_settings_t * settings
FluidSynth settings handle.
Definition fluidsynth.cpp:21
ClampU
constexpr uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Definition math_func.hpp:150
IsInsideMM
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition math_func.hpp:268
GetRailType
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Definition rail_map.h:115
GetTrackBits
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
Definition rail_map.h:136
GetPresentSignals
uint GetPresentSignals(Tile tile)
Get whether the given signals are present (Along/AgainstTrackDir)
Definition rail_map.h:393
IsPlainRail
static debug_inline bool IsPlainRail(Tile t)
Returns whether this is plain rails, with or without signals.
Definition rail_map.h:49
HasSignals
bool HasSignals(Tile t)
Checks if a rail tile has signals.
Definition rail_map.h:72
IsRoadDepot
static debug_inline bool IsRoadDepot(Tile t)
Return whether a tile is a road depot.
Definition road_map.h:106
GetRoadBits
RoadBits GetRoadBits(Tile t, RoadTramType rtt)
Get the present road bits for a specific road type.
Definition road_map.h:128
GetRoadOwner
Owner GetRoadOwner(Tile t, RoadTramType rtt)
Get the owner of a specific road type.
Definition road_map.h:234
IsLevelCrossing
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
Definition road_map.h:85
IsNormalRoad
static debug_inline bool IsNormalRoad(Tile t)
Return whether a tile is a normal road.
Definition road_map.h:64
RoadType
RoadType
The different roadtypes we support.
Definition road_type.h:25
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition road_type.h:30
SlCompatTableHeader
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
Definition saveload.cpp:1924
SlGetStructListLength
size_t SlGetStructListLength(size_t limit)
Get the length of this list; if it exceeds the limit, error out.
Definition saveload.cpp:1720
SlIterateArray
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition saveload.cpp:659
SlErrorCorrupt
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
Definition saveload.cpp:351
SlObject
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
Definition saveload.cpp:1733
SlTableHeader
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
Definition saveload.cpp:1786
SlSetStructListLength
void SlSetStructListLength(size_t length)
Set the length of this list.
Definition saveload.cpp:1704
saveload.h
Functions/types related to saving and loading games.
SLEG_STRUCTLIST
#define SLEG_STRUCTLIST(name, handler)
Storage of a list of structs in every savegame version.
Definition saveload.h:1241
SLF_ALLOW_CONTROL
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
Definition saveload.h:688
ChunkHandlerRef
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
Definition saveload.h:509
ChunkHandlerTable
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
Definition saveload.h:512
SLE_CONDARR
#define SLE_CONDARR(base, variable, type, length, from, to)
Storage of a fixed-size array of SL_VAR elements in some savegame versions.
Definition saveload.h:900
SaveLoadCompatTable
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
Definition saveload.h:518
SLEG_STRUCT
#define SLEG_STRUCT(name, handler)
Storage of a structs in every savegame version.
Definition saveload.h:1218
SLEG_CONDSTRUCT
#define SLEG_CONDSTRUCT(name, handler, from, to)
Storage of a structs in some savegame versions.
Definition saveload.h:1149
SLE_CONDSSTR
#define SLE_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
Definition saveload.h:933
SLE_CONDVECTOR
#define SLE_CONDVECTOR(base, variable, type, from, to)
Storage of a vector of SL_VAR elements in some savegame versions.
Definition saveload.h:974
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition saveload.h:868
IsSavegameVersionBefore
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
Definition saveload.h:1263
SLE_SSTR
#define SLE_SSTR(base, variable, type)
Storage of a std::string in every savegame version.
Definition saveload.h:1046
SLV_175
@ SLV_175
175 24136
Definition saveload.h:253
SLV_16
@ SLV_16
16.0 2817 16.1 3155
Definition saveload.h:60
SLV_84
@ SLV_84
84 11822
Definition saveload.h:143
SLV_107
@ SLV_107
107 15027
Definition saveload.h:171
SLV_85
@ SLV_85
85 11874
Definition saveload.h:145
SLV_6
@ SLV_6
6.0 1721 6.1 1768
Definition saveload.h:46
SLV_34
@ SLV_34
34 6455
Definition saveload.h:83
SLV_EXTEND_CARGOTYPES
@ SLV_EXTEND_CARGOTYPES
199 PR#6802 Extend cargotypes to 64
Definition saveload.h:282
SLV_SAVELOAD_LIST_LENGTH
@ SLV_SAVELOAD_LIST_LENGTH
293 PR#9374 Consistency in list length with SL_STRUCT / SL_STRUCTLIST / SL_DEQUE / SL_REFLIST.
Definition saveload.h:331
SLV_65
@ SLV_65
65 10210
Definition saveload.h:121
SLV_120
@ SLV_120
120 16439
Definition saveload.h:187
SLV_170
@ SLV_170
170 23826
Definition saveload.h:247
SL_MAX_VERSION
@ SL_MAX_VERSION
Highest possible saveload version.
Definition saveload.h:399
SLV_1
@ SLV_1
1.0 0.1.x, 0.2.x
Definition saveload.h:33
SL_MIN_VERSION
@ SL_MIN_VERSION
First savegame version.
Definition saveload.h:31
SLV_63
@ SLV_63
63 9956
Definition saveload.h:118
SLV_104
@ SLV_104
104 14735
Definition saveload.h:167
SLV_2
@ SLV_2
2.0 0.3.0 2.1 0.3.1, 0.3.2
Definition saveload.h:34
SLV_GROUP_LIVERIES
@ SLV_GROUP_LIVERIES
205 PR#7108 Livery storage change and group liveries.
Definition saveload.h:290
SLV_COMPANY_ALLOW_LIST_V2
@ 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...
Definition saveload.h:389
SLV_COMPANY_ALLOW_LIST
@ SLV_COMPANY_ALLOW_LIST
335 PR#12337 Saving of list of client keys that are allowed to join this company.
Definition saveload.h:382
SLV_19
@ SLV_19
19 3396
Definition saveload.h:65
SLV_156
@ SLV_156
156 21728
Definition saveload.h:230
SLV_31
@ SLV_31
31 5999
Definition saveload.h:80
SLV_MAX_LOAN_FOR_COMPANY
@ SLV_MAX_LOAN_FOR_COMPANY
330 PR#11224 Separate max loan for each company.
Definition saveload.h:376
SLE_CONDREF
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
Definition saveload.h:889
REF_ENGINE_RENEWS
@ REF_ENGINE_RENEWS
Load/save a reference to an engine renewal (autoreplace).
Definition saveload.h:607
SaveLoadTable
std::span< const struct SaveLoad > SaveLoadTable
A table of SaveLoad entries.
Definition saveload.h:515
SLEG_CONDSTRUCTLIST
#define SLEG_CONDSTRUCTLIST(name, handler, from, to)
Storage of a list of structs in some savegame versions.
Definition saveload.h:1178
SLE_VAR
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition saveload.h:1002
GetStationType
StationType GetStationType(Tile t)
Get the station type of this tile.
Definition station_map.h:44
IsBuoy
bool IsBuoy(Tile t)
Is tile t a buoy tile?
Definition station_map.h:400
IsStationTileBlocked
bool IsStationTileBlocked(Tile t)
Is tile t a blocked tile?
Definition station_map.h:431
FACIL_AIRPORT
@ FACIL_AIRPORT
Station with an airport.
Definition station_type.h:57
lengthof
#define lengthof(array)
Return the length of an fixed size array.
Definition stdafx.h:280
GetStringTab
StringTab GetStringTab(StringID str)
Extract the StringTab from a StringID.
Definition strings_func.h:25
ChunkHandler
Handlers and description of chunk.
Definition saveload.h:463
CompanyEconomyEntry
Statistics about the economy.
Definition company_base.h:24
CompanyInfrastructure::road
std::array< uint32_t, ROADTYPE_END > road
Count of company owned track bits for each road type.
Definition company_base.h:34
CompanyInfrastructure::station
uint32_t station
Count of company owned station tiles.
Definition company_base.h:37
CompanyInfrastructure::signal
uint32_t signal
Count of company owned signals.
Definition company_base.h:35
CompanyInfrastructure::rail
std::array< uint32_t, RAILTYPE_END > rail
Count of company owned track bits for each rail type.
Definition company_base.h:33
CompanyInfrastructure::water
uint32_t water
Count of company owned track bits for canals.
Definition company_base.h:36
CompanyOldAI
Definition company_sl.cpp:243
CompanyProperties
Statically loadable part of Company pool item.
Definition company_base.h:69
CompanyProperties::allow_list
NetworkAuthorizedKeys allow_list
Public keys of clients that are allowed to join this company.
Definition company_base.h:78
CompanyProperties::old_economy
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
Definition company_base.h:116
CompanyProperties::is_ai
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Definition company_base.h:112
CompanyProperties::cur_economy
CompanyEconomyEntry cur_economy
Economic data of the company of this quarter.
Definition company_base.h:115
CompanyProperties::colour
Colours colour
Company colour.
Definition company_base.h:87
CompanyProperties::num_valid_stat_ent
uint8_t num_valid_stat_ent
Number of valid statistical entries in old_economy.
Definition company_base.h:117
Company
Definition company_base.h:133
Company::infrastructure
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition company_base.h:147
Livery
Information about a particular livery.
Definition livery.h:78
Livery::colour2
Colours colour2
Second colour, for vehicles with 2CC support.
Definition livery.h:81
Livery::colour1
Colours colour1
First colour, for all vehicles.
Definition livery.h:80
Livery::in_use
uint8_t in_use
Bit 0 set if this livery should override the default livery first colour, Bit 1 for the second colour...
Definition livery.h:79
LoadCheckData::companies
CompanyPropertiesMap companies
Company information.
Definition fios.h:43
Map
Size related data of the map.
Definition map_func.h:206
PLYRChunkHandler
Definition company_sl.cpp:519
PLYRChunkHandler::Save
void Save() const override
Save the chunk.
Definition company_sl.cpp:522
PLYRChunkHandler::Load
void Load() const override
Load the chunk.
Definition company_sl.cpp:532
PLYRChunkHandler::FixPointers
void FixPointers() const override
Fix the pointers.
Definition company_sl.cpp:578
PLYRChunkHandler::LoadCheck
void LoadCheck(size_t) const override
Load the chunk for game preview.
Definition company_sl.cpp:545
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition pool_type.hpp:328
Pool::PoolItem<&_company_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition pool_type.hpp:388
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition pool_type.hpp:350
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition pool_type.hpp:339
SaveLoad
SaveLoad type struct.
Definition saveload.h:717
SlAllowListData::KeyWrapper
Definition company_sl.cpp:446
Station
Station data structure.
Definition station_base.h:439
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
GetTileOwner
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
GetTileType
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
Definition tile_map.h:96
MP_ROAD
@ MP_ROAD
A tile with road (or tram tracks)
Definition tile_type.h:50
MP_STATION
@ MP_STATION
A tile of a station.
Definition tile_type.h:53
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition tile_type.h:57
MP_WATER
@ MP_WATER
Water tile.
Definition tile_type.h:54
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition tile_type.h:49
MP_OBJECT
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Definition tile_type.h:58
TracksOverlap
bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
Definition track_func.h:645
TrackBits
TrackBits
Allow incrementing of Track variables.
Definition track_type.h:35
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition transport_type.h:27
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition transport_type.h:28
TRANSPORT_WATER
@ TRANSPORT_WATER
Transport over water.
Definition transport_type.h:29
GetTunnelBridgeLength
uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
Definition tunnelbridge.h:25
GetTunnelBridgeTransportType
TransportType GetTunnelBridgeTransportType(Tile t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
Definition tunnelbridge_map.h:39
GetOtherTunnelBridgeEnd
TileIndex GetOtherTunnelBridgeEnd(Tile t)
Determines type of the wormhole and returns its other end.
Definition tunnelbridge_map.h:78
IsShipDepot
bool IsShipDepot(Tile t)
Is it a water tile with a ship depot on it?
Definition water_map.h:222
WATER_CLASS_CANAL
@ WATER_CLASS_CANAL
Canal.
Definition water_map.h:41
GetWaterClass
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
Definition water_map.h:112
GetLockPart
uint8_t GetLockPart(Tile t)
Get the part of a lock.
Definition water_map.h:326
IsLock
bool IsLock(Tile t)
Is there a lock on a given water tile?
Definition water_map.h:303
LOCK_PART_MIDDLE
@ LOCK_PART_MIDDLE
Middle part of a lock.
Definition water_map.h:66