Skip to content

Commit

Permalink
add faction battle model
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnTW committed Oct 28, 2024
1 parent 5a6639a commit e24fea6
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 45 deletions.
118 changes: 73 additions & 45 deletions M2TWEOP Code/M2TWEOP library/types/faction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,27 @@ void factionRecord::setFactionStratModel(const std::string& model, const int cha
}
const auto levelEntry = &factionEntry->stratInfo->stratModelsArray[level];
levelEntry->stratModelEntry = entry;
gameStringHelpers::setHashedString(&levelEntry->modelName, model.c_str());
}

void factionRecord::setFactionBattleModel(const std::string& model, const int characterType)
{
if (characterType != characterTypeStrat::general && characterType != characterTypeStrat::namedCharacter)
return;
const auto battleMod = unitHelpers::findBattleModel(model.c_str());
if (!battleMod)
{
gameHelpers::logStringGame("factionRecord.setFactionBattleModel: model not found: " + model);
return;
}
const auto descrCharacterPtr = reinterpret_cast<descrCharacterArray*>(dataOffsets::offsets.descrCharacter);
const auto charTypeEntry = &descrCharacterPtr->entries[characterType];
const auto factionEntry = charTypeEntry->ptrsToDescrCharacterFactionEntries[id];
factionEntry->battleMod = techFuncs::createGameClass<eduOfficer>();
factionEntry->battleMod->modelGroup = 0;
factionEntry->battleMod->modelIndex = 0;
gameStringHelpers::setHashedString(&factionEntry->battleMod->name, model.c_str());
factionEntry->battleMod->modelEntry = battleMod;
}

stringWithHash* LOOKUP_STRING_LABEL = new stringWithHash();
Expand Down Expand Up @@ -267,7 +288,6 @@ void factionTileStruct::update(factionStruct* fromFaction)

namespace factionHelpers
{

/*----------------------------------------------------------------------------------------------------------------*\
Faction helpers
\*----------------------------------------------------------------------------------------------------------------*/
Expand Down Expand Up @@ -518,7 +538,7 @@ namespace factionHelpers
if (!stack)
stack = unit->army;
if (unit && unit->army == stack)
unitList[i - 1] = unit;
unitList[i - 1] = unit;
}
if (!stack)
return nullptr;
Expand Down Expand Up @@ -555,24 +575,24 @@ namespace factionHelpers
#pragma endregion Faction helpers


