src/vehicle.h
branchNewGRF_ports
changeset 6868 7eb395287b3d
parent 6800 6c09e1e86fcb
child 6870 ca3fd1fbe311
equal deleted inserted replaced
6867:a4ad48192617 6868:7eb395287b3d
   218 };
   218 };
   219 
   219 
   220 struct Vehicle;
   220 struct Vehicle;
   221 DECLARE_OLD_POOL(Vehicle, Vehicle, 9, 125)
   221 DECLARE_OLD_POOL(Vehicle, Vehicle, 9, 125)
   222 
   222 
       
   223 struct SaveLoad;
       
   224 const SaveLoad *GetVehicleDescription(VehicleType vt);
       
   225 void AfterLoadVehicles();
       
   226 
   223 struct Vehicle : PoolItem<Vehicle, VehicleID, &_Vehicle_pool> {
   227 struct Vehicle : PoolItem<Vehicle, VehicleID, &_Vehicle_pool> {
   224 	VehicleTypeByte type;    ///< Type of vehicle
   228 	VehicleTypeByte type;    ///< Type of vehicle
   225 	byte subtype;            // subtype (Filled with values from EffectVehicles/TrainSubTypes/AircraftSubTypes)
   229 	byte subtype;            // subtype (Filled with values from EffectVehicles/TrainSubTypes/AircraftSubTypes)
   226 
   230 
   227 	Vehicle *next;           // next
   231 private:
       
   232 	Vehicle *next;           // pointer to the next vehicle in the chain
       
   233 	Vehicle *previous;       // NOSAVE: pointer to the previous vehicle in the chain
   228 	Vehicle *first;          // NOSAVE: pointer to the first vehicle in the chain
   234 	Vehicle *first;          // NOSAVE: pointer to the first vehicle in the chain
   229 	Vehicle *depot_list;     //NOSAVE: linked list to tell what vehicles entered a depot during the last tick. Used by autoreplace
   235 public:
       
   236 	friend const SaveLoad *GetVehicleDescription(VehicleType vt); // So we can use private/protected variables in the saveload code
       
   237 	friend void AfterLoadVehicles();
       
   238 
       
   239 	Vehicle *depot_list;     // NOSAVE: linked list to tell what vehicles entered a depot during the last tick. Used by autoreplace
   230 
   240 
   231 	StringID string_id;      // Displayed string
   241 	StringID string_id;      // Displayed string
   232 
   242 
   233 	UnitID unitnumber;       // unit number, for display purposes only
   243 	UnitID unitnumber;       // unit number, for display purposes only
   234 	PlayerByte owner;        // which player owns the vehicle?
   244 	PlayerByte owner;        // which player owns the vehicle?
   415 	 * @return the sprite for the given vehicle in the given direction
   425 	 * @return the sprite for the given vehicle in the given direction
   416 	 */
   426 	 */
   417 	virtual int GetImage(Direction direction) const { return 0; }
   427 	virtual int GetImage(Direction direction) const { return 0; }
   418 
   428 
   419 	/**
   429 	/**
       
   430 	 * Gets the speed in mph that can be sent into SetDParam for string processing.
       
   431 	 * @return the vehicle's speed
       
   432 	 */
       
   433 	virtual int GetDisplaySpeed() const { return 0; }
       
   434 
       
   435 	/**
       
   436 	 * Gets the maximum speed in mph that can be sent into SetDParam for string processing.
       
   437 	 * @return the vehicle's maximum speed
       
   438 	 */
       
   439 	virtual int GetDisplayMaxSpeed() const { return 0; }
       
   440 
       
   441 	/**
       
   442 	 * Gets the running cost of a vehicle
       
   443 	 * @return the vehicle's running cost
       
   444 	 */
       
   445 	virtual Money GetRunningCost() const { return 0; }
       
   446 
       
   447 	/**
       
   448 	 * Check whether the vehicle is in the depot.
       
   449 	 * @return true if and only if the vehicle is in the depot.
       
   450 	 */
       
   451 	virtual bool IsInDepot() const { return false; }
       
   452 
       
   453 	/**
       
   454 	 * Check whether the vehicle is in the depot *and* stopped.
       
   455 	 * @return true if and only if the vehicle is in the depot and stopped.
       
   456 	 */
       
   457 	virtual bool IsStoppedInDepot() const { return this->IsInDepot() && (this->vehstatus & VS_STOPPED) != 0; }
       
   458 
       
   459 	/**
   420 	 * Calls the tick handler of the vehicle
   460 	 * Calls the tick handler of the vehicle
   421 	 */
   461 	 */
   422 	virtual void Tick() {};
   462 	virtual void Tick() {};
   423 
   463 
   424 	bool IsValid() const { return this->type != VEH_INVALID; }
   464 	/**
       
   465 	 * Gets the running cost of a vehicle  that can be sent into SetDParam for string processing.
       
   466 	 * @return the vehicle's running cost
       
   467 	 */
       
   468 	Money GetDisplayRunningCost() const { return (this->GetRunningCost() >> 8); }
       
   469 
       
   470 	/**
       
   471 	 * Is this vehicle a valid vehicle?
       
   472 	 * @return true if and only if the vehicle is valid.
       
   473 	 */
       
   474 	inline bool IsValid() const { return this->type != VEH_INVALID; }
       
   475 
       
   476 	/**
       
   477 	 * Set the next vehicle of this vehicle.
       
   478 	 * @param next the next vehicle. NULL removes the next vehicle.
       
   479 	 */
       
   480 	void SetNext(Vehicle *next);
       
   481 
       
   482 	/**
       
   483 	 * Get the next vehicle of this vehicle.
       
   484 	 * @note articulated parts are also counted as vehicles.
       
   485 	 * @return the next vehicle or NULL when there isn't a next vehicle.
       
   486 	 */
       
   487 	inline Vehicle *Next() const { return this->next; }
       
   488 
       
   489 	/**
       
   490 	 * Get the previous vehicle of this vehicle.
       
   491 	 * @note articulated parts are also counted as vehicles.
       
   492 	 * @return the previous vehicle or NULL when there isn't a previous vehicle.
       
   493 	 */
       
   494 	inline Vehicle *Previous() const { return this->previous; }
       
   495 
       
   496 	/**
       
   497 	 * Get the first vehicle of this vehicle chain.
       
   498 	 * @return the first vehicle of the chain.
       
   499 	 */
       
   500 	inline Vehicle *First() const { return this->first; }
   425 };
   501 };
   426 
   502 
   427 /**
   503 /**
   428  * This class 'wraps' Vehicle; you do not actually instantiate this class.
   504  * This class 'wraps' Vehicle; you do not actually instantiate this class.
   429  * You create a Vehicle using AllocateVehicle, so it is added to the pool
   505  * You create a Vehicle using AllocateVehicle, so it is added to the pool
   496 
   572 
   497 typedef void *VehicleFromPosProc(Vehicle *v, void *data);
   573 typedef void *VehicleFromPosProc(Vehicle *v, void *data);
   498 
   574 
   499 void VehicleServiceInDepot(Vehicle *v);
   575 void VehicleServiceInDepot(Vehicle *v);
   500 void VehiclePositionChanged(Vehicle *v);
   576 void VehiclePositionChanged(Vehicle *v);
   501 void AfterLoadVehicles();
       
   502 Vehicle *GetLastVehicleInChain(Vehicle *v);
   577 Vehicle *GetLastVehicleInChain(Vehicle *v);
   503 Vehicle *GetPrevVehicleInChain(const Vehicle *v);
       
   504 Vehicle *GetFirstVehicleInChain(const Vehicle *v);
       
   505 uint CountVehiclesInChain(const Vehicle *v);
   578 uint CountVehiclesInChain(const Vehicle *v);
   506 bool IsEngineCountable(const Vehicle *v);
   579 bool IsEngineCountable(const Vehicle *v);
   507 void DeleteVehicleChain(Vehicle *v);
   580 void DeleteVehicleChain(Vehicle *v);
   508 void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
   581 void *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
   509 void *VehicleFromPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
   582 void *VehicleFromPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
   543 void VehicleEnteredDepotThisTick(Vehicle *v);
   616 void VehicleEnteredDepotThisTick(Vehicle *v);
   544 
   617 
   545 void BeginVehicleMove(Vehicle *v);
   618 void BeginVehicleMove(Vehicle *v);
   546 void EndVehicleMove(Vehicle *v);
   619 void EndVehicleMove(Vehicle *v);
   547 
   620 
   548 void ShowAircraftViewWindow(const Vehicle* v);
       
   549 
       
   550 UnitID GetFreeUnitNumber(VehicleType type);
   621 UnitID GetFreeUnitNumber(VehicleType type);
   551 
   622 
   552 void TrainConsistChanged(Vehicle *v);
   623 void TrainConsistChanged(Vehicle *v);
   553 void TrainPowerChanged(Vehicle *v);
   624 void TrainPowerChanged(Vehicle *v);
   554 Money GetTrainRunningCost(const Vehicle *v);
   625 Money GetTrainRunningCost(const Vehicle *v);
   555 
   626 
   556 int CheckTrainStoppedInDepot(const Vehicle *v);
       
   557 
       
   558 bool VehicleNeedsService(const Vehicle *v);
   627 bool VehicleNeedsService(const Vehicle *v);
   559 
   628 
   560 uint GenerateVehicleSortList(const Vehicle*** sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type);
   629 uint GenerateVehicleSortList(const Vehicle*** sort_list, uint16 *length_of_array, VehicleType type, PlayerID owner, uint32 index, uint16 window_type);
   561 void BuildDepotVehicleList(VehicleType type, TileIndex tile, Vehicle ***engine_list, uint16 *engine_list_length, uint16 *engine_count, Vehicle ***wagon_list, uint16 *wagon_list_length, uint16 *wagon_count);
   630 void BuildDepotVehicleList(VehicleType type, TileIndex tile, Vehicle ***engine_list, uint16 *engine_list_length, uint16 *engine_count, Vehicle ***wagon_list, uint16 *wagon_list_length, uint16 *wagon_count);
   562 CommandCost SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id);
   631 CommandCost SendAllVehiclesToDepot(VehicleType type, uint32 flags, bool service, PlayerID owner, uint16 vlw_flag, uint32 id);
   563 bool IsVehicleInDepot(const Vehicle *v);
       
   564 void VehicleEnterDepot(Vehicle *v);
   632 void VehicleEnterDepot(Vehicle *v);
   565 
   633 
   566 void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g);
   634 void InvalidateAutoreplaceWindow(EngineID e, GroupID id_g);
   567 
   635 
   568 CommandCost MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs);
   636 CommandCost MaybeReplaceVehicle(Vehicle *v, bool check, bool display_costs);
   569 bool CanBuildVehicleInfrastructure(VehicleType type);
   637 bool CanBuildVehicleInfrastructure(VehicleType type);
       
   638 
       
   639 void CcCloneVehicle(bool success, TileIndex tile, uint32 p1, uint32 p2);
   570 
   640 
   571 /* Flags to add to p2 for goto depot commands */
   641 /* Flags to add to p2 for goto depot commands */
   572 /* Note: bits 8-10 are used for VLW flags */
   642 /* Note: bits 8-10 are used for VLW flags */
   573 enum {
   643 enum {
   574 	DEPOT_SERVICE       = (1 << 0), // The vehicle will leave the depot right after arrival (serivce only)
   644 	DEPOT_SERVICE       = (1 << 0), // The vehicle will leave the depot right after arrival (serivce only)
   599 /* returns true if staying in the same tile */
   669 /* returns true if staying in the same tile */
   600 GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v);
   670 GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v);
   601 Direction GetDirectionTowards(const Vehicle *v, int x, int y);
   671 Direction GetDirectionTowards(const Vehicle *v, int x, int y);
   602 
   672 
   603 #define BEGIN_ENUM_WAGONS(v) do {
   673 #define BEGIN_ENUM_WAGONS(v) do {
   604 #define END_ENUM_WAGONS(v) } while ((v = v->next) != NULL);
   674 #define END_ENUM_WAGONS(v) } while ((v = v->Next()) != NULL);
   605 
   675 
   606 static inline VehicleID GetMaxVehicleIndex()
   676 static inline VehicleID GetMaxVehicleIndex()
   607 {
   677 {
   608 	/* TODO - This isn't the real content of the function, but
   678 	/* TODO - This isn't the real content of the function, but
   609 	 *  with the new pool-system this will be replaced with one that
   679 	 *  with the new pool-system this will be replaced with one that