Changeset - r16294:f97c9cd4ff1e
[Not reviewed]
master
0 1 0
frosch - 14 years ago 2010-10-22 19:57:56
frosch@openttd.org
(svn r21012) -Codechange: Deduplicate some code. (Hirundo)
1 file changed with 6 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -1500,23 +1500,22 @@ static const byte _tunnel_fractcoord_7[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;
 
	/* Direction into the wormhole */
 
	const DiagDirection dir = GetTunnelBridgeDirection(tile);
 
	/* Direction of the vehicle */
 
	const DiagDirection vdir = DirToDiagDir(v->direction);
 

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

	
 
		if (v->type == VEH_TRAIN) {
 
			Train *t = Train::From(v);
 
			fc = (x & 0xF) + (y << 4);
 

	
 
			vdir = DirToDiagDir(t->direction);
 

	
 
			if (t->track != TRACK_BIT_WORMHOLE && dir == vdir) {
 
				if (t->IsFrontEngine() && fc == _tunnel_fractcoord_1[dir]) {
 
					if (!PlayVehicleSound(t, VSE_TUNNEL) && RailVehInfo(t->engine_type)->engclass == 0) {
 
						SndPlayVehicleFx(SND_05_TRAIN_THROUGH_TUNNEL, v);
 
					}
 
@@ -1537,14 +1536,12 @@ static VehicleEnterTileStatus VehicleEnt
 
				assert(t->track);
 
				t->vehstatus &= ~VS_HIDDEN;
 
				return VETSB_ENTERED_WORMHOLE;
 
			}
 
		} else if (v->type == VEH_ROAD) {
 
			RoadVehicle *rv = RoadVehicle::From(v);
 
			fc = (x & 0xF) + (y << 4);
 
			vdir = DirToDiagDir(v->direction);
 

	
 
			/* Enter tunnel? */
 
			if (rv->state != RVSB_WORMHOLE && dir == vdir) {
 
				if (fc == _tunnel_fractcoord_4[dir] ||
 
						fc == _tunnel_fractcoord_5[dir]) {
 
					rv->tile = tile;
 
@@ -1576,13 +1573,13 @@ static VehicleEnterTileStatus VehicleEnt
 
			uint16 spd = GetBridgeSpec(GetBridgeType(tile))->speed;
 

	
 
			if (v->type == VEH_ROAD) spd *= 2;
 
			if (v->cur_speed > spd) v->cur_speed = spd;
 
		}
 

	
 
		if (DirToDiagDir(v->direction) == dir) {
 
		if (vdir == dir) {
 
			switch (dir) {
 
				default: NOT_REACHED();
 
				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;
 
@@ -1609,13 +1606,13 @@ static VehicleEnterTileStatus VehicleEnt
 
					Ship::From(v)->state = TRACK_BIT_WORMHOLE;
 
					break;
 

	
 
				default: NOT_REACHED();
 
			}
 
			return VETSB_ENTERED_WORMHOLE;
 
		} else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) {
 
		} else if (vdir == ReverseDiagDir(dir)) {
 
			v->tile = tile;
 
			switch (v->type) {
 
				case VEH_TRAIN: {
 
					Train *t = Train::From(v);
 
					if (t->track == TRACK_BIT_WORMHOLE) {
 
						t->track = (DiagDirToAxis(dir) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y);
0 comments (0 inline, 0 general)