summaryrefslogtreecommitdiff
path: root/src/effectvehicle.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2016-10-16 14:56:52 +0000
committerfrosch <frosch@openttd.org>2016-10-16 14:56:52 +0000
commit7c4e5242ba77635c6e4aee4075d7e9a6c02ac09c (patch)
treeaa546ab80725f29c5be8d4bef82b266bedde6a30 /src/effectvehicle.cpp
parenta6d1d128dae5a8a329def0b1c4d3c257267a928b (diff)
downloadopenttd-7c4e5242ba77635c6e4aee4075d7e9a6c02ac09c.tar.xz
(svn r27664) -Codechange: Deduplicate code for animating effect vehicles.
Diffstat (limited to 'src/effectvehicle.cpp')
-rw-r--r--src/effectvehicle.cpp57
1 files changed, 29 insertions, 28 deletions
diff --git a/src/effectvehicle.cpp b/src/effectvehicle.cpp
index 209b78d2e..c871ac09a 100644
--- a/src/effectvehicle.cpp
+++ b/src/effectvehicle.cpp
@@ -22,6 +22,22 @@
#include "safeguards.h"
+/**
+ * Increment the sprite unless it has reached the end of the animation.
+ * @param v Vehicle to increment sprite of.
+ * @param last Last sprite of animation.
+ * @return true if the sprite was incremented, false if the end was reached.
+ */
+static bool IncrementSprite(EffectVehicle *v, SpriteID last)
+{
+ if (v->cur_image != last) {
+ v->cur_image++;
+ return true;
+ } else {
+ return false;
+ }
+}
+
static void ChimneySmokeInit(EffectVehicle *v)
{
uint32 r = Random();
@@ -40,9 +56,7 @@ static bool ChimneySmokeTick(EffectVehicle *v)
return false;
}
- if (v->cur_image != SPR_CHIMNEY_SMOKE_7) {
- v->cur_image++;
- } else {
+ if (!IncrementSprite(v, SPR_CHIMNEY_SMOKE_7)) {
v->cur_image = SPR_CHIMNEY_SMOKE_0;
}
v->progress = 7;
@@ -70,9 +84,7 @@ static bool SteamSmokeTick(EffectVehicle *v)
}
if ((v->progress & 0xF) == 4) {
- if (v->cur_image != SPR_STEAM_SMOKE_4) {
- v->cur_image++;
- } else {
+ if (!IncrementSprite(v, SPR_STEAM_SMOKE_4)) {
delete v;
return false;
}
@@ -98,13 +110,11 @@ static bool DieselSmokeTick(EffectVehicle *v)
v->z_pos++;
v->UpdatePositionAndViewport();
} else if ((v->progress & 7) == 1) {
- if (v->cur_image != SPR_DIESEL_SMOKE_5) {
- v->cur_image++;
- v->UpdatePositionAndViewport();
- } else {
+ if (!IncrementSprite(v, SPR_DIESEL_SMOKE_5)) {
delete v;
return false;
}
+ v->UpdatePositionAndViewport();
}
return true;
@@ -122,13 +132,12 @@ static bool ElectricSparkTick(EffectVehicle *v)
v->progress++;
} else {
v->progress = 0;
- if (v->cur_image != SPR_ELECTRIC_SPARK_5) {
- v->cur_image++;
- v->UpdatePositionAndViewport();
- } else {
+
+ if (!IncrementSprite(v, SPR_ELECTRIC_SPARK_5)) {
delete v;
return false;
}
+ v->UpdatePositionAndViewport();
}
return true;
@@ -152,9 +161,7 @@ static bool SmokeTick(EffectVehicle *v)
}
if ((v->progress & 0xF) == 4) {
- if (v->cur_image != SPR_SMOKE_4) {
- v->cur_image++;
- } else {
+ if (!IncrementSprite(v, SPR_SMOKE_4)) {
delete v;
return false;
}
@@ -176,13 +183,11 @@ static bool ExplosionLargeTick(EffectVehicle *v)
{
v->progress++;
if ((v->progress & 3) == 0) {
- if (v->cur_image != SPR_EXPLOSION_LARGE_F) {
- v->cur_image++;
- v->UpdatePositionAndViewport();
- } else {
+ if (!IncrementSprite(v, SPR_EXPLOSION_LARGE_F)) {
delete v;
return false;
}
+ v->UpdatePositionAndViewport();
}
return true;
@@ -198,9 +203,7 @@ static bool BreakdownSmokeTick(EffectVehicle *v)
{
v->progress++;
if ((v->progress & 7) == 0) {
- if (v->cur_image != SPR_BREAKDOWN_SMOKE_3) {
- v->cur_image++;
- } else {
+ if (!IncrementSprite(v, SPR_BREAKDOWN_SMOKE_3)) {
v->cur_image = SPR_BREAKDOWN_SMOKE_0;
}
v->UpdatePositionAndViewport();
@@ -225,13 +228,11 @@ static bool ExplosionSmallTick(EffectVehicle *v)
{
v->progress++;
if ((v->progress & 3) == 0) {
- if (v->cur_image != SPR_EXPLOSION_SMALL_B) {
- v->cur_image++;
- v->UpdatePositionAndViewport();
- } else {
+ if (!IncrementSprite(v, SPR_EXPLOSION_SMALL_B)) {
delete v;
return false;
}
+ v->UpdatePositionAndViewport();
}
return true;