changeset 11978:2e291154df46 draft

(svn r16384) -Codechange: move u.effect to EffectVehicle
author rubidium <rubidium@openttd.org>
date Fri, 22 May 2009 18:56:25 +0000
parents 5a2c559ba843
children 6c50c7cd27fb
files src/effectvehicle.cpp src/effectvehicle_base.h src/effectvehicle_func.h src/industry_cmd.cpp src/roadveh_cmd.cpp src/saveload/oldloader_sl.cpp src/saveload/vehicle_sl.cpp src/ship_cmd.cpp src/train_cmd.cpp src/vehicle_base.h
diffstat 10 files changed, 60 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/src/effectvehicle.cpp
+++ b/src/effectvehicle.cpp
@@ -13,14 +13,14 @@
 
 #include "table/sprites.h"
 
-static void ChimneySmokeInit(Vehicle *v)
+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);
 }
 
-static bool ChimneySmokeTick(Vehicle *v)
+static bool ChimneySmokeTick(EffectVehicle *v)
 {
 	if (v->progress > 0) {
 		v->progress--;
@@ -43,13 +43,13 @@
 	return true;
 }
 
-static void SteamSmokeInit(Vehicle *v)
+static void SteamSmokeInit(EffectVehicle *v)
 {
 	v->cur_image = SPR_STEAM_SMOKE_0;
 	v->progress = 12;
 }
 
-static bool SteamSmokeTick(Vehicle *v)
+static bool SteamSmokeTick(EffectVehicle *v)
 {
 	bool moved = false;
 
@@ -75,13 +75,13 @@
 	return true;
 }
 
-static void DieselSmokeInit(Vehicle *v)
+static void DieselSmokeInit(EffectVehicle *v)
 {
 	v->cur_image = SPR_DIESEL_SMOKE_0;
 	v->progress = 0;
 }
 
-static bool DieselSmokeTick(Vehicle *v)
+static bool DieselSmokeTick(EffectVehicle *v)
 {
 	v->progress++;
 
@@ -101,13 +101,13 @@
 	return true;
 }
 
-static void ElectricSparkInit(Vehicle *v)
+static void ElectricSparkInit(EffectVehicle *v)
 {
 	v->cur_image = SPR_ELECTRIC_SPARK_0;
 	v->progress = 1;
 }
 
-static bool ElectricSparkTick(Vehicle *v)
+static bool ElectricSparkTick(EffectVehicle *v)
 {
 	if (v->progress < 2) {
 		v->progress++;
@@ -125,13 +125,13 @@
 	return true;
 }
 
-static void SmokeInit(Vehicle *v)
+static void SmokeInit(EffectVehicle *v)
 {
 	v->cur_image = SPR_SMOKE_0;
 	v->progress = 12;
 }
 
-static bool SmokeTick(Vehicle *v)
+static bool SmokeTick(EffectVehicle *v)
 {
 	bool moved = false;
 
@@ -157,13 +157,13 @@
 	return true;
 }
 
-static void ExplosionLargeInit(Vehicle *v)
+static void ExplosionLargeInit(EffectVehicle *v)
 {
 	v->cur_image = SPR_EXPLOSION_LARGE_0;
 	v->progress = 0;
 }
 
-static bool ExplosionLargeTick(Vehicle *v)
+static bool ExplosionLargeTick(EffectVehicle *v)
 {
 	v->progress++;
 	if ((v->progress & 3) == 0) {
@@ -179,13 +179,13 @@
 	return true;
 }
 
-static void BreakdownSmokeInit(Vehicle *v)
+static void BreakdownSmokeInit(EffectVehicle *v)
 {
 	v->cur_image = SPR_BREAKDOWN_SMOKE_0;
 	v->progress = 0;
 }
 
-static bool BreakdownSmokeTick(Vehicle *v)
+static bool BreakdownSmokeTick(EffectVehicle *v)
 {
 	v->progress++;
 	if ((v->progress & 7) == 0) {
@@ -197,8 +197,8 @@
 		VehicleMove(v, true);
 	}
 
-	v->u.effect.animation_state--;
-	if (v->u.effect.animation_state == 0) {
+	v->animation_state--;
+	if (v->animation_state == 0) {
 		delete v;
 		return false;
 	}
@@ -206,13 +206,13 @@
 	return true;
 }
 
-static void ExplosionSmallInit(Vehicle *v)
+static void ExplosionSmallInit(EffectVehicle *v)
 {
 	v->cur_image = SPR_EXPLOSION_SMALL_0;
 	v->progress = 0;
 }
 
-static bool ExplosionSmallTick(Vehicle *v)
+static bool ExplosionSmallTick(EffectVehicle *v)
 {
 	v->progress++;
 	if ((v->progress & 3) == 0) {
@@ -228,12 +228,12 @@
 	return true;
 }
 
-static void BulldozerInit(Vehicle *v)
+static void BulldozerInit(EffectVehicle *v)
 {
 	v->cur_image = SPR_BULLDOZER_NE;
 	v->progress = 0;
-	v->u.effect.animation_state = 0;
-	v->u.effect.animation_substate = 0;
+	v->animation_state = 0;
+	v->animation_substate = 0;
 }
 
 struct BulldozerMovement {
@@ -275,22 +275,22 @@
 	{  0, -1 }
 };
 
-static bool BulldozerTick(Vehicle *v)
+static bool BulldozerTick(EffectVehicle *v)
 {
 	v->progress++;
 	if ((v->progress & 7) == 0) {
-		const BulldozerMovement *b = &_bulldozer_movement[v->u.effect.animation_state];
+		const BulldozerMovement *b = &_bulldozer_movement[v->animation_state];
 
 		v->cur_image = SPR_BULLDOZER_NE + b->image;
 
 		v->x_pos += _inc_by_dir[b->direction].x;
 		v->y_pos += _inc_by_dir[b->direction].y;
 
-		v->u.effect.animation_substate++;
-		if (v->u.effect.animation_substate >= b->duration) {
-			v->u.effect.animation_substate = 0;
-			v->u.effect.animation_state++;
-			if (v->u.effect.animation_state == lengthof(_bulldozer_movement)) {
+		v->animation_substate++;
+		if (v->animation_substate >= b->duration) {
+			v->animation_substate = 0;
+			v->animation_state++;
+			if (v->animation_state == lengthof(_bulldozer_movement)) {
 				delete v;
 				return false;
 			}
@@ -301,7 +301,7 @@
 	return true;
 }
 
-static void BubbleInit(Vehicle *v)
+static void BubbleInit(EffectVehicle *v)
 {
 	v->cur_image = SPR_BUBBLE_GENERATE_0;
 	v->spritenum = 0;
@@ -458,7 +458,7 @@
 	_bubble_absorb,
 };
 
-static bool BubbleTick(Vehicle *v)
+static bool BubbleTick(EffectVehicle *v)
 {
 	uint anim_state;
 
@@ -471,14 +471,14 @@
 			VehicleMove(v, true);
 			return true;
 		}
-		if (v->u.effect.animation_substate != 0) {
+		if (v->animation_substate != 0) {
 			v->spritenum = GB(Random(), 0, 2) + 1;
 		} else {
 			v->spritenum = 6;
 		}
 		anim_state = 0;
 	} else {
-		anim_state = v->u.effect.animation_state + 1;
+		anim_state = v->animation_state + 1;
 	}
 
 	const BubbleMovement *b = &_bubble_movement[v->spritenum - 1][anim_state];
@@ -506,7 +506,7 @@
 		if (IsTileType(tile, MP_INDUSTRY) && GetIndustryGfx(tile) == GFX_BUBBLE_CATCHER) AddAnimatedTile(tile);
 	}
 
-	v->u.effect.animation_state = anim_state;
+	v->animation_state = anim_state;
 	b = &_bubble_movement[v->spritenum - 1][anim_state];
 
 	v->x_pos += b->x;
@@ -520,8 +520,8 @@
 }
 
 
-typedef void EffectInitProc(Vehicle *v);
-typedef bool EffectTickProc(Vehicle *v);
+typedef void EffectInitProc(EffectVehicle *v);
+typedef bool EffectTickProc(EffectVehicle *v);
 
 static EffectInitProc * const _effect_init_procs[] = {
 	ChimneySmokeInit,
@@ -550,11 +550,11 @@
 };
 
 
-Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicleType type)
+EffectVehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicleType type)
 {
 	if (!Vehicle::CanAllocateItem()) return NULL;
 
-	Vehicle *v = new EffectVehicle();
+	EffectVehicle *v = new EffectVehicle();
 	v->subtype = type;
 	v->x_pos = x;
 	v->y_pos = y;
@@ -571,14 +571,14 @@
 	return v;
 }
 
-Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicleType type)
+EffectVehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicleType type)
 {
 	int safe_x = Clamp(x, 0, MapMaxX() * TILE_SIZE);
 	int safe_y = Clamp(y, 0, MapMaxY() * TILE_SIZE);
 	return CreateEffectVehicle(x, y, GetSlopeZ(safe_x, safe_y) + z, type);
 }
 
-Vehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicleType type)
+EffectVehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicleType type)
 {
 	return CreateEffectVehicle(v->x_pos + x, v->y_pos + y, v->z_pos + z, type);
 }
--- a/src/effectvehicle_base.h
+++ b/src/effectvehicle_base.h
@@ -23,6 +23,9 @@
  *  - bubbles (industry)
  */
 struct EffectVehicle : public Vehicle {
+	uint16 animation_state;
+	byte animation_substate;
+
 	/** Initializes the Vehicle to a special vehicle */
 	EffectVehicle() { this->type = VEH_EFFECT; }
 
--- a/src/effectvehicle_func.h
+++ b/src/effectvehicle_func.h
@@ -5,7 +5,7 @@
 #ifndef EFFECTVEHICLE_FUNC_H
 #define EFFECTVEHICLE_FUNC_H
 
-#include "vehicle_type.h"
+#include "effectvehicle_base.h"
 
 /** Effect vehicle types */
 enum EffectVehicleType {
@@ -21,8 +21,8 @@
 	EV_BUBBLE          = 9
 };
 
-Vehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicleType type);
-Vehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicleType type);
-Vehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicleType type);
+EffectVehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicleType type);
+EffectVehicle *CreateEffectVehicleAbove(int x, int y, int z, EffectVehicleType type);
+EffectVehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicleType type);
 
 #endif /* EFFECTVEHICLE_FUNC_H */
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -702,8 +702,6 @@
 
 static void TileLoopIndustry_BubbleGenerator(TileIndex tile)
 {
-	int dir;
-	Vehicle *v;
 	static const int8 _bubble_spawn_location[3][4] = {
 		{ 11,   0, -4, -14 },
 		{ -4, -10, -4,   1 },
@@ -712,16 +710,16 @@
 
 	SndPlayTileFx(SND_2E_EXTRACT_AND_POP, tile);
 
-	dir = Random() & 3;
+	int dir = Random() & 3;
 
-	v = CreateEffectVehicleAbove(
+	EffectVehicle *v = CreateEffectVehicleAbove(
 		TileX(tile) * TILE_SIZE + _bubble_spawn_location[0][dir],
 		TileY(tile) * TILE_SIZE + _bubble_spawn_location[1][dir],
 		_bubble_spawn_location[2][dir],
 		EV_BUBBLE
 	);
 
-	if (v != NULL) v->u.effect.animation_substate = dir;
+	if (v != NULL) v->animation_substate = dir;
 }
 
 static void TileLoop_Industry(TileIndex tile)
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -637,8 +637,8 @@
 		}
 
 		if (!(v->vehstatus & VS_HIDDEN)) {
-			Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE);
-			if (u != NULL) u->u.effect.animation_state = v->breakdown_delay * 2;
+			EffectVehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE);
+			if (u != NULL) u->animation_state = v->breakdown_delay * 2;
 		}
 	}
 
