summaryrefslogtreecommitdiff
path: root/src/script/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/api')
-rw-r--r--src/script/api/game/game_viewport.hpp.sq5
-rw-r--r--src/script/api/game_changelog.hpp3
-rw-r--r--src/script/api/script_viewport.cpp33
-rw-r--r--src/script/api/script_viewport.hpp34
4 files changed, 74 insertions, 1 deletions
diff --git a/src/script/api/game/game_viewport.hpp.sq b/src/script/api/game/game_viewport.hpp.sq
index d313f0d75..357357ae3 100644
--- a/src/script/api/game/game_viewport.hpp.sq
+++ b/src/script/api/game/game_viewport.hpp.sq
@@ -21,7 +21,10 @@ void SQGSViewport_Register(Squirrel *engine)
SQGSViewport.PreRegister(engine);
SQGSViewport.AddConstructor<void (ScriptViewport::*)(), 1>(engine, "x");
- SQGSViewport.DefSQStaticMethod(engine, &ScriptViewport::ScrollTo, "ScrollTo", 2, ".i");
+ SQGSViewport.DefSQStaticMethod(engine, &ScriptViewport::ScrollTo, "ScrollTo", 2, ".i");
+ SQGSViewport.DefSQStaticMethod(engine, &ScriptViewport::ScrollEveryoneTo, "ScrollEveryoneTo", 2, ".i");
+ SQGSViewport.DefSQStaticMethod(engine, &ScriptViewport::ScrollCompanyClientsTo, "ScrollCompanyClientsTo", 3, ".ii");
+ SQGSViewport.DefSQStaticMethod(engine, &ScriptViewport::ScrollClientTo, "ScrollClientTo", 3, ".ii");
SQGSViewport.PostRegister(engine);
}
diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp
index 776dd892e..5f278e4f0 100644
--- a/src/script/api/game_changelog.hpp
+++ b/src/script/api/game_changelog.hpp
@@ -22,6 +22,9 @@
* \li GSClient
* \li GSClientList
* \li GSClientList_Company
+ * \li GSViewport::ScrollEveryoneTo
+ * \li GSViewport::ScrollCompanyClientsTo
+ * \li GSViewport::ScrollClientTo
*
* \b 1.8.0
*
diff --git a/src/script/api/script_viewport.cpp b/src/script/api/script_viewport.cpp
index 737e7e68d..bed3ba992 100644
--- a/src/script/api/script_viewport.cpp
+++ b/src/script/api/script_viewport.cpp
@@ -10,9 +10,11 @@
/** @file script_viewport.cpp Implementation of ScriptViewport. */
#include "../../stdafx.h"
+#include "script_error.hpp"
#include "script_viewport.hpp"
#include "script_game.hpp"
#include "script_map.hpp"
+#include "../script_instance.hpp"
#include "../../viewport_func.h"
#include "../../safeguards.h"
@@ -24,3 +26,34 @@
ScrollMainWindowToTile(tile);
}
+
+/* static */ bool ScriptViewport::ScrollEveryoneTo(TileIndex tile)
+{
+ EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
+ EnforcePrecondition(false, ScriptMap::IsValidTile(tile));
+
+ return ScriptObject::DoCommand(tile, VST_EVERYONE, 0, CMD_SCROLL_VIEWPORT);
+}
+
+/* static */ bool ScriptViewport::ScrollCompanyClientsTo(ScriptCompany::CompanyID company, TileIndex tile)
+{
+ EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
+ EnforcePrecondition(false, ScriptMap::IsValidTile(tile));
+
+ company = ScriptCompany::ResolveCompanyID(company);
+ EnforcePrecondition(false, company != ScriptCompany::COMPANY_INVALID);
+
+ return ScriptObject::DoCommand(tile, VST_COMPANY, company, CMD_SCROLL_VIEWPORT);
+}
+
+/* static */ bool ScriptViewport::ScrollClientTo(ScriptClient::ClientID client, TileIndex tile)
+{
+ EnforcePrecondition(false, ScriptGame::IsMultiplayer());
+ EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
+ EnforcePrecondition(false, ScriptMap::IsValidTile(tile));
+
+ client = ScriptClient::ResolveClientID(client);
+ EnforcePrecondition(false, client != ScriptClient::CLIENT_INVALID);
+
+ return ScriptObject::DoCommand(tile, VST_CLIENT, client, CMD_SCROLL_VIEWPORT);
+}
diff --git a/src/script/api/script_viewport.hpp b/src/script/api/script_viewport.hpp
index 542b58095..cae1a5930 100644
--- a/src/script/api/script_viewport.hpp
+++ b/src/script/api/script_viewport.hpp
@@ -13,6 +13,8 @@
#define SCRIPT_VIEWPORT_HPP
#include "script_object.hpp"
+#include "script_client.hpp"
+#include "script_company.hpp"
/**
* Class that manipulates the user's viewport.
@@ -28,6 +30,38 @@ public:
* @pre ScriptMap::IsValidTile(tile).
*/
static void ScrollTo(TileIndex tile);
+
+ /**
+ * Scroll the viewport of all players to the given tile,
+ * where the tile will be in the center of the screen.
+ * @param tile The tile to put in the center of the screen.
+ * @pre ScriptObject::GetCompany() == OWNER_DEITY
+ * @pre ScriptMap::IsValidTile(tile)
+ */
+ static bool ScrollEveryoneTo(TileIndex tile);
+
+ /**
+ * Scroll the viewports of all players in the company to the given tile,
+ * where the tile will be in the center of the screen.
+ * @param company The company which players to scroll the viewport of.
+ * @param tile The tile to put in the center of the screen.
+ * @pre ScriptObject::GetCompany() == OWNER_DEITY
+ * @pre ScriptMap::IsValidTile(tile)
+ * @pre ResolveCompanyID(company) != COMPANY_INVALID
+ */
+ static bool ScrollCompanyClientsTo(ScriptCompany::CompanyID company, TileIndex tile);
+
+ /**
+ * Scroll the viewport of the client to the given tile,
+ * where the tile will be in the center of the screen.
+ * @param client The client to scroll the viewport of.
+ * @param tile The tile to put in the center of the screen.
+ * @pre ScriptGame::IsMultiplayer()
+ * @pre ScriptObject::GetCompany() == OWNER_DEITY
+ * @pre ScriptMap::IsValidTile(tile)
+ * @pre ResolveClientID(client) != CLIENT_INVALID
+ */
+ static bool ScrollClientTo(ScriptClient::ClientID client, TileIndex tile);
};
#endif /* SCRIPT_ADMIN_HPP */