Skip to content

Commit

Permalink
expansion of unit and campaign structs
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnTW committed Oct 7, 2023
1 parent 9db374f commit 8f1cb96
Show file tree
Hide file tree
Showing 15 changed files with 1,124 additions and 99 deletions.
4 changes: 4 additions & 0 deletions M2TWEOP-luaPlugin/luaPlugin/basicEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ void onEventWrapper(const DWORD eventAddr, DWORD** vTab, DWORD arg2)
void initReligionNames()
{
const auto* religionDb = *reinterpret_cast <religionDatabase**>(0x016A0B90);
if (m2tweopHelpers::getGameVersion() == 1)
{
religionDb = *reinterpret_cast <religionDatabase**>(0x016E9DC0);
}
for (int i = 0; i < religionDb->religionCount; i++)
{
religionNames[i] = gameHelpers::getReligionName(i);
Expand Down
11 changes: 2 additions & 9 deletions M2TWEOP-luaPlugin/luaPlugin/basicEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ using namespace std;
extern "C" PLUGINM2TWEOP_API void onReadGameDbsAtStart();
extern "C" PLUGINM2TWEOP_API void onEndSiege(int x, int y);
extern "C" PLUGINM2TWEOP_API void onStartSiege(int x, int y);
std::unordered_map<int, const char*> religionNames = {
};


extern "C" PLUGINM2TWEOP_API void onClickAtTile(int x, int y);
Expand Down Expand Up @@ -59,15 +61,6 @@ std::unordered_map<int, const char*> missionSuccessLvl = {
{2,"partly_successful"},
{3,"highly_successful"}
};
std::unordered_map<int, const char*> religionNames = {
};

struct crusade
{
public:
char pad_0x0000[60]; //0x0000
settlementStruct* targetSettlement; //0x003C
};

void checkLuaFunc(sol::function** lRef);
void initReligionNames();
Expand Down
14 changes: 14 additions & 0 deletions M2TWEOP-luaPlugin/luaPlugin/eopEduHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ void eopEduHelpers::haveAttributeLegioSet(eduEntry* eduEn, bool isHaveLegio)
}
}

bool eopEduHelpers::hasAttribute(unit* unit, const char* attributeName)
{
const auto entry = unit->eduEntry;
const int attributesNum = (reinterpret_cast<DWORD>(entry->EndOfAttributes) - reinterpret_cast<DWORD>(entry->Attributes)) / 8;
for (int i = 0; i < attributesNum; i+= 2)
{
if (strcmp(reinterpret_cast<const char*>(entry->Attributes[i]), attributeName) == 0)
{
return true;
}
}
return false;
}

