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 "ground_vehicle.hpp"
00016 #include "engine_base.h"
00017 #include "cargotype.h"
00018 #include "track_func.h"
00019 #include "road_type.h"
00020 #include "newgrf_properties.h"
00021 #include "newgrf_engine.h"
00022
00023 struct RoadVehicle;
00024
00026 enum RoadVehicleStates {
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 RVSB_IN_DEPOT = 0xFE,
00041 RVSB_WORMHOLE = 0xFF,
00042
00043
00044 RVS_USING_SECOND_BAY = 1,
00045 RVS_ENTERED_STOP = 2,
00046 RVS_DRIVE_SIDE = 4,
00047 RVS_IN_ROAD_STOP = 5,
00048 RVS_IN_DT_ROAD_STOP = 6,
00049
00050
00051 RVSB_IN_ROAD_STOP = 1 << RVS_IN_ROAD_STOP,
00052 RVSB_IN_ROAD_STOP_END = RVSB_IN_ROAD_STOP + TRACKDIR_END,
00053 RVSB_IN_DT_ROAD_STOP = 1 << RVS_IN_DT_ROAD_STOP,
00054 RVSB_IN_DT_ROAD_STOP_END = RVSB_IN_DT_ROAD_STOP + TRACKDIR_END,
00055
00056 RVSB_TRACKDIR_MASK = 0x0F,
00057 RVSB_ROAD_STOP_TRACKDIR_MASK = 0x09
00058 };
00059
00061 static const uint RDE_NEXT_TILE = 0x80;
00062 static const uint RDE_TURNED = 0x40;
00063
00064
00065
00066
00067
00068
00069 static const uint RVC_DEFAULT_START_FRAME = 0;
00070 static const uint RVC_TURN_AROUND_START_FRAME = 1;
00071 static const uint RVC_DEPOT_START_FRAME = 6;
00072 static const uint RVC_START_FRAME_AFTER_LONG_TRAM = 21;
00073 static const uint RVC_TURN_AROUND_START_FRAME_SHORT_TRAM = 16;
00074
00075 static const uint RVC_DRIVE_THROUGH_STOP_FRAME = 11;
00076 static const uint RVC_DEPOT_STOP_FRAME = 11;
00077
00078 enum RoadVehicleSubType {
00079 RVST_FRONT,
00080 RVST_ARTIC_PART,
00081 };
00082
00083
00084 void RoadVehUpdateCache(RoadVehicle *v);
00085
00089 struct RoadVehicle : public GroundVehicle<RoadVehicle, VEH_ROAD> {
00090 byte state;
00091 byte frame;
00092 uint16 blocked_ctr;
00093 byte overtaking;
00094 byte overtaking_ctr;
00095 uint16 crashed_ctr;
00096 byte reverse_ctr;
00097
00098 RoadType roadtype;
00099 RoadTypes compatible_roadtypes;
00100
00102 RoadVehicle() : GroundVehicle<RoadVehicle, VEH_ROAD>() {}
00104 virtual ~RoadVehicle() { this->PreDestructor(); }
00105
00106 friend struct GroundVehicle<RoadVehicle, VEH_ROAD>;
00107
00108 const char *GetTypeString() const { return "road vehicle"; }
00109 void MarkDirty();
00110 void UpdateDeltaXY(Direction direction);
00111 ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_ROADVEH_INC : EXPENSES_ROADVEH_RUN; }
00112 bool IsPrimaryVehicle() const { return this->IsRoadVehFront(); }
00113 SpriteID GetImage(Direction direction) const;
00114 int GetDisplaySpeed() const { return this->cur_speed / 2; }
00115 int GetDisplayMaxSpeed() const { return this->vcache.cached_max_speed / 2; }
00116 Money GetRunningCost() const;
00117 int GetDisplayImageWidth(Point *offset = NULL) const;
00118 bool IsInDepot() const { return this->state == RVSB_IN_DEPOT; }
00119 bool IsStoppedInDepot() const;
00120 bool Tick();
00121 void OnNewDay();
00122 uint Crash(bool flooded = false);
00123 Trackdir GetVehicleTrackdir() const;
00124 TileIndex GetOrderStationLocation(StationID station);
00125 bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
00126
00127 bool IsBus() const;
00128
00129 int GetCurrentMaxSpeed() 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 protected:
00160
00165 FORCEINLINE uint16 GetPower() const
00166 {
00167
00168 if (!this->IsArticulatedPart()) {
00169
00170 return 10 * GetVehicleProperty(this, PROP_ROADVEH_POWER, RoadVehInfo(this->engine_type)->power);
00171 }
00172 return 0;
00173 }
00174
00179 FORCEINLINE uint16 GetPoweredPartPower(const RoadVehicle *head) const
00180 {
00181 return 0;
00182 }
00183
00188 FORCEINLINE uint16 GetWeight() const
00189 {
00190 uint16 weight = (CargoSpec::Get(this->cargo_type)->weight * this->cargo.Count()) / 16;
00191
00192
00193 if (!this->IsArticulatedPart()) {
00194
00195 weight += GetVehicleProperty(this, PROP_ROADVEH_WEIGHT, RoadVehInfo(this->engine_type)->weight) / 4;
00196 }
00197
00198 return weight;
00199 }
00200
00205 FORCEINLINE byte GetTractiveEffort() const
00206 {
00207
00208 return GetVehicleProperty(this, PROP_ROADVEH_TRACTIVE_EFFORT, RoadVehInfo(this->engine_type)->tractive_effort);
00209 }
00210
00215 FORCEINLINE byte GetAirDragArea() const
00216 {
00217 return 6;
00218 }
00219
00224 FORCEINLINE byte GetAirDrag() const
00225 {
00226 return RoadVehInfo(this->engine_type)->air_drag;
00227 }
00228
00233 FORCEINLINE AccelStatus GetAccelerationStatus() const
00234 {
00235 return (this->vehstatus & VS_STOPPED) ? AS_BRAKE : AS_ACCEL;
00236 }
00237
00242 FORCEINLINE uint16 GetCurrentSpeed() const
00243 {
00244 return this->cur_speed / 2;
00245 }
00246
00251 FORCEINLINE uint32 GetRollingFriction() const
00252 {
00253
00254
00255 uint32 coeff = (this->roadtype == ROADTYPE_TRAM) ? 40 : 75;
00256
00257
00258 return coeff * (128 + this->GetCurrentSpeed()) / 128;
00259 }
00260
00265 FORCEINLINE int GetAccelerationType() const
00266 {
00267 return 0;
00268 }
00269
00274 FORCEINLINE uint32 GetSlopeSteepness() const
00275 {
00276 return _settings_game.vehicle.roadveh_slope_steepness;
00277 }
00278
00283 FORCEINLINE uint16 GetMaxTrackSpeed() const
00284 {
00285 return 0;
00286 }
00287
00292 FORCEINLINE bool TileMayHaveSlopedTrack() const
00293 {
00294 TrackStatus ts = GetTileTrackStatus(this->tile, TRANSPORT_ROAD, this->compatible_roadtypes);
00295 TrackBits trackbits = TrackStatusToTrackBits(ts);
00296
00297 return trackbits == TRACK_BIT_X || trackbits == TRACK_BIT_Y;
00298 }
00299 };
00300
00301 #define FOR_ALL_ROADVEHICLES(var) FOR_ALL_VEHICLES_OF_TYPE(RoadVehicle, var)
00302
00303 #endif