Files
@ r13776:13a93fc73a0c
Branch filter:
Location: cpp/openttd-patchpack/source/src/roadveh.h - annotation
r13776:13a93fc73a0c
6.4 KiB
text/x-c
(svn r18312) -Codechange: Simplify the nested widget part arrays of both face windows, and move a bit towards merging.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r6417:89329fa8ac80 r6393:f9322fdf4c2c r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r8144:1432edd15267 r8786:f24a6d1fba34 r9070:e059c65164f3 r8116:df67d3c5e4fd r5475:3f5cd13d1b63 r11978:b70e888fac6f r11978:b70e888fac6f r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11034:b133414fb70f r11034:b133414fb70f r11034:b133414fb70f r11034:b133414fb70f r11034:b133414fb70f r11034:b133414fb70f r11034:b133414fb70f r11034:b133414fb70f r11034:b133414fb70f r11034:b133414fb70f r11034:b133414fb70f r11034:b133414fb70f r11034:b133414fb70f r11034:b133414fb70f r11034:b133414fb70f r11034:b133414fb70f r11034:b133414fb70f r11034:b133414fb70f r11034:b133414fb70f r11034:b133414fb70f r6857:1e07df806ef1 r6857:1e07df806ef1 r6857:1e07df806ef1 r6857:1e07df806ef1 r6857:1e07df806ef1 r6857:1e07df806ef1 r5786:21dd6ba13f91 r5475:3f5cd13d1b63 r11978:b70e888fac6f r8890:02179c54681e r11983:0159b0bf2cf8 r11983:0159b0bf2cf8 r11983:0159b0bf2cf8 r13171:0e07c3ba2aa9 r11983:0159b0bf2cf8 r6552:7cade7798fcb r6552:7cade7798fcb r12033:6a560c929ec8 r6552:7cade7798fcb r12029:5b077ec055c0 r11983:0159b0bf2cf8 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r11979:a450390d0f16 r12090:c20f83257241 r12090:c20f83257241 r6552:7cade7798fcb r7412:e5f07529a093 r6552:7cade7798fcb r6563:67c636a8e3d4 r6553:04028e73a0f7 r6558:469828caa298 r6563:67c636a8e3d4 r12294:7f9f5ab6fe85 r9022:5be8b7703ae9 r10969:8b8a9653d684 r10969:8b8a9653d684 r13482:56711f143646 r12428:f9fdea44ada5 r11979:a450390d0f16 r9935:d6cda74ab287 r11965:2b94ac4aa35a r8467:0ea88f22d4aa r11971:ac7eb21a00e4 r8827:6ee5217ef94b r8890:02179c54681e r13735:8b21c9a2363f r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12294:7f9f5ab6fe85 r12295:bb9023f54628 r6552:7cade7798fcb r6552:7cade7798fcb r12029:5b077ec055c0 r12029:5b077ec055c0 r5475:3f5cd13d1b63 | /* $Id$ */
/*
* This file is part of OpenTTD.
* 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.
* 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.
* 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/>.
*/
/** @file src/roadveh.h Road vehicle states */
#ifndef ROADVEH_H
#define ROADVEH_H
#include "vehicle_base.h"
#include "engine_func.h"
#include "engine_base.h"
#include "economy_func.h"
struct RoadVehicle;
/** Road vehicle states */
enum RoadVehicleStates {
/*
* Lower 4 bits are used for vehicle track direction. (Trackdirs)
* When in a road stop (bit 5 or bit 6 set) these bits give the
* track direction of the entry to the road stop.
* As the entry direction will always be a diagonal
* direction (X_NE, Y_SE, X_SW or Y_NW) only bits 0 and 3
* are needed to hold this direction. Bit 1 is then used to show
* that the vehicle is using the second road stop bay.
* Bit 2 is then used for drive-through stops to show the vehicle
* is stopping at this road stop.
*/
/* Numeric values */
RVSB_IN_DEPOT = 0xFE, ///< The vehicle is in a depot
RVSB_WORMHOLE = 0xFF, ///< The vehicle is in a tunnel and/or bridge
/* Bit numbers */
RVS_USING_SECOND_BAY = 1, ///< Only used while in a road stop
RVS_IS_STOPPING = 2, ///< Only used for drive-through stops. Vehicle will stop here
RVS_DRIVE_SIDE = 4, ///< Only used when retrieving move data
RVS_IN_ROAD_STOP = 5, ///< The vehicle is in a road stop
RVS_IN_DT_ROAD_STOP = 6, ///< The vehicle is in a drive-through road stop
/* Bit sets of the above specified bits */
RVSB_IN_ROAD_STOP = 1 << RVS_IN_ROAD_STOP, ///< The vehicle is in a road stop
RVSB_IN_ROAD_STOP_END = RVSB_IN_ROAD_STOP + TRACKDIR_END,
RVSB_IN_DT_ROAD_STOP = 1 << RVS_IN_DT_ROAD_STOP, ///< The vehicle is in a drive-through road stop
RVSB_IN_DT_ROAD_STOP_END = RVSB_IN_DT_ROAD_STOP + TRACKDIR_END,
RVSB_TRACKDIR_MASK = 0x0F, ///< The mask used to extract track dirs
RVSB_ROAD_STOP_TRACKDIR_MASK = 0x09 ///< Only bits 0 and 3 are used to encode the trackdir for road stops
};
/** State information about the Road Vehicle controller */
enum {
RDE_NEXT_TILE = 0x80, ///< We should enter the next tile
RDE_TURNED = 0x40, ///< We just finished turning
/* Start frames for when a vehicle enters a tile/changes its state.
* The start frame is different for vehicles that turned around or
* are leaving the depot as the do not start at the edge of the tile.
* For trams there are a few different start frames as there are two
* places where trams can turn. */
RVC_DEFAULT_START_FRAME = 0,
RVC_TURN_AROUND_START_FRAME = 1,
RVC_DEPOT_START_FRAME = 6,
RVC_START_FRAME_AFTER_LONG_TRAM = 21,
RVC_TURN_AROUND_START_FRAME_SHORT_TRAM = 16,
/* Stop frame for a vehicle in a drive-through stop */
RVC_DRIVE_THROUGH_STOP_FRAME = 7,
RVC_DEPOT_STOP_FRAME = 11,
};
enum RoadVehicleSubType {
RVST_FRONT,
RVST_ARTIC_PART,
};
void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2);
void RoadVehUpdateCache(RoadVehicle *v);
/** Cached oftenly queried (NewGRF) values */
struct RoadVehicleCache {
byte cached_veh_length;
EngineID first_engine; ///< cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
};
/**
* Buses, trucks and trams belong to this class.
*/
struct RoadVehicle : public SpecializedVehicle<RoadVehicle, VEH_ROAD> {
RoadVehicleCache rcache; ///< Cache of often used calculated values
byte state; ///< @see RoadVehicleStates
byte frame;
uint16 blocked_ctr;
byte overtaking;
byte overtaking_ctr;
uint16 crashed_ctr;
byte reverse_ctr;
struct RoadStop *slot;
byte slot_age;
RoadType roadtype;
RoadTypes compatible_roadtypes;
/** We don't want GCC to zero our struct! It already is zeroed and has an index! */
RoadVehicle() : SpecializedVehicle<RoadVehicle, VEH_ROAD>() {}
/** We want to 'destruct' the right class. */
virtual ~RoadVehicle() { this->PreDestructor(); }
const char *GetTypeString() const { return "road vehicle"; }
void MarkDirty();
void UpdateDeltaXY(Direction direction);
ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_ROADVEH_INC : EXPENSES_ROADVEH_RUN; }
bool IsPrimaryVehicle() const { return this->IsRoadVehFront(); }
SpriteID GetImage(Direction direction) const;
int GetDisplaySpeed() const { return this->cur_speed / 2; }
int GetDisplayMaxSpeed() const { return this->max_speed / 2; }
Money GetRunningCost() const;
int GetDisplayImageWidth(Point *offset = NULL) const;
bool IsInDepot() const { return this->state == RVSB_IN_DEPOT; }
bool IsStoppedInDepot() const;
bool Tick();
void OnNewDay();
Trackdir GetVehicleTrackdir() const;
TileIndex GetOrderStationLocation(StationID station);
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
void FindRoadStopSlot();
/**
* Check if vehicle is a front engine
* @return Returns true if vehicle is a front engine
*/
FORCEINLINE bool IsRoadVehFront() const { return this->subtype == RVST_FRONT; }
/**
* Set front engine state
*/
FORCEINLINE void SetRoadVehFront() { this->subtype = RVST_FRONT; }
/**
* Check if vehicl is an articulated part of an engine
* @return Returns true if vehicle is an articulated part
*/
FORCEINLINE bool IsArticulatedPart() const { return this->subtype == RVST_ARTIC_PART; }
/**
* Set a vehicle to be an articulated part
*/
FORCEINLINE void SetArticulatedPart() { this->subtype = RVST_ARTIC_PART; }
/**
* Check if an engine has an articulated part.
* @return True if the engine has an articulated part.
*/
FORCEINLINE bool HasArticulatedPart() const { return this->Next() != NULL && this->Next()->IsArticulatedPart(); }
};
#define FOR_ALL_ROADVEHICLES(var) FOR_ALL_VEHICLES_OF_TYPE(RoadVehicle, var)
#endif /* ROADVEH_H */
|