From 82fee235caee8f67e2c12c68fc9886bda9bafce5 Mon Sep 17 00:00:00 2001 From: FynnTW Date: Thu, 17 Oct 2024 20:02:48 +0300 Subject: [PATCH] add getting battle coordinates with cursor --- M2TWEOP Code/M2TWEOP library/dataOffsets.cpp | 2 ++ M2TWEOP Code/M2TWEOP library/dataOffsets.h | 1 + M2TWEOP Code/M2TWEOP library/luaPlugin.cpp | 26 ++++++++++++++----- .../M2TWEOP library/types/strategyMap.cpp | 11 +++++++- .../M2TWEOP library/types/strategyMap.h | 3 ++- documentationGenerator/generateLuaDocs.py | 1 + 6 files changed, 36 insertions(+), 8 deletions(-) diff --git a/M2TWEOP Code/M2TWEOP library/dataOffsets.cpp b/M2TWEOP Code/M2TWEOP library/dataOffsets.cpp index 874240a2..abcba549 100644 --- a/M2TWEOP Code/M2TWEOP library/dataOffsets.cpp +++ b/M2TWEOP Code/M2TWEOP library/dataOffsets.cpp @@ -65,6 +65,7 @@ void dataOffsets::initDataOffsets(int gameVer) offsets.ltgdGlobals = 0x016F115C; offsets.groupLabels = 0x001BA96A0; offsets.stratCursorCoords = 0x02c86c28; + offsets.battleCursorCoords = 0x02C86C10; offsets.modelsDb = 0x016e9dc8; offsets.customTiles = 0x02C3BF50; offsets.battlePerimeters = 0x16F0600; @@ -166,6 +167,7 @@ void dataOffsets::initDataOffsets(int gameVer) offsets.ltgdGlobals = 0x016A7Fc4; offsets.groupLabels = 0x01B60580; offsets.stratCursorCoords = 0x02c3da48; + offsets.battleCursorCoords = 0x02c3da30; offsets.modelsDb = 0x016a0b98; offsets.battlefieldEngines = 0x02C3A254; offsets.options1 = 0x02C6D804; diff --git a/M2TWEOP Code/M2TWEOP library/dataOffsets.h b/M2TWEOP Code/M2TWEOP library/dataOffsets.h index 5b85a0b7..f650f07d 100644 --- a/M2TWEOP Code/M2TWEOP library/dataOffsets.h +++ b/M2TWEOP Code/M2TWEOP library/dataOffsets.h @@ -15,6 +15,7 @@ class dataOffsets DWORD stratMapAllOffsetStart = NULL; DWORD stringTable = NULL; DWORD stratCursorCoords = NULL; + DWORD battleCursorCoords = NULL; DWORD customTiles = NULL; DWORD battleCamera = NULL; DWORD battlePerimeters = NULL; diff --git a/M2TWEOP Code/M2TWEOP library/luaPlugin.cpp b/M2TWEOP Code/M2TWEOP library/luaPlugin.cpp index 669a39f6..ca7d150f 100644 --- a/M2TWEOP Code/M2TWEOP library/luaPlugin.cpp +++ b/M2TWEOP Code/M2TWEOP library/luaPlugin.cpp @@ -224,7 +224,8 @@ sol::state* luaPlugin::init(std::string& luaFilePath, std::string& modPath) @tfield setReligionsLimit setReligionsLimit @tfield setEquipmentCosts setEquipmentCosts @tfield isTileFree isTileFree - @tfield getGameTileCoordsWithCursor getGameTileCoordsWithCursor + @tfield getStratHoveredCoords getStratHoveredCoords + @tfield getBattleHoveredCoords getBattleHoveredCoords @tfield getTileVisibility getTileVisibility @tfield setGuildCooldown setGuildCooldown @tfield setEDUUnitsSize setEDUUnitsSize @@ -550,19 +551,32 @@ sol::state* luaPlugin::init(std::string& luaFilePath, std::string& modPath) @tparam int Y coordinate of the tile. @return boolean isFree @usage - M2TWEOP.isTileFree(55,25); + M2TWEOP.isTileFree(55,25); */ tables.M2TWEOP.set_function("isTileFree", &stratMapHelpers::isTileFreeLua); /*** - Get the selected tile coords. - @function M2TWEOP.getGameTileCoordsWithCursor + Get the hovered tile coordinates on the strategy map. + @function M2TWEOP.getStratHoveredCoords @treturn int x @treturn int y @usage - local x,y=M2TWEOP.getGameTileCoordsWithCursor(); + local x,y=M2TWEOP.getStratHoveredCoords(); */ - tables.M2TWEOP.set_function("getGameTileCoordsWithCursor", &stratMapHelpers::getGameTileCoordsWithCursorLua); + tables.M2TWEOP.set_function("getStratHoveredCoords", &stratMapHelpers::getStratHoveredCoords); + + + /*** + Get the hovered position coordinates on the battle map. + @function M2TWEOP.getBattleHoveredCoords + @treturn float x + @treturn float y + @treturn float z + @usage + local x,y,z = M2TWEOP.getBattleHoveredCoords(); + */ + tables.M2TWEOP.set_function("getBattleHoveredCoords", &stratMapHelpers::getBattleHoveredCoords); + tables.M2TWEOP.set_function("getGameTileCoordsWithCursor", &stratMapHelpers::getStratHoveredCoords); tables.M2TWEOP.set_function("getTileRegionID", &stratMapHelpers::getTileRegionID); /*** diff --git a/M2TWEOP Code/M2TWEOP library/types/strategyMap.cpp b/M2TWEOP Code/M2TWEOP library/types/strategyMap.cpp index c8268a8f..55a89924 100644 --- a/M2TWEOP Code/M2TWEOP library/types/strategyMap.cpp +++ b/M2TWEOP Code/M2TWEOP library/types/strategyMap.cpp @@ -705,7 +705,7 @@ namespace stratMapHelpers return true; } - std::tuple getGameTileCoordsWithCursorLua() + std::tuple getStratHoveredCoords() { int x = 0; int y = 0; @@ -720,6 +720,15 @@ namespace stratMapHelpers return static_cast(sqrt(static_cast(dx * dx) + static_cast(dy * dy))); } + std::tuple getBattleHoveredCoords() + { + const auto mouseOffset = reinterpret_cast(dataOffsets::offsets.battleCursorCoords); + float x = mouseOffset[0]; + float z = mouseOffset[1]; + float y = mouseOffset[2]; + return std::make_tuple(x, y, z); + } + void getGameTileCoordsWithCursor(int& x, int& y) { const auto mouseOffset = reinterpret_cast(dataOffsets::offsets.stratCursorCoords); diff --git a/M2TWEOP Code/M2TWEOP library/types/strategyMap.h b/M2TWEOP Code/M2TWEOP library/types/strategyMap.h index 214d1f34..f7919d77 100644 --- a/M2TWEOP Code/M2TWEOP library/types/strategyMap.h +++ b/M2TWEOP Code/M2TWEOP library/types/strategyMap.h @@ -1027,7 +1027,8 @@ namespace stratMapHelpers bool isTileValidForCharacterType(int charType, int x, int y); void viewTacticalMap(int x, int y); void getGameTileCoordsWithCursor(int& x, int& y); - std::tuple getGameTileCoordsWithCursorLua(); + std::tuple getStratHoveredCoords(); + std::tuple getBattleHoveredCoords(); settlementStruct* getSettlement(stratMap* map, const std::string& name); regionStruct* getRegionByName(stratMap* map, const std::string& name); std::pair convertTileCoords(const DWORD arrayIndex); diff --git a/documentationGenerator/generateLuaDocs.py b/documentationGenerator/generateLuaDocs.py index 5e4392b8..f388094a 100644 --- a/documentationGenerator/generateLuaDocs.py +++ b/documentationGenerator/generateLuaDocs.py @@ -149,6 +149,7 @@ def __init__(self, type, name, comment): "crusadeNoProgressTurns", "noCrusadeProgressThisTurn", "childs", + "getGameTileCoordsWithCursor", "getEopBuildEntry", "setBuildingPic", "setBuildingPicConstructed",