summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/command.cpp2
-rw-r--r--src/command_type.h2
-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
-rw-r--r--src/viewport.cpp40
-rw-r--r--src/viewport_type.h10
8 files changed, 128 insertions, 1 deletions
diff --git a/src/command.cpp b/src/command.cpp
index 959610cd2..df0cd004c 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -167,6 +167,7 @@ CommandProc CmdSetStoryPageDate;
CommandProc CmdShowStoryPage;
CommandProc CmdRemoveStoryPage;
CommandProc CmdRemoveStoryPageElement;
+CommandProc CmdScrollViewport;
CommandProc CmdLevelLand;
@@ -322,6 +323,7 @@ static const Command _command_proc_table[] = {
DEF_CMD(CmdShowStoryPage, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_SHOW_STORY_PAGE
DEF_CMD(CmdRemoveStoryPage, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_REMOVE_STORY_PAGE
DEF_CMD(CmdRemoveStoryPageElement, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_REMOVE_STORY_ELEMENT_PAGE
+ DEF_CMD(CmdScrollViewport, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_SCROLL_VIEWPORT
DEF_CMD(CmdLevelLand, CMD_ALL_TILES | CMD_NO_TEST | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_LEVEL_LAND; test run might clear tiles multiple times, in execution that only happens once
diff --git a/src/command_type.h b/src/command_type.h
index f318216ac..0a2fde297 100644
--- a/src/command_type.h
+++ b/src/command_type.h
@@ -293,6 +293,8 @@ enum Commands {
CMD_SHOW_STORY_PAGE, ///< show a story page
CMD_REMOVE_STORY_PAGE, ///< remove a story page
CMD_REMOVE_STORY_PAGE_ELEMENT, ///< remove a story page element
+ CMD_SCROLL_VIEWPORT, ///< scroll main viewport of players
+
CMD_LEVEL_LAND, ///< level land
CMD_BUILD_LOCK, ///< build a lock
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 */
diff --git a/src/viewport.cpp b/src/viewport.cpp
index df431ff3c..6de827b4e 100644
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -84,6 +84,9 @@
#include "linkgraph/linkgraph_gui.h"
#include "viewport_sprite_sorter.h"
#include "bridge_map.h"
+#include "company_base.h"
+#include "command_func.h"
+#include "network/network_func.h"
#include <map>
@@ -3250,3 +3253,40 @@ void InitializeSpriteSorter()
}
assert(_vp_sprite_sorter != NULL);
}
+
+/**
+ * Scroll players main viewport.
+ * @param tile tile to center viewport on
+ * @param flags type of operation
+ * @param p1 ViewportScrollTarget of scroll target
+ * @param p2 company or client id depending on the target
+ * @param text unused
+ * @return the cost of this operation or an error
+ */
+CommandCost CmdScrollViewport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
+{
+ if (_current_company != OWNER_DEITY) return CMD_ERROR;
+ ViewportScrollTarget target = (ViewportScrollTarget)p1;
+ switch (target) {
+ case VST_EVERYONE:
+ break;
+ case VST_COMPANY:
+ if (_local_company != (CompanyID)p2) return CommandCost();
+ break;
+ case VST_CLIENT:
+#ifdef ENABLE_NETWORK
+ if (_network_own_client_id != (ClientID)p2) return CommandCost();
+ break;
+#else
+ return CommandCost();
+#endif
+ default:
+ return CMD_ERROR;
+ }
+
+ if (flags & DC_EXEC) {
+ ResetObjectToPlace();
+ ScrollMainWindowToTile(tile);
+ }
+ return CommandCost();
+}
diff --git a/src/viewport_type.h b/src/viewport_type.h
index 07485c324..74cd88d95 100644
--- a/src/viewport_type.h
+++ b/src/viewport_type.h
@@ -123,4 +123,14 @@ enum ViewportDragDropSelectionProcess {
DDSP_REMOVE_TRUCKSTOP, ///< Road stop removal (trucks)
};
+
+/**
+ * Target of the viewport scrolling GS method
+ */
+enum ViewportScrollTarget {
+ VST_EVERYONE, ///< All players
+ VST_COMPANY, ///< All players in specific company
+ VST_CLIENT, ///< Single player
+};
+
#endif /* VIEWPORT_TYPE_H */