diff --git a/src/order_base.h b/src/order_base.h index b92f8f9050..1ca7c7293b 100644 --- a/src/order_base.h +++ b/src/order_base.h @@ -20,8 +20,8 @@ #include "timer/timer_game_tick.h" #include "saveload/saveload.h" -typedef Pool OrderPool; -typedef Pool OrderListPool; +using OrderPool = Pool; +using OrderListPool = Pool; extern OrderPool _order_pool; extern OrderListPool _orderlist_pool; diff --git a/src/order_gui.cpp b/src/order_gui.cpp index cd0c042cd9..dd7d9e6003 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -380,7 +380,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile) { /* Override the index as it is not coming from a pool, so would not be initialised correctly. */ Order order; - order.index = 0; + order.index = OrderID::Begin(); /* check depot first */ if (IsDepotTypeTile(tile, (TransportType)(uint)v->type) && IsTileOwner(tile, _local_company)) { @@ -665,7 +665,7 @@ private: { Order order; order.next = nullptr; - order.index = 0; + order.index = OrderID::Begin(); order.MakeGoToDepot(INVALID_DEPOT, 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); @@ -1221,7 +1221,7 @@ public: if (order_id != INVALID_VEH_ORDER_ID) { Order order; order.next = nullptr; - order.index = 0; + order.index = OrderID::Begin(); order.MakeConditional(order_id); Command::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), order); diff --git a/src/order_type.h b/src/order_type.h index 8df0889af0..915d0b242f 100644 --- a/src/order_type.h +++ b/src/order_type.h @@ -12,11 +12,12 @@ #include "core/enum_type.hpp" #include "depot_type.h" +#include "core/pool_type.hpp" #include "station_type.h" typedef uint8_t VehicleOrderID; ///< The index of an order within its current vehicle (not pool related) -typedef uint32_t OrderID; -typedef uint16_t OrderListID; +using OrderID = PoolID; +using OrderListID = PoolID; struct DestinationID { using BaseType = uint16_t; @@ -39,7 +40,7 @@ static const VehicleOrderID INVALID_VEH_ORDER_ID = 0xFF; static const VehicleOrderID MAX_VEH_ORDER_ID = INVALID_VEH_ORDER_ID - 1; /** Invalid order (sentinel) */ -static const OrderID INVALID_ORDER = 0xFFFFFF; +static constexpr OrderID INVALID_ORDER = OrderID::Invalid(); /** * Maximum number of orders in implicit-only lists before we start searching diff --git a/src/saveload/order_sl.cpp b/src/saveload/order_sl.cpp index 0ce1bd206e..3ee6b86847 100644 --- a/src/saveload/order_sl.cpp +++ b/src/saveload/order_sl.cpp @@ -164,7 +164,7 @@ struct ORDRChunkHandler : ChunkHandler { /* Update all the next pointer */ for (Order *o : Order::Iterate()) { - size_t order_index = o->index; + size_t order_index = o->index.base(); /* Delete invalid orders */ if (o->IsType(OT_NOTHING)) { delete o; diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 41d9096534..a6adca7626 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -278,7 +278,7 @@ struct TimetableWindow : Window { int GetOrderFromTimetableWndPt(int y, [[maybe_unused]] const Vehicle *v) { int32_t sel = this->vscroll->GetScrolledRowFromWidget(y, this, WID_VT_TIMETABLE_PANEL, WidgetDimensions::scaled.framerect.top); - if (sel == INT32_MAX) return INVALID_ORDER; + if (sel == INT32_MAX) return INVALID_ORDER.base(); assert(IsInsideBS(sel, 0, v->GetNumOrders() * 2)); return sel; } @@ -645,7 +645,7 @@ struct TimetableWindow : Window { int selected = GetOrderFromTimetableWndPt(pt.y, v); this->CloseChildWindows(); - this->sel_index = (selected == INVALID_ORDER || selected == this->sel_index) ? -1 : selected; + this->sel_index = (selected == INVALID_ORDER.base() || selected == this->sel_index) ? -1 : selected; break; }