|
@@ -27,111 +27,111 @@
|
|
|
return ::GetIndustrySpec(industry_type)->enabled;
|
|
|
}
|
|
|
|
|
|
/* static */ bool ScriptIndustryType::IsRawIndustry(IndustryType industry_type)
|
|
|
{
|
|
|
if (!IsValidIndustryType(industry_type)) return false;
|
|
|
|
|
|
return ::GetIndustrySpec(industry_type)->IsRawIndustry();
|
|
|
}
|
|
|
|
|
|
/* static */ bool ScriptIndustryType::IsProcessingIndustry(IndustryType industry_type)
|
|
|
{
|
|
|
if (!IsValidIndustryType(industry_type)) return false;
|
|
|
|
|
|
return ::GetIndustrySpec(industry_type)->IsProcessingIndustry();
|
|
|
}
|
|
|
|
|
|
/* static */ bool ScriptIndustryType::ProductionCanIncrease(IndustryType industry_type)
|
|
|
{
|
|
|
if (!IsValidIndustryType(industry_type)) return false;
|
|
|
|
|
|
if (_settings_game.game_creation.landscape != LT_TEMPERATE) return true;
|
|
|
return (::GetIndustrySpec(industry_type)->behaviour & INDUSTRYBEH_DONT_INCR_PROD) == 0;
|
|
|
}
|
|
|
|
|
|
/* static */ Money ScriptIndustryType::GetConstructionCost(IndustryType industry_type)
|
|
|
{
|
|
|
if (!IsValidIndustryType(industry_type)) return -1;
|
|
|
if (::GetIndustrySpec(industry_type)->IsRawIndustry() && _settings_game.construction.raw_industry_construction == 0) return -1;
|
|
|
|
|
|
return ::GetIndustrySpec(industry_type)->GetConstructionCost();
|
|
|
}
|
|
|
|
|
|
/* static */ std::optional<std::string> ScriptIndustryType::GetName(IndustryType industry_type)
|
|
|
{
|
|
|
if (!IsValidIndustryType(industry_type)) return std::nullopt;
|
|
|
|
|
|
return GetString(::GetIndustrySpec(industry_type)->name);
|
|
|
}
|
|
|
|
|
|
/* static */ ScriptList *ScriptIndustryType::GetProducedCargo(IndustryType industry_type)
|
|
|
{
|
|
|
if (!IsValidIndustryType(industry_type)) return nullptr;
|
|
|
|
|
|
const IndustrySpec *ins = ::GetIndustrySpec(industry_type);
|
|
|
|
|
|
ScriptList *list = new ScriptList();
|
|
|
for (size_t i = 0; i < lengthof(ins->produced_cargo); i++) {
|
|
|
if (ins->produced_cargo[i] != CT_INVALID) list->AddItem(ins->produced_cargo[i]);
|
|
|
if (::IsValidCargoID(ins->produced_cargo[i])) list->AddItem(ins->produced_cargo[i]);
|
|
|
}
|
|
|
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
/* static */ ScriptList *ScriptIndustryType::GetAcceptedCargo(IndustryType industry_type)
|
|
|
{
|
|
|
if (!IsValidIndustryType(industry_type)) return nullptr;
|
|
|
|
|
|
const IndustrySpec *ins = ::GetIndustrySpec(industry_type);
|
|
|
|
|
|
ScriptList *list = new ScriptList();
|
|
|
for (size_t i = 0; i < lengthof(ins->accepts_cargo); i++) {
|
|
|
if (ins->accepts_cargo[i] != CT_INVALID) list->AddItem(ins->accepts_cargo[i]);
|
|
|
if (::IsValidCargoID(ins->accepts_cargo[i])) list->AddItem(ins->accepts_cargo[i]);
|
|
|
}
|
|
|
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
/* static */ bool ScriptIndustryType::CanBuildIndustry(IndustryType industry_type)
|
|
|
{
|
|
|
if (!IsValidIndustryType(industry_type)) return false;
|
|
|
|
|
|
const bool deity = ScriptCompanyMode::IsDeity();
|
|
|
if (::GetIndustryProbabilityCallback(industry_type, deity ? IACT_RANDOMCREATION : IACT_USERCREATION, 1) == 0) return false;
|
|
|
if (deity) return true;
|
|
|
if (!::GetIndustrySpec(industry_type)->IsRawIndustry()) return true;
|
|
|
|
|
|
/* raw_industry_construction == 1 means "Build as other industries" */
|
|
|
return _settings_game.construction.raw_industry_construction == 1;
|
|
|
}
|
|
|
|
|
|
/* static */ bool ScriptIndustryType::CanProspectIndustry(IndustryType industry_type)
|
|
|
{
|
|
|
if (!IsValidIndustryType(industry_type)) return false;
|
|
|
|
|
|
const bool deity = ScriptCompanyMode::IsDeity();
|
|
|
if (!deity && !::GetIndustrySpec(industry_type)->IsRawIndustry()) return false;
|
|
|
if (::GetIndustryProbabilityCallback(industry_type, deity ? IACT_RANDOMCREATION : IACT_USERCREATION, 1) == 0) return false;
|
|
|
|
|
|
/* raw_industry_construction == 2 means "prospect" */
|
|
|
return deity || _settings_game.construction.raw_industry_construction == 2;
|
|
|
}
|
|
|
|
|
|
/* static */ bool ScriptIndustryType::BuildIndustry(IndustryType industry_type, TileIndex tile)
|
|
|
{
|
|
|
EnforceDeityOrCompanyModeValid(false);
|
|
|
EnforcePrecondition(false, CanBuildIndustry(industry_type));
|
|
|
EnforcePrecondition(false, ScriptMap::IsValidTile(tile));
|
|
|
|
|
|
uint32 seed = ScriptBase::Rand();
|
|
|
uint32 layout_index = ScriptBase::RandRange((uint32)::GetIndustrySpec(industry_type)->layouts.size());
|
|
|
return ScriptObject::Command<CMD_BUILD_INDUSTRY>::Do(tile, industry_type, layout_index, true, seed);
|
|
|
}
|
|
|
|
|
|
/* static */ bool ScriptIndustryType::ProspectIndustry(IndustryType industry_type)
|
|
|
{
|
|
|
EnforceDeityOrCompanyModeValid(false);
|
|
|
EnforcePrecondition(false, CanProspectIndustry(industry_type));
|
|
|
|
|
|
uint32 seed = ScriptBase::Rand();
|
|
|
return ScriptObject::Command<CMD_BUILD_INDUSTRY>::Do(0, industry_type, 0, false, seed);
|