company_sl.cpp

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * 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.
00006  * 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.
00007  * 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/>.
00008  */
00009 
00012 #include "../stdafx.h"
00013 #include "../company_func.h"
00014 #include "../company_manager_face.h"
00015 #include "../fios.h"
00016 #include "../rail_map.h"
00017 #include "../road_map.h"
00018 #include "../station_map.h"
00019 #include "../tunnelbridge_map.h"
00020 #include "../tunnelbridge.h"
00021 #include "../station_base.h"
00022 
00023 #include "saveload.h"
00024 
00025 #include "table/strings.h"
00026 
00045 CompanyManagerFace ConvertFromOldCompanyManagerFace(uint32 face)
00046 {
00047   CompanyManagerFace cmf = 0;
00048   GenderEthnicity ge = GE_WM;
00049 
00050   if (HasBit(face, 31)) SetBit(ge, GENDER_FEMALE);
00051   if (HasBit(face, 27) && (HasBit(face, 26) == HasBit(face, 19))) SetBit(ge, ETHNICITY_BLACK);
00052 
00053   SetCompanyManagerFaceBits(cmf, CMFV_GEN_ETHN,    ge, ge);
00054   SetCompanyManagerFaceBits(cmf, CMFV_HAS_GLASSES, ge, GB(face, 28, 3) <= 1);
00055   SetCompanyManagerFaceBits(cmf, CMFV_EYE_COLOUR,  ge, HasBit(ge, ETHNICITY_BLACK) ? 0 : ClampU(GB(face, 20, 3), 5, 7) - 5);
00056   SetCompanyManagerFaceBits(cmf, CMFV_CHIN,        ge, ScaleCompanyManagerFaceValue(CMFV_CHIN,     ge, GB(face,  4, 2)));
00057   SetCompanyManagerFaceBits(cmf, CMFV_EYEBROWS,    ge, ScaleCompanyManagerFaceValue(CMFV_EYEBROWS, ge, GB(face,  6, 4)));
00058   SetCompanyManagerFaceBits(cmf, CMFV_HAIR,        ge, ScaleCompanyManagerFaceValue(CMFV_HAIR,     ge, GB(face, 16, 4)));
00059   SetCompanyManagerFaceBits(cmf, CMFV_JACKET,      ge, ScaleCompanyManagerFaceValue(CMFV_JACKET,   ge, GB(face, 20, 2)));
00060   SetCompanyManagerFaceBits(cmf, CMFV_COLLAR,      ge, ScaleCompanyManagerFaceValue(CMFV_COLLAR,   ge, GB(face, 22, 2)));
00061   SetCompanyManagerFaceBits(cmf, CMFV_GLASSES,     ge, GB(face, 28, 1));
00062 
00063   uint lips = GB(face, 10, 4);
00064   if (!HasBit(ge, GENDER_FEMALE) && lips < 4) {
00065     SetCompanyManagerFaceBits(cmf, CMFV_HAS_MOUSTACHE, ge, true);
00066     SetCompanyManagerFaceBits(cmf, CMFV_MOUSTACHE,     ge, max(lips, 1U) - 1);
00067   } else {
00068     if (!HasBit(ge, GENDER_FEMALE)) {
00069       lips = lips * 15 / 16;
00070       lips -= 3;
00071       if (HasBit(ge, ETHNICITY_BLACK) && lips > 8) lips = 0;
00072     } else {
00073       lips = ScaleCompanyManagerFaceValue(CMFV_LIPS, ge, lips);
00074     }
00075     SetCompanyManagerFaceBits(cmf, CMFV_LIPS, ge, lips);
00076 
00077     uint nose = GB(face, 13, 3);
00078     if (ge == GE_WF) {
00079       nose = (nose * 3 >> 3) * 3 >> 2; // There is 'hole' in the nose sprites for females
00080     } else {
00081       nose = ScaleCompanyManagerFaceValue(CMFV_NOSE, ge, nose);
00082     }
00083     SetCompanyManagerFaceBits(cmf, CMFV_NOSE, ge, nose);
00084   }
00085 
00086   uint tie_earring = GB(face, 24, 4);
00087   if (!HasBit(ge, GENDER_FEMALE) || tie_earring < 3) { // Not all females have an earring
00088     if (HasBit(ge, GENDER_FEMALE)) SetCompanyManagerFaceBits(cmf, CMFV_HAS_TIE_EARRING, ge, true);
00089     SetCompanyManagerFaceBits(cmf, CMFV_TIE_EARRING, ge, HasBit(ge, GENDER_FEMALE) ? tie_earring : ScaleCompanyManagerFaceValue(CMFV_TIE_EARRING, ge, tie_earring / 2));
00090   }
00091 
00092   return cmf;
00093 }
00094 
00096 void AfterLoadCompanyStats()
00097 {
00098   /* Reset infrastructure statistics to zero. */
00099   Company *c;
00100   FOR_ALL_COMPANIES(c) {
00101     MemSetT(c->road_infrastructure, 0, lengthof(c->road_infrastructure));
00102     MemSetT(c->rail_infrastructure, 0, lengthof(c->rail_infrastructure));
00103     c->signal_infrastructure = 0;
00104     c->water_infrastructure = 0;
00105     c->station_infrastructure = 0;
00106     c->airport_infrastructure = 0;
00107   }
00108 
00109   /* Collect airport count. */
00110   Station *st;
00111   FOR_ALL_STATIONS(st) {
00112     if ((st->facilities & FACIL_AIRPORT) && Company::IsValidID(st->owner)) {
00113       Company::Get(st->owner)->airport_infrastructure++;
00114     }
00115   }
00116 
00117   for (TileIndex tile = 0; tile < MapSize(); tile++) {
00118     switch (GetTileType(tile)) {
00119       case MP_RAILWAY:
00120         c = Company::GetIfValid(GetTileOwner(tile));
00121         if (c != NULL) {
00122           uint pieces = 1;
00123           if (IsPlainRail(tile)) {
00124             TrackBits bits = GetTrackBits(tile);
00125             pieces = CountBits(bits);
00126             if (TracksOverlap(bits)) pieces *= pieces;
00127           }
00128           c->rail_infrastructure[GetRailType(tile)] += pieces;
00129 
00130           if (HasSignals(tile)) c->signal_infrastructure += CountBits(GetPresentSignals(tile));
00131         }
00132         break;
00133 
00134       case MP_ROAD: {
00135         if (IsLevelCrossing(tile)) {
00136           c = Company::GetIfValid(GetTileOwner(tile));
00137           if (c != NULL) c->rail_infrastructure[GetRailType(tile)] += LEVELCROSSING_TRACKBIT_FACTOR;
00138         }
00139 
00140         /* Iterate all present road types as each can have a different owner. */
00141         RoadType rt;
00142         FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
00143           c = Company::GetIfValid(IsRoadDepot(tile) ? GetTileOwner(tile) : GetRoadOwner(tile, rt));
00144           /* A level crossings and depots have two road bits. */
00145           if (c != NULL) c->road_infrastructure[rt] += IsNormalRoad(tile) ? CountBits(GetRoadBits(tile, rt)) : 2;
00146         }
00147         break;
00148       }
00149 
00150       case MP_STATION:
00151         c = Company::GetIfValid(GetTileOwner(tile));
00152         if (c != NULL && GetStationType(tile) != STATION_AIRPORT) c->station_infrastructure++;
00153 
00154         switch (GetStationType(tile)) {
00155           case STATION_RAIL:
00156           case STATION_WAYPOINT:
00157             if (c != NULL && !IsStationTileBlocked(tile)) c->rail_infrastructure[GetRailType(tile)]++;
00158             break;
00159 
00160           case STATION_BUS:
00161           case STATION_TRUCK: {
00162             /* Iterate all present road types as each can have a different owner. */
00163             RoadType rt;
00164             FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
00165               c = Company::GetIfValid(GetRoadOwner(tile, rt));
00166               if (c != NULL) c->road_infrastructure[rt] += 2; // A road stop has two road bits.
00167             }
00168             break;
00169           }
00170 
00171           case STATION_DOCK:
00172           case STATION_BUOY:
00173             if (GetWaterClass(tile) == WATER_CLASS_CANAL) {
00174               if (c != NULL) c->water_infrastructure++;
00175             }
00176             break;
00177 
00178           default:
00179             break;
00180         }
00181         break;
00182 
00183       case MP_WATER:
00184       case MP_OBJECT:
00185         if (GetWaterClass(tile) == WATER_CLASS_CANAL) {
00186           c = Company::GetIfValid(GetTileOwner(tile));
00187           if (c != NULL) c->water_infrastructure++;
00188         }
00189         break;
00190 
00191       case MP_TUNNELBRIDGE: {
00192         /* Only count the tunnel/bridge if we're on the northern end tile. */
00193         TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
00194         if (tile < other_end) {
00195           /* Count each tunnel/bridge TUNNELBRIDGE_TRACKBIT_FACTOR times to simulate
00196            * the higher structural maintenance needs, and don't forget the end tiles. */
00197           uint len = (GetTunnelBridgeLength(tile, other_end) + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
00198 
00199           switch (GetTunnelBridgeTransportType(tile)) {
00200             case TRANSPORT_RAIL:
00201               c = Company::GetIfValid(GetTileOwner(tile));
00202               if (c != NULL) c->rail_infrastructure[GetRailType(tile)] += len;
00203               break;
00204 
00205             case TRANSPORT_ROAD: {
00206               /* Iterate all present road types as each can have a different owner. */
00207               RoadType rt;
00208               FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
00209                 c = Company::GetIfValid(GetRoadOwner(tile, rt));
00210                 if (c != NULL) c->road_infrastructure[rt] += len * 2; // A full diagonal road has two road bits.
00211               }
00212               break;
00213             }
00214 
00215             case TRANSPORT_WATER:
00216               c = Company::GetIfValid(GetTileOwner(tile));
00217               if (c != NULL) c->water_infrastructure += len;
00218               break;
00219 
00220             default:
00221               break;
00222           }
00223         }
00224         break;
00225       }
00226 
00227       default:
00228         break;
00229     }
00230   }
00231 }
00232 
00233 /* Save/load of companies */
00234 static const SaveLoad _company_desc[] = {
00235       SLE_VAR(CompanyProperties, name_2,          SLE_UINT32),
00236       SLE_VAR(CompanyProperties, name_1,          SLE_STRINGID),
00237   SLE_CONDSTR(CompanyProperties, name,            SLE_STR, 0,                       84, SL_MAX_VERSION),
00238 
00239       SLE_VAR(CompanyProperties, president_name_1, SLE_UINT16),
00240       SLE_VAR(CompanyProperties, president_name_2, SLE_UINT32),
00241   SLE_CONDSTR(CompanyProperties, president_name,  SLE_STR, 0,                       84, SL_MAX_VERSION),
00242 
00243       SLE_VAR(CompanyProperties, face,            SLE_UINT32),
00244 
00245   /* money was changed to a 64 bit field in savegame version 1. */
00246   SLE_CONDVAR(CompanyProperties, money,                 SLE_VAR_I64 | SLE_FILE_I32,  0, 0),
00247   SLE_CONDVAR(CompanyProperties, money,                 SLE_INT64,                   1, SL_MAX_VERSION),
00248 
00249   SLE_CONDVAR(CompanyProperties, current_loan,          SLE_VAR_I64 | SLE_FILE_I32,  0, 64),
00250   SLE_CONDVAR(CompanyProperties, current_loan,          SLE_INT64,                  65, SL_MAX_VERSION),
00251 
00252       SLE_VAR(CompanyProperties, colour,                SLE_UINT8),
00253       SLE_VAR(CompanyProperties, money_fraction,        SLE_UINT8),
00254   SLE_CONDVAR(CompanyProperties, avail_railtypes,       SLE_UINT8,                   0, 57),
00255       SLE_VAR(CompanyProperties, block_preview,         SLE_UINT8),
00256 
00257   SLE_CONDVAR(CompanyProperties, cargo_types,           SLE_FILE_U16 | SLE_VAR_U32,  0, 93),
00258   SLE_CONDVAR(CompanyProperties, cargo_types,           SLE_UINT32,                 94, SL_MAX_VERSION),
00259   SLE_CONDVAR(CompanyProperties, location_of_HQ,        SLE_FILE_U16 | SLE_VAR_U32,  0,  5),
00260   SLE_CONDVAR(CompanyProperties, location_of_HQ,        SLE_UINT32,                  6, SL_MAX_VERSION),
00261   SLE_CONDVAR(CompanyProperties, last_build_coordinate, SLE_FILE_U16 | SLE_VAR_U32,  0,  5),
00262   SLE_CONDVAR(CompanyProperties, last_build_coordinate, SLE_UINT32,                  6, SL_MAX_VERSION),
00263   SLE_CONDVAR(CompanyProperties, inaugurated_year,      SLE_FILE_U8  | SLE_VAR_I32,  0, 30),
00264   SLE_CONDVAR(CompanyProperties, inaugurated_year,      SLE_INT32,                  31, SL_MAX_VERSION),
00265 
00266       SLE_ARR(CompanyProperties, share_owners,          SLE_UINT8, 4),
00267 
00268       SLE_VAR(CompanyProperties, num_valid_stat_ent,    SLE_UINT8),
00269 
00270       SLE_VAR(CompanyProperties, quarters_of_bankruptcy,SLE_UINT8),
00271   SLE_CONDVAR(CompanyProperties, bankrupt_asked,        SLE_FILE_U8  | SLE_VAR_U16,  0, 103),
00272   SLE_CONDVAR(CompanyProperties, bankrupt_asked,        SLE_UINT16,                104, SL_MAX_VERSION),
00273       SLE_VAR(CompanyProperties, bankrupt_timeout,      SLE_INT16),
00274   SLE_CONDVAR(CompanyProperties, bankrupt_value,        SLE_VAR_I64 | SLE_FILE_I32,  0, 64),
00275   SLE_CONDVAR(CompanyProperties, bankrupt_value,        SLE_INT64,                  65, SL_MAX_VERSION),
00276 
00277   /* yearly expenses was changed to 64-bit in savegame version 2. */
00278   SLE_CONDARR(CompanyProperties, yearly_expenses,       SLE_FILE_I32 | SLE_VAR_I64, 3 * 13, 0, 1),
00279   SLE_CONDARR(CompanyProperties, yearly_expenses,       SLE_INT64, 3 * 13,                  2, IS_SL - 1),
00280   SLE_CONDARR(CompanyProperties, yearly_expenses,       SLE_INT64, 3 * 15,              IS_SL, SL_MAX_VERSION),
00281 
00282   SLE_CONDVAR(CompanyProperties, is_ai,                 SLE_BOOL,                    2, SL_MAX_VERSION),
00283   SLE_CONDNULL(1, 107, 111), 
00284   SLE_CONDNULL(1, 4, 99),
00285 
00286   SLE_CONDVAR(CompanyProperties, terraform_limit,       SLE_UINT32,                156, BEFORE_ADDING_PATCHES_SL),
00287   SLE_CONDVAR(CompanyProperties, terraform_limit,       SLE_UINT32,                KEEP_COMPATIBLE_14_SV, SL_MAX_VERSION),
00288   SLE_CONDVAR(CompanyProperties, clear_limit,           SLE_UINT32,                156, BEFORE_ADDING_PATCHES_SL),
00289   SLE_CONDVAR(CompanyProperties, clear_limit,           SLE_UINT32,                KEEP_COMPATIBLE_14_SV, SL_MAX_VERSION),
00290 
00291   SLE_END()
00292 };
00293 
00294 static const SaveLoad _company_settings_desc[] = {
00295   /* Engine renewal settings */
00296   SLE_CONDNULL(512, 16, 18),
00297   SLE_CONDREF(Company, engine_renew_list,            REF_ENGINE_RENEWS,   19, SL_MAX_VERSION),
00298   SLE_CONDVAR(Company, settings.engine_renew,        SLE_BOOL,            16, SL_MAX_VERSION),
00299   SLE_CONDVAR(Company, settings.engine_renew_months, SLE_INT16,           16, SL_MAX_VERSION),
00300   SLE_CONDVAR(Company, settings.engine_renew_money,  SLE_UINT32,          16, SL_MAX_VERSION),
00301   SLE_CONDVAR(Company, settings.renew_keep_length,   SLE_BOOL,             2, SL_MAX_VERSION),
00302 
00303   /* Default vehicle settings */
00304   SLE_CONDVAR(Company, settings.vehicle.servint_ispercent,   SLE_BOOL,     120, SL_MAX_VERSION),
00305   SLE_CONDVAR(Company, settings.vehicle.servint_trains,    SLE_UINT16,     120, SL_MAX_VERSION),
00306   SLE_CONDVAR(Company, settings.vehicle.servint_roadveh,   SLE_UINT16,     120, SL_MAX_VERSION),
00307   SLE_CONDVAR(Company, settings.vehicle.servint_aircraft,  SLE_UINT16,     120, SL_MAX_VERSION),
00308   SLE_CONDVAR(Company, settings.vehicle.servint_ships,     SLE_UINT16,     120, SL_MAX_VERSION),
00309 
00310   SLE_CONDNULL(63, 2, 143), // old reserved space
00311 
00312   SLE_END()
00313 };
00314 
00315 static const SaveLoad _company_settings_skip_desc[] = {
00316   /* Engine renewal settings */
00317   SLE_CONDNULL(512, 16, 18),
00318   SLE_CONDNULL(2, 19, 68),                 // engine_renew_list
00319   SLE_CONDNULL(4, 69, SL_MAX_VERSION),     // engine_renew_list
00320   SLE_CONDNULL(1, 16, SL_MAX_VERSION),     // settings.engine_renew
00321   SLE_CONDNULL(2, 16, SL_MAX_VERSION),     // settings.engine_renew_months
00322   SLE_CONDNULL(4, 16, SL_MAX_VERSION),     // settings.engine_renew_money
00323   SLE_CONDNULL(1,  2, SL_MAX_VERSION),     // settings.renew_keep_length
00324 
00325   /* Default vehicle settings */
00326   SLE_CONDNULL(1, 120, SL_MAX_VERSION),    // settings.vehicle.servint_ispercent
00327   SLE_CONDNULL(2, 120, SL_MAX_VERSION),    // settings.vehicle.servint_trains
00328   SLE_CONDNULL(2, 120, SL_MAX_VERSION),    // settings.vehicle.servint_roadveh
00329   SLE_CONDNULL(2, 120, SL_MAX_VERSION),    // settings.vehicle.servint_aircraft
00330   SLE_CONDNULL(2, 120, SL_MAX_VERSION),    // settings.vehicle.servint_ships
00331 
00332   SLE_CONDNULL(63, 2, 143), // old reserved space
00333 
00334   SLE_END()
00335 };
00336 
00337 static const SaveLoad _company_economy_desc[] = {
00338   /* these were changed to 64-bit in savegame format 2 */
00339   SLE_CONDVAR(CompanyEconomyEntry, income,              SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
00340   SLE_CONDVAR(CompanyEconomyEntry, income,              SLE_INT64,                  2, SL_MAX_VERSION),
00341   SLE_CONDVAR(CompanyEconomyEntry, expenses,            SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
00342   SLE_CONDVAR(CompanyEconomyEntry, expenses,            SLE_INT64,                  2, SL_MAX_VERSION),
00343   SLE_CONDVAR(CompanyEconomyEntry, company_value,       SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
00344   SLE_CONDVAR(CompanyEconomyEntry, company_value,       SLE_INT64,                  2, SL_MAX_VERSION),
00345 
00346       SLE_VAR(CompanyEconomyEntry, delivered_cargo,     SLE_INT32),
00347       SLE_VAR(CompanyEconomyEntry, performance_history, SLE_INT32),
00348 
00349   SLE_END()
00350 };
00351 
00352 /* We do need to read this single value, as the bigger it gets, the more data is stored */
00353 struct CompanyOldAI {
00354   uint8 num_build_rec;
00355 };
00356 
00357 static const SaveLoad _company_ai_desc[] = {
00358   SLE_CONDNULL(2,  0, 106),
00359   SLE_CONDNULL(2,  0, 12),
00360   SLE_CONDNULL(4, 13, 106),
00361   SLE_CONDNULL(8,  0, 106),
00362    SLE_CONDVAR(CompanyOldAI, num_build_rec, SLE_UINT8, 0, 106),
00363   SLE_CONDNULL(3,  0, 106),
00364 
00365   SLE_CONDNULL(2,  0,  5),
00366   SLE_CONDNULL(4,  6, 106),
00367   SLE_CONDNULL(2,  0,  5),
00368   SLE_CONDNULL(4,  6, 106),
00369   SLE_CONDNULL(2,  0, 106),
00370 
00371   SLE_CONDNULL(2,  0,  5),
00372   SLE_CONDNULL(4,  6, 106),
00373   SLE_CONDNULL(2,  0,  5),
00374   SLE_CONDNULL(4,  6, 106),
00375   SLE_CONDNULL(2,  0, 106),
00376 
00377   SLE_CONDNULL(2,  0, 68),
00378   SLE_CONDNULL(4,  69, 106),
00379 
00380   SLE_CONDNULL(18, 0, 106),
00381   SLE_CONDNULL(20, 0, 106),
00382   SLE_CONDNULL(32, 0, 106),
00383 
00384   SLE_CONDNULL(64, 2, 106),
00385   SLE_END()
00386 };
00387 
00388 static const SaveLoad _company_ai_build_rec_desc[] = {
00389   SLE_CONDNULL(2, 0, 5),
00390   SLE_CONDNULL(4, 6, 106),
00391   SLE_CONDNULL(2, 0, 5),
00392   SLE_CONDNULL(4, 6, 106),
00393   SLE_CONDNULL(8, 0, 106),
00394   SLE_END()
00395 };
00396 
00397 static const SaveLoad _company_livery_desc[] = {
00398   SLE_CONDVAR(Livery, in_use,  SLE_BOOL,  34, SL_MAX_VERSION),
00399   SLE_CONDVAR(Livery, colour1, SLE_UINT8, 34, SL_MAX_VERSION),
00400   SLE_CONDVAR(Livery, colour2, SLE_UINT8, 34, SL_MAX_VERSION),
00401   SLE_END()
00402 };
00403 
00404 static void SaveLoad_PLYR_common(Company *c, CompanyProperties *cprops)
00405 {
00406   int i;
00407 
00408   SlObject(cprops, _company_desc);
00409   if (c != NULL) {
00410     SlObject(c, _company_settings_desc);
00411   } else {
00412     char nothing;
00413     SlObject(&nothing, _company_settings_skip_desc);
00414   }
00415 
00416   /* Keep backwards compatible for savegames, so load the old AI block */
00417   if (IsSavegameVersionBefore(107) && cprops->is_ai) {
00418     CompanyOldAI old_ai;
00419     char nothing;
00420 
00421     SlObject(&old_ai, _company_ai_desc);
00422     for (i = 0; i != old_ai.num_build_rec; i++) {
00423       SlObject(&nothing, _company_ai_build_rec_desc);
00424     }
00425   }
00426 
00427   /* Write economy */
00428   SlObject(&cprops->cur_economy, _company_economy_desc);
00429 
00430   /* Write old economy entries. */
00431   for (i = 0; i < cprops->num_valid_stat_ent; i++) {
00432     SlObject(&cprops->old_economy[i], _company_economy_desc);
00433   }
00434 
00435   /* Write each livery entry. */
00436   int num_liveries = IsSavegameVersionBefore(63) ? LS_END - 4 : (IsSavegameVersionBefore(85) ? LS_END - 2: LS_END);
00437   if (c != NULL) {
00438     for (i = 0; i < num_liveries; i++) {
00439       SlObject(&c->livery[i], _company_livery_desc);
00440     }
00441 
00442     if (num_liveries < LS_END) {
00443       /* We want to insert some liveries somewhere in between. This means some have to be moved. */
00444       memmove(&c->livery[LS_FREIGHT_WAGON], &c->livery[LS_PASSENGER_WAGON_MONORAIL], (LS_END - LS_FREIGHT_WAGON) * sizeof(c->livery[0]));
00445       c->livery[LS_PASSENGER_WAGON_MONORAIL] = c->livery[LS_MONORAIL];
00446       c->livery[LS_PASSENGER_WAGON_MAGLEV]   = c->livery[LS_MAGLEV];
00447     }
00448 
00449     if (num_liveries == LS_END - 4) {
00450       /* Copy bus/truck liveries over to trams */
00451       c->livery[LS_PASSENGER_TRAM] = c->livery[LS_BUS];
00452       c->livery[LS_FREIGHT_TRAM]   = c->livery[LS_TRUCK];
00453     }
00454   } else {
00455     /* Skip liveries */
00456     Livery dummy_livery;
00457     for (i = 0; i < num_liveries; i++) {
00458       SlObject(&dummy_livery, _company_livery_desc);
00459     }
00460   }
00461 }
00462 
00463 static void SaveLoad_PLYR(Company *c)
00464 {
00465   SaveLoad_PLYR_common(c, c);
00466 }
00467 
00468 static void Save_PLYR()
00469 {
00470   Company *c;
00471   FOR_ALL_COMPANIES(c) {
00472     SlSetArrayIndex(c->index);
00473     SlAutolength((AutolengthProc*)SaveLoad_PLYR, c);
00474   }
00475 }
00476 
00477 static void Load_PLYR()
00478 {
00479   int index;
00480   while ((index = SlIterateArray()) != -1) {
00481     Company *c = new (index) Company();
00482     SaveLoad_PLYR(c);
00483     _company_colours[index] = (Colours)c->colour;
00484   }
00485 }
00486 
00487 static void Check_PLYR()
00488 {
00489   int index;
00490   while ((index = SlIterateArray()) != -1) {
00491     CompanyProperties *cprops = new CompanyProperties();
00492     memset(cprops, 0, sizeof(*cprops));
00493     SaveLoad_PLYR_common(NULL, cprops);
00494 
00495     /* We do not load old custom names */
00496     if (IsSavegameVersionBefore(84))
00497     {
00498       if (GB(cprops->name_1, 11, 5) == 15) {
00499         cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
00500       }
00501 
00502       if (GB(cprops->president_name_1, 11, 5) == 15) {
00503         cprops->president_name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
00504       }
00505     }
00506 
00507     if (!_load_check_data.companies.Insert(index, cprops)) delete cprops;
00508   }
00509 }
00510 
00511 static void Ptrs_PLYR()
00512 {
00513   Company *c;
00514   FOR_ALL_COMPANIES(c) {
00515     SlObject(c, _company_settings_desc);
00516   }
00517 }
00518 
00519 
00520 extern const ChunkHandler _company_chunk_handlers[] = {
00521   { 'PLYR', Save_PLYR, Load_PLYR, Ptrs_PLYR, Check_PLYR, CH_ARRAY | CH_LAST},
00522 };