--- a/src/saveload/oldloader_sl.cpp
+++ b/src/saveload/oldloader_sl.cpp
@@ -1122,8 +1122,8 @@
 };
 
 static const OldChunks vehicle_effect_chunk[] = {
-	OCL_SVAR( OC_UINT16, VehicleEffect, animation_state ),
-	OCL_SVAR(  OC_UINT8, VehicleEffect, animation_substate ),
+	OCL_SVAR( OC_UINT16, EffectVehicle, animation_state ),
+	OCL_SVAR(  OC_UINT8, EffectVehicle, animation_substate ),
 
 	OCL_NULL( 7 ), // Junk
 
@@ -1160,7 +1160,7 @@
 			case VEH_ROAD    : res = LoadChunk(ls, &v->u.road,     vehicle_road_chunk);     break;
 			case VEH_SHIP    : res = LoadChunk(ls, v, vehicle_ship_chunk);     break;
 			case VEH_AIRCRAFT: res = LoadChunk(ls, &v->u.air,      vehicle_air_chunk);      break;
-			case VEH_EFFECT  : res = LoadChunk(ls, &v->u.effect,   vehicle_effect_chunk);   break;
+			case VEH_EFFECT  : res = LoadChunk(ls, v, vehicle_effect_chunk);   break;
 			case VEH_DISASTER: res = LoadChunk(ls, &v->u.disaster, vehicle_disaster_chunk); break;
 		}
 	}
