1
0
Fork 0

(svn r8430) -Fix

Replace the rather obscure control flow for handling aircraft/ship/train orders by something remotly comprehensible (see r3584)
release/0.6
tron 2007-01-27 16:45:16 +00:00
parent 08c21c0c61
commit 430e64c848
3 changed files with 70 additions and 59 deletions

View File

@ -1257,31 +1257,35 @@ static void MarkAircraftDirty(Vehicle *v)
static void HandleAircraftLoading(Vehicle *v, int mode) static void HandleAircraftLoading(Vehicle *v, int mode)
{ {
if (v->current_order.type == OT_NOTHING) return; switch (v->current_order.type) {
case OT_LOADING:
if (mode != 0) return;
if (--v->load_unload_time_rem != 0) return;
if (v->current_order.type != OT_DUMMY) { if (CanFillVehicle(v) && (
if (v->current_order.type != OT_LOADING) return; v->current_order.flags & OF_FULL_LOAD ||
if (mode != 0) return; (_patches.gradual_loading && !HASBIT(v->load_status, LS_LOADING_FINISHED))
if (--v->load_unload_time_rem != 0) return; )) {
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC);
if (CanFillVehicle(v) && (v->current_order.flags & OF_FULL_LOAD || if (LoadUnloadVehicle(v, false)) {
(_patches.gradual_loading && !HASBIT(v->load_status, LS_LOADING_FINISHED)))) { InvalidateWindow(WC_AIRCRAFT_LIST, v->owner);
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC); MarkAircraftDirty(v);
if (LoadUnloadVehicle(v, false)) { }
InvalidateWindow(WC_AIRCRAFT_LIST, v->owner); return;
MarkAircraftDirty(v);
} }
return;
}
{
Order b = v->current_order; Order b = v->current_order;
v->current_order.type = OT_NOTHING; v->current_order.type = OT_NOTHING;
v->current_order.flags = 0; v->current_order.flags = 0;
MarkAircraftDirty(v); MarkAircraftDirty(v);
if (!(b.flags & OF_NON_STOP)) return; if (!(b.flags & OF_NON_STOP)) return;
} break;
case OT_DUMMY: break;
default: return;
} }
v->cur_order_index++; v->cur_order_index++;
InvalidateVehicleOrder(v); InvalidateVehicleOrder(v);
} }

View File

@ -273,28 +273,31 @@ static void ProcessShipOrder(Vehicle *v)
static void HandleShipLoading(Vehicle *v) static void HandleShipLoading(Vehicle *v)
{ {
if (v->current_order.type == OT_NOTHING) return; switch (v->current_order.type) {
case OT_LOADING:
if (--v->load_unload_time_rem) return;
if (v->current_order.type != OT_DUMMY) { if (CanFillVehicle(v) && (
if (v->current_order.type != OT_LOADING) return; v->current_order.flags & OF_FULL_LOAD ||
if (--v->load_unload_time_rem) return; (_patches.gradual_loading && !HASBIT(v->load_status, LS_LOADING_FINISHED))
)) {
if (CanFillVehicle(v) && (v->current_order.flags & OF_FULL_LOAD || SET_EXPENSES_TYPE(EXPENSES_SHIP_INC);
(_patches.gradual_loading && !HASBIT(v->load_status, LS_LOADING_FINISHED)))) { if (LoadUnloadVehicle(v, false)) {
SET_EXPENSES_TYPE(EXPENSES_SHIP_INC); InvalidateWindow(WC_SHIPS_LIST, v->owner);
if (LoadUnloadVehicle(v, false)) { MarkShipDirty(v);
InvalidateWindow(WC_SHIPS_LIST, v->owner); }
MarkShipDirty(v); return;
} }
return; PlayShipSound(v);
}
PlayShipSound(v);
{
Order b = v->current_order; Order b = v->current_order;
v->LeaveStation(); v->LeaveStation();
if (!(b.flags & OF_NON_STOP)) return; if (!(b.flags & OF_NON_STOP)) return;
} break;
case OT_DUMMY: break;
default: return;
} }
v->cur_order_index++; v->cur_order_index++;

View File

@ -2605,42 +2605,46 @@ static void MarkTrainDirty(Vehicle *v)
static void HandleTrainLoading(Vehicle *v, bool mode) static void HandleTrainLoading(Vehicle *v, bool mode)
{ {
if (v->current_order.type == OT_NOTHING) return; switch (v->current_order.type) {
case OT_LOADING:
if (mode) return;
if (v->current_order.type != OT_DUMMY) { // don't mark the train as lost if we're loading on the final station.
if (v->current_order.type != OT_LOADING) return; if (v->current_order.flags & OF_NON_STOP) {
if (mode) return; v->u.rail.days_since_order_progr = 0;
// don't mark the train as lost if we're loading on the final station.
if (v->current_order.flags & OF_NON_STOP)
v->u.rail.days_since_order_progr = 0;
if (--v->load_unload_time_rem) return;
if (CanFillVehicle(v) && (v->current_order.flags & OF_FULL_LOAD ||
(_patches.gradual_loading && !HASBIT(v->load_status, LS_LOADING_FINISHED)))) {
v->u.rail.days_since_order_progr = 0; /* Prevent a train lost message for full loading trains */
SET_EXPENSES_TYPE(EXPENSES_TRAIN_INC);
if (LoadUnloadVehicle(v, false)) {
InvalidateWindow(WC_TRAINS_LIST, v->owner);
MarkTrainDirty(v);
// need to update acceleration and cached values since the goods on the train changed.
TrainCargoChanged(v);
UpdateTrainAcceleration(v);
} }
return;
}
TrainPlayLeaveStationSound(v); if (--v->load_unload_time_rem) return;
if (CanFillVehicle(v) && (
v->current_order.flags & OF_FULL_LOAD ||
(_patches.gradual_loading && !HASBIT(v->load_status, LS_LOADING_FINISHED))
)) {
v->u.rail.days_since_order_progr = 0; /* Prevent a train lost message for full loading trains */
SET_EXPENSES_TYPE(EXPENSES_TRAIN_INC);
if (LoadUnloadVehicle(v, false)) {
InvalidateWindow(WC_TRAINS_LIST, v->owner);
MarkTrainDirty(v);
// need to update acceleration and cached values since the goods on the train changed.
TrainCargoChanged(v);
UpdateTrainAcceleration(v);
}
return;
}
TrainPlayLeaveStationSound(v);
{
Order b = v->current_order; Order b = v->current_order;
v->LeaveStation(); v->LeaveStation();
// If this was not the final order, don't remove it from the list. // If this was not the final order, don't remove it from the list.
if (!(b.flags & OF_NON_STOP)) return; if (!(b.flags & OF_NON_STOP)) return;
} break;
case OT_DUMMY: break;
default: return;
} }
v->u.rail.days_since_order_progr = 0; v->u.rail.days_since_order_progr = 0;