Changeset - r11322:36e10b93494e
[Not reviewed]
master
0 2 0
rubidium - 16 years ago 2009-03-11 23:23:08
rubidium@openttd.org
(svn r15677) -Fix [FS#2546]: vehicle images would be determined during the process of moving the vehicle which means that only the (orientation) data for the vehicles in front of it is valid. Now the data for the vehicles behind the vehicle are valid too.
2 files changed with 22 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/roadveh_cmd.cpp
Show inline comments
 
@@ -1245,13 +1245,12 @@ static bool RoadVehLeaveDepot(Vehicle *v
 
	}
 

	
 
	v->vehstatus &= ~VS_HIDDEN;
 
	v->u.road.state = tdir;
 
	v->u.road.frame = RVC_DEPOT_START_FRAME;
 

	
 
	v->cur_image = v->GetImage(v->direction);
 
	v->UpdateDeltaXY(v->direction);
 
	SetRoadVehPosition(v, x, y);
 

	
 
	InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
 

	
 
	return true;
 
@@ -1374,13 +1373,12 @@ static bool IndividualRoadVehicleControl
 
				return false;
 
			}
 
		}
 

	
 
		if (IsTileType(gp.new_tile, MP_TUNNELBRIDGE) && HasBit(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) {
 
			/* Vehicle has just entered a bridge or tunnel */
 
			v->cur_image = v->GetImage(v->direction);
 
			v->UpdateDeltaXY(v->direction);
 
			SetRoadVehPosition(v, gp.x, gp.y);
 
			return true;
 
		}
 

	
 
		v->x_pos = gp.x;
 
@@ -1521,13 +1519,12 @@ again:
 
		}
 
		if (new_dir != v->direction) {
 
			v->direction = new_dir;
 
			v->cur_speed -= v->cur_speed >> 2;
 
		}
 

	
 
		v->cur_image = v->GetImage(v->direction);
 
		v->UpdateDeltaXY(v->direction);
 
		RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y));
 
		return true;
 
	}
 

	
 
	if (rd.x & RDE_TURNED) {
 
@@ -1587,13 +1584,12 @@ again:
 

	
 
		if (new_dir != v->direction) {
 
			v->direction = new_dir;
 
			v->cur_speed -= v->cur_speed >> 2;
 
		}
 

	
 
		v->cur_image = v->GetImage(v->direction);
 
		v->UpdateDeltaXY(v->direction);
 
		RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y));
 
		return true;
 
	}
 

	
 
	/* This vehicle is not in a wormhole and it hasn't entered a new tile. If
 
@@ -1628,13 +1624,12 @@ again:
 
	Direction old_dir = v->direction;
 
	if (new_dir != old_dir) {
 
		v->direction = new_dir;
 
		v->cur_speed -= (v->cur_speed >> 2);
 
		if (old_dir != v->u.road.state) {
 
			/* The vehicle is in a road stop */
 
			v->cur_image = v->GetImage(v->direction);
 
			v->UpdateDeltaXY(v->direction);
 
			SetRoadVehPosition(v, v->x_pos, v->y_pos);
 
			/* Note, return here means that the frame counter is not incremented
 
			 * for vehicles changing direction in a road stop. This causes frames to
 
			 * be repeated. (XXX) Is this intended? */
 
			return true;
 
@@ -1752,13 +1747,12 @@ again:
 
	}
 

	
 
	/* Move to next frame unless vehicle arrived at a stop position
 
	 * in a depot or entered a tunnel/bridge */
 
	if (!HasBit(r, VETS_ENTERED_WORMHOLE)) v->u.road.frame++;
 

	
 
	v->cur_image = v->GetImage(v->direction);
 
	v->UpdateDeltaXY(v->direction);
 
	RoadZPosAffectSpeed(v, SetRoadVehPosition(v, x, y));
 
	return true;
 
}
 

	
 
static void RoadVehController(Vehicle *v)
 
@@ -1810,12 +1804,20 @@ static void RoadVehController(Vehicle *v
 
		adv_spd = (v->direction & 1) ? 192 : 256;
 

	
 
		/* Test for a collision, but only if another movement will occur. */
 
		if (j >= adv_spd && RoadVehCheckTrainCrash(v)) break;
 
	}
 

	
 
	for (Vehicle *u = v; u != NULL; u = u->Next()) {
 
		if ((u->vehstatus & VS_HIDDEN) != 0) continue;
 

	
 
		uint16 old_image = u->cur_image;
 
		u->cur_image = u->GetImage(u->direction);
 
		if (old_image != u->cur_image) VehicleMove(u, true);
 
	}
 

	
 
	if (v->progress == 0) v->progress = j;
 
}
 

	
 
static void AgeRoadVehCargo(Vehicle *v)
 
{
 
	if (_age_cargo_skip_counter != 0) return;
src/train_cmd.cpp
Show inline comments
 
@@ -36,13 +36,13 @@
 

	
 
#include "table/strings.h"
 
#include "table/train_cmd.h"
 

	
 
static Track ChooseTrainTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool force_res, bool *got_reservation, bool mark_stuck);
 
static bool TrainCheckIfLineEnds(Vehicle *v);
 
static void TrainController(Vehicle *v, Vehicle *nomove, bool update_image);
 
static void TrainController(Vehicle *v, Vehicle *nomove);
 
