Changeset - r19754:0cf8a16cae90
[Not reviewed]
master
0 1 0
frosch - 12 years ago 2012-11-12 18:11:46
frosch@openttd.org
(svn r24709) -Codechange: Simplify some code.
1 file changed with 5 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/vehicle.cpp
Show inline comments
 
@@ -1183,120 +1183,119 @@ bool Vehicle::HandleBreakdown()
 
			return false;
 
	}
 
}
 

	
 
/**
 
 * Update age of a vehicle.
 
 * @param v Vehicle to update.
 
 */
 
void AgeVehicle(Vehicle *v)
 
{
 
	if (v->age < MAX_DAY) {
 
		v->age++;
 
		if (v->IsPrimaryVehicle() && v->age == VEHICLE_PROFIT_MIN_AGE + 1) GroupStatistics::VehicleReachedProfitAge(v);
 
	}
 

	
 
	if (!v->IsPrimaryVehicle() && (v->type != VEH_TRAIN || !Train::From(v)->IsEngine())) return;
 

	
 
	int age = v->age - v->max_age;
 
	if (age == DAYS_IN_LEAP_YEAR * 0 || age == DAYS_IN_LEAP_YEAR * 1 ||
 
			age == DAYS_IN_LEAP_YEAR * 2 || age == DAYS_IN_LEAP_YEAR * 3 || age == DAYS_IN_LEAP_YEAR * 4) {
 
		v->reliability_spd_dec <<= 1;
 
	}
 

	
 
	SetWindowDirty(WC_VEHICLE_DETAILS, v->index);
 

	
 
	/* Don't warn about non-primary or not ours vehicles or vehicles that are crashed */
 
	if (v->Previous() != NULL || v->owner != _local_company || (v->vehstatus & VS_CRASHED) != 0) return;
 

	
 
	/* Don't warn if a renew is active */
 
	if (Company::Get(v->owner)->settings.engine_renew && v->GetEngine()->company_avail != 0) return;
 

	
 
	StringID str;
 
	if (age == -DAYS_IN_LEAP_YEAR) {
 
		str = STR_NEWS_VEHICLE_IS_GETTING_OLD;
 
	} else if (age == 0) {
 
		str = STR_NEWS_VEHICLE_IS_GETTING_VERY_OLD;
 
	} else if (age > 0 && (age % DAYS_IN_LEAP_YEAR) == 0) {
 
		str = STR_NEWS_VEHICLE_IS_GETTING_VERY_OLD_AND;
 
	} else {
 
		return;
 
	}
 

	
 
	SetDParam(0, v->index);
 
	AddVehicleAdviceNewsItem(str, v->index);
 
}
 

	
 
/**
 
 * Calculates how full a vehicle is.
 
 * @param v The Vehicle to check. For trains, use the first engine.
 
 * @param front The front vehicle of the consist to check.
 
 * @param colour The string to show depending on if we are unloading or loading
 
 * @return A percentage of how full the Vehicle is.
 
 */
 
uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *colour)
 
uint8 CalcPercentVehicleFilled(const Vehicle *front, StringID *colour)
 
{
 
	int count = 0;
 
	int max = 0;
 
	int cars = 0;
 
	int unloading = 0;
 
	bool loading = false;
 

	
 
	const Vehicle *u = v;
 
	/* The station may be NULL when the (colour) string does not need to be set. */
 
	const Station *st = Station::GetIfValid(v->last_station_visited);
 
	const Station *st = Station::GetIfValid(front->last_station_visited);
 
	assert(colour == NULL || st != NULL);
 

	
 
	/* Count up max and used */
 
	for (; v != NULL; v = v->Next()) {
 
	for (const Vehicle *v = front; v != NULL; v = v->Next()) {
 
		count += v->cargo.Count();
 
		max += v->cargo_cap;
 
		if (v->cargo_cap != 0 && colour != NULL) {
 
			unloading += HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) ? 1 : 0;
 
			loading |= !(u->current_order.GetLoadType() & OLFB_NO_LOAD) && st->goods[v->cargo_type].days_since_pickup != 255;
 
			loading |= !(front->current_order.GetLoadType() & OLFB_NO_LOAD) && st->goods[v->cargo_type].days_since_pickup != 255;
 
			cars++;
 
		}
 
	}
 

	
 
	if (colour != NULL) {
 
		if (unloading == 0 && loading) {
 
			*colour = STR_PERCENT_UP;
 
		} else if (unloading == 0 && !loading) {
 
			*colour = STR_PERCENT_NONE;
 
		} else if (cars == unloading || !loading) {
 
			*colour = STR_PERCENT_DOWN;
 
		} else {
 
			*colour = STR_PERCENT_UP_DOWN;
 
		}
 
	}
 

	
 
	/* Train without capacity */
 
	if (max == 0) return 100;
 

	
 
	/* Return the percentage */
 
	return (count * 100) / max;
 
}
 

	
 
/**
 
 * Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it, etc.
 
 * @param v Vehicle that entered a depot.
 
 */
 
void VehicleEnterDepot(Vehicle *v)
 
{
 
	/* Always work with the front of the vehicle */
 
	assert(v == v->First());
 

	
 
	switch (v->type) {
 
		case VEH_TRAIN: {
 
			Train *t = Train::From(v);
 
			SetWindowClassesDirty(WC_TRAINS_LIST);
 
			/* Clear path reservation */
 
			SetDepotReservation(t->tile, false);
 
			if (_settings_client.gui.show_track_reservation) MarkTileDirtyByTile(t->tile);
 

	
 
			UpdateSignalsOnSegment(t->tile, INVALID_DIAGDIR, t->owner);
 
			t->wait_counter = 0;
 
			t->force_proceed = TFP_NONE;
 
			ClrBit(t->flags, VRF_TOGGLE_REVERSE);
 
			t->ConsistChanged(true);
 
			break;
 
		}
 

	
0 comments (0 inline, 0 general)