summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2019-04-06 07:46:15 +0100
committerMichael Lutz <michi@icosahedron.de>2019-05-01 21:36:27 +0200
commitc02ef3e4564b7b54d49f0827d2d7625cbc38f335 (patch)
tree1c0ee62b6ce55124b247daaafa42300bfaa932e7 /src/saveload
parent21edf67f89c60351d5a0d84625455aa296b6b950 (diff)
downloadopenttd-c02ef3e4564b7b54d49f0827d2d7625cbc38f335.tar.xz
Feature: Add NotRoadTypes (NRT)
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/afterload.cpp91
-rw-r--r--src/saveload/company_sl.cpp23
-rw-r--r--src/saveload/saveload.h1
-rw-r--r--src/saveload/vehicle_sl.cpp16
4 files changed, 92 insertions, 39 deletions
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 6b273e026..662f5a77b 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -282,6 +282,12 @@ static void InitializeWindowsAndCaches()
(*it)->tile = t->xy;
}
}
+ RoadVehicle *rv;
+ FOR_ALL_ROADVEHICLES(rv) {
+ if (rv->IsFrontEngine()) {
+ rv->CargoChanged();
+ }
+ }
RecomputePrices();
@@ -461,8 +467,19 @@ static void FixOwnerOfRailTrack(TileIndex t)
if (IsLevelCrossingTile(t)) {
/* else change the crossing to normal road (road vehicles won't care) */
- MakeRoadNormal(t, GetCrossingRoadBits(t), GetRoadTypes(t), GetTownIndex(t),
- GetRoadOwner(t, ROADTYPE_ROAD), GetRoadOwner(t, ROADTYPE_TRAM));
+ Owner road = GetRoadOwner(t, RTT_ROAD);
+ Owner tram = GetRoadOwner(t, RTT_TRAM);
+ RoadBits bits = GetCrossingRoadBits(t);
+ bool hasroad = HasBit(_me[t].m7, 6);
+ bool hastram = HasBit(_me[t].m7, 7);
+
+ /* MakeRoadNormal */
+ SetTileType(t, MP_ROAD);
+ SetTileOwner(t, road);
+ _m[t].m3 = (hasroad ? bits : 0);
+ _m[t].m5 = (hastram ? bits : 0) | ROAD_TILE_NORMAL << 6;
+ SB(_me[t].m6, 2, 4, 0);
+ SetRoadOwner(t, RTT_TRAM, tram);
return;
}
@@ -1052,18 +1069,18 @@ bool AfterLoadGame()
break;
case ROAD_TILE_DEPOT: break;
}
- SetRoadTypes(t, ROADTYPES_ROAD);
+ SB(_me[t].m7, 6, 2, 1); // Set pre-NRT road type bits for conversion later.
break;
case MP_STATION:
- if (IsRoadStop(t)) SetRoadTypes(t, ROADTYPES_ROAD);
+ if (IsRoadStop(t)) SB(_me[t].m7, 6, 2, 1);
break;
case MP_TUNNELBRIDGE:
/* Middle part of "old" bridges */
if (old_bridge && IsBridge(t) && HasBit(_m[t].m5, 6)) break;
if (((old_bridge && IsBridge(t)) ? (TransportType)GB(_m[t].m5, 1, 2) : GetTunnelBridgeTransportType(t)) == TRANSPORT_ROAD) {
- SetRoadTypes(t, ROADTYPES_ROAD);
+ SB(_me[t].m7, 6, 2, 1); // Set pre-NRT road type bits for conversion later.
}
break;
@@ -1079,7 +1096,7 @@ bool AfterLoadGame()
for (TileIndex t = 0; t < map_size; t++) {
switch (GetTileType(t)) {
case MP_ROAD:
- if (fix_roadtypes) SetRoadTypes(t, (RoadTypes)GB(_me[t].m7, 5, 3));
+ if (fix_roadtypes) SB(_me[t].m7, 6, 2, (RoadTypes)GB(_me[t].m7, 5, 3));
SB(_me[t].m7, 5, 1, GB(_m[t].m3, 7, 1)); // snow/desert
switch (GetRoadTileType(t)) {
default: SlErrorCorrupt("Invalid road tile type");
@@ -1112,7 +1129,7 @@ bool AfterLoadGame()
case MP_STATION:
if (!IsRoadStop(t)) break;
- if (fix_roadtypes) SetRoadTypes(t, (RoadTypes)GB(_m[t].m3, 0, 3));
+ if (fix_roadtypes) SB(_me[t].m7, 6, 2, (RoadTypes)GB(_m[t].m3, 0, 3));
SB(_me[t].m7, 0, 5, HasBit(_me[t].m6, 2) ? OWNER_TOWN : GetTileOwner(t));
SB(_m[t].m3, 4, 4, _m[t].m1);
_m[t].m4 = 0;
@@ -1121,7 +1138,7 @@ bool AfterLoadGame()
case MP_TUNNELBRIDGE:
if (old_bridge && IsBridge(t) && HasBit(_m[t].m5, 6)) break;
if (((old_bridge && IsBridge(t)) ? (TransportType)GB(_m[t].m5, 1, 2) : GetTunnelBridgeTransportType(t)) == TRANSPORT_ROAD) {
- if (fix_roadtypes) SetRoadTypes(t, (RoadTypes)GB(_m[t].m3, 0, 3));
+ if (fix_roadtypes) SB(_me[t].m7, 6, 2, (RoadTypes)GB(_m[t].m3, 0, 3));
Owner o = GetTileOwner(t);
SB(_me[t].m7, 0, 5, o); // road owner
@@ -1191,13 +1208,14 @@ bool AfterLoadGame()
} else {
TownID town = IsTileOwner(t, OWNER_TOWN) ? ClosestTownFromTile(t, UINT_MAX)->index : 0;
- MakeRoadNormal(
- t,
- axis == AXIS_X ? ROAD_Y : ROAD_X,
- ROADTYPES_ROAD,
- town,
- GetTileOwner(t), OWNER_NONE
- );
+ /* MakeRoadNormal */
+ SetTileType(t, MP_ROAD);
+ _m[t].m2 = town;
+ _m[t].m3 = 0;
+ _m[t].m5 = (axis == AXIS_X ? ROAD_Y : ROAD_X) | ROAD_TILE_NORMAL << 6;
+ SB(_me[t].m6, 2, 4, 0);
+ _me[t].m7 = 1 << 6;
+ SetRoadOwner(t, RTT_TRAM, OWNER_NONE);
}
} else {
if (GB(_m[t].m5, 3, 2) == 0) {
@@ -1252,6 +1270,35 @@ bool AfterLoadGame()
}
}
+ if (IsSavegameVersionBefore(SLV_ROAD_TYPES)) {
+ /* Add road subtypes */
+ for (TileIndex t = 0; t < map_size; t++) {
+ bool has_road = false;
+ switch (GetTileType(t)) {
+ case MP_ROAD:
+ has_road = true;
+ break;
+ case MP_STATION:
+ has_road = IsRoadStop(t);
+ break;
+ case MP_TUNNELBRIDGE:
+ has_road = GetTunnelBridgeTransportType(t) == TRANSPORT_ROAD;
+ break;
+ default:
+ break;
+ }
+
+ if (has_road) {
+ RoadType road_rt = HasBit(_me[t].m7, 6) ? ROADTYPE_ROAD : INVALID_ROADTYPE;
+ RoadType tram_rt = HasBit(_me[t].m7, 7) ? ROADTYPE_TRAM : INVALID_ROADTYPE;
+
+ assert(road_rt != INVALID_ROADTYPE || tram_rt != INVALID_ROADTYPE);
+ SetRoadTypes(t, road_rt, tram_rt);
+ SB(_me[t].m7, 6, 2, 0); // Clear pre-NRT road type bits.
+ }
+ }
+ }
+
/* Elrails got added in rev 24 */
if (IsSavegameVersionBefore(SLV_24)) {
RailType min_rail = RAILTYPE_ELECTRIC;
@@ -1375,7 +1422,7 @@ bool AfterLoadGame()
Company *c;
FOR_ALL_COMPANIES(c) {
c->avail_railtypes = GetCompanyRailtypes(c->index);
- c->avail_roadtypes = GetCompanyRoadtypes(c->index);
+ c->avail_roadtypes = GetCompanyRoadTypes(c->index);
}
if (!IsSavegameVersionBefore(SLV_27)) AfterLoadStations();
@@ -1846,10 +1893,10 @@ bool AfterLoadGame()
}
} else if (IsTileType(t, MP_ROAD)) {
/* works for all RoadTileType */
- for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
+ FOR_ALL_ROADTRAMTYPES(rtt) {
/* update even non-existing road types to update tile owner too */
- Owner o = GetRoadOwner(t, rt);
- if (o < MAX_COMPANIES && !Company::IsValidID(o)) SetRoadOwner(t, rt, OWNER_NONE);
+ Owner o = GetRoadOwner(t, rtt);
+ if (o < MAX_COMPANIES && !Company::IsValidID(o)) SetRoadOwner(t, rtt, OWNER_NONE);
}
if (IsLevelCrossing(t)) {
if (!Company::IsValidID(GetTileOwner(t))) FixOwnerOfRailTrack(t);
@@ -2662,7 +2709,7 @@ bool AfterLoadGame()
if (rv->state == RVSB_IN_DEPOT || rv->state == RVSB_WORMHOLE) break;
- TrackStatus ts = GetTileTrackStatus(rv->tile, TRANSPORT_ROAD, rv->compatible_roadtypes);
+ TrackStatus ts = GetTileTrackStatus(rv->tile, TRANSPORT_ROAD, GetRoadTramType(rv->roadtype));
TrackBits trackbits = TrackStatusToTrackBits(ts);
/* Only X/Y tracks can be sloped. */
@@ -2871,8 +2918,8 @@ bool AfterLoadGame()
for (TileIndex t = 0; t < map_size; t++) {
if (!IsStandardRoadStopTile(t)) continue;
Owner o = GetTileOwner(t);
- SetRoadOwner(t, ROADTYPE_ROAD, o);
- SetRoadOwner(t, ROADTYPE_TRAM, o);
+ SetRoadOwner(t, RTT_ROAD, o);
+ SetRoadOwner(t, RTT_TRAM, o);
}
}
diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp
index 6c88db727..f934848e9 100644
--- a/src/saveload/company_sl.cpp
+++ b/src/saveload/company_sl.cpp
@@ -131,11 +131,12 @@ void AfterLoadCompanyStats()
}
/* Iterate all present road types as each can have a different owner. */
- RoadType rt;
- FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
- c = Company::GetIfValid(IsRoadDepot(tile) ? GetTileOwner(tile) : GetRoadOwner(tile, rt));
+ FOR_ALL_ROADTRAMTYPES(rtt) {
+ RoadType rt = GetRoadType(tile, rtt);
+ if (rt == INVALID_ROADTYPE) continue;
+ c = Company::GetIfValid(IsRoadDepot(tile) ? GetTileOwner(tile) : GetRoadOwner(tile, rtt));
/* A level crossings and depots have two road bits. */
- if (c != nullptr) c->infrastructure.road[rt] += IsNormalRoad(tile) ? CountBits(GetRoadBits(tile, rt)) : 2;
+ if (c != nullptr) c->infrastructure.road[rt] += IsNormalRoad(tile) ? CountBits(GetRoadBits(tile, rtt)) : 2;
}
break;
}
@@ -153,9 +154,10 @@ void AfterLoadCompanyStats()
case STATION_BUS:
case STATION_TRUCK: {
/* Iterate all present road types as each can have a different owner. */
- RoadType rt;
- FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
- c = Company::GetIfValid(GetRoadOwner(tile, rt));
+ FOR_ALL_ROADTRAMTYPES(rtt) {
+ RoadType rt = GetRoadType(tile, rtt);
+ if (rt == INVALID_ROADTYPE) continue;
+ c = Company::GetIfValid(GetRoadOwner(tile, rtt));
if (c != nullptr) c->infrastructure.road[rt] += 2; // A road stop has two road bits.
}
break;
@@ -210,9 +212,10 @@ void AfterLoadCompanyStats()
case TRANSPORT_ROAD: {
/* Iterate all present road types as each can have a different owner. */
- RoadType rt;
- FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
- c = Company::GetIfValid(GetRoadOwner(tile, rt));
+ FOR_ALL_ROADTRAMTYPES(rtt) {
+ RoadType rt = GetRoadType(tile, rtt);
+ if (rt == INVALID_ROADTYPE) continue;
+ c = Company::GetIfValid(GetRoadOwner(tile, rtt));
if (c != nullptr) c->infrastructure.road[rt] += len * 2; // A full diagonal road has two road bits.
}
break;
diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h
index 966de0c8a..7ac602a54 100644
--- a/src/saveload/saveload.h
+++ b/src/saveload/saveload.h
@@ -298,6 +298,7 @@ enum SaveLoadVersion : uint16 {
SLV_ROADVEH_PATH_CACHE, ///< 211 PR#7261 Add path cache for road vehicles.
SLV_REMOVE_OPF, ///< 212 PR#7245 Remove OPF.
SLV_TREES_WATER_CLASS, ///< 213 PR#7405 WaterClass update for tree tiles.
+ SLV_ROAD_TYPES, ///< 214 PR#6811 NewGRF road types.
SL_MAX_VERSION, ///< Highest possible saveload version
};
diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp
index c42e3938f..b08c1cb5e 100644
--- a/src/saveload/vehicle_sl.cpp
+++ b/src/saveload/vehicle_sl.cpp
@@ -410,6 +410,14 @@ void AfterLoadVehicles(bool part_of_load)
RoadVehicle *rv = RoadVehicle::From(v);
if (rv->IsFrontEngine()) {
rv->gcache.last_speed = rv->cur_speed; // update displayed road vehicle speed
+
+ rv->roadtype = Engine::Get(rv->engine_type)->u.road.roadtype;
+ rv->compatible_roadtypes = GetRoadTypeInfo(rv->roadtype)->powered_roadtypes;
+ for (RoadVehicle *u = rv; u != nullptr; u = u->Next()) {
+ u->roadtype = rv->roadtype;
+ u->compatible_roadtypes = rv->compatible_roadtypes;
+ }
+
RoadVehUpdateCache(rv);
if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
rv->CargoChanged();
@@ -448,13 +456,7 @@ void AfterLoadVehicles(bool part_of_load)
FOR_ALL_VEHICLES(v) {
switch (v->type) {
- case VEH_ROAD: {
- RoadVehicle *rv = RoadVehicle::From(v);
- rv->roadtype = HasBit(EngInfo(v->First()->engine_type)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD;
- rv->compatible_roadtypes = RoadTypeToRoadTypes(rv->roadtype);
- FALLTHROUGH;
- }
-
+ case VEH_ROAD:
case VEH_TRAIN:
case VEH_SHIP:
v->GetImage(v->direction, EIT_ON_MAP, &v->sprite_seq);