mirror of https://github.com/OpenTTD/OpenTTD
Codechange: strongly type OrderID and OrderListID
parent
d61d643906
commit
9ab36b594d
|
@ -20,8 +20,8 @@
|
|||
#include "timer/timer_game_tick.h"
|
||||
#include "saveload/saveload.h"
|
||||
|
||||
typedef Pool<Order, OrderID, 256, 0xFF0000> OrderPool;
|
||||
typedef Pool<OrderList, OrderListID, 128, 64000> OrderListPool;
|
||||
using OrderPool = Pool<Order, OrderID, 256, OrderID::End().base()>;
|
||||
using OrderListPool = Pool<OrderList, OrderListID, 128, OrderListID::End().base()>;
|
||||
extern OrderPool _order_pool;
|
||||
extern OrderListPool _orderlist_pool;
|
||||
|
||||
|
|
|
@ -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<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), order);
|
||||
|
|
|
@ -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<uint32_t, struct OrderIDTag, 0xFF0000, 0xFFFFFF>;
|
||||
using OrderListID = PoolID<uint16_t, struct OrderListIDTag, 64000, 0xFFFF>;
|
||||
|
||||
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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue