2006-06-05 12:23:18 +02:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-04-03 21:19:04 +02:00
|
|
|
/** @file src/roadveh.h Road vehicle states */
|
2007-03-28 22:41:35 +02:00
|
|
|
|
2006-09-28 20:42:35 +02:00
|
|
|
#ifndef ROADVEH_H
|
|
|
|
#define ROADVEH_H
|
|
|
|
|
2007-12-27 14:35:39 +01:00
|
|
|
#include "vehicle_base.h"
|
2008-03-31 02:17:39 +02:00
|
|
|
#include "engine_func.h"
|
2008-04-29 23:31:29 +02:00
|
|
|
#include "engine_base.h"
|
2007-12-21 22:50:46 +01:00
|
|
|
#include "economy_func.h"
|
2006-06-05 12:23:18 +02:00
|
|
|
|
2009-05-22 22:18:45 +02:00
|
|
|
struct RoadVehicle;
|
|
|
|
|
2009-05-22 22:22:20 +02:00
|
|
|
/** Road vehicle states */
|
|
|
|
enum RoadVehicleStates {
|
|
|
|
/*
|
|
|
|
* Lower 4 bits are used for vehicle track direction. (Trackdirs)
|
|
|
|
* When in a road stop (bit 5 or bit 6 set) these bits give the
|
|
|
|
* track direction of the entry to the road stop.
|
|
|
|
* As the entry direction will always be a diagonal
|
|
|
|
* direction (X_NE, Y_SE, X_SW or Y_NW) only bits 0 and 3
|
|
|
|
* are needed to hold this direction. Bit 1 is then used to show
|
|
|
|
* that the vehicle is using the second road stop bay.
|
|
|
|
* Bit 2 is then used for drive-through stops to show the vehicle
|
|
|
|
* is stopping at this road stop.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Numeric values */
|
|
|
|
RVSB_IN_DEPOT = 0xFE, ///< The vehicle is in a depot
|
|
|
|
RVSB_WORMHOLE = 0xFF, ///< The vehicle is in a tunnel and/or bridge
|
|
|
|
|
|
|
|
/* Bit numbers */
|
|
|
|
RVS_USING_SECOND_BAY = 1, ///< Only used while in a road stop
|
|
|
|
RVS_IS_STOPPING = 2, ///< Only used for drive-through stops. Vehicle will stop here
|
|
|
|
RVS_DRIVE_SIDE = 4, ///< Only used when retrieving move data
|
|
|
|
RVS_IN_ROAD_STOP = 5, ///< The vehicle is in a road stop
|
|
|
|
RVS_IN_DT_ROAD_STOP = 6, ///< The vehicle is in a drive-through road stop
|
|
|
|
|
|
|
|
/* Bit sets of the above specified bits */
|
|
|
|
RVSB_IN_ROAD_STOP = 1 << RVS_IN_ROAD_STOP, ///< The vehicle is in a road stop
|
|
|
|
RVSB_IN_ROAD_STOP_END = RVSB_IN_ROAD_STOP + TRACKDIR_END,
|
|
|
|
RVSB_IN_DT_ROAD_STOP = 1 << RVS_IN_DT_ROAD_STOP, ///< The vehicle is in a drive-through road stop
|
|
|
|
RVSB_IN_DT_ROAD_STOP_END = RVSB_IN_DT_ROAD_STOP + TRACKDIR_END,
|
|
|
|
|
|
|
|
RVSB_TRACKDIR_MASK = 0x0F, ///< The mask used to extract track dirs
|
|
|
|
RVSB_ROAD_STOP_TRACKDIR_MASK = 0x09 ///< Only bits 0 and 3 are used to encode the trackdir for road stops
|
|
|
|
};
|
|
|
|
|
2009-02-06 16:39:34 +01:00
|
|
|
/** State information about the Road Vehicle controller */
|
|
|
|
enum {
|
|
|
|
RDE_NEXT_TILE = 0x80, ///< We should enter the next tile
|
|
|
|
RDE_TURNED = 0x40, ///< We just finished turning
|
|
|
|
|
|
|
|
/* Start frames for when a vehicle enters a tile/changes its state.
|
|
|
|
* The start frame is different for vehicles that turned around or
|
|
|
|
* are leaving the depot as the do not start at the edge of the tile.
|
|
|
|
* For trams there are a few different start frames as there are two
|
|
|
|
* places where trams can turn. */
|
|
|
|
RVC_DEFAULT_START_FRAME = 0,
|
|
|
|
RVC_TURN_AROUND_START_FRAME = 1,
|
|
|
|
RVC_DEPOT_START_FRAME = 6,
|
|
|
|
RVC_START_FRAME_AFTER_LONG_TRAM = 21,
|
|
|
|
RVC_TURN_AROUND_START_FRAME_SHORT_TRAM = 16,
|
|
|
|
/* Stop frame for a vehicle in a drive-through stop */
|
|
|
|
RVC_DRIVE_THROUGH_STOP_FRAME = 7,
|
|
|
|
RVC_DEPOT_STOP_FRAME = 11,
|
|
|
|
};
|
|
|
|
|
2007-06-11 16:00:16 +02: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 15:03:56 +02:00
|
|
|
return v->Next() != NULL && IsRoadVehArticPart(v->Next());
|
2007-06-11 16:00:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-22 03:09:51 +01:00
|
|
|
void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2);
|
2006-09-28 20:42:35 +02:00
|
|
|
|
2009-05-22 22:18:45 +02:00
|
|
|
byte GetRoadVehLength(const RoadVehicle *v);
|
2008-04-11 10:14:43 +02:00
|
|
|
|
2009-05-22 22:18:45 +02:00
|
|
|
void RoadVehUpdateCache(RoadVehicle *v);
|
2008-04-11 10:14:43 +02:00
|
|
|
|
2009-05-23 11:10:56 +02:00
|
|
|
/** Cached oftenly queried (NewGRF) values */
|
|
|
|
struct RoadVehicleCache {
|
|
|
|
byte cached_veh_length;
|
|
|
|
EngineID first_engine;
|
|
|
|
};
|
2007-04-29 23:24:08 +02:00
|
|
|
|
|
|
|
/**
|
2009-05-27 01:24:34 +02:00
|
|
|
* Buses, trucks and trams belong to this class.
|
2007-04-29 23:24:08 +02:00
|
|
|
*/
|
2009-05-27 00:10:13 +02:00
|
|
|
struct RoadVehicle : public SpecializedVehicle<RoadVehicle, VEH_ROAD> {
|
2009-05-23 11:10:56 +02:00
|
|
|
RoadVehicleCache rcache; ///< Cache of often used calculated values
|
2009-05-22 22:22:20 +02:00
|
|
|
byte state; ///< @see RoadVehicleStates
|
|
|
|
byte frame;
|
|
|
|
uint16 blocked_ctr;
|
|
|
|
byte overtaking;
|
|
|
|
byte overtaking_ctr;
|
|
|
|
uint16 crashed_ctr;
|
|
|
|
byte reverse_ctr;
|
|
|
|
struct RoadStop *slot;
|
|
|
|
byte slot_age;
|
|
|
|
|
|
|
|
RoadType roadtype;
|
|
|
|
RoadTypes compatible_roadtypes;
|
|
|
|
|
2007-04-29 23:24:08 +02:00
|
|
|
/** We want to 'destruct' the right class. */
|
2007-08-05 19:43:04 +02:00
|
|
|
virtual ~RoadVehicle() { this->PreDestructor(); }
|
2007-04-29 23:24:08 +02:00
|
|
|
|
2007-05-02 11:39:11 +02:00
|
|
|
const char *GetTypeString() const { return "road vehicle"; }
|
2007-04-30 00:33:51 +02:00
|
|
|
void MarkDirty();
|
2007-05-01 18:35:14 +02:00
|
|
|
void UpdateDeltaXY(Direction direction);
|
2007-05-02 11:39:11 +02:00
|
|
|
ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_ROADVEH_INC : EXPENSES_ROADVEH_RUN; }
|
2007-06-11 16:00:16 +02:00
|
|
|
bool IsPrimaryVehicle() const { return IsRoadVehFront(this); }
|
2008-04-21 22:50:58 +02:00
|
|
|
SpriteID GetImage(Direction direction) const;
|
2009-02-01 18:14:39 +01:00
|
|
|
int GetDisplaySpeed() const { return this->cur_speed / 2; }
|
|
|
|
int GetDisplayMaxSpeed() const { return this->max_speed / 2; }
|
2008-02-21 20:09:10 +01:00
|
|
|
Money GetRunningCost() const { return RoadVehInfo(this->engine_type)->running_cost * GetPriceByIndex(RoadVehInfo(this->engine_type)->running_cost_class); }
|
2009-05-22 22:22:20 +02:00
|
|
|
bool IsInDepot() const { return this->state == RVSB_IN_DEPOT; }
|
2008-08-17 13:12:56 +02:00
|
|
|
bool IsStoppedInDepot() const;
|
2009-05-22 15:53:14 +02:00
|
|
|
bool Tick();
|
2008-02-01 23:02:14 +01:00
|
|
|
void OnNewDay();
|
2009-05-22 20:17:20 +02:00
|
|
|
Trackdir GetVehicleTrackdir() const;
|
2008-04-05 12:55:50 +02:00
|
|
|
TileIndex GetOrderStationLocation(StationID station);
|
2008-04-11 10:14:43 +02:00
|
|
|
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
|
2007-04-29 23:24:08 +02:00
|
|
|
};
|
|
|
|
|
2009-05-27 00:10:13 +02:00
|
|
|
#define FOR_ALL_ROADVEHICLES(var) FOR_ALL_VEHICLES_OF_TYPE(RoadVehicle, var)
|
|
|
|
|
2006-09-28 20:42:35 +02:00
|
|
|
#endif /* ROADVEH_H */
|