summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ground_vehicle.cpp2
-rw-r--r--src/ground_vehicle.hpp26
-rw-r--r--src/saveload/afterload.cpp12
-rw-r--r--src/saveload/vehicle_sl.cpp1
-rw-r--r--src/train.h23
-rw-r--r--src/train_cmd.cpp36
-rw-r--r--src/tunnelbridge_cmd.cpp4
7 files changed, 60 insertions, 44 deletions
diff --git a/src/ground_vehicle.cpp b/src/ground_vehicle.cpp
index 1ab6da9da..92c135ee5 100644
--- a/src/ground_vehicle.cpp
+++ b/src/ground_vehicle.cpp
@@ -116,7 +116,7 @@ int GroundVehicle<T, Type>::GetAcceleration() const
resistance += (area * this->acc_cache.cached_air_drag * speed * speed) / 20000;
}
- resistance += v->GetSlopeResistance();
+ resistance += this->GetSlopeResistance();
resistance *= 4; //[N]
/* This value allows to know if the vehicle is accelerating or braking. */
diff --git a/src/ground_vehicle.hpp b/src/ground_vehicle.hpp
index 106b0b954..2682fb04d 100644
--- a/src/ground_vehicle.hpp
+++ b/src/ground_vehicle.hpp
@@ -37,6 +37,12 @@ struct AccelerationCache {
uint16 cached_max_track_speed; ///< Maximum consist speed limited by track type.
};
+/** Ground vehicle flags. */
+enum GroundVehicleFlags {
+ GVF_GOINGUP_BIT = 0,
+ GVF_GOINGDOWN_BIT = 1,
+};
+
/**
* Base class for all vehicles that move through ground.
*
@@ -58,6 +64,7 @@ struct AccelerationCache {
template <class T, VehicleType Type>
struct GroundVehicle : public SpecializedVehicle<T, Type> {
AccelerationCache acc_cache;
+ uint16 gv_flags; ///< @see GroundVehicleFlags
/**
* The constructor at SpecializedVehicle must be called.
@@ -67,6 +74,25 @@ struct GroundVehicle : public SpecializedVehicle<T, Type> {
void PowerChanged();
void CargoChanged();
int GetAcceleration() const;
+
+ /**
+ * Calculates the total slope resistance for this vehicle.
+ * @return Slope resistance.
+ */
+ FORCEINLINE int32 GetSlopeResistance() const
+ {
+ int32 incl = 0;
+
+ for (const T *u = T::From(this); u != NULL; u = u->Next()) {
+ if (HasBit(u->gv_flags, GVF_GOINGUP_BIT)) {
+ incl += u->acc_cache.cached_slope_resistance;
+ } else if (HasBit(u->gv_flags, GVF_GOINGDOWN_BIT)) {
+ incl -= u->acc_cache.cached_slope_resistance;
+ }
+ }
+
+ return incl;
+ }
};
#endif /* GROUND_VEHICLE_HPP */
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index e4069b1bb..d2b886c6d 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -2072,6 +2072,18 @@ bool AfterLoadGame()
st->airport.h = st->GetAirportSpec()->size_y;
}
}
+
+ Train *t;
+ FOR_ALL_TRAINS(t) {
+ /* Copy old GOINGUP / GOINGDOWN flags. */
+ if (HasBit(t->flags, 1)) {
+ ClrBit(t->flags, 1);
+ SetBit(t->gv_flags, GVF_GOINGUP_BIT);
+ } else if (HasBit(t->flags, 2)) {
+ ClrBit(t->flags, 2);
+ SetBit(t->gv_flags, GVF_GOINGDOWN_BIT);
+ }
+ }
}
/* Road stops is 'only' updating some caches */
diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp
index 70ce2e1f3..15782f524 100644
--- a/src/saveload/vehicle_sl.cpp
+++ b/src/saveload/vehicle_sl.cpp
@@ -544,6 +544,7 @@ const SaveLoad *GetVehicleDescription(VehicleType vt)
SLE_CONDVAR(Train, wait_counter, SLE_UINT16, 136, SL_MAX_VERSION),
SLE_CONDNULL(2, 2, 19),
+ SLE_CONDVAR(Train, gv_flags, SLE_UINT16, 139, SL_MAX_VERSION),
/* reserve extra space in savegame here. (currently 11 bytes) */
SLE_CONDNULL(11, 2, SL_MAX_VERSION),
diff --git a/src/train.h b/src/train.h
index 30226e605..71724c2c3 100644
--- a/src/train.h
+++ b/src/train.h
@@ -24,10 +24,6 @@ struct Train;
enum VehicleRailFlags {
VRF_REVERSING = 0,
- /* used to calculate if train is going up or down */
- VRF_GOINGUP = 1,
- VRF_GOINGDOWN = 2,
-
/* used to store if a wagon is powered or not */
VRF_POWEREDWAGON = 3,
@@ -453,25 +449,6 @@ protected: // These functions should not be called outside acceleration code.
}
/**
- * Calculates the total slope resistance for this vehicle.
- * @return Slope resistance.
- */
- FORCEINLINE int32 GetSlopeResistance() const
- {
- int32 incl = 0;
-
- for (const Train *u = this; u != NULL; u = u->Next()) {
- if (HasBit(u->flags, VRF_GOINGUP)) {
- incl += u->acc_cache.cached_slope_resistance;
- } else if (HasBit(u->flags, VRF_GOINGDOWN)) {
- incl -= u->acc_cache.cached_slope_resistance;
- }
- }
-
- return incl;
- }
-
- /**
* Allows to know the acceleration type of a vehicle.
* @return Acceleration type of the vehicle.
*/
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 39ef3c33f..83fa327b1 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -1477,22 +1477,22 @@ static void SwapTrainFlags(uint16 *swap_flag1, uint16 *swap_flag2)
uint16 flag2 = *swap_flag2;
/* Clear the flags */
- ClrBit(*swap_flag1, VRF_GOINGUP);
- ClrBit(*swap_flag1, VRF_GOINGDOWN);
- ClrBit(*swap_flag2, VRF_GOINGUP);
- ClrBit(*swap_flag2, VRF_GOINGDOWN);
+ ClrBit(*swap_flag1, GVF_GOINGUP_BIT);
+ ClrBit(*swap_flag1, GVF_GOINGDOWN_BIT);
+ ClrBit(*swap_flag2, GVF_GOINGUP_BIT);
+ ClrBit(*swap_flag2, GVF_GOINGDOWN_BIT);
/* Reverse the rail-flags (if needed) */
- if (HasBit(flag1, VRF_GOINGUP)) {
- SetBit(*swap_flag2, VRF_GOINGDOWN);
- } else if (HasBit(flag1, VRF_GOINGDOWN)) {
- SetBit(*swap_flag2, VRF_GOINGUP);
- }
- if (HasBit(flag2, VRF_GOINGUP)) {
- SetBit(*swap_flag1, VRF_GOINGDOWN);
- } else if (HasBit(flag2, VRF_GOINGDOWN)) {
- SetBit(*swap_flag1, VRF_GOINGUP);
- }
+ if (HasBit(flag1, GVF_GOINGUP_BIT)) {
+ SetBit(*swap_flag2, GVF_GOINGDOWN_BIT);
+ } else if (HasBit(flag1, GVF_GOINGDOWN_BIT)) {
+ SetBit(*swap_flag2, GVF_GOINGUP_BIT);
+ }
+ if (HasBit(flag2, GVF_GOINGUP_BIT)) {
+ SetBit(*swap_flag1, GVF_GOINGDOWN_BIT);
+ } else if (HasBit(flag2, GVF_GOINGDOWN_BIT)) {
+ SetBit(*swap_flag1, GVF_GOINGUP_BIT);
+ }
}
static void ReverseTrainSwapVeh(Train *v, int l, int r)
@@ -1523,7 +1523,7 @@ static void ReverseTrainSwapVeh(Train *v, int l, int r)
Swap(a->tile, b->tile);
Swap(a->z_pos, b->z_pos);
- SwapTrainFlags(&a->flags, &b->flags);
+ SwapTrainFlags(&a->gv_flags, &b->gv_flags);
/* update other vars */
a->UpdateViewport(true, true);
@@ -2875,8 +2875,8 @@ static byte AfterSetTrainPos(Train *v, bool new_tile)
v->z_pos = GetSlopeZ(v->x_pos, v->y_pos);
if (new_tile) {
- ClrBit(v->flags, VRF_GOINGUP);
- ClrBit(v->flags, VRF_GOINGDOWN);
+ ClrBit(v->gv_flags, GVF_GOINGUP_BIT);
+ ClrBit(v->gv_flags, GVF_GOINGDOWN_BIT);
if (v->track == TRACK_BIT_X || v->track == TRACK_BIT_Y) {
/* Any track that isn't TRACK_BIT_X or TRACK_BIT_Y cannot be sloped.
@@ -2890,7 +2890,7 @@ static byte AfterSetTrainPos(Train *v, bool new_tile)
byte middle_z = GetSlopeZ((v->x_pos & INV_TILE_SIZE_MASK) | HALF_TILE_SIZE, (v->y_pos & INV_TILE_SIZE_MASK) | HALF_TILE_SIZE);
if (middle_z != v->z_pos) {
- SetBit(v->flags, (middle_z > old_z) ? VRF_GOINGUP : VRF_GOINGDOWN);
+ SetBit(v->gv_flags, (middle_z > old_z) ? GVF_GOINGUP_BIT : GVF_GOINGDOWN_BIT);
}
}
}
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index 020b9f810..0956c7002 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -1473,8 +1473,8 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
case VEH_TRAIN: {
Train *t = Train::From(v);
t->track = TRACK_BIT_WORMHOLE;
- ClrBit(t->flags, VRF_GOINGUP);
- ClrBit(t->flags, VRF_GOINGDOWN);
+ ClrBit(t->gv_flags, GVF_GOINGUP_BIT);
+ ClrBit(t->gv_flags, GVF_GOINGDOWN_BIT);
} break;
case VEH_ROAD: