OpenTTD Source  12.0-beta2
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"
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 
46 {
47  CompanyManagerFace cmf = 0;
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 
97 {
98  /* Reset infrastructure statistics to zero. */
99  for (Company *c : Company::Iterate()) MemSetT(&c->infrastructure, 0);
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 (TileIndex tile = 0; tile < MapSize(); tile++) {
110  switch (GetTileType(tile)) {
111  case MP_RAILWAY:
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 
123  }
124  break;
125 
126  case MP_ROAD: {
127  if (IsLevelCrossing(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:
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  /* Iterate all present road types as each can have a different owner. */
156  for (RoadTramType rtt : _roadtramtypes) {
157  RoadType rt = GetRoadType(tile, rtt);
158  if (rt == INVALID_ROADTYPE) continue;
159  c = Company::GetIfValid(GetRoadOwner(tile, rtt));
160  if (c != nullptr) c->infrastructure.road[rt] += 2; // A road stop has two road bits.
161  }
162  break;
163  }
164 
165  case STATION_DOCK:
166  case STATION_BUOY:
167  if (GetWaterClass(tile) == WATER_CLASS_CANAL) {
168  if (c != nullptr) c->infrastructure.water++;
169  }
170  break;
171 
172  default:
173  break;
174  }
175  break;
176 
177  case MP_WATER:
178  if (IsShipDepot(tile) || IsLock(tile)) {
180  if (c != nullptr) {
182  if (IsLock(tile) && GetLockPart(tile) == LOCK_PART_MIDDLE) {
183  /* The middle tile specifies the owner of the lock. */
184  c->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // the middle tile specifies the owner of the
185  break; // do not count the middle tile as canal
186  }
187  }
188  }
189  FALLTHROUGH;
190 
191  case MP_OBJECT:
192  if (GetWaterClass(tile) == WATER_CLASS_CANAL) {
194  if (c != nullptr) c->infrastructure.water++;
195  }
196  break;
197 
198  case MP_TUNNELBRIDGE: {
199  /* Only count the tunnel/bridge if we're on the northern end tile. */
200  TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
201  if (tile < other_end) {
202  /* Count each tunnel/bridge TUNNELBRIDGE_TRACKBIT_FACTOR times to simulate
203  * the higher structural maintenance needs, and don't forget the end tiles. */
204  uint len = (GetTunnelBridgeLength(tile, other_end) + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
205 
206  switch (GetTunnelBridgeTransportType(tile)) {
207  case TRANSPORT_RAIL:
209  if (c != nullptr) c->infrastructure.rail[GetRailType(tile)] += len;
210  break;
211 
212  case TRANSPORT_ROAD: {
213  /* Iterate all present road types as each can have a different owner. */
214  for (RoadTramType rtt : _roadtramtypes) {
215  RoadType rt = GetRoadType(tile, rtt);
216  if (rt == INVALID_ROADTYPE) continue;
217  c = Company::GetIfValid(GetRoadOwner(tile, rtt));
218  if (c != nullptr) c->infrastructure.road[rt] += len * 2; // A full diagonal road has two road bits.
219  }
220  break;
221  }
222 
223  case TRANSPORT_WATER:
225  if (c != nullptr) c->infrastructure.water += len;
226  break;
227 
228  default:
229  break;
230  }
231  }
232  break;
233  }
234 
235  default:
236  break;
237  }
238  }
239 }
240 
241 /* We do need to read this single value, as the bigger it gets, the more data is stored */
242 struct CompanyOldAI {
243  uint8 num_build_rec;
244 };
245 
246 class SlCompanyOldAIBuildRec : public DefaultSaveLoadHandler<SlCompanyOldAIBuildRec, CompanyOldAI> {
247 public:
248  inline static const SaveLoad description[] = {{}}; // Needed to keep DefaultSaveLoadHandler happy.
249  inline const static SaveLoadCompatTable compat_description = _company_old_ai_buildrec_compat;
250 
251  SaveLoadTable GetDescription() const override { return {}; }
252 
253  void Load(CompanyOldAI *old_ai) const override
254  {
255  for (int i = 0; i != old_ai->num_build_rec; i++) {
256  SlObject(nullptr, this->GetLoadDescription());
257  }
258  }
259 
260  void LoadCheck(CompanyOldAI *old_ai) const override { this->Load(old_ai); }
261 };
262 
263 class SlCompanyOldAI : public DefaultSaveLoadHandler<SlCompanyOldAI, CompanyProperties> {
264 public:
265  inline static const SaveLoad description[] = {
266  SLE_CONDVAR(CompanyOldAI, num_build_rec, SLE_UINT8, SL_MIN_VERSION, SLV_107),
268  };
269  inline const static SaveLoadCompatTable compat_description = _company_old_ai_compat;
270 
271  void Load(CompanyProperties *c) const override
272  {
273  if (!c->is_ai) return;
274 
275  CompanyOldAI old_ai;
276  SlObject(&old_ai, this->GetLoadDescription());
277  }
278 
279  void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
280 };
281 
282 class SlCompanySettings : public DefaultSaveLoadHandler<SlCompanySettings, CompanyProperties> {
283 public:
284  inline static const SaveLoad description[] = {
285  /* Engine renewal settings */
287  SLE_CONDVAR(CompanyProperties, settings.engine_renew, SLE_BOOL, SLV_16, SL_MAX_VERSION),
288  SLE_CONDVAR(CompanyProperties, settings.engine_renew_months, SLE_INT16, SLV_16, SL_MAX_VERSION),
289  SLE_CONDVAR(CompanyProperties, settings.engine_renew_money, SLE_UINT32, SLV_16, SL_MAX_VERSION),
290  SLE_CONDVAR(CompanyProperties, settings.renew_keep_length, SLE_BOOL, SLV_2, SL_MAX_VERSION),
291 
292  /* Default vehicle settings */
293  SLE_CONDVAR(CompanyProperties, settings.vehicle.servint_ispercent, SLE_BOOL, SLV_120, SL_MAX_VERSION),
294  SLE_CONDVAR(CompanyProperties, settings.vehicle.servint_trains, SLE_UINT16, SLV_120, SL_MAX_VERSION),
295  SLE_CONDVAR(CompanyProperties, settings.vehicle.servint_roadveh, SLE_UINT16, SLV_120, SL_MAX_VERSION),
296  SLE_CONDVAR(CompanyProperties, settings.vehicle.servint_aircraft, SLE_UINT16, SLV_120, SL_MAX_VERSION),
297  SLE_CONDVAR(CompanyProperties, settings.vehicle.servint_ships, SLE_UINT16, SLV_120, SL_MAX_VERSION),
298  };
299  inline const static SaveLoadCompatTable compat_description = _company_settings_compat;
300 
301  void Save(CompanyProperties *c) const override
302  {
303  SlObject(c, this->GetDescription());
304  }
305 
306  void Load(CompanyProperties *c) const override
307  {
308  SlObject(c, this->GetLoadDescription());
309  }
310 
311  void FixPointers(CompanyProperties *c) const override
312  {
313  SlObject(c, this->GetDescription());
314  }
315 
316  void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
317 };
318 
319 class SlCompanyEconomy : public DefaultSaveLoadHandler<SlCompanyEconomy, CompanyProperties> {
320 public:
321  inline static const SaveLoad description[] = {
322  SLE_CONDVAR(CompanyEconomyEntry, income, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_2),
323  SLE_CONDVAR(CompanyEconomyEntry, income, SLE_INT64, SLV_2, SL_MAX_VERSION),
324  SLE_CONDVAR(CompanyEconomyEntry, expenses, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_2),
325  SLE_CONDVAR(CompanyEconomyEntry, expenses, SLE_INT64, SLV_2, SL_MAX_VERSION),
326  SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_2),
327  SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_INT64, SLV_2, SL_MAX_VERSION),
328 
329  SLE_CONDVAR(CompanyEconomyEntry, delivered_cargo[NUM_CARGO - 1], SLE_INT32, SL_MIN_VERSION, SLV_170),
330  SLE_CONDARR(CompanyEconomyEntry, delivered_cargo, SLE_UINT32, 32, SLV_170, SLV_EXTEND_CARGOTYPES),
332  SLE_VAR(CompanyEconomyEntry, performance_history, SLE_INT32),
333  };
334  inline const static SaveLoadCompatTable compat_description = _company_economy_compat;
335 
336  void Save(CompanyProperties *c) const override
337  {
338  SlObject(&c->cur_economy, this->GetDescription());
339  }
340 
341  void Load(CompanyProperties *c) const override
342  {
343  SlObject(&c->cur_economy, this->GetLoadDescription());
344  }
345 
346  void FixPointers(CompanyProperties *c) const override
347  {
348  SlObject(&c->cur_economy, this->GetDescription());
349  }
350 
351  void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
352 };
353 
355 public:
356  void Save(CompanyProperties *c) const override
357  {
359  for (int i = 0; i < c->num_valid_stat_ent; i++) {
360  SlObject(&c->old_economy[i], this->GetDescription());
361  }
362  }
363 
364  void Load(CompanyProperties *c) const override
365  {
367  c->num_valid_stat_ent = (uint8)SlGetStructListLength(UINT8_MAX);
368  }
369  if (c->num_valid_stat_ent > lengthof(c->old_economy)) SlErrorCorrupt("Too many old economy entries");
370 
371  for (int i = 0; i < c->num_valid_stat_ent; i++) {
372  SlObject(&c->old_economy[i], this->GetLoadDescription());
373  }
374  }
375 
376  void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
377 };
378 
379 class SlCompanyLiveries : public DefaultSaveLoadHandler<SlCompanyLiveries, CompanyProperties> {
380 public:
381  inline static const SaveLoad description[] = {
382  SLE_CONDVAR(Livery, in_use, SLE_UINT8, SLV_34, SL_MAX_VERSION),
383  SLE_CONDVAR(Livery, colour1, SLE_UINT8, SLV_34, SL_MAX_VERSION),
384  SLE_CONDVAR(Livery, colour2, SLE_UINT8, SLV_34, SL_MAX_VERSION),
385  };
386  inline const static SaveLoadCompatTable compat_description = _company_liveries_compat;
387 
392  size_t GetNumLiveries() const
393  {
394  if (IsSavegameVersionBefore(SLV_63)) return LS_END - 4;
395  if (IsSavegameVersionBefore(SLV_85)) return LS_END - 2;
397  /* Read from the savegame how long the list is. */
398  return SlGetStructListLength(LS_END);
399  }
400 
401  void Save(CompanyProperties *c) const override
402  {
403  SlSetStructListLength(LS_END);
404  for (int i = 0; i < LS_END; i++) {
405  SlObject(&c->livery[i], this->GetDescription());
406  }
407  }
408 
409  void Load(CompanyProperties *c) const override
410  {
411  size_t num_liveries = this->GetNumLiveries();
412  bool update_in_use = IsSavegameVersionBefore(SLV_GROUP_LIVERIES);
413 
414  for (size_t i = 0; i < num_liveries; i++) {
415  SlObject(&c->livery[i], this->GetLoadDescription());
416  if (update_in_use && i != LS_DEFAULT) {
417  if (c->livery[i].in_use == 0) {
418  c->livery[i].colour1 = c->livery[LS_DEFAULT].colour1;
419  c->livery[i].colour2 = c->livery[LS_DEFAULT].colour2;
420  } else {
421  c->livery[i].in_use = 3;
422  }
423  }
424  }
425 
427  /* We want to insert some liveries somewhere in between. This means some have to be moved. */
428  memmove(&c->livery[LS_FREIGHT_WAGON], &c->livery[LS_PASSENGER_WAGON_MONORAIL], (LS_END - LS_FREIGHT_WAGON) * sizeof(c->livery[0]));
429  c->livery[LS_PASSENGER_WAGON_MONORAIL] = c->livery[LS_MONORAIL];
430  c->livery[LS_PASSENGER_WAGON_MAGLEV] = c->livery[LS_MAGLEV];
431  }
432 
434  /* Copy bus/truck liveries over to trams */
435  c->livery[LS_PASSENGER_TRAM] = c->livery[LS_BUS];
436  c->livery[LS_FREIGHT_TRAM] = c->livery[LS_TRUCK];
437  }
438  }
439 
440  void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
441 };
442 
443 /* Save/load of companies */
444 static const SaveLoad _company_desc[] = {
445  SLE_VAR(CompanyProperties, name_2, SLE_UINT32),
446  SLE_VAR(CompanyProperties, name_1, SLE_STRINGID),
448 
449  SLE_VAR(CompanyProperties, president_name_1, SLE_STRINGID),
450  SLE_VAR(CompanyProperties, president_name_2, SLE_UINT32),
452 
453  SLE_VAR(CompanyProperties, face, SLE_UINT32),
454 
455  /* money was changed to a 64 bit field in savegame version 1. */
456  SLE_CONDVAR(CompanyProperties, money, SLE_VAR_I64 | SLE_FILE_I32, SL_MIN_VERSION, SLV_1),
457  SLE_CONDVAR(CompanyProperties, money, SLE_INT64, SLV_1, SL_MAX_VERSION),
458 
459  SLE_CONDVAR(CompanyProperties, current_loan, SLE_VAR_I64 | SLE_FILE_I32, SL_MIN_VERSION, SLV_65),
460  SLE_CONDVAR(CompanyProperties, current_loan, SLE_INT64, SLV_65, SL_MAX_VERSION),
461 
462  SLE_VAR(CompanyProperties, colour, SLE_UINT8),
463  SLE_VAR(CompanyProperties, money_fraction, SLE_UINT8),
464  SLE_VAR(CompanyProperties, block_preview, SLE_UINT8),
465 
466  SLE_CONDVAR(CompanyProperties, location_of_HQ, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
467  SLE_CONDVAR(CompanyProperties, location_of_HQ, SLE_UINT32, SLV_6, SL_MAX_VERSION),
468  SLE_CONDVAR(CompanyProperties, last_build_coordinate, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
469  SLE_CONDVAR(CompanyProperties, last_build_coordinate, SLE_UINT32, SLV_6, SL_MAX_VERSION),
470  SLE_CONDVAR(CompanyProperties, inaugurated_year, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
471  SLE_CONDVAR(CompanyProperties, inaugurated_year, SLE_INT32, SLV_31, SL_MAX_VERSION),
472 
473  SLE_ARR(CompanyProperties, share_owners, SLE_UINT8, 4),
474 
475  SLE_CONDVAR(CompanyProperties, num_valid_stat_ent, SLE_UINT8, SL_MIN_VERSION, SLV_SAVELOAD_LIST_LENGTH),
476 
477  SLE_VAR(CompanyProperties, months_of_bankruptcy, SLE_UINT8),
478  SLE_CONDVAR(CompanyProperties, bankrupt_asked, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_104),
479  SLE_CONDVAR(CompanyProperties, bankrupt_asked, SLE_UINT16, SLV_104, SL_MAX_VERSION),
480  SLE_VAR(CompanyProperties, bankrupt_timeout, SLE_INT16),
481  SLE_CONDVAR(CompanyProperties, bankrupt_value, SLE_VAR_I64 | SLE_FILE_I32, SL_MIN_VERSION, SLV_65),
482  SLE_CONDVAR(CompanyProperties, bankrupt_value, SLE_INT64, SLV_65, SL_MAX_VERSION),
483 
484  /* yearly expenses was changed to 64-bit in savegame version 2. */
485  SLE_CONDARR(CompanyProperties, yearly_expenses, SLE_FILE_I32 | SLE_VAR_I64, 3 * 13, SL_MIN_VERSION, SLV_2),
486  SLE_CONDARR(CompanyProperties, yearly_expenses, SLE_INT64, 3 * 13, SLV_2, SL_MAX_VERSION),
487 
489 
490  SLE_CONDVAR(CompanyProperties, terraform_limit, SLE_UINT32, SLV_156, SL_MAX_VERSION),
491  SLE_CONDVAR(CompanyProperties, clear_limit, SLE_UINT32, SLV_156, SL_MAX_VERSION),
492  SLE_CONDVAR(CompanyProperties, tree_limit, SLE_UINT32, SLV_175, SL_MAX_VERSION),
493  SLEG_STRUCT("settings", SlCompanySettings),
495  SLEG_STRUCT("cur_economy", SlCompanyEconomy),
496  SLEG_STRUCTLIST("old_economy", SlCompanyOldEconomy),
498 };
499 
501  PLYRChunkHandler() : ChunkHandler('PLYR', CH_TABLE) {}
502 
503  void Save() const override
504  {
505  SlTableHeader(_company_desc);
506 
507  for (Company *c : Company::Iterate()) {
508  SlSetArrayIndex(c->index);
509  SlObject(c, _company_desc);
510  }
511  }
512 
513  void Load() const override
514  {
515  const std::vector<SaveLoad> slt = SlCompatTableHeader(_company_desc, _company_sl_compat);
516 
517  int index;
518  while ((index = SlIterateArray()) != -1) {
519  Company *c = new (index) Company();
520  SlObject(c, slt);
521  _company_colours[index] = (Colours)c->colour;
522  }
523  }
524 
525 
526  void LoadCheck(size_t) const override
527  {
528  const std::vector<SaveLoad> slt = SlCompatTableHeader(_company_desc, _company_sl_compat);
529 
530  int index;
531  while ((index = SlIterateArray()) != -1) {
532  CompanyProperties *cprops = new CompanyProperties();
533  SlObject(cprops, slt);
534 
535  /* We do not load old custom names */
537  if (GetStringTab(cprops->name_1) == TEXT_TAB_OLD_CUSTOM) {
538  cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
539  }
540 
541  if (GetStringTab(cprops->president_name_1) == TEXT_TAB_OLD_CUSTOM) {
542  cprops->president_name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
543  }
544  }
545 
546  if (cprops->name.empty() && !IsInsideMM(cprops->name_1, SPECSTR_COMPANY_NAME_START, SPECSTR_COMPANY_NAME_LAST + 1) &&
547  cprops->name_1 != STR_GAME_SAVELOAD_NOT_AVAILABLE && cprops->name_1 != STR_SV_UNNAMED &&
548  cprops->name_1 != SPECSTR_ANDCO_NAME && cprops->name_1 != SPECSTR_PRESIDENT_NAME &&
549  cprops->name_1 != SPECSTR_SILLY_NAME) {
550  cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
551  }
552 
553  if (!_load_check_data.companies.Insert(index, cprops)) delete cprops;
554  }
555  }
556 
557  void FixPointers() const override
558  {
559  for (Company *c : Company::Iterate()) {
560  SlObject(c, _company_desc);
561  }
562  }
563 };
564 
565 static const PLYRChunkHandler PLYR;
566 static const ChunkHandlerRef company_chunk_handlers[] = {
567  PLYR,
568 };
569 
570 extern const ChunkHandlerTable _company_chunk_handlers(company_chunk_handlers);
SLEG_CONDSTRUCTLIST
#define SLEG_CONDSTRUCTLIST(name, handler, from, to)
Storage of a list of structs in some savegame versions.
Definition: saveload.h:929
SLV_65
@ SLV_65
65 10210
Definition: saveload.h:125
CompanyProperties::is_ai
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Definition: company_base.h:94
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
GetStringTab
static StringTab GetStringTab(StringID str)
Extract the StringTab from a StringID.
Definition: strings_func.h:23
DefaultSaveLoadHandler
Default handler for saving/loading an object to/from disk.
Definition: saveload.h:515
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
SlCompanyLiveries
Definition: company_sl.cpp:379
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
SlCompanySettings
Definition: company_sl.cpp:282
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:348
SL_MIN_VERSION
@ SL_MIN_VERSION
First savegame version.
Definition: saveload.h:35
SLV_85
@ SLV_85
85 11874
Definition: saveload.h:149
CompanyManagerFace
uint32 CompanyManagerFace
Company manager face bits, info see in company_manager_face.h.
Definition: company_type.h:51
PLYRChunkHandler::FixPointers
void FixPointers() const override
Fix the pointers.
Definition: company_sl.cpp:557
TRANSPORT_RAIL
@ TRANSPORT_RAIL
Transport by train.
Definition: transport_type.h:27
SLE_CONDSSTR
#define SLE_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
Definition: saveload.h:744
Station
Station data structure.
Definition: station_base.h:447
ChunkHandlerRef
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
Definition: saveload.h:443
LEVELCROSSING_TRACKBIT_FACTOR
static const uint LEVELCROSSING_TRACKBIT_FACTOR
Multiplier for how many regular track bits a level crossing counts.
Definition: economy_type.h:224
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:723
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition: road_type.h:27
PLYRChunkHandler::Save
void Save() const override
Save the chunk.
Definition: company_sl.cpp:503
_load_check_data
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Definition: fios_gui.cpp:38
GenderEthnicity
GenderEthnicity
The gender/race combinations that we have faces for.
Definition: company_manager_face.h:19
CompanyInfrastructure::water
uint32 water
Count of company owned track bits for canals.
Definition: company_base.h:34
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:702
SLV_84
@ SLV_84
84 11822
Definition: saveload.h:147
ClampU
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Definition: math_func.hpp:122
SLE_STR
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
Definition: saveload.h:798
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
CompanyInfrastructure::station
uint32 station
Count of company owned station tiles.
Definition: company_base.h:35
TracksOverlap
static bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
Definition: track_func.h:644
MP_RAILWAY
@ MP_RAILWAY
A railway.
Definition: tile_type.h:47
SaveLoadHandler::GetLoadDescription
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
Definition: saveload.cpp:3436
saveload.h
CompanyProperties::name
std::string name
Name of the company if the user changed it.
Definition: company_base.h:58
GetTrackBits
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
Definition: rail_map.h:136
HasSignals
static bool HasSignals(TileIndex t)
Checks if a rail tile has signals.
Definition: rail_map.h:72
SLV_104
@ SLV_104
104 14735
Definition: saveload.h:171
Company::infrastructure
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition: company_base.h:128
ChunkHandler
Handlers and description of chunk.
Definition: saveload.h:406
SLV_175
@ SLV_175
175 24136
Definition: saveload.h:257
SmallMap::Insert
bool Insert(const T &key, const U &data)
Adds new item to this map.
Definition: smallmap_type.hpp:127
SLV_GROUP_LIVERIES
@ SLV_GROUP_LIVERIES
205 PR#7108 Livery storage change and group liveries.
Definition: saveload.h:294
MP_ROAD
@ MP_ROAD
A tile with road (or tram tracks)
Definition: tile_type.h:48
IsLevelCrossing
static bool IsLevelCrossing(TileIndex t)
Return whether a tile is a level crossing.
Definition: road_map.h:84
CompanyEconomyEntry
Statistics about the economy.
Definition: company_base.h:22
SLE_ARR
#define SLE_ARR(base, variable, type, length)
Storage of fixed-size array of SL_VAR elements in every version of a savegame.
Definition: saveload.h:789
GetLockPart
static byte GetLockPart(TileIndex t)
Get the part of a lock.
Definition: water_map.h:320
CountBits
static uint CountBits(T value)
Counts the number of set bits in a variable.
Definition: bitmath_func.hpp:251
SpecializedStation< Station, false >::Iterate
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
Definition: base_station_base.h:270
GetPresentSignals
static uint GetPresentSignals(TileIndex tile)
Get whether the given signals are present (Along/AgainstTrackDir)
Definition: rail_map.h:393
GENDER_FEMALE
@ GENDER_FEMALE
This bit set means a female, otherwise male.
Definition: company_manager_face.h:20
IsInsideMM
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
Definition: math_func.hpp:204
_company_liveries_compat
const SaveLoadCompat _company_liveries_compat[]
Original field order for SlCompanyLiveries.
Definition: company_sl_compat.h:83
TRANSPORT_ROAD
@ TRANSPORT_ROAD
Transport by road vehicle.
Definition: transport_type.h:28
GetRoadBits
static RoadBits GetRoadBits(TileIndex t, RoadTramType rtt)
Get the present road bits for a specific road type.
Definition: road_map.h:127
_company_colours
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
Definition: company_cmd.cpp:48
PLYRChunkHandler
Definition: company_sl.cpp:500
SLF_ALLOW_CONTROL
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
Definition: saveload.h:625
SLV_156
@ SLV_156
156 21728
Definition: saveload.h:234
MapSize
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
CompanyProperties::colour
byte colour
Company colour.
Definition: company_base.h:70
CompanyOldAI
Definition: company_sl.cpp:242
CompanyProperties::num_valid_stat_ent
byte num_valid_stat_ent
Number of valid statistical entries in old_economy.
Definition: company_base.h:99
span
A trimmed down version of what std::span will be in C++20.
Definition: span_type.hpp:60
SLV_31
@ SLV_31
31 5999
Definition: saveload.h:84
SlCompanyOldAI
Definition: company_sl.cpp:263
IsNormalRoad
static bool IsNormalRoad(TileIndex t)
Return whether a tile is a normal road.
Definition: road_map.h:63
MP_OBJECT
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Definition: tile_type.h:56
IsBuoy
static bool IsBuoy(TileIndex t)
Is tile t a buoy tile?
Definition: station_map.h:306
MP_WATER
@ MP_WATER
Water tile.
Definition: tile_type.h:52
GetStationType
static StationType GetStationType(TileIndex t)
Get the station type of this tile.
Definition: station_map.h:44
_company_old_ai_buildrec_compat
const SaveLoadCompat _company_old_ai_buildrec_compat[]
Original field order for SlCompanyOldAIBuildRec.
Definition: company_sl_compat.h:16
AfterLoadCompanyStats
void AfterLoadCompanyStats()
Rebuilding of company statistics after loading a savegame.
Definition: company_sl.cpp:96
IsShipDepot
static bool IsShipDepot(TileIndex t)
Is it a water tile with a ship depot on it?
Definition: water_map.h:216
TUNNELBRIDGE_TRACKBIT_FACTOR
static const uint TUNNELBRIDGE_TRACKBIT_FACTOR
Multiplier for how many regular track bits a tunnel/bridge counts.
Definition: economy_type.h:222
LOCK_PART_MIDDLE
@ LOCK_PART_MIDDLE
Middle part of a lock.
Definition: water_map.h:65
Livery::in_use
byte 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
SlCompanyOldEconomy
Definition: company_sl.cpp:354
SLV_EXTEND_CARGOTYPES
@ SLV_EXTEND_CARGOTYPES
199 PR#6802 Extend cargotypes to 64
Definition: saveload.h:286
SLE_CONDREF
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
Definition: saveload.h:712
SLV_120
@ SLV_120
120 16439
Definition: saveload.h:191
settings
fluid_settings_t * settings
FluidSynth settings handle.
Definition: fluidsynth.cpp:21
IsSavegameVersionBefore
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:1024
MP_TUNNELBRIDGE
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:55
REF_ENGINE_RENEWS
@ REF_ENGINE_RENEWS
Load/save a reference to an engine renewal (autoreplace).
Definition: saveload.h:541
CompanyInfrastructure::road
uint32 road[ROADTYPE_END]
Count of company owned track bits for each road type.
Definition: company_base.h:31
CompanyInfrastructure::signal
uint32 signal
Count of company owned signals.
Definition: company_base.h:32
IsRoadDepot
static bool IsRoadDepot(TileIndex t)
Return whether a tile is a road depot.
Definition: road_map.h:105
WATER_CLASS_CANAL
@ WATER_CLASS_CANAL
Canal.
Definition: water_map.h:49
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:22
SLV_170
@ SLV_170
170 23826
Definition: saveload.h:251
SLV_107
@ SLV_107
107 15027
Definition: saveload.h:175
SlGetStructListLength
size_t SlGetStructListLength(size_t limit)
Get the length of this list; if it exceeds the limit, error out.
Definition: saveload.cpp:1825
SLV_2
@ SLV_2
2.0 0.3.0 2.1 0.3.1, 0.3.2
Definition: saveload.h:38
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
SL_MAX_VERSION
@ SL_MAX_VERSION
Highest possible saveload version.
Definition: saveload.h:342
_company_old_ai_compat
const SaveLoadCompat _company_old_ai_compat[]
Original field order for SlCompanyOldAI.
Definition: company_sl_compat.h:25
LoadCheckData::companies
CompanyPropertiesMap companies
Company information.
Definition: fios.h:41
IsStationTileBlocked
bool IsStationTileBlocked(TileIndex tile)
Check whether a rail station tile is NOT traversable.
Definition: newgrf_station.cpp:867
SLV_16
@ SLV_16
16.0 2817 16.1 3155
Definition: saveload.h:64
SLE_VAR
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition: saveload.h:772
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:386
GetWaterClass
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
Definition: water_map.h:106
_company_sl_compat
const SaveLoadCompat _company_sl_compat[]
Original field order for company_desc.
Definition: company_sl_compat.h:90
CompanyProperties::cur_economy
CompanyEconomyEntry cur_economy
Economic data of the company of this quarter.
Definition: company_base.h:97
company_sl_compat.h
SLV_6
@ SLV_6
6.0 1721 6.1 1768
Definition: saveload.h:50
IsPlainRail
static bool IsPlainRail(TileIndex t)
Returns whether this is plain rails, with or without signals.
Definition: rail_map.h:49
SlErrorCorrupt
void NORETURN SlErrorCorrupt(const char *msg)
Error handler for corrupt savegames.
Definition: saveload.cpp:364
DefaultSaveLoadHandler< SlCompanySettings, CompanyProperties >::GetDescription
SaveLoadTable GetDescription() const override
Definition: saveload.h:517
TRANSPORT_WATER
@ TRANSPORT_WATER
Transport over water.
Definition: transport_type.h:29
CompanyInfrastructure::rail
uint32 rail[RAILTYPE_END]
Count of company owned track bits for each rail type.
Definition: company_base.h:33
GetRailType
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
Definition: rail_map.h:115
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:51
SlCompanyOldAIBuildRec::GetDescription
SaveLoadTable GetDescription() const override
Get the description of the fields in the savegame.
Definition: company_sl.cpp:251
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:65
IsLock
static bool IsLock(TileIndex t)
Is there a lock on a given water tile?
Definition: water_map.h:297
_company_settings_compat
const SaveLoadCompat _company_settings_compat[]
Original field order for SlCompanySettings.
Definition: company_sl_compat.h:57
LOCK_DEPOT_TILE_FACTOR
static const uint LOCK_DEPOT_TILE_FACTOR
Multiplier for how many regular tiles a lock counts.
Definition: economy_type.h:230
CompanyProperties::president_name_1
StringID president_name_1
Name of the president if the user did not change it.
Definition: company_base.h:60
TrackBits
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:38
GetTunnelBridgeLength
static uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
Definition: tunnelbridge.h:25
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:378
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:335
MemSetT
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
Definition: mem_func.hpp:49
SlCompatTableHeader
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
Definition: saveload.cpp:2029
GetRoadOwner
static Owner GetRoadOwner(TileIndex t, RoadTramType rtt)
Get the owner of a specific road type.
Definition: road_map.h:233
SlCompanyEconomy
Definition: company_sl.cpp:319
GetOtherTunnelBridgeEnd
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
Definition: tunnelbridge_map.h:78
SLV_19
@ SLV_19
19 3396
Definition: saveload.h:69
SlCompanyOldAIBuildRec
Definition: company_sl.cpp:246
SetCompanyManagerFaceBits
static 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
GetTileType
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
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:326
GE_WM
@ GE_WM
A male of Caucasian origin (white)
Definition: company_manager_face.h:23
FACIL_AIRPORT
@ FACIL_AIRPORT
Station with an airport.
Definition: station_type.h:55
SlObject
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
Definition: saveload.cpp:1838
ConvertFromOldCompanyManagerFace
CompanyManagerFace ConvertFromOldCompanyManagerFace(uint32 face)
Converts an old company manager's face format to the new company manager's face format.
Definition: company_sl.cpp:45
SlTableHeader
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
Definition: saveload.cpp:1891
ScaleCompanyManagerFaceValue
static 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
SLEG_CONDSTRUCT
#define SLEG_CONDSTRUCT(name, handler, from, to)
Storage of a structs in some savegame versions.
Definition: saveload.h:900
SlSetStructListLength
void SlSetStructListLength(size_t length)
Set the length of this list.
Definition: saveload.cpp:1809
SaveLoad
SaveLoad type struct.
Definition: saveload.h:653
GetTunnelBridgeTransportType
static TransportType GetTunnelBridgeTransportType(TileIndex 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
_company_economy_compat
const SaveLoadCompat _company_economy_compat[]
Original field order for SlCompanyEconomy.
Definition: company_sl_compat.h:73
Company
Definition: company_base.h:115
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:98
ETHNICITY_BLACK
@ ETHNICITY_BLACK
This bit set means black, otherwise white.
Definition: company_manager_face.h:21
SLV_63
@ SLV_63
63 9956
Definition: saveload.h:122
Livery
Information about a particular livery.
Definition: livery.h:78
PLYRChunkHandler::Load
void Load() const override
Load the chunk.
Definition: company_sl.cpp:513
CompanyProperties
Statically loadable part of Company pool item.
Definition: company_base.h:55
SlCompanyLiveries::GetNumLiveries
size_t GetNumLiveries() const
Get the number of liveries used by this savegame version.
Definition: company_sl.cpp:392
SLV_34
@ SLV_34
34 6455
Definition: saveload.h:87
PLYRChunkHandler::LoadCheck
void LoadCheck(size_t) const override
Load the chunk for game preview.
Definition: company_sl.cpp:526
SlIterateArray
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:670
GE_WF
@ GE_WF
A female of Caucasian origin (white)
Definition: company_manager_face.h:24
SLV_1
@ SLV_1
1.0 0.1.x, 0.2.x
Definition: saveload.h:37
CompanyProperties::name_1
StringID name_1
Name of the company if the user did not change it.
Definition: company_base.h:57
SLEG_STRUCTLIST
#define SLEG_STRUCTLIST(name, handler)
Storage of a list of structs in every savegame version.
Definition: saveload.h:999
SLEG_STRUCT
#define SLEG_STRUCT(name, handler)
Storage of a structs in every savegame version.
Definition: saveload.h:976
Livery::colour2
byte colour2
Second colour, for vehicles with 2CC support.
Definition: livery.h:81
Livery::colour1
byte colour1
First colour, for all vehicles.
Definition: livery.h:80