Changeset - r21614:2d28327333d9
[Not reviewed]
master
0 2 0
frosch - 10 years ago 2014-08-17 14:52:48
frosch@openttd.org
(svn r26746) -Codechange: Separate enums for visual effect type and spawning model.
2 files changed with 25 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/vehicle.cpp
Show inline comments
 
@@ -2383,46 +2383,53 @@ void Vehicle::ShowVisualEffect() const
 
	if (this->type == VEH_ROAD || this->type == VEH_SHIP) max_speed = min(max_speed, this->current_order.GetMaxSpeed() * 2);
 

	
 
	const Vehicle *v = this;
 

	
 
	do {
 
		int effect_offset = GB(v->vcache.cached_vis_effect, VE_OFFSET_START, VE_OFFSET_COUNT) - VE_OFFSET_CENTRE;
 
		byte effect_type = GB(v->vcache.cached_vis_effect, VE_TYPE_START, VE_TYPE_COUNT);
 
		bool disable_effect = HasBit(v->vcache.cached_vis_effect, VE_DISABLE_EFFECT);
 
		VisualEffectSpawnModel effect_model = VESM_NONE;
 

	
 
		if (!HasBit(v->vcache.cached_vis_effect, VE_DISABLE_EFFECT)) {
 
			effect_model = (VisualEffectSpawnModel)GB(v->vcache.cached_vis_effect, VE_TYPE_START, VE_TYPE_COUNT);
 
			assert(effect_model != (VisualEffectSpawnModel)VE_TYPE_DEFAULT); // should have been resolved by UpdateVisualEffect
 
			assert_compile((uint)VESM_STEAM    == (uint)VE_TYPE_STEAM);
 
			assert_compile((uint)VESM_DIESEL   == (uint)VE_TYPE_DIESEL);
 
			assert_compile((uint)VESM_ELECTRIC == (uint)VE_TYPE_ELECTRIC);
 
		}
 

	
 
		/* Show no smoke when:
 
		 * - Smoke has been disabled for this vehicle
 
		 * - The vehicle is not visible
 
		 * - The vehicle is under a bridge
 
		 * - The vehicle is on a depot tile
 
		 * - The vehicle is on a tunnel tile
 
		 * - The vehicle is a train engine that is currently unpowered */
 
		if (disable_effect ||
 
		if (effect_model == VESM_NONE ||
 
				v->vehstatus & VS_HIDDEN ||
 
				(MayHaveBridgeAbove(v->tile) && IsBridgeAbove(v->tile)) ||
 
				IsDepotTile(v->tile) ||
 
				IsTunnelTile(v->tile) ||
 
				(v->type == VEH_TRAIN &&
 
				!HasPowerOnRail(Train::From(v)->railtype, GetTileRailType(v->tile)))) {
 
			continue;
 
		}
 

	
 
		EffectVehicleType evt = EV_END;
 
		switch (effect_type) {
 
			case VE_TYPE_STEAM:
 
		switch (effect_model) {
 
			case VESM_STEAM:
 
				/* Steam smoke - amount is gradually falling until vehicle reaches its maximum speed, after that it's normal.
 
				 * Details: while vehicle's current speed is gradually increasing, steam plumes' density decreases by one third each
 
				 * third of its maximum speed spectrum. Steam emission finally normalises at very close to vehicle's maximum speed.
 
				 * REGULATION:
 
				 * - instead of 1, 4 / 2^smoke_amount (max. 2) is used to provide sufficient regulation to steam puffs' amount. */
 
				if (GB(v->tick_counter, 0, ((4 >> _settings_game.vehicle.smoke_amount) + ((this->cur_speed * 3) / max_speed))) == 0) {
 
					evt = EV_STEAM_SMOKE;
 
				}
 
				break;
 

	
 
			case VE_TYPE_DIESEL: {
 
			case VESM_DIESEL: {
 
				/* Diesel smoke - thicker when vehicle is starting, gradually subsiding till it reaches its maximum speed
 
				 * when smoke emission stops.
 
				 * Details: Vehicle's (max.) speed spectrum is divided into 32 parts. When max. speed is reached, chance for smoke
 
				 * emission erodes by 32 (1/4). For trains, power and weight come in handy too to either increase smoke emission in
 
				 * 6 steps (1000HP each) if the power is low or decrease smoke emission in 6 steps (512 tonnes each) if the train
 
				 * isn't overweight. Power and weight contributions are expressed in a way that neither extreme power, nor
 
@@ -2439,13 +2446,13 @@ void Vehicle::ShowVisualEffect() const
 
						Chance16((64 - ((this->cur_speed << 5) / max_speed) + power_weight_effect), (512 >> _settings_game.vehicle.smoke_amount))) {
 
					evt = EV_DIESEL_SMOKE;
 
				}
 
				break;
 
			}
 

	
 
			case VE_TYPE_ELECTRIC:
 
			case VESM_ELECTRIC:
 
				/* Electric train's spark - more often occurs when train is departing (more load)
 
				 * Details: Electric locomotives are usually at least twice as powerful as their diesel counterparts, so spark
 
				 * emissions are kept simple. Only when starting, creating huge force are sparks more likely to happen, but when
 
				 * reaching its max. speed, quarter by quarter of it, chance decreases until the usual 2,22% at train's top speed.
 
				 * REGULATION:
 
				 * - in Chance16 the last value is 360 / 2^smoke_amount (max. sparks when 90 = smoke_amount of 2). */
 
@@ -2453,13 +2460,13 @@ void Vehicle::ShowVisualEffect() const
 
						Chance16((6 - ((this->cur_speed << 2) / max_speed)), (360 >> _settings_game.vehicle.smoke_amount))) {
 
					evt = EV_ELECTRIC_SPARK;
 
				}
 
				break;
 

	
 
			default:
 
				break;
 
				NOT_REACHED();
 
		}
 

	
 
		if (evt != EV_END) {
 
			sound = true;
 

	
 
			/* The effect offset is relative to a point 4 units behind the vehicle's
src/vehicle_base.h
Show inline comments
 
@@ -89,12 +89,22 @@ enum VisualEffect {
 
	VE_DISABLE_EFFECT      = 6, ///< Flag to disable visual effect
 
	VE_DISABLE_WAGON_POWER = 7, ///< Flag to disable wagon power
 

	
 
	VE_DEFAULT = 0xFF,          ///< Default value to indicate that visual effect should be based on engine class
 
};
 

	
 
/** Models for spawning visual effects. */
 
enum VisualEffectSpawnModel {
 
	VESM_NONE              = 0, ///< No visual effect
 
	VESM_STEAM,                 ///< Steam model
 
	VESM_DIESEL,                ///< Diesel model
 
	VESM_ELECTRIC,              ///< Electric model
 

	
 
	VESM_END
 
};
 

	
 
/**
 
 * Enum to handle ground vehicle subtypes.
 
 * This is defined here instead of at #GroundVehicle because some common function require access to these flags.
 
 * Do not access it directly unless you have to. Use the subtype access functions.
 
 */
 
enum GroundVehicleSubtypeFlags {
0 comments (0 inline, 0 general)