roadveh.h

Go to the documentation of this file.
00001 /* $Id: roadveh.h 18809 2010-01-15 16:41:15Z rubidium $ */
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 "road_type.h"
00017 
00018 struct RoadVehicle;
00019 
00021 enum RoadVehicleStates {
00022   /*
00023    * Lower 4 bits are used for vehicle track direction. (Trackdirs)
00024    * When in a road stop (bit 5 or bit 6 set) these bits give the
00025    * track direction of the entry to the road stop.
00026    * As the entry direction will always be a diagonal
00027    * direction (X_NE, Y_SE, X_SW or Y_NW) only bits 0 and 3
00028    * are needed to hold this direction. Bit 1 is then used to show
00029    * that the vehicle is using the second road stop bay.
00030    * Bit 2 is then used for drive-through stops to show the vehicle
00031    * is stopping at this road stop.
00032    */
00033 
00034   /* Numeric values */
00035   RVSB_IN_DEPOT                = 0xFE,                      
00036   RVSB_WORMHOLE                = 0xFF,                      
00037 
00038   /* Bit numbers */
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   /* Bit sets of the above specified bits */
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   /* Start frames for when a vehicle enters a tile/changes its state.
00060    * The start frame is different for vehicles that turned around or
00061    * are leaving the depot as the do not start at the edge of the tile.
00062    * For trams there are a few different start frames as there are two
00063    * places where trams can turn. */
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   /* Stop frame for a vehicle in a drive-through stop */
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 /* ROADVEH_H */

Generated on Wed Mar 31 22:43:27 2010 for OpenTTD by  doxygen 1.6.1