src/train.h
branchgamebalance
changeset 9912 1ac8aac92385
parent 9911 0b8b245a2391
equal deleted inserted replaced
9911:0b8b245a2391 9912:1ac8aac92385
    29  * @param v vehicle to check
    29  * @param v vehicle to check
    30  * @return Returns true if vehicle is a front engine
    30  * @return Returns true if vehicle is a front engine
    31  */
    31  */
    32 static inline bool IsFrontEngine(const Vehicle *v)
    32 static inline bool IsFrontEngine(const Vehicle *v)
    33 {
    33 {
       
    34 	assert(v->type == VEH_TRAIN);
    34 	return HASBIT(v->subtype, Train_Front);
    35 	return HASBIT(v->subtype, Train_Front);
    35 }
    36 }
    36 
    37 
    37 /** Set front engine state
    38 /** Set front engine state
    38  * @param v vehicle to change
    39  * @param v vehicle to change
    39  */
    40  */
    40 static inline void SetFrontEngine(Vehicle *v)
    41 static inline void SetFrontEngine(Vehicle *v)
    41 {
    42 {
       
    43 	assert(v->type == VEH_TRAIN);
    42 	SETBIT(v->subtype, Train_Front);
    44 	SETBIT(v->subtype, Train_Front);
    43 }
    45 }
    44 
    46 
    45 /** Remove the front engine state
    47 /** Remove the front engine state
    46  * @param v vehicle to change
    48  * @param v vehicle to change
    47  */
    49  */
    48 static inline void ClearFrontEngine(Vehicle *v)
    50 static inline void ClearFrontEngine(Vehicle *v)
    49 {
    51 {
       
    52 	assert(v->type == VEH_TRAIN);
    50 	CLRBIT(v->subtype, Train_Front);
    53 	CLRBIT(v->subtype, Train_Front);
    51 }
    54 }
    52 
    55 
    53 /** Check if a vehicle is an articulated part of an engine
    56 /** Check if a vehicle is an articulated part of an engine
    54  * @param v vehicle to check
    57  * @param v vehicle to check
    55  * @return Returns true if vehicle is an articulated part
    58  * @return Returns true if vehicle is an articulated part
    56  */
    59  */
    57 static inline bool IsArticulatedPart(const Vehicle *v)
    60 static inline bool IsArticulatedPart(const Vehicle *v)
    58 {
    61 {
       
    62 	assert(v->type == VEH_TRAIN);
    59 	return HASBIT(v->subtype, Train_Articulated_Part);
    63 	return HASBIT(v->subtype, Train_Articulated_Part);
    60 }
    64 }
    61 
    65 
    62 /** Set a vehicle to be an articulated part
    66 /** Set a vehicle to be an articulated part
    63  * @param v vehicle to change
    67  * @param v vehicle to change
    64  */
    68  */
    65 static inline void SetArticulatedPart(Vehicle *v)
    69 static inline void SetArticulatedPart(Vehicle *v)
    66 {
    70 {
       
    71 	assert(v->type == VEH_TRAIN);
    67 	SETBIT(v->subtype, Train_Articulated_Part);
    72 	SETBIT(v->subtype, Train_Articulated_Part);
    68 }
    73 }
    69 
    74 
    70 /** Clear a vehicle from being an articulated part
    75 /** Clear a vehicle from being an articulated part
    71  * @param v vehicle to change
    76  * @param v vehicle to change
    72  */
    77  */
    73 static inline void ClearArticulatedPart(Vehicle *v)
    78 static inline void ClearArticulatedPart(Vehicle *v)
    74 {
    79 {
       
    80 	assert(v->type == VEH_TRAIN);
    75 	CLRBIT(v->subtype, Train_Articulated_Part);
    81 	CLRBIT(v->subtype, Train_Articulated_Part);
    76 }
    82 }
    77 
    83 
    78 /** Check if a vehicle is a wagon
    84 /** Check if a vehicle is a wagon
    79  * @param v vehicle to check
    85  * @param v vehicle to check
    80  * @return Returns true if vehicle is a wagon
    86  * @return Returns true if vehicle is a wagon
    81  */
    87  */
    82 static inline bool IsTrainWagon(const Vehicle *v)
    88 static inline bool IsTrainWagon(const Vehicle *v)
    83 {
    89 {
       
    90 	assert(v->type == VEH_TRAIN);
    84 	return HASBIT(v->subtype, Train_Wagon);
    91 	return HASBIT(v->subtype, Train_Wagon);
    85 }
    92 }
    86 
    93 
    87 /** Set a vehicle to be a wagon
    94 /** Set a vehicle to be a wagon
    88  * @param v vehicle to change
    95  * @param v vehicle to change
    89  */
    96  */
    90 static inline void SetTrainWagon(Vehicle *v)
    97 static inline void SetTrainWagon(Vehicle *v)
    91 {
    98 {
       
    99 	assert(v->type == VEH_TRAIN);
    92 	SETBIT(v->subtype, Train_Wagon);
   100 	SETBIT(v->subtype, Train_Wagon);
    93 }
   101 }
    94 
   102 
    95 /** Clear wagon property
   103 /** Clear wagon property
    96  * @param v vehicle to change
   104  * @param v vehicle to change
    97  */
   105  */
    98 static inline void ClearTrainWagon(Vehicle *v)
   106 static inline void ClearTrainWagon(Vehicle *v)
    99 {
   107 {
       
   108 	assert(v->type == VEH_TRAIN);
   100 	CLRBIT(v->subtype, Train_Wagon);
   109 	CLRBIT(v->subtype, Train_Wagon);
   101 }
   110 }
   102 
   111 
   103 /** Check if a vehicle is an engine (can be first in a train)
   112 /** Check if a vehicle is an engine (can be first in a train)
   104  * @param v vehicle to check
   113  * @param v vehicle to check
   105  * @return Returns true if vehicle is an engine
   114  * @return Returns true if vehicle is an engine
   106  */
   115  */
   107 static inline bool IsTrainEngine(const Vehicle *v)
   116 static inline bool IsTrainEngine(const Vehicle *v)
   108 {
   117 {
       
   118 	assert(v->type == VEH_TRAIN);
   109 	return HASBIT(v->subtype, Train_Engine);
   119 	return HASBIT(v->subtype, Train_Engine);
   110 }
   120 }
   111 
   121 
   112 /** Set engine status
   122 /** Set engine status
   113  * @param v vehicle to change
   123  * @param v vehicle to change
   114  */
   124  */
   115 static inline void SetTrainEngine(Vehicle *v)
   125 static inline void SetTrainEngine(Vehicle *v)
   116 {
   126 {
       
   127 	assert(v->type == VEH_TRAIN);
   117 	SETBIT(v->subtype, Train_Engine);
   128 	SETBIT(v->subtype, Train_Engine);
   118 }
   129 }
   119 
   130 
   120 /** Clear engine status
   131 /** Clear engine status
   121  * @param v vehicle to change
   132  * @param v vehicle to change
   122  */
   133  */
   123 static inline void ClearTrainEngine(Vehicle *v)
   134 static inline void ClearTrainEngine(Vehicle *v)
   124 {
   135 {
       
   136 	assert(v->type == VEH_TRAIN);
   125 	CLRBIT(v->subtype, Train_Engine);
   137 	CLRBIT(v->subtype, Train_Engine);
   126 }
   138 }
   127 
   139 
   128 /** Check if a vehicle is a free wagon (got no engine in front of it)
   140 /** Check if a vehicle is a free wagon (got no engine in front of it)
   129  * @param v vehicle to check
   141  * @param v vehicle to check
   130  * @return Returns true if vehicle is a free wagon
   142  * @return Returns true if vehicle is a free wagon
   131  */
   143  */
   132 static inline bool IsFreeWagon(const Vehicle *v)
   144 static inline bool IsFreeWagon(const Vehicle *v)
   133 {
   145 {
       
   146 	assert(v->type == VEH_TRAIN);
   134 	return HASBIT(v->subtype, Train_Free_Wagon);
   147 	return HASBIT(v->subtype, Train_Free_Wagon);
   135 }
   148 }
   136 
   149 
   137 /** Set if a vehicle is a free wagon
   150 /** Set if a vehicle is a free wagon
   138  * @param v vehicle to change
   151  * @param v vehicle to change
   139  */
   152  */
   140 static inline void SetFreeWagon(Vehicle *v)
   153 static inline void SetFreeWagon(Vehicle *v)
   141 {
   154 {
       
   155 	assert(v->type == VEH_TRAIN);
   142 	SETBIT(v->subtype, Train_Free_Wagon);
   156 	SETBIT(v->subtype, Train_Free_Wagon);
   143 }
   157 }
   144 
   158 
   145 /** Clear a vehicle from being a free wagon
   159 /** Clear a vehicle from being a free wagon
   146  * @param v vehicle to change
   160  * @param v vehicle to change
   147  */
   161  */
   148 static inline void ClearFreeWagon(Vehicle *v)
   162 static inline void ClearFreeWagon(Vehicle *v)
   149 {
   163 {
       
   164 	assert(v->type == VEH_TRAIN);
   150 	CLRBIT(v->subtype, Train_Free_Wagon);
   165 	CLRBIT(v->subtype, Train_Free_Wagon);
   151 }
   166 }
   152 
   167 
   153 /** Check if a vehicle is a multiheaded engine
   168 /** Check if a vehicle is a multiheaded engine
   154  * @param v vehicle to check
   169  * @param v vehicle to check
   155  * @return Returns true if vehicle is a multiheaded engine
   170  * @return Returns true if vehicle is a multiheaded engine
   156  */
   171  */
   157 static inline bool IsMultiheaded(const Vehicle *v)
   172 static inline bool IsMultiheaded(const Vehicle *v)
   158 {
   173 {
       
   174 	assert(v->type == VEH_TRAIN);
   159 	return HASBIT(v->subtype, Train_Multiheaded);
   175 	return HASBIT(v->subtype, Train_Multiheaded);
   160 }
   176 }
   161 
   177 
   162 /** Set if a vehicle is a multiheaded engine
   178 /** Set if a vehicle is a multiheaded engine
   163  * @param v vehicle to change
   179  * @param v vehicle to change
   164  */
   180  */
   165 static inline void SetMultiheaded(Vehicle *v)
   181 static inline void SetMultiheaded(Vehicle *v)
   166 {
   182 {
       
   183 	assert(v->type == VEH_TRAIN);
   167 	SETBIT(v->subtype, Train_Multiheaded);
   184 	SETBIT(v->subtype, Train_Multiheaded);
   168 }
   185 }
   169 
   186 
   170 /** Clear multiheaded engine property
   187 /** Clear multiheaded engine property
   171  * @param v vehicle to change
   188  * @param v vehicle to change
   172  */
   189  */
   173 static inline void ClearMultiheaded(Vehicle *v)
   190 static inline void ClearMultiheaded(Vehicle *v)
   174 {
   191 {
       
   192 	assert(v->type == VEH_TRAIN);
   175 	CLRBIT(v->subtype, Train_Multiheaded);
   193 	CLRBIT(v->subtype, Train_Multiheaded);
   176 }
   194 }
   177 
   195 
   178 /** Check if an engine has an articulated part.
   196 /** Check if an engine has an articulated part.
   179  * @param v Vehicle.
   197  * @param v Vehicle.
   180  * @return True if the engine has an articulated part.
   198  * @return True if the engine has an articulated part.
   181  */
   199  */
   182 static inline bool EngineHasArticPart(const Vehicle *v)
   200 static inline bool EngineHasArticPart(const Vehicle *v)
   183 {
   201 {
       
   202 	assert(v->type == VEH_TRAIN);
   184 	return (v->next != NULL && IsArticulatedPart(v->next));
   203 	return (v->next != NULL && IsArticulatedPart(v->next));
   185 }
   204 }
   186 
   205 
   187 /**
   206 /**
   188  * Get the next part of a multi-part engine.
   207  * Get the next part of a multi-part engine.
   199  * @param v Vehicle.
   218  * @param v Vehicle.
   200  * @return Last part of the engine.
   219  * @return Last part of the engine.
   201  */
   220  */
   202 static inline Vehicle *GetLastEnginePart(Vehicle *v)
   221 static inline Vehicle *GetLastEnginePart(Vehicle *v)
   203 {
   222 {
       
   223 	assert(v->type == VEH_TRAIN);
   204 	while (EngineHasArticPart(v)) v = GetNextArticPart(v);
   224 	while (EngineHasArticPart(v)) v = GetNextArticPart(v);
   205 	return v;
   225 	return v;
   206 }
   226 }
   207 
   227 
   208 /** Get the next real (non-articulated part) vehicle in the consist.
   228 /** Get the next real (non-articulated part) vehicle in the consist.
   209  * @param v Vehicle.
   229  * @param v Vehicle.
   210  * @return Next vehicle in the consist.
   230  * @return Next vehicle in the consist.
   211  */
   231  */
   212 static inline Vehicle *GetNextVehicle(const Vehicle *v)
   232 static inline Vehicle *GetNextVehicle(const Vehicle *v)
   213 {
   233 {
       
   234 	assert(v->type == VEH_TRAIN);
   214 	while (EngineHasArticPart(v)) v = GetNextArticPart(v);
   235 	while (EngineHasArticPart(v)) v = GetNextArticPart(v);
   215 
   236 
   216 	/* v now contains the last artic part in the engine */
   237 	/* v now contains the last artic part in the engine */
   217 	return v->next;
   238 	return v->next;
   218 }
   239 }
   247 	void MarkDirty();
   268 	void MarkDirty();
   248 	void UpdateDeltaXY(Direction direction);
   269 	void UpdateDeltaXY(Direction direction);
   249 	ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_TRAIN_INC : EXPENSES_TRAIN_RUN; }
   270 	ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_TRAIN_INC : EXPENSES_TRAIN_RUN; }
   250 	WindowClass GetVehicleListWindowClass() const { return WC_TRAINS_LIST; }
   271 	WindowClass GetVehicleListWindowClass() const { return WC_TRAINS_LIST; }
   251 	void PlayLeaveStationSound() const;
   272 	void PlayLeaveStationSound() const;
       
   273 	bool IsPrimaryVehicle() const { return IsFrontEngine(this); }
       
   274 	bool HasFront() const { return true; }
   252 };
   275 };
   253 
   276 
   254 #endif /* TRAIN_H */
   277 #endif /* TRAIN_H */