summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-11-01 21:30:34 +0100
committerMichael Lutz <michi@icosahedron.de>2021-12-16 22:28:32 +0100
commit6691ee3b963ee3282490360bb3cc1ea09d0c58ea (patch)
tree398b1139844d2566831e249836b6923bd88b6124
parenteab18f06a47e558fe313cb86c855e8949b01feed (diff)
downloadopenttd-6691ee3b963ee3282490360bb3cc1ea09d0c58ea.tar.xz
Codechange: Template script command calls.
-rw-r--r--src/script/api/script_airport.cpp6
-rw-r--r--src/script/api/script_basestation.cpp8
-rw-r--r--src/script/api/script_bridge.cpp13
-rw-r--r--src/script/api/script_company.cpp32
-rw-r--r--src/script/api/script_controller.cpp3
-rw-r--r--src/script/api/script_engine.cpp5
-rw-r--r--src/script/api/script_event_types.cpp6
-rw-r--r--src/script/api/script_game.cpp5
-rw-r--r--src/script/api/script_gamesettings.cpp3
-rw-r--r--src/script/api/script_goal.cpp15
-rw-r--r--src/script/api/script_group.cpp25
-rw-r--r--src/script/api/script_industry.cpp9
-rw-r--r--src/script/api/script_industrytype.cpp5
-rw-r--r--src/script/api/script_marine.cpp25
-rw-r--r--src/script/api/script_news.cpp3
-rw-r--r--src/script/api/script_object.cpp36
-rw-r--r--src/script/api/script_object.hpp81
-rw-r--r--src/script/api/script_objecttype.cpp3
-rw-r--r--src/script/api/script_order.cpp37
-rw-r--r--src/script/api/script_rail.cpp31
-rw-r--r--src/script/api/script_road.cpp19
-rw-r--r--src/script/api/script_sign.cpp7
-rw-r--r--src/script/api/script_station.cpp3
-rw-r--r--src/script/api/script_story_page.cpp30
-rw-r--r--src/script/api/script_subsidy.cpp3
-rw-r--r--src/script/api/script_tile.cpp15
-rw-r--r--src/script/api/script_town.cpp17
-rw-r--r--src/script/api/script_tunnel.cpp13
-rw-r--r--src/script/api/script_vehicle.cpp26
-rw-r--r--src/script/api/script_viewport.cpp7
30 files changed, 308 insertions, 183 deletions
diff --git a/src/script/api/script_airport.cpp b/src/script/api/script_airport.cpp
index 947719172..5927b1662 100644
--- a/src/script/api/script_airport.cpp
+++ b/src/script/api/script_airport.cpp
@@ -12,6 +12,8 @@
#include "script_station.hpp"
#include "../../station_base.h"
#include "../../town.h"
+#include "../../landscape_cmd.h"
+#include "../../station_cmd.h"
#include "../../safeguards.h"
@@ -77,7 +79,7 @@
uint p2 = station_id == ScriptStation::STATION_JOIN_ADJACENT ? 0 : 1;
p2 |= (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16;
- return ScriptObject::DoCommand(tile, type, p2, CMD_BUILD_AIRPORT);
+ return ScriptObject::Command<CMD_BUILD_AIRPORT>::Do(tile, type, p2, {});
}
/* static */ bool ScriptAirport::RemoveAirport(TileIndex tile)
@@ -86,7 +88,7 @@
EnforcePrecondition(false, ::IsValidTile(tile))
EnforcePrecondition(false, IsAirportTile(tile) || IsHangarTile(tile));
- return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
+ return ScriptObject::Command<CMD_LANDSCAPE_CLEAR>::Do(tile, 0, 0, {});
}
/* static */ int32 ScriptAirport::GetNumHangars(TileIndex tile)
diff --git a/src/script/api/script_basestation.cpp b/src/script/api/script_basestation.cpp
index 860e54c78..a24934410 100644
--- a/src/script/api/script_basestation.cpp
+++ b/src/script/api/script_basestation.cpp
@@ -13,6 +13,8 @@
#include "../../station_base.h"
#include "../../string_func.h"
#include "../../strings_func.h"
+#include "../../station_cmd.h"
+#include "../../waypoint_cmd.h"
#include "table/strings.h"
#include "../../safeguards.h"
@@ -42,7 +44,11 @@
EnforcePreconditionEncodedText(false, text);
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_STATION_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
- return ScriptObject::DoCommand(0, station_id, 0, ::Station::IsValidID(station_id) ? CMD_RENAME_STATION : CMD_RENAME_WAYPOINT, text);
+ if (::Station::IsValidID(station_id)) {
+ return ScriptObject::Command<CMD_RENAME_STATION>::Do(0, station_id, 0, text);
+ } else {
+ return ScriptObject::Command<CMD_RENAME_WAYPOINT>::Do(0, station_id, 0, text);
+ }
}
/* static */ TileIndex ScriptBaseStation::GetLocation(StationID station_id)
diff --git a/src/script/api/script_bridge.cpp b/src/script/api/script_bridge.cpp
index 4d685ca21..dc357c255 100644
--- a/src/script/api/script_bridge.cpp
+++ b/src/script/api/script_bridge.cpp
@@ -14,6 +14,9 @@
#include "../../bridge_map.h"
#include "../../strings_func.h"
#include "../../date_func.h"
+#include "../../landscape_cmd.h"
+#include "../../road_cmd.h"
+#include "../../tunnelbridge_cmd.h"
#include "table/strings.h"
#include "../../safeguards.h"
@@ -95,12 +98,12 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance)
/* For rail and water we do nothing special */
if (vehicle_type == ScriptVehicle::VT_RAIL || vehicle_type == ScriptVehicle::VT_WATER) {
- return ScriptObject::DoCommand(end, start, type | bridge_id, CMD_BUILD_BRIDGE);
+ return ScriptObject::Command<CMD_BUILD_BRIDGE>::Do(end, start, type | bridge_id, {});
}
ScriptObject::SetCallbackVariable(0, start);
ScriptObject::SetCallbackVariable(1, end);
- return ScriptObject::DoCommand(end, start, type | bridge_id, CMD_BUILD_BRIDGE, nullptr, &::_DoCommandReturnBuildBridge1);
+ return ScriptObject::Command<CMD_BUILD_BRIDGE>::Do(&::_DoCommandReturnBuildBridge1, end, start, type | bridge_id, {});
}
/* static */ bool ScriptBridge::_BuildBridgeRoad1()
@@ -112,7 +115,7 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance)
DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start);
DiagDirection dir_2 = ::ReverseDiagDir(dir_1);
- return ScriptObject::DoCommand(start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2) | (ScriptRoad::GetCurrentRoadType() << 4), 0, CMD_BUILD_ROAD, nullptr, &::_DoCommandReturnBuildBridge2);
+ return ScriptObject::Command<CMD_BUILD_ROAD>::Do(&::_DoCommandReturnBuildBridge2, start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2) | (ScriptRoad::GetCurrentRoadType() << 4), 0, {});
}
/* static */ bool ScriptBridge::_BuildBridgeRoad2()
@@ -124,14 +127,14 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance)
DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start);
DiagDirection dir_2 = ::ReverseDiagDir(dir_1);
- return ScriptObject::DoCommand(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1) | (ScriptRoad::GetCurrentRoadType() << 4), 0, CMD_BUILD_ROAD);
+ return ScriptObject::Command<CMD_BUILD_ROAD>::Do(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1) | (ScriptRoad::GetCurrentRoadType() << 4), 0, {});
}
/* static */ bool ScriptBridge::RemoveBridge(TileIndex tile)
{
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, IsBridgeTile(tile));
- return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
+ return ScriptObject::Command<CMD_LANDSCAPE_CLEAR>::Do(tile, 0, 0, {});
}
/* static */ char *ScriptBridge::GetName(BridgeID bridge_id, ScriptVehicle::VehicleType vehicle_type)
diff --git a/src/script/api/script_company.cpp b/src/script/api/script_company.cpp
index 876ad84c5..c8f8a616f 100644
--- a/src/script/api/script_company.cpp
+++ b/src/script/api/script_company.cpp
@@ -20,6 +20,10 @@
#include "../../tile_map.h"
#include "../../string_func.h"
#include "../../settings_func.h"
+#include "../../company_cmd.h"
+#include "../../misc_cmd.h"
+#include "../../object_cmd.h"
+#include "../../settings_cmd.h"
#include "table/strings.h"
#include "../../safeguards.h"
@@ -48,7 +52,7 @@
EnforcePreconditionEncodedText(false, text);
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_COMPANY_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
- return ScriptObject::DoCommand(0, 0, 0, CMD_RENAME_COMPANY, text);
+ return ScriptObject::Command<CMD_RENAME_COMPANY>::Do(0, 0, 0, text);
}
/* static */ char *ScriptCompany::GetName(ScriptCompany::CompanyID company)
@@ -69,7 +73,7 @@
EnforcePreconditionEncodedText(false, text);
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_PRESIDENT_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
- return ScriptObject::DoCommand(0, 0, 0, CMD_RENAME_PRESIDENT, text);
+ return ScriptObject::Command<CMD_RENAME_PRESIDENT>::Do(0, 0, 0, text);
}
/* static */ char *ScriptCompany::GetPresidentName(ScriptCompany::CompanyID company)
@@ -97,7 +101,7 @@
GenderEthnicity ge = (GenderEthnicity)((gender == GENDER_FEMALE ? (1 << ::GENDER_FEMALE) : 0) | (::InteractiveRandom() & (1 << ETHNICITY_BLACK)));
RandomCompanyManagerFaceBits(cmf, ge, false);
- return ScriptObject::DoCommand(0, 0, cmf, CMD_SET_COMPANY_MANAGER_FACE);
+ return ScriptObject::Command<CMD_SET_COMPANY_MANAGER_FACE>::Do(0, 0, cmf, {});
}
/* static */ ScriptCompany::Gender ScriptCompany::GetPresidentGender(CompanyID company)
@@ -206,9 +210,11 @@
Money amount = abs(loan - GetLoanAmount());
- return ScriptObject::DoCommand(0,
- amount >> 32, (amount & 0xFFFFFFFC) | 2,
- (loan > GetLoanAmount()) ? CMD_INCREASE_LOAN : CMD_DECREASE_LOAN);
+ if (loan > GetLoanAmount()) {
+ return ScriptObject::Command<CMD_INCREASE_LOAN>::Do(0, amount >> 32, (amount & 0xFFFFFFFC) | 2, {});
+ } else {
+ return ScriptObject::Command<CMD_DECREASE_LOAN>::Do(0, amount >> 32, (amount & 0xFFFFFFFC) | 2, {});
+ }
}
/* static */ bool ScriptCompany::SetMinimumLoanAmount(Money loan)
@@ -238,7 +244,7 @@
EnforcePrecondition(false, company != COMPANY_INVALID);
/* Network commands only allow 0 to indicate invalid tiles, not INVALID_TILE */
- return ScriptObject::DoCommand(tile == INVALID_TILE ? (TileIndex)0U : tile , (uint32)(delta), company | expenses_type << 8 , CMD_CHANGE_BANK_BALANCE);
+ return ScriptObject::Command<CMD_CHANGE_BANK_BALANCE>::Do(tile == INVALID_TILE ? (TileIndex)0U : tile, (uint32)(delta), company | expenses_type << 8, {});
}
/* static */ bool ScriptCompany::BuildCompanyHQ(TileIndex tile)
@@ -246,7 +252,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, ::IsValidTile(tile));
- return ScriptObject::DoCommand(tile, OBJECT_HQ, 0, CMD_BUILD_OBJECT);
+ return ScriptObject::Command<CMD_BUILD_OBJECT>::Do(tile, OBJECT_HQ, 0, {});
}
/* static */ TileIndex ScriptCompany::GetCompanyHQ(CompanyID company)
@@ -260,7 +266,7 @@
/* static */ bool ScriptCompany::SetAutoRenewStatus(bool autorenew)
{
- return ScriptObject::DoCommand(0, 0, autorenew ? 1 : 0, CMD_CHANGE_COMPANY_SETTING, "company.engine_renew");
+ return ScriptObject::Command<CMD_CHANGE_COMPANY_SETTING>::Do(0, 0, autorenew ? 1 : 0, "company.engine_renew");
}
/* static */ bool ScriptCompany::GetAutoRenewStatus(CompanyID company)
@@ -273,7 +279,7 @@
/* static */ bool ScriptCompany::SetAutoRenewMonths(int16 months)
{
- return ScriptObject::DoCommand(0, 0, months, CMD_CHANGE_COMPANY_SETTING, "company.engine_renew_months");
+ return ScriptObject::Command<CMD_CHANGE_COMPANY_SETTING>::Do(0, 0, months, "company.engine_renew_months");
}
/* static */ int16 ScriptCompany::GetAutoRenewMonths(CompanyID company)
@@ -288,7 +294,7 @@
{
EnforcePrecondition(false, money >= 0);
EnforcePrecondition(false, (int64)money <= UINT32_MAX);
- return ScriptObject::DoCommand(0, 0, money, CMD_CHANGE_COMPANY_SETTING, "company.engine_renew_money");
+ return ScriptObject::Command<CMD_CHANGE_COMPANY_SETTING>::Do(0, 0, money, "company.engine_renew_money");
}
/* static */ Money ScriptCompany::GetAutoRenewMoney(CompanyID company)
@@ -301,12 +307,12 @@
/* static */ bool ScriptCompany::SetPrimaryLiveryColour(LiveryScheme scheme, Colours colour)
{
- return ScriptObject::DoCommand(0, scheme, colour, CMD_SET_COMPANY_COLOUR);
+ return ScriptObject::Command<CMD_SET_COMPANY_COLOUR>::Do(0, scheme, colour, {});
}
/* static */ bool ScriptCompany::SetSecondaryLiveryColour(LiveryScheme scheme, Colours colour)
{
- return ScriptObject::DoCommand(0, scheme | 1 << 8, colour, CMD_SET_COMPANY_COLOUR);
+ return ScriptObject::Command<CMD_SET_COMPANY_COLOUR>::Do(0, scheme | 1 << 8, colour, {});
}
/* static */ ScriptCompany::Colours ScriptCompany::GetPrimaryLiveryColour(ScriptCompany::LiveryScheme scheme)
diff --git a/src/script/api/script_controller.cpp b/src/script/api/script_controller.cpp
index 8af7b87a3..74a3ad3ea 100644
--- a/src/script/api/script_controller.cpp
+++ b/src/script/api/script_controller.cpp
@@ -21,6 +21,7 @@
#include "../../ai/ai_gui.hpp"
#include "../../settings_type.h"
#include "../../network/network.h"
+#include "../../misc_cmd.h"
#include "../../safeguards.h"
@@ -59,7 +60,7 @@
ShowAIDebugWindow(ScriptObject::GetRootCompany());
if ((_pause_mode & PM_PAUSED_NORMAL) == PM_UNPAUSED) {
- ScriptObject::DoCommand(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
+ ScriptObject::Command<CMD_PAUSE>::Do(0, PM_PAUSED_NORMAL, 1, {});
}
}
diff --git a/src/script/api/script_engine.cpp b/src/script/api/script_engine.cpp
index 1ec1b23a8..d6cab36b6 100644
--- a/src/script/api/script_engine.cpp
+++ b/src/script/api/script_engine.cpp
@@ -17,6 +17,7 @@
#include "../../engine_base.h"
#include "../../engine_func.h"
#include "../../articulated_vehicles.h"
+#include "../../engine_cmd.h"
#include "table/strings.h"
#include "../../safeguards.h"
@@ -285,7 +286,7 @@
EnforcePrecondition(false, IsValidEngine(engine_id));
EnforcePrecondition(false, company != ScriptCompany::COMPANY_INVALID);
- return ScriptObject::DoCommand(0, engine_id, (uint32)company | (1 << 31), CMD_ENGINE_CTRL);
+ return ScriptObject::Command<CMD_ENGINE_CTRL>::Do(0, engine_id, (uint32)company | (1 << 31), {});
}
/* static */ bool ScriptEngine::DisableForCompany(EngineID engine_id, ScriptCompany::CompanyID company)
@@ -296,5 +297,5 @@
EnforcePrecondition(false, IsValidEngine(engine_id));
EnforcePrecondition(false, company != ScriptCompany::COMPANY_INVALID);
- return ScriptObject::DoCommand(0, engine_id, company, CMD_ENGINE_CTRL);
+ return ScriptObject::Command<CMD_ENGINE_CTRL>::Do(0, engine_id, company, {});
}
diff --git a/src/script/api/script_event_types.cpp b/src/script/api/script_event_types.cpp
index 3cc5287eb..f7776c40e 100644
--- a/src/script/api/script_event_types.cpp
+++ b/src/script/api/script_event_types.cpp
@@ -16,6 +16,8 @@
#include "../../engine_base.h"
#include "../../articulated_vehicles.h"
#include "../../string_func.h"
+#include "../../economy_cmd.h"
+#include "../../engine_cmd.h"
#include "table/strings.h"
#include "../../safeguards.h"
@@ -110,12 +112,12 @@ int32 ScriptEventEnginePreview::GetVehicleType()
bool ScriptEventEnginePreview::AcceptPreview()
{
if (!this->IsEngineValid()) return false;
- return ScriptObject::DoCommand(0, this->engine, 0, CMD_WANT_ENGINE_PREVIEW);
+ return ScriptObject::Command<CMD_WANT_ENGINE_PREVIEW>::Do(0, this->engine, 0, {});
}
bool ScriptEventCompanyAskMerger::AcceptMerger()
{
- return ScriptObject::DoCommand(0, this->owner, 0, CMD_BUY_COMPANY);
+ return ScriptObject::Command<CMD_BUY_COMPANY>::Do(0, this->owner, 0, {});
}
ScriptEventAdminPort::ScriptEventAdminPort(const std::string &json) :
diff --git a/src/script/api/script_game.cpp b/src/script/api/script_game.cpp
index 43674c6f3..9b40a1cd3 100644
--- a/src/script/api/script_game.cpp
+++ b/src/script/api/script_game.cpp
@@ -12,17 +12,18 @@
#include "../../command_type.h"
#include "../../settings_type.h"
#include "../../network/network.h"
+#include "../../misc_cmd.h"
#include "../../safeguards.h"
/* static */ bool ScriptGame::Pause()
{
- return ScriptObject::DoCommand(0, PM_PAUSED_GAME_SCRIPT, 1, CMD_PAUSE);
+ return ScriptObject::Command<CMD_PAUSE>::Do(0, PM_PAUSED_GAME_SCRIPT, 1, {});
}
/* static */ bool ScriptGame::Unpause()
{
- return ScriptObject::DoCommand(0, PM_PAUSED_GAME_SCRIPT, 0, CMD_PAUSE);
+ return ScriptObject::Command<CMD_PAUSE>::Do(0, PM_PAUSED_GAME_SCRIPT, 0, {});
}
/* static */ bool ScriptGame::IsPaused()
diff --git a/src/script/api/script_gamesettings.cpp b/src/script/api/script_gamesettings.cpp
index 78b26e9bb..611b78b8b 100644
--- a/src/script/api/script_gamesettings.cpp
+++ b/src/script/api/script_gamesettings.cpp
@@ -12,6 +12,7 @@
#include "../../settings_internal.h"
#include "../../settings_type.h"
#include "../../command_type.h"
+#include "../../settings_cmd.h"
#include "../../safeguards.h"
@@ -37,7 +38,7 @@
if ((sd->flags & SF_NO_NETWORK_SYNC) != 0) return false;
- return ScriptObject::DoCommand(0, 0, value, CMD_CHANGE_SETTING, sd->GetName().c_str());
+ return ScriptObject::Command<CMD_CHANGE_SETTING>::Do(0, 0, value, sd->GetName());
}
/* static */ bool ScriptGameSettings::IsDisabledVehicleType(ScriptVehicle::VehicleType vehicle_type)
diff --git a/src/script/api/script_goal.cpp b/src/script/api/script_goal.cpp
index f1b75b032..dbc2c51e0 100644
--- a/src/script/api/script_goal.cpp
+++ b/src/script/api/script_goal.cpp
@@ -19,6 +19,7 @@
#include "../../goal_base.h"
#include "../../string_func.h"
#include "../../network/network_base.h"
+#include "../../goal_cmd.h"
#include "../../safeguards.h"
@@ -49,7 +50,7 @@
(type == GT_COMPANY && ScriptCompany::ResolveCompanyID((ScriptCompany::CompanyID)destination) != ScriptCompany::COMPANY_INVALID) ||
(type == GT_STORY_PAGE && story_page != nullptr && (c == INVALID_COMPANY ? story_page->company == INVALID_COMPANY : story_page->company == INVALID_COMPANY || story_page->company == c)));
- if (!ScriptObject::DoCommand(0, type | (c << 8), destination, CMD_CREATE_GOAL, text, &ScriptInstance::DoCommandReturnGoalID)) return GOAL_INVALID;
+ if (!ScriptObject::Command<CMD_CREATE_GOAL>::Do(&ScriptInstance::DoCommandReturnGoalID, 0, type | (c << 8), destination, text)) return GOAL_INVALID;
/* In case of test-mode, we return GoalID 0 */
return (ScriptGoal::GoalID)0;
@@ -60,7 +61,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
EnforcePrecondition(false, IsValidGoal(goal_id));
- return ScriptObject::DoCommand(0, goal_id, 0, CMD_REMOVE_GOAL);
+ return ScriptObject::Command<CMD_REMOVE_GOAL>::Do(0, goal_id, 0, {});
}
/* static */ bool ScriptGoal::SetText(GoalID goal_id, Text *goal)
@@ -72,7 +73,7 @@
EnforcePrecondition(false, goal != nullptr);
EnforcePrecondition(false, !StrEmpty(goal->GetEncodedText()));
- return ScriptObject::DoCommand(0, goal_id, 0, CMD_SET_GOAL_TEXT, goal->GetEncodedText());
+ return ScriptObject::Command<CMD_SET_GOAL_TEXT>::Do(0, goal_id, 0, goal->GetEncodedText());
}
/* static */ bool ScriptGoal::SetProgress(GoalID goal_id, Text *progress)
@@ -87,7 +88,7 @@
progress = nullptr;
}
- return ScriptObject::DoCommand(0, goal_id, 0, CMD_SET_GOAL_PROGRESS, progress != nullptr ? progress->GetEncodedText() : nullptr);
+ return ScriptObject::Command<CMD_SET_GOAL_PROGRESS>::Do(0, goal_id, 0, progress != nullptr ? std::string{ progress->GetEncodedText() } : std::string{});
}
/* static */ bool ScriptGoal::SetCompleted(GoalID goal_id, bool completed)
@@ -95,7 +96,7 @@
EnforcePrecondition(false, IsValidGoal(goal_id));
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
- return ScriptObject::DoCommand(0, goal_id, completed ? 1 : 0, CMD_SET_GOAL_COMPLETED);
+ return ScriptObject::Command<CMD_SET_GOAL_COMPLETED>::Do(0, goal_id, completed ? 1 : 0, {});
}
/* static */ bool ScriptGoal::IsCompleted(GoalID goal_id)
@@ -120,7 +121,7 @@
EnforcePrecondition(false, buttons < (1 << ::GOAL_QUESTION_BUTTON_COUNT));
EnforcePrecondition(false, (int)type < ::GQT_END);
- return ScriptObject::DoCommand(0, uniqueid | (target << 16), buttons | (type << 29) | (is_client ? (1 << 31) : 0), CMD_GOAL_QUESTION, text);
+ return ScriptObject::Command<CMD_GOAL_QUESTION>::Do(0, uniqueid | (target << 16), buttons | (type << 29) | (is_client ? (1 << 31) : 0), text);
}
/* static */ bool ScriptGoal::Question(uint16 uniqueid, ScriptCompany::CompanyID company, Text *question, QuestionType type, int buttons)
@@ -145,5 +146,5 @@
{
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
- return ScriptObject::DoCommand(0, uniqueid, 0, CMD_GOAL_QUESTION_ANSWER);
+ return ScriptObject::Command<CMD_GOAL_QUESTION_ANSWER>::Do(0, uniqueid, 0, {});
}
diff --git a/src/script/api/script_group.cpp b/src/script/api/script_group.cpp
index a6e2fdee2..f4535c35e 100644
--- a/src/script/api/script_group.cpp
+++ b/src/script/api/script_group.cpp
@@ -16,6 +16,9 @@
#include "../../autoreplace_func.h"
#include "../../settings_func.h"
#include "../../vehicle_base.h"
+#include "../../autoreplace_cmd.h"
+#include "../../group_cmd.h"
+#include "../../settings_cmd.h"
#include "table/strings.h"
#include "../../safeguards.h"
@@ -28,7 +31,7 @@
/* static */ ScriptGroup::GroupID ScriptGroup::CreateGroup(ScriptVehicle::VehicleType vehicle_type, GroupID parent_group_id)
{
- if (!ScriptObject::DoCommand(0, (::VehicleType)vehicle_type, parent_group_id, CMD_CREATE_GROUP, nullptr, &ScriptInstance::DoCommandReturnGroupID)) return GROUP_INVALID;
+ if (!ScriptObject::Command<CMD_CREATE_GROUP>::Do(&ScriptInstance::DoCommandReturnGroupID, 0, (::VehicleType)vehicle_type, parent_group_id, {})) return GROUP_INVALID;
/* In case of test-mode, we return GroupID 0 */
return (ScriptGroup::GroupID)0;
@@ -38,7 +41,7 @@
{
EnforcePrecondition(false, IsValidGroup(group_id));
- return ScriptObject::DoCommand(0, group_id, 0, CMD_DELETE_GROUP);
+ return ScriptObject::Command<CMD_DELETE_GROUP>::Do(0, group_id, 0, {});
}
/* static */ ScriptVehicle::VehicleType ScriptGroup::GetVehicleType(GroupID group_id)
@@ -58,7 +61,7 @@
EnforcePreconditionEncodedText(false, text);
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_GROUP_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
- return ScriptObject::DoCommand(0, group_id, 0, CMD_ALTER_GROUP, text);
+ return ScriptObject::Command<CMD_ALTER_GROUP>::Do(0, group_id, 0, text);
}
/* static */ char *ScriptGroup::GetName(GroupID group_id)
@@ -74,7 +77,7 @@
EnforcePrecondition(false, IsValidGroup(group_id));
EnforcePrecondition(false, IsValidGroup(parent_group_id));
- return ScriptObject::DoCommand(0, group_id | 1 << 16, parent_group_id, CMD_ALTER_GROUP);
+ return ScriptObject::Command<CMD_ALTER_GROUP>::Do(0, group_id | 1 << 16, parent_group_id, {});
}
/* static */ ScriptGroup::GroupID ScriptGroup::GetParent(GroupID group_id)
@@ -89,7 +92,7 @@
{
EnforcePrecondition(false, IsValidGroup(group_id));
- return ScriptObject::DoCommand(0, group_id | GroupFlags::GF_REPLACE_PROTECTION, enable ? 1 : 0, CMD_SET_GROUP_FLAG);
+ return ScriptObject::Command<CMD_SET_GROUP_FLAG>::Do(0, group_id | GroupFlags::GF_REPLACE_PROTECTION, enable ? 1 : 0, {});
}
/* static */ bool ScriptGroup::GetAutoReplaceProtection(GroupID group_id)
@@ -120,14 +123,14 @@
EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT);
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id));
- return ScriptObject::DoCommand(0, group_id, vehicle_id, CMD_ADD_VEHICLE_GROUP);
+ return ScriptObject::Command<CMD_ADD_VEHICLE_GROUP>::Do(0, group_id, vehicle_id, {});
}
/* static */ bool ScriptGroup::EnableWagonRemoval(bool enable_removal)
{
if (HasWagonRemoval() == enable_removal) return true;
- return ScriptObject::DoCommand(0, 0, enable_removal ? 1 : 0, CMD_CHANGE_COMPANY_SETTING, "company.renew_keep_length");
+ return ScriptObject::Command<CMD_CHANGE_COMPANY_SETTING>::Do(0, 0, enable_removal ? 1 : 0, "company.renew_keep_length");
}
/* static */ bool ScriptGroup::HasWagonRemoval()
@@ -140,7 +143,7 @@
EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL);
EnforcePrecondition(false, ScriptEngine::IsBuildable(engine_id_new));
- return ScriptObject::DoCommand(0, group_id << 16, (engine_id_new << 16) | engine_id_old, CMD_SET_AUTOREPLACE);
+ return ScriptObject::Command<CMD_SET_AUTOREPLACE>::Do(0, group_id << 16, (engine_id_new << 16) | engine_id_old, {});
}
/* static */ EngineID ScriptGroup::GetEngineReplacement(GroupID group_id, EngineID engine_id)
@@ -154,7 +157,7 @@
{
EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL);
- return ScriptObject::DoCommand(0, group_id << 16, (::INVALID_ENGINE << 16) | engine_id, CMD_SET_AUTOREPLACE);
+ return ScriptObject::Command<CMD_SET_AUTOREPLACE>::Do(0, group_id << 16, (::INVALID_ENGINE << 16) | engine_id, {});
}
/* static */ Money ScriptGroup::GetProfitThisYear(GroupID group_id)
@@ -204,14 +207,14 @@
{
EnforcePrecondition(false, IsValidGroup(group_id));
- return ScriptObject::DoCommand(0, group_id, colour << 16, CMD_SET_GROUP_LIVERY);
+ return ScriptObject::Command<CMD_SET_GROUP_LIVERY>::Do(0, group_id, colour << 16, {});
}
/* static */ bool ScriptGroup::SetSecondaryColour(GroupID group_id, ScriptCompany::Colours colour)
{
EnforcePrecondition(false, IsValidGroup(group_id));
- return ScriptObject::DoCommand(0, group_id, (1 << 8) | (colour << 16), CMD_SET_GROUP_LIVERY);
+ return ScriptObject::Command<CMD_SET_GROUP_LIVERY>::Do(0, group_id, (1 << 8) | (colour << 16), {});
}
/* static */ ScriptCompany::Colours ScriptGroup::GetPrimaryColour(GroupID group_id)
diff --git a/src/script/api/script_industry.cpp b/src/script/api/script_industry.cpp
index 6f54fda14..afcaee554 100644
--- a/src/script/api/script_industry.cpp
+++ b/src/script/api/script_industry.cpp
@@ -19,6 +19,7 @@
#include "../../strings_func.h"
#include "../../station_base.h"
#include "../../newgrf_industries.h"
+#include "../../industry_cmd.h"
#include "table/strings.h"
#include <numeric>
@@ -59,7 +60,7 @@
}
EnforcePrecondition(false, IsValidIndustry(industry_id));
- return ScriptObject::DoCommand(0, industry_id, static_cast<uint32>(IndustryAction::SetText), CMD_INDUSTRY_CTRL, encoded_text);
+ return ScriptObject::Command<CMD_INDUSTRY_CTRL>::Do(0, industry_id, static_cast<uint32>(IndustryAction::SetText), std::string{ encoded_text ? encoded_text : "" });
}
/* static */ ScriptIndustry::CargoAcceptState ScriptIndustry::IsCargoAccepted(IndustryID industry_id, CargoID cargo_id)
@@ -257,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::DoCommand(0, industry_id, 0 | ((control_flags & ::INDCTL_MASK) << 8), CMD_INDUSTRY_CTRL);
+ return ScriptObject::Command<CMD_INDUSTRY_CTRL>::Do(0, industry_id, 0 | ((control_flags & ::INDCTL_MASK) << 8), {});
}
/* static */ ScriptCompany::CompanyID ScriptIndustry::GetExclusiveSupplier(IndustryID industry_id)
@@ -276,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::DoCommand(0, industry_id, 1 | (((uint8)owner) << 16), CMD_INDUSTRY_CTRL);
+ return ScriptObject::Command<CMD_INDUSTRY_CTRL>::Do(0, industry_id, 1 | (((uint8)owner) << 16), {});
}
/* static */ ScriptCompany::CompanyID ScriptIndustry::GetExclusiveConsumer(IndustryID industry_id)
@@ -295,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::DoCommand(0, industry_id, 2 | (((uint8)owner) << 16), CMD_INDUSTRY_CTRL);
+ return ScriptObject::Command<CMD_INDUSTRY_CTRL>::Do(0, industry_id, 2 | (((uint8)owner) << 16), {});
}
diff --git a/src/script/api/script_industrytype.cpp b/src/script/api/script_industrytype.cpp
index ad1ee4fed..ebe28c406 100644
--- a/src/script/api/script_industrytype.cpp
+++ b/src/script/api/script_industrytype.cpp
@@ -15,6 +15,7 @@
#include "../../industry.h"
#include "../../newgrf_industries.h"
#include "../../core/random_func.hpp"
+#include "../../industry_cmd.h"
#include "../../safeguards.h"
@@ -122,7 +123,7 @@
uint32 seed = ::InteractiveRandom();
uint32 layout_index = ::InteractiveRandomRange((uint32)::GetIndustrySpec(industry_type)->layouts.size());
- return ScriptObject::DoCommand(tile, (1 << 16) | (layout_index << 8) | industry_type, seed, CMD_BUILD_INDUSTRY);
+ return ScriptObject::Command<CMD_BUILD_INDUSTRY>::Do(tile, (1 << 16) | (layout_index << 8) | industry_type, seed, {});
}
/* static */ bool ScriptIndustryType::ProspectIndustry(IndustryType industry_type)
@@ -130,7 +131,7 @@
EnforcePrecondition(false, CanProspectIndustry(industry_type));
uint32 seed = ::InteractiveRandom();
- return ScriptObject::DoCommand(0, industry_type, seed, CMD_BUILD_INDUSTRY);
+ return ScriptObject::Command<CMD_BUILD_INDUSTRY>::Do(0, industry_type, seed, {});
}
/* static */ bool ScriptIndustryType::IsBuiltOnWater(IndustryType industry_type)
diff --git a/src/script/api/script_marine.cpp b/src/script/api/script_marine.cpp
index 16f0228db..f368ec918 100644
--- a/src/script/api/script_marine.cpp
+++ b/src/script/api/script_marine.cpp
@@ -11,7 +11,12 @@
#include "script_marine.hpp"
#include "script_station.hpp"
#include "../../station_base.h"
+#include "../../dock_cmd.h"
+#include "../../landscape_cmd.h"
+#include "../../station_cmd.h"
#include "../../tile_cmd.h"
+#include "../../water_cmd.h"
+#include "../../waypoint_cmd.h"
#include "../../safeguards.h"
@@ -78,7 +83,7 @@
EnforcePrecondition(false, ::IsValidTile(front));
EnforcePrecondition(false, (::TileX(front) == ::TileX(tile)) != (::TileY(front) == ::TileY(tile)));
- return ScriptObject::DoCommand(tile, ::TileX(front) == ::TileX(tile), 0, CMD_BUILD_SHIP_DEPOT);
+ return ScriptObject::Command<CMD_BUILD_SHIP_DEPOT>::Do(tile, ::TileX(front) == ::TileX(tile), 0, {});
}
/* static */ bool ScriptMarine::BuildDock(TileIndex tile, StationID station_id)
@@ -89,7 +94,7 @@
uint p1 = station_id == ScriptStation::STATION_JOIN_ADJACENT ? 0 : 1;
uint p2 = (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16;
- return ScriptObject::DoCommand(tile, p1, p2, CMD_BUILD_DOCK);
+ return ScriptObject::Command<CMD_BUILD_DOCK>::Do(tile, p1, p2, {});
}
/* static */ bool ScriptMarine::BuildBuoy(TileIndex tile)
@@ -97,7 +102,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, ::IsValidTile(tile));
- return ScriptObject::DoCommand(tile, 0, 0, CMD_BUILD_BUOY);
+ return ScriptObject::Command<CMD_BUILD_BUOY>::Do(tile, 0, 0, {});
}
/* static */ bool ScriptMarine::BuildLock(TileIndex tile)
@@ -105,7 +110,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, ::IsValidTile(tile));
- return ScriptObject::DoCommand(tile, 0, 0, CMD_BUILD_LOCK);
+ return ScriptObject::Command<CMD_BUILD_LOCK>::Do(tile, 0, 0, {});
}
/* static */ bool ScriptMarine::BuildCanal(TileIndex tile)
@@ -113,7 +118,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, ::IsValidTile(tile));
- return ScriptObject::DoCommand(tile, tile, WATER_CLASS_CANAL, CMD_BUILD_CANAL);
+ return ScriptObject::Command<CMD_BUILD_CANAL>::Do(tile, tile, WATER_CLASS_CANAL, {});
}
/* static */ bool ScriptMarine::RemoveWaterDepot(TileIndex tile)
@@ -122,7 +127,7 @@
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, IsWaterDepotTile(tile));
- return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
+ return ScriptObject::Command<CMD_LANDSCAPE_CLEAR>::Do(tile, 0, 0, {});
}
/* static */ bool ScriptMarine::RemoveDock(TileIndex tile)
@@ -131,7 +136,7 @@
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, IsDockTile(tile));
- return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
+ return ScriptObject::Command<CMD_LANDSCAPE_CLEAR>::Do(tile, 0, 0, {});
}
/* static */ bool ScriptMarine::RemoveBuoy(TileIndex tile)
@@ -140,7 +145,7 @@
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, IsBuoyTile(tile));
- return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
+ return ScriptObject::Command<CMD_LANDSCAPE_CLEAR>::Do(tile, 0, 0, {});
}
/* static */ bool ScriptMarine::RemoveLock(TileIndex tile)
@@ -149,7 +154,7 @@
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, IsLockTile(tile));
- return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
+ return ScriptObject::Command<CMD_LANDSCAPE_CLEAR>::Do(tile, 0, 0, {});
}
/* static */ bool ScriptMarine::RemoveCanal(TileIndex tile)
@@ -158,7 +163,7 @@
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, IsCanalTile(tile));
- return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
+ return ScriptObject::Command<CMD_LANDSCAPE_CLEAR>::Do(tile, 0, 0, {});
}
/* static */ Money ScriptMarine::GetBuildCost(BuildType build_type)
diff --git a/src/script/api/script_news.cpp b/src/script/api/script_news.cpp
index 678cc6985..7f46f5aa6 100644
--- a/src/script/api/script_news.cpp
+++ b/src/script/api/script_news.cpp
@@ -16,6 +16,7 @@
#include "script_error.hpp"
#include "../../command_type.h"
#include "../../string_func.h"
+#include "../../news_cmd.h"
#include "../../safeguards.h"
@@ -38,5 +39,5 @@
if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
if (ref_type == NR_NONE) reference = 0;
- return ScriptObject::DoCommand(0, type | (ref_type << 8) | (c << 16), reference, CMD_CUSTOM_NEWS_ITEM, encoded);
+ return ScriptObject::Command<CMD_CUSTOM_NEWS_ITEM>::Do(0, type | (ref_type << 8) | (c << 16), reference, encoded);
}
diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp
index c63d2a2ea..de4fab481 100644
--- a/src/script/api/script_object.cpp
+++ b/src/script/api/script_object.cpp
@@ -296,39 +296,35 @@ ScriptObject::ActiveInstance::~ActiveInstance()
return GetStorage()->callback_value[index];
}
-/* static */ bool ScriptObject::DoCommand(TileIndex tile, uint32 p1, uint32 p2, Commands cmd, const char *text, Script_SuspendCallbackProc *callback)
+/* static */ CommandCallback *ScriptObject::GetDoCommandCallback()
+{
+ return ScriptObject::GetActiveInstance()->GetDoCommandCallback();
+}
+
+std::tuple<bool, bool, bool> ScriptObject::DoCommandPrep()
{
if (!ScriptObject::CanSuspend()) {
throw Script_FatalError("You are not allowed to execute any DoCommand (even indirect) in your constructor, Save(), Load(), and any valuator.");
}
+ /* Are we only interested in the estimate costs? */
+ bool estimate_only = GetDoCommandMode() != nullptr && !GetDoCommandMode()();
+
+ bool networking = _networking && !_generating_world;
+
if (ScriptObject::GetCompany() != OWNER_DEITY && !::Company::IsValidID(ScriptObject::GetCompany())) {
ScriptObject::SetLastError(ScriptError::ERR_PRECONDITION_INVALID_COMPANY);
- return false;
+ return { true, estimate_only, networking };
}
- std::string command_text = text == nullptr ? std::string{} : text;
- if (!command_text.empty() && (GetCommandFlags(cmd) & CMD_STR_CTRL) == 0) {
- /* The string must be valid, i.e. not contain special codes. Since some
- * can be made with GSText, make sure the control codes are removed. */
- command_text = ::StrMakeValid(command_text, SVS_NONE);
- }
+ return { false, estimate_only, networking };
+}
+bool ScriptObject::DoCommandProcessResult(const CommandCost &res, Script_SuspendCallbackProc *callback, bool estimate_only)
+{
/* Set the default callback to return a true/false result of the DoCommand */
if (callback == nullptr) callback = &ScriptInstance::DoCommandReturn;
- /* Are we only interested in the estimate costs? */
- bool estimate_only = GetDoCommandMode() != nullptr && !GetDoCommandMode()();
-
- /* Only set p2 when the command does not come from the network. */
- if (GetCommandFlags(cmd) & CMD_CLIENT_ID && p2 == 0) p2 = UINT32_MAX;
-
- /* Store the command for command callback validation. */
- if (!estimate_only && _networking && !_generating_world) SetLastCommand(tile, EndianBufferWriter<CommandDataBuffer>::FromValue(std::make_tuple(tile, p1, p2, command_text)), cmd);
-
- /* Try to perform the command. */
- CommandCost res = ::DoCommandPInternal(cmd, STR_NULL, (_networking && !_generating_world) ? ScriptObject::GetActiveInstance()->GetDoCommandCallback() : nullptr, false, estimate_only, false, tile, p1, p2, command_text);
-
/* We failed; set the error and bail out */
if (res.Failed()) {
SetLastError(ScriptError::StringToError(res.GetErrorMessage()));
diff --git a/src/script/api/script_object.hpp b/src/script/api/script_object.hpp
index 40c8eaf85..cfb6d393a 100644
--- a/src/script/api/script_object.hpp
+++ b/src/script/api/script_object.hpp
@@ -13,7 +13,8 @@
#include "../../misc/countedptr.hpp"
#include "../../road_type.h"
#include "../../rail_type.h"
-#include "../../command_type.h"
+#include "../../string_func.h"
+#include "../../command_func.h"
#include "script_types.hpp"
#include "../script_suspend.hpp"
@@ -67,10 +68,32 @@ public:
static class ScriptInstance *GetActiveInstance();
protected:
+ template<Commands TCmd, typename T> struct ScriptDoCommandHelper;
+
/**
- * Executes a raw DoCommand for the script.
+ * Templated wrapper that exposes the command parameter arguments
+ * on the various DoCommand calls.
+ * @tparam Tcmd The command-id to execute.
+ * @tparam Targs The command parameter types.
*/
- static bool DoCommand(TileIndex tile, uint32 p1, uint32 p2, Commands cmd, const char *text = nullptr, Script_SuspendCallbackProc *callback = nullptr);
+ template <Commands Tcmd, typename... Targs>
+ struct ScriptDoCommandHelper<Tcmd, CommandCost(*)(DoCommandFlag, Targs...)> {
+ static bool Do(Script_SuspendCallbackProc *callback, Targs... args)
+ {
+ return Execute(callback, std::forward_as_tuple(args...));
+ }
+
+ static bool Do(Targs... args)
+ {
+ return Execute(nullptr, std::forward_as_tuple(args...));
+ }
+
+ private:
+ static bool Execute(Script_SuspendCallbackProc *callback, std::tuple<Targs...> args);
+ };
+
+ template <Commands Tcmd>
+ using Command = ScriptDoCommandHelper<Tcmd, typename ::CommandTraits<Tcmd>::ProcType>;
/**
* Store the latest command executed by the script.
@@ -299,6 +322,58 @@ private:
* @param story_page_id The new StoryPageID.
*/
static void SetNewStoryPageElementID(StoryPageElementID story_page_element_id);
+
+ /* Helper functions for DoCommand. */
+ static std::tuple<bool, bool, bool> DoCommandPrep();
+ static bool DoCommandProcessResult(const CommandCost &res, Script_SuspendCallbackProc *callback, bool estimate_only);
+ static CommandCallback *GetDoCommandCallback();
};
+namespace ScriptObjectInternal {
+ /** Validate a single string argument coming from network. */
+ template <class T>
+ static inline void SanitizeSingleStringHelper(T &data)
+ {
+ if constexpr (std::is_same_v<std::string, T>) {
+ /* The string must be valid, i.e. not contain special codes. Since some
+ * can be made with GSText, make sure the control codes are removed. */
+ data = ::StrMakeValid(data, SVS_NONE);
+ }
+ }
+
+ /** Helper function to perform validation on command data strings. */
+ template<class Ttuple, size_t... Tindices>
+ static inline void SanitizeStringsHelper(Ttuple &values, std::index_sequence<Tindices...>)
+ {
+ ((SanitizeSingleStringHelper(std::get<Tindices>(values))), ...);
+ }
+}
+
+template <Commands Tcmd, typename... Targs>
+bool ScriptObject::ScriptDoCommandHelper<Tcmd, CommandCost(*)(DoCommandFlag, Targs...)>::Execute(Script_SuspendCallbackProc *callback, std::tuple<Targs...> args)
+{
+ auto [err, estimate_only, networking] = ScriptObject::DoCommandPrep();
+ if (err) return false;
+
+ if ((::GetCommandFlags<Tcmd>() & CMD_STR_CTRL) == 0) {
+ ScriptObjectInternal::SanitizeStringsHelper(args, std::index_sequence_for<Targs...>{});
+ }
+
+ TileIndex tile{};
+ if constexpr (std::is_same_v<TileIndex, std::tuple_element_t<0, decltype(args)>>) {
+ tile = std::get<0>(args);
+ }
+
+ /* Only set p2 when the command does not come from the network. */
+ if ((::GetCommandFlags<Tcmd>() & CMD_CLIENT_ID) != 0 && std::get<2>(args) == 0) std::get<2>(args) = UINT32_MAX;
+
+ /* Store the command for command callback validation. */
+ if (!estimate_only && networking) ScriptObject::SetLastCommand(tile, EndianBufferWriter<CommandDataBuffer>::FromValue(args), Tcmd);
+
+ /* Try to perform the command. */
+ CommandCost res = std::apply(&DoCommandPInternal, std::tuple_cat(std::make_tuple(Tcmd, (StringID)0, networking ? ScriptObject::GetDoCommandCallback() : nullptr, false, estimate_only, false), args));
+
+ return ScriptObject::DoCommandProcessResult(res, callback, estimate_only);
+}
+
#endif /* SCRIPT_OBJECT_HPP */
diff --git a/src/script/api/script_objecttype.cpp b/src/script/api/script_objecttype.cpp
index 27519a664..a4a8ef984 100644
--- a/src/script/api/script_objecttype.cpp
+++ b/src/script/api/script_objecttype.cpp
@@ -13,6 +13,7 @@
#include "script_error.hpp"
#include "script_map.hpp"
+#include "../../object_cmd.h"
#include "../../safeguards.h"
@@ -41,5 +42,5 @@
EnforcePrecondition(false, IsValidObjectType(object_type));
EnforcePrecondition(false, ScriptMap::IsValidTile(tile));
- return ScriptObject::DoCommand(tile, object_type, view, CMD_BUILD_OBJECT);
+ return ScriptObject::Command<CMD_BUILD_OBJECT>::Do(tile, object_type, view, {});
}
diff --git a/src/script/api/script_order.cpp b/src/script/api/script_order.cpp
index ce0ee76de..8faec672f 100644
--- a/src/script/api/script_order.cpp
+++ b/src/script/api/script_order.cpp
@@ -18,6 +18,7 @@
#include "../../depot_base.h"
#include "../../station_base.h"
#include "../../waypoint_base.h"
+#include "../../order_cmd.h"
#include "../../safeguards.h"
@@ -379,7 +380,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
EnforcePrecondition(false, order_position != ORDER_CURRENT && IsConditionalOrder(vehicle_id, order_position));
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, jump_to) && jump_to != ORDER_CURRENT);
- return ScriptObject::DoCommand(0, vehicle_id | (order_position << 20), MOF_COND_DESTINATION | (jump_to << 4), CMD_MODIFY_ORDER);
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, vehicle_id | (order_position << 20), MOF_COND_DESTINATION | (jump_to << 4), {});
}
/* static */ bool ScriptOrder::SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition)
@@ -389,7 +390,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
EnforcePrecondition(false, condition >= OC_LOAD_PERCENTAGE && condition <= OC_REMAINING_LIFETIME);
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
- return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), MOF_COND_VARIABLE | (condition << 4), CMD_MODIFY_ORDER);
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, vehicle_id | (order_pos << 20), MOF_COND_VARIABLE | (condition << 4), {});
}
/* static */ bool ScriptOrder::SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare)
@@ -399,7 +400,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
EnforcePrecondition(false, compare >= CF_EQUALS && compare <= CF_IS_FALSE);
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
- return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), MOF_COND_COMPARATOR | (compare << 4), CMD_MODIFY_ORDER);
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, vehicle_id | (order_pos << 20), MOF_COND_COMPARATOR | (compare << 4), {});
}
/* static */ bool ScriptOrder::SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, int32 value)
@@ -410,7 +411,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
if (GetOrderCondition(vehicle_id, order_position) == OC_MAX_SPEED) value = value * 10 / 16;
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
- return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), MOF_COND_VALUE | (value << 4), CMD_MODIFY_ORDER);
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, vehicle_id | (order_pos << 20), MOF_COND_VALUE | (value << 4), {});
}
/* static */ bool ScriptOrder::SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location)
@@ -425,7 +426,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
uint32 p1 = vehicle_id | (order_pos << 20);
uint32 p2 = MOF_STOP_LOCATION | (stop_location << 4);
- return ScriptObject::DoCommand(0, p1, p2, CMD_MODIFY_ORDER);
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(0, p1, p2, {});
}
/* static */ bool ScriptOrder::SetOrderRefit(VehicleID vehicle_id, OrderPosition order_position, CargoID refit_cargo)
@@ -436,7 +437,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
uint32 p1 = vehicle_id;
uint32 p2 = refit_cargo | ScriptOrderPositionToRealOrderPosition(vehicle_id, ScriptOrder::ResolveOrderPosition(vehicle_id, order_position)) << 16;
- return ScriptObject::DoCommand(0, p1, p2, CMD_ORDER_REFIT);
+ return ScriptObject::Command<CMD_ORDER_REFIT>::Do(0, p1, p2, {});
}
/* static */ bool ScriptOrder::AppendOrder(VehicleID vehicle_id, TileIndex destination, ScriptOrderFlags order_flags)
@@ -506,7 +507,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
order.SetNonStopType((OrderNonStopFlags)GB(order_flags, 0, 2));
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
- return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), order.Pack(), CMD_INSERT_ORDER);
+ return ScriptObject::Command<CMD_INSERT_ORDER>::Do(0, vehicle_id | (order_pos << 20), order.Pack(), {});
}
/* static */ bool ScriptOrder::InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to)
@@ -522,7 +523,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
order.MakeConditional(jump_to);
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
- return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), order.Pack(), CMD_INSERT_ORDER);
+ return ScriptObject::Command<CMD_INSERT_ORDER>::Do(0, vehicle_id | (order_pos << 20), order.Pack(), {});
}
/* static */ bool ScriptOrder::RemoveOrder(VehicleID vehicle_id, OrderPosition order_position)
@@ -532,7 +533,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position);
- return ScriptObject::DoCommand(0, vehicle_id, order_pos, CMD_DELETE_ORDER);
+ return ScriptObject::Command<CMD_DELETE_ORDER>::Do(0, vehicle_id, order_pos, {});
}
/* static */ bool ScriptOrder::SkipToOrder(VehicleID vehicle_id, OrderPosition next_order)
@@ -542,7 +543,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, next_order));
int order_pos = ScriptOrderPositionToRealOrderPosition(vehicle_id, next_order);
- return ScriptObject::DoCommand(0, vehicle_id, order_pos, CMD_SKIP_TO_ORDER);
+ return ScriptObject::Command<CMD_SKIP_TO_ORDER>::Do(0, vehicle_id, order_pos, {});
}
/**
@@ -586,7 +587,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
EnforcePrecondition(false, (order_flags & OF_GOTO_NEAREST_DEPOT) == (current & OF_GOTO_NEAREST_DEPOT));
if ((current & OF_NON_STOP_FLAGS) != (order_flags & OF_NON_STOP_FLAGS)) {
- return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), (order_flags & OF_NON_STOP_FLAGS) << 4 | MOF_NON_STOP, CMD_MODIFY_ORDER, nullptr, &::_DoCommandReturnSetOrderFlags);
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, 0, vehicle_id | (order_pos << 20), (order_flags & OF_NON_STOP_FLAGS) << 4 | MOF_NON_STOP, {});
}
switch (order->GetType()) {
@@ -595,16 +596,16 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
uint data = DA_ALWAYS_GO;
if (order_flags & OF_SERVICE_IF_NEEDED) data = DA_SERVICE;
if (order_flags & OF_STOP_IN_DEPOT) data = DA_STOP;
- return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), (data << 4) | MOF_DEPOT_ACTION, CMD_MODIFY_ORDER, nullptr, &::_DoCommandReturnSetOrderFlags);
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, 0, vehicle_id | (order_pos << 20), (data << 4) | MOF_DEPOT_ACTION, {});
}
break;
case OT_GOTO_STATION:
if ((current & OF_UNLOAD_FLAGS) != (order_flags & OF_UNLOAD_FLAGS)) {
- return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), (order_flags & OF_UNLOAD_FLAGS) << 2 | MOF_UNLOAD, CMD_MODIFY_ORDER, nullptr, &::_DoCommandReturnSetOrderFlags);
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, 0, vehicle_id | (order_pos << 20), (order_flags & OF_UNLOAD_FLAGS) << 2 | MOF_UNLOAD, {});
}
if ((current & OF_LOAD_FLAGS) != (order_flags & OF_LOAD_FLAGS)) {
- return ScriptObject::DoCommand(0, vehicle_id | (order_pos << 20), (order_flags & OF_LOAD_FLAGS) >> 1 | MOF_LOAD, CMD_MODIFY_ORDER, nullptr, &::_DoCommandReturnSetOrderFlags);
+ return ScriptObject::Command<CMD_MODIFY_ORDER>::Do(&::_DoCommandReturnSetOrderFlags, 0, vehicle_id | (order_pos << 20), (order_flags & OF_LOAD_FLAGS) >> 1 | MOF_LOAD, {});
}
break;
@@ -638,7 +639,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
int order_pos_move = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position_move);
int order_pos_target = ScriptOrderPositionToRealOrderPosition(vehicle_id, order_position_target);
- return ScriptObject::DoCommand(0, vehicle_id, order_pos_move | (order_pos_target << 16), CMD_MOVE_ORDER);
+ return ScriptObject::Command<CMD_MOVE_ORDER>::Do(0, vehicle_id, order_pos_move | (order_pos_target << 16), {});
}
/* static */ bool ScriptOrder::CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id)
@@ -646,7 +647,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id));
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(main_vehicle_id));
- return ScriptObject::DoCommand(0, vehicle_id | CO_COPY << 30, main_vehicle_id, CMD_CLONE_ORDER);
+ return ScriptObject::Command<CMD_CLONE_ORDER>::Do(0, vehicle_id | CO_COPY << 30, main_vehicle_id, {});
}
/* static */ bool ScriptOrder::ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id)
@@ -654,14 +655,14 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance)
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id));
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(main_vehicle_id));
- return ScriptObject::DoCommand(0, vehicle_id | CO_SHARE << 30, main_vehicle_id, CMD_CLONE_ORDER);
+ return ScriptObject::Command<CMD_CLONE_ORDER>::Do(0, vehicle_id | CO_SHARE << 30, main_vehicle_id, {});
}
/* static */ bool ScriptOrder::UnshareOrders(VehicleID vehicle_id)
{
EnforcePrecondition(false, ScriptVehicle::IsValidVehicle(vehicle_id));
- return ScriptObject::DoCommand(0, vehicle_id | CO_UNSHARE << 30, 0, CMD_CLONE_ORDER);
+ return ScriptObject::Command<CMD_CLONE_ORDER>::Do(0, vehicle_id | CO_UNSHARE << 30, 0, {});
}
/* static */ uint ScriptOrder::GetOrderDistance(ScriptVehicle::VehicleType vehicle_type, TileIndex origin_tile, TileIndex dest_tile)
diff --git a/src/script/api/script_rail.cpp b/src/script/api/script_rail.cpp
index 8668906c2..ebba16343 100644
--- a/src/script/api/script_rail.cpp
+++ b/src/script/api/script_rail.cpp
@@ -18,6 +18,9 @@
#include "../../newgrf_generic.h"
#include "../../newgrf_station.h"
#include "../../strings_func.h"
+#include "../../rail_cmd.h"
+#include "../../station_cmd.h"
+#include "../../waypoint_cmd.h"
#include "../../safeguards.h"
@@ -113,7 +116,7 @@
EnforcePrecondition(false, ::IsValidTile(end_tile));
EnforcePrecondition(false, IsRailTypeAvailable(convert_to));
- return ScriptObject::DoCommand(start_tile, end_tile, convert_to, CMD_CONVERT_RAIL);
+ return ScriptObject::Command<CMD_CONVERT_RAIL>::Do(start_tile, end_tile, convert_to, {});
}
/* static */ TileIndex ScriptRail::GetRailDepotFrontTile(TileIndex depot)
@@ -141,7 +144,7 @@
uint entrance_dir = (::TileX(tile) == ::TileX(front)) ? (::TileY(tile) < ::TileY(front) ? 1 : 3) : (::TileX(tile) < ::TileX(front) ? 2 : 0);
- return ScriptObject::DoCommand(tile, ScriptObject::GetRailType(), entrance_dir, CMD_BUILD_TRAIN_DEPOT);
+ return ScriptObject::Command<CMD_BUILD_TRAIN_DEPOT>::Do(tile, ScriptObject::GetRailType(), entrance_dir, {});
}
/* static */ bool ScriptRail::BuildRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id)
@@ -157,7 +160,7 @@
uint32 p1 = GetCurrentRailType() | (platform_length << 16) | (num_platforms << 8);
if (direction == RAILTRACK_NW_SE) p1 |= (1 << 6);
if (station_id != ScriptStation::STATION_JOIN_ADJACENT) p1 |= (1 << 24);
- return ScriptObject::DoCommand(tile, p1, (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16, CMD_BUILD_RAIL_STATION);
+ return ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, p1, (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16, {});
}
/* static */ bool ScriptRail::BuildNewGRFRailStation(TileIndex tile, RailTrack direction, uint num_platforms, uint platform_length, StationID station_id, CargoID cargo_id, IndustryType source_industry, IndustryType goal_industry, int distance, bool source_station)
@@ -198,11 +201,11 @@
Debug(grf, 1, "{} returned an invalid station ID for 'AI construction/purchase selection (18)' callback", file->filename);
} else {
/* We might have gotten an usable station spec. Try to build it, but if it fails we'll fall back to the original station. */
- if (ScriptObject::DoCommand(tile, p1, p2 | spec->cls_id | index << 8, CMD_BUILD_RAIL_STATION)) return true;
+ if (ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, p1, p2 | spec->cls_id | index << 8, {})) return true;
}
}
- return ScriptObject::DoCommand(tile, p1, p2, CMD_BUILD_RAIL_STATION);
+ return ScriptObject::Command<CMD_BUILD_RAIL_STATION>::Do(tile, p1, p2, {});
}
/* static */ bool ScriptRail::BuildRailWaypoint(TileIndex tile)
@@ -213,7 +216,7 @@
EnforcePrecondition(false, GetRailTracks(tile) == RAILTRACK_NE_SW || GetRailTracks(tile) == RAILTRACK_NW_SE);
EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType()));
- return ScriptObject::DoCommand(tile, GetCurrentRailType() | (GetRailTracks(tile) == RAILTRACK_NE_SW ? AXIS_X : AXIS_Y) << 6 | 1 << 8 | 1 << 16, STAT_CLASS_WAYP | INVALID_STATION << 16, CMD_BUILD_RAIL_WAYPOINT);
+ return ScriptObject::Command<CMD_BUILD_RAIL_WAYPOINT>::Do(tile, GetCurrentRailType() | (GetRailTracks(tile) == RAILTRACK_NE_SW ? AXIS_X : AXIS_Y) << 6 | 1 << 8 | 1 << 16, STAT_CLASS_WAYP | INVALID_STATION << 16, {});
}
/* static */ bool ScriptRail::RemoveRailWaypointTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail)
@@ -222,7 +225,7 @@
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, ::IsValidTile(tile2));
- return ScriptObject::DoCommand(tile, tile2, keep_rail ? 1 : 0, CMD_REMOVE_FROM_RAIL_WAYPOINT);
+ return ScriptObject::Command<CMD_REMOVE_FROM_RAIL_WAYPOINT>::Do(tile, tile2, keep_rail ? 1 : 0, {});
}
/* static */ bool ScriptRail::RemoveRailStationTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail)
@@ -231,7 +234,7 @@
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, ::IsValidTile(tile2));
- return ScriptObject::DoCommand(tile, tile2, keep_rail ? 1 : 0, CMD_REMOVE_FROM_RAIL_STATION);
+ return ScriptObject::Command<CMD_REMOVE_FROM_RAIL_STATION>::Do(tile, tile2, keep_rail ? 1 : 0, {});
}
/* static */ uint ScriptRail::GetRailTracks(TileIndex tile)
@@ -253,7 +256,7 @@
EnforcePrecondition(false, KillFirstBit((uint)rail_track) == 0);
EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType()));
- return ScriptObject::DoCommand(tile, tile, GetCurrentRailType() | (FindFirstTrack((::TrackBits)rail_track) << 6), CMD_BUILD_RAILROAD_TRACK);
+ return ScriptObject::Command<CMD_BUILD_RAILROAD_TRACK>::Do(tile, tile, GetCurrentRailType() | (FindFirstTrack((::TrackBits)rail_track) << 6), {});
}
/* static */ bool ScriptRail::RemoveRailTrack(TileIndex tile, RailTrack rail_track)
@@ -264,7 +267,7 @@
EnforcePrecondition(false, GetRailTracks(tile) & rail_track);
EnforcePrecondition(false, KillFirstBit((uint)rail_track) == 0);
- return ScriptObject::DoCommand(tile, tile, FindFirstTrack((::TrackBits)rail_track) << 6, CMD_REMOVE_RAILROAD_TRACK);
+ return ScriptObject::Command<CMD_REMOVE_RAILROAD_TRACK>::Do(tile, tile, FindFirstTrack((::TrackBits)rail_track) << 6, {});
}
/* static */ bool ScriptRail::AreTilesConnected(TileIndex from, TileIndex tile, TileIndex to)
@@ -365,7 +368,7 @@ static uint32 SimulateDrag(TileIndex from, TileIndex tile, TileIndex *to)
(::TileY(from) == ::TileY(tile) && ::TileY(tile) == ::TileY(to)));
uint32 p2 = SimulateDrag(from, tile, &to) | 1 << 10 | ScriptRail::GetCurrentRailType();;
- return ScriptObject::DoCommand(tile, to, p2, CMD_BUILD_RAILROAD_TRACK);
+ return ScriptObject::Command<CMD_BUILD_RAILROAD_TRACK>::Do(tile, to, p2, {});
}
/* static */ bool ScriptRail::RemoveRail(TileIndex from, TileIndex tile, TileIndex to)
@@ -382,7 +385,7 @@ static uint32 SimulateDrag(TileIndex from, TileIndex tile, TileIndex *to)
(::TileY(from) == ::TileY(tile) && ::TileY(tile) == ::TileY(to)));
uint32 p2 = SimulateDrag(from, tile, &to);
- return ScriptObject::DoCommand(tile, to, p2, CMD_REMOVE_RAILROAD_TRACK);
+ return ScriptObject::Command<CMD_REMOVE_RAILROAD_TRACK>::Do(tile, to, p2, {});
}
/**
@@ -468,7 +471,7 @@ static bool IsValidSignalType(int signal_type)
}
p1 |= ((signal >= SIGNALTYPE_TWOWAY ? signal ^ SIGNALTYPE_TWOWAY : signal) << 5);
- return ScriptObject::DoCommand(tile, p1, 0, CMD_BUILD_SIGNALS);
+ return ScriptObject::Command<CMD_BUILD_SIGNALS>::Do(tile, p1, 0, {});
}
/* static */ bool ScriptRail::RemoveSignal(TileIndex tile, TileIndex front)
@@ -487,7 +490,7 @@ static bool IsValidSignalType(int signal_type)
}
EnforcePrecondition(false, track != INVALID_TRACK);
- return ScriptObject::DoCommand(tile, track, 0, CMD_REMOVE_SIGNALS);
+ return ScriptObject::Command<CMD_REMOVE_SIGNALS>::Do(tile, track, 0, {});
}
/* static */ Money ScriptRail::GetBuildCost(RailType railtype, BuildType build_type)
diff --git a/src/script/api/script_road.cpp b/src/script/api/script_road.cpp
index e1549b0d7..26cdb5190 100644
--- a/src/script/api/script_road.cpp
+++ b/src/script/api/script_road.cpp
@@ -12,6 +12,9 @@
#include "script_station.hpp"
#include "script_cargo.hpp"
#include "../../station_base.h"
+#include "../../landscape_cmd.h"
+#include "../../road_cmd.h"
+#include "../../station_cmd.h"
#include "../../script/squirrel_helper_type.hpp"
#include "../../safeguards.h"
@@ -126,7 +129,7 @@
EnforcePrecondition(false, ::IsValidTile(end_tile));
EnforcePrecondition(false, IsRoadTypeAvailable(road_type));
- return ScriptObject::DoCommand(start_tile, end_tile, (::RoadType)road_type, CMD_CONVERT_ROAD);
+ return ScriptObject::Command<CMD_CONVERT_ROAD>::Do(start_tile, end_tile, (::RoadType)road_type, {});
}
/* Helper functions for ScriptRoad::CanBuildConnectedRoadParts(). */
@@ -492,7 +495,7 @@ static bool NeighbourHasReachableRoad(::RoadType rt, TileIndex start_tile, DiagD
EnforcePrecondition(false, !one_way || RoadTypeIsRoad(ScriptObject::GetRoadType()));
EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType()));
- return ScriptObject::DoCommand(start, end, (::TileY(start) != ::TileY(end) ? 4 : 0) | (((start < end) == !full) ? 1 : 2) | (ScriptObject::GetRoadType() << 3) | ((one_way ? 1 : 0) << 10) | 1 << 11, CMD_BUILD_LONG_ROAD);
+ return ScriptObject::Command<CMD_BUILD_LONG_ROAD>::Do(start, end, (::TileY(start) != ::TileY(end) ? 4 : 0) | (((start < end) == !full) ? 1 : 2) | (ScriptObject::GetRoadType() << 3) | ((one_way ? 1 : 0) << 10) | 1 << 11, {});
}
/* static */ bool ScriptRoad::BuildRoad(TileIndex start, TileIndex end)
@@ -528,7 +531,7 @@ static bool NeighbourHasReachableRoad(::RoadType rt, TileIndex start_tile, DiagD
uint entrance_dir = (::TileX(tile) == ::TileX(front)) ? (::TileY(tile) < ::TileY(front) ? 1 : 3) : (::TileX(tile) < ::TileX(front) ? 2 : 0);
- return ScriptObject::DoCommand(tile, entrance_dir | (ScriptObject::GetRoadType() << 2), 0, CMD_BUILD_ROAD_DEPOT);
+ return ScriptObject::Command<CMD_BUILD_ROAD_DEPOT>::Do(tile, entrance_dir | (ScriptObject::GetRoadType() << 2), 0, {});
}
/* static */ bool ScriptRoad::_BuildRoadStationInternal(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, bool drive_through, StationID station_id)
@@ -555,7 +558,7 @@ static bool NeighbourHasReachableRoad(::RoadType rt, TileIndex start_tile, DiagD
p2 |= ScriptObject::GetRoadType() << 5;
p2 |= entrance_dir << 3;
p2 |= (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16;
- return ScriptObject::DoCommand(tile, 1 | 1 << 8, p2, CMD_BUILD_ROAD_STOP);
+ return ScriptObject::Command<CMD_BUILD_ROAD_STOP>::Do(tile, 1 | 1 << 8, p2, {});
}
/* static */ bool ScriptRoad::BuildRoadStation(TileIndex tile, TileIndex front, RoadVehicleType road_veh_type, StationID station_id)
@@ -577,7 +580,7 @@ static bool NeighbourHasReachableRoad(::RoadType rt, TileIndex start_tile, DiagD
EnforcePrecondition(false, ::TileX(start) == ::TileX(end) || ::TileY(start) == ::TileY(end));
EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType()));
- return ScriptObject::DoCommand(start, end, (::TileY(start) != ::TileY(end) ? 4 : 0) | (start < end ? 1 : 2) | (ScriptObject::GetRoadType() << 3), CMD_REMOVE_LONG_ROAD);
+ return ScriptObject::Command<CMD_REMOVE_LONG_ROAD>::Do(start, end, (::TileY(start) != ::TileY(end) ? 4 : 0) | (start < end ? 1 : 2) | (ScriptObject::GetRoadType() << 3), {});
}
/* static */ bool ScriptRoad::RemoveRoadFull(TileIndex start, TileIndex end)
@@ -589,7 +592,7 @@ static bool NeighbourHasReachableRoad(::RoadType rt, TileIndex start_tile, DiagD
EnforcePrecondition(false, ::TileX(start) == ::TileX(end) || ::TileY(start) == ::TileY(end));
EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType()));
- return ScriptObject::DoCommand(start, end, (::TileY(start) != ::TileY(end) ? 4 : 0) | (start < end ? 2 : 1) | (ScriptObject::GetRoadType() << 3), CMD_REMOVE_LONG_ROAD);
+ return ScriptObject::Command<CMD_REMOVE_LONG_ROAD>::Do(start, end, (::TileY(start) != ::TileY(end) ? 4 : 0) | (start < end ? 2 : 1) | (ScriptObject::GetRoadType() << 3), {});
}
/* static */ bool ScriptRoad::RemoveRoadDepot(TileIndex tile)
@@ -599,7 +602,7 @@ static bool NeighbourHasReachableRoad(::RoadType rt, TileIndex start_tile, DiagD
EnforcePrecondition(false, IsTileType(tile, MP_ROAD))
EnforcePrecondition(false, GetRoadTileType(tile) == ROAD_TILE_DEPOT);
- return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
+ return ScriptObject::Command<CMD_LANDSCAPE_CLEAR>::Do(tile, 0, 0, {});
}
/* static */ bool ScriptRoad::RemoveRoadStation(TileIndex tile)
@@ -609,7 +612,7 @@ static bool NeighbourHasReachableRoad(::RoadType rt, TileIndex start_tile, DiagD
EnforcePrecondition(false, IsTileType(tile, MP_STATION));
EnforcePrecondition(false, IsRoadStop(tile));
- return ScriptObject::DoCommand(tile, 1 | 1 << 8, GetRoadStopType(tile), CMD_REMOVE_ROAD_STOP);
+ return ScriptObject::Command<CMD_REMOVE_ROAD_STOP>::Do(tile, 1 | 1 << 8, GetRoadStopType(tile), {});
}
/* static */ Money ScriptRoad::GetBuildCost(RoadType roadtype, BuildType build_type)
diff --git a/src/script/api/script_sign.cpp b/src/script/api/script_sign.cpp
index 8908941cf..6062497f0 100644
--- a/src/script/api/script_sign.cpp
+++ b/src/script/api/script_sign.cpp
@@ -15,6 +15,7 @@
#include "../../string_func.h"
#include "../../strings_func.h"
#include "../../tile_map.h"
+#include "../../signs_cmd.h"
#include "../../safeguards.h"
@@ -41,7 +42,7 @@
EnforcePreconditionEncodedText(false, text);
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
- return ScriptObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN, text);
+ return ScriptObject::Command<CMD_RENAME_SIGN>::Do(0, sign_id, 0, text);
}
/* static */ char *ScriptSign::GetName(SignID sign_id)
@@ -63,7 +64,7 @@
/* static */ bool ScriptSign::RemoveSign(SignID sign_id)
{
EnforcePrecondition(false, IsValidSign(sign_id));
- return ScriptObject::DoCommand(0, sign_id, 0, CMD_RENAME_SIGN, "");
+ return ScriptObject::Command<CMD_RENAME_SIGN>::Do(0, sign_id, 0, "");
}
/* static */ SignID ScriptSign::BuildSign(TileIndex location, Text *name)
@@ -76,7 +77,7 @@
EnforcePreconditionEncodedText(INVALID_SIGN, text);
EnforcePreconditionCustomError(INVALID_SIGN, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
- if (!ScriptObject::DoCommand(location, 0, 0, CMD_PLACE_SIGN, text, &ScriptInstance::DoCommandReturnSignID)) return INVALID_SIGN;
+ if (!ScriptObject::Command<CMD_PLACE_SIGN>::Do(&ScriptInstance::DoCommandReturnSignID, location, 0, 0, text)) return INVALID_SIGN;
/* In case of test-mode, we return SignID 0 */
return 0;
diff --git a/src/script/api/script_station.cpp b/src/script/api/script_station.cpp
index a45c19d0d..34e7d8434 100644
--- a/src/script/api/script_station.cpp
+++ b/src/script/api/script_station.cpp
@@ -15,6 +15,7 @@
#include "../../station_base.h"
#include "../../roadstop_base.h"
#include "../../town.h"
+#include "../../station_cmd.h"
#include "../../safeguards.h"
@@ -239,5 +240,5 @@ template<bool Tfrom, bool Tvia>
EnforcePrecondition(false, IsValidStation(station_id));
EnforcePrecondition(false, HasStationType(station_id, STATION_AIRPORT));
- return ScriptObject::DoCommand(0, station_id, 0, CMD_OPEN_CLOSE_AIRPORT);
+ return ScriptObject::Command<CMD_OPEN_CLOSE_AIRPORT>::Do(0, station_id, 0, {});
}
diff --git a/src/script/api/script_story_page.cpp b/src/script/api/script_story_page.cpp
index 4ee90e218..afa259041 100644
--- a/src/script/api/script_story_page.cpp
+++ b/src/script/api/script_story_page.cpp
@@ -19,6 +19,7 @@
#include "../../goal_base.h"
#include "../../string_func.h"
#include "../../tile_map.h"
+#include "../../story_cmd.h"
#include "../../safeguards.h"
@@ -47,12 +48,11 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
uint8 c = company;
if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
- if (!ScriptObject::DoCommand(0,
+ if (!ScriptObject::Command<CMD_CREATE_STORY_PAGE>::Do(&ScriptInstance::DoCommandReturnStoryPageID,
+ 0,
c,
0,
- CMD_CREATE_STORY_PAGE,
- title != nullptr? title->GetEncodedText() : nullptr,
- &ScriptInstance::DoCommandReturnStoryPageID)) return STORY_PAGE_INVALID;
+ title != nullptr ? std::string{ title->GetEncodedText() } : std::string{})) return STORY_PAGE_INVALID;
/* In case of test-mode, we return StoryPageID 0 */
return (ScriptStoryPage::StoryPageID)0;
@@ -89,12 +89,11 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
NOT_REACHED();
}
- if (!ScriptObject::DoCommand(reftile,
+ if (!ScriptObject::Command<CMD_CREATE_STORY_PAGE_ELEMENT>::Do(&ScriptInstance::DoCommandReturnStoryPageElementID,
+ reftile,
story_page_id + (type << 16),
refid,
- CMD_CREATE_STORY_PAGE_ELEMENT,
- StoryPageElementTypeRequiresText(btype) ? text->GetEncodedText() : nullptr,
- &ScriptInstance::DoCommandReturnStoryPageElementID)) return STORY_PAGE_ELEMENT_INVALID;
+ StoryPageElementTypeRequiresText(btype) ? std::string{ text->GetEncodedText() } : std::string{})) return STORY_PAGE_ELEMENT_INVALID;
/* In case of test-mode, we return StoryPageElementID 0 */
return (ScriptStoryPage::StoryPageElementID)0;
@@ -134,11 +133,10 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
NOT_REACHED();
}
- return ScriptObject::DoCommand(reftile,
+ return ScriptObject::Command<CMD_UPDATE_STORY_PAGE_ELEMENT>::Do(reftile,
story_page_element_id,
refid,
- CMD_UPDATE_STORY_PAGE_ELEMENT,
- StoryPageElementTypeRequiresText(type) ? text->GetEncodedText() : nullptr);
+ StoryPageElementTypeRequiresText(type) ? std::string{ text->GetEncodedText() } : std::string{});
}
/* static */ uint32 ScriptStoryPage::GetPageSortValue(StoryPageID story_page_id)
@@ -162,7 +160,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
EnforcePrecondition(false, IsValidStoryPage(story_page_id));
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
- return ScriptObject::DoCommand(0, story_page_id, 0, CMD_SET_STORY_PAGE_TITLE, title != nullptr? title->GetEncodedText() : nullptr);
+ return ScriptObject::Command<CMD_SET_STORY_PAGE_TITLE>::Do(0, story_page_id, 0, title != nullptr ? std::string{ title->GetEncodedText() } : std::string{});
}
/* static */ ScriptCompany::CompanyID ScriptStoryPage::GetCompany(StoryPageID story_page_id)
@@ -188,7 +186,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
EnforcePrecondition(false, IsValidStoryPage(story_page_id));
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
- return ScriptObject::DoCommand(0, story_page_id, date, CMD_SET_STORY_PAGE_DATE, nullptr);
+ return ScriptObject::Command<CMD_SET_STORY_PAGE_DATE>::Do(0, story_page_id, date, {});
}
@@ -197,7 +195,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
EnforcePrecondition(false, IsValidStoryPage(story_page_id));
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
- return ScriptObject::DoCommand(0, story_page_id, 0, CMD_SHOW_STORY_PAGE);
+ return ScriptObject::Command<CMD_SHOW_STORY_PAGE>::Do(0, story_page_id, 0, {});
}
/* static */ bool ScriptStoryPage::Remove(StoryPageID story_page_id)
@@ -205,7 +203,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
EnforcePrecondition(false, IsValidStoryPage(story_page_id));
- return ScriptObject::DoCommand(0, story_page_id, 0, CMD_REMOVE_STORY_PAGE);
+ return ScriptObject::Command<CMD_REMOVE_STORY_PAGE>::Do(0, story_page_id, 0, {});
}
/* static */ bool ScriptStoryPage::RemoveElement(StoryPageElementID story_page_element_id)
@@ -213,7 +211,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
EnforcePrecondition(false, IsValidStoryPageElement(story_page_element_id));
- return ScriptObject::DoCommand(0, story_page_element_id, 0, CMD_REMOVE_STORY_PAGE_ELEMENT);
+ return ScriptObject::Command<CMD_REMOVE_STORY_PAGE_ELEMENT>::Do(0, story_page_element_id, 0, {});
}
/* static */ ScriptStoryPage::StoryPageButtonFormatting ScriptStoryPage::MakePushButtonReference(StoryPageButtonColour colour, StoryPageButtonFlags flags)
diff --git a/src/script/api/script_subsidy.cpp b/src/script/api/script_subsidy.cpp
index c8ca6e3e3..32962d158 100644
--- a/src/script/api/script_subsidy.cpp
+++ b/src/script/api/script_subsidy.cpp
@@ -15,6 +15,7 @@
#include "script_error.hpp"
#include "../../subsidy_base.h"
#include "../../station_base.h"
+#include "../../subsidy_cmd.h"
#include "../../safeguards.h"
@@ -38,7 +39,7 @@
EnforcePrecondition(false, (from_type == SPT_INDUSTRY && ScriptIndustry::IsValidIndustry(from_id)) || (from_type == SPT_TOWN && ScriptTown::IsValidTown(from_id)));
EnforcePrecondition(false, (to_type == SPT_INDUSTRY && ScriptIndustry::IsValidIndustry(to_id)) || (to_type == SPT_TOWN && ScriptTown::IsValidTown(to_id)));
- return ScriptObject::DoCommand(0, from_type | (from_id << 8) | (cargo_type << 24), to_type | (to_id << 8), CMD_CREATE_SUBSIDY);
+ return ScriptObject::Command<CMD_CREATE_SUBSIDY>::Do(0, from_type | (from_id << 8) | (cargo_type << 24), to_type | (to_id << 8), {});
}
/* static */ ScriptCompany::CompanyID ScriptSubsidy::GetAwardedTo(SubsidyID subsidy_id)
diff --git a/src/script/api/script_tile.cpp b/src/script/api/script_tile.cpp
index 90411a7f7..9e67b074a 100644
--- a/src/script/api/script_tile.cpp
+++ b/src/script/api/script_tile.cpp
@@ -17,6 +17,9 @@
#include "../../tree_map.h"
#include "../../town.h"
#include "../../landscape.h"
+#include "../../landscape_cmd.h"
+#include "../../terraform_cmd.h"
+#include "../../tree_cmd.h"
#include "../../safeguards.h"
@@ -252,7 +255,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, tile < ::MapSize());
- return ScriptObject::DoCommand(tile, slope, 1, CMD_TERRAFORM_LAND);
+ return ScriptObject::Command<CMD_TERRAFORM_LAND>::Do(tile, slope, 1, {});
}
/* static */ bool ScriptTile::LowerTile(TileIndex tile, int32 slope)
@@ -260,7 +263,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, tile < ::MapSize());
- return ScriptObject::DoCommand(tile, slope, 0, CMD_TERRAFORM_LAND);
+ return ScriptObject::Command<CMD_TERRAFORM_LAND>::Do(tile, slope, 0, {});
}
/* static */ bool ScriptTile::LevelTiles(TileIndex start_tile, TileIndex end_tile)
@@ -269,14 +272,14 @@
EnforcePrecondition(false, start_tile < ::MapSize());
EnforcePrecondition(false, end_tile < ::MapSize());
- return ScriptObject::DoCommand(end_tile, start_tile, LM_LEVEL << 1, CMD_LEVEL_LAND);
+ return ScriptObject::Command<CMD_LEVEL_LAND>::Do(end_tile, start_tile, LM_LEVEL << 1, {});
}
/* static */ bool ScriptTile::DemolishTile(TileIndex tile)
{
EnforcePrecondition(false, ::IsValidTile(tile));
- return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
+ return ScriptObject::Command<CMD_LANDSCAPE_CLEAR>::Do(tile, 0, 0, {});
}
/* static */ bool ScriptTile::PlantTree(TileIndex tile)
@@ -284,7 +287,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, ::IsValidTile(tile));
- return ScriptObject::DoCommand(tile, TREE_INVALID, tile, CMD_PLANT_TREE);
+ return ScriptObject::Command<CMD_PLANT_TREE>::Do(tile, TREE_INVALID, tile, {});
}
/* static */ bool ScriptTile::PlantTreeRectangle(TileIndex tile, uint width, uint height)
@@ -295,7 +298,7 @@
EnforcePrecondition(false, height >= 1 && height <= 20);
TileIndex end_tile = tile + ::TileDiffXY(width - 1, height - 1);
- return ScriptObject::DoCommand(tile, TREE_INVALID, end_tile, CMD_PLANT_TREE);
+ return ScriptObject::Command<CMD_PLANT_TREE>::Do(tile, TREE_INVALID, end_tile, {});
}
/* static */ bool ScriptTile::IsWithinTownInfluence(TileIndex tile, TownID town_id)
diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp
index 161cf74fd..e3fb26e89 100644
--- a/src/script/api/script_town.cpp
+++ b/src/script/api/script_town.cpp
@@ -17,6 +17,7 @@
#include "../../strings_func.h"
#include "../../station_base.h"
#include "../../landscape.h"
+#include "../../town_cmd.h"
#include "table/strings.h"
#include "../../safeguards.h"
@@ -51,7 +52,7 @@
}
EnforcePrecondition(false, IsValidTown(town_id));
- return ScriptObject::DoCommand(0, town_id, 0, CMD_RENAME_TOWN, text);
+ return ScriptObject::Command<CMD_RENAME_TOWN>::Do(0, town_id, 0, text != nullptr ? std::string{ text } : std::string{});
}
/* static */ bool ScriptTown::SetText(TownID town_id, Text *text)
@@ -65,7 +66,7 @@
}
EnforcePrecondition(false, IsValidTown(town_id));
- return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, 0, CMD_TOWN_SET_TEXT, encoded_text);
+ return ScriptObject::Command<CMD_TOWN_SET_TEXT>::Do(::Town::Get(town_id)->xy, town_id, 0, encoded_text != nullptr ? std::string{ encoded_text } : std::string{});
}
/* static */ int32 ScriptTown::GetPopulation(TownID town_id)
@@ -133,7 +134,7 @@
EnforcePrecondition(false, IsValidTown(town_id));
EnforcePrecondition(false, ScriptCargo::IsValidTownEffect(towneffect_id));
- return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id | (towneffect_id << 16), goal, CMD_TOWN_CARGO_GOAL);
+ return ScriptObject::Command<CMD_TOWN_CARGO_GOAL>::Do(::Town::Get(town_id)->xy, town_id | (towneffect_id << 16), goal, {});
}
/* static */ uint32 ScriptTown::GetCargoGoal(TownID town_id, ScriptCargo::TownEffect towneffect_id)
@@ -176,7 +177,7 @@
break;
}
- return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, growth_rate, CMD_TOWN_GROWTH_RATE);
+ return ScriptObject::Command<CMD_TOWN_GROWTH_RATE>::Do(::Town::Get(town_id)->xy, town_id, growth_rate, {});
}
/* static */ int32 ScriptTown::GetGrowthRate(TownID town_id)
@@ -266,7 +267,7 @@
EnforcePrecondition(false, IsValidTown(town_id));
EnforcePrecondition(false, IsActionAvailable(town_id, town_action));
- return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, town_action, CMD_DO_TOWN_ACTION);
+ return ScriptObject::Command<CMD_DO_TOWN_ACTION>::Do(::Town::Get(town_id)->xy, town_id, town_action, {});
}
/* static */ bool ScriptTown::ExpandTown(TownID town_id, int houses)
@@ -275,7 +276,7 @@
EnforcePrecondition(false, IsValidTown(town_id));
EnforcePrecondition(false, houses > 0);
- return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, houses, CMD_EXPAND_TOWN);
+ return ScriptObject::Command<CMD_EXPAND_TOWN>::Do(::Town::Get(town_id)->xy, town_id, houses, {});
}
/* static */ bool ScriptTown::FoundTown(TileIndex tile, TownSize size, bool city, RoadLayout layout, Text *name)
@@ -305,7 +306,7 @@
return false;
}
- return ScriptObject::DoCommand(tile, size | (city ? 1 << 2 : 0) | layout << 3, townnameparts, CMD_FOUND_TOWN, text);
+ return ScriptObject::Command<CMD_FOUND_TOWN>::Do(tile, size | (city ? 1 << 2 : 0) | layout << 3, townnameparts, text != nullptr ? std::string{ text } : std::string{});
}
/* static */ ScriptTown::TownRating ScriptTown::GetRating(TownID town_id, ScriptCompany::CompanyID company_id)
@@ -360,7 +361,7 @@
uint16 p2 = 0;
memcpy(&p2, &new_rating, sizeof(p2));
- return ScriptObject::DoCommand(0, town_id | (company_id << 16), p2, CMD_TOWN_RATING);
+ return ScriptObject::Command<CMD_TOWN_RATING>::Do(0, town_id | (company_id << 16), p2, {});
}
/* static */ int ScriptTown::GetAllowedNoise(TownID town_id)
diff --git a/src/script/api/script_tunnel.cpp b/src/script/api/script_tunnel.cpp
index c47c64e40..ea9cbc518 100644
--- a/src/script/api/script_tunnel.cpp
+++ b/src/script/api/script_tunnel.cpp
@@ -12,6 +12,9 @@
#include "script_rail.hpp"
#include "../script_instance.hpp"
#include "../../tunnel_map.h"
+#include "../../landscape_cmd.h"
+#include "../../road_cmd.h"
+#include "../../tunnelbridge_cmd.h"
#include "../../safeguards.h"
@@ -96,11 +99,11 @@ static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance)
/* For rail we do nothing special */
if (vehicle_type == ScriptVehicle::VT_RAIL) {
- return ScriptObject::DoCommand(start, type, 0, CMD_BUILD_TUNNEL);
+ return ScriptObject::Command<CMD_BUILD_TUNNEL>::Do(start, type, 0, {});
}
ScriptObject::SetCallbackVariable(0, start);
- return ScriptObject::DoCommand(start, type, 0, CMD_BUILD_TUNNEL, nullptr, &::_DoCommandReturnBuildTunnel1);
+ return ScriptObject::Command<CMD_BUILD_TUNNEL>::Do(&::_DoCommandReturnBuildTunnel1, start, type, 0, {});
}
/* static */ bool ScriptTunnel::_BuildTunnelRoad1()
@@ -112,7 +115,7 @@ static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance)
DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start);
DiagDirection dir_2 = ::ReverseDiagDir(dir_1);
- return ScriptObject::DoCommand(start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2) | (ScriptObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD, nullptr, &::_DoCommandReturnBuildTunnel2);
+ return ScriptObject::Command<CMD_BUILD_ROAD>::Do(&::_DoCommandReturnBuildTunnel2, start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2) | (ScriptObject::GetRoadType() << 4), 0, {});
}
/* static */ bool ScriptTunnel::_BuildTunnelRoad2()
@@ -124,7 +127,7 @@ static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance)
DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start);
DiagDirection dir_2 = ::ReverseDiagDir(dir_1);
- return ScriptObject::DoCommand(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1) | (ScriptObject::GetRoadType() << 4), 0, CMD_BUILD_ROAD);
+ return ScriptObject::Command<CMD_BUILD_ROAD>::Do(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1) | (ScriptObject::GetRoadType() << 4), 0, {});
}
/* static */ bool ScriptTunnel::RemoveTunnel(TileIndex tile)
@@ -132,5 +135,5 @@ static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance)
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, IsTunnelTile(tile));
- return ScriptObject::DoCommand(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
+ return ScriptObject::Command<CMD_LANDSCAPE_CLEAR>::Do(tile, 0, 0, {});
}
diff --git a/src/script/api/script_vehicle.cpp b/src/script/api/script_vehicle.cpp
index a06261618..d245f4132 100644
--- a/src/script/api/script_vehicle.cpp
+++ b/src/script/api/script_vehicle.cpp
@@ -20,6 +20,8 @@
#include "../../train.h"
#include "../../vehicle_func.h"
#include "../../aircraft.h"
+#include "../../roadveh_cmd.h"
+#include "../../train_cmd.h"
#include "../../vehicle_cmd.h"
#include "table/strings.h"
@@ -70,7 +72,7 @@
EnforcePreconditionCustomError(VEHICLE_INVALID, !ScriptGameSettings::IsDisabledVehicleType((ScriptVehicle::VehicleType)type), ScriptVehicle::ERR_VEHICLE_BUILD_DISABLED);
- if (!ScriptObject::DoCommand(depot, engine_id | (cargo << 24), 0, CMD_BUILD_VEHICLE, nullptr, &ScriptInstance::DoCommandReturnVehicleID)) return VEHICLE_INVALID;
+ if (!ScriptObject::Command<CMD_BUILD_VEHICLE>::Do(&ScriptInstance::DoCommandReturnVehicleID, depot, engine_id | (cargo << 24), 0, {})) return VEHICLE_INVALID;
/* In case of test-mode, we return VehicleID 0 */
return 0;
@@ -101,7 +103,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
- if (!ScriptObject::DoCommand(depot, vehicle_id, share_orders, CMD_CLONE_VEHICLE, nullptr, &ScriptInstance::DoCommandReturnVehicleID)) return VEHICLE_INVALID;
+ if (!ScriptObject::Command<CMD_CLONE_VEHICLE>::Do(&ScriptInstance::DoCommandReturnVehicleID, depot, vehicle_id, share_orders, {})) return VEHICLE_INVALID;
/* In case of test-mode, we return VehicleID 0 */
return 0;
@@ -123,7 +125,7 @@
while (dest_wagon-- > 0) w = w->GetNextUnit();
}
- return ScriptObject::DoCommand(0, v->index | (move_attached_wagons ? 1 : 0) << 20, w == nullptr ? ::INVALID_VEHICLE : w->index, CMD_MOVE_RAIL_VEHICLE);
+ return ScriptObject::Command<CMD_MOVE_RAIL_VEHICLE>::Do(0, v->index | (move_attached_wagons ? 1 : 0) << 20, w == nullptr ? ::INVALID_VEHICLE : w->index, {});
}
/* static */ bool ScriptVehicle::MoveWagon(VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon)
@@ -150,7 +152,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, IsValidVehicle(vehicle_id) && ScriptCargo::IsValidCargo(cargo));
- return ScriptObject::DoCommand(0, vehicle_id, cargo, CMD_REFIT_VEHICLE);
+ return ScriptObject::Command<CMD_REFIT_VEHICLE>::Do(0, vehicle_id, cargo, {});
}
@@ -160,7 +162,7 @@
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
const Vehicle *v = ::Vehicle::Get(vehicle_id);
- return ScriptObject::DoCommand(0, vehicle_id | (v->type == VEH_TRAIN ? 1 : 0) << 20, 0, CMD_SELL_VEHICLE);
+ return ScriptObject::Command<CMD_SELL_VEHICLE>::Do(0, vehicle_id | (v->type == VEH_TRAIN ? 1 : 0) << 20, 0, {});
}
/* static */ bool ScriptVehicle::_SellWagonInternal(VehicleID vehicle_id, int wagon, bool sell_attached_wagons)
@@ -172,7 +174,7 @@
const Train *v = ::Train::Get(vehicle_id);
while (wagon-- > 0) v = v->GetNextUnit();
- return ScriptObject::DoCommand(0, v->index | (sell_attached_wagons ? 1 : 0) << 20, 0, CMD_SELL_VEHICLE);
+ return ScriptObject::Command<CMD_SELL_VEHICLE>::Do(0, v->index | (sell_attached_wagons ? 1 : 0) << 20, 0, {});
}
/* static */ bool ScriptVehicle::SellWagon(VehicleID vehicle_id, int wagon)
@@ -190,7 +192,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
- return ScriptObject::DoCommand(0, vehicle_id, 0, CMD_SEND_VEHICLE_TO_DEPOT);
+ return ScriptObject::Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(0, vehicle_id, 0, {});
}
/* static */ bool ScriptVehicle::SendVehicleToDepotForServicing(VehicleID vehicle_id)
@@ -198,7 +200,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
- return ScriptObject::DoCommand(0, vehicle_id | DEPOT_SERVICE, 0, CMD_SEND_VEHICLE_TO_DEPOT);
+ return ScriptObject::Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(0, vehicle_id | DEPOT_SERVICE, 0, {});
}
/* static */ bool ScriptVehicle::IsInDepot(VehicleID vehicle_id)
@@ -218,7 +220,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() != OWNER_DEITY);
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
- return ScriptObject::DoCommand(0, vehicle_id, 0, CMD_START_STOP_VEHICLE);
+ return ScriptObject::Command<CMD_START_STOP_VEHICLE>::Do(0, vehicle_id, 0, {});
}
/* static */ bool ScriptVehicle::ReverseVehicle(VehicleID vehicle_id)
@@ -228,8 +230,8 @@
EnforcePrecondition(false, ::Vehicle::Get(vehicle_id)->type == VEH_ROAD || ::Vehicle::Get(vehicle_id)->type == VEH_TRAIN);
switch (::Vehicle::Get(vehicle_id)->type) {
- case VEH_ROAD: return ScriptObject::DoCommand(0, vehicle_id, 0, CMD_TURN_ROADVEH);
- case VEH_TRAIN: return ScriptObject::DoCommand(0, vehicle_id, 0, CMD_REVERSE_TRAIN_DIRECTION);
+ case VEH_ROAD: return ScriptObject::Command<CMD_TURN_ROADVEH>::Do(0, vehicle_id, 0, {});
+ case VEH_TRAIN: return ScriptObject::Command<CMD_REVERSE_TRAIN_DIRECTION>::Do(0, vehicle_id, 0, {});
default: NOT_REACHED();
}
}
@@ -245,7 +247,7 @@
EnforcePreconditionEncodedText(false, text);
EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_VEHICLE_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG);
- return ScriptObject::DoCommand(0, vehicle_id, 0, CMD_RENAME_VEHICLE, text);
+ return ScriptObject::Command<CMD_RENAME_VEHICLE>::Do(0, vehicle_id, 0, text);
}
/* static */ TileIndex ScriptVehicle::GetLocation(VehicleID vehicle_id)
diff --git a/src/script/api/script_viewport.cpp b/src/script/api/script_viewport.cpp
index 275ab3346..7d57bffb3 100644
--- a/src/script/api/script_viewport.cpp
+++ b/src/script/api/script_viewport.cpp
@@ -14,6 +14,7 @@
#include "script_map.hpp"
#include "../script_instance.hpp"
#include "../../viewport_func.h"
+#include "../../viewport_cmd.h"
#include "../../safeguards.h"
@@ -30,7 +31,7 @@
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
EnforcePrecondition(false, ScriptMap::IsValidTile(tile));
- return ScriptObject::DoCommand(tile, VST_EVERYONE, 0, CMD_SCROLL_VIEWPORT);
+ return ScriptObject::Command<CMD_SCROLL_VIEWPORT>::Do(tile, VST_EVERYONE, 0, {});
}
/* static */ bool ScriptViewport::ScrollCompanyClientsTo(ScriptCompany::CompanyID company, TileIndex tile)
@@ -41,7 +42,7 @@
company = ScriptCompany::ResolveCompanyID(company);
EnforcePrecondition(false, company != ScriptCompany::COMPANY_INVALID);
- return ScriptObject::DoCommand(tile, VST_COMPANY, company, CMD_SCROLL_VIEWPORT);
+ return ScriptObject::Command<CMD_SCROLL_VIEWPORT>::Do(tile, VST_COMPANY, company, {});
}
/* static */ bool ScriptViewport::ScrollClientTo(ScriptClient::ClientID client, TileIndex tile)
@@ -53,5 +54,5 @@
client = ScriptClient::ResolveClientID(client);
EnforcePrecondition(false, client != ScriptClient::CLIENT_INVALID);
- return ScriptObject::DoCommand(tile, VST_CLIENT, client, CMD_SCROLL_VIEWPORT);
+ return ScriptObject::Command<CMD_SCROLL_VIEWPORT>::Do(tile, VST_CLIENT, client, {});
}