|
@@ -44,64 +44,24 @@ enum {
|
|
|
static void IndustryPoolNewBlock(uint start_item)
|
|
|
{
|
|
|
Industry *i;
|
|
|
|
|
|
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
|
|
|
* TODO - This is just a temporary stage, this will be removed. */
|
|
|
for (i = GetIndustry(start_item); i != NULL; i = (i->index + 1 < GetIndustryPoolSize()) ? GetIndustry(i->index + 1) : NULL) i->index = start_item++;
|
|
|
}
|
|
|
|
|
|
/* Initialize the industry-pool */
|
|
|
MemoryPool _industry_pool = { "Industry", INDUSTRY_POOL_MAX_BLOCKS, INDUSTRY_POOL_BLOCK_SIZE_BITS, sizeof(Industry), &IndustryPoolNewBlock, NULL, 0, 0, NULL };
|
|
|
|
|
|
static const IndustryType _industry_close_mode[IT_END] = {
|
|
|
/* COAL_MINE */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* POWER_STATION */ INDUSTRYLIFE_NOT_CLOSABLE,
|
|
|
/* SAWMILL */ INDUSTRYLIFE_CLOSABLE,
|
|
|
/* FOREST */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* OIL_REFINERY */ INDUSTRYLIFE_CLOSABLE,
|
|
|
/* OIL_RIG */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* FACTORY */ INDUSTRYLIFE_CLOSABLE,
|
|
|
/* PRINTING_WORKS */ INDUSTRYLIFE_CLOSABLE,
|
|
|
/* STEEL_MILL */ INDUSTRYLIFE_CLOSABLE,
|
|
|
/* FARM */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* COPPER_MINE */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* OIL_WELL */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* BANK */ INDUSTRYLIFE_NOT_CLOSABLE,
|
|
|
/* FOOD_PROCESS */ INDUSTRYLIFE_CLOSABLE,
|
|
|
/* PAPER_MILL */ INDUSTRYLIFE_CLOSABLE,
|
|
|
/* GOLD_MINE */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* BANK_2, */ INDUSTRYLIFE_NOT_CLOSABLE,
|
|
|
/* DIAMOND_MINE */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* IRON_MINE */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* FRUIT_PLANTATION */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* RUBBER_PLANTATION */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* WATER_SUPPLY */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* WATER_TOWER */ INDUSTRYLIFE_NOT_CLOSABLE,
|
|
|
/* FACTORY_2 */ INDUSTRYLIFE_CLOSABLE,
|
|
|
/* FARM_2 */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* LUMBER_MILL */ INDUSTRYLIFE_CLOSABLE,
|
|
|
/* COTTON_CANDY */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* CANDY_FACTORY */ INDUSTRYLIFE_CLOSABLE,
|
|
|
/* BATTERY_FARM */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* COLA_WELLS */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* TOY_SHOP */ INDUSTRYLIFE_NOT_CLOSABLE,
|
|
|
/* TOY_FACTORY */ INDUSTRYLIFE_CLOSABLE,
|
|
|
/* PLASTIC_FOUNTAINS */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* FIZZY_DRINK_FACTORY */INDUSTRYLIFE_CLOSABLE,
|
|
|
/* BUBBLE_GENERATOR */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* TOFFEE_QUARRY */ INDUSTRYLIFE_PRODUCTION,
|
|
|
/* SUGAR_MINE */ INDUSTRYLIFE_PRODUCTION
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 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);
|
|
@@ -1654,25 +1614,25 @@ void GenerateIndustries(void)
|
|
|
do {
|
|
|
PlaceInitialIndustry(b[1], b[0]);
|
|
|
} while ( (b+=2)[0] != 0);
|
|
|
}
|
|
|
|
|
|
/* Change industry production or do closure */
|
|
|
static void ExtChangeIndustryProduction(Industry *i)
|
|
|
{
|
|
|
bool closeit = true;
|
|
|
int j;
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(i->type);
|
|
|
|
|
|
switch (_industry_close_mode[i->type]) {
|
|
|
switch (indspec->life_type) {
|
|
|
case INDUSTRYLIFE_NOT_CLOSABLE:
|
|
|
return;
|
|
|
|
|
|
case INDUSTRYLIFE_CLOSABLE:
|
|
|
if ((byte)(_cur_year - i->last_prod_year) < 5 || !CHANCE16(1, 180))
|
|
|
closeit = false;
|
|
|
break;
|
|
|
|
|
|
default: /* INDUSTRY_PRODUCTION */
|
|
|
for (j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){
|
|
|
uint32 r = Random();
|
|
|
int old, new, percent;
|
|
@@ -1801,25 +1761,25 @@ static void MaybeNewIndustry(uint32 r)
|
|
|
STR_482D_NEW_UNDER_CONSTRUCTION : STR_482E_NEW_BEING_PLANTED_NEAR,
|
|
|
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY,0), i->xy, 0
|
|
|
);
|
|
|
}
|
|
|
|
|
|
static void ChangeIndustryProduction(Industry *i)
|
|
|
{
|
|
|
bool only_decrease = false;
|
|
|
StringID str = STR_NULL;
|
|
|
int type = i->type;
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(type);
|
|
|
|
|
|
switch (_industry_close_mode[type]) {
|
|
|
switch (indspec->life_type) {
|
|
|
case INDUSTRYLIFE_NOT_CLOSABLE:
|
|
|
return;
|
|
|
|
|
|
case INDUSTRYLIFE_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 */
|