Skip to content

Commit

Permalink
add getting battle coordinates with cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnTW committed Oct 17, 2024
1 parent 56c3bf3 commit 82fee23
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
2 changes: 2 additions & 0 deletions M2TWEOP Code/M2TWEOP library/dataOffsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions M2TWEOP Code/M2TWEOP library/dataOffsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 20 additions & 6 deletions M2TWEOP Code/M2TWEOP library/luaPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

/***
Expand Down
11 changes: 10 additions & 1 deletion M2TWEOP Code/M2TWEOP library/types/strategyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ namespace stratMapHelpers
return true;
}

std::tuple<int, int> getGameTileCoordsWithCursorLua()
std::tuple<int, int> getStratHoveredCoords()
{
int x = 0;
int y = 0;
Expand All @@ -720,6 +720,15 @@ namespace stratMapHelpers
return static_cast<float>(sqrt(static_cast<double>(dx * dx) + static_cast<double>(dy * dy)));
}

std::tuple<float, float, float> getBattleHoveredCoords()
{
const auto mouseOffset = reinterpret_cast<float*>(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<int*>(dataOffsets::offsets.stratCursorCoords);
Expand Down
3 changes: 2 additions & 1 deletion M2TWEOP Code/M2TWEOP library/types/strategyMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, int> getGameTileCoordsWithCursorLua();
std::tuple<int, int> getStratHoveredCoords();
std::tuple<float, float, float> getBattleHoveredCoords();
settlementStruct* getSettlement(stratMap* map, const std::string& name);
regionStruct* getRegionByName(stratMap* map, const std::string& name);
std::pair<int, int> convertTileCoords(const DWORD arrayIndex);
Expand Down
1 change: 1 addition & 0 deletions documentationGenerator/generateLuaDocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def __init__(self, type, name, comment):
"crusadeNoProgressTurns",
"noCrusadeProgressThisTurn",
"childs",
"getGameTileCoordsWithCursor",
"getEopBuildEntry",
"setBuildingPic",
"setBuildingPicConstructed",
Expand Down

0 comments on commit 82fee23

Please sign in to comment.