mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
-Codechange: Move GetSlopeResistance to GroundVehicle.
This commit is contained in:
parent
1c3b7c35a7
commit
4e6cac84d6
@ -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. */
|
||||
|
@ -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 */
|
||||
|
@ -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 */
|
||||
|
@ -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),
|
||||
|
||||
|
23
src/train.h
23
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,
|
||||
|
||||
@ -452,25 +448,6 @@ protected: // These functions should not be called outside acceleration code.
|
||||
return 35;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user