Changeset - r14743:6ee8646cf93f
[Not reviewed]
master
0 7 0
terkhen - 15 years ago 2010-03-06 12:50:55
terkhen@openttd.org
(svn r19341) -Codechange: Move GOINGUP/GOINGDOWN flags to GroundVehicle.
-Codechange: Move GetSlopeResistance to GroundVehicle.
7 files changed with 60 insertions and 44 deletions:
0 comments (0 inline, 0 general)
src/ground_vehicle.cpp
Show inline comments
 
@@ -116,7 +116,7 @@ int GroundVehicle<T, Type>::GetAccelerat
 
		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. */
src/ground_vehicle.hpp
Show inline comments
 
@@ -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 Specialize
 
	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 */
src/saveload/afterload.cpp
Show inline comments
 
@@ -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 */
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -544,6 +544,7 @@ const SaveLoad *GetVehicleDescription(Ve
 
		 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),
 

	
src/train.h
Show inline comments
 
@@ -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
 
	}
 

	
 
	/**
 
	 * 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.
 
	 */
src/train_cmd.cpp
Show inline comments
 
@@ -1477,22 +1477,22 @@ static void SwapTrainFlags(uint16 *swap_
 
	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
 
		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, b
 
	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, b
 
			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);
 
			}
 
		}
 
	}
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -1473,8 +1473,8 @@ static VehicleEnterTileStatus VehicleEnt
 
				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:
0 comments (0 inline, 0 general)