src/vehicle.h
changeset 7993 76b0eb3e19c9
parent 7989 116c8f9769af
child 8033 f80315b59db1
equal deleted inserted replaced
7992:8ac3fcd8d570 7993:76b0eb3e19c9
   217 
   217 
   218 struct Vehicle;
   218 struct Vehicle;
   219 DECLARE_OLD_POOL(Vehicle, Vehicle, 9, 125)
   219 DECLARE_OLD_POOL(Vehicle, Vehicle, 9, 125)
   220 
   220 
   221 struct SaveLoad;
   221 struct SaveLoad;
   222 extern const SaveLoad *GetVehicleDescription(VehicleType vt);
   222 const SaveLoad *GetVehicleDescription(VehicleType vt);
       
   223 void AfterLoadVehicles();
   223 
   224 
   224 struct Vehicle : PoolItem<Vehicle, VehicleID, &_Vehicle_pool> {
   225 struct Vehicle : PoolItem<Vehicle, VehicleID, &_Vehicle_pool> {
   225 	VehicleTypeByte type;    ///< Type of vehicle
   226 	VehicleTypeByte type;    ///< Type of vehicle
   226 	byte subtype;            // subtype (Filled with values from EffectVehicles/TrainSubTypes/AircraftSubTypes)
   227 	byte subtype;            // subtype (Filled with values from EffectVehicles/TrainSubTypes/AircraftSubTypes)
   227 
   228 
   228 private:
   229 private:
   229 	Vehicle *next;           // pointer to the next vehicle in the chain
   230 	Vehicle *next;           // pointer to the next vehicle in the chain
       
   231 	Vehicle *previous;       // NOSAVE: pointer to the previous vehicle in the chain
       
   232 	Vehicle *first;          // NOSAVE: pointer to the first vehicle in the chain
   230 public:
   233 public:
   231 	friend const SaveLoad *GetVehicleDescription(VehicleType vt); // So we can use private/protected variables in the saveload code
   234 	friend const SaveLoad *GetVehicleDescription(VehicleType vt); // So we can use private/protected variables in the saveload code
   232 
   235 	friend void AfterLoadVehicles();
   233 	Vehicle *first;          // NOSAVE: pointer to the first vehicle in the chain
   236 
   234 	Vehicle *depot_list;     // NOSAVE: linked list to tell what vehicles entered a depot during the last tick. Used by autoreplace
   237 	Vehicle *depot_list;     // NOSAVE: linked list to tell what vehicles entered a depot during the last tick. Used by autoreplace
   235 
   238 
   236 	StringID string_id;      // Displayed string
   239 	StringID string_id;      // Displayed string
   237 
   240 
   238 	UnitID unitnumber;       // unit number, for display purposes only
   241 	UnitID unitnumber;       // unit number, for display purposes only
   470 
   473 
   471 	/**
   474 	/**
   472 	 * Set the next vehicle of this vehicle.
   475 	 * Set the next vehicle of this vehicle.
   473 	 * @param next the next vehicle. NULL removes the next vehicle.
   476 	 * @param next the next vehicle. NULL removes the next vehicle.
   474 	 */
   477 	 */
   475 	void SetNext(Vehicle *next) { this->next = next; }
   478 	void SetNext(Vehicle *next);
   476 
   479 
   477 	/**
   480 	/**
   478 	 * Get the next vehicle of this vehicle.
   481 	 * Get the next vehicle of this vehicle.
   479 	 * @note articulated parts are also counted as vehicles.
   482 	 * @note articulated parts are also counted as vehicles.
   480 	 * @return the next vehicle or NULL when there isn't a next vehicle.
   483 	 * @return the next vehicle or NULL when there isn't a next vehicle.
   481 	 */
   484 	 */
   482 	inline Vehicle *Next() const { return this->next; }
   485 	inline Vehicle *Next() const { return this->next; }
       
   486 
       
   487 	/**
       
   488 	 * Get the previous vehicle of this vehicle.
       
   489 	 * @note articulated parts are also counted as vehicles.
       
   490 	 * @return the previous vehicle or NULL when there isn't a previous vehicle.
       
   491 	 */
       
   492 	inline Vehicle *Previous() const { return this->previous; }
       
   493 
       
   494 	/**
       
   495 	 * Get the first vehicle of this vehicle chain.
       
   496 	 * @return the first vehicle of the chain.
       
   497 	 */
       
   498 	inline Vehicle *First() const { return this->first; }
   483 };
   499 };
   484 
   500 
   485 /**
   501 /**
   486  * This class 'wraps' Vehicle; you do not actually instantiate this class.
   502  * This class 'wraps' Vehicle; you do not actually instantiate this class.
   487  * You create a Vehicle using AllocateVehicle, so it is added to the pool
   503  * You create a Vehicle using AllocateVehicle, so it is added to the pool
   554 
   570 
   555 typedef void *VehicleFromPosProc(Vehicle *v, void *data);
   571 typedef void *VehicleFromPosProc(Vehicle *v, void *data);
   556 
   572 
   557 void VehicleServiceInDepot(Vehicle *v);
   573 void VehicleServiceInDepot(Vehicle *v);
   558 void VehiclePositionChanged(Vehicle *v);
   574 void VehiclePositionChanged(Vehicle *v);
   559 void AfterLoadVehicles();
       
   560 Vehicle *GetLastVehicleInChain(Vehicle *v);
   575 Vehicle *GetLastVehicleInChain(Vehicle *v);
   561 Vehicle *GetPrevVehicleInChain(const Vehicle *v);
       
   562 Vehicle *GetFirstVehicleInChain(const Vehicle *v);
       
   563 uint CountVehiclesInChain(const Vehicle *v);
   576 uint CountVehiclesInChain(const Vehicle *v);
   564 bool IsEngineCountable(const Vehicle *v);
   577 bool IsEngineCountable(const Vehicle *v);
   565 void DeleteVehicleChain(Vehicle *v);
   578 void DeleteVehicleChain(Vehicle *v);
   566 void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
   579 void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
   567 void *VehicleFromPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
   580 void *VehicleFromPosXY(int x, int y, void *data, VehicleFromPosProc *proc);