Codechange: make use of Tile in for all direct map accesses
This commit is contained in:
@@ -77,7 +77,7 @@ extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMP
|
||||
* @param t the tile to change.
|
||||
* @param include_invalid_water_class Also consider WATER_CLASS_INVALID, i.e. industry tiles on land
|
||||
*/
|
||||
void SetWaterClassDependingOnSurroundings(TileIndex t, bool include_invalid_water_class)
|
||||
void SetWaterClassDependingOnSurroundings(Tile t, bool include_invalid_water_class)
|
||||
{
|
||||
/* If the slope is not flat, we always assume 'land' (if allowed). Also for one-corner-raised-shores.
|
||||
* Note: Wrt. autosloping under industry tiles this is the most fool-proof behaviour. */
|
||||
@@ -104,7 +104,7 @@ void SetWaterClassDependingOnSurroundings(TileIndex t, bool include_invalid_wate
|
||||
bool has_river = false;
|
||||
|
||||
for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
|
||||
TileIndex neighbour = TileAddByDiagDir(t, dir);
|
||||
Tile neighbour = TileAddByDiagDir(t, dir);
|
||||
switch (GetTileType(neighbour)) {
|
||||
case MP_WATER:
|
||||
/* clear water and shipdepots have already a WaterClass associated */
|
||||
@@ -127,7 +127,7 @@ void SetWaterClassDependingOnSurroundings(TileIndex t, bool include_invalid_wate
|
||||
|
||||
case MP_TREES:
|
||||
/* trees on shore */
|
||||
has_water |= (GB(_m[neighbour].m2, 4, 2) == TREE_GROUND_SHORE);
|
||||
has_water |= (GB(neighbour.m2(), 4, 2) == TREE_GROUND_SHORE);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
@@ -153,13 +153,13 @@ static void ConvertTownOwner()
|
||||
for (auto tile : Map::Iterate()) {
|
||||
switch (GetTileType(tile)) {
|
||||
case MP_ROAD:
|
||||
if (GB(_m[tile].m5, 4, 2) == ROAD_TILE_CROSSING && HasBit(_m[tile].m3, 7)) {
|
||||
_m[tile].m3 = OWNER_TOWN;
|
||||
if (GB(tile.m5(), 4, 2) == ROAD_TILE_CROSSING && HasBit(tile.m3(), 7)) {
|
||||
tile.m3() = OWNER_TOWN;
|
||||
}
|
||||
FALLTHROUGH;
|
||||
|
||||
case MP_TUNNELBRIDGE:
|
||||
if (_m[tile].m1 & 0x80) SetTileOwner(tile, OWNER_TOWN);
|
||||
if (tile.m1() & 0x80) SetTileOwner(tile, OWNER_TOWN);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
@@ -439,14 +439,14 @@ static void CDECL HandleSavegameLoadCrash(int signum)
|
||||
* a rail track had an invalid owner. When conversion isn't possible, track is removed.
|
||||
* @param t tile to update
|
||||
*/
|
||||
static void FixOwnerOfRailTrack(TileIndex t)
|
||||
static void FixOwnerOfRailTrack(Tile t)
|
||||
{
|
||||
assert(!Company::IsValidID(GetTileOwner(t)) && (IsLevelCrossingTile(t) || IsPlainRailTile(t)));
|
||||
|
||||
/* remove leftover rail piece from crossing (from very old savegames) */
|
||||
Train *v = nullptr;
|
||||
for (Train *w : Train::Iterate()) {
|
||||
if (w->tile == t) {
|
||||
if (w->tile == TileIndex(t)) {
|
||||
v = w;
|
||||
break;
|
||||
}
|
||||
@@ -474,15 +474,15 @@ static void FixOwnerOfRailTrack(TileIndex t)
|
||||
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);
|
||||
bool hasroad = HasBit(t.m7(), 6);
|
||||
bool hastram = HasBit(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);
|
||||
t.m3() = (hasroad ? bits : 0);
|
||||
t.m5() = (hastram ? bits : 0) | ROAD_TILE_NORMAL << 6;
|
||||
SB(t.m6(), 2, 4, 0);
|
||||
SetRoadOwner(t, RTT_TRAM, tram);
|
||||
return;
|
||||
}
|
||||
@@ -533,7 +533,7 @@ static uint FixVehicleInclination(Vehicle *v, Direction dir)
|
||||
* @param t The tile to analyze
|
||||
* @return True if a bridge might have been present prior to savegame 194.
|
||||
*/
|
||||
static inline bool MayHaveBridgeAbove(TileIndex t)
|
||||
static inline bool MayHaveBridgeAbove(Tile t)
|
||||
{
|
||||
return IsTileType(t, MP_CLEAR) || IsTileType(t, MP_RAILWAY) || IsTileType(t, MP_ROAD) ||
|
||||
IsTileType(t, MP_WATER) || IsTileType(t, MP_TUNNELBRIDGE) || IsTileType(t, MP_OBJECT);
|
||||
@@ -614,8 +614,8 @@ bool AfterLoadGame()
|
||||
}
|
||||
for (auto t : Map::Iterate()) {
|
||||
if (!IsTileType(t, MP_STATION)) continue;
|
||||
if (_m[t].m5 > 7) continue; // is it a rail station tile?
|
||||
Station *st = Station::Get(_m[t].m2);
|
||||
if (t.m5() > 7) continue; // is it a rail station tile?
|
||||
Station *st = Station::Get(t.m2());
|
||||
assert(st->train_station.tile != 0);
|
||||
int dx = TileX(t) - TileX(st->train_station.tile);
|
||||
int dy = TileY(t) - TileY(st->train_station.tile);
|
||||
@@ -630,14 +630,14 @@ bool AfterLoadGame()
|
||||
|
||||
/* In old savegame versions, the heightlevel was coded in bits 0..3 of the type field */
|
||||
for (auto t : Map::Iterate()) {
|
||||
_m[t].height = GB(_m[t].type, 0, 4);
|
||||
SB(_m[t].type, 0, 2, GB(_me[t].m6, 0, 2));
|
||||
SB(_me[t].m6, 0, 2, 0);
|
||||
t.height() = GB(t.type(), 0, 4);
|
||||
SB(t.type(), 0, 2, GB(t.m6(), 0, 2));
|
||||
SB(t.m6(), 0, 2, 0);
|
||||
if (MayHaveBridgeAbove(t)) {
|
||||
SB(_m[t].type, 2, 2, GB(_me[t].m6, 6, 2));
|
||||
SB(_me[t].m6, 6, 2, 0);
|
||||
SB(t.type(), 2, 2, GB(t.m6(), 6, 2));
|
||||
SB(t.m6(), 6, 2, 0);
|
||||
} else {
|
||||
SB(_m[t].type, 2, 2, 0);
|
||||
SB(t.type(), 2, 2, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -847,7 +847,7 @@ bool AfterLoadGame()
|
||||
break;
|
||||
|
||||
case MP_STATION: {
|
||||
if (HasBit(_me[t].m6, 3)) SetBit(_me[t].m6, 2);
|
||||
if (HasBit(t.m6(), 3)) SetBit(t.m6(), 2);
|
||||
StationGfx gfx = GetStationGfx(t);
|
||||
StationType st;
|
||||
if ( IsInsideMM(gfx, 0, 8)) { // Rail station
|
||||
@@ -885,7 +885,7 @@ bool AfterLoadGame()
|
||||
ResetSignalHandlers();
|
||||
return false;
|
||||
}
|
||||
SB(_me[t].m6, 3, 3, st);
|
||||
SB(t.m6(), 3, 3, st);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -965,13 +965,13 @@ bool AfterLoadGame()
|
||||
for (auto t : Map::Iterate()) {
|
||||
switch (GetTileType(t)) {
|
||||
case MP_HOUSE:
|
||||
_m[t].m4 = _m[t].m2;
|
||||
t.m4() = t.m2();
|
||||
SetTownIndex(t, CalcClosestTownFromTile(t)->index);
|
||||
break;
|
||||
|
||||
case MP_ROAD:
|
||||
_m[t].m4 |= (_m[t].m2 << 4);
|
||||
if ((GB(_m[t].m5, 4, 2) == ROAD_TILE_CROSSING ? (Owner)_m[t].m3 : GetTileOwner(t)) == OWNER_TOWN) {
|
||||
t.m4() |= (t.m2() << 4);
|
||||
if ((GB(t.m5(), 4, 2) == ROAD_TILE_CROSSING ? (Owner)t.m3() : GetTileOwner(t)) == OWNER_TOWN) {
|
||||
SetTownIndex(t, CalcClosestTownFromTile(t)->index);
|
||||
} else {
|
||||
SetTownIndex(t, 0);
|
||||
@@ -1023,20 +1023,20 @@ bool AfterLoadGame()
|
||||
if (IsPlainRail(t)) {
|
||||
/* Swap ground type and signal type for plain rail tiles, so the
|
||||
* ground type uses the same bits as for depots and waypoints. */
|
||||
uint tmp = GB(_m[t].m4, 0, 4);
|
||||
SB(_m[t].m4, 0, 4, GB(_m[t].m2, 0, 4));
|
||||
SB(_m[t].m2, 0, 4, tmp);
|
||||
} else if (HasBit(_m[t].m5, 2)) {
|
||||
uint tmp = GB(t.m4(), 0, 4);
|
||||
SB(t.m4(), 0, 4, GB(t.m2(), 0, 4));
|
||||
SB(t.m2(), 0, 4, tmp);
|
||||
} else if (HasBit(t.m5(), 2)) {
|
||||
/* Split waypoint and depot rail type and remove the subtype. */
|
||||
ClrBit(_m[t].m5, 2);
|
||||
ClrBit(_m[t].m5, 6);
|
||||
ClrBit(t.m5(), 2);
|
||||
ClrBit(t.m5(), 6);
|
||||
}
|
||||
break;
|
||||
|
||||
case MP_ROAD:
|
||||
/* Swap m3 and m4, so the track type for rail crossings is the
|
||||
* same as for normal rail. */
|
||||
Swap(_m[t].m3, _m[t].m4);
|
||||
Swap(t.m3(), t.m4());
|
||||
break;
|
||||
|
||||
default: break;
|
||||
@@ -1050,31 +1050,31 @@ bool AfterLoadGame()
|
||||
for (auto t : Map::Iterate()) {
|
||||
switch (GetTileType(t)) {
|
||||
case MP_ROAD:
|
||||
SB(_m[t].m5, 6, 2, GB(_m[t].m5, 4, 2));
|
||||
SB(t.m5(), 6, 2, GB(t.m5(), 4, 2));
|
||||
switch (GetRoadTileType(t)) {
|
||||
default: SlErrorCorrupt("Invalid road tile type");
|
||||
case ROAD_TILE_NORMAL:
|
||||
SB(_m[t].m4, 0, 4, GB(_m[t].m5, 0, 4));
|
||||
SB(_m[t].m4, 4, 4, 0);
|
||||
SB(_me[t].m6, 2, 4, 0);
|
||||
SB(t.m4(), 0, 4, GB(t.m5(), 0, 4));
|
||||
SB(t.m4(), 4, 4, 0);
|
||||
SB(t.m6(), 2, 4, 0);
|
||||
break;
|
||||
case ROAD_TILE_CROSSING:
|
||||
SB(_m[t].m4, 5, 2, GB(_m[t].m5, 2, 2));
|
||||
SB(t.m4(), 5, 2, GB(t.m5(), 2, 2));
|
||||
break;
|
||||
case ROAD_TILE_DEPOT: break;
|
||||
}
|
||||
SB(_me[t].m7, 6, 2, 1); // Set pre-NRT road type bits for conversion later.
|
||||
SB(t.m7(), 6, 2, 1); // Set pre-NRT road type bits for conversion later.
|
||||
break;
|
||||
|
||||
case MP_STATION:
|
||||
if (IsRoadStop(t)) SB(_me[t].m7, 6, 2, 1);
|
||||
if (IsRoadStop(t)) SB(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) {
|
||||
SB(_me[t].m7, 6, 2, 1); // Set pre-NRT road type bits for conversion later.
|
||||
if (old_bridge && IsBridge(t) && HasBit(t.m5(), 6)) break;
|
||||
if (((old_bridge && IsBridge(t)) ? (TransportType)GB(t.m5(), 1, 2) : GetTunnelBridgeTransportType(t)) == TRANSPORT_ROAD) {
|
||||
SB(t.m7(), 6, 2, 1); // Set pre-NRT road type bits for conversion later.
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1090,24 +1090,24 @@ bool AfterLoadGame()
|
||||
for (auto t : Map::Iterate()) {
|
||||
switch (GetTileType(t)) {
|
||||
case MP_ROAD:
|
||||
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
|
||||
if (fix_roadtypes) SB(t.m7(), 6, 2, (RoadTypes)GB(t.m7(), 5, 3));
|
||||
SB(t.m7(), 5, 1, GB(t.m3(), 7, 1)); // snow/desert
|
||||
switch (GetRoadTileType(t)) {
|
||||
default: SlErrorCorrupt("Invalid road tile type");
|
||||
case ROAD_TILE_NORMAL:
|
||||
SB(_me[t].m7, 0, 4, GB(_m[t].m3, 0, 4)); // road works
|
||||
SB(_me[t].m6, 3, 3, GB(_m[t].m3, 4, 3)); // ground
|
||||
SB(_m[t].m3, 0, 4, GB(_m[t].m4, 4, 4)); // tram bits
|
||||
SB(_m[t].m3, 4, 4, GB(_m[t].m5, 0, 4)); // tram owner
|
||||
SB(_m[t].m5, 0, 4, GB(_m[t].m4, 0, 4)); // road bits
|
||||
SB(t.m7(), 0, 4, GB(t.m3(), 0, 4)); // road works
|
||||
SB(t.m6(), 3, 3, GB(t.m3(), 4, 3)); // ground
|
||||
SB(t.m3(), 0, 4, GB(t.m4(), 4, 4)); // tram bits
|
||||
SB(t.m3(), 4, 4, GB(t.m5(), 0, 4)); // tram owner
|
||||
SB(t.m5(), 0, 4, GB(t.m4(), 0, 4)); // road bits
|
||||
break;
|
||||
|
||||
case ROAD_TILE_CROSSING:
|
||||
SB(_me[t].m7, 0, 5, GB(_m[t].m4, 0, 5)); // road owner
|
||||
SB(_me[t].m6, 3, 3, GB(_m[t].m3, 4, 3)); // ground
|
||||
SB(_m[t].m3, 4, 4, GB(_m[t].m5, 0, 4)); // tram owner
|
||||
SB(_m[t].m5, 0, 1, GB(_m[t].m4, 6, 1)); // road axis
|
||||
SB(_m[t].m5, 5, 1, GB(_m[t].m4, 5, 1)); // crossing state
|
||||
SB(t.m7(), 0, 5, GB(t.m4(), 0, 5)); // road owner
|
||||
SB(t.m6(), 3, 3, GB(t.m3(), 4, 3)); // ground
|
||||
SB(t.m3(), 4, 4, GB(t.m5(), 0, 4)); // tram owner
|
||||
SB(t.m5(), 0, 1, GB(t.m4(), 6, 1)); // road axis
|
||||
SB(t.m5(), 5, 1, GB(t.m4(), 5, 1)); // crossing state
|
||||
break;
|
||||
|
||||
case ROAD_TILE_DEPOT:
|
||||
@@ -1117,32 +1117,32 @@ bool AfterLoadGame()
|
||||
const Town *town = CalcClosestTownFromTile(t);
|
||||
if (town != nullptr) SetTownIndex(t, town->index);
|
||||
}
|
||||
_m[t].m4 = 0;
|
||||
t.m4() = 0;
|
||||
break;
|
||||
|
||||
case MP_STATION:
|
||||
if (!IsRoadStop(t)) break;
|
||||
|
||||
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;
|
||||
if (fix_roadtypes) SB(t.m7(), 6, 2, (RoadTypes)GB(t.m3(), 0, 3));
|
||||
SB(t.m7(), 0, 5, HasBit(t.m6(), 2) ? OWNER_TOWN : GetTileOwner(t));
|
||||
SB(t.m3(), 4, 4, t.m1());
|
||||
t.m4() = 0;
|
||||
break;
|
||||
|
||||
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) SB(_me[t].m7, 6, 2, (RoadTypes)GB(_m[t].m3, 0, 3));
|
||||
if (old_bridge && IsBridge(t) && HasBit(t.m5(), 6)) break;
|
||||
if (((old_bridge && IsBridge(t)) ? (TransportType)GB(t.m5(), 1, 2) : GetTunnelBridgeTransportType(t)) == TRANSPORT_ROAD) {
|
||||
if (fix_roadtypes) SB(t.m7(), 6, 2, (RoadTypes)GB(t.m3(), 0, 3));
|
||||
|
||||
Owner o = GetTileOwner(t);
|
||||
SB(_me[t].m7, 0, 5, o); // road owner
|
||||
SB(_m[t].m3, 4, 4, o == OWNER_NONE ? OWNER_TOWN : o); // tram owner
|
||||
SB(t.m7(), 0, 5, o); // road owner
|
||||
SB(t.m3(), 4, 4, o == OWNER_NONE ? OWNER_TOWN : o); // tram owner
|
||||
}
|
||||
SB(_me[t].m6, 2, 4, GB(_m[t].m2, 4, 4)); // bridge type
|
||||
SB(_me[t].m7, 5, 1, GB(_m[t].m4, 7, 1)); // snow/desert
|
||||
SB(t.m6(), 2, 4, GB(t.m2(), 4, 4)); // bridge type
|
||||
SB(t.m7(), 5, 1, GB(t.m4(), 7, 1)); // snow/desert
|
||||
|
||||
_m[t].m2 = 0;
|
||||
_m[t].m4 = 0;
|
||||
t.m2() = 0;
|
||||
t.m4() = 0;
|
||||
break;
|
||||
|
||||
default: break;
|
||||
@@ -1155,24 +1155,24 @@ bool AfterLoadGame()
|
||||
for (auto t : Map::Iterate()) {
|
||||
switch (GetTileType(t)) {
|
||||
case MP_RAILWAY:
|
||||
SetRailType(t, (RailType)GB(_m[t].m3, 0, 4));
|
||||
SetRailType(t, (RailType)GB(t.m3(), 0, 4));
|
||||
break;
|
||||
|
||||
case MP_ROAD:
|
||||
if (IsLevelCrossing(t)) {
|
||||
SetRailType(t, (RailType)GB(_m[t].m3, 0, 4));
|
||||
SetRailType(t, (RailType)GB(t.m3(), 0, 4));
|
||||
}
|
||||
break;
|
||||
|
||||
case MP_STATION:
|
||||
if (HasStationRail(t)) {
|
||||
SetRailType(t, (RailType)GB(_m[t].m3, 0, 4));
|
||||
SetRailType(t, (RailType)GB(t.m3(), 0, 4));
|
||||
}
|
||||
break;
|
||||
|
||||
case MP_TUNNELBRIDGE:
|
||||
if (GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL) {
|
||||
SetRailType(t, (RailType)GB(_m[t].m3, 0, 4));
|
||||
SetRailType(t, (RailType)GB(t.m3(), 0, 4));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1186,11 +1186,11 @@ bool AfterLoadGame()
|
||||
for (auto t : Map::Iterate()) {
|
||||
if (MayHaveBridgeAbove(t)) ClearBridgeMiddle(t);
|
||||
if (IsBridgeTile(t)) {
|
||||
if (HasBit(_m[t].m5, 6)) { // middle part
|
||||
Axis axis = (Axis)GB(_m[t].m5, 0, 1);
|
||||
if (HasBit(t.m5(), 6)) { // middle part
|
||||
Axis axis = (Axis)GB(t.m5(), 0, 1);
|
||||
|
||||
if (HasBit(_m[t].m5, 5)) { // transport route under bridge?
|
||||
if (GB(_m[t].m5, 3, 2) == TRANSPORT_RAIL) {
|
||||
if (HasBit(t.m5(), 5)) { // transport route under bridge?
|
||||
if (GB(t.m5(), 3, 2) == TRANSPORT_RAIL) {
|
||||
MakeRailNormal(
|
||||
t,
|
||||
GetTileOwner(t),
|
||||
@@ -1202,15 +1202,15 @@ bool AfterLoadGame()
|
||||
|
||||
/* 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;
|
||||
t.m2() = town;
|
||||
t.m3() = 0;
|
||||
t.m5() = (axis == AXIS_X ? ROAD_Y : ROAD_X) | ROAD_TILE_NORMAL << 6;
|
||||
SB(t.m6(), 2, 4, 0);
|
||||
t.m7() = 1 << 6;
|
||||
SetRoadOwner(t, RTT_TRAM, OWNER_NONE);
|
||||
}
|
||||
} else {
|
||||
if (GB(_m[t].m5, 3, 2) == 0) {
|
||||
if (GB(t.m5(), 3, 2) == 0) {
|
||||
MakeClear(t, CLEAR_GRASS, 3);
|
||||
} else {
|
||||
if (!IsTileFlat(t)) {
|
||||
@@ -1226,12 +1226,12 @@ bool AfterLoadGame()
|
||||
}
|
||||
SetBridgeMiddle(t, axis);
|
||||
} else { // ramp
|
||||
Axis axis = (Axis)GB(_m[t].m5, 0, 1);
|
||||
uint north_south = GB(_m[t].m5, 5, 1);
|
||||
Axis axis = (Axis)GB(t.m5(), 0, 1);
|
||||
uint north_south = GB(t.m5(), 5, 1);
|
||||
DiagDirection dir = ReverseDiagDir(XYNSToDiagDir(axis, north_south));
|
||||
TransportType type = (TransportType)GB(_m[t].m5, 1, 2);
|
||||
TransportType type = (TransportType)GB(t.m5(), 1, 2);
|
||||
|
||||
_m[t].m5 = 1 << 7 | type << 2 | dir;
|
||||
t.m5() = 1 << 7 | type << 2 | dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1282,12 +1282,12 @@ bool AfterLoadGame()
|
||||
}
|
||||
|
||||
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;
|
||||
RoadType road_rt = HasBit(t.m7(), 6) ? ROADTYPE_ROAD : INVALID_ROADTYPE;
|
||||
RoadType tram_rt = HasBit(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.
|
||||
SB(t.m7(), 6, 2, 0); // Clear pre-NRT road type bits.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1365,23 +1365,23 @@ bool AfterLoadGame()
|
||||
* (see the code somewhere above) so don't use m4, use m2 instead. */
|
||||
|
||||
/* convert PBS signals to combo-signals */
|
||||
if (HasBit(_m[t].m2, 2)) SB(_m[t].m2, 0, 2, SIGTYPE_COMBO);
|
||||
if (HasBit(t.m2(), 2)) SB(t.m2(), 0, 2, SIGTYPE_COMBO);
|
||||
|
||||
/* move the signal variant back */
|
||||
SB(_m[t].m2, 2, 1, HasBit(_m[t].m2, 3) ? SIG_SEMAPHORE : SIG_ELECTRIC);
|
||||
ClrBit(_m[t].m2, 3);
|
||||
SB(t.m2(), 2, 1, HasBit(t.m2(), 3) ? SIG_SEMAPHORE : SIG_ELECTRIC);
|
||||
ClrBit(t.m2(), 3);
|
||||
}
|
||||
|
||||
/* Clear PBS reservation on track */
|
||||
if (!IsRailDepotTile(t)) {
|
||||
SB(_m[t].m4, 4, 4, 0);
|
||||
SB(t.m4(), 4, 4, 0);
|
||||
} else {
|
||||
ClrBit(_m[t].m3, 6);
|
||||
ClrBit(t.m3(), 6);
|
||||
}
|
||||
break;
|
||||
|
||||
case MP_STATION: // Clear PBS reservation on station
|
||||
ClrBit(_m[t].m3, 6);
|
||||
ClrBit(t.m3(), 6);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
@@ -1475,31 +1475,31 @@ bool AfterLoadGame()
|
||||
if (IsSavegameVersionBefore(SLV_53)) {
|
||||
for (auto t : Map::Iterate()) {
|
||||
if (IsTileType(t, MP_HOUSE)) {
|
||||
if (GB(_m[t].m3, 6, 2) != TOWN_HOUSE_COMPLETED) {
|
||||
if (GB(t.m3(), 6, 2) != TOWN_HOUSE_COMPLETED) {
|
||||
/* Move the construction stage from m3[7..6] to m5[5..4].
|
||||
* The construction counter does not have to move. */
|
||||
SB(_m[t].m5, 3, 2, GB(_m[t].m3, 6, 2));
|
||||
SB(_m[t].m3, 6, 2, 0);
|
||||
SB(t.m5(), 3, 2, GB(t.m3(), 6, 2));
|
||||
SB(t.m3(), 6, 2, 0);
|
||||
|
||||
/* The "house is completed" bit is now in m6[2]. */
|
||||
SetHouseCompleted(t, false);
|
||||
} else {
|
||||
/* The "lift has destination" bit has been moved from
|
||||
* m5[7] to m7[0]. */
|
||||
SB(_me[t].m7, 0, 1, HasBit(_m[t].m5, 7));
|
||||
ClrBit(_m[t].m5, 7);
|
||||
SB(t.m7(), 0, 1, HasBit(t.m5(), 7));
|
||||
ClrBit(t.m5(), 7);
|
||||
|
||||
/* The "lift is moving" bit has been removed, as it does
|
||||
* the same job as the "lift has destination" bit. */
|
||||
ClrBit(_m[t].m1, 7);
|
||||
ClrBit(t.m1(), 7);
|
||||
|
||||
/* The position of the lift goes from m1[7..0] to m6[7..2],
|
||||
* making m1 totally free, now. The lift position does not
|
||||
* have to be a full byte since the maximum value is 36. */
|
||||
SetLiftPosition(t, GB(_m[t].m1, 0, 6 ));
|
||||
SetLiftPosition(t, GB(t.m1(), 0, 6 ));
|
||||
|
||||
_m[t].m1 = 0;
|
||||
_m[t].m3 = 0;
|
||||
t.m1() = 0;
|
||||
t.m3() = 0;
|
||||
SetHouseCompleted(t, true);
|
||||
}
|
||||
}
|
||||
@@ -1514,19 +1514,19 @@ bool AfterLoadGame()
|
||||
if (IsTileType(t, MP_INDUSTRY)) {
|
||||
switch (GetIndustryGfx(t)) {
|
||||
case GFX_POWERPLANT_SPARKS:
|
||||
_m[t].m3 = GB(_m[t].m1, 2, 5);
|
||||
t.m3() = GB(t.m1(), 2, 5);
|
||||
break;
|
||||
|
||||
case GFX_OILWELL_ANIMATED_1:
|
||||
case GFX_OILWELL_ANIMATED_2:
|
||||
case GFX_OILWELL_ANIMATED_3:
|
||||
_m[t].m3 = GB(_m[t].m1, 0, 2);
|
||||
t.m3() = GB(t.m1(), 0, 2);
|
||||
break;
|
||||
|
||||
case GFX_COAL_MINE_TOWER_ANIMATED:
|
||||
case GFX_COPPER_MINE_TOWER_ANIMATED:
|
||||
case GFX_GOLD_MINE_TOWER_ANIMATED:
|
||||
_m[t].m3 = _m[t].m1;
|
||||
t.m3() = t.m1();
|
||||
break;
|
||||
|
||||
default: // No animation states to change
|
||||
@@ -1571,8 +1571,8 @@ bool AfterLoadGame()
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_52)) {
|
||||
for (auto t : Map::Iterate()) {
|
||||
if (IsTileType(t, MP_OBJECT) && _m[t].m5 == OBJECT_STATUE) {
|
||||
_m[t].m2 = CalcClosestTownFromTile(t)->index;
|
||||
if (IsTileType(t, MP_OBJECT) && t.m5() == OBJECT_STATUE) {
|
||||
t.m2() = CalcClosestTownFromTile(t)->index;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1631,10 +1631,10 @@ bool AfterLoadGame()
|
||||
for (auto t : Map::Iterate()) {
|
||||
if (IsTileType(t, MP_RAILWAY) && HasSignals(t)) {
|
||||
/* move signal states */
|
||||
SetSignalStates(t, GB(_m[t].m2, 4, 4));
|
||||
SB(_m[t].m2, 4, 4, 0);
|
||||
SetSignalStates(t, GB(t.m2(), 4, 4));
|
||||
SB(t.m2(), 4, 4, 0);
|
||||
/* clone signal type and variant */
|
||||
SB(_m[t].m2, 4, 3, GB(_m[t].m2, 0, 3));
|
||||
SB(t.m2(), 4, 3, GB(t.m2(), 0, 3));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1675,7 +1675,7 @@ bool AfterLoadGame()
|
||||
if (IsSavegameVersionBefore(SLV_83)) {
|
||||
for (auto t : Map::Iterate()) {
|
||||
if (IsShipDepotTile(t)) {
|
||||
_m[t].m4 = (TileHeight(t) == 0) ? OWNER_WATER : OWNER_NONE;
|
||||
t.m4() = (TileHeight(t) == 0) ? OWNER_WATER : OWNER_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1709,8 +1709,8 @@ bool AfterLoadGame()
|
||||
if (IsSavegameVersionBefore(SLV_81)) {
|
||||
for (auto t : Map::Iterate()) {
|
||||
if (GetTileType(t) == MP_TREES) {
|
||||
TreeGround groundType = (TreeGround)GB(_m[t].m2, 4, 2);
|
||||
if (groundType != TREE_GROUND_SNOW_DESERT) SB(_m[t].m2, 6, 2, 3);
|
||||
TreeGround groundType = (TreeGround)GB(t.m2(), 4, 2);
|
||||
if (groundType != TREE_GROUND_SNOW_DESERT) SB(t.m2(), 6, 2, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1772,8 +1772,8 @@ bool AfterLoadGame()
|
||||
case STATION_OILRIG:
|
||||
case STATION_DOCK:
|
||||
case STATION_BUOY:
|
||||
SetWaterClass(t, (WaterClass)GB(_m[t].m3, 0, 2));
|
||||
SB(_m[t].m3, 0, 2, 0);
|
||||
SetWaterClass(t, (WaterClass)GB(t.m3(), 0, 2));
|
||||
SB(t.m3(), 0, 2, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -1783,8 +1783,8 @@ bool AfterLoadGame()
|
||||
break;
|
||||
|
||||
case MP_WATER:
|
||||
SetWaterClass(t, (WaterClass)GB(_m[t].m3, 0, 2));
|
||||
SB(_m[t].m3, 0, 2, 0);
|
||||
SetWaterClass(t, (WaterClass)GB(t.m3(), 0, 2));
|
||||
SB(t.m3(), 0, 2, 0);
|
||||
break;
|
||||
|
||||
case MP_OBJECT:
|
||||
@@ -1811,7 +1811,7 @@ bool AfterLoadGame()
|
||||
MakeCanal(t, o, Random());
|
||||
}
|
||||
} else if (IsShipDepot(t)) {
|
||||
Owner o = (Owner)_m[t].m4; // Original water owner
|
||||
Owner o = (Owner)t.m4(); // Original water owner
|
||||
SetWaterClass(t, o == OWNER_WATER ? WATER_CLASS_SEA : WATER_CLASS_CANAL);
|
||||
}
|
||||
}
|
||||
@@ -1899,8 +1899,8 @@ bool AfterLoadGame()
|
||||
/* Increase HouseAnimationFrame from 5 to 7 bits */
|
||||
for (auto t : Map::Iterate()) {
|
||||
if (IsTileType(t, MP_HOUSE) && GetHouseType(t) >= NEW_HOUSE_OFFSET) {
|
||||
SB(_me[t].m6, 2, 6, GB(_me[t].m6, 3, 5));
|
||||
SB(_m[t].m3, 5, 1, 0);
|
||||
SB(t.m6(), 2, 6, GB(t.m6(), 3, 5));
|
||||
SB(t.m3(), 5, 1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1933,7 +1933,7 @@ bool AfterLoadGame()
|
||||
|
||||
/* Replace "house construction year" with "house age" */
|
||||
if (IsTileType(t, MP_HOUSE) && IsHouseCompleted(t)) {
|
||||
_m[t].m5 = Clamp(_cur_year - (_m[t].m5 + ORIGINAL_BASE_YEAR), 0, 0xFF);
|
||||
t.m5() = Clamp(_cur_year - (t.m5() + ORIGINAL_BASE_YEAR), 0, 0xFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1947,10 +1947,10 @@ bool AfterLoadGame()
|
||||
case MP_RAILWAY:
|
||||
if (HasSignals(t)) {
|
||||
/* move the signal variant */
|
||||
SetSignalVariant(t, TRACK_UPPER, HasBit(_m[t].m2, 2) ? SIG_SEMAPHORE : SIG_ELECTRIC);
|
||||
SetSignalVariant(t, TRACK_LOWER, HasBit(_m[t].m2, 6) ? SIG_SEMAPHORE : SIG_ELECTRIC);
|
||||
ClrBit(_m[t].m2, 2);
|
||||
ClrBit(_m[t].m2, 6);
|
||||
SetSignalVariant(t, TRACK_UPPER, HasBit(t.m2(), 2) ? SIG_SEMAPHORE : SIG_ELECTRIC);
|
||||
SetSignalVariant(t, TRACK_LOWER, HasBit(t.m2(), 6) ? SIG_SEMAPHORE : SIG_ELECTRIC);
|
||||
ClrBit(t.m2(), 2);
|
||||
ClrBit(t.m2(), 6);
|
||||
}
|
||||
|
||||
/* Clear PBS reservation on track */
|
||||
@@ -2028,11 +2028,11 @@ bool AfterLoadGame()
|
||||
for (auto t : Map::Iterate()) {
|
||||
/* Check for HQ bit being set, instead of using map accessor,
|
||||
* since we've already changed it code-wise */
|
||||
if (IsTileType(t, MP_OBJECT) && HasBit(_m[t].m5, 7)) {
|
||||
if (IsTileType(t, MP_OBJECT) && HasBit(t.m5(), 7)) {
|
||||
/* Move size and part identification of HQ out of the m5 attribute,
|
||||
* on new locations */
|
||||
_m[t].m3 = GB(_m[t].m5, 0, 5);
|
||||
_m[t].m5 = OBJECT_HQ;
|
||||
t.m3() = GB(t.m5(), 0, 5);
|
||||
t.m5() = OBJECT_HQ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2041,13 +2041,13 @@ bool AfterLoadGame()
|
||||
if (!IsTileType(t, MP_OBJECT)) continue;
|
||||
|
||||
/* Reordering/generalisation of the object bits. */
|
||||
ObjectType type = _m[t].m5;
|
||||
SB(_me[t].m6, 2, 4, type == OBJECT_HQ ? GB(_m[t].m3, 2, 3) : 0);
|
||||
_m[t].m3 = type == OBJECT_HQ ? GB(_m[t].m3, 1, 1) | GB(_m[t].m3, 0, 1) << 4 : 0;
|
||||
ObjectType type = t.m5();
|
||||
SB(t.m6(), 2, 4, type == OBJECT_HQ ? GB(t.m3(), 2, 3) : 0);
|
||||
t.m3() = type == OBJECT_HQ ? GB(t.m3(), 1, 1) | GB(t.m3(), 0, 1) << 4 : 0;
|
||||
|
||||
/* Make sure those bits are clear as well! */
|
||||
_m[t].m4 = 0;
|
||||
_me[t].m7 = 0;
|
||||
t.m4() = 0;
|
||||
t.m7() = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2060,15 +2060,15 @@ bool AfterLoadGame()
|
||||
/* No towns, so remove all objects! */
|
||||
DoClearSquare(t);
|
||||
} else {
|
||||
uint offset = _m[t].m3;
|
||||
uint offset = t.m3();
|
||||
|
||||
/* Also move the animation state. */
|
||||
_m[t].m3 = GB(_me[t].m6, 2, 4);
|
||||
SB(_me[t].m6, 2, 4, 0);
|
||||
t.m3() = GB(t.m6(), 2, 4);
|
||||
SB(t.m6(), 2, 4, 0);
|
||||
|
||||
if (offset == 0) {
|
||||
/* No offset, so make the object. */
|
||||
ObjectType type = _m[t].m5;
|
||||
ObjectType type = t.m5();
|
||||
int size = type == OBJECT_HQ ? 2 : 1;
|
||||
|
||||
if (!Object::CanAllocateItem()) {
|
||||
@@ -2078,18 +2078,18 @@ bool AfterLoadGame()
|
||||
}
|
||||
|
||||
Object *o = new Object();
|
||||
o->location.tile = t;
|
||||
o->location.tile = (TileIndex)t;
|
||||
o->location.w = size;
|
||||
o->location.h = size;
|
||||
o->build_date = _date;
|
||||
o->town = type == OBJECT_STATUE ? Town::Get(_m[t].m2) : CalcClosestTownFromTile(t, UINT_MAX);
|
||||
_m[t].m2 = o->index;
|
||||
o->town = type == OBJECT_STATUE ? Town::Get(t.m2()) : CalcClosestTownFromTile(t, UINT_MAX);
|
||||
t.m2() = o->index;
|
||||
Object::IncTypeCount(type);
|
||||
} else {
|
||||
/* We're at an offset, so get the ID from our "root". */
|
||||
TileIndex northern_tile = t - TileXY(GB(offset, 0, 4), GB(offset, 4, 4));
|
||||
Tile northern_tile = t - TileXY(GB(offset, 0, 4), GB(offset, 4, 4));
|
||||
assert(IsTileType(northern_tile, MP_OBJECT));
|
||||
_m[t].m2 = _m[northern_tile].m2;
|
||||
t.m2() = northern_tile.m2();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2294,16 +2294,17 @@ bool AfterLoadGame()
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_128)) {
|
||||
for (const Depot *d : Depot::Iterate()) {
|
||||
Tile tile = d->xy;
|
||||
/* At some point, invalid depots were saved into the game (possibly those removed in the past?)
|
||||
* Remove them here, so they don't cause issues further down the line */
|
||||
if (!IsDepotTile(d->xy)) {
|
||||
if (!IsDepotTile(tile)) {
|
||||
Debug(sl, 0, "Removing invalid depot {} at {}, {}", d->index, TileX(d->xy), TileY(d->xy));
|
||||
delete d;
|
||||
d = nullptr;
|
||||
continue;
|
||||
}
|
||||
_m[d->xy].m2 = d->index;
|
||||
if (IsTileType(d->xy, MP_WATER)) _m[GetOtherShipDepotTile(d->xy)].m2 = d->index;
|
||||
tile.m2() = d->index;
|
||||
if (IsTileType(tile, MP_WATER)) Tile(GetOtherShipDepotTile(tile)).m2() = d->index;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2324,15 +2325,15 @@ bool AfterLoadGame()
|
||||
if (IsTileType(t, MP_CLEAR)) {
|
||||
if (GetRawClearGround(t) == CLEAR_SNOW) {
|
||||
SetClearGroundDensity(t, CLEAR_GRASS, GetClearDensity(t));
|
||||
SetBit(_m[t].m3, 4);
|
||||
SetBit(t.m3(), 4);
|
||||
} else {
|
||||
ClrBit(_m[t].m3, 4);
|
||||
ClrBit(t.m3(), 4);
|
||||
}
|
||||
}
|
||||
if (IsTileType(t, MP_TREES)) {
|
||||
uint density = GB(_m[t].m2, 6, 2);
|
||||
uint ground = GB(_m[t].m2, 4, 2);
|
||||
_m[t].m2 = ground << 6 | density << 4;
|
||||
uint density = GB(t.m2(), 6, 2);
|
||||
uint ground = GB(t.m2(), 4, 2);
|
||||
t.m2() = ground << 6 | density << 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2440,23 +2441,23 @@ bool AfterLoadGame()
|
||||
switch (GetTileType(t)) {
|
||||
case MP_HOUSE:
|
||||
if (GetHouseType(t) >= NEW_HOUSE_OFFSET) {
|
||||
uint per_proc = _me[t].m7;
|
||||
_me[t].m7 = GB(_me[t].m6, 2, 6) | (GB(_m[t].m3, 5, 1) << 6);
|
||||
SB(_m[t].m3, 5, 1, 0);
|
||||
SB(_me[t].m6, 2, 6, std::min(per_proc, 63U));
|
||||
uint per_proc = t.m7();
|
||||
t.m7() = GB(t.m6(), 2, 6) | (GB(t.m3(), 5, 1) << 6);
|
||||
SB(t.m3(), 5, 1, 0);
|
||||
SB(t.m6(), 2, 6, std::min(per_proc, 63U));
|
||||
}
|
||||
break;
|
||||
|
||||
case MP_INDUSTRY: {
|
||||
uint rand = _me[t].m7;
|
||||
_me[t].m7 = _m[t].m3;
|
||||
_m[t].m3 = rand;
|
||||
uint rand = t.m7();
|
||||
t.m7() = t.m3();
|
||||
t.m3() = rand;
|
||||
break;
|
||||
}
|
||||
|
||||
case MP_OBJECT:
|
||||
_me[t].m7 = _m[t].m3;
|
||||
_m[t].m3 = 0;
|
||||
t.m7() = t.m3();
|
||||
t.m3() = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -2771,16 +2772,16 @@ bool AfterLoadGame()
|
||||
for (auto t : Map::Iterate()) {
|
||||
if (!IsTileType(t, MP_CLEAR) && !IsTileType(t, MP_TREES)) continue;
|
||||
if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_FIELDS)) continue;
|
||||
uint fence = GB(_m[t].m4, 5, 3);
|
||||
uint fence = GB(t.m4(), 5, 3);
|
||||
if (fence != 0 && IsTileType(TILE_ADDXY(t, 1, 0), MP_CLEAR) && IsClearGround(TILE_ADDXY(t, 1, 0), CLEAR_FIELDS)) {
|
||||
SetFence(TILE_ADDXY(t, 1, 0), DIAGDIR_NE, fence);
|
||||
}
|
||||
fence = GB(_m[t].m4, 2, 3);
|
||||
fence = GB(t.m4(), 2, 3);
|
||||
if (fence != 0 && IsTileType(TILE_ADDXY(t, 0, 1), MP_CLEAR) && IsClearGround(TILE_ADDXY(t, 0, 1), CLEAR_FIELDS)) {
|
||||
SetFence(TILE_ADDXY(t, 0, 1), DIAGDIR_NW, fence);
|
||||
}
|
||||
SB(_m[t].m4, 2, 3, 0);
|
||||
SB(_m[t].m4, 5, 3, 0);
|
||||
SB(t.m4(), 2, 3, 0);
|
||||
SB(t.m4(), 5, 3, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2880,9 +2881,9 @@ bool AfterLoadGame()
|
||||
/* Move ObjectType from map to pool */
|
||||
for (auto t : Map::Iterate()) {
|
||||
if (IsTileType(t, MP_OBJECT)) {
|
||||
Object *o = Object::Get(_m[t].m2);
|
||||
o->type = _m[t].m5;
|
||||
_m[t].m5 = 0; // zero upper bits of (now bigger) ObjectID
|
||||
Object *o = Object::Get(t.m2());
|
||||
o->type = t.m5();
|
||||
t.m5() = 0; // zero upper bits of (now bigger) ObjectID
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3191,7 +3192,7 @@ bool AfterLoadGame()
|
||||
/* Reset unused tree counters to reduce the savegame size. */
|
||||
for (auto t : Map::Iterate()) {
|
||||
if (IsTileType(t, MP_TREES)) {
|
||||
SB(_m[t].m2, 0, 4, 0);
|
||||
SB(t.m2(), 0, 4, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ struct MAPTChunkHandler : ChunkHandler {
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].type = buf[j];
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).type() = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ struct MAPTChunkHandler : ChunkHandler {
|
||||
|
||||
SlSetLength(size);
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].type;
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).type();
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ struct MAPHChunkHandler : ChunkHandler {
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].height = buf[j];
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).height() = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ struct MAPHChunkHandler : ChunkHandler {
|
||||
|
||||
SlSetLength(size);
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].height;
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).height();
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
}
|
||||
}
|
||||
@@ -131,7 +131,7 @@ struct MAPOChunkHandler : ChunkHandler {
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m1 = buf[j];
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).m1() = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ struct MAPOChunkHandler : ChunkHandler {
|
||||
|
||||
SlSetLength(size);
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m1;
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).m1();
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
}
|
||||
}
|
||||
@@ -161,7 +161,7 @@ struct MAP2ChunkHandler : ChunkHandler {
|
||||
/* In those versions the m2 was 8 bits */
|
||||
IsSavegameVersionBefore(SLV_5) ? SLE_FILE_U8 | SLE_VAR_U16 : SLE_UINT16
|
||||
);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m2 = buf[j];
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).m2() = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ struct MAP2ChunkHandler : ChunkHandler {
|
||||
|
||||
SlSetLength(size * sizeof(uint16));
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m2;
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).m2();
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16);
|
||||
}
|
||||
}
|
||||
@@ -188,7 +188,7 @@ struct M3LOChunkHandler : ChunkHandler {
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m3 = buf[j];
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).m3() = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ struct M3LOChunkHandler : ChunkHandler {
|
||||
|
||||
SlSetLength(size);
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m3;
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).m3();
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
}
|
||||
}
|
||||
@@ -215,7 +215,7 @@ struct M3HIChunkHandler : ChunkHandler {
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m4 = buf[j];
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).m4() = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ struct M3HIChunkHandler : ChunkHandler {
|
||||
|
||||
SlSetLength(size);
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m4;
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).m4();
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
}
|
||||
}
|
||||
@@ -242,7 +242,7 @@ struct MAP5ChunkHandler : ChunkHandler {
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m5 = buf[j];
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).m5() = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ struct MAP5ChunkHandler : ChunkHandler {
|
||||
|
||||
SlSetLength(size);
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m5;
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).m5();
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
}
|
||||
}
|
||||
@@ -272,16 +272,16 @@ struct MAPEChunkHandler : ChunkHandler {
|
||||
/* 1024, otherwise we overflow on 64x64 maps! */
|
||||
SlCopy(buf.data(), 1024, SLE_UINT8);
|
||||
for (uint j = 0; j != 1024; j++) {
|
||||
_me[i++].m6 = GB(buf[j], 0, 2);
|
||||
_me[i++].m6 = GB(buf[j], 2, 2);
|
||||
_me[i++].m6 = GB(buf[j], 4, 2);
|
||||
_me[i++].m6 = GB(buf[j], 6, 2);
|
||||
Tile(i++).m6() = GB(buf[j], 0, 2);
|
||||
Tile(i++).m6() = GB(buf[j], 2, 2);
|
||||
Tile(i++).m6() = GB(buf[j], 4, 2);
|
||||
Tile(i++).m6() = GB(buf[j], 6, 2);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _me[i++].m6 = buf[j];
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).m6() = buf[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -293,7 +293,7 @@ struct MAPEChunkHandler : ChunkHandler {
|
||||
|
||||
SlSetLength(size);
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _me[i++].m6;
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).m6();
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
}
|
||||
}
|
||||
@@ -309,7 +309,7 @@ struct MAP7ChunkHandler : ChunkHandler {
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _me[i++].m7 = buf[j];
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).m7() = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ struct MAP7ChunkHandler : ChunkHandler {
|
||||
|
||||
SlSetLength(size);
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _me[i++].m7;
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).m7();
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
}
|
||||
}
|
||||
@@ -336,7 +336,7 @@ struct MAP8ChunkHandler : ChunkHandler {
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _me[i++].m8 = buf[j];
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) Tile(i++).m8() = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,7 +347,7 @@ struct MAP8ChunkHandler : ChunkHandler {
|
||||
|
||||
SlSetLength(size * sizeof(uint16));
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _me[i++].m8;
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = Tile(i++).m8();
|
||||
SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,46 +54,48 @@ static void FixTTDMapArray()
|
||||
{
|
||||
/* _old_map3 is moved to _m::m3 and _m::m4 */
|
||||
for (TileIndex t = 0; t < OLD_MAP_SIZE; t++) {
|
||||
_m[t].m3 = _old_map3[t * 2];
|
||||
_m[t].m4 = _old_map3[t * 2 + 1];
|
||||
Tile tile(t);
|
||||
tile.m3() = _old_map3[t * 2];
|
||||
tile.m4() = _old_map3[t * 2 + 1];
|
||||
}
|
||||
|
||||
for (TileIndex t = 0; t < OLD_MAP_SIZE; t++) {
|
||||
switch (GetTileType(t)) {
|
||||
Tile tile(t);
|
||||
switch (GetTileType(tile)) {
|
||||
case MP_STATION:
|
||||
_m[t].m4 = 0; // We do not understand this TTDP station mapping (yet)
|
||||
switch (_m[t].m5) {
|
||||
tile.m4() = 0; // We do not understand this TTDP station mapping (yet)
|
||||
switch (tile.m5()) {
|
||||
/* We have drive through stops at a totally different place */
|
||||
case 0x53: case 0x54: _m[t].m5 += 170 - 0x53; break; // Bus drive through
|
||||
case 0x57: case 0x58: _m[t].m5 += 168 - 0x57; break; // Truck drive through
|
||||
case 0x55: case 0x56: _m[t].m5 += 170 - 0x55; break; // Bus tram stop
|
||||
case 0x59: case 0x5A: _m[t].m5 += 168 - 0x59; break; // Truck tram stop
|
||||
case 0x53: case 0x54: tile.m5() += 170 - 0x53; break; // Bus drive through
|
||||
case 0x57: case 0x58: tile.m5() += 168 - 0x57; break; // Truck drive through
|
||||
case 0x55: case 0x56: tile.m5() += 170 - 0x55; break; // Bus tram stop
|
||||
case 0x59: case 0x5A: tile.m5() += 168 - 0x59; break; // Truck tram stop
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
|
||||
case MP_RAILWAY:
|
||||
/* We save presignals different from TTDPatch, convert them */
|
||||
if (GB(_m[t].m5, 6, 2) == 1) { // RAIL_TILE_SIGNALS
|
||||
if (GB(tile.m5(), 6, 2) == 1) { // RAIL_TILE_SIGNALS
|
||||
/* This byte is always zero in TTD for this type of tile */
|
||||
if (_m[t].m4) { // Convert the presignals to our own format
|
||||
_m[t].m4 = (_m[t].m4 >> 1) & 7;
|
||||
if (tile.m4()) { // Convert the presignals to our own format
|
||||
tile.m4() = (tile.m4() >> 1) & 7;
|
||||
}
|
||||
}
|
||||
/* TTDPatch stores PBS things in L6 and all elsewhere; so we'll just
|
||||
* clear it for ourselves and let OTTD's rebuild PBS itself */
|
||||
_m[t].m4 &= 0xF; // Only keep the lower four bits; upper four is PBS
|
||||
tile.m4() &= 0xF; // Only keep the lower four bits; upper four is PBS
|
||||
break;
|
||||
|
||||
case MP_WATER:
|
||||
/* if water class == 3, make river there */
|
||||
if (GB(_m[t].m3, 0, 2) == 3) {
|
||||
SetTileType(t, MP_WATER);
|
||||
SetTileOwner(t, OWNER_WATER);
|
||||
_m[t].m2 = 0;
|
||||
_m[t].m3 = 2; // WATER_CLASS_RIVER
|
||||
_m[t].m4 = Random();
|
||||
_m[t].m5 = 0;
|
||||
if (GB(tile.m3(), 0, 2) == 3) {
|
||||
SetTileType(tile, MP_WATER);
|
||||
SetTileOwner(tile, OWNER_WATER);
|
||||
tile.m2() = 0;
|
||||
tile.m3() = 2; // WATER_CLASS_RIVER
|
||||
tile.m4() = Random();
|
||||
tile.m5() = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -192,7 +194,8 @@ void FixOldVehicles()
|
||||
RoadVehicle *rv = RoadVehicle::From(v);
|
||||
if (rv->state != RVSB_IN_DEPOT && rv->state != RVSB_WORMHOLE) {
|
||||
ClrBit(rv->state, 2);
|
||||
if (IsTileType(rv->tile, MP_STATION) && _m[rv->tile].m5 >= 168) {
|
||||
Tile tile(rv->tile);
|
||||
if (IsTileType(tile, MP_STATION) && tile.m5() >= 168) {
|
||||
/* Update the vehicle's road state to show we're in a drive through road stop. */
|
||||
SetBit(rv->state, RVS_IN_DT_ROAD_STOP);
|
||||
}
|
||||
@@ -218,13 +221,14 @@ void FixOldVehicles()
|
||||
static bool FixTTOMapArray()
|
||||
{
|
||||
for (TileIndex t = 0; t < OLD_MAP_SIZE; t++) {
|
||||
TileType tt = GetTileType(t);
|
||||
Tile tile(t);
|
||||
TileType tt = GetTileType(tile);
|
||||
if (tt == 11) {
|
||||
/* TTO has a different way of storing monorail.
|
||||
* Instead of using bits in m3 it uses a different tile type. */
|
||||
_m[t].m3 = 1; // rail type = monorail (in TTD)
|
||||
SetTileType(t, MP_RAILWAY);
|
||||
_m[t].m2 = 1; // set monorail ground to RAIL_GROUND_GRASS
|
||||
tile.m3() = 1; // rail type = monorail (in TTD)
|
||||
SetTileType(tile, MP_RAILWAY);
|
||||
tile.m2() = 1; // set monorail ground to RAIL_GROUND_GRASS
|
||||
tt = MP_RAILWAY;
|
||||
}
|
||||
|
||||
@@ -233,18 +237,18 @@ static bool FixTTOMapArray()
|
||||
break;
|
||||
|
||||
case MP_RAILWAY:
|
||||
switch (GB(_m[t].m5, 6, 2)) {
|
||||
switch (GB(tile.m5(), 6, 2)) {
|
||||
case 0: // RAIL_TILE_NORMAL
|
||||
break;
|
||||
case 1: // RAIL_TILE_SIGNALS
|
||||
_m[t].m4 = (~_m[t].m5 & 1) << 2; // signal variant (present only in OTTD)
|
||||
SB(_m[t].m2, 6, 2, GB(_m[t].m5, 3, 2)); // signal status
|
||||
_m[t].m3 |= 0xC0; // both signals are present
|
||||
_m[t].m5 = HasBit(_m[t].m5, 5) ? 2 : 1; // track direction (only X or Y)
|
||||
_m[t].m5 |= 0x40; // RAIL_TILE_SIGNALS
|
||||
tile.m4() = (~tile.m5() & 1) << 2; // signal variant (present only in OTTD)
|
||||
SB(tile.m2(), 6, 2, GB(tile.m5(), 3, 2)); // signal status
|
||||
tile.m3() |= 0xC0; // both signals are present
|
||||
tile.m5() = HasBit(tile.m5(), 5) ? 2 : 1; // track direction (only X or Y)
|
||||
tile.m5() |= 0x40; // RAIL_TILE_SIGNALS
|
||||
break;
|
||||
case 3: // RAIL_TILE_DEPOT
|
||||
_m[t].m2 = 0;
|
||||
tile.m2() = 0;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
@@ -252,12 +256,12 @@ static bool FixTTOMapArray()
|
||||
break;
|
||||
|
||||
case MP_ROAD: // road (depot) or level crossing
|
||||
switch (GB(_m[t].m5, 4, 4)) {
|
||||
switch (GB(tile.m5(), 4, 4)) {
|
||||
case 0: // ROAD_TILE_NORMAL
|
||||
if (_m[t].m2 == 4) _m[t].m2 = 5; // 'small trees' -> ROADSIDE_TREES
|
||||
if (tile.m2() == 4) tile.m2() = 5; // 'small trees' -> ROADSIDE_TREES
|
||||
break;
|
||||
case 1: // ROAD_TILE_CROSSING (there aren't monorail crossings in TTO)
|
||||
_m[t].m3 = _m[t].m1; // set owner of road = owner of rail
|
||||
tile.m3() = tile.m1(); // set owner of road = owner of rail
|
||||
break;
|
||||
case 2: // ROAD_TILE_DEPOT
|
||||
break;
|
||||
@@ -267,69 +271,69 @@ static bool FixTTOMapArray()
|
||||
break;
|
||||
|
||||
case MP_HOUSE:
|
||||
_m[t].m3 = _m[t].m2 & 0xC0; // construction stage
|
||||
_m[t].m2 &= 0x3F; // building type
|
||||
if (_m[t].m2 >= 5) _m[t].m2++; // skip "large office block on snow"
|
||||
tile.m3() = tile.m2() & 0xC0; // construction stage
|
||||
tile.m2() &= 0x3F; // building type
|
||||
if (tile.m2() >= 5) tile.m2()++; // skip "large office block on snow"
|
||||
break;
|
||||
|
||||
case MP_TREES:
|
||||
_m[t].m3 = GB(_m[t].m5, 3, 3); // type of trees
|
||||
_m[t].m5 &= 0xC7; // number of trees and growth status
|
||||
tile.m3() = GB(tile.m5(), 3, 3); // type of trees
|
||||
tile.m5() &= 0xC7; // number of trees and growth status
|
||||
break;
|
||||
|
||||
case MP_STATION:
|
||||
_m[t].m3 = (_m[t].m5 >= 0x08 && _m[t].m5 <= 0x0F) ? 1 : 0; // monorail -> 1, others 0 (rail, road, airport, dock)
|
||||
if (_m[t].m5 >= 8) _m[t].m5 -= 8; // shift for monorail
|
||||
if (_m[t].m5 >= 0x42) _m[t].m5++; // skip heliport
|
||||
tile.m3() = (tile.m5() >= 0x08 && tile.m5() <= 0x0F) ? 1 : 0; // monorail -> 1, others 0 (rail, road, airport, dock)
|
||||
if (tile.m5() >= 8) tile.m5() -= 8; // shift for monorail
|
||||
if (tile.m5() >= 0x42) tile.m5()++; // skip heliport
|
||||
break;
|
||||
|
||||
case MP_WATER:
|
||||
_m[t].m3 = _m[t].m2 = 0;
|
||||
tile.m3() = tile.m2() = 0;
|
||||
break;
|
||||
|
||||
case MP_VOID:
|
||||
_m[t].m2 = _m[t].m3 = _m[t].m5 = 0;
|
||||
tile.m2() = tile.m3() = tile.m5() = 0;
|
||||
break;
|
||||
|
||||
case MP_INDUSTRY:
|
||||
_m[t].m3 = 0;
|
||||
switch (_m[t].m5) {
|
||||
tile.m3() = 0;
|
||||
switch (tile.m5()) {
|
||||
case 0x24: // farm silo
|
||||
_m[t].m5 = 0x25;
|
||||
tile.m5() = 0x25;
|
||||
break;
|
||||
case 0x25: case 0x27: // farm
|
||||
case 0x28: case 0x29: case 0x2A: case 0x2B: // factory
|
||||
_m[t].m5--;
|
||||
tile.m5()--;
|
||||
break;
|
||||
default:
|
||||
if (_m[t].m5 >= 0x2C) _m[t].m5 += 3; // iron ore mine, steel mill or bank
|
||||
if (tile.m5() >= 0x2C) tile.m5() += 3; // iron ore mine, steel mill or bank
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case MP_TUNNELBRIDGE:
|
||||
if (HasBit(_m[t].m5, 7)) { // bridge
|
||||
byte m5 = _m[t].m5;
|
||||
_m[t].m5 = m5 & 0xE1; // copy bits 7..5, 1
|
||||
if (GB(m5, 1, 2) == 1) _m[t].m5 |= 0x02; // road bridge
|
||||
if (GB(m5, 1, 2) == 3) _m[t].m2 |= 0xA0; // monorail bridge -> tubular, steel bridge
|
||||
if (HasBit(tile.m5(), 7)) { // bridge
|
||||
byte m5 = tile.m5();
|
||||
tile.m5() = m5 & 0xE1; // copy bits 7..5, 1
|
||||
if (GB(m5, 1, 2) == 1) tile.m5() |= 0x02; // road bridge
|
||||
if (GB(m5, 1, 2) == 3) tile.m2() |= 0xA0; // monorail bridge -> tubular, steel bridge
|
||||
if (!HasBit(m5, 6)) { // bridge head
|
||||
_m[t].m3 = (GB(m5, 1, 2) == 3) ? 1 : 0; // track subtype (1 for monorail, 0 for others)
|
||||
tile.m3() = (GB(m5, 1, 2) == 3) ? 1 : 0; // track subtype (1 for monorail, 0 for others)
|
||||
} else { // middle bridge part
|
||||
_m[t].m3 = HasBit(m5, 2) ? 0x10 : 0; // track subtype on bridge
|
||||
if (GB(m5, 3, 2) == 3) _m[t].m3 |= 1; // track subtype under bridge
|
||||
if (GB(m5, 3, 2) == 1) _m[t].m5 |= 0x08; // set for road/water under (0 for rail/clear)
|
||||
tile.m3() = HasBit(m5, 2) ? 0x10 : 0; // track subtype on bridge
|
||||
if (GB(m5, 3, 2) == 3) tile.m3() |= 1; // track subtype under bridge
|
||||
if (GB(m5, 3, 2) == 1) tile.m5() |= 0x08; // set for road/water under (0 for rail/clear)
|
||||
}
|
||||
} else { // tunnel entrance/exit
|
||||
_m[t].m2 = 0;
|
||||
_m[t].m3 = HasBit(_m[t].m5, 3); // monorail
|
||||
_m[t].m5 &= HasBit(_m[t].m5, 3) ? 0x03 : 0x07 ; // direction, transport type (== 0 for rail)
|
||||
tile.m2() = 0;
|
||||
tile.m3() = HasBit(tile.m5(), 3); // monorail
|
||||
tile.m5() &= HasBit(tile.m5(), 3) ? 0x03 : 0x07 ; // direction, transport type (== 0 for rail)
|
||||
}
|
||||
break;
|
||||
|
||||
case MP_OBJECT:
|
||||
_m[t].m2 = 0;
|
||||
_m[t].m3 = 0;
|
||||
tile.m2() = 0;
|
||||
tile.m3() = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -1471,10 +1475,10 @@ static bool LoadOldMapPart1(LoadgameState *ls, int num)
|
||||
}
|
||||
|
||||
for (uint i = 0; i < OLD_MAP_SIZE; i++) {
|
||||
_m[i].m1 = ReadByte(ls);
|
||||
Tile(i).m1() = ReadByte(ls);
|
||||
}
|
||||
for (uint i = 0; i < OLD_MAP_SIZE; i++) {
|
||||
_m[i].m2 = ReadByte(ls);
|
||||
Tile(i).m2() = ReadByte(ls);
|
||||
}
|
||||
|
||||
if (_savegame_type != SGT_TTO) {
|
||||
@@ -1484,10 +1488,10 @@ static bool LoadOldMapPart1(LoadgameState *ls, int num)
|
||||
}
|
||||
for (uint i = 0; i < OLD_MAP_SIZE / 4; i++) {
|
||||
byte b = ReadByte(ls);
|
||||
_me[i * 4 + 0].m6 = GB(b, 0, 2);
|
||||
_me[i * 4 + 1].m6 = GB(b, 2, 2);
|
||||
_me[i * 4 + 2].m6 = GB(b, 4, 2);
|
||||
_me[i * 4 + 3].m6 = GB(b, 6, 2);
|
||||
Tile(i * 4 + 0).m6() = GB(b, 0, 2);
|
||||
Tile(i * 4 + 1).m6() = GB(b, 2, 2);
|
||||
Tile(i * 4 + 2).m6() = GB(b, 4, 2);
|
||||
Tile(i * 4 + 3).m6() = GB(b, 6, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1499,10 +1503,10 @@ static bool LoadOldMapPart2(LoadgameState *ls, int num)
|
||||
uint i;
|
||||
|
||||
for (i = 0; i < OLD_MAP_SIZE; i++) {
|
||||
_m[i].type = ReadByte(ls);
|
||||
Tile(i).type() = ReadByte(ls);
|
||||
}
|
||||
for (i = 0; i < OLD_MAP_SIZE; i++) {
|
||||
_m[i].m5 = ReadByte(ls);
|
||||
Tile(i).m5() = ReadByte(ls);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -91,9 +91,10 @@ void MoveBuoysToWaypoints()
|
||||
if (train) {
|
||||
/* When we make a rail waypoint of the station, convert the map as well. */
|
||||
for (TileIndex t : train_st) {
|
||||
if (!IsTileType(t, MP_STATION) || GetStationIndex(t) != index) continue;
|
||||
Tile tile(t);
|
||||
if (!IsTileType(tile, MP_STATION) || GetStationIndex(tile) != index) continue;
|
||||
|
||||
SB(_me[t].m6, 3, 3, STATION_WAYPOINT);
|
||||
SB(tile.m6(), 3, 3, STATION_WAYPOINT);
|
||||
wp->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,10 +74,11 @@ void MoveWaypointsToBaseStations()
|
||||
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;
|
||||
Tile tile = wp.xy;
|
||||
tile.m2() = (StationID)wp.index;
|
||||
|
||||
if (HasBit(_m[wp.xy].m3, 4)) {
|
||||
wp.spec = StationClass::Get(STAT_CLASS_WAYP)->GetSpec(_m[wp.xy].m4 + 1);
|
||||
if (HasBit(tile.m3(), 4)) {
|
||||
wp.spec = StationClass::Get(STAT_CLASS_WAYP)->GetSpec(tile.m4() + 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -102,10 +103,10 @@ void MoveWaypointsToBaseStations()
|
||||
TileIndex t = wp.xy;
|
||||
/* Sometimes waypoint (sign) locations became disconnected from their actual location in
|
||||
* the map array. If this is the case, try to locate the actual location in the map array */
|
||||
if (!IsTileType(t, MP_RAILWAY) || GetRailTileType(t) != 2 /* RAIL_TILE_WAYPOINT */ || _m[t].m2 != wp.index) {
|
||||
if (!IsTileType(t, MP_RAILWAY) || GetRailTileType(t) != 2 /* RAIL_TILE_WAYPOINT */ || Tile(t).m2() != wp.index) {
|
||||
Debug(sl, 0, "Found waypoint tile {} with invalid position", t);
|
||||
for (t = 0; t < Map::Size(); t++) {
|
||||
if (IsTileType(t, MP_RAILWAY) && GetRailTileType(t) == 2 /* RAIL_TILE_WAYPOINT */ && _m[t].m2 == wp.index) {
|
||||
if (IsTileType(t, MP_RAILWAY) && GetRailTileType(t) == 2 /* RAIL_TILE_WAYPOINT */ && Tile(t).m2() == wp.index) {
|
||||
Debug(sl, 0, "Found actual waypoint position at {}", t);
|
||||
break;
|
||||
}
|
||||
@@ -125,19 +126,20 @@ void MoveWaypointsToBaseStations()
|
||||
new_wp->string_id = STR_SV_STNAME_WAYPOINT;
|
||||
|
||||
/* The tile might've been reserved! */
|
||||
bool reserved = !IsSavegameVersionBefore(SLV_100) && HasBit(_m[t].m5, 4);
|
||||
Tile tile(t);
|
||||
bool reserved = !IsSavegameVersionBefore(SLV_100) && HasBit(tile.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));
|
||||
MakeRailWaypoint(tile, GetTileOwner(tile), new_wp->index, (Axis)GB(tile.m5(), 0, 1), 0, GetRailType(tile));
|
||||
new_wp->facilities |= FACIL_TRAIN;
|
||||
new_wp->owner = GetTileOwner(t);
|
||||
new_wp->owner = GetTileOwner(tile);
|
||||
|
||||
SetRailStationReservation(t, reserved);
|
||||
SetRailStationReservation(tile, reserved);
|
||||
|
||||
if (wp.spec != nullptr) {
|
||||
SetCustomStationSpecIndex(t, AllocateSpecToStation(wp.spec, new_wp, true));
|
||||
SetCustomStationSpecIndex(tile, AllocateSpecToStation(wp.spec, new_wp, true));
|
||||
}
|
||||
new_wp->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
|
||||
new_wp->rect.BeforeAddTile(tile, StationRect::ADD_FORCE);
|
||||
|
||||
wp.new_index = new_wp->index;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user