(svn r12600) -Codechange: make GetNonStopType return a more augmented type; not is there a non-stop order but the kind of non-stop order, so one doesn't need to check _patches.new_nonstop type everywhere.

This commit is contained in:
rubidium 2008-04-07 08:59:04 +00:00
parent 6af1fb2bdd
commit c57a1d74c3
8 changed files with 50 additions and 44 deletions

View File

@ -165,7 +165,7 @@ public:
/** How must the consist be unloaded? */ /** How must the consist be unloaded? */
inline byte GetUnloadType() const { return GB(this->flags, 0, 2); } inline byte GetUnloadType() const { return GB(this->flags, 0, 2); }
/** Where must we stop? */ /** Where must we stop? */
inline byte GetNonStopType() const { return this->flags & OFB_NON_STOP; } OrderNonStopFlags GetNonStopType() const;
/** What caused us going to the depot? */ /** What caused us going to the depot? */
inline byte GetDepotOrderType() const { return this->flags; } inline byte GetDepotOrderType() const { return this->flags; }
/** What are we going to do when in the depot. */ /** What are we going to do when in the depot. */
@ -176,7 +176,7 @@ public:
/** Set how the consist must be unloaded. */ /** Set how the consist must be unloaded. */
inline void SetUnloadType(byte unload_type) { SB(this->flags, 0, 2, unload_type); } inline void SetUnloadType(byte unload_type) { SB(this->flags, 0, 2, unload_type); }
/** Set whether we must stop at stations or not. */ /** Set whether we must stop at stations or not. */
inline void SetNonStopType(byte non_stop_type) { SB(this->flags, 3, 1, !!non_stop_type); } inline void SetNonStopType(OrderNonStopFlags non_stop_type) { SB(this->flags, 3, 1, !!non_stop_type); }
/** Set the cause to go to the depot. */ /** Set the cause to go to the depot. */
inline void SetDepotOrderType(byte depot_order_type) { this->flags = depot_order_type; } inline void SetDepotOrderType(byte depot_order_type) { this->flags = depot_order_type; }
/** Set what we are going to do in the depot. */ /** Set what we are going to do in the depot. */

View File

