# HG changeset patch # User belugas # Date 1177123653 0 # Node ID 3207d8852fb9dcddd1d10af3357954b258765860 # Parent 683f200b2510f17a25e55c43799983ec3e406822 (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... diff -r 683f200b2510 -r 3207d8852fb9 src/industry_cmd.cpp --- a/src/industry_cmd.cpp Sat Apr 21 02:42:51 2007 +0000 +++ b/src/industry_cmd.cpp Sat Apr 21 02:47:33 2007 +0000 @@ -137,8 +137,7 @@ static void IndustryDrawSugarMine(const TileInfo *ti) { - const DrawIndustrySpec1Struct *d; - uint32 image; + const DrawIndustryAnimationStruct *d; if (!IsIndustryCompleted(ti->tile)) return; @@ -146,23 +145,23 @@ AddChildSpriteScreen(SPR_IT_SUGAR_MINE_SIEVE + d->image_1, PAL_NONE, d->x, 0); - image = d->image_2; - if (image != 0) AddChildSpriteScreen(SPR_IT_SUGAR_MINE_CLOUDS + image - 1, PAL_NONE, 8, 41); + if (d->image_2 != 0) { + AddChildSpriteScreen(SPR_IT_SUGAR_MINE_CLOUDS + d->image_2 - 1, PAL_NONE, 8, 41); + } - image = d->image_3; - if (image != 0) { - AddChildSpriteScreen(SPR_IT_SUGAR_MINE_PILE + image - 1, PAL_NONE, - _drawtile_proc1_x[image - 1], _drawtile_proc1_y[image - 1]); + if (d->image_3 != 0) { + AddChildSpriteScreen(SPR_IT_SUGAR_MINE_PILE + d->image_3 - 1, PAL_NONE, + _drawtile_proc1[d->image_3 - 1].x, _drawtile_proc1[d->image_3 - 1].y); } } static void IndustryDrawToffeeQuarry(const TileInfo *ti) { - int x = 0; + uint8 x = 0; if (IsIndustryCompleted(ti->tile)) { - x = _industry_anim_offs[GetIndustryAnimationState(ti->tile)]; - if ( (byte)x == 0xFF) + x = _industry_anim_offs_toffee[GetIndustryAnimationState(ti->tile)]; + if (x == 0xFF) x = 0; } @@ -173,7 +172,7 @@ static void IndustryDrawBubbleGenerator( const TileInfo *ti) { 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 { AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_SPRING, PAL_NONE, 3, 67); } @@ -181,12 +180,12 @@ 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) { - 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) { @@ -200,13 +199,13 @@ static void IndustryDrawCoalPlantSparks(const TileInfo *ti) { if (IsIndustryCompleted(ti->tile)) { - uint image = GetIndustryAnimationState(ti->tile); + uint8 image = GetIndustryAnimationState(ti->tile); if (image != 0 && image < 7) { AddChildSpriteScreen(image + SPR_IT_POWER_PLANT_TRANSFORMERS, PAL_NONE, - _coal_plant_sparks_x[image - 1], - _coal_plant_sparks_y[image - 1] + _coal_plant_sparks[image - 1].x, + _coal_plant_sparks[image - 1].y ); } } @@ -412,7 +411,7 @@ if ((_tick_counter & 3) == 0) { m = GetIndustryAnimationState(tile); - if (_industry_anim_offs[m] == 0xFF) { + if (_industry_anim_offs_toffee[m] == 0xFF) { SndPlayTileFx(SND_30_CARTOON_SOUND, tile); } diff -r 683f200b2510 -r 3207d8852fb9 src/table/industry_land.h --- a/src/table/industry_land.h Sat Apr 21 02:42:51 2007 +0000 +++ b/src/table/industry_land.h Sat Apr 21 02:47:33 2007 +0000 @@ -2,20 +2,30 @@ /** @file industry_land.h */ -struct DrawIndustrySpec1Struct { - byte x; - byte image_1; - byte image_2; - byte image_3; +/** + * This is used to gather some data about animation + * drawing in the industry code + * Image_1-2-3 are in fact only offset in the sprites + * 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; - byte image_2; - byte image_3; +/** + * Simple structure gathering x,y coordinates for + * industries animations + */ +struct DrawIndustryCoordinates { + byte x; ///< coordinate x of the pair + byte y; ///< coordinate y of the pair }; - /** * Macro to ease the declaration of the array * @param s1 sprite ID of ground sprite @@ -734,9 +744,10 @@ 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*/ -static const DrawIndustrySpec1Struct _draw_industry_spec1[96] = { +static const DrawIndustryAnimationStruct _draw_industry_spec1[96] = { { 8, 4, 0, 0}, { 6, 0, 1, 0}, { 4, 0, 2, 0}, @@ -836,71 +847,77 @@ }; /* this is ONLY used for Sugar Mine*/ -static const byte _drawtile_proc1_x[5] = { - 22, 17, 14, 10, 8 -}; - -/* this is ONLY used for Sugar Mine*/ -static const byte _drawtile_proc1_y[5] = { - 73, 70, 69, 66, 41 +static const DrawIndustryCoordinates _drawtile_proc1[5] = { + {22, 73}, + {17, 70}, + {14, 69}, + {10, 66}, + { 8, 41}, }; -/* this is ONLY used for Toy Factory*/ -static const DrawIndustrySpec4Struct _industry_anim_offs_3[] = { - {255, 255, 0}, - { 0, 255, 0}, - { 1, 255, 0}, - { 2, 255, 0}, - { 3, 255, 0}, - { 4, 255, 0}, - { 5, 255, 0}, - { 6, 255, 0}, - { 7, 255, 0}, - { 8, 255, 0}, - { 9, 255, 0}, - { 10, 255, 0}, - { 11, 255, 0}, - { 12, 255, 0}, - { 13, 255, 0}, - { 14, 255, 0}, - { 15, 255, 0}, - { 16, 255, 0}, - { 17, 255, 0}, - { 18, 255, 0}, - { 18, 255, 1}, - { 18, 255, 2}, - { 18, 255, 4}, - { 18, 255, 6}, - { 18, 255, 8}, - { 18, 255, 11}, - { 18, 255, 14}, - { 18, 255, 17}, - { 18, 255, 20}, - { 18, 255, 24}, - {255, 0, 29}, - {255, 0, 24}, - {255, 0, 20}, - {255, 0, 17}, - {255, 0, 14}, - {255, 0, 11}, - {255, 0, 8}, - {255, 0, 6}, - {255, 0, 4}, - {255, 0, 2}, - {255, 0, 1}, - {255, 1, 0}, - {255, 2, 0}, - {255, 3, 0}, - {255, 4, 0}, - {255, 5, 0}, - {255, 6, 0}, - {255, 7, 0}, - {255, 8, 0}, - {255, 255, 0}, +/** this is ONLY used for Toy Factory. + * 255 means no drawing + * @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 + */ +#define MD( img1, img2, img3) { (50 - img1 * 2), img1, img2, img3 } +static const DrawIndustryAnimationStruct _industry_anim_offs_toys[] = { + MD(255, 255, 0), + MD( 0, 255, 0), + MD( 1, 255, 0), + MD( 2, 255, 0), + MD( 3, 255, 0), + MD( 4, 255, 0), + MD( 5, 255, 0), + MD( 6, 255, 0), + MD( 7, 255, 0), + MD( 8, 255, 0), + MD( 9, 255, 0), + MD( 10, 255, 0), + MD( 11, 255, 0), + MD( 12, 255, 0), + MD( 13, 255, 0), + MD( 14, 255, 0), + MD( 15, 255, 0), + MD( 16, 255, 0), + MD( 17, 255, 0), + MD( 18, 255, 0), + MD( 18, 255, 1), + MD( 18, 255, 2), + MD( 18, 255, 4), + MD( 18, 255, 6), + MD( 18, 255, 8), + MD( 18, 255, 11), + MD( 18, 255, 14), + MD( 18, 255, 17), + MD( 18, 255, 20), + MD( 18, 255, 24), + MD(255, 0, 29), + MD(255, 0, 24), + MD(255, 0, 20), + MD(255, 0, 17), + MD(255, 0, 14), + MD(255, 0, 11), + MD(255, 0, 8), + MD(255, 0, 6), + MD(255, 0, 4), + MD(255, 0, 2), + MD(255, 0, 1), + MD(255, 1, 0), + MD(255, 2, 0), + MD(255, 3, 0), + MD(255, 4, 0), + MD(255, 5, 0), + MD(255, 6, 0), + MD(255, 7, 0), + MD(255, 8, 0), + MD(255, 255, 0), }; +#undef MD /* 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, 7, 5, 3, 1, 255, 0, 0, 0, 2, 4, 6, 8, 10, 9, 7, 5, 3, 1, 255, 0, @@ -911,13 +928,22 @@ }; /* 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, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 85, 84, 83, 82, 81, 80, 79, 78, 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}; -static const byte _coal_plant_sparks_y[] = {23, 11, 6, 3, 1, 0}; +/** + * Movement of the sparks , only used for Power Station + */ +static const DrawIndustryCoordinates _coal_plant_sparks[] = { + {11, 23}, + {11, 11}, + {14, 6}, + {13, 3}, + {18, 1}, + {15, 0}, +}; +