Changeset - r15947:6f1c6a44a807
[Not reviewed]
master
0 6 0
rubidium - 14 years ago 2010-08-28 14:14:37
rubidium@openttd.org
(svn r20645) -Codechange [FS#4086]: unify the code for checking for breakdown handling as well (Hirundo)
6 files changed with 17 insertions and 34 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -1772,20 +1772,13 @@ static bool AircraftEventHandler(Aircraf
 
	if (v->vehstatus & VS_CRASHED) {
 
		return HandleCrashedAircraft(v);
 
	}
 

	
 
	if (v->vehstatus & VS_STOPPED) return true;
 

	
 
	/* aircraft is broken down? */
 
	if (v->breakdown_ctr != 0) {
 
		if (v->breakdown_ctr <= 2) {
 
			v->HandleBreakdown();
 
		} else {
 
			if (!v->current_order.IsType(OT_LOADING)) v->breakdown_ctr--;
 
		}
 
	}
 
	v->HandleBreakdown();
 

	
 
	HandleAircraftSmoke(v);
 
	ProcessOrders(v);
 
	v->HandleLoading(loop != 0);
 

	
 
	if (v->current_order.IsType(OT_LOADING) || v->current_order.IsType(OT_LEAVESTATION)) return true;
src/roadveh_cmd.cpp
Show inline comments
 
@@ -1482,20 +1482,13 @@ static bool RoadVehController(RoadVehicl
 
	/* handle crashed */
 
	if (v->vehstatus & VS_CRASHED || RoadVehCheckTrainCrash(v)) {
 
		return RoadVehIsCrashed(v);
 
	}
 

	
 
	/* road vehicle has broken down? */
 
	if (v->breakdown_ctr != 0) {
 
		if (v->breakdown_ctr <= 2) {
 
			v->HandleBreakdown();
 
			return true;
 
		}
 
		if (!v->current_order.IsType(OT_LOADING)) v->breakdown_ctr--;
 
	}
 

	
 
	if (v->HandleBreakdown()) return true;
 
	if (v->vehstatus & VS_STOPPED) return true;
 

	
 
	ProcessOrders(v);
 
	v->HandleLoading();
 

	
 
	if (v->current_order.IsType(OT_LOADING)) return true;
src/ship_cmd.cpp
Show inline comments
 
@@ -421,19 +421,13 @@ static void ShipController(Ship *v)
 
	Track track;
 
	TrackBits tracks;
 

	
 
	v->tick_counter++;
 
	v->current_order_time++;
 

	
 
	if (v->breakdown_ctr != 0) {
 
		if (v->breakdown_ctr <= 2) {
 
			v->HandleBreakdown();
 
			return;
 
		}
 
		if (!v->current_order.IsType(OT_LOADING)) v->breakdown_ctr--;
 
	}
 
	if (v->HandleBreakdown()) return;
 

	
 
	if (v->vehstatus & VS_STOPPED) return;
 

	
 
	ProcessOrders(v);
 
	v->HandleLoading();
 

	
src/train_cmd.cpp
Show inline comments
 
@@ -3713,19 +3713,13 @@ static bool TrainLocoHandler(Train *v, b
 
	if (v->force_proceed != TFP_NONE) {
 
		ClrBit(v->flags, VRF_TRAIN_STUCK);
 
		SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
	}
 

	
 
	/* train is broken down? */
 
	if (v->breakdown_ctr != 0) {
 
		if (v->breakdown_ctr <= 2) {
 
			v->HandleBreakdown();
 
			return true;
 
		}
 
		if (!v->current_order.IsType(OT_LOADING)) v->breakdown_ctr--;
 
	}
 
	if (v->HandleBreakdown()) return true;
 

	
 
	if (HasBit(v->flags, VRF_REVERSING) && v->cur_speed == 0) {
 
		ReverseTrainDirection(v);
 
	}
 

	
 
	/* exit if train is stopped */
src/vehicle.cpp
Show inline comments
 
@@ -983,19 +983,24 @@ void CheckVehicleBreakdown(Vehicle *v)
 
		v->breakdown_ctr    = GB(r, 16, 6) + 0x3F;
 
		v->breakdown_delay  = GB(r, 24, 7) + 0x80;
 
		v->breakdown_chance = 0;
 
	}
 
}
 

	
 
void Vehicle::HandleBreakdown()
 
bool Vehicle::HandleBreakdown()
 
{
 
	/* Possible states for Vehicle::breakdown_ctr
 
	 * 0  - vehicle is running normally
 
	 * 1  - vehicle is currently broken down
 
	 * 2  - vehicle is going to break down now
 
	 * >2 - vehicle is counting down to the actual breakdown event */
 
	if (this->breakdown_ctr == 0) return false;
 
	if (this->breakdown_ctr > 2) {
 
		if (!this->current_order.IsType(OT_LOADING)) this->breakdown_ctr--;
 
		return false;
 
	}
 
	if (this->breakdown_ctr != 1) {
 
		this->breakdown_ctr = 1;
 

	
 
		if (this->breakdowns_since_last_service != 255) {
 
			this->breakdowns_since_last_service++;
 
		}
 
@@ -1021,22 +1026,23 @@ void Vehicle::HandleBreakdown()
 
				if (u != NULL) u->animation_state = this->breakdown_delay * 2;
 
			}
 
		}
 
	}
 

	
 
	/* Aircraft breakdowns end only when arriving at the airport */
 
	if (this->type == VEH_AIRCRAFT) return;
 
	if (this->type == VEH_AIRCRAFT) return false;
 

	
 
	/* For trains this function is called twice per tick, so decrease v->breakdown_delay at half the rate */
 
	if ((this->tick_counter & (this->type == VEH_TRAIN ? 3 : 1)) == 0) {
 
		if (--this->breakdown_delay == 0) {
 
			this->breakdown_ctr = 0;
 
			this->MarkDirty();
 
			SetWindowDirty(WC_VEHICLE_VIEW, this->index);
 
		}
 
	}
 
	return true;
 
}
 

	
 
void AgeVehicle(Vehicle *v)
 
{
 
	if (v->age < MAX_DAY) v->age++;
 

	
src/vehicle_base.h
Show inline comments
 
@@ -520,17 +520,20 @@ public:
 
		if (HasBit(src->vehicle_flags, VF_AUTOFILL_TIMETABLE)) SetBit(this->vehicle_flags, VF_AUTOFILL_TIMETABLE);
 
		if (HasBit(src->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME)) SetBit(this->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
 

	
 
		this->service_interval = src->service_interval;
 
	}
 

	
 

	
 
	/**
 
	 * Handle all of the aspects of a vehicle breakdown.
 
	 * Handle all of the aspects of a vehicle breakdown
 
	 * This includes adding smoke and sounds, and ending the breakdown when appropriate.
 
	 * @return true iff the vehicle is stopped because of a breakdown
 
	 * @note This function always returns false for aircraft, since these never stop for breakdowns
 
	 */
 
	void HandleBreakdown();
 
	bool HandleBreakdown();
 

	
 
	bool NeedsAutorenewing(const Company *c) const;
 

	
 
	/**
 
	 * Check if the vehicle needs to go to a depot in near future (if a opportunity presents itself) for service or replacement.
 
	 *
0 comments (0 inline, 0 general)