MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / FixOldVehicles

Function FixOldVehicles

src/saveload/oldloader_sl.cpp:160–208  ·  view source on GitHub ↗

* Convert the old style vehicles into something that resembles * the old new style savegames. Then #AfterLoadGame can handle * the rest of the conversion. */

Source from the content-addressed store, hash-verified

158 * the rest of the conversion.
159 */
160void FixOldVehicles(LoadgameState &ls)
161{
162 for (Vehicle *v : Vehicle::Iterate()) {
163 if ((size_t)v->next == 0xFFFF) {
164 v->next = nullptr;
165 } else {
166 v->next = Vehicle::GetIfValid((size_t)v->next);
167 }
168
169 /* For some reason we need to correct for this */
170 switch (v->spritenum) {
171 case 0xfd: break;
172 case 0xff: v->spritenum = 0xfe; break;
173 default: v->spritenum >>= 1; break;
174 }
175
176 /* Vehicle-subtype is different in TTD(Patch) */
177 if (v->type == VEH_EFFECT) v->subtype = v->subtype >> 1;
178
179 v->name = CopyFromOldName(ls.vehicle_names[v->index.base()]);
180
181 /* We haven't used this bit for stations for ages */
182 if (v->type == VEH_ROAD) {
183 RoadVehicle *rv = RoadVehicle::From(v);
184 if (rv->state != RVSB_IN_DEPOT && rv->state != RVSB_WORMHOLE) {
185 ClrBit(rv->state, 2);
186 Tile tile(rv->tile);
187 if (IsTileType(tile, MP_STATION) && tile.m5() >= 168) {
188 /* Update the vehicle's road state to show we're in a drive through road stop. */
189 SetBit(rv->state, RVS_IN_DT_ROAD_STOP);
190 }
191 }
192 }
193
194 /* The subtype should be 0, but it sometimes isn't :( */
195 if (v->type == VEH_ROAD || v->type == VEH_SHIP) v->subtype = 0;
196
197 /* Sometimes primary vehicles would have a nothing (invalid) order
198 * or vehicles that could not have an order would still have a
199 * (loading) order which causes assertions and the like later on.
200 */
201 if (!IsCompanyBuildableVehicleType(v) ||
202 (v->IsPrimaryVehicle() && v->current_order.IsType(OT_NOTHING))) {
203 v->current_order.MakeDummy();
204 }
205
206 /* Shared orders are fixed in AfterLoadVehicles now */
207 }
208}
209
210static bool FixTTOMapArray()
211{

Callers 2

LoadTTDMainFunction · 0.85
LoadTTOMainFunction · 0.85

Calls 9

CopyFromOldNameFunction · 0.85
ClrBitFunction · 0.85
IsTileTypeFunction · 0.85
SetBitFunction · 0.85
IsTypeMethod · 0.80
MakeDummyMethod · 0.80
baseMethod · 0.45
IsPrimaryVehicleMethod · 0.45

Tested by

no test coverage detected