1
0
Fork 0

(svn r3981) More work for the rail accessing functions and enums

release/0.5
tron 2006-03-19 13:48:08 +00:00
parent 52e5d9f328
commit 4b74fa1923
8 changed files with 51 additions and 50 deletions

View File

@ -2182,7 +2182,7 @@ static bool AiRemoveTileAndGoForward(Player *p)
// Then remove and signals if there are any. // Then remove and signals if there are any.
if (IsTileType(tile, MP_RAILWAY) && if (IsTileType(tile, MP_RAILWAY) &&
(_m[tile].m5&0xC0) == 0x40) { GetRailTileType(tile) == RAIL_TYPE_SIGNALS) {
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_REMOVE_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) static void AiRemovePlayerRailOrRoad(Player *p, TileIndex tile)
{ {
byte m5; TrackBits rails;
if (IsTileType(tile, MP_RAILWAY)) { if (IsTileType(tile, MP_RAILWAY)) {
if (!IsTileOwner(tile, _current_player)) return; if (!IsTileOwner(tile, _current_player)) return;
m5 = _m[tile].m5; if (IsPlainRailTile(tile)) {
if ((m5 & 0xFC) != 0xC0) {
is_rail_crossing:; 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: 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_dir_a = 0;
p->ai.cur_tile_a = tile; p->ai.cur_tile_a = tile;
p->ai.state = AIS_REMOVE_SINGLE_RAIL_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: 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_dir_a = 1;
p->ai.cur_tile_a = tile; p->ai.cur_tile_a = tile;
p->ai.state = AIS_REMOVE_SINGLE_RAIL_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: 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_dir_a = 2;
p->ai.cur_tile_a = tile; p->ai.cur_tile_a = tile;
p->ai.state = AIS_REMOVE_SINGLE_RAIL_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: 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_dir_a = 3;
p->ai.cur_tile_a = tile; p->ai.cur_tile_a = tile;
p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE; p->ai.state = AIS_REMOVE_SINGLE_RAIL_TILE;
@ -3675,7 +3674,7 @@ pos_3:
return; return;
} }
m5 = 0; rails = 0;
switch (GetBridgeRampDirection(tile)) { switch (GetBridgeRampDirection(tile)) {
default: default:

View File

@ -582,8 +582,10 @@ static void DisasterTick_4(Vehicle *v)
tile_org = tile = RandomTile(); tile_org = tile = RandomTile();
do { do {
if (IsTileType(tile, MP_RAILWAY) && if (IsTileType(tile, MP_RAILWAY) &&
(_m[tile].m5 & ~3) != 0xC0 && IS_HUMAN_PLAYER(GetTileOwner(tile))) IsPlainRailTile(tile) &&
IS_HUMAN_PLAYER(GetTileOwner(tile))) {
break; break;
}
tile = TILE_MASK(tile+1); tile = TILE_MASK(tile+1);
} while (tile != tile_org); } while (tile != tile_org);
v->dest_tile = tile; v->dest_tile = tile;

View File

@ -1562,7 +1562,7 @@ static bool LoadOldMain(LoadgameState *ls)
for (i = 0; i < OLD_MAP_SIZE; i ++) { for (i = 0; i < OLD_MAP_SIZE; i ++) {
if (IsTileType(i, MP_RAILWAY)) { if (IsTileType(i, MP_RAILWAY)) {
/* We save presignals different from TTDPatch, convert them */ /* 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 */ /* This byte is always zero in TTD for this type of tile */
if (_m[i].m4) /* Convert the presignals to our own format */ if (_m[i].m4) /* Convert the presignals to our own format */
_m[i].m4 = (_m[i].m4 >> 1) & 7; _m[i].m4 = (_m[i].m4 >> 1) & 7;

View File

@ -197,7 +197,8 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
switch (GetTileType(tile)) { switch (GetTileType(tile)) {
case MP_RAILWAY: case MP_RAILWAY:
if (v->type == VEH_Train && IsTileOwner(tile, _local_player)) { 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.type = OT_GOTO_DEPOT;
order.flags = OF_PART_OF_ORDERS; order.flags = OF_PART_OF_ORDERS;
order.station = GetDepotByTile(tile)->index; order.station = GetDepotByTile(tile)->index;

View File

@ -1084,15 +1084,10 @@ static int32 ClearTile_Track(TileIndex tile, byte flags)
} }
case RAIL_TYPE_DEPOT_WAYPOINT: case RAIL_TYPE_DEPOT_WAYPOINT:
switch (m5 & RAIL_SUBTYPE_MASK) { if (GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) {
case RAIL_SUBTYPE_DEPOT:
return RemoveTrainDepot(tile, flags); return RemoveTrainDepot(tile, flags);
} else {
case RAIL_SUBTYPE_WAYPOINT:
return RemoveTrainWaypoint(tile, flags, false); return RemoveTrainWaypoint(tile, flags, false);
default:
return CMD_ERROR;
} }
default: default:
@ -1995,10 +1990,10 @@ static uint32 GetTileTrackStatus_Track(TileIndex tile, TransportType mode)
} }
return ret; return ret;
} else { } else {
if (_m[tile].m5 & 0x40) { if (GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) {
return GetRailWaypointBits(tile) * 0x101;
} else {
return 0; return 0;
} else {
return GetRailWaypointBits(tile) * 0x101;
} }
} }
} }
@ -2034,7 +2029,7 @@ static void GetTileDesc_Track(TileIndex tile, TileDesc *td)
case RAIL_TYPE_DEPOT_WAYPOINT: case RAIL_TYPE_DEPOT_WAYPOINT:
default: 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; STR_1023_RAILROAD_TRAIN_DEPOT : STR_LANDINFO_WAYPOINT;
break; break;
} }

View File

@ -83,10 +83,8 @@ static void PlaceRail_AutoRail(TileIndex tile)
static void PlaceExtraDepotRail(TileIndex tile, uint16 extra) static void PlaceExtraDepotRail(TileIndex tile, uint16 extra)
{ {
byte b = _m[tile].m5; if (GetRailTileType(tile) != RAIL_TYPE_NORMAL) return;
if ((GetTrackBits(tile) & GB(extra, 8, 8)) == 0) return;
if (GB(b, 6, 2) != RAIL_TYPE_NORMAL >> 6) return;
if (!(b & (extra >> 8))) return;
DoCommandP(tile, _cur_railtype, extra & 0xFF, NULL, CMD_BUILD_SINGLE_RAIL | CMD_AUTO | CMD_NO_WATER); DoCommandP(tile, _cur_railtype, extra & 0xFF, NULL, CMD_BUILD_SINGLE_RAIL | CMD_AUTO | CMD_NO_WATER);
} }

View File

@ -334,14 +334,19 @@ int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
} }
#undef M #undef M
if (ti.map5 == 2) { if (GetRailTileType(tile) != RAIL_TYPE_NORMAL) goto do_clear;
if (pieces & ROAD_Y) goto do_clear; switch (GetTrackBits(tile)) {
roaddir = AXIS_X; case TRACK_BIT_X:
} else if (ti.map5 == 1) {
if (pieces & ROAD_X) goto do_clear; if (pieces & ROAD_X) goto do_clear;
roaddir = AXIS_Y; roaddir = AXIS_Y;
} else { break;
goto do_clear;
case TRACK_BIT_Y:
if (pieces & ROAD_Y) goto do_clear;
roaddir = AXIS_X;
break;
default: goto do_clear;
} }
if (flags & DC_EXEC) { if (flags & DC_EXEC) {

View File

@ -1746,13 +1746,14 @@ typedef struct TrainFindDepotData {
static bool NtpCallbFindDepot(TileIndex tile, TrainFindDepotData *tfdd, int track, uint length) static bool NtpCallbFindDepot(TileIndex tile, TrainFindDepotData *tfdd, int track, uint length)
{ {
if (IsTileType(tile, MP_RAILWAY) && IsTileOwner(tile, tfdd->owner)) { if (IsTileType(tile, MP_RAILWAY) &&
if ((_m[tile].m5 & 0xFC) == 0xC0) { IsTileOwner(tile, tfdd->owner) &&
GetRailTileType(tile) == RAIL_TYPE_DEPOT_WAYPOINT &&
GetRailTileSubtype(tile) == RAIL_SUBTYPE_DEPOT) {
tfdd->best_length = length; tfdd->best_length = length;
tfdd->tile = tile; tfdd->tile = tile;
return true; return true;
} }
}
return false; return false;
} }
@ -2654,7 +2655,7 @@ static void TrainMovedChangeSignals(TileIndex tile, DiagDirection dir)
{ {
if (IsTileType(tile, MP_RAILWAY) && if (IsTileType(tile, MP_RAILWAY) &&
GetRailTileType(tile) == RAIL_TYPE_SIGNALS) { 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]); UpdateSignalsOnSegment(tile, _otherside_signal_directions[i]);
} }
} }