Changeset - r14001:7218fa375880
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2009-12-19 22:04:02
rubidium@openttd.org
(svn r18553) -Fix: make aircraft behave the same on autoreplace/autorenew as other vehicles
1 file changed with 2 insertions and 42 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -1371,52 +1371,12 @@ void AircraftLeaveHangar(Aircraft *v)
 
	VehicleServiceInDepot(v);
 
	SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos);
 
	InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
 
	SetWindowClassesDirty(WC_AIRCRAFT_LIST);
 
}
 

	
 
/** Checks if an aircraft should head towards a hangar because it needs replacement
 
 * @param *v the vehicle to test
 
 * @return true if the aircraft should head towards a hangar
 
 */
 
static inline bool CheckSendAircraftToHangarForReplacement(const Vehicle *v)
 
{
 
	EngineID new_engine;
 
	Company *c = Company::Get(v->owner);
 

	
 
	if (VehicleHasDepotOrders(v)) return false; // The aircraft will end up in the hangar eventually on it's own
 

	
 
	new_engine = EngineReplacementForCompany(c, v->engine_type, v->group_id);
 

	
 
	if (new_engine == INVALID_ENGINE) {
 
		/* There is no autoreplace assigned to this EngineID so we will set it to renew to the same type if needed */
 
		new_engine = v->engine_type;
 

	
 
		if (!v->NeedsAutorenewing(c)) {
 
			/* No need to replace the aircraft */
 
			return false;
 
		}
 
	}
 

	
 
	if (!HasBit(Engine::Get(new_engine)->company_avail, v->owner)) {
 
		/* Engine is not buildable anymore */
 
		return false;
 
	}
 

	
 
	if (c->money < (c->settings.engine_renew_money + (2 * DoCommand(0, new_engine, 0, DC_QUERY_COST, CMD_BUILD_AIRCRAFT).GetCost()))) {
 
		/* We lack enough money to request the replacement right away.
 
		 * We want 2*(the price of the new vehicle) and not looking at the value of the vehicle we are going to sell.
 
		 * The reason is that we don't want to send a whole lot of vehicles to the hangars when we only have enough money to replace a single one.
 
		 * Remember this happens in the background so the user can't stop this. */
 
		return false;
 
	}
 

	
 
	/* We found no reason NOT to send the aircraft to a hangar so we will send it there at once */
 
	return true;
 
}
 

	
 
////////////////////////////////////////////////////////////////////////////////
 
///////////////////   AIRCRAFT MOVEMENT SCHEME  ////////////////////////////////
 
////////////////////////////////////////////////////////////////////////////////
 
static void AircraftEventHandler_EnterTerminal(Aircraft *v, const AirportFTAClass *apc)
 
{
 
	AircraftEntersTerminal(v);
 
@@ -1552,13 +1512,13 @@ static void AircraftEventHandler_HeliTak
 
	v->UpdateDeltaXY(INVALID_DIR);
 

	
 
	/* get the next position to go to, differs per airport */
 
	AircraftNextAirportPos_and_Order(v);
 

	
 
	/* Send the helicopter to a hangar if needed for replacement */
 
	if (CheckSendAircraftToHangarForReplacement(v)) {
 
	if (v->NeedsAutomaticServicing()) {
 
		_current_company = v->owner;
 
		DoCommand(v->tile, v->index, DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
 
		_current_company = OWNER_NONE;
 
	}
 
}
 

	
 
@@ -1604,13 +1564,13 @@ static void AircraftEventHandler_Flying(
 
static void AircraftEventHandler_Landing(Aircraft *v, const AirportFTAClass *apc)
 
{
 
	v->state = ENDLANDING;
 
	AircraftLandAirplane(v);  // maybe crash airplane
 

	
 
	/* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */
 
	if (CheckSendAircraftToHangarForReplacement(v)) {
 
	if (v->NeedsAutomaticServicing()) {
 
		_current_company = v->owner;
 
		DoCommand(v->tile, v->index, DEPOT_SERVICE, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
 
		_current_company = OWNER_NONE;
 
	}
 
}
 

	
0 comments (0 inline, 0 general)