void addToLua(sol::state& luaState)
{
struct
{
sol::usertype<factionStruct>factionStruct;
sol::usertype<factionRecord>factionRecord;
sol::usertype<factionEconomy>factionEconomy;
sol::usertype<factionRanking>factionRanking;
sol::usertype<aiFaction> aiFaction;
sol::usertype<aiLongTermGoalDirector> aiLongTermGoalDirector;
sol::usertype<aiPersonalityValues> aiPersonality;
sol::usertype<aiGlobalStrategyDirector> aiGlobalStrategyDirector;
sol::usertype<decisionValuesLTGD> decisionValuesLTGD;
sol::usertype<militaryValuesLTGD> aiFactionValues;
sol::usertype<interFactionLTGD> interFactionLTGD;
sol::usertype<holdRegionsWinCondition>holdRegionsWinCondition;
sol::usertype<battleFactionCounter>battleFactionCounter;
}types;
void addToLua(sol::state& luaState)
{
struct
{
sol::usertype<factionStruct>factionStruct;
sol::usertype<factionRecord>factionRecord;
sol::usertype<factionEconomy>factionEconomy;
sol::usertype<factionRanking>factionRanking;
sol::usertype<aiFaction> aiFaction;
sol::usertype<aiLongTermGoalDirector> aiLongTermGoalDirector;
sol::usertype<aiPersonalityValues> aiPersonality;
sol::usertype<aiGlobalStrategyDirector> aiGlobalStrategyDirector;
sol::usertype<decisionValuesLTGD> decisionValuesLTGD;
sol::usertype<militaryValuesLTGD> aiFactionValues;
sol::usertype<interFactionLTGD> interFactionLTGD;
sol::usertype<holdRegionsWinCondition>holdRegionsWinCondition;
sol::usertype<battleFactionCounter>battleFactionCounter;
}types;

///Faction
//@section Faction
Expand Down Expand Up @@ -904,7 +924,7 @@ namespace factionHelpers
@tparam int Y
@treturn watchtowerStruct watchTower
@usage
fac:createWatchtower(193, 283)
fac:createWatchtower(193, 283)
*/
types.factionStruct.set_function("createWatchtower", &spawnWatchtower);

Expand Down Expand Up @@ -1022,7 +1042,7 @@ namespace factionHelpers
@tparam int characterTypeIndex
@tparam int factionID
@usage
fac:setCharacterNameFaction(characterType.spy, 2)
fac:setCharacterNameFaction(characterType.spy, 2)
*/
types.factionStruct.set_function("setCharacterNameFaction", &factionStruct::setCharacterNameFaction);

Expand All @@ -1033,7 +1053,7 @@ namespace factionHelpers
@tparam int y
@treturn int visibility use tileVisibility enum
@usage
local vis = fac:getTileVisibility(172, 293)
local vis = fac:getTileVisibility(172, 293)
*/
types.factionStruct.set_function("getTileVisibility", &factionStruct::getTileVisibility);

Expand All @@ -1044,7 +1064,7 @@ namespace factionHelpers
@tparam int y
@tparam int visibility use tileVisibility enum
@usage
fac:setTileVisibility(172, 293, tileVisibility.wasVisible)
fac:setTileVisibility(172, 293, tileVisibility.wasVisible)
*/
types.factionStruct.set_function("setTileVisibility", &factionStruct::setTileVisibility);

Expand All @@ -1054,7 +1074,7 @@ namespace factionHelpers
@tparam int x
@tparam int y
@usage
local vis = fac:revealTile(172, 293)
local vis = fac:revealTile(172, 293)
*/
types.factionStruct.set_function("revealTile", &factionStruct::revealTile);

Expand All @@ -1064,7 +1084,7 @@ namespace factionHelpers
@tparam int x
@tparam int y
@usage
fac:hideRevealedTile(172, 293)
fac:hideRevealedTile(172, 293)
*/
types.factionStruct.set_function("hideRevealedTile", &factionStruct::hideRevealedTile);

Expand Down Expand Up @@ -1097,7 +1117,7 @@ namespace factionHelpers
@tparam bool castle
@treturn settlementStruct newSett
@usage
fac:addSettlement(123, 234, "coolSettlement", 1, false)
fac:addSettlement(123, 234, "coolSettlement", 1, false)
*/
types.factionStruct.set_function("addSettlement", &settlementHelpers::createSettlement);

Expand All @@ -1108,7 +1128,7 @@ namespace factionHelpers
@tparam int G
@tparam int B
@usage
fac:setColor(255, 255, 255)
fac:setColor(255, 255, 255)
*/
types.factionStruct.set_function("setColor", &factionStruct::setColor);

Expand All @@ -1119,7 +1139,7 @@ namespace factionHelpers
@tparam int G
@tparam int B
@usage
fac:setSecondaryColor(255, 255, 255)
fac:setSecondaryColor(255, 255, 255)
*/
types.factionStruct.set_function("setSecondaryColor", &factionStruct::setSecondaryColor);

Expand Down Expand Up @@ -1213,11 +1233,11 @@ namespace factionHelpers
@tparam int targetX
@tparam int targetY
@usage
local units = {}
for i = 0, myStack.unitsNum / 2 - 1 do
table.insert(units, myStack:getUnit(i))
end
fac:splitArmy(units, 154, 84)
local units = {}
for i = 0, myStack.unitsNum / 2 - 1 do
table.insert(units, myStack:getUnit(i))
end
fac:splitArmy(units, 154, 84)
*/
types.factionStruct.set_function("splitArmy", &splitArmy);

Expand All @@ -1227,7 +1247,7 @@ namespace factionHelpers
@tparam int regionID
@treturn bool result
@usage
local isNeighbour = fac:isNeighbourRegion(34)
local isNeighbour = fac:isNeighbourRegion(34)
*/
types.factionStruct.set_function("isNeighbourRegion", &factionStruct::isInNeighbourArray);

Expand All @@ -1237,7 +1257,7 @@ namespace factionHelpers
@tparam int charType
@treturn int count
@usage
local count = fac:getCharacterCountOfType(characterType.general)
local count = fac:getCharacterCountOfType(characterType.general)
*/
types.factionStruct.set_function("getCharacterCountOfType", &factionStruct::getCharacterCountOfType);

Expand All @@ -1247,7 +1267,7 @@ namespace factionHelpers
@tparam character candidate
@treturn bool canSee
@usage
local canSee = fac:canSeeCharacter(someCharacter)
local canSee = fac:canSeeCharacter(someCharacter)
*/
types.factionStruct.set_function("canSeeCharacter", &factionStruct::canSeeCharacter);

Expand All @@ -1257,7 +1277,7 @@ namespace factionHelpers
@tparam string label
@treturn characterRecord charRecord
@usage
local myChar = fac:getCharacterByLabel("rufus_1")
local myChar = fac:getCharacterByLabel("rufus_1")
*/
types.factionStruct.set_function("getCharacterByLabel", &factionStruct::getCharacterByLabel);

Expand Down Expand Up @@ -1663,7 +1683,7 @@ namespace factionHelpers
@tparam int type use building capabilities enum
@tparam int value
@usage
aiPersonality:setConstructionValue(buildingCapability.law_bonus, 100)
aiPersonality:setConstructionValue(buildingCapability.law_bonus, 100)
*/
types.aiPersonality.set_function("setConstructionValue", &aiPersonalityValues::setConstructionValue);
/***
Expand All @@ -1672,7 +1692,7 @@ namespace factionHelpers
@tparam int type use characterTypes
@tparam int value
@usage
aiPersonality:setConstructionAgentValue(characterType.diplomat, 100)
aiPersonality:setConstructionAgentValue(characterType.diplomat, 100)
*/
types.aiPersonality.set_function("setConstructionAgentValue", &aiPersonalityValues::setConstructionAgentValue);
/***
Expand All @@ -1681,7 +1701,7 @@ namespace factionHelpers
@tparam int type use unitCategoryClass enum
@tparam int value
@usage
aiPersonality:setConstructionUnitValue(unitCategoryClass.heavyCavalry, 100)
aiPersonality:setConstructionUnitValue(unitCategoryClass.heavyCavalry, 100)
*/
types.aiPersonality.set_function("setConstructionUnitValue", &aiPersonalityValues::setConstructionUnitValue);
/***
Expand Down Expand Up @@ -1802,6 +1822,7 @@ namespace factionHelpers
@tfield int hordeMaxPercentArmyStack
@tfield int cultureID
@tfield setFactionStratModel setFactionStratModel
@tfield setFactionBattleModel setFactionBattleModel
@table factionRecord
*/
Expand Down Expand Up @@ -1856,7 +1877,14 @@ namespace factionHelpers
*/
types.factionRecord.set_function("setFactionStratModel", &factionRecord::setFactionStratModel);



}
}
/***
Set a faction's default battle model
@function factionRecord:setFactionBattleModel
@tparam string model
@tparam int characterType
@usage
factionRec:setFactionBattleModel("arnor_general", characterType.general)
*/
types.factionRecord.set_function("setFactionBattleModel", &factionRecord::setFactionBattleModel);
}
}
1 change: 1 addition & 0 deletions M2TWEOP Code/M2TWEOP library/types/faction.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ struct factionRecord { /* see descr_sm_factions.txt */
int getCultureId();
void setCulture(int Id);
void setFactionStratModel(const std::string& model, int characterType, int level);
void setFactionBattleModel(const std::string& model, int characterType);
};

class eopFactionData
Expand Down

0 comments on commit e24fea6

Please sign in to comment.