I'm trying to add a new function called in the DLL, "unitCustomCombat", but I can't get it to work. I commented out all of the code in the resolvecombat() function fo CvUnit.cpp and replaced it with a section similar to how other override functions are called. In CvGameUtils.py, I added a new function that's supposed to damage all units in the defending tile. When a unit attacks, a few shots get fired but no one dies and the unit eventually withdraws from combat.
Here's what I've got so far. In the DLL:
In the Python:
I tried passing the units rather than the unitIDs, but tried the unitIDs as an alternative. The makeexception() call works as expected if I insert it into another bit of code, like the building override, but it doesn't bring up the python exception popup. If I damage the unit after the python function is called in the SDK, the defending unit dies as expected, so the new function must be getting ignored.
Can someone please help? My next step is to probably "Steal" another function that I know works, in case the number of overrides may be hardcoded.
Here's what I've got so far. In the DLL:
Code:
void CvUnit::resolveCombat(CvUnit* pDefender, CvPlot* pPlot, CvBattleDefinition& kBattle)
{
CyArgsList argsList;
argsList.add(getID());
argsList.add(pDefender->getID());
long lResult=0;
gDLL->getPythonIFace()->callFunction(PYGameModule, "unitCustomCombat", argsList.makeFunctionArgs(), &lResult);
In the Python:
Code:
def unitCustomCombat(self, argsList):
makeexception()
DefenderID, AttackerID = argsList
Defender = getUnit(DefenderID)
Attacker = getUnit(AttackerID)
Defender.changeDamage(100, Attacker.getOwnerINLINE())
Attacker.changeExperience(1, 10000, False)
return False
I tried passing the units rather than the unitIDs, but tried the unitIDs as an alternative. The makeexception() call works as expected if I insert it into another bit of code, like the building override, but it doesn't bring up the python exception popup. If I damage the unit after the python function is called in the SDK, the defending unit dies as expected, so the new function must be getting ignored.
Can someone please help? My next step is to probably "Steal" another function that I know works, in case the number of overrides may be hardcoded.