2006-06-05 10:23:18 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-04-03 19:19:04 +00:00
|
|
|
/** @file src/roadveh.h Road vehicle states */
|
2007-03-28 20:41:35 +00:00
|
|
|
|
2006-09-28 18:42:35 +00:00
|
|
|
#ifndef ROADVEH_H
|
|
|
|
#define ROADVEH_H
|
|
|
|
|
2007-12-27 13:35:39 +00:00
|
|
|
#include "vehicle_base.h"
|
2008-03-31 00:17:39 +00:00
|
|
|
#include "engine_func.h"
|
2008-04-29 21:31:29 +00:00
|
|
|
#include "engine_base.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "economy_func.h"
|
2006-06-05 10:23:18 +00:00
|
|
|
|
2007-06-11 14:00:16 +00:00
|
|
|
enum RoadVehicleSubType {
|
|
|
|
RVST_FRONT,
|
|
|
|
RVST_ARTIC_PART,
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline bool IsRoadVehFront(const Vehicle *v)
|
|
|
|
{
|
|
|
|
assert(v->type == VEH_ROAD);
|
|
|
|
return v->subtype == RVST_FRONT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void SetRoadVehFront(Vehicle *v)
|
|
|
|
{
|
|
|
|
assert(v->type == VEH_ROAD);
|
|
|
|
v->subtype = RVST_FRONT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsRoadVehArticPart(const Vehicle *v)
|
|
|
|
{
|
|
|
|
assert(v->type == VEH_ROAD);
|
|
|
|
return v->subtype == RVST_ARTIC_PART;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void SetRoadVehArticPart(Vehicle *v)
|
|
|
|
{
|
|
|
|
assert(v->type == VEH_ROAD);
|
|
|
|
v->subtype = RVST_ARTIC_PART;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool RoadVehHasArticPart(const Vehicle *v)
|
|
|
|
{
|
|
|
|
assert(v->type == VEH_ROAD);
|
2007-08-30 13:03:56 +00:00
|
|
|
return v->Next() != NULL && IsRoadVehArticPart(v->Next());
|
2007-06-11 14:00:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-22 02:09:51 +00:00
|
|
|
void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2);
|
2006-09-28 18:42:35 +00:00
|
|
|
|
2008-04-11 08:14:43 +00:00
|
|
|
byte GetRoadVehLength(const Vehicle *v);
|
|
|
|
|
|
|
|
void RoadVehUpdateCache(Vehicle *v);
|
|
|
|
|
2007-04-29 21:24:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class 'wraps' Vehicle; you do not actually instantiate this class.
|
|
|
|
* You create a Vehicle using AllocateVehicle, so it is added to the pool
|
|
|
|
* and you reinitialize that to a Train using:
|
|
|
|
* v = new (v) RoadVehicle();
|
|
|
|
*
|
|
|
|
* As side-effect the vehicle type is set correctly.
|
|
|
|
*/
|
|
|
|
struct RoadVehicle : public Vehicle {
|
|
|
|
/** Initializes the Vehicle to a road vehicle */
|
|
|
|
RoadVehicle() { this->type = VEH_ROAD; }
|
|
|
|
|
|
|
|
/** We want to 'destruct' the right class. */
|
2007-08-05 17:43:04 +00:00
|
|
|
virtual ~RoadVehicle() { this->PreDestructor(); }
|
2007-04-29 21:24:08 +00:00
|
|
|
|
2007-05-02 09:39:11 +00:00
|
|
|
const char *GetTypeString() const { return "road vehicle"; }
|
2007-04-29 22:33:51 +00:00
|
|
|
void MarkDirty();
|
2007-05-01 16:35:14 +00:00
|
|
|
void UpdateDeltaXY(Direction direction);
|
2007-05-02 09:39:11 +00:00
|
|
|
ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_ROADVEH_INC : EXPENSES_ROADVEH_RUN; }
|
2007-06-11 14:00:16 +00:00
|
|
|
bool IsPrimaryVehicle() const { return IsRoadVehFront(this); }
|
2008-04-21 20:50:58 +00:00
|
|
|
SpriteID GetImage(Direction direction) const;
|
2007-08-26 20:43:22 +00:00
|
|
|
int GetDisplaySpeed() const { return this->cur_speed * 10 / 32; }
|
2007-08-28 06:46:33 +00:00
|
|
|
int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 32; }
|
2008-02-21 19:09:10 +00:00
|
|
|
Money GetRunningCost() const { return RoadVehInfo(this->engine_type)->running_cost * GetPriceByIndex(RoadVehInfo(this->engine_type)->running_cost_class); }
|
2007-08-29 21:49:08 +00:00
|
|
|
bool IsInDepot() const { return this->u.road.state == RVSB_IN_DEPOT; }
|
2008-08-17 11:12:56 +00:00
|
|
|
bool IsStoppedInDepot() const;
|
2007-07-01 19:24:54 +00:00
|
|
|
void Tick();
|
2008-02-01 22:02:14 +00:00
|
|
|
void OnNewDay();
|
2008-04-05 10:55:50 +00:00
|
|
|
TileIndex GetOrderStationLocation(StationID station);
|
2008-04-11 08:14:43 +00:00
|
|
|
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
|
2007-04-29 21:24:08 +00:00
|
|
|
};
|
|
|
|
|
2006-09-28 18:42:35 +00:00
|
|
|
#endif /* ROADVEH_H */
|