roadveh.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef ROADVEH_H
00013 #define ROADVEH_H
00014
00015 #include "vehicle_base.h"
00016 #include "engine_func.h"
00017 #include "engine_base.h"
00018 #include "economy_func.h"
00019
00020 struct RoadVehicle;
00021
00023 enum RoadVehicleStates {
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 RVSB_IN_DEPOT = 0xFE,
00038 RVSB_WORMHOLE = 0xFF,
00039
00040
00041 RVS_USING_SECOND_BAY = 1,
00042 RVS_DRIVE_SIDE = 4,
00043 RVS_IN_ROAD_STOP = 5,
00044 RVS_IN_DT_ROAD_STOP = 6,
00045
00046
00047 RVSB_IN_ROAD_STOP = 1 << RVS_IN_ROAD_STOP,
00048 RVSB_IN_ROAD_STOP_END = RVSB_IN_ROAD_STOP + TRACKDIR_END,
00049 RVSB_IN_DT_ROAD_STOP = 1 << RVS_IN_DT_ROAD_STOP,
00050 RVSB_IN_DT_ROAD_STOP_END = RVSB_IN_DT_ROAD_STOP + TRACKDIR_END,
00051
00052 RVSB_TRACKDIR_MASK = 0x0F,
00053 RVSB_ROAD_STOP_TRACKDIR_MASK = 0x09
00054 };
00055
00057 enum {
00058 RDE_NEXT_TILE = 0x80,
00059 RDE_TURNED = 0x40,
00060
00061
00062
00063
00064
00065
00066 RVC_DEFAULT_START_FRAME = 0,
00067 RVC_TURN_AROUND_START_FRAME = 1,
00068 RVC_DEPOT_START_FRAME = 6,
00069 RVC_START_FRAME_AFTER_LONG_TRAM = 21,
00070 RVC_TURN_AROUND_START_FRAME_SHORT_TRAM = 16,
00071
00072 RVC_DRIVE_THROUGH_STOP_FRAME = 11,
00073 RVC_DEPOT_STOP_FRAME = 11,
00074 };
00075
00076 enum RoadVehicleSubType {
00077 RVST_FRONT,
00078 RVST_ARTIC_PART,
00079 };
00080
00081
00082 void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2);
00083
00084 void RoadVehUpdateCache(RoadVehicle *v);
00085
00087 struct RoadVehicleCache {
00088 uint16 cached_total_length;
00089 byte cached_veh_length;
00090 EngineID first_engine;
00091 };
00092
00096 struct RoadVehicle : public SpecializedVehicle<RoadVehicle, VEH_ROAD> {
00097 RoadVehicleCache rcache;
00098 byte state;
00099 byte frame;
00100 uint16 blocked_ctr;
00101 byte overtaking;
00102 byte overtaking_ctr;
00103 uint16 crashed_ctr;
00104 byte reverse_ctr;
00105
00106 RoadType roadtype;
00107 RoadTypes compatible_roadtypes;
00108
00110 RoadVehicle() : SpecializedVehicle<RoadVehicle, VEH_ROAD>() {}
00112 virtual ~RoadVehicle() { this->PreDestructor(); }
00113
00114 const char *GetTypeString() const { return "road vehicle"; }
00115 void MarkDirty();
00116 void UpdateDeltaXY(Direction direction);
00117 ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_ROADVEH_INC : EXPENSES_ROADVEH_RUN; }
00118 bool IsPrimaryVehicle() const { return this->IsRoadVehFront(); }
00119 SpriteID GetImage(Direction direction) const;
00120 int GetDisplaySpeed() const { return this->cur_speed / 2; }
00121 int GetDisplayMaxSpeed() const { return this->max_speed / 2; }
00122 Money GetRunningCost() const;
00123 int GetDisplayImageWidth(Point *offset = NULL) const;
00124 bool IsInDepot() const { return this->state == RVSB_IN_DEPOT; }
00125 bool IsStoppedInDepot() const;
00126 bool Tick();
00127 void OnNewDay();
00128 uint Crash(bool flooded = false);
00129 Trackdir GetVehicleTrackdir() const;
00130 TileIndex GetOrderStationLocation(StationID station);
00131 bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
00132
00133 bool IsBus() const;
00134
00139 FORCEINLINE bool IsRoadVehFront() const { return this->subtype == RVST_FRONT; }
00140
00144 FORCEINLINE void SetRoadVehFront() { this->subtype = RVST_FRONT; }
00145
00150 FORCEINLINE bool IsArticulatedPart() const { return this->subtype == RVST_ARTIC_PART; }
00151
00155 FORCEINLINE void SetArticulatedPart() { this->subtype = RVST_ARTIC_PART; }
00156
00161 FORCEINLINE bool HasArticulatedPart() const { return this->Next() != NULL && this->Next()->IsArticulatedPart(); }
00162 };
00163
00164 #define FOR_ALL_ROADVEHICLES(var) FOR_ALL_VEHICLES_OF_TYPE(RoadVehicle, var)
00165
00166 #endif