View Full Version : [PYTHON] onCombatResult
Molybdeus Jul 17, 2007, 09:12 PM I'm trying to make a simple python script, but my incredible ineptitude with python (an inability to find comprehensive for Civ4's python functions) is causing me problems.
Using onCombatResult . . .
1. I need to get the location (iX, iY) of the victorious unit that triggered onCombatResult.
2. I need to use CyMap().plot(iX, iY).changeCulture (pWinner, 2, False) to alter the culture of the tile the battle was found on.
Molybdeus Jul 17, 2007, 10:23 PM I'm currently using the following code in CvEventManager.
def onCombatResult(self, argsList):
'Combat Result'
pWinner,pLoser = argsList
playerX = PyPlayer(pWinner.getOwner())
unitX = PyInfo.UnitInfo(pWinner.getUnitType())
playerY = PyPlayer(pLoser.getOwner())
unitY = PyInfo.UnitInfo(pLoser.getUnitType())
iX = unitx.getX()
iY = unitx.getY()
CyMap().plot(iX,iY).changeCulture(playerX, 2, False)
if (not self.__LOG_COMBAT):
return
if playerX and playerX and unitX and playerY:
CvUtil.pyPrint('Player %d Civilization %s Unit %s has defeated Player %d Civilization %s Unit %s'
%(playerX.getID(), playerX.getCivilizationName(), unitX.getDescription(),
playerY.getID(), playerY.getCivilizationName(), unitY.getDescription()))
It doesn't seem to be working. :(
primordial stew Jul 18, 2007, 12:02 AM Doesn't case matter? If so, you have unitx.getX(), but earlier it is: unitX = ...
Anyway, the plot can be gotten directly from pWinner, so no need for unitX/x to exist. Just use this instead:
iX = pWinner.getX()
iY = pWinner.getY()
Molybdeus Jul 18, 2007, 10:00 AM Thanks. I finally got it to work. My naval mod can now proceed. :)
Zebra 9 Jul 18, 2007, 12:09 PM Why don't you just use the plot instance which is built into the unit.
def onCombatResult(self, argsList):
'Combat Result'
pWinner,pLoser = argsList
playerX = PyPlayer(pWinner.getOwner())
unitX = PyInfo.UnitInfo(pWinner.getUnitType())
playerY = PyPlayer(pLoser.getOwner())
unitY = PyInfo.UnitInfo(pLoser.getUnitType())
pWinner.plot().changeCulture(pWinner.getOwner(), 2, False)
if (not self.__LOG_COMBAT):
return
if playerX and playerX and unitX and playerY:
CvUtil.pyPrint('Player %d Civilization %s Unit %s has defeated Player %d Civilization %s Unit %s'
%(playerX.getID(), playerX.getCivilizationName(), unitX.getDescription(),
playerY.getID(), playerY.getCivilizationName(), unitY.getDescription()))
Sto Jul 18, 2007, 12:39 PM ... to alter the culture of the tile the battle was found on.
Perhaps there is a little mistake between Winner/Looser and Attacker/Defender . The tile where the battle was found on is the tile of the defender , not necessary the winner plot ( and probably more often the looser plot ) . However , i don't know an easy way to get this plot .
Tcho !
EDIT: pUnit.isAttacking() seems to be the good test to check who is the defender , but i've never used it .
|
|