1
0
Fork 0

(svn r1824) -Codechange: made ChangeIndustryProduction a bit more readable

release/0.4.5
truelight 2005-02-06 15:07:29 +00:00
parent 92d1b6060c
commit b0d6d59be5
1 changed files with 144 additions and 85 deletions

View File

@ -86,8 +86,51 @@ typedef struct IndustrySpec {
#include "table/build_industry.h" #include "table/build_industry.h"
static const byte _industry_close_mode[37] = { typedef enum IndustryType {
1,0,2,1,2,1,2,2,2,1,1,1,0,2,2,1,0,1,1,1,1,1,0,2,1,2,1,2,1,1,0,2,1,2,1,1,1, INDUSTRY_NOT_CLOSABLE, //! Industry can never close
INDUSTRY_PRODUCTION, //! Industry can close and change of production
INDUSTRY_CLOSABLE, //! Industry can only close (no production change)
} IndustryType;
static const IndustryType _industry_close_mode[37] = {
/* COAL_MINE */ INDUSTRY_PRODUCTION,
/* POWER_STATION */ INDUSTRY_NOT_CLOSABLE,
/* SAWMILL */ INDUSTRY_CLOSABLE,
/* FOREST */ INDUSTRY_PRODUCTION,
/* OIL_REFINERY */ INDUSTRY_CLOSABLE,
/* OIL_RIG */ INDUSTRY_PRODUCTION,
/* FACTORY */ INDUSTRY_CLOSABLE,
/* PRINTING_WORKS */ INDUSTRY_CLOSABLE,
/* STEEL_MILL */ INDUSTRY_CLOSABLE,
/* FARM */ INDUSTRY_PRODUCTION,
/* COPPER_MINE */ INDUSTRY_PRODUCTION,
/* OIL_WELL */ INDUSTRY_PRODUCTION,
/* BANK */ INDUSTRY_NOT_CLOSABLE,
/* FOOD_PROCESS */ INDUSTRY_CLOSABLE,
/* PAPER_MILL */ INDUSTRY_CLOSABLE,
/* GOLD_MINE */ INDUSTRY_PRODUCTION,
/* BANK_2, */ INDUSTRY_NOT_CLOSABLE,
/* DIAMOND_MINE */ INDUSTRY_PRODUCTION,
/* IRON_MINE */ INDUSTRY_PRODUCTION,
/* FRUIT_PLANTATION */ INDUSTRY_PRODUCTION,
/* RUBBER_PLANTATION */ INDUSTRY_PRODUCTION,
/* WATER_SUPPLY */ INDUSTRY_PRODUCTION,
/* WATER_TOWER */ INDUSTRY_NOT_CLOSABLE,
/* FACTORY_2 */ INDUSTRY_CLOSABLE,
/* FARM_2 */ INDUSTRY_PRODUCTION,
/* LUMBER_MILL */ INDUSTRY_CLOSABLE,
/* COTTON_CANDY */ INDUSTRY_PRODUCTION,
/* CANDY_FACTORY */ INDUSTRY_CLOSABLE,
/* BATTERY_FARM */ INDUSTRY_PRODUCTION,
/* COLA_WELLS */ INDUSTRY_PRODUCTION,
/* TOY_SHOP */ INDUSTRY_NOT_CLOSABLE,
/* TOY_FACTORY */ INDUSTRY_CLOSABLE,
/* PLASTIC_FOUNTAINS */ INDUSTRY_PRODUCTION,
/* FIZZY_DRINK_FACTORY */INDUSTRY_CLOSABLE,
/* BUBBLE_GENERATOR */ INDUSTRY_PRODUCTION,
/* TOFFEE_QUARRY */ INDUSTRY_PRODUCTION,
/* SUGAR_MINE */ INDUSTRY_PRODUCTION
}; };
static const StringID _industry_prod_up_strings[] = { static const StringID _industry_prod_up_strings[] = {
@ -1634,17 +1677,19 @@ void GenerateIndustries(void)
static void ExtChangeIndustryProduction(Industry *i) static void ExtChangeIndustryProduction(Industry *i)
{ {
bool closeit; bool closeit = true;
int j; int j;
if (_industry_close_mode[i->type] == 0) return; switch (_industry_close_mode[i->type]) {
case INDUSTRY_NOT_CLOSABLE:
return;
closeit = true; case INDUSTRY_CLOSABLE:
if (_industry_close_mode[i->type] == 2) {
if ( (byte)(_cur_year - i->last_prod_year) < 5 || !CHANCE16(1,180)) if ( (byte)(_cur_year - i->last_prod_year) < 5 || !CHANCE16(1,180))
closeit = false; closeit = false;
} else { break;
default: /* INDUSTRY_PRODUCTION */
for (j=0; j != 2 && i->produced_cargo[j]!=255; j++){ for (j=0; j != 2 && i->produced_cargo[j]!=255; j++){
uint32 r; uint32 r;
int change,percent,old; int change,percent,old;
@ -1678,6 +1723,7 @@ static void ExtChangeIndustryProduction(Industry *i)
i->xy + TILE_XY(1,1), 0); i->xy + TILE_XY(1,1), 0);
} }
} }
break;
} }
if (closeit) { if (closeit) {
@ -1767,18 +1813,24 @@ static void MaybeNewIndustry(uint32 r)
AddNewsItem( STR_482D_NEW_UNDER_CONSTRUCTION + (type == IT_FOREST), NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ECONOMY,0), i->xy, 0); AddNewsItem( STR_482D_NEW_UNDER_CONSTRUCTION + (type == IT_FOREST), NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ECONOMY,0), i->xy, 0);
} }
static void MaybeCloseIndustry(Industry *i) static void ChangeIndustryProduction(Industry *i)
{ {
uint32 r; bool only_decrease = false;
StringID str; StringID str = STR_NULL;
int type = i->type; int type = i->type;
if (_industry_close_mode[type] == 1) { switch (_industry_close_mode[type]) {
/* decrease or increase */ case INDUSTRY_NOT_CLOSABLE:
if (type == IT_OIL_WELL && _opt.landscape == LT_NORMAL) goto decrease_production; return;
if (CHANCE16I(1,3,r=Random())) {
if ((i->pct_transported[0] > 153) ^ CHANCE16I(1,3,r>>16)) {
case INDUSTRY_PRODUCTION:
/* decrease or increase */
if (type == IT_OIL_WELL && _opt.landscape == LT_NORMAL)
only_decrease = true;
if (only_decrease || CHANCE16(1,3)) {
/* If you transport > 60%, 66% chance we increase, else 33% chance we increase */
if (!only_decrease && (i->pct_transported[0] > 153) != CHANCE16(1,3)) {
/* Increase production */ /* Increase production */
if (i->prod_level != 0x80) { if (i->prod_level != 0x80) {
byte b; byte b;
@ -1786,41 +1838,48 @@ static void MaybeCloseIndustry(Industry *i)
i->prod_level <<= 1; i->prod_level <<= 1;
b = i->production_rate[0] * 2; b = i->production_rate[0] * 2;
if (i->production_rate[0] >= 128) b=255; if (i->production_rate[0] >= 128)
b = 0xFF;
i->production_rate[0] = b; i->production_rate[0] = b;
b = i->production_rate[1] * 2; b = i->production_rate[1] * 2;
if (i->production_rate[1] >= 128) b=255; if (i->production_rate[1] >= 128)
b = 0xFF;
i->production_rate[1] = b; i->production_rate[1] = b;
str = _industry_prod_up_strings[type]; str = _industry_prod_up_strings[type];
goto add_news;
} }
} else { } else {
decrease_production:
/* Decrease production */ /* Decrease production */
if (i->prod_level == 4) goto close_industry; if (i->prod_level == 4) {
i->prod_level = 0;
str = _industry_close_strings[type];
} else {
i->prod_level >>= 1; i->prod_level >>= 1;
i->production_rate[0] = (i->production_rate[0] + 1) >> 1; i->production_rate[0] = (i->production_rate[0] + 1) >> 1;
i->production_rate[1] = (i->production_rate[1] + 1) >> 1; i->production_rate[1] = (i->production_rate[1] + 1) >> 1;
str = _industry_prod_down_strings[type]; str = _industry_prod_down_strings[type];
goto add_news;
} }
} }
} else if (_industry_close_mode[type] > 1) { }
break;
case INDUSTRY_CLOSABLE:
/* maybe close */ /* maybe close */
if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1,2)) { if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1,2)) {
close_industry:
i->prod_level = 0; i->prod_level = 0;
str = _industry_close_strings[type]; str = _industry_close_strings[type];
add_news: }
break;
}
if (str != STR_NULL) {
SetDParam(1, type + STR_4802_COAL_MINE); SetDParam(1, type + STR_4802_COAL_MINE);
SetDParam(0, i->town->index); SetDParam(0, i->town->index);
AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), i->xy + TILE_XY(1,1), 0); AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), i->xy + TILE_XY(1,1), 0);
} }
} }
}
void IndustryMonthlyLoop(void) void IndustryMonthlyLoop(void)
{ {
@ -1839,7 +1898,7 @@ void IndustryMonthlyLoop(void)
} else if (!_patches.smooth_economy && _total_industries > 0) { } else if (!_patches.smooth_economy && _total_industries > 0) {
i = GetIndustry(RandomRange(_total_industries)); i = GetIndustry(RandomRange(_total_industries));
if (i->xy != 0) if (i->xy != 0)
MaybeCloseIndustry(i); ChangeIndustryProduction(i);
} }
_current_player = old_player; _current_player = old_player;