Skip to content

Commit

Permalink
fix bug with hidden resources, add getTrait and getAncillary
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnTW committed Nov 1, 2024
1 parent 556715b commit b8976ff
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 3 deletions.
22 changes: 22 additions & 0 deletions M2TWEOP Code/M2TWEOP library/luaPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ sol::state* luaPlugin::init(std::string& luaFilePath, std::string& modPath)
@tfield toggleDeveloperMode toggleDeveloperMode
@tfield saveGame saveGame
@tfield copyFile copyFile
@tfield getAncillary getAncillary
@tfield getTrait getTrait
@tfield setExpandedString setExpandedString
@tfield getGameVersion getGameVersion
@tfield setPerfectSpy setPerfectSpy
Expand Down Expand Up @@ -338,6 +340,26 @@ sol::state* luaPlugin::init(std::string& luaFilePath, std::string& modPath)
*/
tables.M2TWEOP.set_function("saveGame", &gameHelpers::saveGame);

/***
Get an ancillary by name.
@function M2TWEOP.getAncillary
@tparam string name
@treturn ancillary anc
@usage
M2TWEOP.getAncillary("ancillary_name");
*/
tables.M2TWEOP.set_function("getAncillary", &characterRecordHelpers::findAncillary);

/***
Get a trait by name.
@function M2TWEOP.getTrait
@tparam string name
@tparam traitEntry trait
@usage
M2TWEOP.getTrait("trait_name");
*/
tables.M2TWEOP.set_function("getTrait", &characterRecordHelpers::findTrait);

/***
Copy a file.
@function M2TWEOP.copyFile
Expand Down
6 changes: 4 additions & 2 deletions M2TWEOP Code/M2TWEOP library/patchesForGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1681,8 +1681,6 @@ void __fastcall patchesForGame::clickAtTile(coordPair* xy)

void __stdcall patchesForGame::afterCampaignMapLoaded()
{
if (!eopHiddenResources::isInitialized())
eopHiddenResources::initialize();
discordManager::onCampaignMapLoaded();
globals::dataS.Modules.tacticalMapViewer.unView();
plugData::data.luaAll.fillHashMaps();
Expand Down Expand Up @@ -1732,6 +1730,8 @@ void __stdcall patchesForGame::onUnloadCampaign()
}
void __stdcall patchesForGame::onNewGameLoaded()
{
if (!eopHiddenResources::isInitialized())
eopHiddenResources::initialize();
eopCharacterDataDb::get()->clearData();
minorSettlementDb::load();
eopSettlementDataDb::get()->newGameLoaded();
Expand Down Expand Up @@ -1957,6 +1957,8 @@ void __fastcall patchesForGame::onEvent(DWORD** vTab, DWORD arg2)
}
else if (eventCode == gameReloaded)
{
if (!eopHiddenResources::isInitialized())
eopHiddenResources::initialize();
minorSettlementDb::load();
eopSettlementDataDb::get()->onGameLoaded();
eopFortDataDb::get()->onGameLoaded();
Expand Down
44 changes: 43 additions & 1 deletion M2TWEOP Code/M2TWEOP library/types/characterRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,10 +831,13 @@ namespace characterRecordHelpers
Basic ancillary table
@tfield int index
@tfield string localizedName
@tfield string description
@tfield string effectsDescription
@tfield string name (internal)
@tfield int effectsNum
@tfield bool isUnique
@tfield bool transferable
@tfield string name
@tfield string type
@tfield string imagePath
@tfield getEffect getEffect
Expand All @@ -855,6 +858,15 @@ namespace characterRecordHelpers
types.ancillary.set("imagePath", sol::property(
&getStringPropertyAnc<ancillaryStruct_imagePath>, &setStringPropertyAnc<ancillaryStruct_imagePath>
));
types.ancillary.set("localizedName", sol::property(
&ancillary::getLocalizedName, &ancillary::setLocalizedName
));
types.ancillary.set("description", sol::property(
&ancillary::getLocalizedDescr, &ancillary::setLocalizedDescr
));
types.ancillary.set("effectsDescription", sol::property(
&ancillary::getLocalizedEffectsDescr, &ancillary::setLocalizedEffectsDescr
));
/***
Get an ancillary effect.
@function ancillary:getEffect
Expand Down Expand Up @@ -1041,6 +1053,36 @@ namespace characterRecordHelpers
}
}

std::string ancillary::getLocalizedName()
{
return gameStringHelpers::uniStringToStr(*localizedAncName);
}

void ancillary::setLocalizedName(const std::string& newName)
{
gameStringHelpers::createUniString(*localizedAncName, newName.c_str());
}

std::string ancillary::getLocalizedDescr()
{
return gameStringHelpers::uniStringToStr(*localizedAncDesc);
}

void ancillary::setLocalizedDescr(const std::string& newDescr)
{
gameStringHelpers::createUniString(*localizedAncDesc, newDescr.c_str());
}

std::string ancillary::getLocalizedEffectsDescr()
{
return gameStringHelpers::uniStringToStr(*effectsDescr);
}

void ancillary::setLocalizedEffectsDescr(const std::string& newDescr)
{
gameStringHelpers::createUniString(*effectsDescr, newDescr.c_str());
}

std::string characterRecord::giveValidLabel()
{
if (labelCrypt != 0 && label)
Expand Down
7 changes: 7 additions & 0 deletions M2TWEOP Code/M2TWEOP library/types/characterRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ struct ancillary { /* structure of ancillary */
int typeHash; //004C
bool transferable;//00050
char pad_0051[31];
std::string getLocalizedName();
void setLocalizedName(const std::string& newName);
std::string getLocalizedDescr();
void setLocalizedDescr(const std::string& newDescr);
std::string getLocalizedEffectsDescr();
void setLocalizedEffectsDescr(const std::string& newDescr);

