|
@@ -1414,96 +1414,101 @@ static void DoCreateNewIndustry(Industry
|
|
|
{
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(type);
|
|
|
uint32 r;
|
|
|
uint j;
|
|
|
|
|
|
i->xy = tile;
|
|
|
i->width = i->height = 0;
|
|
|
i->type = type;
|
|
|
IncIndustryTypeCount(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];
|
|
|
|
|
|
if (_patches.smooth_economy) {
|
|
|
i->production_rate[0] = min((RandomRange(256) + 128) * i->production_rate[0] >> 8 , 255);
|
|
|
i->production_rate[1] = min((RandomRange(256) + 128) * i->production_rate[1] >> 8 , 255);
|
|
|
}
|
|
|
|
|
|
i->town = t;
|
|
|
i->owner = owner;
|
|
|
|
|
|
r = Random();
|
|
|
i->random_color = GB(r, 8, 4);
|
|
|
i->counter = GB(r, 0, 12);
|
|
|
i->produced_cargo_waiting[0] = 0;
|
|
|
i->produced_cargo_waiting[1] = 0;
|
|
|
i->incoming_cargo_waiting[0] = 0;
|
|
|
i->incoming_cargo_waiting[1] = 0;
|
|
|
i->incoming_cargo_waiting[2] = 0;
|
|
|
i->this_month_production[0] = 0;
|
|
|
i->this_month_production[1] = 0;
|
|
|
i->this_month_transported[0] = 0;
|
|
|
i->this_month_transported[1] = 0;
|
|
|
i->last_month_pct_transported[0] = 0;
|
|
|
i->last_month_pct_transported[1] = 0;
|
|
|
i->last_month_transported[0] = 0;
|
|
|
i->last_month_transported[1] = 0;
|
|
|
i->was_cargo_delivered = false;
|
|
|
i->last_prod_year = _cur_year;
|
|
|
i->last_month_production[0] = i->production_rate[0] * 8;
|
|
|
i->last_month_production[1] = i->production_rate[1] * 8;
|
|
|
i->founder = _current_player;
|
|
|
|
|
|
if (HASBIT(indspec->callback_flags, CBM_IND_DECIDE_COLOUR)) {
|
|
|
uint16 res = GetIndustryCallback(CBID_INDUSTRY_DECIDE_COLOUR, 0, 0, i, type, INVALID_TILE);
|
|
|
if (res != CALLBACK_FAILED) i->random_color = GB(res, 0, 4);
|
|
|
}
|
|
|
|
|
|
if (HASBIT(indspec->callback_flags, CBM_IND_INPUT_CARGO_TYPES)) {
|
|
|
for (j = 0; j < lengthof(i->accepts_cargo); j++) i->accepts_cargo[j] = CT_INVALID;
|
|
|
for (j = 0; j < lengthof(i->accepts_cargo); j++) {
|
|
|
uint16 res = GetIndustryCallback(CBID_INDUSTRY_INPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE);
|
|
|
if (res == CALLBACK_FAILED || GB(res, 0, 8) == CT_INVALID) break;
|
|
|
i->accepts_cargo[j] = GetCargoTranslation(GB(res, 0, 8), indspec->grf_prop.grffile);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (HASBIT(indspec->callback_flags, CBM_IND_OUTPUT_CARGO_TYPES)) {
|
|
|
for (j = 0; j < lengthof(i->produced_cargo); j++) i->produced_cargo[j] = CT_INVALID;
|
|
|
for (j = 0; j < lengthof(i->produced_cargo); j++) {
|
|
|
uint16 res = GetIndustryCallback(CBID_INDUSTRY_OUTPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE);
|
|
|
if (res == CALLBACK_FAILED || GB(res, 0, 8) == CT_INVALID) break;
|
|
|
i->produced_cargo[j] = GetCargoTranslation(GB(res, 0, 8), indspec->grf_prop.grffile);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
i->construction_date = _date;
|
|
|
i->construction_type = (_game_mode == GM_EDITOR) ? ICT_SCENARIO_EDITOR :
|
|
|
(_generating_world ? ICT_MAP_GENERATION : ICT_NORMAL_GAMEPLAY);
|
|
|
|
|
|
/* Adding 1 here makes it conform to specs of var44 of varaction2 for industries
|
|
|
* 0 = created prior of newindustries
|
|
|
* else, chosen layout + 1 */
|
|
|
i->selected_layout = layout + 1;
|
|
|
|
|
|
if (!_generating_world) i->last_month_production[0] = i->last_month_production[1] = 0;
|
|
|
|
|
|
i->prod_level = 0x10;
|
|
|
|
|
|
do {
|
|
|
TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
|
|
|
|
|
|
if (it->gfx != GFX_WATERTILE_SPECIALCHECK) {
|
|
|
byte size;
|
|
|
|
|
|
size = it->ti.x;
|
|
|
if (size > i->width) i->width = size;
|
|
|
size = it->ti.y;
|
|
|
if (size > i->height)i->height = size;
|
|
|
|
|
|
DoCommand(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
|
|
|
|
|
MakeIndustry(cur_tile, i->index, it->gfx);
|
|
|
if (_generating_world) {
|
|
|
SetIndustryConstructionCounter(cur_tile, 3);
|
|
|
SetIndustryConstructionStage(cur_tile, 2);
|