Mercurial > hg > openttd
changeset 899:f8b37d44e4c9 draft
(svn r1385) Fix: [ 1095020 ] When all stations in an aircraft's order list are demolished, the plane eventually crashes (running out of fuel)
author | dominik <dominik@openttd.org> |
---|---|
date | Wed, 05 Jan 2005 13:15:27 +0000 |
parents | 1f00332cda59 |
children | 767fb627c5c7 |
files | aircraft_cmd.c lang/english.txt |
diffstat | 2 files changed, 68 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/aircraft_cmd.c +++ b/aircraft_cmd.c @@ -18,6 +18,7 @@ static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport); static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport); static void AirportGoToNextPosition(Vehicle *v, const AirportFTAClass *Airport); +static void CrashAirplane(Vehicle *v); static void AircraftNextAirportPos_and_Order(Vehicle *v); static byte GetAircraftFlyingAltitude(const Vehicle *v); @@ -920,9 +921,20 @@ { uint32 r; Station *st; + int z; v->u.air.crashed_counter++; + st = DEREF_STATION(v->u.air.targetairport); + + // make aircraft crash down to the ground + if ( st->airport_tile==0 && ((v->u.air.crashed_counter % 3) == 0) ) { + z = GetSlopeZ(v->x_pos, v->y_pos) + 1; + v->z_pos -= 1; + if (v->z_pos < z) + DoDeleteAircraft(v); + } + if (v->u.air.crashed_counter < 650) { if (CHANCE16R(1,32,r)) { v->direction = (v->direction+_crashed_aircraft_moddir[(r >> 16)&3]) & 7; @@ -935,7 +947,6 @@ EV_DEMOLISH); } } else if (v->u.air.crashed_counter >= 10000) { - st = DEREF_STATION(v->u.air.targetairport); // remove rubble of crashed airplane // clear runway-in on all airports, set by crashing plane @@ -989,13 +1000,25 @@ } } +// returns true if the vehicle does have valid orders +// false if none are valid +static bool CheckForValidOrders(Vehicle *v) +{ + int i; + for (i = 0; i < v->num_orders; i++) { + if( v->schedule_ptr[i].type != OT_DUMMY ) + return true; + } + return false; +} + static void ProcessAircraftOrder(Vehicle *v) { Order order; // OT_GOTO_DEPOT, OT_LOADING - if (v->current_order.type >= OT_GOTO_DEPOT && - v->current_order.type <= OT_LOADING) { + if (v->current_order.type == OT_GOTO_DEPOT || + v->current_order.type == OT_LOADING) { if (v->current_order.type != OT_GOTO_DEPOT || !(v->current_order.flags & OF_UNLOAD)) return; @@ -1031,6 +1054,9 @@ v->u.air.targetairport = order.station; } + if ( order.type == OT_DUMMY && !CheckForValidOrders(v)) + CrashAirplane(v); + InvalidateVehicleOrderWidget(v); } @@ -1067,12 +1093,47 @@ InvalidateVehicleOrderWidget(v); } +static void CrashAirplane(Vehicle *v) +{ + uint16 amt; + Station *st; + StringID newsitem; + + v->vehstatus |= VS_CRASHED; + v->u.air.crashed_counter = 0; + + CreateEffectVehicleRel(v, 4, 4, 8, EV_CRASHED_SMOKE); + + InvalidateWindow(WC_VEHICLE_VIEW, v->index); + + amt = 2; + if (v->cargo_type == CT_PASSENGERS) amt += v->cargo_count; + SetDParam(0, amt); + + v->cargo_count = 0; + v->next->cargo_count = 0, + st = DEREF_STATION(v->u.air.targetairport); + if(st->airport_tile==0) { + newsitem = STR_PLANE_CRASH_OUT_OF_FUEL; + } else { + SetDParam(1, st->index); + newsitem = STR_A034_PLANE_CRASH_DIE_IN_FIREBALL; + } + + SetDParam(1, st->index); + AddNewsItem(newsitem, + NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), + v->index, + 0); + + SndPlayVehicleFx(SND_12_EXPLOSION, v); +} + static void MaybeCrashAirplane(Vehicle *v) { Station *st; uint16 prob; int i; - uint16 amt; st = DEREF_STATION(v->u.air.targetairport); @@ -1091,28 +1152,7 @@ st->goods[i].waiting_acceptance &= ~0xFFF; } - v->vehstatus |= VS_CRASHED; - v->u.air.crashed_counter = 0; - - CreateEffectVehicleRel(v, 4, 4, 8, EV_CRASHED_SMOKE); - - InvalidateWindow(WC_VEHICLE_VIEW, v->index); - - amt = 2; - if (v->cargo_type == CT_PASSENGERS) amt += v->cargo_count; - SetDParam(0, amt); - - v->cargo_count = 0; - v->next->cargo_count = 0, - - SetDParam(1, st->index); - AddNewsItem(STR_A034_PLANE_CRASH_DIE_IN_FIREBALL, - NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0), - v->index, - 0); - - ModifyStationRatingAround(TILE_FROM_XY(v->x_pos, v->y_pos), v->owner, -160, 30); - SndPlayVehicleFx(SND_12_EXPLOSION, v); + CrashAirplane(v); } // we've landed and just arrived at a terminal
--- a/lang/english.txt +++ b/lang/english.txt @@ -2665,7 +2665,8 @@ STR_A031_CAN_T_NAME_AIRCRAFT :{WHITE}Can't name aircraft... STR_A032_NAME_AIRCRAFT :{BLACK}Name aircraft STR_A033_CITIZENS_CELEBRATE_FIRST :{BLACK}{BIGFONT}Citizens celebrate . . .{}First aircraft arrives at {STATION}! -STR_A034_PLANE_CRASH_DIE_IN_FIREBALL :{BLACK}{BIGFONT}Plane Crash!{}{COMMA16} die in fireball at {STATION} +STR_A034_PLANE_CRASH_DIE_IN_FIREBALL :{BLACK}{BIGFONT}Plane Crash!{}{COMMA16} die in fireball at {STATION} +STR_PLANE_CRASH_OUT_OF_FUEL :{BLACK}{BIGFONT}Plane Crash!{}Aircraft ran out of fuel, {COMMA16} die in fireball! STR_A035_DESTINATIONS :{TINYFONT}{BLACK}Destinations: STR_A036 :{TINYFONT}{BLACK}{STATION} STR_A037_RENAME :{BLACK}Rename