traitEffect* getEffect(const int i)
{
Expand Down Expand Up @@ -550,6 +556,7 @@ namespace characterRecordHelpers
int addAncillary(characterRecord* character, ancillary* anc);
void removeAncillary(characterRecord* character, ancillary* anc);
ancillary* findAncillary(const std::string& ancName);
traitEntry* findTrait(const std::string& name);

void removeTrait(characterRecord* character, const char* traitName);
void addTrait(characterRecord* character, const char* traitName, int traitLevel);
Expand Down
2 changes: 2 additions & 0 deletions M2TWEOP Code/M2TWEOP library/types/eopBuildings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ void eopHiddenResources::addHiddenResourceToRegionIndex(const std::string& name,

bool eopHiddenResources::hasHiddenResource(const int regionId, const int id)
{
if (!isInitialized())
initialize();
if (regionId >= static_cast<int>(m_HiddenResources.size()))
return false;
const auto& res = m_HiddenResources[regionId];
Expand Down
2 changes: 2 additions & 0 deletions M2TWEOP Code/M2TWEOP library/types/faction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,7 @@ namespace factionHelpers
@tfield int secondaryColorBlue Warning: resets on reload.
@tfield int triumphValue Usage unknown.
@tfield int religionID
@tfield string name
@tfield int standardIndex Warning: resets on reload.
@tfield int logoIndex Warning: resets on reload.
@tfield int smallLogoIndex Warning: resets on reload.
Expand Down Expand Up @@ -1831,6 +1832,7 @@ namespace factionHelpers
*/
types.factionRecord = luaState.new_usertype<factionRecord>("factionRecord");
types.factionRecord.set("primaryColorRed", &factionRecord::primary_colour_red);
types.factionRecord.set("name", &factionRecord::facName);
types.factionRecord.set("primaryColorGreen", &factionRecord::primary_colour_green);
types.factionRecord.set("primaryColorBlue", &factionRecord::primary_colour_blue);
types.factionRecord.set("canHorde", &factionRecord::canHorde);
Expand Down

0 comments on commit b8976ff

Please sign in to comment.