diff options
author | tron <tron@openttd.org> | 2006-03-19 13:48:08 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2006-03-19 13:48:08 +0000 |
commit | 4b74fa19230897c9e9b20e6bcba2b16c748cb09f (patch) | |
tree | 66c89a776909a6e784becbe687a7906a69356023 | |
parent | 52e5d9f328de74cc984077d49ea612961e5ce969 (diff) | |
download | openttd-4b74fa19230897c9e9b20e6bcba2b16c748cb09f.tar.xz |
(svn r3981) More work for the rail accessing functions and enums
-rw-r--r-- | ai/default/default.c | 29 | ||||
-rw-r--r-- | disaster_cmd.c | 4 | ||||
-rw-r--r-- | oldloader.c | 2 | ||||
-rw-r--r-- | order_gui.c | 3 | ||||
-rw-r--r-- | rail_cmd.c | 21 | ||||
-rw-r--r-- | rail_gui.c | 6 | ||||
-rw-r--r-- | road_cmd.c | 21 | ||||
-rw-r--r-- | train_cmd.c | 15 |
8 files changed, 51 insertions, 50 deletions
diff --git a/ai/default/default.c b/ai/default/default.c index 5d481b7e1..4ba475e06 100644 --- a/ai/default/default.c +++ b/ai/default/default.c @@ -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: diff --git a/disaster_cmd.c b/disaster_cmd.c index 06d856a87..d773abfb7 100644 --- a/disaster_cmd.c +++ b/disaster_cmd.c @@ -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; diff --git a/oldloader.c b/oldloader.c index 4489e44f1..c17c8077f 100644 --- a/oldloader.c +++ b/oldloader.c @@ -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; diff --git a/order_gui.c b/order_gui.c index cf65b2288..a83c7b70e 100644 --- a/order_gui.c +++ b/order_gui.c @@ -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; diff --git a/rail_cmd.c b/rail_cmd.c index 21c1e92f5..67dc936bc 100644 --- a/rail_cmd.c +++ b/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; } diff --git a/rail_gui.c b/rail_gui.c index d2fcb1920..f641a551e 100644 --- a/rail_gui.c +++ b/rail_gui.c @@ -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); } diff --git a/road_cmd.c b/road_cmd.c index a0c7066e3..79c3e213c 100644 --- a/road_cmd.c +++ b/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) { diff --git a/train_cmd.c b/train_cmd.c index 189947c99..13124d92b 100644 --- a/train_cmd.c +++ b/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]); } } |