Files
@ r3340:baed05973439
Branch filter:
Location: cpp/openttd-patchpack/source/train.h - annotation
r3340:baed05973439
4.8 KiB
text/x-c
(svn r4124) - CodeChange: remove windows-specific code from initializing the random generator. There was no need for it.
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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2676:cfc81c07cc6a r2855:93020c5c02b9 r2855:93020c5c02b9 r2855:93020c5c02b9 r2676:cfc81c07cc6a | /* $Id$ */
#ifndef TRAIN_H
#define TRAIN_H
#include "stdafx.h"
#include "vehicle.h"
/*
* enum to handle train subtypes
* Do not access it directly unless you have to. Use the access functions below
* This is an enum to tell what bit to access as it is a bitmask
*/
typedef enum TrainSubtypes {
Train_Front = 0, // Leading engine of a train
Train_Articulated_Part = 1, // Articulated part of an engine
Train_Wagon = 2, // Wagon
Train_Engine = 3, // Engine, that can be front engines, but might be placed behind another engine
Train_Free_Wagon = 4, // First in a wagon chain (in depot)
Train_Multiheaded = 5, // Engine is a multiheaded
} TrainSubtype;
/** Check if a vehicle is front engine
* @param v vehicle to check
* @return Returns true if vehicle is a front engine
*/
static inline bool IsFrontEngine(const Vehicle *v)
{
return HASBIT(v->subtype, Train_Front);
}
/** Set front engine state
* @param v vehicle to change
*/
static inline void SetFrontEngine(Vehicle *v)
{
SETBIT(v->subtype, Train_Front);
}
/** Remove the front engine state
* @param v vehicle to change
*/
static inline void ClearFrontEngine(Vehicle *v)
{
CLRBIT(v->subtype, Train_Front);
}
/** Check if a vehicle is an articulated part of an engine
* @param v vehicle to check
* @return Returns true if vehicle is an articulated part
*/
static inline bool IsArticulatedPart(const Vehicle *v)
{
return HASBIT(v->subtype, Train_Articulated_Part);
}
/** Set a vehicle to be an articulated part
* @param v vehicle to change
*/
static inline void SetArticulatedPart(Vehicle *v)
{
SETBIT(v->subtype, Train_Articulated_Part);
}
/** Clear a vehicle from being an articulated part
* @param v vehicle to change
*/
static inline void ClearArticulatedPart(Vehicle *v)
{
CLRBIT(v->subtype, Train_Articulated_Part);
}
/** Check if a vehicle is a wagon
* @param v vehicle to check
* @return Returns true if vehicle is a wagon
*/
static inline bool IsTrainWagon(const Vehicle *v)
{
return HASBIT(v->subtype, Train_Wagon);
}
/** Set a vehicle to be a wagon
* @param v vehicle to change
*/
static inline void SetTrainWagon(Vehicle *v)
{
SETBIT(v->subtype, Train_Wagon);
}
/** Clear wagon property
* @param v vehicle to change
*/
static inline void ClearTrainWagon(Vehicle *v)
{
CLRBIT(v->subtype, Train_Wagon);
}
/** Check if a vehicle is an engine (can be first in a train)
* @param v vehicle to check
* @return Returns true if vehicle is an engine
*/
static inline bool IsTrainEngine(const Vehicle *v)
{
return HASBIT(v->subtype, Train_Engine);
}
/** Set engine status
* @param v vehicle to change
*/
static inline void SetTrainEngine(Vehicle *v)
{
SETBIT(v->subtype, Train_Engine);
}
/** Clear engine status
* @param v vehicle to change
*/
static inline void ClearTrainEngine(Vehicle *v)
{
CLRBIT(v->subtype, Train_Engine);
}
/** Check if a vehicle is a free wagon (got no engine in front of it)
* @param v vehicle to check
* @return Returns true if vehicle is a free wagon
*/
static inline bool IsFreeWagon(const Vehicle *v)
{
return HASBIT(v->subtype, Train_Free_Wagon);
}
/** Set if a vehicle is a free wagon
* @param v vehicle to change
*/
static inline void SetFreeWagon(Vehicle *v)
{
SETBIT(v->subtype, Train_Free_Wagon);
}
/** Clear a vehicle from being a free wagon
* @param v vehicle to change
*/
static inline void ClearFreeWagon(Vehicle *v)
{
CLRBIT(v->subtype, Train_Free_Wagon);
}
/** Check if a vehicle is a multiheaded engine
* @param v vehicle to check
* @return Returns true if vehicle is a multiheaded engine
*/
static inline bool IsMultiheaded(const Vehicle *v)
{
return HASBIT(v->subtype, Train_Multiheaded);
}
/** Set if a vehicle is a multiheaded engine
* @param v vehicle to change
*/
static inline void SetMultiheaded(Vehicle *v)
{
SETBIT(v->subtype, Train_Multiheaded);
}
/** Clear multiheaded engine property
* @param v vehicle to change
*/
static inline void ClearMultiheaded(Vehicle *v)
{
CLRBIT(v->subtype, Train_Multiheaded);
}
/** Get the next real (non-articulated part) vehicle in the consist.
* @param v Vehicle.
* @return Next vehicle in the consist.
*/
static inline Vehicle *GetNextVehicle(const Vehicle *v)
{
Vehicle *u = v->next;
while (u != NULL && IsArticulatedPart(u)) {
u = u->next;
}
return u;
}
/** Check if an engine has an articulated part.
* @param v Vehicle.
* @return True if the engine has an articulated part.
*/
static inline bool EngineHasArticPart(const Vehicle *v)
{
return (v->next != NULL && IsArticulatedPart(v->next));
}
/** Get the last part of a multi-part engine.
* @param v Vehicle.
* @return Last part of the engine.
*/
static inline Vehicle *GetLastEnginePart(Vehicle *v)
{
while (EngineHasArticPart(v)) v = v->next;
return v;
}
void ConvertOldMultiheadToNew(void);
void ConnectMultiheadedTrains(void);
#endif /* TRAIN_H */
|