From fc4f6dcfb1a31568a988f217cfa3bed194351318 Mon Sep 17 00:00:00 2001 From: belugas Date: Sat, 2 Feb 2008 02:45:09 +0000 Subject: (svn r12040) -Codechange: Change IsOrderListShared from a simple function to a class member(MagicBuzz). --- src/autoreplace_cmd.cpp | 2 +- src/order.h | 1 - src/order_cmd.cpp | 17 +++-------------- src/order_gui.cpp | 2 +- src/vehicle_base.h | 7 +++++++ 5 files changed, 12 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index b451be8de..57083e1ab 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -215,7 +215,7 @@ static CommandCost ReplaceVehicle(Vehicle **w, byte flags, Money total_cost) DoCommand(0, (front->index << 16) | new_v->index, 1, DC_EXEC, CMD_MOVE_RAIL_VEHICLE); } else { // copy/clone the orders - DoCommand(0, (old_v->index << 16) | new_v->index, IsOrderListShared(old_v) ? CO_SHARE : CO_COPY, DC_EXEC, CMD_CLONE_ORDER); + DoCommand(0, (old_v->index << 16) | new_v->index, old_v->IsOrderListShared() ? CO_SHARE : CO_COPY, DC_EXEC, CMD_CLONE_ORDER); new_v->cur_order_index = old_v->cur_order_index; ChangeVehicleViewWindow(old_v, new_v); new_v->profit_this_year = old_v->profit_this_year; diff --git a/src/order.h b/src/order.h index e961cec80..350d8c563 100644 --- a/src/order.h +++ b/src/order.h @@ -212,7 +212,6 @@ void InvalidateVehicleOrder(const Vehicle *v); bool VehicleHasDepotOrders(const Vehicle *v); void CheckOrders(const Vehicle*); void DeleteVehicleOrders(Vehicle *v); -bool IsOrderListShared(const Vehicle *v); void AssignOrder(Order *order, Order data); bool CheckForValidOrders(const Vehicle* v); diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 0c0259705..770c91880 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -837,7 +837,7 @@ CommandCost CmdCloneOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) } /* make sure there are orders available */ - delta = IsOrderListShared(dst) ? src->num_orders + 1 : src->num_orders - dst->num_orders; + delta = dst->IsOrderListShared() ? src->num_orders + 1 : src->num_orders - dst->num_orders; if (!HasOrderPoolFree(delta)) return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS); @@ -939,7 +939,7 @@ void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *bak) if (v->name != NULL) bak->name = strdup(v->name); /* If we have shared orders, store it on a special way */ - if (IsOrderListShared(v)) { + if (v->IsOrderListShared()) { const Vehicle *u = (v->next_shared) ? v->next_shared : v->prev_shared; bak->clone = u->index; @@ -1209,7 +1209,7 @@ void DeleteVehicleOrders(Vehicle *v) /* If we have a shared order-list, don't delete the list, but just remove our pointer */ - if (IsOrderListShared(v)) { + if (v->IsOrderListShared()) { Vehicle *u = v; v->orders = NULL; @@ -1257,17 +1257,6 @@ Date GetServiceIntervalClamped(uint index) return (_patches.servint_ispercent) ? Clamp(index, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : Clamp(index, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS); } -/** - * - * Check if we share our orders with an other vehicle - * - * @return Returns the vehicle who has the same order - * - */ -bool IsOrderListShared(const Vehicle *v) -{ - return v->next_shared != NULL || v->prev_shared != NULL; -} /** * diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 78d44603a..6a05adf77 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -120,7 +120,7 @@ static void DrawOrdersWindow(Window *w) v = GetVehicle(w->window_number); - shared_orders = IsOrderListShared(v); + shared_orders = v->IsOrderListShared(); SetVScrollCount(w, v->num_orders + 1); diff --git a/src/vehicle_base.h b/src/vehicle_base.h index cce77aa4d..a19b80dfb 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -461,6 +461,13 @@ public: * @return the first vehicle of the chain. */ inline Vehicle *First() const { return this->first; } + + /** + * Check if we share our orders with another vehicle. + * This is done by checking the previous and next pointers in the shared chain. + * @return true if there are other vehicles sharing the same order + */ + inline bool IsOrderListShared() const { return this->next_shared != NULL || this->prev_shared != NULL; }; }; /** -- cgit v1.2.3-70-g09d2