diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/newgrf_engine.cpp | 2 | ||||
-rw-r--r-- | src/order_cmd.cpp | 40 | ||||
-rw-r--r-- | src/order_gui.cpp | 22 | ||||
-rw-r--r-- | src/timetable_gui.cpp | 16 | ||||
-rw-r--r-- | src/train_cmd.cpp | 6 | ||||
-rw-r--r-- | src/vehicle_base.h | 6 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 2 |
7 files changed, 50 insertions, 44 deletions
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index 75a082429..876ce6cb0 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -655,7 +655,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by case 0x05: return GB(v->index, 8, 8); case 0x0A: return v->current_order.Pack(); case 0x0B: return GB(v->current_order.Pack(), 8, 8); - case 0x0C: return v->num_orders; + case 0x0C: return v->GetNumOrders(); case 0x0D: return v->cur_order_index; case 0x10: return v->load_unload_time_rem; case 0x11: return GB(v->load_unload_time_rem, 8, 8); diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 6f5b5d55e..d97eeadec 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -310,7 +310,7 @@ static TileIndex GetOrderLocation(const Order& o) static uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth = 0) { if (cur->IsType(OT_CONDITIONAL)) { - if (conditional_depth > v->num_orders) return 0; + if (conditional_depth > v->GetNumOrders()) return 0; conditional_depth++; @@ -464,7 +464,7 @@ CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, c case OT_CONDITIONAL: { VehicleOrderID skip_to = new_order.GetConditionSkipToOrder(); - if (skip_to != 0 && skip_to >= v->num_orders) return CMD_ERROR; // Always allow jumping to the first (even when there is no order). + if (skip_to != 0 && skip_to >= v->GetNumOrders()) return CMD_ERROR; // Always allow jumping to the first (even when there is no order). if (new_order.GetConditionVariable() > OCV_END) return CMD_ERROR; OrderConditionComparator occ = new_order.GetConditionComparator(); @@ -492,7 +492,7 @@ CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, c default: return CMD_ERROR; } - if (sel_ord > v->num_orders) return CMD_ERROR; + if (sel_ord > v->GetNumOrders()) return CMD_ERROR; if (!Order::CanAllocateItem()) return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS); @@ -563,7 +563,7 @@ CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, c if (sel_ord <= u->cur_order_index) { uint cur = u->cur_order_index + 1; /* Check if we don't go out of bound */ - if (cur < u->num_orders) + if (cur < u->GetNumOrders()) u->cur_order_index = cur; } /* Update any possible open window of the vehicle */ @@ -580,7 +580,7 @@ CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, c order->SetConditionSkipToOrder(order_id + 1); } if (order_id == cur_order_id) { - order->SetConditionSkipToOrder((order_id + 1) % v->num_orders); + order->SetConditionSkipToOrder((order_id + 1) % v->GetNumOrders()); } } cur_order_id++; @@ -627,7 +627,7 @@ CommandCost CmdDeleteOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, c if (!CheckOwnership(v->owner)) return CMD_ERROR; /* If we did not select an order, we maybe want to de-clone the orders */ - if (sel_ord >= v->num_orders) + if (sel_ord >= v->GetNumOrders()) return DecloneOrder(v, flags); order = GetVehicleOrder(v, sel_ord); @@ -685,7 +685,7 @@ CommandCost CmdDeleteOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, c order->SetConditionSkipToOrder(max(order_id - 1, 0)); } if (order_id == cur_order_id) { - order->SetConditionSkipToOrder((order_id + 1) % v->num_orders); + order->SetConditionSkipToOrder((order_id + 1) % v->GetNumOrders()); } } cur_order_id++; @@ -714,7 +714,7 @@ CommandCost CmdSkipToOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, c v = GetVehicle(veh_id); if (!CheckOwnership(v->owner) || sel_ord == v->cur_order_index || - sel_ord >= v->num_orders || v->num_orders < 2) return CMD_ERROR; + sel_ord >= v->GetNumOrders() || v->GetNumOrders() < 2) return CMD_ERROR; if (flags & DC_EXEC) { v->cur_order_index = sel_ord; @@ -755,8 +755,8 @@ CommandCost CmdMoveOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, con if (!CheckOwnership(v->owner)) return CMD_ERROR; /* Don't make senseless movements */ - if (moving_order >= v->num_orders || target_order >= v->num_orders || - moving_order == target_order || v->num_orders <= 1) + if (moving_order >= v->GetNumOrders() || target_order >= v->GetNumOrders() || + moving_order == target_order || v->GetNumOrders() <= 1) return CMD_ERROR; Order *moving_one = GetVehicleOrder(v, moving_order); @@ -861,7 +861,7 @@ CommandCost CmdModifyOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, c if (!CheckOwnership(v->owner)) return CMD_ERROR; /* Is it a valid order? */ - if (sel_ord >= v->num_orders) return CMD_ERROR; + if (sel_ord >= v->GetNumOrders()) return CMD_ERROR; Order *order = GetVehicleOrder(v, sel_ord); switch (order->GetType()) { @@ -945,7 +945,7 @@ CommandCost CmdModifyOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, c break; case MOF_COND_DESTINATION: - if (data >= v->num_orders) return CMD_ERROR; + if (data >= v->GetNumOrders()) return CMD_ERROR; break; } @@ -1102,7 +1102,7 @@ CommandCost CmdCloneOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, co DeleteVehicleOrders(dst); dst->orders = src->orders; - dst->num_orders = src->num_orders; + dst->num_orders = src->GetNumOrders(); /* Link this vehicle in the shared-list */ dst->AddToShared(src); @@ -1147,7 +1147,7 @@ CommandCost CmdCloneOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, co } /* make sure there are orders available */ - delta = dst->IsOrderListShared() ? src->num_orders + 1 : src->num_orders - dst->num_orders; + delta = dst->IsOrderListShared() ? src->GetNumOrders() + 1 : src->GetNumOrders() - dst->GetNumOrders(); if (!Order::CanAllocateItem(delta)) { return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS); } @@ -1166,7 +1166,7 @@ CommandCost CmdCloneOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, co order_dst = &(*order_dst)->next; } - dst->num_orders = src->num_orders; + dst->num_orders = src->GetNumOrders(); InvalidateVehicleOrder(dst, -1); @@ -1358,7 +1358,7 @@ CommandCost CmdRestoreOrderIndex(TileIndex tile, uint32 flags, uint32 p1, uint32 /* Check the vehicle type and ownership, and if the service interval and order are in range */ if (!CheckOwnership(v->owner)) return CMD_ERROR; - if (serv_int != GetServiceIntervalClamped(serv_int) || cur_ord >= v->num_orders) return CMD_ERROR; + if (serv_int != GetServiceIntervalClamped(serv_int) || cur_ord >= v->GetNumOrders()) return CMD_ERROR; if (flags & DC_EXEC) { v->cur_order_index = cur_ord; @@ -1432,7 +1432,7 @@ void CheckOrders(const Vehicle* v) } /* Check if the last and the first order are the same */ - if (v->num_orders > 1) { + if (v->GetNumOrders() > 1) { const Order* last = GetLastVehicleOrder(v); if (v->orders->Equals(*last)) { @@ -1657,7 +1657,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth) break; case OT_CONDITIONAL: { - if (conditional_depth > v->num_orders) return false; + if (conditional_depth > v->GetNumOrders()) return false; VehicleOrderID next_order = ProcessConditionalOrder(order, v); if (next_order != INVALID_VEH_ORDER_ID) { @@ -1670,7 +1670,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth) } /* Get the current order */ - if (v->cur_order_index >= v->num_orders) 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); v->current_order = *order; @@ -1739,7 +1739,7 @@ bool ProcessOrders(Vehicle *v) } /* Get the current order */ - if (v->cur_order_index >= v->num_orders) 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); diff --git a/src/order_gui.cpp b/src/order_gui.cpp index e31114b45..a3a69d8a1 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -393,7 +393,7 @@ private: int OrderGetSel() { int num = this->selected_order; - return (num >= 0 && num < vehicle->num_orders) ? num : vehicle->num_orders; + return (num >= 0 && num < vehicle->GetNumOrders()) ? num : vehicle->GetNumOrders(); } /** @@ -419,7 +419,7 @@ private: sel += this->vscroll.pos; - return (sel <= vehicle->num_orders && sel >= 0) ? sel : INVALID_ORDER; + return (sel <= vehicle->GetNumOrders() && sel >= 0) ? sel : INVALID_ORDER; } bool HandleOrderVehClick(const Vehicle *u) @@ -433,7 +433,7 @@ private: /* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet * obviously if you press CTRL on a non-empty orders vehicle you know what you are doing */ - if (this->vehicle->num_orders != 0 && _ctrl_pressed == 0) return false; + if (this->vehicle->GetNumOrders() != 0 && _ctrl_pressed == 0) return false; if (DoCommandP(this->vehicle->tile, this->vehicle->index | (u->index << 16), _ctrl_pressed ? CO_SHARE : CO_COPY, _ctrl_pressed ? CMD_CLONE_ORDER | CMD_MSG(STR_CANT_SHARE_ORDER_LIST) : CMD_CLONE_ORDER | CMD_MSG(STR_CANT_COPY_ORDER_LIST))) { @@ -579,9 +579,9 @@ private: { /* Don't skip when there's nothing to skip */ if (_ctrl_pressed && w->vehicle->cur_order_index == w->OrderGetSel()) return; - if (w->vehicle->num_orders <= 1) return; + if (w->vehicle->GetNumOrders() <= 1) return; - DoCommandP(w->vehicle->tile, w->vehicle->index, _ctrl_pressed ? w->OrderGetSel() : ((w->vehicle->cur_order_index + 1) % w->vehicle->num_orders), + DoCommandP(w->vehicle->tile, w->vehicle->index, _ctrl_pressed ? w->OrderGetSel() : ((w->vehicle->cur_order_index + 1) % w->vehicle->GetNumOrders()), CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_CAN_T_SKIP_TO_ORDER : STR_CAN_T_SKIP_ORDER)); } @@ -596,7 +596,7 @@ private: int selected = w->selected_order + (int)_networking; if (DoCommandP(w->vehicle->tile, w->vehicle->index, w->OrderGetSel(), CMD_DELETE_ORDER | CMD_MSG(STR_8834_CAN_T_DELETE_THIS_ORDER))) { - w->selected_order = selected >= w->vehicle->num_orders ? -1 : selected; + w->selected_order = selected >= w->vehicle->GetNumOrders() ? -1 : selected; } } @@ -692,7 +692,7 @@ public: { bool shared_orders = this->vehicle->IsOrderListShared(); - SetVScrollCount(this, this->vehicle->num_orders + 1); + SetVScrollCount(this, this->vehicle->GetNumOrders() + 1); int sel = OrderGetSel(); const Order *order = GetVehicleOrder(this->vehicle, sel); @@ -703,11 +703,11 @@ public: this->widget[ORDER_WIDGET_COND_COMPARATOR].data = _order_conditional_condition[order == NULL ? 0 : order->GetConditionComparator()]; /* skip */ - this->SetWidgetDisabledState(ORDER_WIDGET_SKIP, this->vehicle->num_orders <= 1); + this->SetWidgetDisabledState(ORDER_WIDGET_SKIP, this->vehicle->GetNumOrders() <= 1); /* delete */ this->SetWidgetDisabledState(ORDER_WIDGET_DELETE, - (uint)this->vehicle->num_orders + ((shared_orders || this->vehicle->num_orders != 0) ? 1 : 0) <= (uint)this->selected_order); + (uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order); /* non-stop only for trains */ this->SetWidgetDisabledState(ORDER_WIDGET_NON_STOP, (this->vehicle->type != VEH_TRAIN && this->vehicle->type != VEH_ROAD) || order == NULL); @@ -836,7 +836,7 @@ public: int sel = this->GetOrderFromPt(pt.y); - if (_ctrl_pressed && sel < this->vehicle->num_orders) { + if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) { const Order *ord = GetVehicleOrder(this->vehicle, sel); TileIndex xy = 0; @@ -1022,7 +1022,7 @@ public: int from_order = this->OrderGetSel(); int to_order = this->GetOrderFromPt(pt.y); - if (!(from_order == to_order || from_order == INVALID_ORDER || from_order > this->vehicle->num_orders || to_order == INVALID_ORDER || to_order > this->vehicle->num_orders) && + if (!(from_order == to_order || from_order == INVALID_ORDER || from_order > this->vehicle->GetNumOrders() || to_order == INVALID_ORDER || to_order > this->vehicle->GetNumOrders()) && DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_CAN_T_MOVE_THIS_ORDER))) { this->selected_order = -1; } diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 416bc7410..4097788d8 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -75,7 +75,7 @@ struct TimetableWindow : Window { sel += this->vscroll.pos; - return (sel < v->num_orders * 2 && sel >= 0) ? sel : INVALID_ORDER; + return (sel < v->GetNumOrders() * 2 && sel >= 0) ? sel : INVALID_ORDER; } virtual void OnInvalidateData(int data) @@ -105,7 +105,7 @@ struct TimetableWindow : Window { if (from == to) break; // no need to change anything /* if from == INVALID_VEH_ORDER_ID, one order was added; if to == INVALID_VEH_ORDER_ID, one order was removed */ - uint old_num_orders = this->vehicle->num_orders - (uint)(from == INVALID_VEH_ORDER_ID) + (uint)(to == INVALID_VEH_ORDER_ID); + uint old_num_orders = this->vehicle->GetNumOrders() - (uint)(from == INVALID_VEH_ORDER_ID) + (uint)(to == INVALID_VEH_ORDER_ID); VehicleOrderID selected_order = (this->sel_index + 1) / 2; if (selected_order == old_num_orders) selected_order = 0; // when last travel time is selected, it belongs to order 0 @@ -133,7 +133,7 @@ struct TimetableWindow : Window { /* recompute new sel_index */ this->sel_index = 2 * selected_order - (int)travel; /* travel time of first order needs special handling */ - if (this->sel_index == -1) this->sel_index = this->vehicle->num_orders * 2 - 1; + if (this->sel_index == -1) this->sel_index = this->vehicle->GetNumOrders() * 2 - 1; } break; } } @@ -144,12 +144,12 @@ struct TimetableWindow : Window { const Vehicle *v = this->vehicle; int selected = this->sel_index; - SetVScrollCount(this, v->num_orders * 2); + SetVScrollCount(this, v->GetNumOrders() * 2); if (v->owner == _local_company) { bool disable = true; if (selected != -1) { - const Order *order = GetVehicleOrder(v, ((selected + 1) / 2) % v->num_orders); + const Order *order = GetVehicleOrder(v, ((selected + 1) / 2) % v->GetNumOrders()); if (selected % 2 == 1) { disable = order != NULL && order->IsType(OT_CONDITIONAL); } else { @@ -190,7 +190,7 @@ struct TimetableWindow : Window { order_id++; - if (order_id >= v->num_orders) { + if (order_id >= v->GetNumOrders()) { order = GetVehicleOrder(v, 0); final_order = true; } else { @@ -249,7 +249,7 @@ struct TimetableWindow : Window { uint order_number = (selected + 1) / 2; uint is_journey = (selected % 2 == 1) ? 1 : 0; - if (order_number >= v->num_orders) order_number = 0; + if (order_number >= v->GetNumOrders()) order_number = 0; return v->index | (order_number << 16) | (is_journey << 24); } @@ -274,7 +274,7 @@ struct TimetableWindow : Window { int selected = this->sel_index; VehicleOrderID real = (selected + 1) / 2; - if (real >= v->num_orders) real = 0; + if (real >= v->GetNumOrders()) real = 0; const Order *order = GetVehicleOrder(v, real); StringID current = STR_EMPTY; diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index cd085c0d2..e5a2e75f1 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1454,7 +1454,7 @@ CommandCost CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, /* Copy orders (by sharing) */ new_f->orders = first->orders; - new_f->num_orders = first->num_orders; + new_f->num_orders = first->GetNumOrders(); new_f->AddToShared(first); DeleteVehicleOrders(first); @@ -2360,7 +2360,7 @@ static void CheckNextTrainTile(Vehicle *v) /* Exit if we are on a station tile and are going to stop. */ if (IsRailwayStationTile(v->tile) && v->current_order.ShouldStopAtStation(v, GetStationIndex(v->tile))) return; /* Exit if the current order doesn't have a destination, but the train has orders. */ - if ((v->current_order.IsType(OT_NOTHING) || v->current_order.IsType(OT_LEAVESTATION)) && v->num_orders > 0) return; + if ((v->current_order.IsType(OT_NOTHING) || v->current_order.IsType(OT_LEAVESTATION)) && v->GetNumOrders() > 0) return; Trackdir td = GetVehicleTrackdir(v); @@ -2853,7 +2853,7 @@ public: do { /* Wrap around. */ - if (this->index >= this->v->num_orders) this->index = 0; + if (this->index >= this->v->GetNumOrders()) this->index = 0; Order *order = GetVehicleOrder(this->v, this->index); assert(order != NULL); diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 15f2df1aa..e49219ddb 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -512,6 +512,12 @@ public: */ inline bool IsOrderListShared() const { return this->previous_shared != NULL || this->next_shared != NULL; }; + /** + * Get the number of orders this vehicle has. + * @return the number of orders this vehicle has. + */ + inline VehicleOrderID GetNumOrders() const { return this->num_orders; } + /** * Copy certain configurations and statistics of a vehicle after successful autoreplace/renew * The function shall copy everything that cannot be copied by a command (like orders / group etc), diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 5c0136390..6f5df3e62 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1926,7 +1926,7 @@ struct VehicleViewWindow : Window { /* fall-through if aircraft. Does this even happen? */ default: - if (v->num_orders == 0) { + if (v->GetNumOrders() == 0) { str = STR_NO_ORDERS + _settings_client.gui.vehicle_speed; SetDParam(0, v->GetDisplaySpeed()); } else { |