Changeset - r1432:3002f37ab682
[Not reviewed]
master
0 1 0
tron - 20 years ago 2005-03-06 12:41:18
tron@openttd.org
(svn r1936) End some void-pointer-as-int-abuse; this also fixes a latent bug where a TileIndex was only 24bit wide (on 32bit architectures)
1 file changed with 20 insertions and 8 deletions:
0 comments (0 inline, 0 general)
train_cmd.c
Show inline comments
 
@@ -2365,22 +2365,29 @@ static void CheckTrainCollision(Vehicle 
 
		0);
 

	
 
	ModifyStationRatingAround(v->tile, v->owner, -160, 30);
 
	SndPlayVehicleFx(SND_13_BIG_CRASH, v);
 
}
 

	
 
typedef struct VehicleAtSignalData {
 
	TileIndex tile;
 
	byte direction;
 
} VehicleAtSignalData;
 

	
 
static void *CheckVehicleAtSignal(Vehicle *v, void *data)
 
{
 
	uint32 d = (uint32)data;
 

	
 
	if (v->type == VEH_Train && v->subtype == TS_Front_Engine && v->tile == (TileIndex)(d >> 8)) {
 
		byte diff = (v->direction - (byte)d + 2) & 7;
 
	const VehicleAtSignalData* vasd = data;
 

	
 
	if (v->type == VEH_Train && v->subtype == TS_Front_Engine &&
 
			v->tile == vasd->tile) {
 
		byte diff = (v->direction - vasd->direction + 2) & 7;
 

	
 
		if (diff == 2 || (v->cur_speed <= 5 && diff <= 4))
 
			return (void*)1;
 
			return v;
 
	}
 
	return 0;
 
	return NULL;
 
}
 

	
 
static void TrainController(Vehicle *v)
 
{
 
	Vehicle *prev = NULL;
 
	GetNewVehiclePosResult gp;
 
@@ -2578,15 +2585,20 @@ red_light: {
 
				return;
 
		} else if (_map3_lo[gp.new_tile] & _signal_along_trackdir[i]){
 
			v->cur_speed = 0;
 
			v->subspeed = 0;
 
			v->progress = 255-10;
 
			if (++v->load_unload_time_rem < _patches.wait_twoway_signal * 73) {
 
				uint o_tile = gp.new_tile + TileOffsByDir(enterdir);
 
				TileIndex o_tile = gp.new_tile + TileOffsByDir(enterdir);
 
				VehicleAtSignalData vasd = {
 
					o_tile,
 
					dir ^ 4
 
				};
 

	
 
				/* check if a train is waiting on the other side */
 
				if (VehicleFromPos(o_tile, (void*)( (o_tile<<8) | (dir^4)), (VehicleFromPosProc*)CheckVehicleAtSignal) == NULL)
 
				if (VehicleFromPos(o_tile, &vasd, CheckVehicleAtSignal) == NULL)
 
					return;
 
			}
 
		}
 
	}
 

	
 
reverse_train_direction:
0 comments (0 inline, 0 general)