Changeset - r63:76f13376c302
[Not reviewed]
master
0 1 0
dominik - 20 years ago 2004-08-16 13:31:18
dominik@openttd.org
(svn r64) Fix: Road vehicles don't get stuck any more (Truelight + Celestar
1 file changed with 15 insertions and 6 deletions:
0 comments (0 inline, 0 general)
roadveh_cmd.c
Show inline comments
 
@@ -734,19 +734,24 @@ typedef struct RoadVehFindData {
 

	
 
void *EnumCheckRoadVehClose(Vehicle *v, RoadVehFindData *rvf)
 
{
 
	static const byte _dists[] = { 
 
		4, 8, 4, 4, 4, 8, 4, 4,
 
		4, 4, 4, 8, 4, 4, 4, 8,
 
	static const short _dists[] = { 
 
		-4, -8, -4, -1, 4, 8, 4, 1,
 
		-4, -1, 4, 8, 4, 1, -4, -8,
 
	};
 
	
 
	short x_diff = v->x_pos - rvf->x;
 
	short y_diff = v->y_pos - rvf->y;
 

	
 
	if (rvf->veh == v || 
 
			v->type != VEH_Road || 
 
			v->u.road.state == 254 ||
 
			myabs(v->z_pos - rvf->veh->z_pos) > 6 ||
 
			v->direction != rvf->dir ||
 
			myabs(rvf->x - v->x_pos) >= _dists[v->direction] ||
 
			myabs(rvf->y - v->y_pos) >= _dists[v->direction+8])
 
				return NULL;
 
			(_dists[v->direction] < 0 && (x_diff <= _dists[v->direction] || x_diff > 0)) ||
 
			(_dists[v->direction] > 0 && (x_diff >= _dists[v->direction] || x_diff < 0)) ||
 
			(_dists[v->direction+8] < 0 && (y_diff <= _dists[v->direction+8] || y_diff > 0)) ||
 
			(_dists[v->direction+8] > 0 && (y_diff >= _dists[v->direction+8] || y_diff < 0)))
 
   				return NULL;
 

	
 
	return v;
 
}
 
@@ -765,6 +770,10 @@ static Vehicle *RoadVehFindCloseTo(Vehic
 
	rvf.veh = v;
 
	u = VehicleFromPos(TILE_FROM_XY(x,y), &rvf, (VehicleFromPosProc*)EnumCheckRoadVehClose);
 
	
 
	// This code protects a roadvehicle from being blocked for ever
 
	//  If more then 1480 / 74 days a road vehicle is blocked, it will
 
	//  drive just through it. The ultimate backup-code of TTD.
 
	// It can be disabled.
 
	if (u == NULL) {
 
		v->u.road.unk2 = 0;
 
		return NULL;
0 comments (0 inline, 0 general)