src/train.h
branchnoai
changeset 9732 f8eb3e208514
parent 9724 b39bc69bb2f2
child 9826 9707ad4c9b60
equal deleted inserted replaced
9731:9b1552d0fd9b 9732:f8eb3e208514
    15  * Do not access it directly unless you have to. Use the access functions below
    15  * Do not access it directly unless you have to. Use the access functions below
    16  * This is an enum to tell what bit to access as it is a bitmask
    16  * This is an enum to tell what bit to access as it is a bitmask
    17  */
    17  */
    18 
    18 
    19 enum TrainSubtype {
    19 enum TrainSubtype {
    20 	Train_Front             = 0, ///< Leading engine of a train
    20 	TS_FRONT             = 0, ///< Leading engine of a train
    21 	Train_Articulated_Part  = 1, ///< Articulated part of an engine
    21 	TS_ARTICULATED_PART  = 1, ///< Articulated part of an engine
    22 	Train_Wagon             = 2, ///< Wagon
    22 	TS_WAGON             = 2, ///< Wagon
    23 	Train_Engine            = 3, ///< Engine, that can be front engines, but might be placed behind another engine
    23 	TS_ENGINE            = 3, ///< Engine, that can be front engines, but might be placed behind another engine
    24 	Train_Free_Wagon        = 4, ///< First in a wagon chain (in depot)
    24 	TS_FREE_WAGON        = 4, ///< First in a wagon chain (in depot)
    25 	Train_Multiheaded       = 5, ///< Engine is a multiheaded
    25 	TS_MULTIHEADED       = 5, ///< Engine is a multiheaded
    26 };
    26 };
    27 
    27 
    28 
    28 
    29 /** Check if a vehicle is front engine
    29 /** Check if a vehicle is front engine
    30  * @param v vehicle to check
    30  * @param v vehicle to check
    31  * @return Returns true if vehicle is a front engine
    31  * @return Returns true if vehicle is a front engine
    32  */
    32  */
    33 static inline bool IsFrontEngine(const Vehicle *v)
    33 static inline bool IsFrontEngine(const Vehicle *v)
    34 {
    34 {
    35 	assert(v->type == VEH_TRAIN);
    35 	assert(v->type == VEH_TRAIN);
    36 	return HasBit(v->subtype, Train_Front);
    36 	return HasBit(v->subtype, TS_FRONT);
    37 }
    37 }
    38 
    38 
    39 /** Set front engine state
    39 /** Set front engine state
    40  * @param v vehicle to change
    40  * @param v vehicle to change
    41  */
    41  */
    42 static inline void SetFrontEngine(Vehicle *v)
    42 static inline void SetFrontEngine(Vehicle *v)
    43 {
    43 {
    44 	assert(v->type == VEH_TRAIN);
    44 	assert(v->type == VEH_TRAIN);
    45 	SetBit(v->subtype, Train_Front);
    45 	SetBit(v->subtype, TS_FRONT);
    46 }
    46 }
    47 
    47 
    48 /** Remove the front engine state
    48 /** Remove the front engine state
    49  * @param v vehicle to change
    49  * @param v vehicle to change
    50  */
    50  */
    51 static inline void ClearFrontEngine(Vehicle *v)
    51 static inline void ClearFrontEngine(Vehicle *v)
    52 {
    52 {
    53 	assert(v->type == VEH_TRAIN);
    53 	assert(v->type == VEH_TRAIN);
    54 	ClrBit(v->subtype, Train_Front);
    54 	ClrBit(v->subtype, TS_FRONT);
    55 }
    55 }
    56 
    56 
    57 /** Check if a vehicle is an articulated part of an engine
    57 /** Check if a vehicle is an articulated part of an engine
    58  * @param v vehicle to check
    58  * @param v vehicle to check
    59  * @return Returns true if vehicle is an articulated part
    59  * @return Returns true if vehicle is an articulated part
    60  */
    60  */
    61 static inline bool IsArticulatedPart(const Vehicle *v)
    61 static inline bool IsArticulatedPart(const Vehicle *v)
    62 {
    62 {
    63 	assert(v->type == VEH_TRAIN);
    63 	assert(v->type == VEH_TRAIN);
    64 	return HasBit(v->subtype, Train_Articulated_Part);
    64 	return HasBit(v->subtype, TS_ARTICULATED_PART);
    65 }
    65 }
    66 
    66 
    67 /** Set a vehicle to be an articulated part
    67 /** Set a vehicle to be an articulated part
    68  * @param v vehicle to change
    68  * @param v vehicle to change
    69  */
    69  */
    70 static inline void SetArticulatedPart(Vehicle *v)
    70 static inline void SetArticulatedPart(Vehicle *v)
    71 {
    71 {
    72 	assert(v->type == VEH_TRAIN);
    72 	assert(v->type == VEH_TRAIN);
    73 	SetBit(v->subtype, Train_Articulated_Part);
    73 	SetBit(v->subtype, TS_ARTICULATED_PART);
    74 }
    74 }
    75 
    75 
    76 /** Clear a vehicle from being an articulated part
    76 /** Clear a vehicle from being an articulated part
    77  * @param v vehicle to change
    77  * @param v vehicle to change
    78  */
    78  */
    79 static inline void ClearArticulatedPart(Vehicle *v)
    79 static inline void ClearArticulatedPart(Vehicle *v)
    80 {
    80 {
    81 	assert(v->type == VEH_TRAIN);
    81 	assert(v->type == VEH_TRAIN);
    82 	ClrBit(v->subtype, Train_Articulated_Part);
    82 	ClrBit(v->subtype, TS_ARTICULATED_PART);
    83 }
    83 }
    84 
    84 
    85 /** Check if a vehicle is a wagon
    85 /** Check if a vehicle is a wagon
    86  * @param v vehicle to check
    86  * @param v vehicle to check
    87  * @return Returns true if vehicle is a wagon
    87  * @return Returns true if vehicle is a wagon
    88  */
    88  */
    89 static inline bool IsTrainWagon(const Vehicle *v)
    89 static inline bool IsTrainWagon(const Vehicle *v)
    90 {
    90 {
    91 	assert(v->type == VEH_TRAIN);
    91 	assert(v->type == VEH_TRAIN);
    92 	return HasBit(v->subtype, Train_Wagon);
    92 	return HasBit(v->subtype, TS_WAGON);
    93 }
    93 }
    94 
    94 
    95 /** Set a vehicle to be a wagon
    95 /** Set a vehicle to be a wagon
    96  * @param v vehicle to change
    96  * @param v vehicle to change
    97  */
    97  */
    98 static inline void SetTrainWagon(Vehicle *v)
    98 static inline void SetTrainWagon(Vehicle *v)
    99 {
    99 {
   100 	assert(v->type == VEH_TRAIN);
   100 	assert(v->type == VEH_TRAIN);
   101 	SetBit(v->subtype, Train_Wagon);
   101 	SetBit(v->subtype, TS_WAGON);
   102 }
   102 }
   103 
   103 
   104 /** Clear wagon property
   104 /** Clear wagon property
   105  * @param v vehicle to change
   105  * @param v vehicle to change
   106  */
   106  */
   107 static inline void ClearTrainWagon(Vehicle *v)
   107 static inline void ClearTrainWagon(Vehicle *v)
   108 {
   108 {
   109 	assert(v->type == VEH_TRAIN);
   109 	assert(v->type == VEH_TRAIN);
   110 	ClrBit(v->subtype, Train_Wagon);
   110 	ClrBit(v->subtype, TS_WAGON);
   111 }
   111 }
   112 
   112 
   113 /** Check if a vehicle is an engine (can be first in a train)
   113 /** Check if a vehicle is an engine (can be first in a train)
   114  * @param v vehicle to check
   114  * @param v vehicle to check
   115  * @return Returns true if vehicle is an engine
   115  * @return Returns true if vehicle is an engine
   116  */
   116  */
   117 static inline bool IsTrainEngine(const Vehicle *v)
   117 static inline bool IsTrainEngine(const Vehicle *v)
   118 {
   118 {
   119 	assert(v->type == VEH_TRAIN);
   119 	assert(v->type == VEH_TRAIN);
   120 	return HasBit(v->subtype, Train_Engine);
   120 	return HasBit(v->subtype, TS_ENGINE);
   121 }
   121 }
   122 
   122 
   123 /** Set engine status
   123 /** Set engine status
   124  * @param v vehicle to change
   124  * @param v vehicle to change
   125  */
   125  */
   126 static inline void SetTrainEngine(Vehicle *v)
   126 static inline void SetTrainEngine(Vehicle *v)
   127 {
   127 {
   128 	assert(v->type == VEH_TRAIN);
   128 	assert(v->type == VEH_TRAIN);
   129 	SetBit(v->subtype, Train_Engine);
   129 	SetBit(v->subtype, TS_ENGINE);
   130 }
   130 }
   131 
   131 
   132 /** Clear engine status
   132 /** Clear engine status
   133  * @param v vehicle to change
   133  * @param v vehicle to change
   134  */
   134  */
   135 static inline void ClearTrainEngine(Vehicle *v)
   135 static inline void ClearTrainEngine(Vehicle *v)
   136 {
   136 {
   137 	assert(v->type == VEH_TRAIN);
   137 	assert(v->type == VEH_TRAIN);
   138 	ClrBit(v->subtype, Train_Engine);
   138 	ClrBit(v->subtype, TS_ENGINE);
   139 }
   139 }
   140 
   140 
   141 /** Check if a vehicle is a free wagon (got no engine in front of it)
   141 /** Check if a vehicle is a free wagon (got no engine in front of it)
   142  * @param v vehicle to check
   142  * @param v vehicle to check
   143  * @return Returns true if vehicle is a free wagon
   143  * @return Returns true if vehicle is a free wagon
   144  */
   144  */
   145 static inline bool IsFreeWagon(const Vehicle *v)
   145 static inline bool IsFreeWagon(const Vehicle *v)
   146 {
   146 {
   147 	assert(v->type == VEH_TRAIN);
   147 	assert(v->type == VEH_TRAIN);
   148 	return HasBit(v->subtype, Train_Free_Wagon);
   148 	return HasBit(v->subtype, TS_FREE_WAGON);
   149 }
   149 }
   150 
   150 
   151 /** Set if a vehicle is a free wagon
   151 /** Set if a vehicle is a free wagon
   152  * @param v vehicle to change
   152  * @param v vehicle to change
   153  */
   153  */
   154 static inline void SetFreeWagon(Vehicle *v)
   154 static inline void SetFreeWagon(Vehicle *v)
   155 {
   155 {
   156 	assert(v->type == VEH_TRAIN);
   156 	assert(v->type == VEH_TRAIN);
   157 	SetBit(v->subtype, Train_Free_Wagon);
   157 	SetBit(v->subtype, TS_FREE_WAGON);
   158 }
   158 }
   159 
   159 
   160 /** Clear a vehicle from being a free wagon
   160 /** Clear a vehicle from being a free wagon
   161  * @param v vehicle to change
   161  * @param v vehicle to change
   162  */
   162  */
   163 static inline void ClearFreeWagon(Vehicle *v)
   163 static inline void ClearFreeWagon(Vehicle *v)
   164 {
   164 {
   165 	assert(v->type == VEH_TRAIN);
   165 	assert(v->type == VEH_TRAIN);
   166 	ClrBit(v->subtype, Train_Free_Wagon);
   166 	ClrBit(v->subtype, TS_FREE_WAGON);
   167 }
   167 }
   168 
   168 
   169 /** Check if a vehicle is a multiheaded engine
   169 /** Check if a vehicle is a multiheaded engine
   170  * @param v vehicle to check
   170  * @param v vehicle to check
   171  * @return Returns true if vehicle is a multiheaded engine
   171  * @return Returns true if vehicle is a multiheaded engine
   172  */
   172  */
   173 static inline bool IsMultiheaded(const Vehicle *v)
   173 static inline bool IsMultiheaded(const Vehicle *v)
   174 {
   174 {
   175 	assert(v->type == VEH_TRAIN);
   175 	assert(v->type == VEH_TRAIN);
   176 	return HasBit(v->subtype, Train_Multiheaded);
   176 	return HasBit(v->subtype, TS_MULTIHEADED);
   177 }
   177 }
   178 
   178 
   179 /** Set if a vehicle is a multiheaded engine
   179 /** Set if a vehicle is a multiheaded engine
   180  * @param v vehicle to change
   180  * @param v vehicle to change
   181  */
   181  */
   182 static inline void SetMultiheaded(Vehicle *v)
   182 static inline void SetMultiheaded(Vehicle *v)
   183 {
   183 {
   184 	assert(v->type == VEH_TRAIN);
   184 	assert(v->type == VEH_TRAIN);
   185 	SetBit(v->subtype, Train_Multiheaded);
   185 	SetBit(v->subtype, TS_MULTIHEADED);
   186 }
   186 }
   187 
   187 
   188 /** Clear multiheaded engine property
   188 /** Clear multiheaded engine property
   189  * @param v vehicle to change
   189  * @param v vehicle to change
   190  */
   190  */
   191 static inline void ClearMultiheaded(Vehicle *v)
   191 static inline void ClearMultiheaded(Vehicle *v)
   192 {
   192 {
   193 	assert(v->type == VEH_TRAIN);
   193 	assert(v->type == VEH_TRAIN);
   194 	ClrBit(v->subtype, Train_Multiheaded);
   194 	ClrBit(v->subtype, TS_MULTIHEADED);
   195 }
   195 }
   196 
   196 
   197 /** Check if an engine has an articulated part.
   197 /** Check if an engine has an articulated part.
   198  * @param v Vehicle.
   198  * @param v Vehicle.
   199  * @return True if the engine has an articulated part.
   199  * @return True if the engine has an articulated part.