diff options
author | smatz <smatz@openttd.org> | 2009-05-26 22:45:48 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2009-05-26 22:45:48 +0000 |
commit | 5a463c8347fe1e68ab31dda1425e9060d52bfbd6 (patch) | |
tree | 55f5c9de8dcbda6268d003b29af59650594ce27a /src/saveload | |
parent | 7ee882d03f4c41d8659ed82fd5be0d0efbae0a0c (diff) | |
download | openttd-5a463c8347fe1e68ab31dda1425e9060d52bfbd6.tar.xz |
(svn r16442) -Codechange: use new Vehicle accessors at more places
Diffstat (limited to 'src/saveload')
-rw-r--r-- | src/saveload/afterload.cpp | 27 | ||||
-rw-r--r-- | src/saveload/vehicle_sl.cpp | 84 |
2 files changed, 52 insertions, 59 deletions
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index c4f9b9c81..36dca96bc 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -314,9 +314,9 @@ static void FixOwnerOfRailTrack(TileIndex t) assert(!Company::IsValidID(GetTileOwner(t)) && (IsLevelCrossingTile(t) || IsPlainRailTile(t))); /* remove leftover rail piece from crossing (from very old savegames) */ - Vehicle *v = NULL, *w; - FOR_ALL_VEHICLES(w) { - if (w->type == VEH_TRAIN && w->tile == t) { + Train *v = NULL, *w; + FOR_ALL_TRAINS(w) { + if (w->tile == t) { v = w; break; } @@ -1286,10 +1286,10 @@ bool AfterLoadGame() } if (CheckSavegameVersion(50)) { - Vehicle *v; + Aircraft *v; /* Aircraft units changed from 8 mph to 1 km/h */ - FOR_ALL_VEHICLES(v) { - if (v->type == VEH_AIRCRAFT && v->subtype <= AIR_AIRCRAFT) { + FOR_ALL_AIRCRAFT(v) { + if (v->subtype <= AIR_AIRCRAFT) { const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type); v->cur_speed *= 129; v->cur_speed /= 10; @@ -1624,10 +1624,9 @@ bool AfterLoadGame() if (CheckSavegameVersion(62)) { /* Remove all trams from savegames without tram support. * There would be trams without tram track under causing crashes sooner or later. */ - Vehicle *v; - FOR_ALL_VEHICLES(v) { - if (v->type == VEH_ROAD && v->First() == v && - HasBit(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM)) { + RoadVehicle *v; + FOR_ALL_ROADVEHICLES(v) { + if (v->First() == v && HasBit(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM)) { if (_switch_mode_errorstr == INVALID_STRING_ID || _switch_mode_errorstr == STR_NEWGRF_COMPATIBLE_LOAD_WARNING) { _switch_mode_errorstr = STR_LOADGAME_REMOVED_TRAMS; } @@ -1735,11 +1734,11 @@ bool AfterLoadGame() } if (CheckSavegameVersion(104)) { - Vehicle *v; - FOR_ALL_VEHICLES(v) { + Aircraft *a; + FOR_ALL_AIRCRAFT(a) { /* Set engine_type of shadow and rotor */ - if (v->type == VEH_AIRCRAFT && !IsNormalAircraft(v)) { - v->engine_type = v->First()->engine_type; + if (!IsNormalAircraft(a)) { + a->engine_type = a->First()->engine_type; } } diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp index 65c1347d0..ae3b539e9 100644 --- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -100,55 +100,49 @@ void ConnectMultiheadedTrains() */ void ConvertOldMultiheadToNew() { - Vehicle *v; - FOR_ALL_VEHICLES(v) { - if (v->type == VEH_TRAIN) { - SetBit(v->subtype, 7); // indicates that it's the old format and needs to be converted in the next loop - } - } - - FOR_ALL_VEHICLES(v) { - if (v->type == VEH_TRAIN) { - if (HasBit(v->subtype, 7) && ((v->subtype & ~0x80) == 0 || (v->subtype & ~0x80) == 4)) { - for (Vehicle *u = v; u != NULL; u = u->Next()) { - const RailVehicleInfo *rvi = RailVehInfo(u->engine_type); - - ClrBit(u->subtype, 7); - switch (u->subtype) { - case 0: // TS_Front_Engine - if (rvi->railveh_type == RAILVEH_MULTIHEAD) SetMultiheaded(u); - SetFrontEngine(u); - SetTrainEngine(u); - break; - - case 1: // TS_Artic_Part - u->subtype = 0; - SetArticulatedPart(u); - break; + Train *t; + FOR_ALL_TRAINS(t) SetBit(t->subtype, 7); // indicates that it's the old format and needs to be converted in the next loop + + FOR_ALL_TRAINS(t) { + if (HasBit(t->subtype, 7) && ((t->subtype & ~0x80) == 0 || (t->subtype & ~0x80) == 4)) { + for (Vehicle *u = t; u != NULL; u = u->Next()) { + const RailVehicleInfo *rvi = RailVehInfo(u->engine_type); + + ClrBit(u->subtype, 7); + switch (u->subtype) { + case 0: // TS_Front_Engine + if (rvi->railveh_type == RAILVEH_MULTIHEAD) SetMultiheaded(u); + SetFrontEngine(u); + SetTrainEngine(u); + break; - case 2: // TS_Not_First - u->subtype = 0; - if (rvi->railveh_type == RAILVEH_WAGON) { - /* normal wagon */ - SetTrainWagon(u); - break; - } - if (rvi->railveh_type == RAILVEH_MULTIHEAD && rvi->image_index == u->spritenum - 1) { - /* rear end of a multiheaded engine */ - SetMultiheaded(u); - break; - } - if (rvi->railveh_type == RAILVEH_MULTIHEAD) SetMultiheaded(u); - SetTrainEngine(u); - break; + case 1: // TS_Artic_Part + u->subtype = 0; + SetArticulatedPart(u); + break; - case 4: // TS_Free_Car - u->subtype = 0; + case 2: // TS_Not_First + u->subtype = 0; + if (rvi->railveh_type == RAILVEH_WAGON) { + /* normal wagon */ SetTrainWagon(u); - SetFreeWagon(u); break; - default: NOT_REACHED(); - } + } + if (rvi->railveh_type == RAILVEH_MULTIHEAD && rvi->image_index == u->spritenum - 1) { + /* rear end of a multiheaded engine */ + SetMultiheaded(u); + break; + } + if (rvi->railveh_type == RAILVEH_MULTIHEAD) SetMultiheaded(u); + SetTrainEngine(u); + break; + + case 4: // TS_Free_Car + u->subtype = 0; + SetTrainWagon(u); + SetFreeWagon(u); + break; + default: NOT_REACHED(); } } } |