summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorPavel Stupnikov <dp@dpointer.org>2020-01-15 20:46:26 +0300
committerNiels Martin Hansen <nielsm@indvikleren.dk>2020-01-15 18:46:26 +0100
commitd7a928a08b0d614bc06f4a6e8a275582a100599f (patch)
treeefd1163e334ea02f8ba5811df5ff4ca175c37374 /src/script
parent4366f8e46a601aa1edaa5f5c3a7e41d453637b4c (diff)
downloadopenttd-d7a928a08b0d614bc06f4a6e8a275582a100599f.tar.xz
Feature: GS method to control engine availability for a specific company (#7791)
* Feature: GS method to allow company to use an engine before its introduction date * Feature: GS method to retire an engine early for a specific company
Diffstat (limited to 'src/script')
-rw-r--r--src/script/api/game/game_engine.hpp.sq2
-rw-r--r--src/script/api/game_changelog.hpp2
-rw-r--r--src/script/api/script_engine.cpp22
-rw-r--r--src/script/api/script_engine.hpp23
4 files changed, 49 insertions, 0 deletions
diff --git a/src/script/api/game/game_engine.hpp.sq b/src/script/api/game/game_engine.hpp.sq
index fdef599c3..2efa1414a 100644
--- a/src/script/api/game/game_engine.hpp.sq
+++ b/src/script/api/game/game_engine.hpp.sq
@@ -46,6 +46,8 @@ void SQGSEngine_Register(Squirrel *engine)
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::IsArticulated, "IsArticulated", 2, ".i");
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::GetPlaneType, "GetPlaneType", 2, ".i");
SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::GetMaximumOrderDistance, "GetMaximumOrderDistance", 2, ".i");
+ SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::EnableForCompany, "EnableForCompany", 3, ".ii");
+ SQGSEngine.DefSQStaticMethod(engine, &ScriptEngine::DisableForCompany, "DisableForCompany", 3, ".ii");
SQGSEngine.PostRegister(engine);
}
diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp
index 74fdb6423..235dcee98 100644
--- a/src/script/api/game_changelog.hpp
+++ b/src/script/api/game_changelog.hpp
@@ -25,6 +25,8 @@
* \li GSRoad::RoadVehHasPowerOnRoad
* \li GSRoad::ConvertRoadType
* \li GSRoad::GetMaxSpeed
+ * \li GSEngine::EnableForCompany
+ * \li GSEngine::DisableForCompany
*
* \b 1.9.0
*
diff --git a/src/script/api/script_engine.cpp b/src/script/api/script_engine.cpp
index 6b1e267ff..1ec1b23a8 100644
--- a/src/script/api/script_engine.cpp
+++ b/src/script/api/script_engine.cpp
@@ -276,3 +276,25 @@
return 0;
}
}
+
+/* static */ bool ScriptEngine::EnableForCompany(EngineID engine_id, ScriptCompany::CompanyID company)
+{
+ company = ScriptCompany::ResolveCompanyID(company);
+
+ EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
+ EnforcePrecondition(false, IsValidEngine(engine_id));
+ EnforcePrecondition(false, company != ScriptCompany::COMPANY_INVALID);
+
+ return ScriptObject::DoCommand(0, engine_id, (uint32)company | (1 << 31), CMD_ENGINE_CTRL);
+}
+
+/* static */ bool ScriptEngine::DisableForCompany(EngineID engine_id, ScriptCompany::CompanyID company)
+{
+ company = ScriptCompany::ResolveCompanyID(company);
+
+ EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
+ EnforcePrecondition(false, IsValidEngine(engine_id));
+ EnforcePrecondition(false, company != ScriptCompany::COMPANY_INVALID);
+
+ return ScriptObject::DoCommand(0, engine_id, company, CMD_ENGINE_CTRL);
+}
diff --git a/src/script/api/script_engine.hpp b/src/script/api/script_engine.hpp
index 4a570fb9c..f6bdbedbf 100644
--- a/src/script/api/script_engine.hpp
+++ b/src/script/api/script_engine.hpp
@@ -287,6 +287,29 @@ public:
* @see ScriptOrder::GetOrderDistance
*/
static uint GetMaximumOrderDistance(EngineID engine_id);
+
+ /**
+ * Allows a company to use an engine before its intro date or after retirement.
+ * @param engine_id The engine to enable.
+ * @param company_id The company to allow using the engine.
+ * @pre IsValidEngine(engine_id).
+ * @pre ScriptCompany.ResolveCompanyID(company_id) != ScriptCompany::COMPANY_INVALID.
+ * @return True if the action succeeded.
+ * @api -ai
+ */
+ static bool EnableForCompany(EngineID engine_id, ScriptCompany::CompanyID company_id);
+
+ /**
+ * Forbids a company to use an engine before its natural retirement.
+ * @param engine_id The engine to disable.
+ * @param company_id The company to forbid using the engine.
+ * @pre IsValidEngine(engine_id).
+ * @pre ScriptCompany.ResolveCompanyID(company_id) != ScriptCompany::COMPANY_INVALID.
+ * @return True if the action succeeded.
+ * @api -ai
+ */
+ static bool DisableForCompany(EngineID engine_id, ScriptCompany::CompanyID company_id);
+
};
#endif /* SCRIPT_ENGINE_HPP */