--- a/src/tunnelbridge_cmd.cpp Wed Feb 14 00:57:15 2007 +0000
+++ b/src/tunnelbridge_cmd.cpp Wed Feb 14 10:46:38 2007 +0000
@@ -1250,7 +1250,10 @@
static const byte _tunnel_fractcoord_3[4] = {0x82, 0x88, 0x86, 0x48};
static const byte _exit_tunnel_track[4] = {1, 2, 1, 2};
-static const byte _road_exit_tunnel_state[4] = {8, 9, 0, 1};
+/** Get the trackdir of the exit of a tunnel */
+static const Trackdir _road_exit_tunnel_state[DIAGDIR_END] = {
+ TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_X_NE, TRACKDIR_Y_SE
+};
static const byte _road_exit_tunnel_frame[4] = {2, 7, 9, 4};
static const byte _tunnel_fractcoord_4[4] = {0x52, 0x85, 0x98, 0x29};
@@ -1262,7 +1265,7 @@
{
int z = GetSlopeZ(x, y) - v->z_pos;
- if (myabs(z) > 2) return 8;
+ if (myabs(z) > 2) return VETSB_CANNOT_ENTER;
if (IsTunnel(tile)) {
byte fc;
@@ -1275,18 +1278,18 @@
dir = GetTunnelDirection(tile);
vdir = DirToDiagDir(v->direction);
- if (v->u.rail.track != 0x40 && dir == vdir) {
+ if (v->u.rail.track != TRACK_BIT_WORMHOLE && dir == vdir) {
if (IsFrontEngine(v) && fc == _tunnel_fractcoord_1[dir]) {
if (!PlayVehicleSound(v, VSE_TUNNEL) && v->spritenum < 4) {
SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v);
}
- return 0;
+ return VETSB_CONTINUE;
}
if (fc == _tunnel_fractcoord_2[dir]) {
v->tile = tile;
v->u.rail.track = TRACK_BIT_WORMHOLE;
v->vehstatus |= VS_HIDDEN;
- return 4;
+ return VETSB_ENTERED_WORMHOLE;
}
}
@@ -1296,7 +1299,7 @@
v->u.rail.track = (TrackBits)_exit_tunnel_track[dir];
assert(v->u.rail.track);
v->vehstatus &= ~VS_HIDDEN;
- return 4;
+ return VETSB_ENTERED_WORMHOLE;
}
} else if (v->type == VEH_Road) {
fc = (x & 0xF) + (y << 4);
@@ -1304,15 +1307,15 @@
vdir = DirToDiagDir(v->direction);
// Enter tunnel?
- if (v->u.road.state != 0xFF && dir == vdir) {
+ if (v->u.road.state != RVSB_WORMHOLE && dir == vdir) {
if (fc == _tunnel_fractcoord_4[dir] ||
fc == _tunnel_fractcoord_5[dir]) {
v->tile = tile;
- v->u.road.state = 0xFF;
+ v->u.road.state = RVSB_WORMHOLE;
v->vehstatus |= VS_HIDDEN;
- return 4;
+ return VETSB_ENTERED_WORMHOLE;
} else {
- return 0;
+ return VETSB_CONTINUE;
}
}
@@ -1326,7 +1329,7 @@
v->u.road.state = _road_exit_tunnel_state[dir];
v->u.road.frame = _road_exit_tunnel_frame[dir];
v->vehstatus &= ~VS_HIDDEN;
- return 4;
+ return VETSB_ENTERED_WORMHOLE;
}
}
} else if (IsBridge(tile)) { // XXX is this necessary?
@@ -1344,37 +1347,37 @@
if (DirToDiagDir(v->direction) == dir) {
switch (dir) {
default: NOT_REACHED();
- case DIAGDIR_NE: if ((x & 0xF) != 0) return 0; break;
- case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return 0; break;
- case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return 0; break;
- case DIAGDIR_NW: if ((y & 0xF) != 0) return 0; break;
+ case DIAGDIR_NE: if ((x & 0xF) != 0) return VETSB_CONTINUE; break;
+ case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return VETSB_CONTINUE; break;
+ case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return VETSB_CONTINUE; break;
+ case DIAGDIR_NW: if ((y & 0xF) != 0) return VETSB_CONTINUE; break;
}
if (v->type == VEH_Train) {
v->u.rail.track = TRACK_BIT_WORMHOLE;
CLRBIT(v->u.rail.flags, VRF_GOINGUP);
CLRBIT(v->u.rail.flags, VRF_GOINGDOWN);
} else {
- v->u.road.state = 0xFF;
+ v->u.road.state = RVSB_WORMHOLE;
}
- return 4;
+ return VETSB_ENTERED_WORMHOLE;
} else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) {
v->tile = tile;
if (v->type == VEH_Train) {
- if (v->u.rail.track == 0x40) {
+ if (v->u.rail.track == TRACK_BIT_WORMHOLE) {
v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
- return 4;
+ return VETSB_ENTERED_WORMHOLE;
}
} else {
- if (v->u.road.state == 0xFF) {
+ if (v->u.road.state == RVSB_WORMHOLE) {
v->u.road.state = _road_exit_tunnel_state[dir];
v->u.road.frame = 0;
- return 4;
+ return VETSB_ENTERED_WORMHOLE;
}
}
- return 0;
+ return VETSB_CONTINUE;
}
}
- return 0;
+ return VETSB_CONTINUE;
}
extern const TileTypeProcs _tile_type_tunnelbridge_procs = {