diff options
-rw-r--r-- | src/autoreplace_cmd.cpp | 6 | ||||
-rw-r--r-- | src/openttd.cpp | 6 | ||||
-rw-r--r-- | src/order_base.h | 41 | ||||
-rw-r--r-- | src/order_cmd.cpp | 17 | ||||
-rw-r--r-- | src/order_gui.cpp | 6 | ||||
-rw-r--r-- | src/vehicle.cpp | 4 |
6 files changed, 55 insertions, 25 deletions
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index 59dcbddc9..bb13c7374 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -71,9 +71,9 @@ static bool VerifyAutoreplaceRefitForOrders(const Vehicle *v, const EngineID eng } FOR_VEHICLE_ORDERS(u, o) { - if (!(o->refit_cargo < NUM_CARGO)) continue; - if (!CanRefitTo(v->engine_type, o->refit_cargo)) continue; - if (!CanRefitTo(engine_type, o->refit_cargo)) return false; + if (!o->IsRefit()) continue; + if (!CanRefitTo(v->engine_type, o->GetRefitCargo())) continue; + if (!CanRefitTo(engine_type, o->GetRefitCargo())) return false; } return true; diff --git a/src/openttd.cpp b/src/openttd.cpp index 74e623a44..bbe017a35 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1987,13 +1987,11 @@ bool AfterLoadGame() Vehicle *v; FOR_ALL_ORDERS(order) { - order->refit_cargo = CT_NO_REFIT; - order->refit_subtype = CT_NO_REFIT; + order->SetRefit(CT_NO_REFIT); } FOR_ALL_VEHICLES(v) { - v->current_order.refit_cargo = CT_NO_REFIT; - v->current_order.refit_subtype = CT_NO_REFIT; + v->current_order.SetRefit(CT_NO_REFIT); } } diff --git a/src/order_base.h b/src/order_base.h index ada3aad37..8acea0069 100644 --- a/src/order_base.h +++ b/src/order_base.h @@ -31,7 +31,10 @@ private: friend Order UnpackOldOrder(uint16 packed); ///< 'Uncompressing' a loaded old order. friend Order UnpackVersion4Order(uint16 packed); ///< 'Uncompressing' a loaded ancient order. - OrderTypeByte type; + OrderTypeByte type; ///< The type of order + + CargoID refit_cargo; ///< Refit CargoID + byte refit_subtype; ///< Refit subtype public: Order *next; ///< Pointer to next order. If NULL, end of list @@ -39,9 +42,6 @@ public: uint8 flags; DestinationID dest; ///< The destionation of the order. - CargoID refit_cargo; // Refit CargoID - byte refit_subtype; // Refit subtype - uint16 wait_time; ///< How long in ticks to wait at the destination. uint16 travel_time; ///< How long in ticks the journey to this destination should take. @@ -83,8 +83,10 @@ public: * Makes this order a Go To Depot order. * @param destination the depot to go to. * @param order is this order a 'default' order, or an overriden vehicle order? + * @param cargo the cargo type to change to. + * @param subtype the subtype to change to. */ - void MakeGoToDepot(DepotID destination, bool order); + void MakeGoToDepot(DepotID destination, bool order, CargoID cargo = CT_NO_REFIT, byte subtype = 0); /** * Makes this order a Go To Waypoint order. @@ -113,6 +115,35 @@ public: */ void FreeChain(); + /** + * Is this order a refit order. + * @pre IsType(OT_GOTO_DEPOT) + * @return true if a refit should happen. + */ + inline bool IsRefit() const { return this->refit_cargo < NUM_CARGO; } + + /** + * Get the cargo to to refit to. + * @pre IsType(OT_GOTO_DEPOT) + * @return the cargo type. + */ + inline CargoID GetRefitCargo() const { return this->refit_cargo; } + + /** + * Get the cargo subtype to to refit to. + * @pre IsType(OT_GOTO_DEPOT) + * @return the cargo subtype. + */ + inline byte GetRefitSubtype() const { return this->refit_subtype; } + + /** + * Make this depot order also a refit order. + * @param cargo the cargo type to change to. + * @param subtype the subtype to change to. + * @pre IsType(OT_GOTO_DEPOT). + */ + void SetRefit(CargoID cargo, byte subtype = 0); + bool ShouldStopAtStation(const Vehicle *v, StationID station) const; /** diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index e4ebd0590..70482d453 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -55,13 +55,12 @@ void Order::MakeGoToStation(StationID destination) this->dest = destination; } -void Order::MakeGoToDepot(DepotID destination, bool order) +void Order::MakeGoToDepot(DepotID destination, bool order, CargoID cargo, byte subtype) { this->type = OT_GOTO_DEPOT; this->flags = order ? OFB_PART_OF_ORDERS : OFB_NON_STOP; this->dest = destination; - this->refit_cargo = CT_NO_REFIT; - this->refit_subtype = 0; + this->SetRefit(cargo, subtype); } void Order::MakeGoToWaypoint(WaypointID destination) @@ -88,6 +87,12 @@ void Order::MakeDummy() this->flags = 0; } +void Order::SetRefit(CargoID cargo, byte subtype) +{ + this->refit_cargo = cargo; + this->refit_subtype = subtype; +} + void Order::FreeChain() { if (next != NULL) next->FreeChain(); @@ -1002,8 +1007,7 @@ CommandCost CmdOrderRefit(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) if (flags & DC_EXEC) { Vehicle *u; - order->refit_cargo = cargo; - order->refit_subtype = subtype; + order->SetRefit(cargo, subtype); u = GetFirstVehicleFromSharedList(v); for (; u != NULL; u = u->next_shared) { @@ -1012,8 +1016,7 @@ CommandCost CmdOrderRefit(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) /* If the vehicle already got the current depot set as current order, then update current order as well */ if (u->cur_order_index == order_number && HasBit(u->current_order.flags, OF_PART_OF_ORDERS)) { - u->current_order.refit_cargo = cargo; - u->current_order.refit_subtype = subtype; + u->current_order.SetRefit(cargo, subtype); } } } diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 03cbb3e6b..00d3a1fbc 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -225,9 +225,9 @@ static void DrawOrdersWindow(Window *w) if (order->flags & OFB_FULL_LOAD) s++; /* service at */ SetDParam(1, s); - if (order->refit_cargo < NUM_CARGO) { + if (order->IsRefit()) { SetDParam(3, STR_REFIT_ORDER); - SetDParam(4, GetCargo(order->refit_cargo)->name); + SetDParam(4, GetCargo(order->GetRefitCargo())->name); } else { SetDParam(3, STR_EMPTY); } @@ -263,8 +263,6 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile) Order order; order.next = NULL; order.index = 0; - order.refit_cargo = CT_INVALID; - order.refit_subtype = 0; // check depot first if (_patches.gotodepot) { diff --git a/src/vehicle.cpp b/src/vehicle.cpp index c81baf4b6..bf3618517 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2243,11 +2243,11 @@ void VehicleEnterDepot(Vehicle *v) t = v->current_order; v->current_order.MakeDummy(); - if (t.refit_cargo < NUM_CARGO) { + if (t.IsRefit()) { CommandCost cost; _current_player = v->owner; - cost = DoCommand(v->tile, v->index, t.refit_cargo | t.refit_subtype << 8, DC_EXEC, GetCmdRefitVeh(v)); + cost = DoCommand(v->tile, v->index, t.GetRefitCargo() | t.GetRefitSubtype() << 8, DC_EXEC, GetCmdRefitVeh(v)); if (CmdFailed(cost)) { v->leave_depot_instantly = false; // We ensure that the vehicle stays in the depot |