@ -39,7 +39,16 @@ assert_compile(sizeof(DestinationID) >= sizeof(StationID));
TileIndex _backup_orders_tile; TileIndex _backup_orders_tile;
BackuppedOrders _backup_orders_data; BackuppedOrders _backup_orders_data;
DEFINE_OLD_POOL_GENERIC(Order, Order) DEFINE_OLD_POOL_GENERIC(Order, Order);
OrderNonStopFlags Order::GetNonStopType() const
{
return (this->flags & 0x8) ?
((!_patches.new_nonstop || !this->IsType(OT_GOTO_STATION)) ?
ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS :
ONSF_NO_STOP_AT_DESTINATION_STATION) :
ONSF_STOP_EVERYWHERE;
}
void Order::Free() void Order::Free()
{ {
@ -59,7 +68,12 @@ void Order::MakeGoToStation(StationID destination)
void Order::MakeGoToDepot(DepotID destination, bool order, CargoID cargo, byte subtype) void Order::MakeGoToDepot(DepotID destination, bool order, CargoID cargo, byte subtype)
{ {
this->type = OT_GOTO_DEPOT; this->type = OT_GOTO_DEPOT;
this->flags = order ? OFB_PART_OF_ORDERS : OFB_NON_STOP; this->flags = 0;
if (order) {
this->SetDepotOrderType(OFB_PART_OF_ORDERS);
} else {
this->SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
}
this->dest = destination; this->dest = destination;
this->SetRefit(cargo, subtype); this->SetRefit(cargo, subtype);
} }
@ -303,7 +317,7 @@ CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
default: return CMD_ERROR; default: return CMD_ERROR;
} }
if (new_order.GetNonStopType() != OFB_NO_NON_STOP && v->type != VEH_TRAIN) return CMD_ERROR; if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
/* Order flags can be any of the following for stations: /* Order flags can be any of the following for stations:
* [full-load | unload] [+ transfer] [+ non-stop] * [full-load | unload] [+ transfer] [+ non-stop]
@ -358,7 +372,7 @@ CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
} }
} }
if (new_order.GetNonStopType() != OFB_NO_NON_STOP && v->type != VEH_TRAIN) return CMD_ERROR; if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
/* Order flags can be any of the following for depots: /* Order flags can be any of the following for depots:
* order [+ halt] [+ non-stop] * order [+ halt] [+ non-stop]
@ -385,16 +399,7 @@ CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
/* Order flags can be any of the following for waypoints: /* Order flags can be any of the following for waypoints:
* [non-stop] * [non-stop]
* non-stop orders (if any) are only valid for trains */ * non-stop orders (if any) are only valid for trains */
switch (new_order.GetNonStopType()) { if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
case OFB_NO_NON_STOP: break;
case OFB_NON_STOP:
if (v->type != VEH_TRAIN) return CMD_ERROR;
break;
default: return CMD_ERROR;
}
break;
} }
default: return CMD_ERROR; default: return CMD_ERROR;
@ -588,7 +593,7 @@ CommandCost CmdDeleteOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
/* NON-stop flag is misused to see if a train is in a station that is /* NON-stop flag is misused to see if a train is in a station that is
* on his order list or not */ * on his order list or not */
if (sel_ord == u->cur_order_index && u->current_order.IsType(OT_LOADING)) { if (sel_ord == u->cur_order_index && u->current_order.IsType(OT_LOADING)) {
u->current_order.SetNonStopType(OFB_NO_NON_STOP); u->current_order.SetNonStopType(ONSF_STOP_EVERYWHERE);
} }
/* Update any possible open window of the vehicle */ /* Update any possible open window of the vehicle */
@ -772,7 +777,7 @@ CommandCost CmdModifyOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
order->SetLoadType(0); order->SetLoadType(0);
break; break;
case OF_NON_STOP: case OF_NON_STOP:
order->SetNonStopType(order->GetNonStopType() ^ OFB_NON_STOP); order->SetNonStopType(order->GetNonStopType() == ONSF_STOP_EVERYWHERE ? ONSF_NO_STOP_AT_ANY_STATION : ONSF_STOP_EVERYWHERE);
break; break;
case OF_TRANSFER: case OF_TRANSFER:
order->SetUnloadType(order->GetUnloadType() ^ OFB_TRANSFER); order->SetUnloadType(order->GetUnloadType() ^ OFB_TRANSFER);
@ -1396,9 +1401,8 @@ bool ProcessOrders(Vehicle *v)
v->cur_order_index++; v->cur_order_index++;
} }
/* Check if we've reached a non-stop station while TTDPatch nonstop is enabled.. */ /* Check if we've reached a non-stop station.. */
if (_patches.new_nonstop && if ((v->current_order.GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) &&
v->current_order.GetNonStopType() & OFB_NON_STOP &&
IsTileType(v->tile, MP_STATION) && IsTileType(v->tile, MP_STATION) &&
v->current_order.GetDestination() == GetStationIndex(v->tile)) { v->current_order.GetDestination() == GetStationIndex(v->tile)) {
v->last_station_visited = v->current_order.GetDestination(); v->last_station_visited = v->current_order.GetDestination();
@ -1482,10 +1486,8 @@ bool Order::ShouldStopAtStation(const Vehicle *v, StationID station) const
{ {
return return
v->last_station_visited != station && // Do stop only when we've not just been there v->last_station_visited != station && // Do stop only when we've not just been there
type == OT_GOTO_STATION && // Do stop only when going to a station /* Finally do stop when there is no non-stop flag set for this type of station. */
/* Finally do stop when the non-stop flag is not set, or when we should stop at !(this->GetNonStopType() & ((this->dest == station) ? ONSF_NO_STOP_AT_DESTINATION_STATION : ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS));
* this station according to the new_nonstop setting. */
(!(this->flags & OFB_NON_STOP) || ((this->dest != station) == _patches.new_nonstop));
} }
void InitializeOrders() void InitializeOrders()

View File

@ -215,7 +215,7 @@ static void DrawOrdersWindow(Window *w)
SetDParam(2, GetDepot(order->GetDestination())->town_index); SetDParam(2, GetDepot(order->GetDestination())->town_index);
switch (v->type) { switch (v->type) {
case VEH_TRAIN: s = (order->GetNonStopType() & OFB_NON_STOP) ? STR_880F_GO_NON_STOP_TO_TRAIN_DEPOT : STR_GO_TO_TRAIN_DEPOT; break; case VEH_TRAIN: s = (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_880F_GO_NON_STOP_TO_TRAIN_DEPOT : STR_GO_TO_TRAIN_DEPOT; break;
case VEH_ROAD: s = STR_GO_TO_ROADVEH_DEPOT; break; case VEH_ROAD: s = STR_GO_TO_ROADVEH_DEPOT; break;
case VEH_SHIP: s = STR_GO_TO_SHIP_DEPOT; break; case VEH_SHIP: s = STR_GO_TO_SHIP_DEPOT; break;
default: break; default: break;
@ -235,7 +235,7 @@ static void DrawOrdersWindow(Window *w)
} }
case OT_GOTO_WAYPOINT: case OT_GOTO_WAYPOINT:
SetDParam(1, (order->GetNonStopType() & OFB_NON_STOP) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT); SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT);
SetDParam(2, order->GetDestination()); SetDParam(2, order->GetDestination());
break; break;

View File

@ -59,12 +59,16 @@ enum OrderFlagMasks {
OFB_HALT_IN_DEPOT = 0x4, OFB_HALT_IN_DEPOT = 0x4,
/** if OFB_PART_OF_ORDERS is set, this will cause the order only be come active if the vehicle needs servicing */ /** if OFB_PART_OF_ORDERS is set, this will cause the order only be come active if the vehicle needs servicing */
OFB_SERVICE_IF_NEEDED = 0x4, //used when OFB_PART_OF_ORDERS is set. OFB_SERVICE_IF_NEEDED = 0x4, //used when OFB_PART_OF_ORDERS is set.
};
//Common flags /**
/** This causes the vehicle not to stop at intermediate OR the destination station (depending on patch settings) * Non-stop order flags.
* @todo make this two different flags */ */
OFB_NO_NON_STOP = 0x0, enum OrderNonStopFlags {
OFB_NON_STOP = 0x8 ONSF_STOP_EVERYWHERE = 0,
ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS = 1,
ONSF_NO_STOP_AT_DESTINATION_STATION = 2,
ONSF_NO_STOP_AT_ANY_STATION = 3
}; };
/** Order flags bits - these are for the *BIT macros /** Order flags bits - these are for the *BIT macros

View File

@ -1929,7 +1929,7 @@ static void CheckIfRoadVehNeedsService(Vehicle *v)
} }
if (v->current_order.IsType(OT_GOTO_DEPOT) && if (v->current_order.IsType(OT_GOTO_DEPOT) &&
v->current_order.GetNonStopType() & OFB_NON_STOP && v->current_order.GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS &&
!Chance16(1, 20)) { !Chance16(1, 20)) {
return; return;
} }

View File

@ -70,7 +70,7 @@ CommandCost CmdChangeTimetable(TileIndex tile, uint32 flags, uint32 p1, uint32 p
bool is_journey = HasBit(p1, 24) || packed_time; bool is_journey = HasBit(p1, 24) || packed_time;
if (!is_journey) { if (!is_journey) {
if (!order->IsType(OT_GOTO_STATION)) return_cmd_error(STR_TIMETABLE_ONLY_WAIT_AT_STATIONS); if (!order->IsType(OT_GOTO_STATION)) return_cmd_error(STR_TIMETABLE_ONLY_WAIT_AT_STATIONS);
if (_patches.new_nonstop && (order->GetNonStopType() & OFB_NON_STOP)) return_cmd_error(STR_TIMETABLE_NOT_STOPPING_HERE); if (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) return_cmd_error(STR_TIMETABLE_NOT_STOPPING_HERE);
} }
if (flags & DC_EXEC) { if (flags & DC_EXEC) {

View File

@ -79,7 +79,7 @@ static void DrawTimetableWindow(Window *w)
w->EnableWidget(TTV_CLEAR_TIME); w->EnableWidget(TTV_CLEAR_TIME);
} else { } else {
const Order *order = GetVehicleOrder(v, (selected + 1) / 2); const Order *order = GetVehicleOrder(v, (selected + 1) / 2);
bool disable = order == NULL || !order->IsType(OT_GOTO_STATION) || (_patches.new_nonstop && (order->GetNonStopType() & OFB_NON_STOP)); bool disable = order == NULL || !order->IsType(OT_GOTO_STATION) || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION);
w->SetWidgetDisabledState(TTV_CHANGE_TIME, disable); w->SetWidgetDisabledState(TTV_CHANGE_TIME, disable);
w->SetWidgetDisabledState(TTV_CLEAR_TIME, disable); w->SetWidgetDisabledState(TTV_CLEAR_TIME, disable);
@ -119,7 +119,7 @@ static void DrawTimetableWindow(Window *w)
break; break;
case OT_GOTO_STATION: case OT_GOTO_STATION:
SetDParam(0, (order->GetNonStopType() & OFB_NON_STOP) ? STR_880A_GO_NON_STOP_TO : STR_8806_GO_TO); SetDParam(0, (order->GetNonStopType() != ONSF_STOP_EVERYWHERE) ? STR_880A_GO_NON_STOP_TO : STR_8806_GO_TO);
SetDParam(1, order->GetDestination()); SetDParam(1, order->GetDestination());
if (order->wait_time > 0) { if (order->wait_time > 0) {
@ -139,7 +139,7 @@ static void DrawTimetableWindow(Window *w)
SetDParam(1, GetDepot(order->GetDestination())->town_index); SetDParam(1, GetDepot(order->GetDestination())->town_index);
switch (v->type) { switch (v->type) {
case VEH_TRAIN: string = (order->GetNonStopType() & OFB_NON_STOP) ? STR_880F_GO_NON_STOP_TO_TRAIN_DEPOT : STR_GO_TO_TRAIN_DEPOT; break; case VEH_TRAIN: string = (order->GetNonStopType() != ONSF_STOP_EVERYWHERE) ? STR_880F_GO_NON_STOP_TO_TRAIN_DEPOT : STR_GO_TO_TRAIN_DEPOT; break;
case VEH_ROAD: string = STR_GO_TO_ROADVEH_DEPOT; break; case VEH_ROAD: string = STR_GO_TO_ROADVEH_DEPOT; break;
case VEH_SHIP: string = STR_GO_TO_SHIP_DEPOT; break; case VEH_SHIP: string = STR_GO_TO_SHIP_DEPOT; break;
default: break; default: break;
@ -152,7 +152,7 @@ static void DrawTimetableWindow(Window *w)
} break; } break;
case OT_GOTO_WAYPOINT: case OT_GOTO_WAYPOINT:
SetDParam(0, (order->GetNonStopType() & OFB_NON_STOP) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT); SetDParam(0, (order->GetNonStopType() != ONSF_STOP_EVERYWHERE) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT);
SetDParam(1, order->GetDestination()); SetDParam(1, order->GetDestination());
break; break;
@ -197,7 +197,7 @@ static void DrawTimetableWindow(Window *w)
for (const Order *order = GetVehicleOrder(v, 0); order != NULL; order = order->next) { for (const Order *order = GetVehicleOrder(v, 0); order != NULL; order = order->next) {
total_time += order->travel_time + order->wait_time; total_time += order->travel_time + order->wait_time;
if (order->travel_time == 0) complete = false; if (order->travel_time == 0) complete = false;
if (order->wait_time == 0 && order->IsType(OT_GOTO_STATION) && !(_patches.new_nonstop && (order->GetNonStopType() & OFB_NON_STOP))) complete = false; if (order->wait_time == 0 && order->IsType(OT_GOTO_STATION) && !(order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) complete = false;
} }
if (total_time != 0) { if (total_time != 0) {

View File

@ -3138,12 +3138,12 @@ void Vehicle::BeginLoading()
* necessary to be known for HandleTrainLoading to determine * necessary to be known for HandleTrainLoading to determine
* whether the train is lost or not; not marking a train lost * whether the train is lost or not; not marking a train lost
* that arrives at random stations is bad. */ * that arrives at random stations is bad. */
this->current_order.SetNonStopType(OFB_NON_STOP); this->current_order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
current_order.MakeLoading(true); current_order.MakeLoading(true);
UpdateVehicleTimetable(this, true); UpdateVehicleTimetable(this, true);
} else { } else {
this->current_order.SetNonStopType(OFB_NO_NON_STOP); this->current_order.SetNonStopType(ONSF_STOP_EVERYWHERE);
current_order.MakeLoading(false); current_order.MakeLoading(false);
} }
@ -3165,7 +3165,7 @@ void Vehicle::LeaveStation()
assert(current_order.IsType(OT_LOADING)); assert(current_order.IsType(OT_LOADING));
/* Only update the timetable if the vehicle was supposed to stop here. */ /* Only update the timetable if the vehicle was supposed to stop here. */
if (current_order.GetNonStopType() != OFB_NO_NON_STOP) UpdateVehicleTimetable(this, false); if (current_order.GetNonStopType() != ONSF_STOP_EVERYWHERE) UpdateVehicleTimetable(this, false);
current_order.MakeLeaveStation(); current_order.MakeLeaveStation();
GetStation(this->last_station_visited)->loading_vehicles.remove(this); GetStation(this->last_station_visited)->loading_vehicles.remove(this);
@ -3187,11 +3187,11 @@ void Vehicle::HandleLoading(bool mode)
this->PlayLeaveStationSound(); this->PlayLeaveStationSound();
Order b = this->current_order; bool at_destination_station = this->current_order.GetNonStopType() != ONSF_STOP_EVERYWHERE;
this->LeaveStation(); this->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.GetNonStopType() & OFB_NON_STOP)) return; if (!at_destination_station) return;
break; break;
} }