Changeset - r18024:9fef0937e079
[Not reviewed]
master
0 2 0
frosch - 13 years ago 2011-08-27 10:33:45
frosch@openttd.org
(svn r22849) -Codechange: Add ShipVehicleInfo::ApplyWaterClassSpeedFrac() to apply ocean/canal speed fractions to velocities.
2 files changed with 10 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/engine_type.h
Show inline comments
 
@@ -74,6 +74,13 @@ struct ShipVehicleInfo {
 
	byte visual_effect;    ///< Bitstuffed NewGRF visual effect data
 
	byte ocean_speed_frac; ///< Fraction of maximum speed for ocean tiles.
 
	byte canal_speed_frac; ///< Fraction of maximum speed for canal/river tiles.
 

	
 
	/** Apply ocean/canal speed fraction to a velocity */
 
	uint ApplyWaterClassSpeedFrac(uint raw_speed, bool is_ocean) const
 
	{
 
		/* speed_frac == 0 means no reduction while 0xFF means reduction to 1/256. */
 
		return raw_speed * (256 - (is_ocean ? this->ocean_speed_frac : this->canal_speed_frac)) / 256;
 
	}
 
};
 

	
 
/**
src/ship_cmd.cpp
Show inline comments
 
@@ -178,9 +178,9 @@ void Ship::UpdateCache()
 
	const ShipVehicleInfo *svi = ShipVehInfo(this->engine_type);
 

	
 
	/* Get speed fraction for the current water type. Aqueducts are always canals. */
 
	byte speed_frac = (GetEffectiveWaterClass(this->tile) == WATER_CLASS_SEA) ? svi->ocean_speed_frac : svi->canal_speed_frac;
 
	/* speed_frac == 0 means no reduction while 0xFF means reduction to 1/256. */
 
	this->vcache.cached_max_speed = GetVehicleProperty(this, PROP_SHIP_SPEED, svi->max_speed) * (256 - speed_frac) / 256;
 
	bool is_ocean = GetEffectiveWaterClass(this->tile) == WATER_CLASS_SEA;
 
	uint raw_speed = GetVehicleProperty(this, PROP_SHIP_SPEED, svi->max_speed);
 
	this->vcache.cached_max_speed = svi->ApplyWaterClassSpeedFrac(raw_speed, is_ocean);
 

	
 
	/* Update cargo aging period. */
 
	this->vcache.cached_cargo_age_period = GetVehicleProperty(this, PROP_SHIP_CARGO_AGE_PERIOD, EngInfo(this->engine_type)->cargo_age_period);
0 comments (0 inline, 0 general)