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 "road_type.h"
00017
00018 struct RoadVehicle;
00019
00021 enum RoadVehicleStates {
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 RVSB_IN_DEPOT = 0xFE,
00036 RVSB_WORMHOLE = 0xFF,
00037
00038
00039 RVS_USING_SECOND_BAY = 1,
00040 RVS_DRIVE_SIDE = 4,
00041 RVS_IN_ROAD_STOP = 5,
00042 RVS_IN_DT_ROAD_STOP = 6,
00043
00044
00045 RVSB_IN_ROAD_STOP = 1 << RVS_IN_ROAD_STOP,
00046 RVSB_IN_ROAD_STOP_END = RVSB_IN_ROAD_STOP + TRACKDIR_END,
00047 RVSB_IN_DT_ROAD_STOP = 1 << RVS_IN_DT_ROAD_STOP,
00048 RVSB_IN_DT_ROAD_STOP_END = RVSB_IN_DT_ROAD_STOP + TRACKDIR_END,
00049
00050 RVSB_TRACKDIR_MASK = 0x0F,
00051 RVSB_ROAD_STOP_TRACKDIR_MASK = 0x09
00052 };
00053
00055 enum {
00056 RDE_NEXT_TILE = 0x80,
00057 RDE_TURNED = 0x40,
00058
00059
00060
00061
00062
00063
00064 RVC_DEFAULT_START_FRAME = 0,
00065 RVC_TURN_AROUND_START_FRAME = 1,
00066 RVC_DEPOT_START_FRAME = 6,
00067 RVC_START_FRAME_AFTER_LONG_TRAM = 21,
00068 RVC_TURN_AROUND_START_FRAME_SHORT_TRAM = 16,
00069
00070 RVC_DRIVE_THROUGH_STOP_FRAME = 11,
00071 RVC_DEPOT_STOP_FRAME = 11,
00072 };
00073
00074 enum RoadVehicleSubType {
00075 RVST_FRONT,
00076 RVST_ARTIC_PART,
00077 };
00078
00079
00080 void RoadVehUpdateCache(RoadVehicle *v);
00081
00083 struct RoadVehicleCache {
00084 uint16 cached_total_length;
00085 byte cached_veh_length;
00086 EngineID first_engine;
00087 };
00088
00092 struct RoadVehicle : public SpecializedVehicle<RoadVehicle, VEH_ROAD> {
00093 RoadVehicleCache rcache;
00094 byte state;
00095 byte frame;
00096 uint16 blocked_ctr;
00097 byte overtaking;
00098 byte overtaking_ctr;
00099 uint16 crashed_ctr;
00100 byte reverse_ctr;
00101
00102 RoadType roadtype;
00103 RoadTypes compatible_roadtypes;
00104
00106 RoadVehicle() : SpecializedVehicle<RoadVehicle, VEH_ROAD>() {}
00108 virtual ~RoadVehicle() { this->PreDestructor(); }
00109
00110 const char *GetTypeString() const { return "road vehicle"; }
00111 void MarkDirty();
00112 void UpdateDeltaXY(Direction direction);
00113 ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_ROADVEH_INC : EXPENSES_ROADVEH_RUN; }
00114 bool IsPrimaryVehicle() const { return this->IsRoadVehFront(); }
00115 SpriteID GetImage(Direction direction) const;
00116 int GetDisplaySpeed() const { return this->cur_speed / 2; }
00117 int GetDisplayMaxSpeed() const { return this->max_speed / 2; }
00118 Money GetRunningCost() const;
00119 int GetDisplayImageWidth(Point *offset = NULL) const;
00120 bool IsInDepot() const { return this->state == RVSB_IN_DEPOT; }
00121 bool IsStoppedInDepot() const;
00122 bool Tick();
00123 void OnNewDay();
00124 uint Crash(bool flooded = false);
00125 Trackdir GetVehicleTrackdir() const;
00126 TileIndex GetOrderStationLocation(StationID station);
00127 bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
00128
00129 bool IsBus() const;
00130
00135 FORCEINLINE bool IsRoadVehFront() const { return this->subtype == RVST_FRONT; }
00136
00140 FORCEINLINE void SetRoadVehFront() { this->subtype = RVST_FRONT; }
00141
00146 FORCEINLINE bool IsArticulatedPart() const { return this->subtype == RVST_ARTIC_PART; }
00147
00151 FORCEINLINE void SetArticulatedPart() { this->subtype = RVST_ARTIC_PART; }
00152
00157 FORCEINLINE bool HasArticulatedPart() const { return this->Next() != NULL && this->Next()->IsArticulatedPart(); }
00158 };
00159
00160 #define FOR_ALL_ROADVEHICLES(var) FOR_ALL_VEHICLES_OF_TYPE(RoadVehicle, var)
00161
00162 #endif