(svn r1868) Improve readability of the bulldozer movement code

This commit is contained in:
tron 2005-02-13 11:27:41 +00:00
parent 204d08140a
commit 9f7074a706
2 changed files with 55 additions and 44 deletions

View File

@ -727,6 +727,12 @@ enum Sprites {
SPR_TYCOON_IMG1_BEGIN = 4814, SPR_TYCOON_IMG1_BEGIN = 4814,
SPR_TYCOON_IMG2_BEGIN = 4824, SPR_TYCOON_IMG2_BEGIN = 4824,
/* Effect vehciles */
SPR_BULLDOZER_NE = 1416,
SPR_BULLDOZER_SE = 1417,
SPR_BULLDOZER_SW = 1418,
SPR_BULLDOZER_NW = 1419,
/* road_gui.c */ /* road_gui.c */
SPR_IMG_ROAD_NW = 1309, SPR_IMG_ROAD_NW = 1309,
SPR_IMG_ROAD_NE = 1310, SPR_IMG_ROAD_NE = 1310,

View File

@ -1,6 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "ttd.h" #include "ttd.h"
#include "spritecache.h" #include "spritecache.h"
#include "table/sprites.h"
#include "table/strings.h" #include "table/strings.h"
#include "map.h" #include "map.h"
#include "tile.h" #include "tile.h"
@ -778,66 +779,70 @@ static void EffectTick_7(Vehicle *v)
} }
} }
static void EffectInit_8(Vehicle *v) static void BulldozerInit(Vehicle *v)
{ {
v->cur_image = 1416; v->cur_image = SPR_BULLDOZER_NE;
v->progress = 0; v->progress = 0;
v->u.special.unk0 = 0; v->u.special.unk0 = 0;
v->u.special.unk2 = 0; v->u.special.unk2 = 0;
} }
#define MK(imag,dir,dur) (imag<<6)+(dir<<4)+dur typedef struct BulldozerMovement {
static const byte _effecttick8_data[] = { byte image:2;
MK(0,0,4), byte direction:2;
MK(3,3,4), byte duration:3;
MK(2,2,7), } BulldozerMovement;
MK(0,2,7),
MK(1,1,3),
MK(2,2,7),
MK(0,2,7),
MK(1,1,3),
MK(2,2,7),
MK(0,2,7),
MK(3,3,6),
MK(2,2,6),
MK(1,1,7),
MK(3,1,7),
MK(0,0,3),
MK(1,1,7),
MK(3,1,7),
MK(0,0,3),
MK(1,1,7),
MK(3,1,7),
255
};
#undef MK
static const int8 _xy_inc_by_dir[5] = { static const BulldozerMovement _bulldozer_movement[] = {
-1, 0, 1, 0, -1, { 0, 0, 4 },
{ 3, 3, 4 },
{ 2, 2, 7 },
{ 0, 2, 7 },
{ 1, 1, 3 },
{ 2, 2, 7 },
{ 0, 2, 7 },
{ 1, 1, 3 },
{ 2, 2, 7 },
{ 0, 2, 7 },
{ 3, 3, 6 },
{ 2, 2, 6 },
{ 1, 1, 7 },
{ 3, 1, 7 },
{ 0, 0, 3 },
{ 1, 1, 7 },
{ 3, 1, 7 },
{ 0, 0, 3 },
{ 1, 1, 7 },
{ 3, 1, 7 }
}; };
#define GET_X_INC_BY_DIR(d) _xy_inc_by_dir[d] static const struct {
#define GET_Y_INC_BY_DIR(d) _xy_inc_by_dir[(d)+1] int8 x;
int8 y;
} _inc_by_dir[] = {
{ -1, 0 },
{ 0, 1 },
{ 1, 0 },
{ 0, -1 }
};
static void EffectTick_8(Vehicle *v) static void BulldozerTick(Vehicle *v)
{ {
byte b; if ((++v->progress & 7) == 0) {
const BulldozerMovement* b = &_bulldozer_movement[v->u.special.unk0];
if (!(++v->progress & 7)) {
v->u.special.unk2++;
BeginVehicleMove(v); BeginVehicleMove(v);
b = _effecttick8_data[v->u.special.unk0]; v->cur_image = SPR_BULLDOZER_NE + b->image;
v->cur_image = 0x588 + (b>>6); v->x_pos += _inc_by_dir[b->direction].x;
v->y_pos += _inc_by_dir[b->direction].y;
v->x_pos += GET_X_INC_BY_DIR((b>>4)&3); v->u.special.unk2++;
v->y_pos += GET_X_INC_BY_DIR((b>>4)&3); if (v->u.special.unk2 < b->duration) {
if (v->u.special.unk2 < (b & 7)) {
v->u.special.unk2 = 0; v->u.special.unk2 = 0;
v->u.special.unk0++; v->u.special.unk0++;
if (_effecttick8_data[v->u.special.unk0] == 0xFF) { if (v->u.special.unk0 == lengthof(_bulldozer_movement)) {
EndVehicleMove(v); EndVehicleMove(v);
DeleteVehicle(v); DeleteVehicle(v);
return; return;
@ -1086,7 +1091,7 @@ static EffectInitProc * const _effect_init_procs[] = {
EffectInit_5, EffectInit_5,
EffectInit_6, EffectInit_6,
EffectInit_7, EffectInit_7,
EffectInit_8, BulldozerInit,
EffectInit_9, EffectInit_9,
}; };
@ -1099,7 +1104,7 @@ static EffectTickProc * const _effect_tick_procs[] = {
EffectTick_5, EffectTick_5,
EffectTick_6, EffectTick_6,
EffectTick_7, EffectTick_7,
EffectTick_8, BulldozerTick,
EffectTick_9, EffectTick_9,
}; };