# roadveh.h

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    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    * Lower 4 bits are used for vehicle track direction. (Trackdirs)
    00026    * When in a road stop (bit 5 or bit 6 set) these bits give the
    00027    * track direction of the entry to the road stop.
    00028    * As the entry direction will always be a diagonal
    00029    * direction (X_NE, Y_SE, X_SW or Y_NW) only bits 0 and 3
    00030    * are needed to hold this direction. Bit 1 is then used to show
    00031    * that the vehicle is using the second road stop bay.
    00032    * Bit 2 is then used for drive-through stops to show the vehicle
    00033    * is stopping at this road stop.
    00034    */
    00035
    00036   /* Numeric values */
    00037   RVSB_IN_DEPOT                = 0xFE,
    00038   RVSB_WORMHOLE                = 0xFF,
    00039
    00040   /* Bit numbers */
    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   /* Bit sets of the above specified bits */
    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   /* Start frames for when a vehicle enters a tile/changes its state.
    00062    * The start frame is different for vehicles that turned around or
    00063    * are leaving the depot as the do not start at the edge of the tile.
    00064    * For trams there are a few different start frames as there are two
    00065    * places where trams can turn. */
    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   /* Stop frame for a vehicle in a drive-through stop */
    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 /* ROADVEH_H */