Changeset - r5856:e64c21408d74
[Not reviewed]
master
0 3 0
tron - 17 years ago 2007-01-27 16:45:16
tron@openttd.org
(svn r8430) -Fix

Replace the rather obscure control flow for handling aircraft/ship/train orders by something remotly comprehensible (see r3584)
3 files changed with 73 insertions and 62 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -1248,49 +1248,53 @@ static void ProcessAircraftOrder(Vehicle
 
/** Mark all views dirty for an aircraft.
 
 * @param v vehicle to be redrawn.
 
 */
 
static void MarkAircraftDirty(Vehicle *v)
 
{
 
		v->cur_image = GetAircraftImage(v, v->direction);
 
		if (v->subtype == AIR_HELICOPTER) v->next->next->cur_image = GetRotorImage(v);
 
		MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
 
}
 

	
 
static void HandleAircraftLoading(Vehicle *v, int mode)
 
{
 
	if (v->current_order.type == OT_NOTHING) return;
 

	
 
	if (v->current_order.type != OT_DUMMY) {
 
		if (v->current_order.type != OT_LOADING) return;
 
		if (mode != 0) return;
 
		if (--v->load_unload_time_rem != 0) return;
 
	switch (v->current_order.type) {
 
		case OT_LOADING:
 
			if (mode != 0) return;
 
			if (--v->load_unload_time_rem != 0) return;
 

	
 
		if (CanFillVehicle(v) && (v->current_order.flags & OF_FULL_LOAD ||
 
				(_patches.gradual_loading && !HASBIT(v->load_status, LS_LOADING_FINISHED)))) {
 
			SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC);
 
			if (LoadUnloadVehicle(v, false)) {
 
				InvalidateWindow(WC_AIRCRAFT_LIST, v->owner);
 
				MarkAircraftDirty(v);
 
			if (CanFillVehicle(v) && (
 
						v->current_order.flags & OF_FULL_LOAD ||
 
						(_patches.gradual_loading && !HASBIT(v->load_status, LS_LOADING_FINISHED))
 
					)) {
 
				SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC);
 
				if (LoadUnloadVehicle(v, false)) {
 
					InvalidateWindow(WC_AIRCRAFT_LIST, v->owner);
 
					MarkAircraftDirty(v);
 
				}
 
				return;
 
			}
 
			return;
 
		}
 

	
 
		{
 
			Order b = v->current_order;
 
			v->current_order.type = OT_NOTHING;
 
			v->current_order.flags = 0;
 
			MarkAircraftDirty(v);
 
			if (!(b.flags & OF_NON_STOP)) return;
 
		}
 
			break;
 

	
 
		case OT_DUMMY: break;
 

	
 
		default: return;
 
	}
 

	
 
	v->cur_order_index++;
 
	InvalidateVehicleOrder(v);
 
}
 

	
 
static void CrashAirplane(Vehicle *v)
 
{
 
	uint16 amt;
 
	Station *st;
 
	StringID newsitem;
 

	
 
	v->vehstatus |= VS_CRASHED;
 
	v->u.air.crashed_counter = 0;
src/ship_cmd.cpp
Show inline comments
 
@@ -264,46 +264,49 @@ static void ProcessShipOrder(Vehicle *v)
 
		v->dest_tile = GetDepot(order->dest)->xy;
 
	} else {
 
		v->dest_tile = 0;
 
	}
 

	
 
	InvalidateVehicleOrder(v);
 

	
 
	InvalidateWindowClasses(WC_SHIPS_LIST);
 
}
 

	
 
static void HandleShipLoading(Vehicle *v)
 