static TileIndex TrainApproachingCrossingTile(const Vehicle *v);
 
static void CheckIfTrainNeedsService(Vehicle *v);
 
static void CheckNextTrainTile(Vehicle *v);
 

	
 
static const byte _vehicle_initial_x_fract[4] = {10, 8, 4,  8};
 
static const byte _vehicle_initial_y_fract[4] = { 8, 4, 8, 10};
 
@@ -1757,13 +1757,13 @@ static void AdvanceWagonsBeforeSwap(Vehi
 
		first = first->Next();
 

	
 
		int differential = base->u.rail.cached_veh_length - last->u.rail.cached_veh_length;
 

	
 
		/* do not update images now
 
		 * negative differential will be handled in AdvanceWagonsAfterSwap() */
 
		for (int i = 0; i < differential; i++) TrainController(first, last->Next(), false);
 
		for (int i = 0; i < differential; i++) TrainController(first, last->Next());
 

	
 
		base = first; // == base->Next()
 
		length -= 2;
 
	}
 
}
 

	
 
@@ -1787,13 +1787,13 @@ static void AdvanceWagonsAfterSwap(Vehic
 
		/* 'pull' next wagon out of the depot, so we won't miss it (it could stay in depot forever) */
 
		int d = TicksToLeaveDepot(dep);
 

	
 
		if (d <= 0) {
 
			leave->vehstatus &= ~VS_HIDDEN; // move it out of the depot
 
			leave->u.rail.track = TrackToTrackBits(GetRailDepotTrack(leave->tile));
 
			for (int i = 0; i >= d; i--) TrainController(leave, NULL, false); // maybe move it, and maybe let another wagon leave
 
			for (int i = 0; i >= d; i--) TrainController(leave, NULL); // maybe move it, and maybe let another wagon leave
 
		}
 
	} else {
 
		dep = NULL; // no vehicle in a depot, so no vehicle leaving a depot
 
	}
 

	
 
	Vehicle *base = v;
 
@@ -1816,13 +1816,13 @@ static void AdvanceWagonsAfterSwap(Vehic
 
		last = last->Previous();
 
		first = first->Next();
 

	
 
		int differential = last->u.rail.cached_veh_length - base->u.rail.cached_veh_length;
 

	
 
		/* do not update images now */
 
		for (int i = 0; i < differential; i++) TrainController(first, (nomove ? last->Next() : NULL), false);
 
		for (int i = 0; i < differential; i++) TrainController(first, (nomove ? last->Next() : NULL));
 

	
 
		base = first; // == base->Next()
 
		length -= 2;
 
	}
 
}
 

	
 
@@ -3636,13 +3636,13 @@ static Vehicle *CheckVehicleAtSignal(Veh
 
		if (v->cur_speed <= 5 && TrainExitDir(v->direction, v->u.rail.track) == exitdir) return v;
 
	}
 

	
 
	return NULL;
 
}
 

	
 
static void TrainController(Vehicle *v, Vehicle *nomove, bool update_image)
 
static void TrainController(Vehicle *v, Vehicle *nomove)
 
{
 
	Vehicle *prev;
 

	
 
	/* For every vehicle after and including the given vehicle */
 
	for (prev = v->Previous(); v != nomove; prev = v, v = v->Next()) {
 
		DiagDirection enterdir = DIAGDIR_BEGIN;
 
@@ -3838,13 +3838,12 @@ static void TrainController(Vehicle *v, 
 
				continue;
 
			}
 
		}
 

	
 
		/* update image of train, as well as delta XY */
 
		v->UpdateDeltaXY(v->direction);
 
		if (update_image) v->cur_image = v->GetImage(v->direction);
 

	
 
		v->x_pos = gp.x;
 
		v->y_pos = gp.y;
 

	
 
		/* update the Z position of the vehicle */
 
		byte old_z = AfterSetTrainPos(v, (gp.new_tile != gp.old_tile));
 
@@ -4337,21 +4336,29 @@ static void TrainLocoHandler(Vehicle *v,
 
		if (v->cur_speed == 0) SetLastSpeed(v, v->cur_speed);
 
	} else {
 
		TrainCheckIfLineEnds(v);
 
		/* Loop until the train has finished moving. */
 
		do {
 
			j -= adv_spd;
 
			TrainController(v, NULL, true);
 
			TrainController(v, NULL);
 
			/* Don't continue to move if the train crashed. */
 
			if (CheckTrainCollision(v)) break;
 
			/* 192 spd used for going straight, 256 for going diagonally. */
 
			adv_spd = (v->direction & 1) ? 192 : 256;
 
		} while (j >= adv_spd);
 
		SetLastSpeed(v, v->cur_speed);
 
	}
 

	
 
	for (Vehicle *u = v; u != NULL; u = u->Next()) {
 
		if ((u->vehstatus & VS_HIDDEN) != 0) continue;
 

	
 
		uint16 old_image = u->cur_image;
 
		u->cur_image = u->GetImage(u->direction);
 
		if (old_image != u->cur_image) VehicleMove(u, true);
 
	}
 

	
 
	if (v->progress == 0) v->progress = j; // Save unused spd for next time, if TrainController didn't set progress
 
}
 

	
 

	
 

	
 
Money Train::GetRunningCost() const
0 comments (0 inline, 0 general)