(svn r9705) -Codechange: Merge some data arrays together, making a bit more logical units.

Calculate with a macro (for _industry_anim_offs_toys) the value of x, instead of doing it at run time.
And give some more descriptive names too...
This commit is contained in:
belugas 2007-04-21 02:47:33 +00:00
parent 31a3208257
commit cd97dec5a7
2 changed files with 119 additions and 94 deletions

View File

@ -137,8 +137,7 @@ void DestroyIndustry(Industry *i)
static void IndustryDrawSugarMine(const TileInfo *ti) static void IndustryDrawSugarMine(const TileInfo *ti)
{ {
const DrawIndustrySpec1Struct *d; const DrawIndustryAnimationStruct *d;
uint32 image;
if (!IsIndustryCompleted(ti->tile)) return; if (!IsIndustryCompleted(ti->tile)) return;
@ -146,23 +145,23 @@ static void IndustryDrawSugarMine(const TileInfo *ti)
AddChildSpriteScreen(SPR_IT_SUGAR_MINE_SIEVE + d->image_1, PAL_NONE, d->x, 0); AddChildSpriteScreen(SPR_IT_SUGAR_MINE_SIEVE + d->image_1, PAL_NONE, d->x, 0);
image = d->image_2; if (d->image_2 != 0) {
if (image != 0) AddChildSpriteScreen(SPR_IT_SUGAR_MINE_CLOUDS + image - 1, PAL_NONE, 8, 41); AddChildSpriteScreen(SPR_IT_SUGAR_MINE_CLOUDS + d->image_2 - 1, PAL_NONE, 8, 41);
}
image = d->image_3; if (d->image_3 != 0) {
if (image != 0) { AddChildSpriteScreen(SPR_IT_SUGAR_MINE_PILE + d->image_3 - 1, PAL_NONE,
AddChildSpriteScreen(SPR_IT_SUGAR_MINE_PILE + image - 1, PAL_NONE, _drawtile_proc1[d->image_3 - 1].x, _drawtile_proc1[d->image_3 - 1].y);
_drawtile_proc1_x[image - 1], _drawtile_proc1_y[image - 1]);
} }
} }
static void IndustryDrawToffeeQuarry(const TileInfo *ti) static void IndustryDrawToffeeQuarry(const TileInfo *ti)
{ {
int x = 0; uint8 x = 0;
if (IsIndustryCompleted(ti->tile)) { if (IsIndustryCompleted(ti->tile)) {
x = _industry_anim_offs[GetIndustryAnimationState(ti->tile)]; x = _industry_anim_offs_toffee[GetIndustryAnimationState(ti->tile)];
if ( (byte)x == 0xFF) if (x == 0xFF)
x = 0; x = 0;
} }
@ -173,7 +172,7 @@ static void IndustryDrawToffeeQuarry(const TileInfo *ti)
static void IndustryDrawBubbleGenerator( const TileInfo *ti) static void IndustryDrawBubbleGenerator( const TileInfo *ti)
{ {
if (IsIndustryCompleted(ti->tile)) { if (IsIndustryCompleted(ti->tile)) {
AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_BUBBLE, PAL_NONE, 5, _industry_anim_offs_2[GetIndustryAnimationState(ti->tile)]); AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_BUBBLE, PAL_NONE, 5, _industry_anim_offs_bubbles[GetIndustryAnimationState(ti->tile)]);
} else { } else {
AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_SPRING, PAL_NONE, 3, 67); AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_SPRING, PAL_NONE, 3, 67);
} }
@ -181,12 +180,12 @@ static void IndustryDrawBubbleGenerator( const TileInfo *ti)
static void IndustryDrawToyFactory(const TileInfo *ti) static void IndustryDrawToyFactory(const TileInfo *ti)
{ {
const DrawIndustrySpec4Struct *d; const DrawIndustryAnimationStruct *d;
d = &_industry_anim_offs_3[GetIndustryAnimationState(ti->tile)]; d = &_industry_anim_offs_toys[GetIndustryAnimationState(ti->tile)];
if (d->image_1 != 0xFF) { if (d->image_1 != 0xFF) {
AddChildSpriteScreen(SPR_IT_TOY_FACTORY_CLAY, PAL_NONE, 50 - d->image_1 * 2, 96 + d->image_1); AddChildSpriteScreen(SPR_IT_TOY_FACTORY_CLAY, PAL_NONE, d->x, 96 + d->image_1);
} }
if (d->image_2 != 0xFF) { if (d->image_2 != 0xFF) {
@ -200,13 +199,13 @@ static void IndustryDrawToyFactory(const TileInfo *ti)
static void IndustryDrawCoalPlantSparks(const TileInfo *ti) static void IndustryDrawCoalPlantSparks(const TileInfo *ti)
{ {
if (IsIndustryCompleted(ti->tile)) { if (IsIndustryCompleted(ti->tile)) {
uint image = GetIndustryAnimationState(ti->tile); uint8 image = GetIndustryAnimationState(ti->tile);
if (image != 0 && image < 7) { if (image != 0 && image < 7) {
AddChildSpriteScreen(image + SPR_IT_POWER_PLANT_TRANSFORMERS, AddChildSpriteScreen(image + SPR_IT_POWER_PLANT_TRANSFORMERS,
PAL_NONE, PAL_NONE,
_coal_plant_sparks_x[image - 1], _coal_plant_sparks[image - 1].x,
_coal_plant_sparks_y[image - 1] _coal_plant_sparks[image - 1].y
); );
} }
} }
@ -412,7 +411,7 @@ static void AnimateTile_Industry(TileIndex tile)
if ((_tick_counter & 3) == 0) { if ((_tick_counter & 3) == 0) {
m = GetIndustryAnimationState(tile); m = GetIndustryAnimationState(tile);
if (_industry_anim_offs[m] == 0xFF) { if (_industry_anim_offs_toffee[m] == 0xFF) {
SndPlayTileFx(SND_30_CARTOON_SOUND, tile); SndPlayTileFx(SND_30_CARTOON_SOUND, tile);
} }

View File

@ -2,20 +2,30 @@
/** @file industry_land.h */ /** @file industry_land.h */
struct DrawIndustrySpec1Struct { /**
byte x; * This is used to gather some data about animation
byte image_1; * drawing in the industry code
byte image_2; * Image_1-2-3 are in fact only offset in the sprites
byte image_3; * used by the industry.
* To specify an invalid one, either 255 or 0 is used,
* depending of the industry.
*/
struct DrawIndustryAnimationStruct {
int x; ///< coordinate x of the first image offset
byte image_1; ///< image offset 1
byte image_2; ///< image offset 2
byte image_3; ///< image offset 3
}; };
struct DrawIndustrySpec4Struct { /**
byte image_1; * Simple structure gathering x,y coordinates for
byte image_2; * industries animations
byte image_3; */
struct DrawIndustryCoordinates {
byte x; ///< coordinate x of the pair
byte y; ///< coordinate y of the pair
}; };
/** /**
* Macro to ease the declaration of the array * Macro to ease the declaration of the array
* @param s1 sprite ID of ground sprite * @param s1 sprite ID of ground sprite
@ -734,9 +744,10 @@ static const DrawBuildingsTileStruct _industry_draw_tile_data[NUM_INDUSTRY_GFXES
M( 0xf8d, PAL_NONE, 0x12a5 | (1 << PALETTE_MODIFIER_COLOR), PAL_NONE, 0, 0, 16, 16, 50, 1), M( 0xf8d, PAL_NONE, 0x12a5 | (1 << PALETTE_MODIFIER_COLOR), PAL_NONE, 0, 0, 16, 16, 50, 1),
M( 0xf8d, PAL_NONE, 0x12a5 | (1 << PALETTE_MODIFIER_COLOR), PAL_NONE, 0, 0, 16, 16, 50, 1), M( 0xf8d, PAL_NONE, 0x12a5 | (1 << PALETTE_MODIFIER_COLOR), PAL_NONE, 0, 0, 16, 16, 50, 1),
}; };
#undef M
/* this is ONLY used for Sugar Mine*/ /* this is ONLY used for Sugar Mine*/
static const DrawIndustrySpec1Struct _draw_industry_spec1[96] = { static const DrawIndustryAnimationStruct _draw_industry_spec1[96] = {
{ 8, 4, 0, 0}, { 8, 4, 0, 0},
{ 6, 0, 1, 0}, { 6, 0, 1, 0},
{ 4, 0, 2, 0}, { 4, 0, 2, 0},
@ -836,71 +847,77 @@ static const DrawIndustrySpec1Struct _draw_industry_spec1[96] = {
}; };
/* this is ONLY used for Sugar Mine*/ /* this is ONLY used for Sugar Mine*/
static const byte _drawtile_proc1_x[5] = { static const DrawIndustryCoordinates _drawtile_proc1[5] = {
22, 17, 14, 10, 8 {22, 73},
{17, 70},
{14, 69},
{10, 66},
{ 8, 41},
}; };
/* this is ONLY used for Sugar Mine*/ /** this is ONLY used for Toy Factory.
static const byte _drawtile_proc1_y[5] = { * 255 means no drawing
73, 70, 69, 66, 41 * @param img1 offset from base sprite SPR_IT_SUGAR_MINE_SIEVE
}; * @param img2 offset from base sprite SPR_IT_SUGAR_MINE_CLOUDS
* @param img3 offset from base sprite SPR_IT_SUGAR_MINE_PILE
/* this is ONLY used for Toy Factory*/ */
static const DrawIndustrySpec4Struct _industry_anim_offs_3[] = { #define MD( img1, img2, img3) { (50 - img1 * 2), img1, img2, img3 }
{255, 255, 0}, static const DrawIndustryAnimationStruct _industry_anim_offs_toys[] = {
{ 0, 255, 0}, MD(255, 255, 0),
{ 1, 255, 0}, MD( 0, 255, 0),
{ 2, 255, 0}, MD( 1, 255, 0),
{ 3, 255, 0}, MD( 2, 255, 0),
{ 4, 255, 0}, MD( 3, 255, 0),
{ 5, 255, 0}, MD( 4, 255, 0),
{ 6, 255, 0}, MD( 5, 255, 0),
{ 7, 255, 0}, MD( 6, 255, 0),
{ 8, 255, 0}, MD( 7, 255, 0),
{ 9, 255, 0}, MD( 8, 255, 0),
{ 10, 255, 0}, MD( 9, 255, 0),
{ 11, 255, 0}, MD( 10, 255, 0),
{ 12, 255, 0}, MD( 11, 255, 0),
{ 13, 255, 0}, MD( 12, 255, 0),
{ 14, 255, 0}, MD( 13, 255, 0),
{ 15, 255, 0}, MD( 14, 255, 0),
{ 16, 255, 0}, MD( 15, 255, 0),
{ 17, 255, 0}, MD( 16, 255, 0),
{ 18, 255, 0}, MD( 17, 255, 0),
{ 18, 255, 1}, MD( 18, 255, 0),
{ 18, 255, 2}, MD( 18, 255, 1),
{ 18, 255, 4}, MD( 18, 255, 2),
{ 18, 255, 6}, MD( 18, 255, 4),
{ 18, 255, 8}, MD( 18, 255, 6),
{ 18, 255, 11}, MD( 18, 255, 8),
{ 18, 255, 14}, MD( 18, 255, 11),
{ 18, 255, 17}, MD( 18, 255, 14),
{ 18, 255, 20}, MD( 18, 255, 17),
{ 18, 255, 24}, MD( 18, 255, 20),
{255, 0, 29}, MD( 18, 255, 24),
{255, 0, 24}, MD(255, 0, 29),
{255, 0, 20}, MD(255, 0, 24),
{255, 0, 17}, MD(255, 0, 20),
{255, 0, 14}, MD(255, 0, 17),
{255, 0, 11}, MD(255, 0, 14),
{255, 0, 8}, MD(255, 0, 11),
{255, 0, 6}, MD(255, 0, 8),
{255, 0, 4}, MD(255, 0, 6),
{255, 0, 2}, MD(255, 0, 4),
{255, 0, 1}, MD(255, 0, 2),
{255, 1, 0}, MD(255, 0, 1),
{255, 2, 0}, MD(255, 1, 0),
{255, 3, 0}, MD(255, 2, 0),
{255, 4, 0}, MD(255, 3, 0),
{255, 5, 0}, MD(255, 4, 0),
{255, 6, 0}, MD(255, 5, 0),
{255, 7, 0}, MD(255, 6, 0),
{255, 8, 0}, MD(255, 7, 0),
{255, 255, 0}, MD(255, 8, 0),
MD(255, 255, 0),
}; };
#undef MD
/* this is ONLY used for Toffee Quarry*/ /* this is ONLY used for Toffee Quarry*/
static const byte _industry_anim_offs[] = { static const byte _industry_anim_offs_toffee[] = {
255, 0, 0, 0, 2, 4, 6, 8, 10, 9, 255, 0, 0, 0, 2, 4, 6, 8, 10, 9,
7, 5, 3, 1, 255, 0, 0, 0, 2, 4, 7, 5, 3, 1, 255, 0, 0, 0, 2, 4,
6, 8, 10, 9, 7, 5, 3, 1, 255, 0, 6, 8, 10, 9, 7, 5, 3, 1, 255, 0,
@ -911,13 +928,22 @@ static const byte _industry_anim_offs[] = {
}; };
/* this is ONLY used for the Bubble Generator*/ /* this is ONLY used for the Bubble Generator*/
static const byte _industry_anim_offs_2[] = { static const byte _industry_anim_offs_bubbles[] = {
68, 69, 71, 74, 77, 80, 83, 85, 86, 86, 68, 69, 71, 74, 77, 80, 83, 85, 86, 86,
86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86,
86, 86, 85, 84, 83, 82, 81, 80, 79, 78, 86, 86, 85, 84, 83, 82, 81, 80, 79, 78,
77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68,
}; };
/* those are ONLY used for Power Station*/ /**
static const byte _coal_plant_sparks_x[] = {11, 11, 14, 13, 18, 15}; * Movement of the sparks , only used for Power Station
static const byte _coal_plant_sparks_y[] = {23, 11, 6, 3, 1, 0}; */
static const DrawIndustryCoordinates _coal_plant_sparks[] = {
{11, 23},
{11, 11},
{14, 6},
{13, 3},
{18, 1},
{15, 0},
};