diff options
author | smatz <smatz@openttd.org> | 2009-05-22 13:53:14 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2009-05-22 13:53:14 +0000 |
commit | b687ac51ee5e8628ed56319df573c903c0c86ef3 (patch) | |
tree | 26a2219b3bac39dd367deb2de9fcbac64570a93d /src/aircraft_cmd.cpp | |
parent | 561d97880d3c2be7d8160f67d18d3e3b85c284e6 (diff) | |
download | openttd-b687ac51ee5e8628ed56319df573c903c0c86ef3.tar.xz |
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
Diffstat (limited to 'src/aircraft_cmd.cpp')
-rw-r--r-- | src/aircraft_cmd.cpp | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index d3314d34f..25ba931b0 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -1137,7 +1137,7 @@ static bool AircraftController(Vehicle *v) } -static void HandleCrashedAircraft(Vehicle *v) +static bool HandleCrashedAircraft(Vehicle *v) { v->u.air.crashed_counter += 3; @@ -1182,7 +1182,11 @@ static void HandleCrashedAircraft(Vehicle *v) } delete v; + + return false; } + + return true; } static void HandleBrokenAircraft(Vehicle *v) @@ -1988,16 +1992,15 @@ static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *apc) return false; // it shouldn't get here anytime, but just to be sure } -static void AircraftEventHandler(Vehicle *v, int loop) +static bool AircraftEventHandler(Vehicle *v, int loop) { v->tick_counter++; if (v->vehstatus & VS_CRASHED) { - HandleCrashedAircraft(v); - return; + return HandleCrashedAircraft(v); } - if (v->vehstatus & VS_STOPPED) return; + if (v->vehstatus & VS_STOPPED) return true; /* aircraft is broken down? */ if (v->breakdown_ctr != 0) { @@ -2012,14 +2015,16 @@ static void AircraftEventHandler(Vehicle *v, int loop) ProcessOrders(v); v->HandleLoading(loop != 0); - if (v->current_order.IsType(OT_LOADING) || v->current_order.IsType(OT_LEAVESTATION)) return; + if (v->current_order.IsType(OT_LOADING) || v->current_order.IsType(OT_LEAVESTATION)) return true; AirportGoToNextPosition(v); + + return true; } -void Aircraft::Tick() +bool Aircraft::Tick() { - if (!IsNormalAircraft(this)) return; + if (!IsNormalAircraft(this)) return true; if (!(this->vehstatus & VS_STOPPED)) this->running_ticks++; @@ -2030,10 +2035,13 @@ void Aircraft::Tick() this->current_order_time++; for (uint i = 0; i != 2; i++) { - AircraftEventHandler(this, i); - if (this->type != VEH_AIRCRAFT) // In case it was deleted - break; + /* stop if the aircraft was deleted */ + if (!AircraftEventHandler(this, i)) return false; + assert(this->IsValid()); + assert(IsNormalAircraft(this)); } + + return true; } |