int eopEduHelpers::getArmourUpgradeLevelsNum(int idx)
{
eduEntry* eduEn = eopEduHelpers::getEduEntry(idx);
Expand Down
1 change: 1 addition & 0 deletions M2TWEOP-luaPlugin/luaPlugin/eopEduHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace eopEduHelpers
int getEntryStat(int idx, UnitEnums::eduStat stat, int sec);
void addUnitToRQ(int idx, settlementStruct* sett);
int multiplexor(int n1, int n2, int sel);
bool hasAttribute(unit* unit, const char* attributeName);

void setEntryLocalizedName(int index, const char* newLocName);
void setEntryLocalizedDescr(int index, const char* newLocDescr);
Expand Down
39 changes: 39 additions & 0 deletions M2TWEOP-luaPlugin/luaPlugin/factionHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "plugData.h"
#include <windows.h>

#include "gameDataAllHelper.h"

std::string factionHelpers::getFactionName(const factionStruct* fac)
{
return std::string(fac->factSmDescr->facName);
Expand Down Expand Up @@ -47,6 +49,43 @@ void factionHelpers::deleteFort(const factionStruct* fac, fortStruct* fort)
(*(*plugData::data.funcs.deleteFort))(fac, fort);
}

bool factionHelpers::hasMilitaryAccess(const factionStruct* fac1, const factionStruct* fac2)
{
const auto gameData = gameDataAllHelper::get();
const auto campaign = gameData->campaignData;
const auto agreements = campaign->diplomaticStandings[fac1->dipNum][fac2->dipNum].trade;
return agreements & static_cast<int8_t>(0x2);
}

void factionHelpers::setMilitaryAccess(const factionStruct* fac1, const factionStruct* fac2, bool set)
{
const auto gameData = gameDataAllHelper::get();
const auto campaign = gameData->campaignData;
const auto agreements = campaign->diplomaticStandings[fac1->dipNum][fac2->dipNum].trade;
if (set)
{
campaign->diplomaticStandings[fac1->dipNum][fac2->dipNum].trade = agreements | static_cast<int8_t>(0x2);
}
else
{
campaign->diplomaticStandings[fac1->dipNum][fac2->dipNum].trade = agreements & static_cast<int8_t>(~0x2);
}
}

float factionHelpers::getFactionStanding(const factionStruct* fac1, const factionStruct* fac2)
{
const auto gameData = gameDataAllHelper::get();
const auto campaign = gameData->campaignData;
return campaign->diplomaticStandings[fac1->dipNum][fac2->dipNum].factionStanding;
}

void factionHelpers::setFactionStanding(const factionStruct* fac1, const factionStruct* fac2, float standing)
{
const auto gameData = gameDataAllHelper::get();
const auto campaign = gameData->campaignData;
campaign->diplomaticStandings[fac1->dipNum][fac2->dipNum].factionStanding = standing;
}

void factionHelpers::createFortXY(const factionStruct* fac, int x, int y)
{
(*(*plugData::data.funcs.createFortXY))(fac, x, y);
Expand Down
5 changes: 4 additions & 1 deletion M2TWEOP-luaPlugin/luaPlugin/factionHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ namespace factionHelpers
void createFortXY(const factionStruct* fac, int x, int y);
void createFort(const general* gen);
void changeFactionName(factionStruct* fac, const char* newName);

bool hasMilitaryAccess(const factionStruct* fac1, const factionStruct* fac2);
float getFactionStanding(const factionStruct* fac1, const factionStruct* fac2);
void setFactionStanding(const factionStruct* fac1, const factionStruct* fac2, float standing);
void setMilitaryAccess(const factionStruct* fac1, const factionStruct* fac2, bool set);
std::string getLocalizedFactionName(factionStruct* fac);

//faction
Expand Down
43 changes: 43 additions & 0 deletions M2TWEOP-luaPlugin/luaPlugin/gameHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,53 @@ namespace gameHelpers
(*(*plugData::data.funcs.historicEvent))(name, title, description);
}

general* gameHelpers::getCardinal(const collegeOfCardinals* college, const int index)
{
return college->cardinalsArray[index].trackedCharacter->character;
}

fortStruct* gameHelpers::getFortAll(const campaign* campaign, const int index)
{
return campaign->fortsArray[index];
}

portBuildingStruct* gameHelpers::getPortAll(const campaign* campaign, const int index)
{
return campaign->portsBuildings[index];
}

watchTowerStruct* gameHelpers::getWatchTowerAll(const campaign* campaign, const int index)
{
return campaign->watchtowers[index];
}

settlementStruct* getSettlementByName(campaign* campaign, const char* name)
{
settlementList* settlementList = &campaign->settlementList;
int settNum = 0;
while (settlementList != nullptr)
{
settNum = settlementList->settlementsNum;
for (int i = 0; i < settNum; i++)
{
if (strcmp(settlementList->settlements[i]->name, name) == 0)
{
return settlementList->settlements[i];
}
}
settlementList = settlementList->nextSettlements;
}
return nullptr;
}

const char* getReligionName(const int index)
{

const auto* religionDb = *reinterpret_cast <religionDatabase**>(0x016A0B90);
if (m2tweopHelpers::getGameVersion() == 1)
{
religionDb = *reinterpret_cast <religionDatabase**>(0x016E9DC0);
}
const wchar_t* name = religionDb->religionNames[index]->string;
// Determine the size of the required buffer
const int size = WideCharToMultiByte(CP_UTF8, 0, name, -1, nullptr, 0, nullptr, nullptr);
Expand Down
6 changes: 5 additions & 1 deletion M2TWEOP-luaPlugin/luaPlugin/gameHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ namespace gameHelpers
void changeRegionName(regionStruct* region, const char* newName);
std::string getRegionName(regionStruct* region);
void changeRebelsName(regionStruct* region, const char* newName);

general* getCardinal(const collegeOfCardinals* college, const int index);
fortStruct* getFortAll(const campaign* campaign, const int index);
portBuildingStruct* getPortAll(const campaign* campaign, const int index);
watchTowerStruct* getWatchTowerAll(const campaign* campaign, const int index);
settlementStruct* getSettlementByName(campaign* campaign, const char* name);
std::string getRebelsName(regionStruct* region);

int getMercUnitNum(mercPool* mercPool);
Expand Down
Loading

0 comments on commit 8f1cb96

Please sign in to comment.