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
 
@@ -19,12 +19,28 @@
 
#include "effectvehicle_func.h"
 
#include "effectvehicle_base.h"
 

	
 
#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();
 
	v->cur_image = SPR_CHIMNEY_SMOKE_0 + GB(r, 0, 3);
 
	v->progress = GB(r, 16, 3);
 
}
 
@@ -37,15 +53,13 @@ static bool ChimneySmokeTick(EffectVehic
 
		TileIndex tile = TileVirtXY(v->x_pos, v->y_pos);
 
		if (!IsTileType(tile, MP_INDUSTRY)) {
 
			delete 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;
 
		v->UpdatePositionAndViewport();
 
	}
 

	
 
@@ -67,15 +81,13 @@ static bool SteamSmokeTick(EffectVehicle
 
	if ((v->progress & 7) == 0) {
 
		v->z_pos++;
 
		moved = true;
 
	}
 

	
 
	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;
 
		}
 
		moved = true;
 
	}
 

	
 
@@ -95,19 +107,17 @@ static bool DieselSmokeTick(EffectVehicl
 
	v->progress++;
 

	
 
	if ((v->progress & 3) == 0) {
 
		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;
 
}
 

	
 
static void ElectricSparkInit(EffectVehicle *v)
 
@@ -119,19 +129,18 @@ static void ElectricSparkInit(EffectVehi
 
static bool ElectricSparkTick(EffectVehicle *v)
 
{
 
	if (v->progress < 2) {
 
		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;
 
}
 

	
 
static void SmokeInit(EffectVehicle *v)
 
@@ -149,15 +158,13 @@ static bool SmokeTick(EffectVehicle *v)
 
	if ((v->progress & 3) == 0) {
 
		v->z_pos++;
 
		moved = true;
 
	}
 

	
 
	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;
 
		}
 
		moved = true;
 
	}
 

	
 
@@ -173,19 +180,17 @@ static void ExplosionLargeInit(EffectVeh
 
}
 

	
 
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;
 
}
 

	
 
static void BreakdownSmokeInit(EffectVehicle *v)
 
@@ -195,15 +200,13 @@ static void BreakdownSmokeInit(EffectVeh
 
}
 

	
 
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();
 
	}
 

	
 
	v->animation_state--;
 
@@ -222,19 +225,17 @@ static void ExplosionSmallInit(EffectVeh
 
}
 

	
 
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;
 
}
 

	
 
static void BulldozerInit(EffectVehicle *v)
0 comments (0 inline, 0 general)