1
0
Fork 0

(svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends

release/0.5
tron 2006-03-06 20:28:28 +00:00
parent fc1e9c5a92
commit 2d3c28f2b3
10 changed files with 83 additions and 71 deletions

View File

@ -3636,7 +3636,7 @@ pos_3:
if (IsLevelCrossing(tile)) goto is_rail_crossing; if (IsLevelCrossing(tile)) goto is_rail_crossing;
if (GetRoadType(tile) == ROAD_DEPOT) { if (GetRoadType(tile) == ROAD_DEPOT) {
uint dir; DiagDirection dir;
// Check if there are any stations around. // Check if there are any stations around.
if (IsTileType(tile + TileDiffXY(-1, 0), MP_STATION) && if (IsTileType(tile + TileDiffXY(-1, 0), MP_STATION) &&
@ -3664,7 +3664,7 @@ pos_3:
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
DoCommandByTile( DoCommandByTile(
TILE_MASK(tile + TileOffsByDir(dir)), TILE_MASK(tile + TileOffsByDir(dir)),
8 >> (dir ^ 2), DiagDirToRoadBits(ReverseDiagDir(dir)),
0, 0,
DC_EXEC, DC_EXEC,
CMD_REMOVE_ROAD); CMD_REMOVE_ROAD);

View File

@ -784,7 +784,7 @@ static void AiNew_State_FindDepot(Player *p)
// But first we walk through the route see if we can find a depot that is ours // But first we walk through the route see if we can find a depot that is ours
// this keeps things nice ;) // this keeps things nice ;)
int g, i, r; int g, i, r;
uint j; DiagDirection j;
TileIndex tile; TileIndex tile;
assert(p->ainew.state == AI_STATE_FIND_DEPOT); assert(p->ainew.state == AI_STATE_FIND_DEPOT);
@ -793,23 +793,19 @@ static void AiNew_State_FindDepot(Player *p)
for (i=2;i<p->ainew.path_info.route_length-2;i++) { for (i=2;i<p->ainew.path_info.route_length-2;i++) {
tile = p->ainew.path_info.route[i]; tile = p->ainew.path_info.route[i];
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++) {
if (IsTileType(tile + TileOffsByDir(j), MP_STREET)) { TileIndex t = tile + TileOffsByDir(j);
if (GetRoadType(tile + TileOffsByDir(j)) == ROAD_DEPOT) {
// We found a depot, is it ours? (TELL ME!!!) if (IsTileType(t, MP_STREET) &&
if (IsTileOwner(tile + TileOffsByDir(j), _current_player)) { GetRoadType(t) == ROAD_DEPOT &&
// Now, is it pointing to the right direction......... IsTileOwner(t, _current_player) &&
if (GB(_m[tile + TileOffsByDir(j)].m5, 0, 2) == (j ^ 2)) { GB(_m[t].m5, 0, 2) == ReverseDiagDir(j)) { // right direction?
// Yeah!!! p->ainew.depot_tile = t;
p->ainew.depot_tile = tile + TileOffsByDir(j); p->ainew.depot_direction = ReverseDiagDir(j);
p->ainew.depot_direction = j ^ 2; // Reverse direction
p->ainew.state = AI_STATE_VERIFY_ROUTE; p->ainew.state = AI_STATE_VERIFY_ROUTE;
return; return;
} }
} }
} }
}
}
}
// This routine let depot finding start in the middle, and work his way to the stations // This routine let depot finding start in the middle, and work his way to the stations
// It makes depot placing nicer :) // It makes depot placing nicer :)
@ -828,27 +824,29 @@ static void AiNew_State_FindDepot(Player *p)
tile = p->ainew.path_info.route[i]; tile = p->ainew.path_info.route[i];
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++) {
TileIndex t = tile + TileOffsByDir(j);
// It may not be placed on the road/rail itself // It may not be placed on the road/rail itself
// And because it is not build yet, we can't see it on the tile.. // And because it is not build yet, we can't see it on the tile..
// So check the surrounding tiles :) // So check the surrounding tiles :)
if (tile + TileOffsByDir(j) == p->ainew.path_info.route[i-1] || if (t == p->ainew.path_info.route[i - 1] ||
tile + TileOffsByDir(j) == p->ainew.path_info.route[i+1]) t == p->ainew.path_info.route[i + 1]) {
continue; continue;
}
// Not around a bridge? // Not around a bridge?
if (p->ainew.path_info.route_extra[i] != 0) continue; if (p->ainew.path_info.route_extra[i] != 0) continue;
if (IsTileType(tile, MP_TUNNELBRIDGE)) continue; if (IsTileType(tile, MP_TUNNELBRIDGE)) continue;
// Is the terrain clear? // Is the terrain clear?
if (IsTileType(tile + TileOffsByDir(j), MP_CLEAR) || if (IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)) {
IsTileType(tile + TileOffsByDir(j), MP_TREES)) {
// If the current tile is on a slope (tileh != 0) then we do not allow this // If the current tile is on a slope (tileh != 0) then we do not allow this
if (GetTileSlope(tile, NULL) != 0) continue; if (GetTileSlope(tile, NULL) != 0) continue;
// Check if everything went okay.. // Check if everything went okay..
r = AiNew_Build_Depot(p, tile + TileOffsByDir(j), j ^ 2, 0); r = AiNew_Build_Depot(p, t, ReverseDiagDir(j), 0);
if (CmdFailed(r)) continue; if (CmdFailed(r)) continue;
// Found a spot! // Found a spot!
p->ainew.new_cost += r; p->ainew.new_cost += r;
p->ainew.depot_tile = tile + TileOffsByDir(j); p->ainew.depot_tile = t;
p->ainew.depot_direction = j ^ 2; // Reverse direction p->ainew.depot_direction = ReverseDiagDir(j); // Reverse direction
p->ainew.state = AI_STATE_VERIFY_ROUTE; p->ainew.state = AI_STATE_VERIFY_ROUTE;
return; return;
} }

View File

@ -34,12 +34,18 @@ static inline DiagDirection ReverseDiagDir(DiagDirection d)
} }
static inline DiagDirection DirToDiagdir(Direction dir) static inline DiagDirection DirToDiagDir(Direction dir)
{ {
return (DiagDirection)(dir >> 1); return (DiagDirection)(dir >> 1);
} }
static inline Direction DiagDirToDir(DiagDirection dir)
{
return (Direction)(dir * 2 + 1);
}
/* the 2 axis */ /* the 2 axis */
typedef enum Axis { typedef enum Axis {
AXIS_X = 0, AXIS_X = 0,

View File

@ -127,7 +127,7 @@ static const byte _otherdir_mask[4] = {
0x2A, 0x2A,
}; };
static void TPFMode2(TrackPathFinder *tpf, TileIndex tile, int direction) static void TPFMode2(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
{ {
uint bits; uint bits;
int i; int i;
@ -275,7 +275,7 @@ const byte _ffb_64[128] = {
48,56,56,58,56,60,60,62, 48,56,56,58,56,60,60,62,
}; };
static void TPFMode1(TrackPathFinder *tpf, TileIndex tile, uint direction) static void TPFMode1(TrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
{ {
uint bits; uint bits;
int i; int i;
@ -343,7 +343,7 @@ static void TPFMode1(TrackPathFinder *tpf, TileIndex tile, uint direction)
return; return;
tile = tile_org; tile = tile_org;
direction ^= 2; direction = ReverseDiagDir(direction);
bits = GetTileTrackStatus(tile, tpf->tracktype); bits = GetTileTrackStatus(tile, tpf->tracktype);
bits |= (bits >> 8); bits |= (bits >> 8);
@ -370,7 +370,7 @@ static void TPFMode1(TrackPathFinder *tpf, TileIndex tile, uint direction)
} while (bits != 0); } while (bits != 0);
} }
void FollowTrack(TileIndex tile, uint16 flags, byte direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data) void FollowTrack(TileIndex tile, uint16 flags, DiagDirection direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data)
{ {
TrackPathFinder tpf; TrackPathFinder tpf;
@ -506,7 +506,7 @@ static inline void HeapifyDown(NewTrackPathFinder *tpf)
// mark a tile as visited and store the length of the path. // mark a tile as visited and store the length of the path.
// if we already had a better path to this tile, return false. // if we already had a better path to this tile, return false.
// otherwise return true. // otherwise return true.
static bool NtpVisit(NewTrackPathFinder *tpf, TileIndex tile, uint dir, uint length) static bool NtpVisit(NewTrackPathFinder* tpf, TileIndex tile, DiagDirection dir, uint length)
{ {
uint hash,head; uint hash,head;
HashLink *link, *new_link; HashLink *link, *new_link;
@ -671,7 +671,7 @@ static const byte _length_of_track[16] = {
// Tile is the tile the train is at. // Tile is the tile the train is at.
// direction is the tile the train is moving towards. // direction is the tile the train is moving towards.
static void NTPEnum(NewTrackPathFinder *tpf, TileIndex tile, uint direction) static void NTPEnum(NewTrackPathFinder* tpf, TileIndex tile, DiagDirection direction)
{ {
TrackBits bits, allbits; TrackBits bits, allbits;
uint track; uint track;
@ -912,7 +912,7 @@ start_at:
// new pathfinder for trains. better and faster. // new pathfinder for trains. better and faster.
void NewTrainPathfind(TileIndex tile, TileIndex dest, byte direction, NTPEnumProc *enum_proc, void *data) void NewTrainPathfind(TileIndex tile, TileIndex dest, DiagDirection direction, NTPEnumProc* enum_proc, void* data)
{ {
NewTrackPathFinder tpf; NewTrackPathFinder tpf;

View File

@ -3,6 +3,8 @@
#ifndef PATHFIND_H #ifndef PATHFIND_H
#define PATHFIND_H #define PATHFIND_H
#include "direction.h"
//#define PF_BENCH // perform simple benchmarks on the train pathfinder (not //#define PF_BENCH // perform simple benchmarks on the train pathfinder (not
//supported on all archs) //supported on all archs)
@ -58,7 +60,7 @@ struct TrackPathFinder {
TrackPathFinderLink links[0x400]; /* hopefully, this is enough. */ TrackPathFinderLink links[0x400]; /* hopefully, this is enough. */
}; };
void FollowTrack(TileIndex tile, uint16 flags, byte direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data); void FollowTrack(TileIndex tile, uint16 flags, DiagDirection direction, TPFEnumProc* enum_proc, TPFAfterProc* after_proc, void* data);
typedef struct { typedef struct {
TileIndex tile; TileIndex tile;
@ -66,6 +68,6 @@ typedef struct {
} FindLengthOfTunnelResult; } FindLengthOfTunnelResult;
FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, uint direction); FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, uint direction);
void NewTrainPathfind(TileIndex tile, TileIndex dest, byte direction, NTPEnumProc *enum_proc, void *data); void NewTrainPathfind(TileIndex tile, TileIndex dest, DiagDirection direction, NTPEnumProc* enum_proc, void* data);
#endif /* PATHFIND_H */ #endif /* PATHFIND_H */

View File

@ -1755,13 +1755,13 @@ make_red:
} }
bool UpdateSignalsOnSegment(TileIndex tile, byte direction) bool UpdateSignalsOnSegment(TileIndex tile, Direction dir)
{ {
SetSignalsData ssd; SetSignalsData ssd;
int result = -1; int result = -1;
DiagDirection direction = DirToDiagDir(dir);
ssd.cur_stack = 0; ssd.cur_stack = 0;
direction >>= 1;
for (;;) { for (;;) {
// go through one segment and update all signals pointing into that segment. // go through one segment and update all signals pointing into that segment.

View File

@ -309,7 +309,6 @@ static bool EnumRoadSignalFindDepot(TileIndex tile, void* data, int track, uint
static const Depot* FindClosestRoadDepot(const Vehicle* v) static const Depot* FindClosestRoadDepot(const Vehicle* v)
{ {
TileIndex tile = v->tile; TileIndex tile = v->tile;
int i;
if (v->u.road.state == 255) tile = GetVehicleOutOfTunnelTile(v); if (v->u.road.state == 255) tile = GetVehicleOutOfTunnelTile(v);
@ -327,6 +326,8 @@ static const Depot* FindClosestRoadDepot(const Vehicle* v)
/* We do not search in two directions here, why should we? We can't reverse right now can we? */ /* We do not search in two directions here, why should we? We can't reverse right now can we? */
} else { } else {
RoadFindDepotData rfdd; RoadFindDepotData rfdd;
DiagDirection i;
rfdd.owner = v->owner; rfdd.owner = v->owner;
rfdd.best_length = (uint)-1; rfdd.best_length = (uint)-1;
@ -1187,14 +1188,14 @@ static void RoadVehController(Vehicle *v)
if (v->current_order.type == OT_LOADING) return; if (v->current_order.type == OT_LOADING) return;
if (v->u.road.state == 254) { if (v->u.road.state == 254) {
int dir; DiagDirection dir;
const RoadDriveEntry* rdp; const RoadDriveEntry* rdp;
byte rd2; byte rd2;
v->cur_speed = 0; v->cur_speed = 0;
dir = GB(_m[v->tile].m5, 0, 2); dir = GB(_m[v->tile].m5, 0, 2);
v->direction = dir * 2 + 1; v->direction = DiagDirToDir(dir);
rd2 = _roadveh_data_2[dir]; rd2 = _roadveh_data_2[dir];
rdp = _road_drive_data[(_opt.road_side << 4) + rd2]; rdp = _road_drive_data[(_opt.road_side << 4) + rd2];

View File

@ -522,7 +522,7 @@ static int32 CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 flags)
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
Vehicle *u, *w; Vehicle *u, *w;
uint dir; DiagDirection dir;
v = vl[0]; v = vl[0];
v->spritenum = rvi->image_index; v->spritenum = rvi->image_index;
@ -541,7 +541,7 @@ static int32 CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 flags)
dir = GB(_m[tile].m5, 0, 2); dir = GB(_m[tile].m5, 0, 2);
v->direction = dir * 2 + 1; v->direction = DiagDirToDir(dir);
v->tile = tile; v->tile = tile;
x = TileX(tile) * TILE_SIZE | _vehicle_initial_x_fract[dir]; x = TileX(tile) * TILE_SIZE | _vehicle_initial_x_fract[dir];
@ -694,13 +694,13 @@ int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
uint dir; DiagDirection dir;
v->unitnumber = unit_num; v->unitnumber = unit_num;
dir = GB(_m[tile].m5, 0, 2); dir = GB(_m[tile].m5, 0, 2);
v->direction = dir * 2 + 1; v->direction = DiagDirToDir(dir);
v->tile = tile; v->tile = tile;
v->owner = _current_player; v->owner = _current_player;
v->x_pos = (x |= _vehicle_initial_x_fract[dir]); v->x_pos = (x |= _vehicle_initial_x_fract[dir]);
@ -1354,7 +1354,7 @@ int32 CmdSellRailWagon(int x, int y, uint32 flags, uint32 p1, uint32 p2)
return cost; return cost;
} }
static void UpdateTrainDeltaXY(Vehicle *v, int direction) static void UpdateTrainDeltaXY(Vehicle *v, Direction direction)
{ {
#define MKIT(a,b,c,d) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0) #define MKIT(a,b,c,d) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0)
static const uint32 _delta_xy_table[8] = { static const uint32 _delta_xy_table[8] = {
@ -1744,7 +1744,6 @@ static bool NtpCallbFindDepot(TileIndex tile, TrainFindDepotData *tfdd, int trac
// crashed! // crashed!
static TrainFindDepotData FindClosestTrainDepot(Vehicle *v) static TrainFindDepotData FindClosestTrainDepot(Vehicle *v)
{ {
int i;
TrainFindDepotData tfdd; TrainFindDepotData tfdd;
TileIndex tile = v->tile; TileIndex tile = v->tile;
@ -1782,14 +1781,16 @@ static TrainFindDepotData FindClosestTrainDepot(Vehicle *v)
} }
} else { } else {
// search in the forward direction first. // search in the forward direction first.
i = v->direction >> 1; DiagDirection i;
if (!(v->direction & 1) && v->u.rail.track != _state_dir_table[i]) i = (i - 1) & 3;
i = DirToDiagDir(v->direction);
if (!(v->direction & 1) && v->u.rail.track != _state_dir_table[i]) i = (i + 3) & 3;
NewTrainPathfind(tile, 0, i, (NTPEnumProc*)NtpCallbFindDepot, &tfdd); NewTrainPathfind(tile, 0, i, (NTPEnumProc*)NtpCallbFindDepot, &tfdd);
if (tfdd.best_length == (uint)-1){ if (tfdd.best_length == (uint)-1){
tfdd.reverse = true; tfdd.reverse = true;
// search in backwards direction // search in backwards direction
i = (v->direction^4) >> 1; i = ReverseDiagDir(DirToDiagDir(v->direction));
if (!(v->direction & 1) && v->u.rail.track != _state_dir_table[i]) i = (i - 1) & 3; if (!(v->direction & 1) && v->u.rail.track != _state_dir_table[i]) i = (i + 3) & 3;
NewTrainPathfind(tile, 0, i, (NTPEnumProc*)NtpCallbFindDepot, &tfdd); NewTrainPathfind(tile, 0, i, (NTPEnumProc*)NtpCallbFindDepot, &tfdd);
} }
} }
@ -2081,7 +2082,7 @@ static unsigned int _declspec(naked) _rdtsc(void)
/* choose a track */ /* choose a track */
static byte ChooseTrainTrack(Vehicle *v, TileIndex tile, int enterdir, TrackdirBits trackdirbits) static byte ChooseTrainTrack(Vehicle* v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirbits)
{ {
TrainTrackFollowerData fd; TrainTrackFollowerData fd;
uint best_track; uint best_track;
@ -2496,7 +2497,7 @@ static const byte _new_vehicle_direction_table[11] = {
2, 3, 4, 2, 3, 4,
}; };
static int GetNewVehicleDirectionByTile(TileIndex new_tile, TileIndex old_tile) static Direction GetNewVehicleDirectionByTile(TileIndex new_tile, TileIndex old_tile)
{ {
uint offs = (TileY(new_tile) - TileY(old_tile) + 1) * 4 + uint offs = (TileY(new_tile) - TileY(old_tile) + 1) * 4 +
TileX(new_tile) - TileX(old_tile) + 1; TileX(new_tile) - TileX(old_tile) + 1;
@ -2504,7 +2505,7 @@ static int GetNewVehicleDirectionByTile(TileIndex new_tile, TileIndex old_tile)
return _new_vehicle_direction_table[offs]; return _new_vehicle_direction_table[offs];
} }
static int GetNewVehicleDirection(const Vehicle *v, int x, int y) static Direction GetNewVehicleDirection(const Vehicle *v, int x, int y)
{ {
uint offs = (y - v->y_pos + 1) * 4 + (x - v->x_pos + 1); uint offs = (y - v->y_pos + 1) * 4 + (x - v->x_pos + 1);
assert(offs < 11); assert(offs < 11);
@ -2620,7 +2621,7 @@ static const byte _otherside_signal_directions[14] = {
5, 7, 7, 5, 7, 1, 5, 7, 7, 5, 7, 1,
}; };
static void TrainMovedChangeSignals(TileIndex tile, int dir) static void TrainMovedChangeSignals(TileIndex tile, DiagDirection dir)
{ {
if (IsTileType(tile, MP_RAILWAY) && (_m[tile].m5 & 0xC0) == 0x40) { if (IsTileType(tile, MP_RAILWAY) && (_m[tile].m5 & 0xC0) == 0x40) {
uint i = FindFirstBit2x64((_m[tile].m5 + (_m[tile].m5 << 8)) & _reachable_tracks[dir]); uint i = FindFirstBit2x64((_m[tile].m5 + (_m[tile].m5 << 8)) & _reachable_tracks[dir]);
@ -2751,7 +2752,10 @@ static void TrainController(Vehicle *v)
Vehicle *prev; Vehicle *prev;
GetNewVehiclePosResult gp; GetNewVehiclePosResult gp;
uint32 r, tracks,ts; uint32 r, tracks,ts;
int i, enterdir, newdir, dir; int i;
DiagDirection enterdir;
Direction dir;
Direction newdir;
byte chosen_dir; byte chosen_dir;
byte chosen_track; byte chosen_track;
byte old_z; byte old_z;
@ -2795,7 +2799,7 @@ static void TrainController(Vehicle *v)
byte bits; byte bits;
/* Determine what direction we're entering the new tile from */ /* Determine what direction we're entering the new tile from */
dir = GetNewVehicleDirectionByTile(gp.new_tile, gp.old_tile); dir = GetNewVehicleDirectionByTile(gp.new_tile, gp.old_tile);
enterdir = dir >> 1; enterdir = DirToDiagDir(dir);
assert(enterdir==0 || enterdir==1 || enterdir==2 || enterdir==3); assert(enterdir==0 || enterdir==1 || enterdir==2 || enterdir==3);
/* Get the status of the tracks in the new tile and mask /* Get the status of the tracks in the new tile and mask
@ -2871,7 +2875,7 @@ static void TrainController(Vehicle *v)
/* Signals can only change when the first /* Signals can only change when the first
* (above) or the last vehicle moves. */ * (above) or the last vehicle moves. */
if (v->next == NULL) if (v->next == NULL)
TrainMovedChangeSignals(gp.old_tile, (enterdir) ^ 2); TrainMovedChangeSignals(gp.old_tile, ReverseDiagDir(enterdir));
if (prev == NULL) AffectSpeedByDirChange(v, chosen_dir); if (prev == NULL) AffectSpeedByDirChange(v, chosen_dir);
@ -3117,7 +3121,7 @@ static bool TrainCheckIfLineEnds(Vehicle *v)
tile = v->tile; tile = v->tile;
// tunnel entrance? // tunnel entrance?
if (IsTunnelTile(tile) && GB(_m[tile].m5, 0, 2) * 2 + 1 == v->direction) if (IsTunnelTile(tile) && DiagDirToDir(GB(_m[tile].m5, 0, 2)) == v->direction)
return true; return true;
// depot? // depot?

View File

@ -427,7 +427,7 @@ not_valid_below:;
return cost; return cost;
} }
static bool DoCheckTunnelInWay(TileIndex tile, uint z, uint dir) static bool DoCheckTunnelInWay(TileIndex tile, uint z, DiagDirection dir)
{ {
TileIndexDiff delta = TileOffsByDir(dir); TileIndexDiff delta = TileOffsByDir(dir);
uint height; uint height;
@ -450,10 +450,11 @@ static bool DoCheckTunnelInWay(TileIndex tile, uint z, uint dir)
bool CheckTunnelInWay(TileIndex tile, int z) bool CheckTunnelInWay(TileIndex tile, int z)
{ {
return DoCheckTunnelInWay(tile,z,0) && return
DoCheckTunnelInWay(tile,z,1) && DoCheckTunnelInWay(tile, z, DIAGDIR_NE) &&
DoCheckTunnelInWay(tile,z,2) && DoCheckTunnelInWay(tile, z, DIAGDIR_SE) &&
DoCheckTunnelInWay(tile,z,3); DoCheckTunnelInWay(tile, z, DIAGDIR_SW) &&
DoCheckTunnelInWay(tile, z, DIAGDIR_NW);
} }
@ -535,7 +536,7 @@ int32 CmdBuildTunnel(int x, int y, uint32 flags, uint32 p1, uint32 p2)
_m[end_tile].m3 = GB(p1, 0, 4); // rail type (if any) _m[end_tile].m3 = GB(p1, 0, 4); // rail type (if any)
_m[end_tile].m5 = (GB(p1, 9, 1) << 2) | (direction ^ 2); // transport type and entrance direction _m[end_tile].m5 = (GB(p1, 9, 1) << 2) | (direction ^ 2); // transport type and entrance direction
if (GB(p1, 9, 1) == 0) UpdateSignalsOnSegment(start_tile, direction << 1); if (GB(p1, 9, 1) == 0) UpdateSignalsOnSegment(start_tile, DiagDirToDir(direction));
} }
return cost; return cost;
@ -545,7 +546,7 @@ TileIndex CheckTunnelBusy(TileIndex tile, uint *length)
{ {
uint z = GetTileZ(tile); uint z = GetTileZ(tile);
byte m5 = _m[tile].m5; byte m5 = _m[tile].m5;
int delta = TileOffsByDir(m5 & 3); TileIndexDiff delta = TileOffsByDir(m5 & 3);
uint len = 0; uint len = 0;
TileIndex starttile = tile; TileIndex starttile = tile;
Vehicle *v; Vehicle *v;
@ -1407,11 +1408,11 @@ static const byte _tunnel_fractcoord_7[4] = {0x52, 0x85, 0x96, 0x49};
static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y) static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y)
{ {
int dir, vdir;
if (GB(_m[tile].m5, 4, 4) == 0) { if (GB(_m[tile].m5, 4, 4) == 0) {
int z = GetSlopeZ(x, y) - v->z_pos; int z = GetSlopeZ(x, y) - v->z_pos;
byte fc; byte fc;
DiagDirection dir;
DiagDirection vdir;
if (myabs(z) > 2) return 8; if (myabs(z) > 2) return 8;
@ -1419,7 +1420,7 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
fc = (x & 0xF) + (y << 4); fc = (x & 0xF) + (y << 4);
dir = GB(_m[tile].m5, 0, 2); dir = GB(_m[tile].m5, 0, 2);
vdir = v->direction >> 1; vdir = DirToDiagDir(v->direction);
if (v->u.rail.track != 0x40 && dir == vdir) { if (v->u.rail.track != 0x40 && dir == vdir) {
if (IsFrontEngine(v) && fc == _tunnel_fractcoord_1[dir]) { if (IsFrontEngine(v) && fc == _tunnel_fractcoord_1[dir]) {
@ -1435,7 +1436,7 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
} }
} }
if (dir == (vdir^2) && fc == _tunnel_fractcoord_3[dir] && z == 0) { if (dir == ReverseDiagDir(vdir) && fc == _tunnel_fractcoord_3[dir] && z == 0) {
/* We're at the tunnel exit ?? */ /* We're at the tunnel exit ?? */
v->tile = tile; v->tile = tile;
v->u.rail.track = _exit_tunnel_track[dir]; v->u.rail.track = _exit_tunnel_track[dir];
@ -1446,7 +1447,7 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
} else if (v->type == VEH_Road) { } else if (v->type == VEH_Road) {
fc = (x & 0xF) + (y << 4); fc = (x & 0xF) + (y << 4);
dir = GB(_m[tile].m5, 0, 2); dir = GB(_m[tile].m5, 0, 2);
vdir = v->direction >> 1; vdir = DirToDiagDir(v->direction);
// Enter tunnel? // Enter tunnel?
if (v->u.road.state != 0xFF && dir == vdir) { if (v->u.road.state != 0xFF && dir == vdir) {
@ -1461,7 +1462,7 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
} }
} }
if (dir == (vdir ^ 2) && ( if (dir == ReverseDiagDir(vdir) && (
/* We're at the tunnel exit ?? */ /* We're at the tunnel exit ?? */
fc == _tunnel_fractcoord_6[dir] || fc == _tunnel_fractcoord_6[dir] ||
fc == _tunnel_fractcoord_7[dir] fc == _tunnel_fractcoord_7[dir]

View File

@ -284,7 +284,7 @@ void VehicleInTheWayErrMsg(const Vehicle* v);
Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z); Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z);
TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v); TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v);
bool UpdateSignalsOnSegment(TileIndex tile, byte direction); bool UpdateSignalsOnSegment(TileIndex tile, Direction direction);
void SetSignalsOnBothDir(TileIndex tile, byte track); void SetSignalsOnBothDir(TileIndex tile, byte track);
Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y); Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y);