{
 
	if (v->current_order.type == OT_NOTHING) return;
 

	
 
	if (v->current_order.type != OT_DUMMY) {
 
		if (v->current_order.type != OT_LOADING) return;
 
		if (--v->load_unload_time_rem) return;
 
	switch (v->current_order.type) {
 
		case OT_LOADING:
 
			if (--v->load_unload_time_rem) return;
 

	
 
		if (CanFillVehicle(v) && (v->current_order.flags & OF_FULL_LOAD ||
 
				(_patches.gradual_loading && !HASBIT(v->load_status, LS_LOADING_FINISHED)))) {
 
			SET_EXPENSES_TYPE(EXPENSES_SHIP_INC);
 
			if (LoadUnloadVehicle(v, false)) {
 
				InvalidateWindow(WC_SHIPS_LIST, v->owner);
 
				MarkShipDirty(v);
 
			if (CanFillVehicle(v) && (
 
						v->current_order.flags & OF_FULL_LOAD ||
 
						(_patches.gradual_loading && !HASBIT(v->load_status, LS_LOADING_FINISHED))
 
					)) {
 
				SET_EXPENSES_TYPE(EXPENSES_SHIP_INC);
 
				if (LoadUnloadVehicle(v, false)) {
 
					InvalidateWindow(WC_SHIPS_LIST, v->owner);
 
					MarkShipDirty(v);
 
				}
 
				return;
 
			}
 
			return;
 
		}
 
		PlayShipSound(v);
 
			PlayShipSound(v);
 

	
 
		{
 
			Order b = v->current_order;
 
			v->LeaveStation();
 
			if (!(b.flags & OF_NON_STOP)) return;
 
		}
 
			break;
 

	
 
		case OT_DUMMY: break;
 

	
 
		default: return;
 
	}
 

	
 
	v->cur_order_index++;
 
	InvalidateVehicleOrder(v);
 
}
 

	
 
static void UpdateShipDeltaXY(Vehicle *v, int dir)
 
{
 
#define MKIT(d,c,b,a) ((a&0xFF)<<24) | ((b&0xFF)<<16) | ((c&0xFF)<<8) | ((d&0xFF)<<0)
 
	static const uint32 _delta_xy_table[8] = {
 
		MKIT( -3,  -3,  6,  6),
 
		MKIT(-16,  -3, 32,  6),
src/train_cmd.cpp
Show inline comments
 
@@ -2596,60 +2596,64 @@ static bool ProcessTrainOrder(Vehicle *v
 
}
 

	
 
static void MarkTrainDirty(Vehicle *v)
 
{
 
	do {
 
		v->cur_image = GetTrainImage(v, v->direction);
 
		MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
 
	} while ((v = v->next) != NULL);
 
}
 

	
 
static void HandleTrainLoading(Vehicle *v, bool mode)
 
{
 
	if (v->current_order.type == OT_NOTHING) return;
 

	
 
	if (v->current_order.type != OT_DUMMY) {
 
		if (v->current_order.type != OT_LOADING) return;
 
		if (mode) return;
 

	
 
		// don't mark the train as lost if we're loading on the final station.
 
		if (v->current_order.flags & OF_NON_STOP)
 
			v->u.rail.days_since_order_progr = 0;
 

	
 
		if (--v->load_unload_time_rem) return;
 

	
 
		if (CanFillVehicle(v) && (v->current_order.flags & OF_FULL_LOAD ||
 
				(_patches.gradual_loading && !HASBIT(v->load_status, LS_LOADING_FINISHED)))) {
 
			v->u.rail.days_since_order_progr = 0; /* Prevent a train lost message for full loading trains */
 
			SET_EXPENSES_TYPE(EXPENSES_TRAIN_INC);
 
			if (LoadUnloadVehicle(v, false)) {
 
				InvalidateWindow(WC_TRAINS_LIST, v->owner);
 
				MarkTrainDirty(v);
 

	
 
				// need to update acceleration and cached values since the goods on the train changed.
 
				TrainCargoChanged(v);
 
				UpdateTrainAcceleration(v);
 
	switch (v->current_order.type) {
 
		case OT_LOADING:
 
			if (mode) return;
 

	
 
			// don't mark the train as lost if we're loading on the final station.
 
			if (v->current_order.flags & OF_NON_STOP) {
 
				v->u.rail.days_since_order_progr = 0;
 
			}
 
			return;
 
		}
 

	
 
		TrainPlayLeaveStationSound(v);
 

	
 
		{
 

	
 
			if (--v->load_unload_time_rem) return;
 

	
 
			if (CanFillVehicle(v) && (
 
						v->current_order.flags & OF_FULL_LOAD ||
 
						(_patches.gradual_loading && !HASBIT(v->load_status, LS_LOADING_FINISHED))
 
					)) {
 
				v->u.rail.days_since_order_progr = 0; /* Prevent a train lost message for full loading trains */
 
				SET_EXPENSES_TYPE(EXPENSES_TRAIN_INC);
 
				if (LoadUnloadVehicle(v, false)) {
 
					InvalidateWindow(WC_TRAINS_LIST, v->owner);
 
					MarkTrainDirty(v);
 

	
 
					// need to update acceleration and cached values since the goods on the train changed.
 
					TrainCargoChanged(v);
 
					UpdateTrainAcceleration(v);
 
				}
 
				return;
 
			}
 

	
 
			TrainPlayLeaveStationSound(v);
 

	
 
			Order b = v->current_order;
 
			v->LeaveStation();
 

	
 
			// If this was not the final order, don't remove it from the list.
 
			if (!(b.flags & OF_NON_STOP)) return;
 
		}
 
			break;
 

	
 
		case OT_DUMMY: break;
 

	
 
		default: return;
 
	}
 

	
 
	v->u.rail.days_since_order_progr = 0;
 
	v->cur_order_index++;
 
	InvalidateVehicleOrder(v);
 
}
 

	
 
static int UpdateTrainSpeed(Vehicle *v)
 
{
 
	uint spd;
 
	uint accel;
 

	
0 comments (0 inline, 0 general)