Codechange: Use enum class and EnumBitSet for various order flags. (#14783)

This commit is contained in:
Peter Nelson
2025-12-06 12:29:11 +00:00
committed by dP
parent c26a9827b8
commit ab20a16ed2
20 changed files with 362 additions and 344 deletions

View File

@@ -160,14 +160,14 @@ static const StringID _order_goto_dropdown_aircraft[] = {
/** Variables for conditional orders; this defines the order of appearance in the dropdown box */
static const OrderConditionVariable _order_conditional_variable[] = {
OCV_LOAD_PERCENTAGE,
OCV_RELIABILITY,
OCV_MAX_RELIABILITY,
OCV_MAX_SPEED,
OCV_AGE,
OCV_REMAINING_LIFETIME,
OCV_REQUIRES_SERVICE,
OCV_UNCONDITIONALLY,
OrderConditionVariable::LoadPercentage,
OrderConditionVariable::Reliability,
OrderConditionVariable::MaxReliability,
OrderConditionVariable::MaxSpeed,
OrderConditionVariable::Age,
OrderConditionVariable::RemainingLifetime,
OrderConditionVariable::RequiresService,
OrderConditionVariable::Unconditionally,
};
static const StringID _order_conditional_condition[] = {
@@ -191,17 +191,12 @@ static const StringID _order_depot_action_dropdown[] = {
STR_ORDER_DROP_UNBUNCH,
};
static int DepotActionStringIndex(const Order *order)
static OrderDepotAction DepotActionStringIndex(const Order *order)
{
if (order->GetDepotActionType() & ODATFB_HALT) {
return DA_STOP;
} else if (order->GetDepotOrderType() & ODTFB_SERVICE) {
return DA_SERVICE;
} else if (order->GetDepotActionType() & ODATFB_UNBUNCH) {
return DA_UNBUNCH;
} else {
return DA_ALWAYS_GO;
}
if (order->GetDepotActionType().Test(OrderDepotActionFlag::Halt)) return OrderDepotAction::Stop;
if (order->GetDepotOrderType().Test(OrderDepotTypeFlag::Service)) return OrderDepotAction::Service;
if (order->GetDepotActionType().Test(OrderDepotActionFlag::Unbunch)) return OrderDepotAction::Unbunch;
return OrderDepotAction::AlwaysGo;
}
static const StringID _order_refit_action_dropdown[] = {
@@ -211,10 +206,10 @@ static const StringID _order_refit_action_dropdown[] = {
static StringID GetOrderGoToString(const Order &order)
{
if (order.GetDepotOrderType() & ODTFB_SERVICE) {
return (order.GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT;
if (order.GetDepotOrderType().Test(OrderDepotTypeFlag::Service)) {
return order.GetNonStopType().Test(OrderNonStopFlag::NoIntermediate) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT;
} else {
return (order.GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO;
return order.GetNonStopType().Test(OrderNonStopFlag::NoIntermediate) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO;
}
}
@@ -271,7 +266,7 @@ void DrawOrderString(const Vehicle *v, const Order *order, VehicleOrderID order_
OrderUnloadFlags unload = order->GetUnloadType();
bool valid_station = CanVehicleUseStation(v, Station::Get(order->GetDestination().ToStationID()));
line = GetString(valid_station ? STR_ORDER_GO_TO_STATION : STR_ORDER_GO_TO_STATION_CAN_T_USE_STATION, STR_ORDER_GO_TO + (v->IsGroundVehicle() ? order->GetNonStopType() : 0), order->GetDestination());
line = GetString(valid_station ? STR_ORDER_GO_TO_STATION : STR_ORDER_GO_TO_STATION_CAN_T_USE_STATION, STR_ORDER_GO_TO + (v->IsGroundVehicle() ? order->GetNonStopType() : OrderNonStopFlags{}).base(), order->GetDestination());
if (timetable) {
/* Show only wait time in the timetable window. */
if (order->GetWaitTime() > 0) {
@@ -280,7 +275,7 @@ void DrawOrderString(const Vehicle *v, const Order *order, VehicleOrderID order_
}
} else {
/* Show non-stop, refit and stop location only in the order window. */
if (!(order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) {
if (!order->GetNonStopType().Test(OrderNonStopFlag::NoDestination)) {
StringID str = _station_load_types[order->IsRefit()][unload][load];
if (str != INVALID_STRING_ID) {
if (order->IsRefit()) {
@@ -291,10 +286,10 @@ void DrawOrderString(const Vehicle *v, const Order *order, VehicleOrderID order_
}
}
if (v->type == VEH_TRAIN && (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) == 0) {
if (v->type == VEH_TRAIN && !order->GetNonStopType().Test(OrderNonStopFlag::NoDestination)) {
/* Only show the stopping location if other than the default chosen by the player. */
if (order->GetStopLocation() != (OrderStopLocation)(_settings_client.gui.stop_location)) {
line += GetString(STR_ORDER_STOP_LOCATION_NEAR_END + order->GetStopLocation());
if (order->GetStopLocation() != _settings_client.gui.stop_location) {
line += GetString(STR_ORDER_STOP_LOCATION_NEAR_END + to_underlying(order->GetStopLocation()));
}
}
}
@@ -302,7 +297,7 @@ void DrawOrderString(const Vehicle *v, const Order *order, VehicleOrderID order_
}
case OT_GOTO_DEPOT:
if (!(order->GetDepotActionType() & ODATFB_NEAREST_DEPOT)) {
if (!order->GetDepotActionType().Test(OrderDepotActionFlag::NearestDepot)) {
/* Going to a specific depot. */
line = GetString(STR_ORDER_GO_TO_DEPOT_FORMAT, GetOrderGoToString(*order), v->type, order->GetDestination());
} else if (v->type == VEH_AIRCRAFT) {
@@ -314,38 +309,38 @@ void DrawOrderString(const Vehicle *v, const Order *order, VehicleOrderID order_
}
/* Do not show stopping in the depot in the timetable window. */
if (!timetable && (order->GetDepotActionType() & ODATFB_HALT)) {
if (!timetable && order->GetDepotActionType().Test(OrderDepotActionFlag::Halt)) {
line += GetString(STR_ORDER_STOP_ORDER);
}
/* Do not show refitting in the depot in the timetable window. */
if (!timetable && order->IsRefit()) {
line += GetString((order->GetDepotActionType() & ODATFB_HALT) ? STR_ORDER_REFIT_STOP_ORDER : STR_ORDER_REFIT_ORDER, CargoSpec::Get(order->GetRefitCargo())->name);
line += GetString(order->GetDepotActionType().Test(OrderDepotActionFlag::Halt) ? STR_ORDER_REFIT_STOP_ORDER : STR_ORDER_REFIT_ORDER, CargoSpec::Get(order->GetRefitCargo())->name);
}
/* Show unbunching depot in both order and timetable windows. */
if (order->GetDepotActionType() & ODATFB_UNBUNCH) {
if (order->GetDepotActionType().Test(OrderDepotActionFlag::Unbunch)) {
line += GetString(STR_ORDER_WAIT_TO_UNBUNCH);
}
break;
case OT_GOTO_WAYPOINT:
line = GetString((order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT : STR_ORDER_GO_TO_WAYPOINT, order->GetDestination());
line = GetString(order->GetNonStopType().Test(OrderNonStopFlag::NoIntermediate) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT : STR_ORDER_GO_TO_WAYPOINT, order->GetDestination());
break;
case OT_CONDITIONAL:
if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) {
if (order->GetConditionVariable() == OrderConditionVariable::Unconditionally) {
line = GetString(STR_ORDER_CONDITIONAL_UNCONDITIONAL, order->GetConditionSkipToOrder() + 1);
} else {
OrderConditionComparator occ = order->GetConditionComparator();
uint value = order->GetConditionValue();
if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value, v->type);
if (order->GetConditionVariable() == OrderConditionVariable::MaxSpeed) value = ConvertSpeedToDisplaySpeed(value, v->type);
line = GetString((occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_ORDER_CONDITIONAL_TRUE_FALSE : STR_ORDER_CONDITIONAL_NUM,
line = GetString((occ == OrderConditionComparator::IsTrue || occ == OrderConditionComparator::IsFalse) ? STR_ORDER_CONDITIONAL_TRUE_FALSE : STR_ORDER_CONDITIONAL_NUM,
order->GetConditionSkipToOrder() + 1,
STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable(),
STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ,
STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + to_underlying(order->GetConditionVariable()),
STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + to_underlying(occ),
value);
}
@@ -385,17 +380,17 @@ static std::pair<Order, citymania::FeederOrderMod> GetOrderCmdFromTile(const Veh
/* check depot first */
if (IsDepotTypeTile(tile, (TransportType)(uint)v->type) && IsTileOwner(tile, _local_company)) {
order.MakeGoToDepot(GetDepotDestinationIndex(tile),
ODTFB_PART_OF_ORDERS,
(_settings_client.gui.new_nonstop && v->IsGroundVehicle()) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
OrderDepotTypeFlag::PartOfOrders,
(_settings_client.gui.new_nonstop && v->IsGroundVehicle()) ? OrderNonStopFlag::NoIntermediate : OrderNonStopFlags{});
switch (citymania::GetDepotOrderModAction()) {
case citymania::DepotOrderModAction::Service: order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() | ODTFB_SERVICE)); break;
case citymania::DepotOrderModAction::Stop: order.SetDepotActionType(ODATFB_HALT); break;
case citymania::DepotOrderModAction::Unbunch: order.SetDepotActionType(ODATFB_UNBUNCH); break;
case citymania::DepotOrderModAction::Service: order.SetDepotOrderType((OrderDepotTypeFlags)(order.GetDepotOrderType() | OrderDepotTypeFlag::Service)); break;
case citymania::DepotOrderModAction::Stop: order.SetDepotActionType(OrderDepotActionFlag::Halt); break;
case citymania::DepotOrderModAction::Unbunch: order.SetDepotActionType(OrderDepotActionFlag::Unbunch); break;
default: break;
}
if (order.GetDepotActionType() & ODATFB_UNBUNCH) {
if (order.GetDepotActionType().Test(OrderDepotActionFlag::Unbunch)) {
/* Check to see if we are allowed to make this an unbunching order. */
bool failed = false;
if (v->HasFullLoadOrder()) {
@@ -419,7 +414,7 @@ static std::pair<Order, citymania::FeederOrderMod> GetOrderCmdFromTile(const Veh
}
/* Now we are allowed to set the action type. */
// order.SetDepotActionType(ODATFB_UNBUNCH);
// order.SetDepotActionType(OrderDepotActionFlag::Unbunch);
}
return {order, citymania::FeederOrderMod::None};
@@ -430,7 +425,7 @@ static std::pair<Order, citymania::FeederOrderMod> GetOrderCmdFromTile(const Veh
v->type == VEH_TRAIN &&
IsTileOwner(tile, _local_company)) {
order.MakeGoToWaypoint(GetStationIndex(tile));
if (_settings_client.gui.new_nonstop != citymania::_fn_mod) order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
if (_settings_client.gui.new_nonstop != citymania::_fn_mod) order.SetNonStopType({});
return {order, citymania::FeederOrderMod::None};
}
@@ -439,7 +434,7 @@ static std::pair<Order, citymania::FeederOrderMod> GetOrderCmdFromTile(const Veh
v->type == VEH_ROAD &&
IsTileOwner(tile, _local_company)) {
order.MakeGoToWaypoint(GetStationIndex(tile));
if (_settings_client.gui.new_nonstop != _ctrl_pressed) order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
if (_settings_client.gui.new_nonstop != _ctrl_pressed) order.SetNonStopType({});
return std::make_pair(order, citymania::FeederOrderMod::None);
}
@@ -477,8 +472,8 @@ static std::pair<Order, citymania::FeederOrderMod> GetOrderCmdFromTile(const Veh
order.SetUnloadType(ofs.unload);
feeder_mod = ofs.mod;
if (_settings_client.gui.new_nonstop && v->IsGroundVehicle()) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
order.SetStopLocation(v->type == VEH_TRAIN ? (OrderStopLocation)(_settings_client.gui.stop_location) : OSL_PLATFORM_FAR_END);
if (_settings_client.gui.new_nonstop && v->IsGroundVehicle()) order.SetNonStopType(OrderNonStopFlag::NoIntermediate);
order.SetStopLocation(v->type == VEH_TRAIN ? (OrderStopLocation)(_settings_client.gui.stop_location) : OrderStopLocation::FarEnd);
return {order, feeder_mod};
}
}
@@ -660,16 +655,16 @@ private:
/**
* Handle the click on the service.
*/
void OrderClick_Service(int i)
void OrderClick_Service(std::optional<OrderDepotAction> i)
{
VehicleOrderID sel_ord = this->OrderGetSel();
if (i < 0) {
if (!i.has_value()) {
const Order *order = this->vehicle->GetOrder(sel_ord);
if (order == nullptr) return;
i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE;
i = order->GetDepotOrderType().Test(OrderDepotTypeFlag::Service) ? OrderDepotAction::AlwaysGo : OrderDepotAction::Service;
}
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_DEPOT_ACTION, i);
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_DEPOT_ACTION, to_underlying(i.value()));
}
/**
@@ -678,9 +673,9 @@ private:
void OrderClick_NearestDepot()
{
Order order{};
order.MakeGoToDepot(DepotID::Invalid(), ODTFB_PART_OF_ORDERS,
_settings_client.gui.new_nonstop && this->vehicle->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
order.SetDepotActionType(ODATFB_NEAREST_DEPOT);
order.MakeGoToDepot(DepotID::Invalid(), OrderDepotTypeFlag::PartOfOrders,
_settings_client.gui.new_nonstop && this->vehicle->IsGroundVehicle() ? OrderNonStopFlag::NoIntermediate : OrderNonStopFlags{});
order.SetDepotActionType(OrderDepotActionFlag::NearestDepot);
Command<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), order);
}
@@ -720,9 +715,9 @@ private:
/**
* Handle the click on the nonstop button.
* @param non_stop what non-stop type to use; -1 to use the 'next' one.
* @param non_stop what non-stop type to use; std::nullopt to use the 'next' one.
*/
void OrderClick_Nonstop(int non_stop)
void OrderClick_Nonstop(std::optional<OrderNonStopFlags> non_stop)
{
if (!this->vehicle->IsGroundVehicle()) return;
@@ -731,13 +726,13 @@ private:
if (order == nullptr || order->GetNonStopType() == non_stop) return;
/* Keypress if negative, so 'toggle' to the next */
if (non_stop < 0) {
non_stop = order->GetNonStopType() ^ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS;
/* Keypress if no value, so 'toggle' to the next */
if (!non_stop.has_value()) {
non_stop = order->GetNonStopType().Flip(OrderNonStopFlag::NoIntermediate);
}
this->SetWidgetDirty(WID_O_NON_STOP);
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_NON_STOP, non_stop);
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_NON_STOP, non_stop.value().base());
}
/**
@@ -864,7 +859,7 @@ public:
case WID_O_COND_VARIABLE: {
Dimension d = {0, 0};
for (const auto &ocv : _order_conditional_variable) {
d = maxdim(d, GetStringBoundingBox(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + ocv));
d = maxdim(d, GetStringBoundingBox(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + to_underlying(ocv)));
}
d.width += padding.width;
d.height += padding.height;
@@ -1020,8 +1015,8 @@ public:
this->DisableWidget(WID_O_UNLOAD);
this->DisableWidget(WID_O_REFIT_DROPDOWN);
} else {
this->SetWidgetDisabledState(WID_O_FULL_LOAD, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // full load
this->SetWidgetDisabledState(WID_O_UNLOAD, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // unload
this->SetWidgetDisabledState(WID_O_FULL_LOAD, order->GetNonStopType().Test(OrderNonStopFlag::NoDestination)); // full load
this->SetWidgetDisabledState(WID_O_UNLOAD, order->GetNonStopType().Test(OrderNonStopFlag::NoDestination)); // unload
switch (order->GetType()) {
case OT_GOTO_STATION:
@@ -1033,7 +1028,7 @@ public:
middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
right_sel->SetDisplayedPlane(DP_RIGHT_REFIT);
this->EnableWidget(WID_O_NON_STOP);
this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType().Test(OrderNonStopFlag::NoIntermediate));
}
this->SetWidgetLoweredState(WID_O_FULL_LOAD, order->GetLoadType() == OLF_FULL_LOAD_ANY);
this->SetWidgetLoweredState(WID_O_UNLOAD, order->GetUnloadType() == OUFB_UNLOAD);
@@ -1041,7 +1036,7 @@ public:
/* Can only do refitting when stopping at the destination and loading cargo.
* Also enable the button if a refit is already set to allow clearing it. */
this->SetWidgetDisabledState(WID_O_REFIT_DROPDOWN,
order->GetLoadType() == OLFB_NO_LOAD || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ||
order->GetLoadType() == OLFB_NO_LOAD || order->GetNonStopType().Test(OrderNonStopFlag::NoDestination) ||
((!this->can_do_refit || !this->can_do_autorefit) && !order->IsRefit()));
break;
@@ -1055,7 +1050,7 @@ public:
middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
this->EnableWidget(WID_O_NON_STOP);
this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType().Test(OrderNonStopFlag::NoIntermediate));
}
this->DisableWidget(WID_O_FULL_LOAD);
this->DisableWidget(WID_O_UNLOAD);
@@ -1071,12 +1066,12 @@ public:
middle_sel->SetDisplayedPlane(DP_MIDDLE_SERVICE);
right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
this->EnableWidget(WID_O_NON_STOP);
this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
this->SetWidgetLoweredState(WID_O_NON_STOP, order->GetNonStopType().Test(OrderNonStopFlag::NoIntermediate));
}
/* Disable refit button if the order is no 'always go' order.
* However, keep the service button enabled for refit-orders to allow clearing refits (without knowing about ctrl). */
this->SetWidgetDisabledState(WID_O_REFIT,
(order->GetDepotOrderType() & ODTFB_SERVICE) || (order->GetDepotActionType() & ODATFB_HALT) ||
order->GetDepotOrderType().Test(OrderDepotTypeFlag::Service) || order->GetDepotActionType().Test(OrderDepotActionFlag::Halt) ||
(!this->can_do_refit && !order->IsRefit()));
break;
@@ -1088,10 +1083,10 @@ public:
}
OrderConditionVariable ocv = order->GetConditionVariable();
/* Set the strings for the dropdown boxes. */
this->GetWidget<NWidgetCore>(WID_O_COND_VARIABLE)->SetString(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + ocv);
this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->SetString(_order_conditional_condition[order->GetConditionComparator()]);
this->SetWidgetDisabledState(WID_O_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
this->SetWidgetDisabledState(WID_O_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY);
this->GetWidget<NWidgetCore>(WID_O_COND_VARIABLE)->SetString(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + to_underlying(ocv));
this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->SetString(_order_conditional_condition[to_underlying(order->GetConditionComparator())]);
this->SetWidgetDisabledState(WID_O_COND_COMPARATOR, ocv == OrderConditionVariable::Unconditionally);
this->SetWidgetDisabledState(WID_O_COND_VALUE, ocv == OrderConditionVariable::RequiresService || ocv == OrderConditionVariable::Unconditionally);
break;
}
@@ -1194,7 +1189,7 @@ public:
if (order != nullptr && order->IsType(OT_CONDITIONAL)) {
uint value = order->GetConditionValue();
if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value, this->vehicle->type);
if (order->GetConditionVariable() == OrderConditionVariable::MaxSpeed) value = ConvertSpeedToDisplaySpeed(value, this->vehicle->type);
return GetString(STR_JUST_COMMA, value);
}
return {};
@@ -1209,9 +1204,9 @@ public:
if (order == nullptr || !order->IsType(OT_GOTO_DEPOT)) return {};
/* Select the current action selected in the dropdown. The flags don't match the dropdown so we can't just use an index. */
if (order->GetDepotOrderType() & ODTFB_SERVICE) return GetString(STR_ORDER_DROP_SERVICE_DEPOT);
if (order->GetDepotActionType() & ODATFB_HALT) return GetString(STR_ORDER_DROP_HALT_DEPOT);
if (order->GetDepotActionType() & ODATFB_UNBUNCH) return GetString(STR_ORDER_DROP_UNBUNCH);
if (order->GetDepotOrderType().Test(OrderDepotTypeFlag::Service)) return GetString(STR_ORDER_DROP_SERVICE_DEPOT);
if (order->GetDepotActionType().Test(OrderDepotActionFlag::Halt)) return GetString(STR_ORDER_DROP_HALT_DEPOT);
if (order->GetDepotActionType().Test(OrderDepotActionFlag::Unbunch)) return GetString(STR_ORDER_DROP_UNBUNCH);
return GetString(STR_ORDER_DROP_GO_ALWAYS_DEPOT);
}
@@ -1255,7 +1250,7 @@ public:
if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER,
this->vehicle->tile, this->vehicle->index, sel,
MOF_STOP_LOCATION, (this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END);
MOF_STOP_LOCATION, (to_underlying(this->vehicle->GetOrder(sel)->GetStopLocation()) + 1) % to_underlying(OrderStopLocation::End));
}
} else {
/* Select clicked order */
@@ -1285,11 +1280,11 @@ public:
case WID_O_NON_STOP:
if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
this->OrderClick_Nonstop(-1);
this->OrderClick_Nonstop(std::nullopt);
} else {
const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
assert(o != nullptr);
ShowDropDownMenu(this, _order_non_stop_dropdown, o->GetNonStopType(), WID_O_NON_STOP, 0,
ShowDropDownMenu(this, _order_non_stop_dropdown, o->GetNonStopType().base(), WID_O_NON_STOP, 0,
o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
}
break;
@@ -1335,7 +1330,7 @@ public:
break;
case WID_O_DEPOT_ACTION:
ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), WID_O_DEPOT_ACTION, 0, 0);
ShowDropDownMenu(this, _order_depot_action_dropdown, to_underlying(DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel()))), WID_O_DEPOT_ACTION, 0, 0);
break;
case WID_O_REFIT_DROPDOWN:
@@ -1353,16 +1348,16 @@ public:
case WID_O_COND_VARIABLE: {
DropDownList list;
for (const auto &ocv : _order_conditional_variable) {
list.push_back(MakeDropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + ocv, ocv));
list.push_back(MakeDropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + to_underlying(ocv), to_underlying(ocv)));
}
ShowDropDownList(this, std::move(list), this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), WID_O_COND_VARIABLE);
ShowDropDownList(this, std::move(list), to_underlying(this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable()), WID_O_COND_VARIABLE);
break;
}
case WID_O_COND_COMPARATOR: {
const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
assert(o != nullptr);
ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
ShowDropDownMenu(this, _order_conditional_condition, to_underlying(o->GetConditionComparator()), WID_O_COND_COMPARATOR, 0, (o->GetConditionVariable() == OrderConditionVariable::RequiresService) ? 0x3F : 0xC0);
break;
}
@@ -1370,7 +1365,7 @@ public:
const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
assert(order != nullptr);
uint value = order->GetConditionValue();
if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value, this->vehicle->type);
if (order->GetConditionVariable() == OrderConditionVariable::MaxSpeed) value = ConvertSpeedToDisplaySpeed(value, this->vehicle->type);
ShowQueryString(GetString(STR_JUST_INT, value), STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, this, CS_NUMERAL, {});
break;
}
@@ -1390,12 +1385,12 @@ public:
if (!value.has_value()) return;
switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
case OCV_MAX_SPEED:
case OrderConditionVariable::MaxSpeed:
value = ConvertDisplaySpeedToSpeed(*value, this->vehicle->type);
break;
case OCV_RELIABILITY:
case OCV_LOAD_PERCENTAGE:
case OrderConditionVariable::Reliability:
case OrderConditionVariable::LoadPercentage:
value = Clamp(*value, 0, 100);
break;
@@ -1409,7 +1404,7 @@ public:
{
switch (widget) {
case WID_O_NON_STOP:
this->OrderClick_Nonstop(index);
this->OrderClick_Nonstop(static_cast<OrderNonStopFlags>(index));
break;
case WID_O_FULL_LOAD:
@@ -1431,7 +1426,7 @@ public:
break;
case WID_O_DEPOT_ACTION:
this->OrderClick_Service(index);
this->OrderClick_Service(static_cast<OrderDepotAction>(index));
break;
case WID_O_REFIT_DROPDOWN:
@@ -1494,11 +1489,11 @@ public:
case OHK_SKIP: this->OrderClick_Skip(); break;
case OHK_DELETE: this->OrderClick_Delete(); break;
case OHK_GOTO: this->OrderClick_Goto(OPOS_GOTO); break;
case OHK_NONSTOP: this->OrderClick_Nonstop(-1); break;
case OHK_NONSTOP: this->OrderClick_Nonstop(std::nullopt); break;
case OHK_FULLLOAD: this->OrderClick_FullLoad(OLF_FULL_LOAD_ANY, true); break;
case OHK_UNLOAD: this->OrderClick_Unload(OUFB_UNLOAD, true); break;
case OHK_NEAREST_DEPOT: this->OrderClick_NearestDepot(); break;
case OHK_ALWAYS_SERVICE: this->OrderClick_Service(-1); break;
case OHK_ALWAYS_SERVICE: this->OrderClick_Service(std::nullopt); break;
case OHK_TRANSFER: this->OrderClick_Unload(OUFB_TRANSFER, true); break;
case OHK_NO_UNLOAD: this->OrderClick_Unload(OUFB_NO_UNLOAD, true); break;
case OHK_NO_LOAD: this->OrderClick_FullLoad(OLFB_NO_LOAD, true); break;