mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r3981) More work for the rail accessing functions and enums
This commit is contained in:
parent
52e5d9f328
commit
4b74fa1923
|
@ -2182,7 +2182,7 @@ static bool AiRemoveTileAndGoForward(Player *p)
|
|||
|
||||
// Then remove and signals if there are any.
|
||||
if (IsTileType(tile, MP_RAILWAY) &&
|
||||
(_m[tile].m5&0xC0) == 0x40) {
|
||||
GetRailTileType(tile) == RAIL_TYPE_SIGNALS) {
|
||||
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_REMOVE_SIGNALS);
|
||||
}
|
||||
|
||||
|
@ -3567,21 +3567,20 @@ static void AiStateRemoveStation(Player *p)
|
|||
|
||||
static void AiRemovePlayerRailOrRoad(Player *p, TileIndex tile)
|
||||
{
|
||||
byte m5;
|
||||
TrackBits rails;
|
||||
|
||||
if (IsTileType(tile, MP_RAILWAY)) {
|
||||
if (!IsTileOwner(tile, _current_player)) return;
|
||||
|
||||
m5 = _m[tile].m5;
|
||||
if ((m5 & 0xFC) != 0xC0) {
|
||||
if (IsPlainRailTile(tile)) {
|
||||
is_rail_crossing:;
|
||||
m5 = GetRailTrackStatus(tile);
|
||||
rails = GetRailTrackStatus(tile);
|
||||
|
||||
if (m5 == 0xC || m5 == 0x30) return;
|
||||
if (rails == TRACK_BIT_HORZ || rails == TRACK_BIT_VERT) return;
|
||||
|
||||
if (m5 & 0x25) {
|
||||
if (rails & TRACK_BIT_3WAY_NE) {
|
||||
pos_0:
|
||||
if (!(GetRailTrackStatus(TILE_MASK(tile - TileDiffXY(1, 0))) & 0x19)) {
|
||||
if ((GetRailTrackStatus(TILE_MASK(tile - TileDiffXY(1, 0))) & TRACK_BIT_3WAY_SW) == 0) {
|
||||
p->ai.cur_dir_a = 0;
|
||||
p->ai.cur_tile_a = tile;
|
||||
p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
|
||||
|
@ -3589,9 +3588,9 @@ pos_0:
|
|||
}
|
||||
}
|
||||
|
||||
if (m5 & 0x2A) {
|
||||
if (rails & TRACK_BIT_3WAY_SE) {
|
||||
pos_1:
|
||||
if (!(GetRailTrackStatus(TILE_MASK(tile + TileDiffXY(0, 1))) & 0x16)) {
|
||||
if ((GetRailTrackStatus(TILE_MASK(tile + TileDiffXY(0, 1))) & TRACK_BIT_3WAY_NW) == 0) {
|
||||
p->ai.cur_dir_a = 1;
|
||||
p->ai.cur_tile_a = tile;
|
||||
p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
|
||||
|
@ -3599,9 +3598,9 @@ pos_1:
|
|||
}
|
||||
}
|
||||
|
||||
if (m5 & 0x19) {
|
||||
if (rails & TRACK_BIT_3WAY_SW) {
|
||||
pos_2:
|
||||
if (!(GetRailTrackStatus(TILE_MASK(tile + TileDiffXY(1, 0))) & 0x25)) {
|
||||
if ((GetRailTrackStatus(TILE_MASK(tile + TileDiffXY(1, 0))) & TRACK_BIT_3WAY_NE) == 0) {
|
||||
p->ai.cur_dir_a = 2;
|
||||
p->ai.cur_tile_a = tile;
|
||||
p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
|
||||
|
@ -3609,9 +3608,9 @@ pos_2:
|
|||
}
|
||||
}
|
||||
|
||||
if (m5 & 0x16) {
|
||||
if (rails & TRACK_BIT_3WAY_NW) {
|
||||
pos_3:
|
||||
if (!(GetRailTrackStatus(TILE_MASK(tile - TileDiffXY(0, 1))) & 0x2A)) {
|
||||
if ((GetRailTrackStatus(TILE_MASK(tile - TileDiffXY(0, 1))) & TRACK_BIT_3WAY_SE) == 0) {
|
||||
p->ai.cur_dir_a = 3;
|
||||
p->ai.cur_tile_a = tile;
|
||||
p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
|
||||
|
@ -3675,7 +3674,7 @@ pos_3:
|
|||
return;
|
||||
}
|
||||
|
||||
m5 = 0;
|
||||
rails = 0;
|
||||
|
||||
switch (GetBridgeRampDirection(tile)) {
|
||||
default:
|
||||
|
|
|
@ -582,8 +582,10 @@ static void DisasterTick_4(Vehicle *v)
|
|||
tile_org = tile = RandomTile();
|
||||
do {
|
||||
if (IsTileType(tile, MP_RAILWAY) &&
|
||||
(_m[tile].m5 & ~3) != 0xC0 && IS_HUMAN_PLAYER(GetTileOwner(tile)))
|
||||
IsPlainRailTile(tile) &&
|
||||
IS_HUMAN_PLAYER(GetTileOwner(tile))) {
|
||||
break;
|
||||
}
|
||||
tile = TILE_MASK(tile+1);
|
||||
} while (tile != tile_org);
|
||||
v->dest_tile = tile;
|
||||
|
|
|
@ -1562,7 +1562,7 @@ static bool LoadOldMain(LoadgameState *ls)
|
|||
for (i = 0; i < OLD_MAP_SIZE; i ++) {
|
||||
if (IsTileType(i, MP_RAILWAY)) {
|
||||
/* We save presignals different from TTDPatch, convert them */
|
||||
if (GB(_m[i].m5, 6, 2) == 1) {
|
||||
if (GetRailTileType(i) == RAIL_TYPE_SIGNALS) {
|
||||
/* This byte is always zero in TTD for this type of tile */
|
||||
if (_m[i].m4) /* Convert the presignals to our own format */
|
||||
_m[i].m4 = (_m[i].m4 >> 1) & 7;
|
||||
|
|
|
@ -197,7 +197,8 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
|||
switch (GetTileType(tile)) {
|
||||
case MP_RAILWAY:
|
||||
if (v->type == VEH_Train && IsTileOwner(tile, _local_player)) {
|
||||
if ((_m[tile].m5&0xFC)==0xC0) {
|
||||
if (GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT &&
|
||||
GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) {
|
||||
order.type = OT_GOTO_DEPOT;
|
||||
order.flags = OF_PART_OF_ORDERS;
|
||||
order.station = GetDepotByTile(tile)->index;
|
||||
|
|
21
rail_cmd.c
21
rail_cmd.c
|
@ -1084,15 +1084,10 @@ static int32 ClearTile_Track(TileIndex tile, byte flags)
|
|||
}
|
||||
|
||||
case RAIL_TYPE_DEPOT_WAYPOINT:
|
||||
switch (m5 & RAIL_SUBTYPE_MASK) {
|
||||
case RAIL_SUBTYPE_DEPOT:
|
||||
return RemoveTrainDepot(tile, flags);
|
||||
|
||||
case RAIL_SUBTYPE_WAYPOINT:
|
||||
return RemoveTrainWaypoint(tile, flags, false);
|
||||
|
||||
default:
|
||||
return CMD_ERROR;
|
||||
if (GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) {
|
||||
return RemoveTrainDepot(tile, flags);
|
||||
} else {
|
||||
return RemoveTrainWaypoint(tile, flags, false);
|
||||
}
|
||||
|
||||
default:
|
||||
|
@ -1995,10 +1990,10 @@ static uint32 GetTileTrackStatus_Track(TileIndex tile, TransportType mode)
|
|||
}
|
||||
return ret;
|
||||
} else {
|
||||
if (_m[tile].m5 & 0x40) {
|
||||
return GetRailWaypointBits(tile) * 0x101;
|
||||
} else {
|
||||
if (GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) {
|
||||
return 0;
|
||||
} else {
|
||||
return GetRailWaypointBits(tile) * 0x101;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2034,7 +2029,7 @@ static void GetTileDesc_Track(TileIndex tile, TileDesc *td)
|
|||
|
||||
case RAIL_TYPE_DEPOT_WAYPOINT:
|
||||
default:
|
||||
td->str = ((_m[tile].m5 & RAIL_SUBTYPE_MASK) == RAIL_SUBTYPE_DEPOT) ?
|
||||
td->str = (GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) ?
|
||||
STR_1023_RAILROAD_TRAIN_DEPOT : STR_LANDINFO_WAYPOINT;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -83,10 +83,8 @@ static void PlaceRail_AutoRail(TileIndex tile)
|
|||
|
||||
static void PlaceExtraDepotRail(TileIndex tile, uint16 extra)
|
||||
{
|
||||
byte b = _m[tile].m5;
|
||||
|
||||
if (GB(b, 6, 2) != RAIL_TYPE_NORMAL >> 6) return;
|
||||
if (!(b & (extra >> 8))) return;
|
||||
if (GetRailTileType(tile) != RAIL_TYPE_NORMAL) return;
|
||||
if ((GetTrackBits(tile) & GB(extra, 8, 8)) == 0) return;
|
||||
|
||||
DoCommandP(tile, _cur_railtype, extra & 0xFF, NULL, CMD_BUILD_SINGLE_RAIL | CMD_AUTO | CMD_NO_WATER);
|
||||
}
|
||||
|
|
21
road_cmd.c
21
road_cmd.c
|
@ -334,14 +334,19 @@ int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|||
}
|
||||
#undef M
|
||||
|
||||
if (ti.map5 == 2) {
|
||||
if (pieces & ROAD_Y) goto do_clear;
|
||||
roaddir = AXIS_X;
|
||||
} else if (ti.map5 == 1) {
|
||||
if (pieces & ROAD_X) goto do_clear;
|
||||
roaddir = AXIS_Y;
|
||||
} else {
|
||||
goto do_clear;
|
||||
if (GetRailTileType(tile) != RAIL_TYPE_NORMAL) goto do_clear;
|
||||
switch (GetTrackBits(tile)) {
|
||||
case TRACK_BIT_X:
|
||||
if (pieces & ROAD_X) goto do_clear;
|
||||
roaddir = AXIS_Y;
|
||||
break;
|
||||
|
||||
case TRACK_BIT_Y:
|
||||
if (pieces & ROAD_Y) goto do_clear;
|
||||
roaddir = AXIS_X;
|
||||
break;
|
||||
|
||||
default: goto do_clear;
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
|
|
15
train_cmd.c
15
train_cmd.c
|
@ -1746,12 +1746,13 @@ typedef struct TrainFindDepotData {
|
|||
|
||||
static bool NtpCallbFindDepot(TileIndex tile, TrainFindDepotData *tfdd, int track, uint length)
|
||||
{
|
||||
if (IsTileType(tile, MP_RAILWAY) && IsTileOwner(tile, tfdd->owner)) {
|
||||
if ((_m[tile].m5 & 0xFC) == 0xC0) {
|
||||
tfdd->best_length = length;
|
||||
tfdd->tile = tile;
|
||||
return true;
|
||||
}
|
||||
if (IsTileType(tile, MP_RAILWAY) &&
|
||||
IsTileOwner(tile, tfdd->owner) &&
|
||||
GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT &&
|
||||
GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) {
|
||||
tfdd->best_length = length;
|
||||
tfdd->tile = tile;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -2654,7 +2655,7 @@ static void TrainMovedChangeSignals(TileIndex tile, DiagDirection dir)
|
|||
{
|
||||
if (IsTileType(tile, MP_RAILWAY) &&
|
||||
GetRailTileType(tile) == RAIL_TYPE_SIGNALS) {
|
||||
uint i = FindFirstBit2x64((_m[tile].m5 + (_m[tile].m5 << 8)) & _reachable_tracks[dir]);
|
||||
uint i = FindFirstBit2x64(GetTrackBits(tile) * 0x101 & _reachable_tracks[dir]);
|
||||
UpdateSignalsOnSegment(tile, _otherside_signal_directions[i]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue