summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2014-08-17 14:52:32 +0000
committerfrosch <frosch@openttd.org>2014-08-17 14:52:32 +0000
commitd263fcce824907fb26b4ec123065f86f878625d0 (patch)
tree3764a7fb11095fd7bd53792c7e3a82636d339143
parent7ca57bc578277acb13f28e50c25ec3fab9c07fb8 (diff)
downloadopenttd-d263fcce824907fb26b4ec123065f86f878625d0.tar.xz
(svn r26745) -Codechange: Deduplicate calls to CreateEffectVehicleRel for vehicle visual effects.
-rw-r--r--src/vehicle.cpp42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index e7c26aa50..afaa0a43b 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -2406,19 +2406,7 @@ void Vehicle::ShowVisualEffect() const
continue;
}
- /* The effect offset is relative to a point 4 units behind the vehicle's
- * front (which is the center of an 8/8 vehicle). Shorter vehicles need a
- * correction factor. */
- if (v->type == VEH_TRAIN) effect_offset += (VEHICLE_LENGTH - Train::From(v)->gcache.cached_veh_length) / 2;
-
- int x = _vehicle_smoke_pos[v->direction] * effect_offset;
- int y = _vehicle_smoke_pos[(v->direction + 2) % 8] * effect_offset;
-
- if (v->type == VEH_TRAIN && HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION)) {
- x = -x;
- y = -y;
- }
-
+ EffectVehicleType evt = EV_END;
switch (effect_type) {
case VE_TYPE_STEAM:
/* Steam smoke - amount is gradually falling until vehicle reaches its maximum speed, after that it's normal.
@@ -2427,8 +2415,7 @@ void Vehicle::ShowVisualEffect() const
* 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) {
- CreateEffectVehicleRel(v, x, y, 10, EV_STEAM_SMOKE);
- sound = true;
+ evt = EV_STEAM_SMOKE;
}
break;
@@ -2450,8 +2437,7 @@ void Vehicle::ShowVisualEffect() const
}
if (this->cur_speed < (max_speed >> (2 >> _settings_game.vehicle.smoke_amount)) &&
Chance16((64 - ((this->cur_speed << 5) / max_speed) + power_weight_effect), (512 >> _settings_game.vehicle.smoke_amount))) {
- CreateEffectVehicleRel(v, x, y, 10, EV_DIESEL_SMOKE);
- sound = true;
+ evt = EV_DIESEL_SMOKE;
}
break;
}
@@ -2465,14 +2451,32 @@ void Vehicle::ShowVisualEffect() const
* - in Chance16 the last value is 360 / 2^smoke_amount (max. sparks when 90 = smoke_amount of 2). */
if (GB(v->tick_counter, 0, 2) == 0 &&
Chance16((6 - ((this->cur_speed << 2) / max_speed)), (360 >> _settings_game.vehicle.smoke_amount))) {
- CreateEffectVehicleRel(v, x, y, 10, EV_ELECTRIC_SPARK);
- sound = true;
+ evt = EV_ELECTRIC_SPARK;
}
break;
default:
break;
}
+
+ if (evt != EV_END) {
+ sound = true;
+
+ /* The effect offset is relative to a point 4 units behind the vehicle's
+ * front (which is the center of an 8/8 vehicle). Shorter vehicles need a
+ * correction factor. */
+ if (v->type == VEH_TRAIN) effect_offset += (VEHICLE_LENGTH - Train::From(v)->gcache.cached_veh_length) / 2;
+
+ int x = _vehicle_smoke_pos[v->direction] * effect_offset;
+ int y = _vehicle_smoke_pos[(v->direction + 2) % 8] * effect_offset;
+
+ if (v->type == VEH_TRAIN && HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION)) {
+ x = -x;
+ y = -y;
+ }
+
+ CreateEffectVehicleRel(v, x, y, 10, evt);
+ }
} while ((v = v->Next()) != NULL);
if (sound) PlayVehicleSound(this, VSE_VISUAL_EFFECT);