mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Decouple INDUSTRY_CTRL into separate commands (#10475)
This commit is contained in:
parent
d7fcb420c4
commit
fe2c8a1240
|
@ -232,7 +232,9 @@ enum Commands : uint16 {
|
|||
CMD_CHANGE_SERVICE_INT, ///< change the server interval of a vehicle
|
||||
|
||||
CMD_BUILD_INDUSTRY, ///< build a new industry
|
||||
CMD_INDUSTRY_CTRL, ///< change industry properties
|
||||
CMD_INDUSTRY_SET_FLAGS, ///< change industry control flags
|
||||
CMD_INDUSTRY_SET_EXCLUSIVITY, ///< change industry exclusive consumer/supplier
|
||||
CMD_INDUSTRY_SET_TEXT, ///< change additional text for the industry
|
||||
|
||||
CMD_SET_COMPANY_MANAGER_FACE, ///< set the manager's face of the company
|
||||
CMD_SET_COMPANY_COLOUR, ///< set the colour of the company
|
||||
|
|
|
@ -33,13 +33,6 @@ enum ProductionLevels {
|
|||
PRODLEVEL_MAXIMUM = 0x80, ///< the industry is running at full speed
|
||||
};
|
||||
|
||||
enum class IndustryAction : byte {
|
||||
SetControlFlags = 0, ///< Set IndustryControlFlags
|
||||
SetExclusiveSupplier = 1, ///< Set exclusive supplier
|
||||
SetExclusiveConsumer = 2, ///< Set exclusive consumer
|
||||
SetText = 3, ///< Set additional text
|
||||
};
|
||||
|
||||
/**
|
||||
* Flags to control/override the behaviour of an industry.
|
||||
* These flags are controlled by game scripts.
|
||||
|
|
|
@ -2092,56 +2092,73 @@ CommandCost CmdBuildIndustry(DoCommandFlag flags, TileIndex tile, IndustryType i
|
|||
}
|
||||
|
||||
/**
|
||||
* Change industry properties
|
||||
* Set industry control flags.
|
||||
* @param flags Type of operation.
|
||||
* @param ind_id IndustryID
|
||||
* @param action IndustryAction to perform
|
||||
* @param ctlflags IndustryControlFlags (only used with set control flags)
|
||||
* @param company_id CompanyID to set or INVALID_OWNER (available to everyone) or
|
||||
* OWNER_NONE (neutral stations only) or OWNER_DEITY (no one)
|
||||
* (only used with set exclusive supplier / consumer)
|
||||
* @param text - Additional industry text (only used with set text action)
|
||||
* @param ctlflags IndustryControlFlags
|
||||
* @return Empty cost or an error.
|
||||
*/
|
||||
CommandCost CmdIndustryCtrl(DoCommandFlag flags, IndustryID ind_id, IndustryAction action, IndustryControlFlags ctlflags, Owner company_id, const std::string &text)
|
||||
CommandCost CmdIndustrySetFlags(DoCommandFlag flags, IndustryID ind_id, IndustryControlFlags ctlflags)
|
||||
{
|
||||
if (_current_company != OWNER_DEITY) return CMD_ERROR;
|
||||
|
||||
Industry *ind = Industry::GetIfValid(ind_id);
|
||||
if (ind == nullptr) return CMD_ERROR;
|
||||
|
||||
switch (action) {
|
||||
case IndustryAction::SetControlFlags: {
|
||||
if (flags & DC_EXEC) ind->ctlflags = ctlflags & INDCTL_MASK;
|
||||
if (flags & DC_EXEC) ind->ctlflags = ctlflags & INDCTL_MASK;
|
||||
|
||||
break;
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change exclusive consumer or supplier for the industry.
|
||||
* @param flags Type of operation.
|
||||
* @param ind_id IndustryID
|
||||
* @param company_id CompanyID to set or INVALID_OWNER (available to everyone) or
|
||||
* OWNER_NONE (neutral stations only) or OWNER_DEITY (no one)
|
||||
* @param consumer Set exclusive consumer if true, supplier if false.
|
||||
* @return Empty cost or an error.
|
||||
*/
|
||||
CommandCost CmdIndustrySetExclusivity(DoCommandFlag flags, IndustryID ind_id, Owner company_id, bool consumer)
|
||||
{
|
||||
if (_current_company != OWNER_DEITY) return CMD_ERROR;
|
||||
|
||||
Industry *ind = Industry::GetIfValid(ind_id);
|
||||
if (ind == nullptr) return CMD_ERROR;
|
||||
|
||||
if (company_id != OWNER_NONE && company_id != INVALID_OWNER && company_id != OWNER_DEITY
|
||||
&& !Company::IsValidID(company_id)) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (consumer) {
|
||||
ind->exclusive_consumer = company_id;
|
||||
} else {
|
||||
ind->exclusive_supplier = company_id;
|
||||
}
|
||||
}
|
||||
|
||||
case IndustryAction::SetExclusiveSupplier:
|
||||
case IndustryAction::SetExclusiveConsumer: {
|
||||
if (company_id != OWNER_NONE && company_id != INVALID_OWNER && company_id != OWNER_DEITY
|
||||
&& !Company::IsValidID(company_id)) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (action == IndustryAction::SetExclusiveSupplier) {
|
||||
ind->exclusive_supplier = company_id;
|
||||
} else {
|
||||
ind->exclusive_consumer = company_id;
|
||||
}
|
||||
}
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
/**
|
||||
* Change additional industry text.
|
||||
* @param flags Type of operation.
|
||||
* @param ind_id IndustryID
|
||||
* @param text - Additional industry text.
|
||||
* @return Empty cost or an error.
|
||||
*/
|
||||
CommandCost CmdIndustrySetText(DoCommandFlag flags, IndustryID ind_id, const std::string &text)
|
||||
{
|
||||
if (_current_company != OWNER_DEITY) return CMD_ERROR;
|
||||
|
||||
case IndustryAction::SetText: {
|
||||
ind->text.clear();
|
||||
if (!text.empty()) ind->text = text;
|
||||
InvalidateWindowData(WC_INDUSTRY_VIEW, ind->index);
|
||||
break;
|
||||
}
|
||||
Industry *ind = Industry::GetIfValid(ind_id);
|
||||
if (ind == nullptr) return CMD_ERROR;
|
||||
|
||||
default:
|
||||
return CMD_ERROR;
|
||||
if (flags & DC_EXEC) {
|
||||
ind->text.clear();
|
||||
if (!text.empty()) ind->text = text;
|
||||
InvalidateWindowData(WC_INDUSTRY_VIEW, ind->index);
|
||||
}
|
||||
|
||||
return CommandCost();
|
||||
|
|
|
@ -14,14 +14,17 @@
|
|||
#include "company_type.h"
|
||||
#include "industry_type.h"
|
||||
|
||||
enum class IndustryAction : byte;
|
||||
enum IndustryControlFlags : byte;
|
||||
|
||||
CommandCost CmdBuildIndustry(DoCommandFlag flags, TileIndex tile, IndustryType it, uint32 first_layout, bool fund, uint32 seed);
|
||||
CommandCost CmdIndustryCtrl(DoCommandFlag flags, IndustryID ind_id, IndustryAction action, IndustryControlFlags ctlflags, Owner company_id, const std::string &text);
|
||||
CommandCost CmdIndustrySetFlags(DoCommandFlag flags, IndustryID ind_id, IndustryControlFlags ctlflags);
|
||||
CommandCost CmdIndustrySetExclusivity(DoCommandFlag flags, IndustryID ind_id, Owner company_id, bool consumer);
|
||||
CommandCost CmdIndustrySetText(DoCommandFlag flags, IndustryID ind_id, const std::string &text);
|
||||
|
||||
DEF_CMD_TRAIT(CMD_BUILD_INDUSTRY, CmdBuildIndustry, CMD_DEITY, CMDT_LANDSCAPE_CONSTRUCTION)
|
||||
DEF_CMD_TRAIT(CMD_INDUSTRY_CTRL, CmdIndustryCtrl, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT)
|
||||
DEF_CMD_TRAIT(CMD_BUILD_INDUSTRY, CmdBuildIndustry, CMD_DEITY, CMDT_LANDSCAPE_CONSTRUCTION)
|
||||
DEF_CMD_TRAIT(CMD_INDUSTRY_SET_FLAGS, CmdIndustrySetFlags, CMD_DEITY, CMDT_OTHER_MANAGEMENT)
|
||||
DEF_CMD_TRAIT(CMD_INDUSTRY_SET_EXCLUSIVITY, CmdIndustrySetExclusivity, CMD_DEITY, CMDT_OTHER_MANAGEMENT)
|
||||
DEF_CMD_TRAIT(CMD_INDUSTRY_SET_TEXT, CmdIndustrySetText, CMD_DEITY | CMD_STR_CTRL, CMDT_OTHER_MANAGEMENT)
|
||||
|
||||
void CcBuildIndustry(Commands cmd, const CommandCost &result, TileIndex tile, IndustryType indtype, uint32, bool, uint32);
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
}
|
||||
EnforcePrecondition(false, IsValidIndustry(industry_id));
|
||||
|
||||
return ScriptObject::Command<CMD_INDUSTRY_CTRL>::Do(industry_id, IndustryAction::SetText, INDCTL_NONE, INVALID_OWNER, std::string{ encoded_text ? encoded_text : "" });
|
||||
return ScriptObject::Command<CMD_INDUSTRY_SET_TEXT>::Do(industry_id, std::string{ encoded_text ? encoded_text : "" });
|
||||
}
|
||||
|
||||
/* static */ ScriptIndustry::CargoAcceptState ScriptIndustry::IsCargoAccepted(IndustryID industry_id, CargoID cargo_id)
|
||||
|
@ -258,7 +258,7 @@ bool ScriptIndustry::SetControlFlags(IndustryID industry_id, uint32 control_flag
|
|||
if (ScriptObject::GetCompany() != OWNER_DEITY) return false;
|
||||
if (!IsValidIndustry(industry_id)) return false;
|
||||
|
||||
return ScriptObject::Command<CMD_INDUSTRY_CTRL>::Do(industry_id, IndustryAction::SetControlFlags, (::IndustryControlFlags)control_flags & ::INDCTL_MASK, INVALID_OWNER, {});
|
||||
return ScriptObject::Command<CMD_INDUSTRY_SET_FLAGS>::Do(industry_id, (::IndustryControlFlags)control_flags & ::INDCTL_MASK);
|
||||
}
|
||||
|
||||
/* static */ ScriptCompany::CompanyID ScriptIndustry::GetExclusiveSupplier(IndustryID industry_id)
|
||||
|
@ -277,7 +277,7 @@ bool ScriptIndustry::SetControlFlags(IndustryID industry_id, uint32 control_flag
|
|||
|
||||
auto company = ScriptCompany::ResolveCompanyID(company_id);
|
||||
::Owner owner = (company == ScriptCompany::COMPANY_INVALID ? ::INVALID_OWNER : (::Owner)company);
|
||||
return ScriptObject::Command<CMD_INDUSTRY_CTRL>::Do(industry_id, IndustryAction::SetExclusiveSupplier, INDCTL_NONE, owner, {});
|
||||
return ScriptObject::Command<CMD_INDUSTRY_SET_EXCLUSIVITY>::Do(industry_id, owner, false);
|
||||
}
|
||||
|
||||
/* static */ ScriptCompany::CompanyID ScriptIndustry::GetExclusiveConsumer(IndustryID industry_id)
|
||||
|
@ -296,5 +296,5 @@ bool ScriptIndustry::SetControlFlags(IndustryID industry_id, uint32 control_flag
|
|||
|
||||
auto company = ScriptCompany::ResolveCompanyID(company_id);
|
||||
::Owner owner = (company == ScriptCompany::COMPANY_INVALID ? ::INVALID_OWNER : (::Owner)company);
|
||||
return ScriptObject::Command<CMD_INDUSTRY_CTRL>::Do(industry_id, IndustryAction::SetExclusiveConsumer, INDCTL_NONE, owner, {});
|
||||
return ScriptObject::Command<CMD_INDUSTRY_SET_EXCLUSIVITY>::Do(industry_id, owner, true);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue