OpenTTD: src/saveload/company_sl.cpp Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

company_sl.cpp
Go to the documentation of this file.
1 /* $Id: company_sl.cpp 26590 2014-05-16 17:39:35Z rubidium $ */
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
20 #include "saveload.h"
21
22 #include "table/strings.h"
23
24 #include "../safeguards.h"
25
44 CompanyManagerFace ConvertFromOldCompanyManagerFace(uint32 face)
45 {
46 CompanyManagerFace cmf = 0;
47 GenderEthnicity ge = GE_WM;
48
49 if (HasBit(face, 31)) SetBit(ge, GENDER_FEMALE);
50 if (HasBit(face, 27) && (HasBit(face, 26) == HasBit(face, 19))) SetBit(ge, ETHNICITY_BLACK);
51
52 SetCompanyManagerFaceBits(cmf, CMFV_GEN_ETHN, ge, ge);
53 SetCompanyManagerFaceBits(cmf, CMFV_HAS_GLASSES, ge, GB(face, 28, 3) <= 1);
54 SetCompanyManagerFaceBits(cmf, CMFV_EYE_COLOUR, ge, HasBit(ge, ETHNICITY_BLACK) ? 0 : ClampU(GB(face, 20, 3), 5, 7) - 5);
55 SetCompanyManagerFaceBits(cmf, CMFV_CHIN, ge, ScaleCompanyManagerFaceValue(CMFV_CHIN, ge, GB(face, 4, 2)));
56 SetCompanyManagerFaceBits(cmf, CMFV_EYEBROWS, ge, ScaleCompanyManagerFaceValue(CMFV_EYEBROWS, ge, GB(face, 6, 4)));
57 SetCompanyManagerFaceBits(cmf, CMFV_HAIR, ge, ScaleCompanyManagerFaceValue(CMFV_HAIR, ge, GB(face, 16, 4)));
58 SetCompanyManagerFaceBits(cmf, CMFV_JACKET, ge, ScaleCompanyManagerFaceValue(CMFV_JACKET, ge, GB(face, 20, 2)));
59 SetCompanyManagerFaceBits(cmf, CMFV_COLLAR, ge, ScaleCompanyManagerFaceValue(CMFV_COLLAR, ge, GB(face, 22, 2)));
60 SetCompanyManagerFaceBits(cmf, CMFV_GLASSES, ge, GB(face, 28, 1));
61
62 uint lips = GB(face, 10, 4);
63 if (!HasBit(ge, GENDER_FEMALE) && lips < 4) {
64 SetCompanyManagerFaceBits(cmf, CMFV_HAS_MOUSTACHE, ge, true);
65 SetCompanyManagerFaceBits(cmf, CMFV_MOUSTACHE, ge, max(lips, 1U) - 1);
66 } else {
67 if (!HasBit(ge, GENDER_FEMALE)) {
68 lips = lips * 15 / 16;
69 lips -= 3;
70 if (HasBit(ge, ETHNICITY_BLACK) && lips > 8) lips = 0;
71 } else {
72 lips = ScaleCompanyManagerFaceValue(CMFV_LIPS, ge, lips);
73 }
74 SetCompanyManagerFaceBits(cmf, CMFV_LIPS, ge, lips);
75
76 uint nose = GB(face, 13, 3);
77 if (ge == GE_WF) {
78 nose = (nose * 3 >> 3) * 3 >> 2; // There is 'hole' in the nose sprites for females
79 } else {
80 nose = ScaleCompanyManagerFaceValue(CMFV_NOSE, ge, nose);
81 }
82 SetCompanyManagerFaceBits(cmf, CMFV_NOSE, ge, nose);
83 }
84
85 uint tie_earring = GB(face, 24, 4);
86 if (!HasBit(ge, GENDER_FEMALE) || tie_earring < 3) { // Not all females have an earring
87 if (HasBit(ge, GENDER_FEMALE)) SetCompanyManagerFaceBits(cmf, CMFV_HAS_TIE_EARRING, ge, true);
88 SetCompanyManagerFaceBits(cmf, CMFV_TIE_EARRING, ge, HasBit(ge, GENDER_FEMALE) ? tie_earring : ScaleCompanyManagerFaceValue(CMFV_TIE_EARRING, ge, tie_earring / 2));
89 }
90
91 return cmf;
92 }
93
95 void AfterLoadCompanyStats()
96 {
97 /* Reset infrastructure statistics to zero. */
98 Company *c;
99 FOR_ALL_COMPANIES(c) MemSetT(&c->infrastructure, 0);
100
101 /* Collect airport count. */
102 Station *st;
103 FOR_ALL_STATIONS(st) {
104 if ((st->facilities & FACIL_AIRPORT) && Company::IsValidID(st->owner)) {
105 Company::Get(st->owner)->infrastructure.airport++;
106 }
107 }
108
109 for (TileIndex tile = 0; tile < MapSize(); tile++) {
110 switch (GetTileType(tile)) {
111 case MP_RAILWAY:
112 c = Company::GetIfValid(GetTileOwner(tile));
113 if (c != NULL) {
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 != NULL) c->infrastructure.rail[GetRailType(tile)] += LEVELCROSSING_TRACKBIT_FACTOR;
130 }
131
132 /* Iterate all present road types as each can have a different owner. */
133 RoadType rt;
134 FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
135 c = Company::GetIfValid(IsRoadDepot(tile) ? GetTileOwner(tile) : GetRoadOwner(tile, rt));
136 /* A level crossings and depots have two road bits. */
137 if (c != NULL) c->infrastructure.road[rt] += IsNormalRoad(tile) ? CountBits(GetRoadBits(tile, rt)) : 2;
138 }
139 break;
140 }
141
142 case MP_STATION:
143 c = Company::GetIfValid(GetTileOwner(tile));
144 if (c != NULL && GetStationType(tile) != STATION_AIRPORT && !IsBuoy(tile)) c->infrastructure.station++;
145
146 switch (GetStationType(tile)) {
147 case STATION_RAIL:
148 case STATION_WAYPOINT:
149 if (c != NULL && !IsStationTileBlocked(tile)) c->infrastructure.rail[GetRailType(tile)]++;
150 break;
151
152 case STATION_BUS:
153 case STATION_TRUCK: {
154 /* Iterate all present road types as each can have a different owner. */
155 RoadType rt;
156 FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
157 c = Company::GetIfValid(GetRoadOwner(tile, rt));
158 if (c != NULL) c->infrastructure.road[rt] += 2; // A road stop has two road bits.
159 }
160 break;
161 }
162
163 case STATION_DOCK:
164 case STATION_BUOY:
165 if (GetWaterClass(tile) == WATER_CLASS_CANAL) {
166 if (c != NULL) c->infrastructure.water++;
167 }
168 break;
169
170 default:
171 break;
172 }
173 break;
174
175 case MP_WATER:
176 if (IsShipDepot(tile) || IsLock(tile)) {
177 c = Company::GetIfValid(GetTileOwner(tile));
178 if (c != NULL) {
179 if (IsShipDepot(tile)) c->infrastructure.water += LOCK_DEPOT_TILE_FACTOR;
180 if (IsLock(tile) && GetLockPart(tile) == LOCK_PART_MIDDLE) {
181 /* The middle tile specifies the owner of the lock. */
182 c->infrastructure.water += 3 * LOCK_DEPOT_TILE_FACTOR; // the middle tile specifies the owner of the
183 break; // do not count the middle tile as canal
184 }
185 }
186 }
187 /* FALL THROUGH */
188
189 case MP_OBJECT:
190 if (GetWaterClass(tile) == WATER_CLASS_CANAL) {
191 c = Company::GetIfValid(GetTileOwner(tile));
192 if (c != NULL) c->infrastructure.water++;
193 }
194 break;
195
196 case MP_TUNNELBRIDGE: {
197 /* Only count the tunnel/bridge if we're on the northern end tile. */
198 TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
199 if (tile < other_end) {
200 /* Count each tunnel/bridge TUNNELBRIDGE_TRACKBIT_FACTOR times to simulate
201 * the higher structural maintenance needs, and don't forget the end tiles. */
202 uint len = (GetTunnelBridgeLength(tile, other_end) + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
203
204 switch (GetTunnelBridgeTransportType(tile)) {
205 case TRANSPORT_RAIL:
206 c = Company::GetIfValid(GetTileOwner(tile));
207 if (c != NULL) c->infrastructure.rail[GetRailType(tile)] += len;
208 break;
209
210 case TRANSPORT_ROAD: {
211 /* Iterate all present road types as each can have a different owner. */
212 RoadType rt;
213 FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
214 c = Company::GetIfValid(GetRoadOwner(tile, rt));
215 if (c != NULL) c->infrastructure.road[rt] += len * 2; // A full diagonal road has two road bits.
216 }
217 break;
218 }
219
220 case TRANSPORT_WATER:
221 c = Company::GetIfValid(GetTileOwner(tile));
222 if (c != NULL) c->infrastructure.water += len;
223 break;
224
225 default:
226 break;
227 }
228 }
229 break;
230 }
231
232 default:
233 break;
234 }
235 }
236 }
237
238
239
240 /* Save/load of companies */
241 static const SaveLoad _company_desc[] = {
242 SLE_VAR(CompanyProperties, name_2, SLE_UINT32),
243 SLE_VAR(CompanyProperties, name_1, SLE_STRINGID),
244 SLE_CONDSTR(CompanyProperties, name, SLE_STR | SLF_ALLOW_CONTROL, 0, 84, SL_MAX_VERSION),
245
246 SLE_VAR(CompanyProperties, president_name_1, SLE_UINT16),
247 SLE_VAR(CompanyProperties, president_name_2, SLE_UINT32),
248 SLE_CONDSTR(CompanyProperties, president_name, SLE_STR | SLF_ALLOW_CONTROL, 0, 84, SL_MAX_VERSION),
249
250 SLE_VAR(CompanyProperties, face, SLE_UINT32),
251
252 /* money was changed to a 64 bit field in savegame version 1. */
253 SLE_CONDVAR(CompanyProperties, money, SLE_VAR_I64 | SLE_FILE_I32, 0, 0),
254 SLE_CONDVAR(CompanyProperties, money, SLE_INT64, 1, SL_MAX_VERSION),
255
256 SLE_CONDVAR(CompanyProperties, current_loan, SLE_VAR_I64 | SLE_FILE_I32, 0, 64),
257 SLE_CONDVAR(CompanyProperties, current_loan, SLE_INT64, 65, SL_MAX_VERSION),
258
259 SLE_VAR(CompanyProperties, colour, SLE_UINT8),
260 SLE_VAR(CompanyProperties, money_fraction, SLE_UINT8),
261 SLE_CONDVAR(CompanyProperties, avail_railtypes, SLE_VAR_I32 | SLE_FILE_I8, 0, 57),
262 SLE_VAR(CompanyProperties, block_preview, SLE_UINT8),
263
264 SLE_CONDNULL(2, 0, 93),
265 SLE_CONDNULL(4, 94, 169),
266 SLE_CONDVAR(CompanyProperties, location_of_HQ, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
267 SLE_CONDVAR(CompanyProperties, location_of_HQ, SLE_UINT32, 6, SL_MAX_VERSION),
268 SLE_CONDVAR(CompanyProperties, last_build_coordinate, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
269 SLE_CONDVAR(CompanyProperties, last_build_coordinate, SLE_UINT32, 6, SL_MAX_VERSION),
270 SLE_CONDVAR(CompanyProperties, inaugurated_year, SLE_FILE_U8 | SLE_VAR_I32, 0, 30),
271 SLE_CONDVAR(CompanyProperties, inaugurated_year, SLE_INT32, 31, SL_MAX_VERSION),
272
273 SLE_ARR(CompanyProperties, share_owners, SLE_UINT8, 4),
274
275 SLE_VAR(CompanyProperties, num_valid_stat_ent, SLE_UINT8),
276
277 SLE_VAR(CompanyProperties, months_of_bankruptcy, SLE_UINT8),
278 SLE_CONDVAR(CompanyProperties, bankrupt_asked, SLE_FILE_U8 | SLE_VAR_U16, 0, 103),
279 SLE_CONDVAR(CompanyProperties, bankrupt_asked, SLE_UINT16, 104, SL_MAX_VERSION),
280 SLE_VAR(CompanyProperties, bankrupt_timeout, SLE_INT16),
281 SLE_CONDVAR(CompanyProperties, bankrupt_value, SLE_VAR_I64 | SLE_FILE_I32, 0, 64),
282 SLE_CONDVAR(CompanyProperties, bankrupt_value, SLE_INT64, 65, SL_MAX_VERSION),
283
284 /* yearly expenses was changed to 64-bit in savegame version 2. */
285 SLE_CONDARR(CompanyProperties, yearly_expenses, SLE_FILE_I32 | SLE_VAR_I64, 3 * 13, 0, 1),
286 SLE_CONDARR(CompanyProperties, yearly_expenses, SLE_INT64, 3 * 13, 2, SL_MAX_VERSION),
287
288 SLE_CONDVAR(CompanyProperties, is_ai, SLE_BOOL, 2, SL_MAX_VERSION),
289 SLE_CONDNULL(1, 107, 111),
290 SLE_CONDNULL(1, 4, 99),
291
292 SLE_CONDVAR(CompanyProperties, terraform_limit, SLE_UINT32, 156, SL_MAX_VERSION),
293 SLE_CONDVAR(CompanyProperties, clear_limit, SLE_UINT32, 156, SL_MAX_VERSION),
294 SLE_CONDVAR(CompanyProperties, tree_limit, SLE_UINT32, 175, SL_MAX_VERSION),
295
296 SLE_END()
297 };
298
299 static const SaveLoad _company_settings_desc[] = {
300 /* Engine renewal settings */
301 SLE_CONDNULL(512, 16, 18),
302 SLE_CONDREF(Company, engine_renew_list, REF_ENGINE_RENEWS, 19, SL_MAX_VERSION),
303 SLE_CONDVAR(Company, settings.engine_renew, SLE_BOOL, 16, SL_MAX_VERSION),
304 SLE_CONDVAR(Company, settings.engine_renew_months, SLE_INT16, 16, SL_MAX_VERSION),
305 SLE_CONDVAR(Company, settings.engine_renew_money, SLE_UINT32, 16, SL_MAX_VERSION),
306 SLE_CONDVAR(Company, settings.renew_keep_length, SLE_BOOL, 2, SL_MAX_VERSION),
307
308 /* Default vehicle settings */
309 SLE_CONDVAR(Company, settings.vehicle.servint_ispercent, SLE_BOOL, 120, SL_MAX_VERSION),
310 SLE_CONDVAR(Company, settings.vehicle.servint_trains, SLE_UINT16, 120, SL_MAX_VERSION),
311 SLE_CONDVAR(Company, settings.vehicle.servint_roadveh, SLE_UINT16, 120, SL_MAX_VERSION),
312 SLE_CONDVAR(Company, settings.vehicle.servint_aircraft, SLE_UINT16, 120, SL_MAX_VERSION),
313 SLE_CONDVAR(Company, settings.vehicle.servint_ships, SLE_UINT16, 120, SL_MAX_VERSION),
314
315 SLE_CONDNULL(63, 2, 143), // old reserved space
316
317 SLE_END()
318 };
319
320 static const SaveLoad _company_settings_skip_desc[] = {
321 /* Engine renewal settings */
322 SLE_CONDNULL(512, 16, 18),
323 SLE_CONDNULL(2, 19, 68), // engine_renew_list
324 SLE_CONDNULL(4, 69, SL_MAX_VERSION), // engine_renew_list
325 SLE_CONDNULL(1, 16, SL_MAX_VERSION), // settings.engine_renew
326 SLE_CONDNULL(2, 16, SL_MAX_VERSION), // settings.engine_renew_months
327 SLE_CONDNULL(4, 16, SL_MAX_VERSION), // settings.engine_renew_money
328 SLE_CONDNULL(1, 2, SL_MAX_VERSION), // settings.renew_keep_length
329
330 /* Default vehicle settings */
331 SLE_CONDNULL(1, 120, SL_MAX_VERSION), // settings.vehicle.servint_ispercent
332 SLE_CONDNULL(2, 120, SL_MAX_VERSION), // settings.vehicle.servint_trains
333 SLE_CONDNULL(2, 120, SL_MAX_VERSION), // settings.vehicle.servint_roadveh
334 SLE_CONDNULL(2, 120, SL_MAX_VERSION), // settings.vehicle.servint_aircraft
335 SLE_CONDNULL(2, 120, SL_MAX_VERSION), // settings.vehicle.servint_ships
336
337 SLE_CONDNULL(63, 2, 143), // old reserved space
338
339 SLE_END()
340 };
341
342 static const SaveLoad _company_economy_desc[] = {
343 /* these were changed to 64-bit in savegame format 2 */
344 SLE_CONDVAR(CompanyEconomyEntry, income, SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
345 SLE_CONDVAR(CompanyEconomyEntry, income, SLE_INT64, 2, SL_MAX_VERSION),
346 SLE_CONDVAR(CompanyEconomyEntry, expenses, SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
347 SLE_CONDVAR(CompanyEconomyEntry, expenses, SLE_INT64, 2, SL_MAX_VERSION),
348 SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
349 SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_INT64, 2, SL_MAX_VERSION),
350
351 SLE_CONDVAR(CompanyEconomyEntry, delivered_cargo[NUM_CARGO - 1], SLE_INT32, 0, 169),
352 SLE_CONDARR(CompanyEconomyEntry, delivered_cargo, SLE_UINT32, NUM_CARGO, 170, SL_MAX_VERSION),
353 SLE_VAR(CompanyEconomyEntry, performance_history, SLE_INT32),
354
355 SLE_END()
356 };
357
358 /* We do need to read this single value, as the bigger it gets, the more data is stored */
359 struct CompanyOldAI {
360 uint8 num_build_rec;
361 };
362
363 static const SaveLoad _company_ai_desc[] = {
364 SLE_CONDNULL(2, 0, 106),
365 SLE_CONDNULL(2, 0, 12),
366 SLE_CONDNULL(4, 13, 106),
367 SLE_CONDNULL(8, 0, 106),
368 SLE_CONDVAR(CompanyOldAI, num_build_rec, SLE_UINT8, 0, 106),
369 SLE_CONDNULL(3, 0, 106),
370
371 SLE_CONDNULL(2, 0, 5),
372 SLE_CONDNULL(4, 6, 106),
373 SLE_CONDNULL(2, 0, 5),
374 SLE_CONDNULL(4, 6, 106),
375 SLE_CONDNULL(2, 0, 106),
376
377 SLE_CONDNULL(2, 0, 5),
378 SLE_CONDNULL(4, 6, 106),
379 SLE_CONDNULL(2, 0, 5),
380 SLE_CONDNULL(4, 6, 106),
381 SLE_CONDNULL(2, 0, 106),
382
383 SLE_CONDNULL(2, 0, 68),
384 SLE_CONDNULL(4, 69, 106),
385
386 SLE_CONDNULL(18, 0, 106),
387 SLE_CONDNULL(20, 0, 106),
388 SLE_CONDNULL(32, 0, 106),
389
390 SLE_CONDNULL(64, 2, 106),
391 SLE_END()
392 };
393
394 static const SaveLoad _company_ai_build_rec_desc[] = {
395 SLE_CONDNULL(2, 0, 5),
396 SLE_CONDNULL(4, 6, 106),
397 SLE_CONDNULL(2, 0, 5),
398 SLE_CONDNULL(4, 6, 106),
399 SLE_CONDNULL(8, 0, 106),
400 SLE_END()
401 };
402
403 static const SaveLoad _company_livery_desc[] = {
404 SLE_CONDVAR(Livery, in_use, SLE_BOOL, 34, SL_MAX_VERSION),
405 SLE_CONDVAR(Livery, colour1, SLE_UINT8, 34, SL_MAX_VERSION),
406 SLE_CONDVAR(Livery, colour2, SLE_UINT8, 34, SL_MAX_VERSION),
407 SLE_END()
408 };
409
410 static void SaveLoad_PLYR_common(Company *c, CompanyProperties *cprops)
411 {
412 int i;
413
414 SlObject(cprops, _company_desc);
415 if (c != NULL) {
416 SlObject(c, _company_settings_desc);
417 } else {
418 char nothing;
419 SlObject(&nothing, _company_settings_skip_desc);
420 }
421
422 /* Keep backwards compatible for savegames, so load the old AI block */
423 if (IsSavegameVersionBefore(107) && cprops->is_ai) {
424 CompanyOldAI old_ai;
425 char nothing;
426
427 SlObject(&old_ai, _company_ai_desc);
428 for (i = 0; i != old_ai.num_build_rec; i++) {
429 SlObject(&nothing, _company_ai_build_rec_desc);
430 }
431 }
432
433 /* Write economy */
434 SlObject(&cprops->cur_economy, _company_economy_desc);
435
436 /* Write old economy entries. */
437 if (cprops->num_valid_stat_ent > lengthof(cprops->old_economy)) SlErrorCorrupt("Too many old economy entries");
438 for (i = 0; i < cprops->num_valid_stat_ent; i++) {
439 SlObject(&cprops->old_economy[i], _company_economy_desc);
440 }
441
442 /* Write each livery entry. */
443 int num_liveries = IsSavegameVersionBefore(63) ? LS_END - 4 : (IsSavegameVersionBefore(85) ? LS_END - 2: LS_END);
444 if (c != NULL) {
445 for (i = 0; i < num_liveries; i++) {
446 SlObject(&c->livery[i], _company_livery_desc);
447 }
448
449 if (num_liveries < LS_END) {
450 /* We want to insert some liveries somewhere in between. This means some have to be moved. */
451 memmove(&c->livery[LS_FREIGHT_WAGON], &c->livery[LS_PASSENGER_WAGON_MONORAIL], (LS_END - LS_FREIGHT_WAGON) * sizeof(c->livery[0]));
452 c->livery[LS_PASSENGER_WAGON_MONORAIL] = c->livery[LS_MONORAIL];
453 c->livery[LS_PASSENGER_WAGON_MAGLEV] = c->livery[LS_MAGLEV];
454 }
455
456 if (num_liveries == LS_END - 4) {
457 /* Copy bus/truck liveries over to trams */
458 c->livery[LS_PASSENGER_TRAM] = c->livery[LS_BUS];
459 c->livery[LS_FREIGHT_TRAM] = c->livery[LS_TRUCK];
460 }
461 } else {
462 /* Skip liveries */
463 Livery dummy_livery;
464 for (i = 0; i < num_liveries; i++) {
465 SlObject(&dummy_livery, _company_livery_desc);
466 }
467 }
468 }
469
470 static void SaveLoad_PLYR(Company *c)
471 {
472 SaveLoad_PLYR_common(c, c);
473 }
474
475 static void Save_PLYR()
476 {
477 Company *c;
478 FOR_ALL_COMPANIES(c) {
479 SlSetArrayIndex(c->index);
480 SlAutolength((AutolengthProc*)SaveLoad_PLYR, c);
481 }
482 }
483
484 static void Load_PLYR()
485 {
486 int index;
487 while ((index = SlIterateArray()) != -1) {
488 Company *c = new (index) Company();
489 SaveLoad_PLYR(c);
490 _company_colours[index] = (Colours)c->colour;
491 }
492 }
493
494 static void Check_PLYR()
495 {
496 int index;
497 while ((index = SlIterateArray()) != -1) {
498 CompanyProperties *cprops = new CompanyProperties();
499 memset(cprops, 0, sizeof(*cprops));
500 SaveLoad_PLYR_common(NULL, cprops);
501
502 /* We do not load old custom names */
503 if (IsSavegameVersionBefore(84)) {
504 if (GB(cprops->name_1, 11, 5) == 15) {
505 cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
506 }
507
508 if (GB(cprops->president_name_1, 11, 5) == 15) {
509 cprops->president_name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
510 }
511 }
512
513 if (cprops->name == NULL && !IsInsideMM(cprops->name_1, SPECSTR_COMPANY_NAME_START, SPECSTR_COMPANY_NAME_LAST + 1) &&
514 cprops->name_1 != STR_GAME_SAVELOAD_NOT_AVAILABLE && cprops->name_1 != STR_SV_UNNAMED &&
515 cprops->name_1 != SPECSTR_ANDCO_NAME && cprops->name_1 != SPECSTR_PRESIDENT_NAME &&
516 cprops->name_1 != SPECSTR_SILLY_NAME) {
517 cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
518 }
519
520 if (!_load_check_data.companies.Insert(index, cprops)) delete cprops;
521 }
522 }
523
524 static void Ptrs_PLYR()
525 {
526 Company *c;
527 FOR_ALL_COMPANIES(c) {
528 SlObject(c, _company_settings_desc);
529 }
530 }
531
532
533 extern const ChunkHandler _company_chunk_handlers[] = {
534 { 'PLYR', Save_PLYR, Load_PLYR, Ptrs_PLYR, Check_PLYR, CH_ARRAY | CH_LAST},
535 };