mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 07:29:44 +00:00
(svn r27664) -Codechange: Deduplicate code for animating effect vehicles.
This commit is contained in:
parent
a6d1d128da
commit
7c4e5242ba
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user