--- a/src/saveload/vehicle_sl.cpp
+++ b/src/saveload/vehicle_sl.cpp
@@ -606,8 +606,8 @@
 		     SLE_VAR(Vehicle, progress,              SLE_UINT8),
 		     SLE_VAR(Vehicle, vehstatus,             SLE_UINT8),
 
-		    SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleEffect, animation_state),    SLE_UINT16),
-		    SLE_VARX(cpp_offsetof(Vehicle, u) + cpp_offsetof(VehicleEffect, animation_substate), SLE_UINT8),
+		     SLE_VAR(EffectVehicle, animation_state,    SLE_UINT16),
+		     SLE_VAR(EffectVehicle, animation_substate, SLE_UINT8),
 
 		 SLE_CONDVAR(Vehicle, spritenum,             SLE_UINT8,                    2, SL_MAX_VERSION),
 
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -213,8 +213,8 @@
 		}
 
 		if (!(v->vehstatus & VS_HIDDEN)) {
-			Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE);
-			if (u != NULL) u->u.effect.animation_state = v->breakdown_delay * 2;
+			EffectVehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE);
+			if (u != NULL) u->animation_state = v->breakdown_delay * 2;
 		}
 	}
 
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -4079,8 +4079,8 @@
 		}
 
 		if (!(v->vehstatus & VS_HIDDEN)) {
-			Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE);
-			if (u != NULL) u->u.effect.animation_state = v->breakdown_delay * 2;
+			EffectVehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE);
+			if (u != NULL) u->animation_state = v->breakdown_delay * 2;
 		}
 	}
 
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -175,11 +175,6 @@
 	RoadTypes compatible_roadtypes;
 };
 
-struct VehicleEffect {
-	uint16 animation_state;
-	byte animation_substate;
-};
-
 struct VehicleDisaster {
 	uint16 image_override;
 	VehicleID big_ufo_destroyer_target;
@@ -316,7 +311,6 @@
 		VehicleRail rail;
 		VehicleAir air;
 		VehicleRoad road;
-		VehicleEffect effect;
 		VehicleDisaster disaster;
 	} u;