Changeset - r22457:dce2da0dd85d
[Not reviewed]
master
0 1 0
frosch - 8 years ago 2016-10-16 14:56:52
frosch@openttd.org
(svn r27664) -Codechange: Deduplicate code for animating effect vehicles.
1 file changed with 29 insertions and 28 deletions:
0 comments (0 inline, 0 general)
src/effectvehicle.cpp
Show inline comments
 
@@ -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(EffectVehic
 
			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
 
	}
 

	
 
	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(EffectVehicl
 
		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(EffectVehi
 
		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(EffectVeh
 
{
 
	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(EffectVeh
 
{
 
	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(EffectVeh
 
{
 
	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;
0 comments (0 inline, 0 general)