roadveh.h

Go to the documentation of this file.
00001 /* $Id: roadveh.h 15374 2009-02-06 15:39:34Z rubidium $ */
00002 
00005 #ifndef ROADVEH_H
00006 #define ROADVEH_H
00007 
00008 #include "vehicle_base.h"
00009 #include "engine_func.h"
00010 #include "engine_base.h"
00011 #include "economy_func.h"
00012 
00014 enum {
00015   RDE_NEXT_TILE = 0x80, 
00016   RDE_TURNED    = 0x40, 
00017 
00018   /* Start frames for when a vehicle enters a tile/changes its state.
00019    * The start frame is different for vehicles that turned around or
00020    * are leaving the depot as the do not start at the edge of the tile.
00021    * For trams there are a few different start frames as there are two
00022    * places where trams can turn. */
00023   RVC_DEFAULT_START_FRAME                =  0,
00024   RVC_TURN_AROUND_START_FRAME            =  1,
00025   RVC_DEPOT_START_FRAME                  =  6,
00026   RVC_START_FRAME_AFTER_LONG_TRAM        = 21,
00027   RVC_TURN_AROUND_START_FRAME_SHORT_TRAM = 16,
00028   /* Stop frame for a vehicle in a drive-through stop */
00029   RVC_DRIVE_THROUGH_STOP_FRAME           =  7,
00030   RVC_DEPOT_STOP_FRAME                   = 11,
00031 };
00032 
00033 enum RoadVehicleSubType {
00034   RVST_FRONT,
00035   RVST_ARTIC_PART,
00036 };
00037 
00038 static inline bool IsRoadVehFront(const Vehicle *v)
00039 {
00040   assert(v->type == VEH_ROAD);
00041   return v->subtype == RVST_FRONT;
00042 }
00043 
00044 static inline void SetRoadVehFront(Vehicle *v)
00045 {
00046   assert(v->type == VEH_ROAD);
00047   v->subtype = RVST_FRONT;
00048 }
00049 
00050 static inline bool IsRoadVehArticPart(const Vehicle *v)
00051 {
00052   assert(v->type == VEH_ROAD);
00053   return v->subtype == RVST_ARTIC_PART;
00054 }
00055 
00056 static inline void SetRoadVehArticPart(Vehicle *v)
00057 {
00058   assert(v->type == VEH_ROAD);
00059   v->subtype = RVST_ARTIC_PART;
00060 }
00061 
00062 static inline bool RoadVehHasArticPart(const Vehicle *v)
00063 {
00064   assert(v->type == VEH_ROAD);
00065   return v->Next() != NULL && IsRoadVehArticPart(v->Next());
00066 }
00067 
00068 
00069 void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2);
00070 
00071 byte GetRoadVehLength(const Vehicle *v);
00072 
00073 void RoadVehUpdateCache(Vehicle *v);
00074 
00075 
00084 struct RoadVehicle : public Vehicle {
00086   RoadVehicle() { this->type = VEH_ROAD; }
00087 
00089   virtual ~RoadVehicle() { this->PreDestructor(); }
00090 
00091   const char *GetTypeString() const { return "road vehicle"; }
00092   void MarkDirty();
00093   void UpdateDeltaXY(Direction direction);
00094   ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_ROADVEH_INC : EXPENSES_ROADVEH_RUN; }
00095   bool IsPrimaryVehicle() const { return IsRoadVehFront(this); }
00096   SpriteID GetImage(Direction direction) const;
00097   int GetDisplaySpeed() const { return this->cur_speed / 2; }
00098   int GetDisplayMaxSpeed() const { return this->max_speed / 2; }
00099   Money GetRunningCost() const { return RoadVehInfo(this->engine_type)->running_cost * GetPriceByIndex(RoadVehInfo(this->engine_type)->running_cost_class); }
00100   bool IsInDepot() const { return this->u.road.state == RVSB_IN_DEPOT; }
00101   bool IsStoppedInDepot() const;
00102   void Tick();
00103   void OnNewDay();
00104   TileIndex GetOrderStationLocation(StationID station);
00105   bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
00106 };
00107 
00108 #endif /* ROADVEH_H */

Generated on Mon May 11 15:48:06 2009 for OpenTTD by  doxygen 1.5.6