/** * Perform all steps to upgrade from the old station buoys to the new version * that uses waypoints. This includes some old saveload mechanics. */ void MoveBuoysToWaypoints() { /* Buoy orders become waypoint orders */ OrderList *ol; FOR_ALL_ORDER_LISTS(ol) { if (ol->GetFirstSharedVehicle()->type != VEH_SHIP) continue; for (Order *o = ol->GetFirstOrder(); o != NULL; o = o->next) UpdateWaypointOrder(o); } Vehicle *v; FOR_ALL_VEHICLES(v) { if (v->type != VEH_SHIP) continue; UpdateWaypointOrder(&v->current_order); } /* Now make the stations waypoints */ Station *st; FOR_ALL_STATIONS(st) { if ((st->had_vehicle_of_type & HVOT_WAYPOINT) == 0) continue; StationID index = st->index; TileIndex xy = st->xy; Town *town = st->town; StringID string_id = st->string_id; char *name = st->name; Date build_date = st->build_date; /* Delete the station, so we can make it a real waypoint. */ delete st; Waypoint *wp = new (index) Waypoint(xy); wp->town = town; wp->string_id = STR_SV_STNAME_BUOY; wp->name = name; wp->delete_ctr = 0; // Just reset delete counter for once. wp->build_date = build_date; wp->owner = OWNER_NONE; if (IsInsideBS(string_id, STR_SV_STNAME_BUOY, 9)) wp->town_cn = string_id - STR_SV_STNAME_BUOY; if (IsBuoyTile(xy) && GetStationIndex(xy) == index) { wp->facilities |= FACIL_DOCK; } wp->rect.BeforeAddTile(xy, StationRect::ADD_FORCE); } }
/** * Perform all steps to upgrade from the old station buoys to the new version * that uses waypoints. This includes some old saveload mechanics. */ void MoveBuoysToWaypoints() { /* Buoy orders become waypoint orders */ OrderList *ol; FOR_ALL_ORDER_LISTS(ol) { VehicleType vt = ol->GetFirstSharedVehicle()->type; if (vt != VEH_SHIP && vt != VEH_TRAIN) continue; for (Order *o = ol->GetFirstOrder(); o != NULL; o = o->next) UpdateWaypointOrder(o); } Vehicle *v; FOR_ALL_VEHICLES(v) { VehicleType vt = v->type; if (vt != VEH_SHIP && vt != VEH_TRAIN) continue; UpdateWaypointOrder(&v->current_order); } /* Now make the stations waypoints */ Station *st; FOR_ALL_STATIONS(st) { if ((st->had_vehicle_of_type & HVOT_WAYPOINT) == 0) continue; StationID index = st->index; TileIndex xy = st->xy; Town *town = st->town; StringID string_id = st->string_id; char *name = st->name; st->name = NULL; Date build_date = st->build_date; /* TTDPatch could use "buoys with rail station" for rail waypoints */ bool train = st->train_station.tile != INVALID_TILE; TileArea train_st = st->train_station; /* Delete the station, so we can make it a real waypoint. */ delete st; /* Stations and waypoints are in the same pool, so if a station * is deleted there must be place for a Waypoint. */ assert(Waypoint::CanAllocateItem()); Waypoint *wp = new (index) Waypoint(xy); wp->town = town; wp->string_id = train ? STR_SV_STNAME_WAYPOINT : STR_SV_STNAME_BUOY; wp->name = name; wp->delete_ctr = 0; // Just reset delete counter for once. wp->build_date = build_date; wp->owner = train ? GetTileOwner(xy) : OWNER_NONE; if (IsInsideBS(string_id, STR_SV_STNAME_BUOY, 9)) wp->town_cn = string_id - STR_SV_STNAME_BUOY; if (train) { /* When we make a rail waypoint of the station, convert the map as well. */ TILE_AREA_LOOP(t, train_st) { if (!IsTileType(t, MP_STATION) || GetStationIndex(t) != index) continue; SB(_me[t].m6, 3, 3, STATION_WAYPOINT); wp->rect.BeforeAddTile(t, StationRect::ADD_FORCE); } wp->train_station = train_st; wp->facilities |= FACIL_TRAIN; } else if (IsBuoyTile(xy) && GetStationIndex(xy) == index) { wp->rect.BeforeAddTile(xy, StationRect::ADD_FORCE); wp->facilities |= FACIL_DOCK; } }
/** * Perform all steps to upgrade from the old waypoints to the new version * that uses station. This includes some old saveload mechanics. */ void MoveWaypointsToBaseStations() { /* In version 17, ground type is moved from m2 to m4 for depots and * waypoints to make way for storing the index in m2. The custom graphics * id which was stored in m4 is now saved as a grf/id reference in the * waypoint struct. */ if (IsSavegameVersionBefore(17)) { for (OldWaypoint *wp = _old_waypoints.Begin(); wp != _old_waypoints.End(); wp++) { if (wp->delete_ctr != 0) continue; // The waypoint was deleted /* Waypoint indices were not added to the map prior to this. */ _m[wp->xy].m2 = (StationID)wp->index; if (HasBit(_m[wp->xy].m3, 4)) { wp->spec = StationClass::Get(STAT_CLASS_WAYP, _m[wp->xy].m4 + 1); } } } else { /* As of version 17, we recalculate the custom graphic ID of waypoints * from the GRF ID / station index. */ for (OldWaypoint *wp = _old_waypoints.Begin(); wp != _old_waypoints.End(); wp++) { for (uint i = 0; i < StationClass::GetCount(STAT_CLASS_WAYP); i++) { const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP, i); if (statspec != NULL && statspec->grf_prop.grffile->grfid == wp->grfid && statspec->grf_prop.local_id == wp->localidx) { wp->spec = statspec; break; } } } } if (!Waypoint::CanAllocateItem(_old_waypoints.Length())) SlError(STR_ERROR_TOO_MANY_STATIONS_LOADING); /* All saveload conversions have been done. Create the new waypoints! */ for (OldWaypoint *wp = _old_waypoints.Begin(); wp != _old_waypoints.End(); wp++) { Waypoint *new_wp = new Waypoint(wp->xy); new_wp->town = wp->town; new_wp->town_cn = wp->town_cn; new_wp->name = wp->name; new_wp->delete_ctr = 0; // Just reset delete counter for once. new_wp->build_date = wp->build_date; new_wp->owner = wp->owner; new_wp->string_id = STR_SV_STNAME_WAYPOINT; TileIndex t = wp->xy; if (IsTileType(t, MP_RAILWAY) && GetRailTileType(t) == 2 /* RAIL_TILE_WAYPOINT */ && _m[t].m2 == wp->index) { /* The tile might've been reserved! */ bool reserved = !IsSavegameVersionBefore(100) && HasBit(_m[t].m5, 4); /* The tile really has our waypoint, so reassign the map array */ MakeRailWaypoint(t, GetTileOwner(t), new_wp->index, (Axis)GB(_m[t].m5, 0, 1), 0, GetRailType(t)); new_wp->facilities |= FACIL_TRAIN; new_wp->owner = GetTileOwner(t); SetRailStationReservation(t, reserved); if (wp->spec != NULL) { SetCustomStationSpecIndex(t, AllocateSpecToStation(wp->spec, new_wp, true)); } new_wp->rect.BeforeAddTile(t, StationRect::ADD_FORCE); } wp->new_index = new_wp->index; } /* Update the orders of vehicles */ OrderList *ol; FOR_ALL_ORDER_LISTS(ol) { if (ol->GetFirstSharedVehicle()->type != VEH_TRAIN) continue; for (Order *o = ol->GetFirstOrder(); o != NULL; o = o->next) UpdateWaypointOrder(o); } Vehicle *v; FOR_ALL_VEHICLES(v) { if (v->type != VEH_TRAIN) continue; UpdateWaypointOrder(&v->current_order); } _old_waypoints.Reset(); }