--- a/src/industry_cmd.cpp Wed Jun 13 11:17:30 2007 +0000
+++ b/src/industry_cmd.cpp Wed Jun 13 11:45:14 2007 +0000
@@ -55,26 +55,16 @@
* Retrieve the type for this industry. Although it is accessed by a tile,
* it will return the general type of industry, and not the sprite index
* as would do GetIndustryGfx.
- * The same information can be accessed by looking at Industry->type
* @param tile that is queried
* @pre IsTileType(tile, MP_INDUSTRY)
* @return general type for this industry, as defined in industry.h
**/
IndustryType GetIndustryType(TileIndex tile)
{
- IndustryGfx this_type = GetIndustryGfx(tile);
- IndustryType iloop;
-
assert(IsTileType(tile, MP_INDUSTRY));
- for (iloop = IT_COAL_MINE; iloop < NUM_INDUSTRYTYPES; iloop += 1) {
- if (IS_BYTE_INSIDE(this_type, industry_gfx_Solver[iloop].MinGfx,
- industry_gfx_Solver[iloop].MaxGfx + 1)) {
- return iloop;
- }
- }
-
- return IT_INVALID; //we have not found equivalent, whatever the reason
+ const Industry *ind = GetIndustryByTile(tile);
+ return IsValidIndustry(ind) ? ind->type : (IndustryType)IT_INVALID;
}
/**
@@ -137,8 +127,7 @@
static void IndustryDrawSugarMine(const TileInfo *ti)
{
- const DrawIndustrySpec1Struct *d;
- uint32 image;
+ const DrawIndustryAnimationStruct *d;
if (!IsIndustryCompleted(ti->tile)) return;
@@ -146,23 +135,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 +162,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 +170,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 +189,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
);
}
}
@@ -356,7 +345,7 @@
i->last_mo_production[0] += cw;
- am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[0], cw);
+ am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[0], cw);
i->last_mo_transported[0] += am;
if (am != 0) {
uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production;
@@ -378,7 +367,7 @@
i->last_mo_production[1] += cw;
- am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[1], cw);
+ am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[1], cw);
i->last_mo_transported[1] += am;
}
}
@@ -412,7 +401,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);
}
@@ -753,7 +742,7 @@
static void GetProducedCargo_Industry(TileIndex tile, CargoID *b)
{
- const Industry *i = GetIndustryByTile(tile);
+ const IndustrySpec *i = GetIndustrySpec(GetIndustryByTile(tile)->type);
b[0] = i->produced_cargo[0];
b[1] = i->produced_cargo[1];
@@ -916,57 +905,17 @@
i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + 45); ///< Found a tree, add according value to waiting cargo
}
-static const byte _industry_sounds[37][2] = {
- {0},
- {0},
- {1, SND_28_SAWMILL},
- {0},
- {0},
- {0},
- {1, SND_03_FACTORY_WHISTLE},
- {1, SND_03_FACTORY_WHISTLE},
- {0},
- {3, SND_24_SHEEP},
- {0},
- {0},
- {0},
- {0},
- {1, SND_28_SAWMILL},
- {0},
- {0},
- {0},
- {0},
- {0},
- {0},
- {0},
- {0},
- {1, SND_03_FACTORY_WHISTLE},
- {0},
- {0},
- {0},
- {0},
- {0},
- {0},
- {0},
- {0},
- {1, SND_33_PLASTIC_MINE},
- {0},
- {0},
- {0},
- {0},
-};
-
-
static void ProduceIndustryGoods(Industry *i)
{
uint32 r;
uint num;
+ const IndustrySpec *indsp = GetIndustrySpec(i->type);
/* play a sound? */
if ((i->counter & 0x3F) == 0) {
- if (CHANCE16R(1, 14, r) && (num = _industry_sounds[i->type][0]) != 0) {
+ if (CHANCE16R(1, 14, r) && (num = indsp->number_of_sounds) != 0) {
SndPlayTileFx(
- (SoundFx)(_industry_sounds[i->type][1] + (((r >> 16) * num) >> 16)),
+ (SoundFx)(indsp->random_sounds[((r >> 16) * num) >> 16]),
i->xy);
}
}
@@ -975,7 +924,7 @@
/* produce some cargo */
if ((i->counter & 0xFF) == 0) {
- IndustyBehaviour indbehav = GetIndustrySpec(i->type)->behaviour;
+ IndustyBehaviour indbehav = indsp->behaviour;
i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + i->production_rate[0]);
i->cargo_waiting[1] = min(0xffff, i->cargo_waiting[1] + i->production_rate[1]);
@@ -1334,7 +1283,7 @@
/* check if an industry that accepts the same goods is nearby */
if (DistanceMax(tile, i->xy) <= 14 &&
indspec->accepts_cargo[0] != CT_INVALID &&
- indspec->accepts_cargo[0] == i->accepts_cargo[0] && (
+ indspec->accepts_cargo[0] == indspec->accepts_cargo[0] && (
_game_mode != GM_EDITOR ||
!_patches.same_industry_close ||
!_patches.multiple_industry_per_town
@@ -1385,11 +1334,6 @@
i->width = i->height = 0;
i->type = type;
- i->produced_cargo[0] = indspec->produced_cargo[0];
- i->produced_cargo[1] = indspec->produced_cargo[1];
- i->accepts_cargo[0] = indspec->accepts_cargo[0];
- i->accepts_cargo[1] = indspec->accepts_cargo[1];
- i->accepts_cargo[2] = indspec->accepts_cargo[2];
i->production_rate[0] = indspec->production_rate[0];
i->production_rate[1] = indspec->production_rate[1];
@@ -1542,9 +1486,10 @@
return CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, it);
}
-static const byte _numof_industry_table[4][12] = {
+static const byte _numof_industry_table[5][12] = {
/* difficulty settings for number of industries */
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //none
+ {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, //very low
{0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5}, //low
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, //normal
{0, 2, 3, 4, 6, 7, 8, 9, 10, 10, 10}, //high
@@ -1638,7 +1583,7 @@
break;
default: /* INDUSTRY_PRODUCTION */
- for (j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){
+ for (j = 0; j < 2 && indspec->produced_cargo[j] != CT_INVALID; j++){
uint32 r = Random();
int old_prod, new_prod, percent;
int mag;
@@ -1664,7 +1609,7 @@
mag = abs(percent);
if (mag >= 10) {
SetDParam(2, mag);
- SetDParam(0, GetCargo(i->produced_cargo[j])->name);
+ SetDParam(0, GetCargo(indspec->produced_cargo[j])->name);
SetDParam(1, i->index);
AddNewsItem(
percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN,
@@ -1693,40 +1638,26 @@
{
byte pct;
bool refresh = false;
+ const IndustrySpec *indsp = GetIndustrySpec(i->type);
- if (i->produced_cargo[0] != CT_INVALID) {
- pct = 0;
- if (i->last_mo_production[0] != 0) {
- i->last_prod_year = _cur_year;
- pct = min(i->last_mo_transported[0] * 256 / i->last_mo_production[0], 255);
+ for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) {
+ if (indsp->produced_cargo[j] != CT_INVALID) {
+ pct = 0;
+ if (i->last_mo_production[j] != 0) {
+ i->last_prod_year = _cur_year;
+ pct = min(i->last_mo_transported[j] * 256 / i->last_mo_production[j], 255);
+ }
+ i->pct_transported[j] = pct;
+
+ i->total_production[j] = i->last_mo_production[j];
+ i->last_mo_production[j] = 0;
+
+ i->total_transported[j] = i->last_mo_transported[j];
+ i->last_mo_transported[j] = 0;
+ refresh = true;
}
- i->pct_transported[0] = pct;
-
- i->total_production[0] = i->last_mo_production[0];
- i->last_mo_production[0] = 0;
-
- i->total_transported[0] = i->last_mo_transported[0];
- i->last_mo_transported[0] = 0;
- refresh = true;
}
- if (i->produced_cargo[1] != CT_INVALID) {
- pct = 0;
- if (i->last_mo_production[1] != 0) {
- i->last_prod_year = _cur_year;
- pct = min(i->last_mo_transported[1] * 256 / i->last_mo_production[1], 255);
- }
- i->pct_transported[1] = pct;
-
- i->total_production[1] = i->last_mo_production[1];
- i->last_mo_production[1] = 0;
-
- i->total_transported[1] = i->last_mo_transported[1];
- i->last_mo_transported[1] = 0;
- refresh = true;
- }
-
-
if (refresh)
InvalidateWindow(WC_INDUSTRY_VIEW, i->index);
@@ -1920,10 +1851,10 @@
SLE_VAR(Industry, width, SLE_UINT8),
SLE_VAR(Industry, height, SLE_UINT8),
SLE_REF(Industry, town, REF_TOWN),
- SLE_ARR(Industry, produced_cargo, SLE_UINT8, 2),
+ SLE_CONDNULL( 2, 2, 60), ///< used to be industry's produced_cargo
SLE_ARR(Industry, cargo_waiting, SLE_UINT16, 2),
SLE_ARR(Industry, production_rate, SLE_UINT8, 2),
- SLE_ARR(Industry, accepts_cargo, SLE_UINT8, 3),
+ SLE_CONDNULL( 3, 2, 60), ///< used to be industry's accepts_cargo
SLE_VAR(Industry, prod_level, SLE_UINT8),
SLE_ARR(Industry, last_mo_production, SLE_UINT16, 2),
SLE_ARR(Industry, last_mo_transported, SLE_UINT16, 2),