Skip to content

Commit

Permalink
add ground move costs
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnTW committed Oct 17, 2024
1 parent 82fee23 commit 5df00a5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
2 changes: 2 additions & 0 deletions M2TWEOP Code/M2TWEOP library/dataOffsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void dataOffsets::initDataOffsets(int gameVer)
offsets.traitDb = 0x1666F90;
offsets.ancillaryDb = 0x1666F40;
offsets.modelRigidCounts = 0x1B5EFE4;
offsets.groundMoveCosts = 0x164A0A0;


offsets.fortVtbl = 0x13362F4;
Expand Down Expand Up @@ -204,6 +205,7 @@ void dataOffsets::initDataOffsets(int gameVer)
offsets.uiStratUiV2 = 0x2C6D1B0;
offsets.isDLC = 0x016A284C;
offsets.modelRigidCounts = 0x1B15EB4;
offsets.groundMoveCosts = 0x01602188;

offsets.audioEnable = reinterpret_cast<bool*>(0x01639f1d);
offsets.audioMaster_vol = reinterpret_cast<int*>(0x01639f60);
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 @@ -16,6 +16,7 @@ class dataOffsets
DWORD stringTable = NULL;
DWORD stratCursorCoords = NULL;
DWORD battleCursorCoords = NULL;
DWORD groundMoveCosts = NULL;
DWORD customTiles = NULL;
DWORD battleCamera = NULL;
DWORD battlePerimeters = NULL;
Expand Down
22 changes: 22 additions & 0 deletions M2TWEOP Code/M2TWEOP library/luaPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ sol::state* luaPlugin::init(std::string& luaFilePath, std::string& modPath)
@tfield setKhakiTextColor setKhakiTextColor
@tfield getMinorSettlementBalance getMinorSettlementBalance
@tfield generateSprite generateSprite
@tfield getGroundTypeMoveCost getGroundTypeMoveCost
@tfield setGroundTypeMoveCost setGroundTypeMoveCost
@table M2TWEOP
*/

Expand Down Expand Up @@ -903,6 +905,26 @@ sol::state* luaPlugin::init(std::string& luaFilePath, std::string& modPath)
*/
tables.M2TWEOP.set_function("generateSprite", &gameHelpers::generateSprite);

/***
Get the move cost of a ground type.
@function M2TWEOP.getGroundTypeMoveCost
@tparam int groundType
@treturn float moveCost
@usage
local cost = M2TWEOP.getGroundTypeMoveCost(strategyGroundType.hills)
*/
tables.M2TWEOP.set_function("getGroundTypeMoveCost", &stratMapHelpers::getGroundTypeMoveCost);

/***
Set the move cost of a ground type.
@function M2TWEOP.setGroundTypeMoveCost
@tparam int groundType
@tparam float moveCost
@usage
M2TWEOP.setGroundTypeMoveCost(strategyGroundType.hills, 11.0)
*/
tables.M2TWEOP.set_function("setGroundTypeMoveCost", &stratMapHelpers::setGroundTypeMoveCost);

/***
Add a banner symbol. Add them onCampaignMapLoaded or later!
@function M2TWEOP.addBanner
Expand Down
18 changes: 17 additions & 1 deletion M2TWEOP Code/M2TWEOP library/types/strategyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,23 @@ namespace stratMapHelpers
{
globals::dataS.Modules.tacticalMapViewer.view(x, y);
}


float getGroundTypeMoveCost(const int groundType)
{
if (groundType < 0 || groundType > strategyGroundType::impassableSea)
return -1;
const auto costsOffset = reinterpret_cast<float*>(dataOffsets::offsets.groundMoveCosts);
return costsOffset[groundType];
}

void setGroundTypeMoveCost(const int groundType, const float newCost)
{
if (groundType < 0 || groundType > strategyGroundType::impassableSea)
return;
const auto costsOffset = reinterpret_cast<float*>(dataOffsets::offsets.groundMoveCosts);
costsOffset[groundType] = newCost;
}

void moveStratCameraSlow(int x, int y)
{
if (!isStratMap())
Expand Down
2 changes: 2 additions & 0 deletions M2TWEOP Code/M2TWEOP library/types/strategyMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,8 @@ namespace stratMapHelpers
std::pair<int, int> findValidTileNearTile(int x, int y, int charType);
bool isTileValidForCharacterType(int charType, int x, int y);
void viewTacticalMap(int x, int y);
float getGroundTypeMoveCost(int groundType);
void setGroundTypeMoveCost(int groundType, float newCost);
void getGameTileCoordsWithCursor(int& x, int& y);
std::tuple<int, int> getStratHoveredCoords();
std::tuple<float, float, float> getBattleHoveredCoords();
Expand Down

0 comments on commit 5df00a5

Please sign in to comment.