Import Improved Breakdowns patch
Fix trailing whitespace http://www.tt-forums.net/viewtopic.php?p=1146419#p1146419
This commit is contained in:

committed by
Jonathan G Rennison

parent
c8a727d3fc
commit
9f5164b403
@@ -130,6 +130,11 @@ static StationID FindNearestHangar(const Aircraft *v)
|
||||
|
||||
const AirportFTAClass *afc = st->airport.GetFTA();
|
||||
if (!st->airport.HasHangar() || (
|
||||
/* the airport needs to have facilities for this plane type */
|
||||
(AircraftVehInfo(v->engine_type)->subtype & AIR_CTOL) ?
|
||||
!(afc->flags & AirportFTAClass::AIRPLANES) :
|
||||
!(afc->flags & AirportFTAClass::HELICOPTERS)
|
||||
) || (
|
||||
/* don't crash the plane if we know it can't land at the airport */
|
||||
(afc->flags & AirportFTAClass::SHORT_STRIP) &&
|
||||
(avi->subtype & AIR_FAST) &&
|
||||
@@ -301,6 +306,9 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *
|
||||
|
||||
v->reliability = e->reliability;
|
||||
v->reliability_spd_dec = e->reliability_spd_dec;
|
||||
/* higher speed means higher breakdown chance */
|
||||
/* to somewhat compensate for the fact that fast aircraft spend less time in the air */
|
||||
v->breakdown_chance = Clamp(64 + (AircraftVehInfo(v->engine_type)->max_speed >> 3), 0, 255);
|
||||
v->max_age = e->GetLifeLengthInDays();
|
||||
|
||||
_new_vehicle_id = v->index;
|
||||
@@ -642,7 +650,7 @@ static int UpdateAircraftSpeed(Aircraft *v, uint speed_limit = SPEED_LIMIT_NONE,
|
||||
spd = min(v->cur_speed + (spd >> 8) + (v->subspeed < t), speed_limit);
|
||||
|
||||
/* adjust speed for broken vehicles */
|
||||
if (v->vehstatus & VS_AIRCRAFT_BROKEN) spd = min(spd, SPEED_LIMIT_BROKEN);
|
||||
if (v->breakdown_ctr == 1 && v->breakdown_type == BREAKDOWN_AIRCRAFT_SPEED) spd = min(v->breakdown_severity << 3, spd);
|
||||
|
||||
/* updates statusbar only if speed have changed to save CPU time */
|
||||
if (spd != v->cur_speed) {
|
||||
@@ -1094,6 +1102,39 @@ static bool AircraftController(Aircraft *v)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a broken plane that needs to visit a depot to the correct location.
|
||||
* @param v The airplane in question
|
||||
*/
|
||||
void FindBreakdownDestination(Aircraft *v)
|
||||
{
|
||||
assert(v->type == VEH_AIRCRAFT && v->breakdown_ctr == 1);
|
||||
|
||||
DestinationID destination = INVALID_STATION;
|
||||
if (v->breakdown_type == BREAKDOWN_AIRCRAFT_DEPOT) {
|
||||
/* Go to a hangar, if possible at our current destination */
|
||||
v->FindClosestDepot(NULL, &destination, NULL);
|
||||
} else if (v->breakdown_type == BREAKDOWN_AIRCRAFT_EM_LANDING) {
|
||||
/* Go to the nearest airport with a hangar */
|
||||
destination = FindNearestHangar(v);
|
||||
} else {
|
||||
NOT_REACHED();
|
||||
}
|
||||
|
||||
if(destination != INVALID_STATION) {
|
||||
if(destination != v->current_order.GetDestination()) {
|
||||
v->current_order.MakeGoToDepot(destination, ODTFB_BREAKDOWN);
|
||||
AircraftNextAirportPos_and_Order(v);
|
||||
} else {
|
||||
v->current_order.MakeGoToDepot(destination, ODTFB_BREAKDOWN);
|
||||
}
|
||||
} else {
|
||||
/* If no hangar was found, crash */
|
||||
v->targetairport = INVALID_STATION;
|
||||
CrashAirplane(v);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle crashed aircraft \a v.
|
||||
* @param v Crashed aircraft.
|
||||
@@ -1174,8 +1215,9 @@ static void HandleAircraftSmoke(Aircraft *v, bool mode)
|
||||
|
||||
if (!(v->vehstatus & VS_AIRCRAFT_BROKEN)) return;
|
||||
|
||||
/* breakdown-related speed limits are lifted when we are on the ground */
|
||||
if(v->state != FLYING && v->state != LANDING && v->breakdown_type == BREAKDOWN_AIRCRAFT_SPEED) {
|
||||
/* Stop smoking when landed */
|
||||
if (v->cur_speed < 10) {
|
||||
v->vehstatus &= ~VS_AIRCRAFT_BROKEN;
|
||||
v->breakdown_ctr = 0;
|
||||
return;
|
||||
@@ -1291,13 +1333,18 @@ static void MaybeCrashAirplane(Aircraft *v)
|
||||
Station *st = Station::Get(v->targetairport);
|
||||
|
||||
/* FIXME -- MaybeCrashAirplane -> increase crashing chances of very modern airplanes on smaller than AT_METROPOLITAN airports */
|
||||
uint32 prob = (0x4000 << _settings_game.vehicle.plane_crashes);
|
||||
uint32 prob = (_settings_game.vehicle.improved_breakdowns && _settings_game.difficulty.vehicle_breakdowns) ?
|
||||
0x10000 / 10000 : 0x4000 << _settings_game.vehicle.plane_crashes;
|
||||
|
||||
if ((st->airport.GetFTA()->flags & AirportFTAClass::SHORT_STRIP) &&
|
||||
(AircraftVehInfo(v->engine_type)->subtype & AIR_FAST) &&
|
||||
!_cheats.no_jetcrash.value) {
|
||||
prob /= 20;
|
||||
} else {
|
||||
} else if (!_settings_game.vehicle.improved_breakdowns) {
|
||||
prob /= 1500;
|
||||
} else if (v->breakdown_ctr == 1 && v->breakdown_type == BREAKDOWN_AIRCRAFT_EM_LANDING) {
|
||||
/* Airplanes that are attempting an emergency landing have a 2% chance to crash */
|
||||
prob = 0x10000 / 50;
|
||||
}
|
||||
|
||||
if (GB(Random(), 0, 22) > prob) return;
|
||||
|
Reference in New Issue
Block a user