summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ai/api/ai_order.cpp14
-rw-r--r--src/order_cmd.cpp18
-rw-r--r--src/order_gui.cpp32
-rw-r--r--src/timetable_cmd.cpp4
-rw-r--r--src/timetable_gui.cpp10
-rw-r--r--src/train_cmd.cpp2
-rw-r--r--src/vehicle.cpp2
-rw-r--r--src/vehicle_base.h29
8 files changed, 60 insertions, 51 deletions
diff --git a/src/ai/api/ai_order.cpp b/src/ai/api/ai_order.cpp
index 22b86f683..ce1e3ed46 100644
--- a/src/ai/api/ai_order.cpp
+++ b/src/ai/api/ai_order.cpp
@@ -60,7 +60,7 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or
order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position);
if (order_position == AIOrder::ORDER_INVALID) return NULL;
}
- return ::GetVehicleOrder(v, order_position);
+ return v->GetOrder(order_position);
}
/* static */ bool AIOrder::IsGotoStationOrder(VehicleID vehicle_id, OrderPosition order_position)
@@ -92,7 +92,7 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or
if (order_position == ORDER_CURRENT) return false;
if (!IsValidVehicleOrder(vehicle_id, order_position)) return false;
- const Order *order = ::GetVehicleOrder(Vehicle::Get(vehicle_id), order_position);
+ const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
return order->GetType() == OT_CONDITIONAL;
}
@@ -236,7 +236,7 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or
if (!IsValidVehicleOrder(vehicle_id, order_position)) return ORDER_INVALID;
if (order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position)) return ORDER_INVALID;
- const Order *order = ::GetVehicleOrder(Vehicle::Get(vehicle_id), order_position);
+ const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
return (OrderPosition)order->GetConditionSkipToOrder();
}
@@ -245,7 +245,7 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or
if (!IsValidVehicleOrder(vehicle_id, order_position)) return OC_INVALID;
if (order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position)) return OC_INVALID;
- const Order *order = ::GetVehicleOrder(Vehicle::Get(vehicle_id), order_position);
+ const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
return (OrderCondition)order->GetConditionVariable();
}
@@ -254,7 +254,7 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or
if (!IsValidVehicleOrder(vehicle_id, order_position)) return CF_INVALID;
if (order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position)) return CF_INVALID;
- const Order *order = ::GetVehicleOrder(Vehicle::Get(vehicle_id), order_position);
+ const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
return (CompareFunction)order->GetConditionComparator();
}
@@ -263,7 +263,7 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or
if (!IsValidVehicleOrder(vehicle_id, order_position)) return -1;
if (order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position)) return -1;
- const Order *order = ::GetVehicleOrder(Vehicle::Get(vehicle_id), order_position);
+ const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
int32 value = order->GetConditionValue();
if (order->GetConditionVariable() == OCV_MAX_SPEED) value = value * 16 / 10;
return value;
@@ -432,7 +432,7 @@ static void _DoCommandReturnSetOrderFlags(class AIInstance *instance)
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
EnforcePrecondition(false, AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags));
- const Order *order = ::GetVehicleOrder(Vehicle::Get(vehicle_id), order_position);
+ const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
AIOrderFlags current = GetOrderFlags(vehicle_id, order_position);
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index 62bf9bed4..c84026fa4 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -398,7 +398,7 @@ static uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle
conditional_depth++;
- int dist1 = GetOrderDistance(prev, GetVehicleOrder(v, cur->GetConditionSkipToOrder()), v, conditional_depth);
+ int dist1 = GetOrderDistance(prev, v->GetOrder(cur->GetConditionSkipToOrder()), v, conditional_depth);
int dist2 = GetOrderDistance(prev, cur->next == NULL ? v->orders.list->GetFirstOrder() : cur->next, v, conditional_depth);
return max(dist1, dist2);
}
@@ -668,7 +668,7 @@ CommandCost CmdDeleteOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
if (sel_ord >= v->GetNumOrders())
return DecloneOrder(v, flags);
- order = GetVehicleOrder(v, sel_ord);
+ order = v->GetOrder(sel_ord);
if (order == NULL) return CMD_ERROR;
if (flags & DC_EXEC) {
@@ -772,7 +772,7 @@ CommandCost CmdMoveOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
moving_order == target_order || v->GetNumOrders() <= 1)
return CMD_ERROR;
- Order *moving_one = GetVehicleOrder(v, moving_order);
+ Order *moving_one = v->GetOrder(moving_order);
/* Don't move an empty order */
if (moving_one == NULL) return CMD_ERROR;
@@ -849,7 +849,7 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
/* Is it a valid order? */
if (sel_ord >= v->GetNumOrders()) return CMD_ERROR;
- Order *order = GetVehicleOrder(v, sel_ord);
+ Order *order = v->GetOrder(sel_ord);
switch (order->GetType()) {
case OT_GOTO_STATION:
if (mof == MOF_COND_VARIABLE || mof == MOF_COND_COMPARATOR || mof == MOF_DEPOT_ACTION || mof == MOF_COND_VALUE || Station::Get(order->GetDestination())->IsBuoy()) return CMD_ERROR;
@@ -1191,7 +1191,7 @@ CommandCost CmdOrderRefit(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
const Vehicle *v = Vehicle::GetIfValid(veh);
if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
- Order *order = GetVehicleOrder(v, order_number);
+ Order *order = v->GetOrder(order_number);
if (order == NULL) return CMD_ERROR;
if (flags & DC_EXEC) {
@@ -1412,7 +1412,7 @@ void CheckOrders(const Vehicle *v)
/* Check if the last and the first order are the same */
if (v->GetNumOrders() > 1) {
- const Order *last = GetLastVehicleOrder(v);
+ const Order *last = v->GetLastOrder();
if (v->orders.list->GetFirstOrder()->Equals(*last)) {
problem_type = 2;
@@ -1648,7 +1648,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth)
if (next_order != INVALID_VEH_ORDER_ID) {
UpdateVehicleTimetable(v, false);
v->cur_order_index = next_order;
- v->current_order_time += GetVehicleOrder(v, next_order)->travel_time;
+ v->current_order_time += v->GetOrder(next_order)->travel_time;
} else {
UpdateVehicleTimetable(v, true);
v->IncrementOrderIndex();
@@ -1657,7 +1657,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth)
assert(v->cur_order_index < v->GetNumOrders());
/* Get the current order */
- const Order *order = GetVehicleOrder(v, v->cur_order_index);
+ const Order *order = v->GetOrder(v->cur_order_index);
v->current_order = *order;
return UpdateOrderDest(v, order, conditional_depth + 1);
}
@@ -1726,7 +1726,7 @@ bool ProcessOrders(Vehicle *v)
/* Get the current order */
if (v->cur_order_index >= v->GetNumOrders()) v->cur_order_index = 0;
- const Order *order = GetVehicleOrder(v, v->cur_order_index);
+ const Order *order = v->GetOrder(v->cur_order_index);
/* If no order, do nothing. */
if (order == NULL || (v->type == VEH_AIRCRAFT && order->IsType(OT_DUMMY) && !CheckForValidOrders(v))) {
diff --git a/src/order_gui.cpp b/src/order_gui.cpp
index e44c27f9a..93693db9d 100644
--- a/src/order_gui.cpp
+++ b/src/order_gui.cpp
@@ -470,7 +470,7 @@ private:
static void OrderClick_FullLoad(OrdersWindow *w, int load_type)
{
VehicleOrderID sel_ord = w->OrderGetSel();
- const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
+ const Order *order = w->vehicle->GetOrder(sel_ord);
if (order == NULL || order->GetLoadType() == load_type) return;
@@ -490,7 +490,7 @@ private:
VehicleOrderID sel_ord = w->OrderGetSel();
if (i < 0) {
- const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
+ const Order *order = w->vehicle->GetOrder(sel_ord);
if (order == NULL) return;
i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE;
}
@@ -535,7 +535,7 @@ private:
static void OrderClick_Unload(OrdersWindow *w, int unload_type)
{
VehicleOrderID sel_ord = w->OrderGetSel();
- const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
+ const Order *order = w->vehicle->GetOrder(sel_ord);
if (order == NULL || order->GetUnloadType() == unload_type) return;
@@ -555,7 +555,7 @@ private:
static void OrderClick_Nonstop(OrdersWindow *w, int non_stop)
{
VehicleOrderID sel_ord = w->OrderGetSel();
- const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
+ const Order *order = w->vehicle->GetOrder(sel_ord);
if (order == NULL || order->GetNonStopType() == non_stop) return;
@@ -711,7 +711,7 @@ public:
SetVScrollCount(this, this->vehicle->GetNumOrders() + 1);
int sel = OrderGetSel();
- const Order *order = GetVehicleOrder(this->vehicle, sel);
+ const Order *order = this->vehicle->GetOrder(sel);
if (this->vehicle->owner == _local_company) {
/* Set the strings for the dropdown boxes. */
@@ -824,7 +824,7 @@ public:
int y = 15;
int i = this->vscroll.pos;
- order = GetVehicleOrder(this->vehicle, i);
+ order = this->vehicle->GetOrder(i);
StringID str;
while (order != NULL) {
/* Don't draw anything if it extends past the end of the window. */
@@ -852,7 +852,7 @@ public:
int sel = this->GetOrderFromPt(pt.y);
if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
- const Order *ord = GetVehicleOrder(this->vehicle, sel);
+ const Order *ord = this->vehicle->GetOrder(sel);
TileIndex xy = INVALID_TILE;
switch (ord->GetType()) {
@@ -880,7 +880,7 @@ public:
} else if (sel == this->selected_order) {
if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 16),
- MOF_STOP_LOCATION | ((GetVehicleOrder(this->vehicle, sel)->GetStopLocation() + 1) % OSL_END) << 4,
+ MOF_STOP_LOCATION | ((this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END) << 4,
CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
}
} else {
@@ -909,7 +909,7 @@ public:
break;
case ORDER_WIDGET_NON_STOP_DROPDOWN: {
- const Order *o = GetVehicleOrder(this->vehicle, this->OrderGetSel());
+ const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), ORDER_WIDGET_NON_STOP_DROPDOWN, 0, o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
} break;
@@ -926,7 +926,7 @@ public:
break;
case ORDER_WIDGET_FULL_LOAD_DROPDOWN:
- ShowDropDownMenu(this, _order_full_load_drowdown, GetVehicleOrder(this->vehicle, this->OrderGetSel())->GetLoadType(), ORDER_WIDGET_FULL_LOAD_DROPDOWN, 0, 2);
+ ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), ORDER_WIDGET_FULL_LOAD_DROPDOWN, 0, 2);
break;
case ORDER_WIDGET_UNLOAD:
@@ -934,7 +934,7 @@ public:
break;
case ORDER_WIDGET_UNLOAD_DROPDOWN:
- ShowDropDownMenu(this, _order_unload_drowdown, GetVehicleOrder(this->vehicle, this->OrderGetSel())->GetUnloadType(), ORDER_WIDGET_UNLOAD_DROPDOWN, 0, 8);
+ ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), ORDER_WIDGET_UNLOAD_DROPDOWN, 0, 8);
break;
case ORDER_WIDGET_REFIT:
@@ -946,7 +946,7 @@ public:
break;
case ORDER_WIDGET_SERVICE_DROPDOWN:
- ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(GetVehicleOrder(this->vehicle, this->OrderGetSel())), ORDER_WIDGET_SERVICE_DROPDOWN, 0, 0);
+ ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), ORDER_WIDGET_SERVICE_DROPDOWN, 0, 0);
break;
case ORDER_WIDGET_TIMETABLE_VIEW:
@@ -954,16 +954,16 @@ public:
break;
case ORDER_WIDGET_COND_VARIABLE:
- ShowDropDownMenu(this, _order_conditional_variable, GetVehicleOrder(this->vehicle, this->OrderGetSel())->GetConditionVariable(), ORDER_WIDGET_COND_VARIABLE, 0, 0);
+ ShowDropDownMenu(this, _order_conditional_variable, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), ORDER_WIDGET_COND_VARIABLE, 0, 0);
break;
case ORDER_WIDGET_COND_COMPARATOR: {
- const Order *o = GetVehicleOrder(this->vehicle, this->OrderGetSel());
+ const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), ORDER_WIDGET_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
} break;
case ORDER_WIDGET_COND_VALUE: {
- const Order *order = GetVehicleOrder(this->vehicle, this->OrderGetSel());
+ const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
uint value = order->GetConditionValue();
if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
SetDParam(0, value);
@@ -982,7 +982,7 @@ public:
VehicleOrderID sel = this->OrderGetSel();
uint value = atoi(str);
- switch (GetVehicleOrder(this->vehicle, sel)->GetConditionVariable()) {
+ switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
case OCV_MAX_SPEED:
value = ConvertDisplaySpeedToSpeed(value);
break;
diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp
index d73052916..4e12743b4 100644
--- a/src/timetable_cmd.cpp
+++ b/src/timetable_cmd.cpp
@@ -13,7 +13,7 @@
static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16 time, bool is_journey)
{
- Order *order = GetVehicleOrder(v, order_number);
+ Order *order = v->GetOrder(order_number);
int delta;
if (is_journey) {
@@ -62,7 +62,7 @@ CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, u
if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
VehicleOrderID order_number = GB(p1, 16, 8);
- Order *order = GetVehicleOrder(v, order_number);
+ Order *order = v->GetOrder(order_number);
if (order == NULL) return CMD_ERROR;
bool packed_time = HasBit(p1, 25);
diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp
index 72d66c1c4..a02dd696a 100644
--- a/src/timetable_gui.cpp
+++ b/src/timetable_gui.cpp
@@ -146,7 +146,7 @@ struct TimetableWindow : Window {
if (v->owner == _local_company) {
bool disable = true;
if (selected != -1) {
- const Order *order = GetVehicleOrder(v, ((selected + 1) / 2) % v->GetNumOrders());
+ const Order *order = v->GetOrder(((selected + 1) / 2) % v->GetNumOrders());
if (selected % 2 == 1) {
disable = order != NULL && order->IsType(OT_CONDITIONAL);
} else {
@@ -176,7 +176,7 @@ struct TimetableWindow : Window {
VehicleOrderID order_id = (i + 1) / 2;
bool final_order = false;
- const Order *order = GetVehicleOrder(v, order_id);
+ const Order *order = v->GetOrder(order_id);
while (order != NULL) {
/* Don't draw anything if it extends past the end of the window. */
@@ -188,7 +188,7 @@ struct TimetableWindow : Window {
order_id++;
if (order_id >= v->GetNumOrders()) {
- order = GetVehicleOrder(v, 0);
+ order = v->GetOrder(0);
final_order = true;
} else {
order = order->next;
@@ -220,7 +220,7 @@ struct TimetableWindow : Window {
uint total_time = 0;
bool complete = true;
- for (const Order *order = GetVehicleOrder(v, 0); order != NULL; order = order->next) {
+ for (const Order *order = v->GetOrder(0); order != NULL; order = order->next) {
total_time += order->travel_time + order->wait_time;
if (order->travel_time == 0 && !order->IsType(OT_CONDITIONAL)) complete = false;
if (order->wait_time == 0 && order->IsType(OT_GOTO_STATION) && !(order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) complete = false;
@@ -273,7 +273,7 @@ struct TimetableWindow : Window {
if (real >= v->GetNumOrders()) real = 0;
- const Order *order = GetVehicleOrder(v, real);
+ const Order *order = v->GetOrder(real);
StringID current = STR_EMPTY;
if (order != NULL) {
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index d0bba76b6..8bbd9010d 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -2868,7 +2868,7 @@ public:
/* Wrap around. */
if (this->index >= this->v->GetNumOrders()) this->index = 0;
- Order *order = GetVehicleOrder(this->v, this->index);
+ Order *order = this->v->GetOrder(this->index);
assert(order != NULL);
switch (order->GetType()) {
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index d1665a26a..87027d083 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1021,7 +1021,7 @@ void VehicleEnterDepot(Vehicle *v)
if (v->current_order.IsType(OT_GOTO_DEPOT)) {
InvalidateWindow(WC_VEHICLE_VIEW, v->index);
- const Order *real_order = GetVehicleOrder(v, v->cur_order_index);
+ const Order *real_order = v->GetOrder(v->cur_order_index);
Order t = v->current_order;
v->current_order.MakeDummy();
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index 350b5e7c5..8883470ab 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -470,6 +470,25 @@ public:
if (this->cur_order_index >= this->GetNumOrders()) this->cur_order_index = 0;
InvalidateVehicleOrder(this, 0);
}
+
+ /**
+ * Returns order 'index' of a vehicle or NULL when it doesn't exists
+ * @param index the order to fetch
+ * @return the found (or not) order
+ */
+ inline Order *GetOrder(int index) const
+ {
+ return (this->orders.list == NULL) ? NULL : this->orders.list->GetOrderAt(index);
+ }
+
+ /**
+ * Returns the last order of a vehicle, or NULL if it doesn't exists
+ * @return last order of a vehicle, if available
+ */
+ inline Order *GetLastOrder() const
+ {
+ return (this->orders.list == NULL) ? NULL : this->orders.list->GetLastOrder();
+ }
};
/**
@@ -520,16 +539,6 @@ struct FreeUnitIDGenerator {
~FreeUnitIDGenerator() { free(this->cache); }
};
-/* Returns order 'index' of a vehicle or NULL when it doesn't exists */
-static inline Order *GetVehicleOrder(const Vehicle *v, int index) { return (v->orders.list == NULL) ? NULL : v->orders.list->GetOrderAt(index); }
-
-/**
- * Returns the last order of a vehicle, or NULL if it doesn't exists
- * @param v Vehicle to query
- * @return last order of a vehicle, if available
- */
-static inline Order *GetLastVehicleOrder(const Vehicle *v) { return (v->orders.list == NULL) ? NULL : v->orders.list->GetLastOrder(); }
-
void CheckVehicle32Day(Vehicle *v);
static const int32 INVALID_COORD = 0x7fffffff;