Changeset - r16414:400537a27ef8
[Not reviewed]
master
0 1 0
rubidium - 14 years ago 2010-11-10 23:15:48
rubidium@openttd.org
(svn r21140) -Codechange: Use the new 'frame' variable to handle road vehicles entering or leaving a tunnel (Hirundo)
1 file changed with 20 insertions and 16 deletions:
0 comments (0 inline, 0 general)
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -1495,18 +1495,27 @@ static const byte TUNNEL_SOUND_FRAME = 1
 
 * When entering a tunnel, hide the train when it reaches the given frame.
 
 * When leaving a tunnel, show the train when it is one frame further
 
 * to the 'outside', i.e. at (TILE_SIZE-1) - (frame) + 1
 
 */
 
static const byte _train_tunnel_frame[DIAGDIR_END] = {14, 9, 7, 12};
 

	
 
static const byte _road_exit_tunnel_frame[DIAGDIR_END] = {2, 7, 9, 4};
 
/**
 
 * Frame when a road vehicle enters a tunnel with a certain direction.
 
 * This differs per direction, like for trains. To make it even more fun,
 
 * the entry and exit frames are not consistent. This is the entry frame,
 
 * the road vehicle should be hidden when it reaches this frame.
 
 */
 
static const byte _road_enter_tunnel_frame[DIAGDIR_END] = {13, 8, 8, 13};
 

	
 
static const byte _tunnel_fractcoord_4[DIAGDIR_END]    = {0x52, 0x85, 0x98, 0x29};
 
static const byte _tunnel_fractcoord_5[DIAGDIR_END]    = {0x92, 0x89, 0x58, 0x25};
 
static const byte _tunnel_fractcoord_6[DIAGDIR_END]    = {0x92, 0x89, 0x56, 0x45};
 
static const byte _tunnel_fractcoord_7[DIAGDIR_END]    = {0x52, 0x85, 0x96, 0x49};
 
/**
 
 * Frame when a road vehicle exits a tunnel with a certain direction.
 
 * Note that 'direction' refers to the tunnel direction, not the
 
 * vehicle direction. As stated above, this frame is not the same as the
 
 * entry frame, for unclear (historical?) reasons.
 
 */
 
static const byte _road_exit_tunnel_frame[DIAGDIR_END] = {2, 7, 9, 4};
 

	
 
static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y)
 
{
 
	int z = GetSlopeZ(x, y) - v->z_pos;
 

	
 
	if (abs(z) > 2) return VETSB_CANNOT_ENTER;
 
@@ -1517,14 +1526,12 @@ static VehicleEnterTileStatus VehicleEnt
 
	/* New position of the vehicle on the tile */
 
	byte pos = (DiagDirToAxis(vdir) == AXIS_X ? x : y) & TILE_UNIT_MASK;
 
	/* Number of units moved by the vehicle since entering the tile */
 
	byte frame = (vdir == DIAGDIR_NE || vdir == DIAGDIR_NW) ? TILE_SIZE - 1 - pos : pos;
 

	
 
	if (IsTunnel(tile)) {
 
		byte fc = (x & 0xF) + (y << 4);
 

	
 
		if (v->type == VEH_TRAIN) {
 
			Train *t = Train::From(v);
 

	
 
			if (t->track != TRACK_BIT_WORMHOLE && dir == vdir) {
 
				if (t->IsFrontEngine() && frame == TUNNEL_SOUND_FRAME) {
 
					if (!PlayVehicleSound(t, VSE_TUNNEL) && RailVehInfo(t->engine_type)->engclass == 0) {
 
@@ -1550,32 +1557,29 @@ static VehicleEnterTileStatus VehicleEnt
 
			}
 
		} else if (v->type == VEH_ROAD) {
 
			RoadVehicle *rv = RoadVehicle::From(v);
 

	
 
			/* Enter tunnel? */
 
			if (rv->state != RVSB_WORMHOLE && dir == vdir) {
 
				if (fc == _tunnel_fractcoord_4[dir] ||
 
						fc == _tunnel_fractcoord_5[dir]) {
 
				if (frame == _road_enter_tunnel_frame[dir]) {
 
					/* Frame should be equal to the next frame number in the RV's movement */
 
					assert(frame == rv->frame + 1);
 
					rv->tile = tile;
 
					rv->state = RVSB_WORMHOLE;
 
					rv->vehstatus |= VS_HIDDEN;
 
					return VETSB_ENTERED_WORMHOLE;
 
				} else {
 
					return VETSB_CONTINUE;
 
				}
 
			}
 

	
 
			if (dir == ReverseDiagDir(vdir) && (
 
						/* We're at the tunnel exit ?? */
 
						fc == _tunnel_fractcoord_6[dir] ||
 
						fc == _tunnel_fractcoord_7[dir]
 
					) &&
 
					z == 0) {
 
			/* We're at the tunnel exit ?? */
 
			if (dir == ReverseDiagDir(vdir) && frame == _road_exit_tunnel_frame[dir] && z == 0) {
 
				rv->tile = tile;
 
				rv->state = DiagDirToDiagTrackdir(vdir);
 
				rv->frame = _road_exit_tunnel_frame[dir];
 
				rv->frame = frame;
 
				rv->vehstatus &= ~VS_HIDDEN;
 
				return VETSB_ENTERED_WORMHOLE;
 
			}
 
		}
 
	} else { // IsBridge(tile)
 
		if (v->type != VEH_SHIP) {
0 comments (0 inline, 0 general)