(svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle

This commit is contained in:
rubidium 2009-05-23 12:27:42 +00:00
parent f490394aa8
commit 86710c5185
8 changed files with 60 additions and 51 deletions

View File

@ -60,7 +60,7 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or
order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position); order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position);
if (order_position == AIOrder::ORDER_INVALID) return NULL; 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) /* 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 (order_position == ORDER_CURRENT) return false;
if (!IsValidVehicleOrder(vehicle_id, order_position)) 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; 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 (!IsValidVehicleOrder(vehicle_id, order_position)) return ORDER_INVALID;
if (order_position == ORDER_CURRENT || !IsConditionalOrder(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(); 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 (!IsValidVehicleOrder(vehicle_id, order_position)) return OC_INVALID;
if (order_position == ORDER_CURRENT || !IsConditionalOrder(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(); 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 (!IsValidVehicleOrder(vehicle_id, order_position)) return CF_INVALID;
if (order_position == ORDER_CURRENT || !IsConditionalOrder(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(); 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 (!IsValidVehicleOrder(vehicle_id, order_position)) return -1;
if (order_position == ORDER_CURRENT || !IsConditionalOrder(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(); int32 value = order->GetConditionValue();
if (order->GetConditionVariable() == OCV_MAX_SPEED) value = value * 16 / 10; if (order->GetConditionVariable() == OCV_MAX_SPEED) value = value * 16 / 10;
return value; return value;
@ -432,7 +432,7 @@ static void _DoCommandReturnSetOrderFlags(class AIInstance *instance)
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
EnforcePrecondition(false, AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags)); 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); AIOrderFlags current = GetOrderFlags(vehicle_id, order_position);

View File

@ -398,7 +398,7 @@ static uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle
conditional_depth++; 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); int dist2 = GetOrderDistance(prev, cur->next == NULL ? v->orders.list->GetFirstOrder() : cur->next, v, conditional_depth);
return max(dist1, dist2); return max(dist1, dist2);
} }
@ -668,7 +668,7 @@ CommandCost CmdDeleteOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
if (sel_ord >= v->GetNumOrders()) if (sel_ord >= v->GetNumOrders())
return DecloneOrder(v, flags); return DecloneOrder(v, flags);
order = GetVehicleOrder(v, sel_ord); order = v->GetOrder(sel_ord);
if (order == NULL) return CMD_ERROR; if (order == NULL) return CMD_ERROR;
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
@ -772,7 +772,7 @@ CommandCost CmdMoveOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
moving_order == target_order || v->GetNumOrders() <= 1) moving_order == target_order || v->GetNumOrders() <= 1)
return CMD_ERROR; return CMD_ERROR;
Order *moving_one = GetVehicleOrder(v, moving_order); Order *moving_one = v->GetOrder(moving_order);
/* Don't move an empty order */ /* Don't move an empty order */
if (moving_one == NULL) return CMD_ERROR; 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? */ /* Is it a valid order? */
if (sel_ord >= v->GetNumOrders()) return CMD_ERROR; if (sel_ord >= v->GetNumOrders()) return CMD_ERROR;
Order *order = GetVehicleOrder(v, sel_ord); Order *order = v->GetOrder(sel_ord);
switch (order->GetType()) { switch (order->GetType()) {
case OT_GOTO_STATION: 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; 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); const Vehicle *v = Vehicle::GetIfValid(veh);
if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR; 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 (order == NULL) return CMD_ERROR;
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
@ -1412,7 +1412,7 @@ void CheckOrders(const Vehicle *v)
/* Check if the last and the first order are the same */ /* Check if the last and the first order are the same */
if (v->GetNumOrders() > 1) { if (v->GetNumOrders() > 1) {
const Order *last = GetLastVehicleOrder(v); const Order *last = v->GetLastOrder();
if (v->orders.list->GetFirstOrder()->Equals(*last)) { if (v->orders.list->GetFirstOrder()->Equals(*last)) {
problem_type = 2; problem_type = 2;
@ -1648,7 +1648,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth)
if (next_order != INVALID_VEH_ORDER_ID) { if (next_order != INVALID_VEH_ORDER_ID) {
UpdateVehicleTimetable(v, false); UpdateVehicleTimetable(v, false);
v->cur_order_index = next_order; 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 { } else {
UpdateVehicleTimetable(v, true); UpdateVehicleTimetable(v, true);
v->IncrementOrderIndex(); v->IncrementOrderIndex();
@ -1657,7 +1657,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth)
assert(v->cur_order_index < v->GetNumOrders()); assert(v->cur_order_index < v->GetNumOrders());
/* Get the current order */ /* 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; v->current_order = *order;
return UpdateOrderDest(v, order, conditional_depth + 1); return UpdateOrderDest(v, order, conditional_depth + 1);
} }
@ -1726,7 +1726,7 @@ bool ProcessOrders(Vehicle *v)
/* Get the current order */ /* Get the current order */
if (v->cur_order_index >= v->GetNumOrders()) v->cur_order_index = 0; 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 no order, do nothing. */
if (order == NULL || (v->type == VEH_AIRCRAFT && order->IsType(OT_DUMMY) && !CheckForValidOrders(v))) { if (order == NULL || (v->type == VEH_AIRCRAFT && order->IsType(OT_DUMMY) && !CheckForValidOrders(v))) {

View File

@ -470,7 +470,7 @@ private:
static void OrderClick_FullLoad(OrdersWindow *w, int load_type) static void OrderClick_FullLoad(OrdersWindow *w, int load_type)
{ {
VehicleOrderID sel_ord = w->OrderGetSel(); 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; if (order == NULL || order->GetLoadType() == load_type) return;
@ -490,7 +490,7 @@ private:
VehicleOrderID sel_ord = w->OrderGetSel(); VehicleOrderID sel_ord = w->OrderGetSel();
if (i < 0) { if (i < 0) {
const Order *order = GetVehicleOrder(w->vehicle, sel_ord); const Order *order = w->vehicle->GetOrder(sel_ord);
if (order == NULL) return; if (order == NULL) return;
i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE; i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE;
} }
@ -535,7 +535,7 @@ private:
static void OrderClick_Unload(OrdersWindow *w, int unload_type) static void OrderClick_Unload(OrdersWindow *w, int unload_type)
{ {
VehicleOrderID sel_ord = w->OrderGetSel(); 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; if (order == NULL || order->GetUnloadType() == unload_type) return;
@ -555,7 +555,7 @@ private:
static void OrderClick_Nonstop(OrdersWindow *w, int non_stop) static void OrderClick_Nonstop(OrdersWindow *w, int non_stop)
{ {
VehicleOrderID sel_ord = w->OrderGetSel(); 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; if (order == NULL || order->GetNonStopType() == non_stop) return;
@ -711,7 +711,7 @@ public:
SetVScrollCount(this, this->vehicle->GetNumOrders() + 1); SetVScrollCount(this, this->vehicle->GetNumOrders() + 1);
int sel = OrderGetSel(); int sel = OrderGetSel();
const Order *order = GetVehicleOrder(this->vehicle, sel); const Order *order = this->vehicle->GetOrder(sel);
if (this->vehicle->owner == _local_company) { if (this->vehicle->owner == _local_company) {
/* Set the strings for the dropdown boxes. */ /* Set the strings for the dropdown boxes. */
@ -824,7 +824,7 @@ public:
int y = 15; int y = 15;
int i = this->vscroll.pos; int i = this->vscroll.pos;
order = GetVehicleOrder(this->vehicle, i); order = this->vehicle->GetOrder(i);
StringID str; StringID str;
while (order != NULL) { while (order != NULL) {
/* Don't draw anything if it extends past the end of the window. */ /* Don't draw anything if it extends past the end of the window. */
@ -852,7 +852,7 @@ public:
int sel = this->GetOrderFromPt(pt.y); int sel = this->GetOrderFromPt(pt.y);
if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) { 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; TileIndex xy = INVALID_TILE;
switch (ord->GetType()) { switch (ord->GetType()) {
@ -880,7 +880,7 @@ public:
} else if (sel == this->selected_order) { } else if (sel == this->selected_order) {
if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) { if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 16), 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)); CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
} }
} else { } else {
@ -909,7 +909,7 @@ public:
break; break;
case ORDER_WIDGET_NON_STOP_DROPDOWN: { 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)); 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; } break;
@ -926,7 +926,7 @@ public:
break; break;
case ORDER_WIDGET_FULL_LOAD_DROPDOWN: 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; break;
case ORDER_WIDGET_UNLOAD: case ORDER_WIDGET_UNLOAD:
@ -934,7 +934,7 @@ public:
break; break;
case ORDER_WIDGET_UNLOAD_DROPDOWN: 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; break;
case ORDER_WIDGET_REFIT: case ORDER_WIDGET_REFIT:
@ -946,7 +946,7 @@ public:
break; break;
case ORDER_WIDGET_SERVICE_DROPDOWN: 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; break;
case ORDER_WIDGET_TIMETABLE_VIEW: case ORDER_WIDGET_TIMETABLE_VIEW:
@ -954,16 +954,16 @@ public:
break; break;
case ORDER_WIDGET_COND_VARIABLE: 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; break;
case ORDER_WIDGET_COND_COMPARATOR: { 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); ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), ORDER_WIDGET_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
} break; } break;
case ORDER_WIDGET_COND_VALUE: { 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(); uint value = order->GetConditionValue();
if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value); if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
SetDParam(0, value); SetDParam(0, value);
@ -982,7 +982,7 @@ public:
VehicleOrderID sel = this->OrderGetSel(); VehicleOrderID sel = this->OrderGetSel();
uint value = atoi(str); uint value = atoi(str);
switch (GetVehicleOrder(this->vehicle, sel)->GetConditionVariable()) { switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
case OCV_MAX_SPEED: case OCV_MAX_SPEED:
value = ConvertDisplaySpeedToSpeed(value); value = ConvertDisplaySpeedToSpeed(value);
break; break;

View File

@ -13,7 +13,7 @@
static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16 time, bool is_journey) 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; int delta;
if (is_journey) { 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; if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
VehicleOrderID order_number = GB(p1, 16, 8); 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; if (order == NULL) return CMD_ERROR;
bool packed_time = HasBit(p1, 25); bool packed_time = HasBit(p1, 25);

View File

@ -146,7 +146,7 @@ struct TimetableWindow : Window {
if (v->owner == _local_company) { if (v->owner == _local_company) {
bool disable = true; bool disable = true;
if (selected != -1) { 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) { if (selected % 2 == 1) {
disable = order != NULL && order->IsType(OT_CONDITIONAL); disable = order != NULL && order->IsType(OT_CONDITIONAL);
} else { } else {
@ -176,7 +176,7 @@ struct TimetableWindow : Window {
VehicleOrderID order_id = (i + 1) / 2; VehicleOrderID order_id = (i + 1) / 2;
bool final_order = false; bool final_order = false;
const Order *order = GetVehicleOrder(v, order_id); const Order *order = v->GetOrder(order_id);
while (order != NULL) { while (order != NULL) {
/* Don't draw anything if it extends past the end of the window. */ /* Don't draw anything if it extends past the end of the window. */
@ -188,7 +188,7 @@ struct TimetableWindow : Window {
order_id++; order_id++;
if (order_id >= v->GetNumOrders()) { if (order_id >= v->GetNumOrders()) {
order = GetVehicleOrder(v, 0); order = v->GetOrder(0);
final_order = true; final_order = true;
} else { } else {
order = order->next; order = order->next;
@ -220,7 +220,7 @@ struct TimetableWindow : Window {
uint total_time = 0; uint total_time = 0;
bool complete = true; 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; total_time += order->travel_time + order->wait_time;
if (order->travel_time == 0 && !order->IsType(OT_CONDITIONAL)) complete = false; 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; 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; if (real >= v->GetNumOrders()) real = 0;
const Order *order = GetVehicleOrder(v, real); const Order *order = v->GetOrder(real);
StringID current = STR_EMPTY; StringID current = STR_EMPTY;
if (order != NULL) { if (order != NULL) {

View File

@ -2868,7 +2868,7 @@ public:
/* Wrap around. */ /* Wrap around. */
if (this->index >= this->v->GetNumOrders()) this->index = 0; 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); assert(order != NULL);
switch (order->GetType()) { switch (order->GetType()) {

View File

@ -1021,7 +1021,7 @@ void VehicleEnterDepot(Vehicle *v)
if (v->current_order.IsType(OT_GOTO_DEPOT)) { if (v->current_order.IsType(OT_GOTO_DEPOT)) {
InvalidateWindow(WC_VEHICLE_VIEW, v->index); 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; Order t = v->current_order;
v->current_order.MakeDummy(); v->current_order.MakeDummy();

View File

@ -470,6 +470,25 @@ public:
if (this->cur_order_index >= this->GetNumOrders()) this->cur_order_index = 0; if (this->cur_order_index >= this->GetNumOrders()) this->cur_order_index = 0;
InvalidateVehicleOrder(this, 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); } ~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); void CheckVehicle32Day(Vehicle *v);
static const int32 INVALID_COORD = 0x7fffffff; static const int32 INVALID_COORD = 0x7fffffff;