summaryrefslogtreecommitdiff
path: root/src/vehicle_base.h
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-08-17 19:56:17 +0000
committerrubidium <rubidium@openttd.org>2008-08-17 19:56:17 +0000
commitabd9f748715c3f1278d54637c725e18d5cbe5bd5 (patch)
treea82f738989c2591bdcb5d757a2d2cc647a67f8c5 /src/vehicle_base.h
parentca3f1f64068e28109a5b6d62f88ef5f18f581856 (diff)
downloadopenttd-abd9f748715c3f1278d54637c725e18d5cbe5bd5.tar.xz
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
Diffstat (limited to 'src/vehicle_base.h')
-rw-r--r--src/vehicle_base.h48
1 files changed, 31 insertions, 17 deletions
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index c2e9161f7..d0bc4188c 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -202,6 +202,10 @@ private:
Vehicle *next; ///< pointer to the next vehicle in the chain
Vehicle *previous; ///< NOSAVE: pointer to the previous vehicle in the chain
Vehicle *first; ///< NOSAVE: pointer to the first vehicle in the chain
+
+ Vehicle *next_shared; ///< pointer to the next vehicle that shares the order
+ Vehicle *previous_shared; ///< NOSAVE: pointer to the previous vehicle in the shared order chain
+ Vehicle *first_shared; ///< NOSAVE: pointer to the first vehicle in the shared order chain
public:
friend const SaveLoad *GetVehicleDescription(VehicleType vt); ///< So we can use private/protected variables in the saveload code
friend void AfterLoadVehicles(bool clear_te_id); ///< So we can set the previous and first pointers while loading
@@ -214,9 +218,6 @@ public:
TileIndex tile; ///< Current tile index
TileIndex dest_tile; ///< Heading for this tile
- Vehicle *next_shared; ///< If not NULL, this points to the next vehicle that shared the order
- Vehicle *prev_shared; ///< If not NULL, this points to the prev vehicle that shared the order
-
Money profit_this_year; ///< Profit this year << 8, low 8 bits are fract
Money profit_last_year; ///< Profit last year << 8, low 8 bits are fract
Money value;
@@ -476,12 +477,37 @@ public:
*/
inline Vehicle *First() const { return this->first; }
+
+ /**
+ * Adds this vehicle to a shared vehicle chain.
+ * @param shared_chain a vehicle of the chain with shared vehicles.
+ * @pre !this->IsOrderListShared()
+ */
+ void AddToShared(Vehicle *shared_chain);
+
+ /**
+ * Removes the vehicle from the shared order list.
+ */
+ void RemoveFromShared();
+
+ /**
+ * Get the next vehicle of this vehicle.
+ * @note articulated parts are also counted as vehicles.
+ * @return the next vehicle or NULL when there isn't a next vehicle.
+ */
+ inline Vehicle *NextShared() const { return this->next_shared; }
+
+ /**
+ * Get the first vehicle of this vehicle chain.
+ * @return the first vehicle of the chain.
+ */
+ inline Vehicle *FirstShared() const { return this->first_shared; }
+
/**
* 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; };
+ inline bool IsOrderListShared() const { return this->previous_shared != NULL || this->next_shared != NULL; };
/**
* Copy certain configurations and statistics of a vehicle after successful autoreplace/renew
@@ -648,18 +674,6 @@ static inline Order *GetLastVehicleOrder(const Vehicle *v)
return order;
}
-/** Get the first vehicle of a shared-list, so we only have to walk forwards
- * @param v Vehicle to query
- * @return first vehicle of a shared-list
- */
-static inline Vehicle *GetFirstVehicleFromSharedList(const Vehicle *v)
-{
- Vehicle *u = (Vehicle *)v;
- while (u->prev_shared != NULL) u = u->prev_shared;
-
- return u;
-}
-
/**
* Returns the Trackdir on which the vehicle is currently located.
* Works for trains and ships.