summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/articulated_vehicles.cpp2
-rw-r--r--src/saveload/vehicle_sl.cpp28
-rw-r--r--src/train.h171
-rw-r--r--src/train_cmd.cpp28
4 files changed, 92 insertions, 137 deletions
diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp
index 7936b1273..51ae3d4f1 100644
--- a/src/articulated_vehicles.cpp
+++ b/src/articulated_vehicles.cpp
@@ -322,7 +322,7 @@ void AddArticulatedParts(Vehicle *first, VehicleType type)
t->cargo_cap = 0;
}
- SetArticulatedPart(t);
+ t->SetArticulatedPart();
} break;
case VEH_ROAD: {
diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp
index bbe0a5f4f..b08d373d2 100644
--- a/src/saveload/vehicle_sl.cpp
+++ b/src/saveload/vehicle_sl.cpp
@@ -50,7 +50,7 @@ void ConnectMultiheadedTrains()
if (u->IsMultiheaded()) {
if (!u->IsEngine()) {
/* we got a rear car without a front car. We will convert it to a front one */
- SetTrainEngine(u);
+ u->SetEngine();
u->spritenum--;
}
@@ -63,7 +63,7 @@ void ConnectMultiheadedTrains()
/* we found a car to partner with this engine. Now we will make sure it face the right way */
if (w->IsEngine()) {
- ClearTrainEngine(w);
+ w->ClearEngine();
w->spritenum++;
}
break;
@@ -87,7 +87,7 @@ void ConnectMultiheadedTrains()
u->other_multiheaded_part = w;
} else {
/* we got a front car and no rear cars. We will fake this one for forget that it should have been multiheaded */
- ClearMultiheaded(u);
+ u->ClearMultiheaded();
}
}
}
@@ -106,42 +106,42 @@ void ConvertOldMultiheadToNew()
FOR_ALL_TRAINS(t) {
if (HasBit(t->subtype, 7) && ((t->subtype & ~0x80) == 0 || (t->subtype & ~0x80) == 4)) {
- for (Vehicle *u = t; u != NULL; u = u->Next()) {
+ for (Train *u = t; u != NULL; u = u->Next()) {
const RailVehicleInfo *rvi = RailVehInfo(u->engine_type);
ClrBit(u->subtype, 7);
switch (u->subtype) {
case 0: // TS_Front_Engine
- if (rvi->railveh_type == RAILVEH_MULTIHEAD) SetMultiheaded(u);
- SetFrontEngine(u);
- SetTrainEngine(u);
+ if (rvi->railveh_type == RAILVEH_MULTIHEAD) u->SetMultiheaded();
+ u->SetFrontEngine();
+ u->SetEngine();
break;
case 1: // TS_Artic_Part
u->subtype = 0;
- SetArticulatedPart(u);
+ u->SetArticulatedPart();
break;
case 2: // TS_Not_First
u->subtype = 0;
if (rvi->railveh_type == RAILVEH_WAGON) {
/* normal wagon */
- SetTrainWagon(u);
+ u->SetWagon();
break;
}
if (rvi->railveh_type == RAILVEH_MULTIHEAD && rvi->image_index == u->spritenum - 1) {
/* rear end of a multiheaded engine */
- SetMultiheaded(u);
+ u->SetMultiheaded();
break;
}
- if (rvi->railveh_type == RAILVEH_MULTIHEAD) SetMultiheaded(u);
- SetTrainEngine(u);
+ if (rvi->railveh_type == RAILVEH_MULTIHEAD) u->SetMultiheaded();
+ u->SetEngine();
break;
case 4: // TS_Free_Car
u->subtype = 0;
- SetTrainWagon(u);
- SetFreeWagon(u);
+ u->SetWagon();
+ u->SetFreeWagon();
break;
default: NOT_REACHED();
}
diff --git a/src/train.h b/src/train.h
index ef4b06167..4476bb7ff 100644
--- a/src/train.h
+++ b/src/train.h
@@ -51,114 +51,6 @@ enum TrainSubtype {
TS_MULTIHEADED = 5, ///< Engine is a multiheaded
};
-/** Set front engine state
- * @param v vehicle to change
- */
-static inline void SetFrontEngine(Vehicle *v)
-{
- assert(v->type == VEH_TRAIN);
- SetBit(v->subtype, TS_FRONT);
-}
-
-/** Remove the front engine state
- * @param v vehicle to change
- */
-static inline void ClearFrontEngine(Vehicle *v)
-{
- assert(v->type == VEH_TRAIN);
- ClrBit(v->subtype, TS_FRONT);
-}
-
-/** Set a vehicle to be an articulated part
- * @param v vehicle to change
- */
-static inline void SetArticulatedPart(Vehicle *v)
-{
- assert(v->type == VEH_TRAIN);
- SetBit(v->subtype, TS_ARTICULATED_PART);
-}
-
-/** Clear a vehicle from being an articulated part
- * @param v vehicle to change
- */
-static inline void ClearArticulatedPart(Vehicle *v)
-{
- assert(v->type == VEH_TRAIN);
- ClrBit(v->subtype, TS_ARTICULATED_PART);
-}
-
-/** Set a vehicle to be a wagon
- * @param v vehicle to change
- */
-static inline void SetTrainWagon(Vehicle *v)
-{
- assert(v->type == VEH_TRAIN);
- SetBit(v->subtype, TS_WAGON);
-}
-
-/** Clear wagon property
- * @param v vehicle to change
- */
-static inline void ClearTrainWagon(Vehicle *v)
-{
- assert(v->type == VEH_TRAIN);
- ClrBit(v->subtype, TS_WAGON);
-}
-
-/** Set engine status
- * @param v vehicle to change
- */
-static inline void SetTrainEngine(Vehicle *v)
-{
- assert(v->type == VEH_TRAIN);
- SetBit(v->subtype, TS_ENGINE);
-}
-
-/** Clear engine status
- * @param v vehicle to change
- */
-static inline void ClearTrainEngine(Vehicle *v)
-{
- assert(v->type == VEH_TRAIN);
- ClrBit(v->subtype, TS_ENGINE);
-}
-
-/** Set if a vehicle is a free wagon
- * @param v vehicle to change
- */
-static inline void SetFreeWagon(Vehicle *v)
-{
- assert(v->type == VEH_TRAIN);
- SetBit(v->subtype, TS_FREE_WAGON);
-}
-
-/** Clear a vehicle from being a free wagon
- * @param v vehicle to change
- */
-static inline void ClearFreeWagon(Vehicle *v)
-{
- assert(v->type == VEH_TRAIN);
- ClrBit(v->subtype, TS_FREE_WAGON);
-}
-
-
-/** Set if a vehicle is a multiheaded engine
- * @param v vehicle to change
- */
-static inline void SetMultiheaded(Vehicle *v)
-{
- assert(v->type == VEH_TRAIN);
- SetBit(v->subtype, TS_MULTIHEADED);
-}
-
-/** Clear multiheaded engine property
- * @param v vehicle to change
- */
-static inline void ClearMultiheaded(Vehicle *v)
-{
- assert(v->type == VEH_TRAIN);
- ClrBit(v->subtype, TS_MULTIHEADED);
-}
void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2);
void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2);
@@ -258,6 +150,69 @@ struct Train : public SpecializedVehicle<Train, VEH_TRAIN> {
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
/**
+ * Set front engine state
+ */
+ FORCEINLINE void SetFrontEngine() { SetBit(this->subtype, TS_FRONT); }
+
+ /**
+ * Remove the front engine state
+ */
+ FORCEINLINE void ClearFrontEngine() { ClrBit(this->subtype, TS_FRONT); }
+
+ /**
+ * Set a vehicle to be an articulated part
+ */
+ FORCEINLINE void SetArticulatedPart() { SetBit(this->subtype, TS_ARTICULATED_PART); }
+
+ /**
+ * Clear a vehicle from being an articulated part
+ */
+ FORCEINLINE void ClearArticulatedPart() { ClrBit(this->subtype, TS_ARTICULATED_PART); }
+
+ /**
+ * Set a vehicle to be a wagon
+ */
+ FORCEINLINE void SetWagon() { SetBit(this->subtype, TS_WAGON); }
+
+ /**
+ * Clear wagon property
+ */
+ FORCEINLINE void ClearWagon() { ClrBit(this->subtype, TS_WAGON); }
+
+ /**
+ * Set engine status
+ * @param v vehicle to change
+ */
+ FORCEINLINE void SetEngine() { SetBit(this->subtype, TS_ENGINE); }
+
+ /**
+ * Clear engine status
+ */
+ FORCEINLINE void ClearEngine() { ClrBit(this->subtype, TS_ENGINE); }
+
+ /**
+ * Set if a vehicle is a free wagon
+ */
+ FORCEINLINE void SetFreeWagon() { SetBit(this->subtype, TS_FREE_WAGON); }
+
+ /**
+ * Clear a vehicle from being a free wagon
+ * @param v vehicle to change
+ */
+ FORCEINLINE void ClearFreeWagon() { ClrBit(this->subtype, TS_FREE_WAGON); }
+
+ /**
+ * Set if a vehicle is a multiheaded engine
+ */
+ FORCEINLINE void SetMultiheaded() { SetBit(this->subtype, TS_MULTIHEADED); }
+
+ /**
+ * Clear multiheaded engine property
+ */
+ FORCEINLINE void ClearMultiheaded() { ClrBit(this->subtype, TS_MULTIHEADED); }
+
+
+ /**
* Check if train is a front engine
* @return Returns true if train is a front engine
*/
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 5c44604fb..93af6877a 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -704,12 +704,12 @@ static CommandCost CmdBuildRailWagon(EngineID engine, TileIndex tile, DoCommandF
v->vehstatus = VS_HIDDEN | VS_DEFPAL;
// v->subtype = 0;
- SetTrainWagon(v);
+ v->SetWagon();
if (u != NULL) {
u->SetNext(v);
} else {
- SetFreeWagon(v);
+ v->SetFreeWagon();
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
}
@@ -784,8 +784,8 @@ static void AddRearEngineToMultiheadedTrain(Train *v)
u->build_year = v->build_year;
u->cur_image = SPR_IMG_QUERY;
u->random_bits = VehicleRandomBits();
- SetMultiheaded(v);
- SetMultiheaded(u);
+ v->SetMultiheaded();
+ u->SetMultiheaded();
v->SetNext(u);
VehicleMove(u, false);
@@ -886,8 +886,8 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
v->group_id = DEFAULT_GROUP;
// v->subtype = 0;
- SetFrontEngine(v);
- SetTrainEngine(v);
+ v->SetFrontEngine();
+ v->SetEngine();
VehicleMove(v, false);
@@ -971,7 +971,7 @@ static Train *UnlinkWagon(Train *v, Train *first)
v = GetNextVehicle(v);
if (v == NULL) return NULL;
- if (v->IsWagon()) SetFreeWagon(v);
+ if (v->IsWagon()) v->SetFreeWagon();
/* First can be an articulated engine, meaning GetNextVehicle() isn't
* v->Next(). Thus set the next vehicle of the last articulated part
@@ -1020,8 +1020,8 @@ static void AddWagonToConsist(Train *v, Train *dest)
v->SetNext(NULL);
dest->SetNext(v);
v->SetNext(next);
- ClearFreeWagon(v);
- ClearFrontEngine(v);
+ v->ClearFreeWagon();
+ v->ClearFrontEngine();
}
/*
@@ -1302,7 +1302,7 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, u
if (src->IsEngine()) {
if (!src->IsFrontEngine()) {
/* setting the type to 0 also involves setting up the orders field. */
- SetFrontEngine(src);
+ src->SetFrontEngine();
assert(src->orders.list == NULL);
/* Decrease the engines number of the src engine_type */
@@ -1314,7 +1314,7 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, u
src->group_id = DEFAULT_GROUP;
}
} else {
- SetFreeWagon(src);
+ src->SetFreeWagon();
}
dst_head = src;
} else {
@@ -1331,8 +1331,8 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, u
if (src->IsFrontEngine() || src->IsFreeWagon()) {
InvalidateWindowData(WC_VEHICLE_DEPOT, src->tile);
- ClearFrontEngine(src);
- ClearFreeWagon(src);
+ src->ClearFrontEngine();
+ src->ClearFreeWagon();
src->unitnumber = 0; // doesn't occupy a unitnumber anymore.
}
@@ -1504,7 +1504,7 @@ CommandCost CmdSellRailWagon(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
/* 4 If the second wagon was an engine, update it to front_engine
* which UnlinkWagon() has changed to TS_Free_Car */
- if (switch_engine) SetFrontEngine(first);
+ if (switch_engine) first->SetFrontEngine();
/* 5. If the train still exists, update its acceleration, window, etc. */
if (first != NULL) {