|
@@ -449,13 +449,13 @@ static void AddAcceptedCargo_Industry(Ti
|
|
|
for (uint i = 0; i < 3; i++) cargo_acceptance[i] = GB(res, i * 4, 4);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for (byte i = 0; i < lengthof(itspec->accepts_cargo); i++) {
|
|
|
CargoID a = accepts_cargo[i];
|
|
|
if (a == CT_INVALID || cargo_acceptance[i] <= 0) continue; // work only with valid cargoes
|
|
|
if (!IsValidCargoID(a) || cargo_acceptance[i] <= 0) continue; // work only with valid cargoes
|
|
|
|
|
|
/* Add accepted cargo */
|
|
|
acceptance[a] += cargo_acceptance[i];
|
|
|
|
|
|
/* Maybe set 'always accepted' bit (if it's not set already) */
|
|
|
if (HasBit(*always_accepted, a)) continue;
|
|
@@ -531,13 +531,13 @@ static bool TransportIndustryGoods(TileI
|
|
|
Industry *i = Industry::GetByTile(tile);
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(i->type);
|
|
|
bool moved_cargo = false;
|
|
|
|
|
|
for (uint j = 0; j < lengthof(i->produced_cargo_waiting); j++) {
|
|
|
uint cw = ClampTo<uint8_t>(i->produced_cargo_waiting[j]);
|
|
|
if (cw > indspec->minimal_cargo && i->produced_cargo[j] != CT_INVALID) {
|
|
|
if (cw > indspec->minimal_cargo && IsValidCargoID(i->produced_cargo[j])) {
|
|
|
i->produced_cargo_waiting[j] -= cw;
|
|
|
|
|
|
/* fluctuating economy? */
|
|
|
if (EconomyIsInRecession()) cw = (cw + 1) / 2;
|
|
|
|
|
|
i->this_month_production[j] += cw;
|
|
@@ -988,13 +988,13 @@ bool IsTileForestIndustry(TileIndex tile
|
|
|
/* Check for organic industry (i.e. not processing or extractive) */
|
|
|
if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_ORGANIC) == 0) return false;
|
|
|
|
|
|
/* Check for wood production */
|
|
|
for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
|
|
|
/* The industry produces wood. */
|
|
|
if (ind->produced_cargo[i] != CT_INVALID && CargoSpec::Get(ind->produced_cargo[i])->label == 'WOOD') return true;
|
|
|
if (IsValidCargoID(ind->produced_cargo[i]) && CargoSpec::Get(ind->produced_cargo[i])->label == 'WOOD') return true;
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6};
|
|
@@ -1864,13 +1864,13 @@ static void DoCreateNewIndustry(Industry
|
|
|
break;
|
|
|
}
|
|
|
CargoID cargo = GetCargoTranslation(GB(res, 0, 8), indspec->grf_prop.grffile);
|
|
|
/* Industries without "unlimited" cargo types support depend on the specific order/slots of cargo types.
|
|
|
* They need to be able to blank out specific slots without aborting the callback sequence,
|
|
|
* and solve this by returning undefined cargo indexes. Skip these. */
|
|
|
if (cargo == CT_INVALID && !(indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED)) continue;
|
|
|
if (!IsValidCargoID(cargo) && !(indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED)) continue;
|
|
|
/* Verify valid cargo */
|
|
|
if (std::find(indspec->accepts_cargo, endof(indspec->accepts_cargo), cargo) == endof(indspec->accepts_cargo)) {
|
|
|
/* Cargo not in spec, error in NewGRF */
|
|
|
ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_INPUT_CARGO_TYPES, res);
|
|
|
break;
|
|
|
}
|
|
@@ -1894,13 +1894,13 @@ static void DoCreateNewIndustry(Industry
|
|
|
if (indspec->grf_prop.grffile->grf_version >= 8 && res >= 0x100) {
|
|
|
ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_OUTPUT_CARGO_TYPES, res);
|
|
|
break;
|
|
|
}
|
|
|
CargoID cargo = GetCargoTranslation(GB(res, 0, 8), indspec->grf_prop.grffile);
|
|
|
/* Allow older GRFs to skip slots. */
|
|
|
if (cargo == CT_INVALID && !(indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED)) continue;
|
|
|
if (!IsValidCargoID(cargo) && !(indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED)) continue;
|
|
|
/* Verify valid cargo */
|
|
|
if (std::find(indspec->produced_cargo, endof(indspec->produced_cargo), cargo) == endof(indspec->produced_cargo)) {
|
|
|
/* Cargo not in spec, error in NewGRF */
|
|
|
ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_OUTPUT_CARGO_TYPES, res);
|
|
|
break;
|
|
|
}
|
|
@@ -2417,13 +2417,13 @@ void GenerateIndustries()
|
|
|
* Monthly update of industry statistics.
|
|
|
* @param i Industry to update.
|
|
|
*/
|
|
|
static void UpdateIndustryStatistics(Industry *i)
|
|
|
{
|
|
|
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
|
|
if (i->produced_cargo[j] != CT_INVALID) {
|
|
|
if (IsValidCargoID(i->produced_cargo[j])) {
|
|
|
byte pct = 0;
|
|
|
if (i->this_month_production[j] != 0) {
|
|
|
i->last_prod_year = TimerGameCalendar::year;
|
|
|
pct = ClampTo<byte>(i->this_month_transported[j] * 256 / i->this_month_production[j]);
|
|
|
}
|
|
|
i->last_month_pct_transported[j] = pct;
|
|
@@ -2619,13 +2619,13 @@ static bool CheckIndustryCloseDownProtec
|
|
|
* @param *c_produces: Pointer to boolean for production of cargo
|
|
|
* @return: \c *c_accepts is set when industry accepts the cargo type,
|
|
|
* \c *c_produces is set when the industry produces the cargo type
|
|
|
*/
|
|
|
static void CanCargoServiceIndustry(CargoID cargo, Industry *ind, bool *c_accepts, bool *c_produces)
|
|
|
{
|
|
|
if (cargo == CT_INVALID) return;
|
|
|
if (!IsValidCargoID(cargo)) return;
|
|
|
|
|
|
/* Check for acceptance of cargo */
|
|
|
for (byte j = 0; j < lengthof(ind->accepts_cargo); j++) {
|
|
|
if (cargo == ind->accepts_cargo[j] && !IndustryTemporarilyRefusesCargo(ind, cargo)) {
|
|
|
*c_accepts = true;
|
|
|
break;
|
|
@@ -2797,13 +2797,13 @@ static void ChangeIndustryProduction(Ind
|
|
|
div = 1; // Decrease production
|
|
|
}
|
|
|
}
|
|
|
} else if (_settings_game.economy.type == ET_SMOOTH) {
|
|
|
closeit = !(i->ctlflags & (INDCTL_NO_CLOSURE | INDCTL_NO_PRODUCTION_DECREASE));
|
|
|
for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
|
|
|
if (i->produced_cargo[j] == CT_INVALID) continue;
|
|
|
if (!IsValidCargoID(i->produced_cargo[j])) continue;
|
|
|
uint32 r = Random();
|
|
|
int old_prod, new_prod, percent;
|
|
|
/* If over 60% is transported, mult is 1, else mult is -1. */
|
|
|
int mult = (i->last_month_pct_transported[j] > PERCENT_TRANSPORTED_60) ? 1 : -1;
|
|
|
|
|
|
new_prod = old_prod = i->production_rate[j];
|