OpenTTD
company_sl.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #include "../stdafx.h"
13 #include "../company_func.h"
14 #include "../company_manager_face.h"
15 #include "../fios.h"
16 #include "../tunnelbridge_map.h"
17 #include "../tunnelbridge.h"
18 #include "../station_base.h"
19 #include "../strings_func.h"
20 
21 #include "saveload.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, 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  Company *c;
100  FOR_ALL_COMPANIES(c) MemSetT(&c->infrastructure, 0);
101 
102  /* Collect airport count. */
103  Station *st;
104  FOR_ALL_STATIONS(st) {
105  if ((st->facilities & FACIL_AIRPORT) && Company::IsValidID(st->owner)) {
106  Company::Get(st->owner)->infrastructure.airport++;
107  }
108  }
109 
110  for (TileIndex tile = 0; tile < MapSize(); tile++) {
111  switch (GetTileType(tile)) {
112  case MP_RAILWAY:
114  if (c != nullptr) {
115  uint pieces = 1;
116  if (IsPlainRail(tile)) {
117  TrackBits bits = GetTrackBits(tile);
118  pieces = CountBits(bits);
119  if (TracksOverlap(bits)) pieces *= pieces;
120  }
121  c->infrastructure.rail[GetRailType(tile)] += pieces;
122 
124  }
125  break;
126 
127  case MP_ROAD: {
128  if (IsLevelCrossing(tile)) {
130  if (c != nullptr) c->infrastructure.rail[GetRailType(tile)] += LEVELCROSSING_TRACKBIT_FACTOR;
131  }
132 
133  /* Iterate all present road types as each can have a different owner. */
134  FOR_ALL_ROADTRAMTYPES(rtt) {
135  RoadType rt = GetRoadType(tile, rtt);
136  if (rt == INVALID_ROADTYPE) continue;
137  c = Company::GetIfValid(IsRoadDepot(tile) ? GetTileOwner(tile) : GetRoadOwner(tile, rtt));
138  /* A level crossings and depots have two road bits. */
139  if (c != nullptr) c->infrastructure.road[rt] += IsNormalRoad(tile) ? CountBits(GetRoadBits(tile, rtt)) : 2;
140  }
141  break;
142  }
143 
144  case MP_STATION:
146  if (c != nullptr && GetStationType(tile) != STATION_AIRPORT && !IsBuoy(tile)) c->infrastructure.station++;
147 
148  switch (GetStationType(tile)) {
149  case STATION_RAIL:
150  case STATION_WAYPOINT:
151  if (c != nullptr && !IsStationTileBlocked(tile)) c->infrastructure.rail[GetRailType(tile)]++;
152  break;
153 
154  case STATION_BUS:
155  case STATION_TRUCK: {
156  /* Iterate all present road types as each can have a different owner. */
157  FOR_ALL_ROADTRAMTYPES(rtt) {
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)) {
181  if (c != nullptr) {
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) {
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:
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_ALL_ROADTRAMTYPES(rtt) {
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:
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 
243 
244 /* Save/load of companies */
245 static const SaveLoad _company_desc[] = {
246  SLE_VAR(CompanyProperties, name_2, SLE_UINT32),
247  SLE_VAR(CompanyProperties, name_1, SLE_STRINGID),
249 
250  SLE_VAR(CompanyProperties, president_name_1, SLE_STRINGID),
251  SLE_VAR(CompanyProperties, president_name_2, SLE_UINT32),
253 
254  SLE_VAR(CompanyProperties, face, SLE_UINT32),
255 
256  /* money was changed to a 64 bit field in savegame version 1. */
257  SLE_CONDVAR(CompanyProperties, money, SLE_VAR_I64 | SLE_FILE_I32, SL_MIN_VERSION, SLV_1),
258  SLE_CONDVAR(CompanyProperties, money, SLE_INT64, SLV_1, SL_MAX_VERSION),
259 
260  SLE_CONDVAR(CompanyProperties, current_loan, SLE_VAR_I64 | SLE_FILE_I32, SL_MIN_VERSION, SLV_65),
261  SLE_CONDVAR(CompanyProperties, current_loan, SLE_INT64, SLV_65, SL_MAX_VERSION),
262 
263  SLE_VAR(CompanyProperties, colour, SLE_UINT8),
264  SLE_VAR(CompanyProperties, money_fraction, SLE_UINT8),
266  SLE_VAR(CompanyProperties, block_preview, SLE_UINT8),
267 
270  SLE_CONDVAR(CompanyProperties, location_of_HQ, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
271  SLE_CONDVAR(CompanyProperties, location_of_HQ, SLE_UINT32, SLV_6, SL_MAX_VERSION),
272  SLE_CONDVAR(CompanyProperties, last_build_coordinate, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
273  SLE_CONDVAR(CompanyProperties, last_build_coordinate, SLE_UINT32, SLV_6, SL_MAX_VERSION),
274  SLE_CONDVAR(CompanyProperties, inaugurated_year, SLE_FILE_U8 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
275  SLE_CONDVAR(CompanyProperties, inaugurated_year, SLE_INT32, SLV_31, SL_MAX_VERSION),
276 
277  SLE_ARR(CompanyProperties, share_owners, SLE_UINT8, 4),
278 
279  SLE_VAR(CompanyProperties, num_valid_stat_ent, SLE_UINT8),
280 
281  SLE_VAR(CompanyProperties, months_of_bankruptcy, SLE_UINT8),
282  SLE_CONDVAR(CompanyProperties, bankrupt_asked, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_104),
283  SLE_CONDVAR(CompanyProperties, bankrupt_asked, SLE_UINT16, SLV_104, SL_MAX_VERSION),
284  SLE_VAR(CompanyProperties, bankrupt_timeout, SLE_INT16),
285  SLE_CONDVAR(CompanyProperties, bankrupt_value, SLE_VAR_I64 | SLE_FILE_I32, SL_MIN_VERSION, SLV_65),
286  SLE_CONDVAR(CompanyProperties, bankrupt_value, SLE_INT64, SLV_65, SL_MAX_VERSION),
287 
288  /* yearly expenses was changed to 64-bit in savegame version 2. */
289  SLE_CONDARR(CompanyProperties, yearly_expenses, SLE_FILE_I32 | SLE_VAR_I64, 3 * 13, SL_MIN_VERSION, SLV_2),
290  SLE_CONDARR(CompanyProperties, yearly_expenses, SLE_INT64, 3 * 13, SLV_2, SL_MAX_VERSION),
291 
295 
296  SLE_CONDVAR(CompanyProperties, terraform_limit, SLE_UINT32, SLV_156, SL_MAX_VERSION),
297  SLE_CONDVAR(CompanyProperties, clear_limit, SLE_UINT32, SLV_156, SL_MAX_VERSION),
298  SLE_CONDVAR(CompanyProperties, tree_limit, SLE_UINT32, SLV_175, SL_MAX_VERSION),
299 
300  SLE_END()
301 };
302 
303 static const SaveLoad _company_settings_desc[] = {
304  /* Engine renewal settings */
305  SLE_CONDNULL(512, SLV_16, SLV_19),
307  SLE_CONDVAR(Company, settings.engine_renew, SLE_BOOL, SLV_16, SL_MAX_VERSION),
308  SLE_CONDVAR(Company, settings.engine_renew_months, SLE_INT16, SLV_16, SL_MAX_VERSION),
309  SLE_CONDVAR(Company, settings.engine_renew_money, SLE_UINT32, SLV_16, SL_MAX_VERSION),
310  SLE_CONDVAR(Company, settings.renew_keep_length, SLE_BOOL, SLV_2, SL_MAX_VERSION),
311 
312  /* Default vehicle settings */
313  SLE_CONDVAR(Company, settings.vehicle.servint_ispercent, SLE_BOOL, SLV_120, SL_MAX_VERSION),
314  SLE_CONDVAR(Company, settings.vehicle.servint_trains, SLE_UINT16, SLV_120, SL_MAX_VERSION),
315  SLE_CONDVAR(Company, settings.vehicle.servint_roadveh, SLE_UINT16, SLV_120, SL_MAX_VERSION),
316  SLE_CONDVAR(Company, settings.vehicle.servint_aircraft, SLE_UINT16, SLV_120, SL_MAX_VERSION),
317  SLE_CONDVAR(Company, settings.vehicle.servint_ships, SLE_UINT16, SLV_120, SL_MAX_VERSION),
318 
319  SLE_CONDNULL(63, SLV_2, SLV_144), // old reserved space
320 
321  SLE_END()
322 };
323 
324 static const SaveLoad _company_settings_skip_desc[] = {
325  /* Engine renewal settings */
326  SLE_CONDNULL(512, SLV_16, SLV_19),
327  SLE_CONDNULL(2, SLV_19, SLV_69), // engine_renew_list
328  SLE_CONDNULL(4, SLV_69, SL_MAX_VERSION), // engine_renew_list
329  SLE_CONDNULL(1, SLV_16, SL_MAX_VERSION), // settings.engine_renew
330  SLE_CONDNULL(2, SLV_16, SL_MAX_VERSION), // settings.engine_renew_months
331  SLE_CONDNULL(4, SLV_16, SL_MAX_VERSION), // settings.engine_renew_money
332  SLE_CONDNULL(1, SLV_2, SL_MAX_VERSION), // settings.renew_keep_length
333 
334  /* Default vehicle settings */
335  SLE_CONDNULL(1, SLV_120, SL_MAX_VERSION), // settings.vehicle.servint_ispercent
336  SLE_CONDNULL(2, SLV_120, SL_MAX_VERSION), // settings.vehicle.servint_trains
337  SLE_CONDNULL(2, SLV_120, SL_MAX_VERSION), // settings.vehicle.servint_roadveh
338  SLE_CONDNULL(2, SLV_120, SL_MAX_VERSION), // settings.vehicle.servint_aircraft
339  SLE_CONDNULL(2, SLV_120, SL_MAX_VERSION), // settings.vehicle.servint_ships
340 
341  SLE_CONDNULL(63, SLV_2, SLV_144), // old reserved space
342 
343  SLE_END()
344 };
345 
346 static const SaveLoad _company_economy_desc[] = {
347  /* these were changed to 64-bit in savegame format 2 */
348  SLE_CONDVAR(CompanyEconomyEntry, income, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_2),
349  SLE_CONDVAR(CompanyEconomyEntry, income, SLE_INT64, SLV_2, SL_MAX_VERSION),
350  SLE_CONDVAR(CompanyEconomyEntry, expenses, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_2),
351  SLE_CONDVAR(CompanyEconomyEntry, expenses, SLE_INT64, SLV_2, SL_MAX_VERSION),
352  SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_2),
353  SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_INT64, SLV_2, SL_MAX_VERSION),
354 
355  SLE_CONDVAR(CompanyEconomyEntry, delivered_cargo[NUM_CARGO - 1], SLE_INT32, SL_MIN_VERSION, SLV_170),
356  SLE_CONDARR(CompanyEconomyEntry, delivered_cargo, SLE_UINT32, 32, SLV_170, SLV_EXTEND_CARGOTYPES),
358  SLE_VAR(CompanyEconomyEntry, performance_history, SLE_INT32),
359 
360  SLE_END()
361 };
362 
363 /* We do need to read this single value, as the bigger it gets, the more data is stored */
364 struct CompanyOldAI {
365  uint8 num_build_rec;
366 };
367 
368 static const SaveLoad _company_ai_desc[] = {
373  SLE_CONDVAR(CompanyOldAI, num_build_rec, SLE_UINT8, SL_MIN_VERSION, SLV_107),
375 
381 
387 
390 
394 
395  SLE_CONDNULL(64, SLV_2, SLV_107),
396  SLE_END()
397 };
398 
399 static const SaveLoad _company_ai_build_rec_desc[] = {
405  SLE_END()
406 };
407 
408 static const SaveLoad _company_livery_desc[] = {
409  SLE_CONDVAR(Livery, in_use, SLE_UINT8, SLV_34, SL_MAX_VERSION),
410  SLE_CONDVAR(Livery, colour1, SLE_UINT8, SLV_34, SL_MAX_VERSION),
411  SLE_CONDVAR(Livery, colour2, SLE_UINT8, SLV_34, SL_MAX_VERSION),
412  SLE_END()
413 };
414 
415 static void SaveLoad_PLYR_common(Company *c, CompanyProperties *cprops)
416 {
417  int i;
418 
419  SlObject(cprops, _company_desc);
420  if (c != nullptr) {
421  SlObject(c, _company_settings_desc);
422  } else {
423  char nothing;
424  SlObject(&nothing, _company_settings_skip_desc);
425  }
426 
427  /* Keep backwards compatible for savegames, so load the old AI block */
428  if (IsSavegameVersionBefore(SLV_107) && cprops->is_ai) {
429  CompanyOldAI old_ai;
430  char nothing;
431 
432  SlObject(&old_ai, _company_ai_desc);
433  for (i = 0; i != old_ai.num_build_rec; i++) {
434  SlObject(&nothing, _company_ai_build_rec_desc);
435  }
436  }
437 
438  /* Write economy */
439  SlObject(&cprops->cur_economy, _company_economy_desc);
440 
441  /* Write old economy entries. */
442  if (cprops->num_valid_stat_ent > lengthof(cprops->old_economy)) SlErrorCorrupt("Too many old economy entries");
443  for (i = 0; i < cprops->num_valid_stat_ent; i++) {
444  SlObject(&cprops->old_economy[i], _company_economy_desc);
445  }
446 
447  /* Write each livery entry. */
448  int num_liveries = IsSavegameVersionBefore(SLV_63) ? LS_END - 4 : (IsSavegameVersionBefore(SLV_85) ? LS_END - 2: LS_END);
449  bool update_in_use = IsSavegameVersionBefore(SLV_GROUP_LIVERIES);
450  if (c != nullptr) {
451  for (i = 0; i < num_liveries; i++) {
452  SlObject(&c->livery[i], _company_livery_desc);
453  if (update_in_use && i != LS_DEFAULT) {
454  if (c->livery[i].in_use == 0) {
455  c->livery[i].colour1 = c->livery[LS_DEFAULT].colour1;
456  c->livery[i].colour2 = c->livery[LS_DEFAULT].colour2;
457  } else {
458  c->livery[i].in_use = 3;
459  }
460  }
461  }
462 
463  if (num_liveries < LS_END) {
464  /* We want to insert some liveries somewhere in between. This means some have to be moved. */
465  memmove(&c->livery[LS_FREIGHT_WAGON], &c->livery[LS_PASSENGER_WAGON_MONORAIL], (LS_END - LS_FREIGHT_WAGON) * sizeof(c->livery[0]));
466  c->livery[LS_PASSENGER_WAGON_MONORAIL] = c->livery[LS_MONORAIL];
467  c->livery[LS_PASSENGER_WAGON_MAGLEV] = c->livery[LS_MAGLEV];
468  }
469 
470  if (num_liveries == LS_END - 4) {
471  /* Copy bus/truck liveries over to trams */
472  c->livery[LS_PASSENGER_TRAM] = c->livery[LS_BUS];
473  c->livery[LS_FREIGHT_TRAM] = c->livery[LS_TRUCK];
474  }
475  } else {
476  /* Skip liveries */
477  Livery dummy_livery;
478  for (i = 0; i < num_liveries; i++) {
479  SlObject(&dummy_livery, _company_livery_desc);
480  }
481  }
482 }
483 
484 static void SaveLoad_PLYR(Company *c)
485 {
486  SaveLoad_PLYR_common(c, c);
487 }
488 
489 static void Save_PLYR()
490 {
491  Company *c;
492  FOR_ALL_COMPANIES(c) {
493  SlSetArrayIndex(c->index);
494  SlAutolength((AutolengthProc*)SaveLoad_PLYR, c);
495  }
496 }
497 
498 static void Load_PLYR()
499 {
500  int index;
501  while ((index = SlIterateArray()) != -1) {
502  Company *c = new (index) Company();
503  SaveLoad_PLYR(c);
504  _company_colours[index] = (Colours)c->colour;
505  }
506 }
507 
508 static void Check_PLYR()
509 {
510  int index;
511  while ((index = SlIterateArray()) != -1) {
512  CompanyProperties *cprops = new CompanyProperties();
513  SaveLoad_PLYR_common(nullptr, cprops);
514 
515  /* We do not load old custom names */
517  if (GetStringTab(cprops->name_1) == TEXT_TAB_OLD_CUSTOM) {
518  cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
519  }
520 
521  if (GetStringTab(cprops->president_name_1) == TEXT_TAB_OLD_CUSTOM) {
522  cprops->president_name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
523  }
524  }
525 
526  if (cprops->name == nullptr && !IsInsideMM(cprops->name_1, SPECSTR_COMPANY_NAME_START, SPECSTR_COMPANY_NAME_LAST + 1) &&
527  cprops->name_1 != STR_GAME_SAVELOAD_NOT_AVAILABLE && cprops->name_1 != STR_SV_UNNAMED &&
528  cprops->name_1 != SPECSTR_ANDCO_NAME && cprops->name_1 != SPECSTR_PRESIDENT_NAME &&
529  cprops->name_1 != SPECSTR_SILLY_NAME) {
530  cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
531  }
532 
533  if (!_load_check_data.companies.Insert(index, cprops)) delete cprops;
534  }
535 }
536 
537 static void Ptrs_PLYR()
538 {
539  Company *c;
540  FOR_ALL_COMPANIES(c) {
541  SlObject(c, _company_settings_desc);
542  }
543 }
544 
545 
546 extern const ChunkHandler _company_chunk_handlers[] = {
547  { 'PLYR', Save_PLYR, Load_PLYR, Ptrs_PLYR, Check_PLYR, CH_ARRAY | CH_LAST},
548 };
#define SLE_CONDNULL(length, from, to)
Empty space in some savegame versions.
Definition: saveload.h:644
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:98
StationFacility facilities
The facilities that this station has.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:257
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:765
static byte GetLockPart(TileIndex t)
Get the part of a lock.
Definition: water_map.h:322
char * name
Name of the company if the user changed it.
Definition: company_base.h:59
A female of Caucasian origin (white)
static const uint LEVELCROSSING_TRACKBIT_FACTOR
Multiplier for how many regular track bits a level crossing counts.
Definition: economy_type.h:215
2.0 0.3.0 2.1 0.3.1, 0.3.2
Definition: saveload.h:35
void AfterLoadCompanyStats()
Rebuilding of company statistics after loading a savegame.
Definition: company_sl.cpp:96
#define SLE_CONDSTR(base, variable, type, length, from, to)
Storage of a string in some savegame versions.
Definition: saveload.h:568
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
Definition: saveload.h:546
void NORETURN SlErrorCorrupt(const char *msg)
Error handler for corrupt savegames.
Definition: saveload.cpp:356
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
107 15027
Definition: saveload.h:172
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
Definition: water_map.h:108
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
This bit set means a female, otherwise male.
A tile with road (or tram tracks)
Definition: tile_type.h:45
Maximal number of cargo types in a game.
Definition: cargo_type.h:66
120 16439
Definition: saveload.h:188
fluid_settings_t * settings
FluidSynth settings handle.
Definition: fluidsynth.cpp:22
Transport over water.
16.0 2817 16.1 3155
Definition: saveload.h:61
104 14735
Definition: saveload.h:168
85 11874
Definition: saveload.h:146
#define SLE_ARR(base, variable, type, length)
Storage of an array in every version of a savegame.
Definition: saveload.h:613
175 24136
Definition: saveload.h:254
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
flag for invalid roadtype
Definition: road_type.h:32
13.1 2080 0.4.0, 0.4.0.1
Definition: saveload.h:57
A railway.
Definition: tile_type.h:44
static StringTab GetStringTab(StringID str)
Extract the StringTab from a StringID.
Definition: strings_func.h:25
Contains objects such as transmitters and owned land.
Definition: tile_type.h:53
A male of Caucasian origin (white)
uint32 station
Count of company owned station tiles.
Definition: company_base.h:36
170 23826
Definition: saveload.h:248
static bool IsLevelCrossing(TileIndex t)
Return whether a tile is a level crossing.
Definition: road_map.h:86
RoadType
The different roadtypes we support.
Definition: road_type.h:27
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
static StationType GetStationType(TileIndex t)
Get the station type of this tile.
Definition: station_map.h:46
58 9762
Definition: saveload.h:113
static uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
Definition: math_func.hpp:184
static bool IsLock(TileIndex t)
Is there a lock on a given water tile?
Definition: water_map.h:299
static uint GetPresentSignals(TileIndex tile)
Get whether the given signals are present (Along/AgainstTrackDir)
Definition: rail_map.h:395
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:266
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Definition: fios_gui.cpp:40
uint32 CompanyManagerFace
Company manager face bits, info see in company_manager_face.h.
Definition: company_type.h:53
Load/save a reference to an engine renewal (autoreplace).
Definition: saveload.h:379
Functions/types related to saving and loading games.
uint32 signal
Count of company owned signals.
Definition: company_base.h:33
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:536
static bool IsBuoy(TileIndex t)
Is tile t a buoy tile?
Definition: station_map.h:308
94 12816
Definition: saveload.h:156
byte num_valid_stat_ent
Number of valid statistical entries in old_economy.
Definition: company_base.h:100
Highest possible saveload version.
Definition: saveload.h:307
static RoadBits GetRoadBits(TileIndex t, RoadTramType rtt)
Get the present road bits for a specific road type.
Definition: road_map.h:129
205 PR#7108 Livery storage change and group liveries.
Definition: saveload.h:291
allow control codes in the strings
Definition: saveload.h:473
34 6455
Definition: saveload.h:84
First savegame version.
Definition: saveload.h:32
CompanyPropertiesMap companies
Company information.
Definition: fios.h:43
Statically loadable part of Company pool item.
Definition: company_base.h:56
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:180
static uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
Definition: tunnelbridge.h:27
uint32 road[ROADTYPE_END]
Count of company owned track bits for each road type.
Definition: company_base.h:32
Water tile.
Definition: tile_type.h:49
Information about a particular livery.
Definition: livery.h:80
static const uint TUNNELBRIDGE_TRACKBIT_FACTOR
Multiplier for how many regular track bits a tunnel/bridge counts.
Definition: economy_type.h:213
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:40
static void SetCompanyManagerFaceBits(CompanyManagerFace &cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge, uint val)
Sets the company manager&#39;s face bits for the given company manager&#39;s face variable.
CompanyManagerFace ConvertFromOldCompanyManagerFace(uint32 face)
Converts an old company manager&#39;s face format to the new company manager&#39;s face format.
Definition: company_sl.cpp:45
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Definition: company_base.h:95
bool Insert(const T &key, const U &data)
Adds new item to this map.
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
84 11822
Definition: saveload.h:144
6.0 1721 6.1 1768
Definition: saveload.h:47
static uint ScaleCompanyManagerFaceValue(CompanyManagerFaceVariable cmfv, GenderEthnicity ge, uint val)
Scales a company manager&#39;s face bits variable to the correct scope.
byte colour2
Second colour, for vehicles with 2CC support.
Definition: livery.h:83
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:639
Handlers and description of chunk.
Definition: saveload.h:358
static bool HasSignals(TileIndex t)
Checks if a rail tile has signals.
Definition: rail_map.h:74
1.0 0.1.x, 0.2.x
Definition: saveload.h:34
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
Definition: rail_map.h:138
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
Definition: company_base.h:133
uint32 rail[RAILTYPE_END]
Count of company owned track bits for each rail type.
Definition: company_base.h:34
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:653
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
Transport by train.
Station with an airport.
Definition: station_type.h:57
112 15290
Definition: saveload.h:178
static uint MapSize()
Get the size of the map.
Definition: map_func.h:94
static Owner GetRoadOwner(TileIndex t, RoadTramType rtt)
Get the owner of a specific road type.
Definition: road_map.h:235
bool IsStationTileBlocked(TileIndex tile)
Check whether a rail station tile is NOT traversable.
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:52
144 20334
Definition: saveload.h:216
#define SLE_CONDARR(base, variable, type, length, from, to)
Storage of an array in some savegame versions.
Definition: saveload.h:557
static bool IsShipDepot(TileIndex t)
Is it a water tile with a ship depot on it?
Definition: water_map.h:218
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
Middle part of a lock.
Definition: water_map.h:67
StringID name_1
Name of the company if the user did not change it.
Definition: company_base.h:58
static const uint LOCK_DEPOT_TILE_FACTOR
Multiplier for how many regular tiles a lock counts.
Definition: economy_type.h:217
byte colour
Company colour.
Definition: company_base.h:71
StringID president_name_1
Name of the president if the user did not change it.
Definition: company_base.h:61
19 3396
Definition: saveload.h:66
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
Definition: company_base.h:99
A tile of a station.
Definition: tile_type.h:48
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1548
Transport by road vehicle.
static uint CountBits(T value)
Counts the number of set bits in a variable.
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:81
65 10210
Definition: saveload.h:122
Owner owner
The owner of this station.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:235
This bit set means black, otherwise white.
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
Definition: company_cmd.cpp:48
void SlAutolength(AutolengthProc *proc, void *arg)
Do something of which I have no idea what it is :P.
Definition: saveload.cpp:1576
static bool IsNormalRoad(TileIndex t)
Return whether a tile is a normal road.
Definition: road_map.h:65
63 9956
Definition: saveload.h:119
156 21728
Definition: saveload.h:231
GenderEthnicity
The gender/race combinations that we have faces for.
Statistics about the economy.
Definition: company_base.h:23
SaveLoad type struct.
Definition: saveload.h:498
69 10319
Definition: saveload.h:126
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition: saveload.h:596
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
byte colour1
First colour, for all vehicles.
Definition: livery.h:82
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
Definition: saveload.h:622
static bool IsPlainRail(TileIndex t)
Returns whether this is plain rails, with or without signals.
Definition: rail_map.h:51
199 PR#6802 Extend cargotypes to 64
Definition: saveload.h:283
CompanyEconomyEntry cur_economy
Economic data of the company of this quarter.
Definition: company_base.h:98
31 5999
Definition: saveload.h:81
100 13952
Definition: saveload.h:164
Station data structure.
Definition: station_base.h:452
static bool IsRoadDepot(TileIndex t)
Return whether a tile is a road depot.
Definition: road_map.h:107
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
Definition: rail_map.h:117
static bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
Definition: track_func.h:655
Last chunk in this array.
Definition: saveload.h:393
4.0 1 4.1 122 0.3.3, 0.3.4 4.2 1222 0.3.5 4.3 1417 4.4 1426
Definition: saveload.h:38
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
Definition: mem_func.hpp:51
uint32 water
Count of company owned track bits for canals.
Definition: company_base.h:35