[PYTHON] onCombatResult

Molybdeus

Prince
Joined
Jul 30, 2006
Messages
528
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.
 
I'm currently using the following code in CvEventManager.

Code:
	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. :(
 
Why don't you just use the plot instance which is built into the unit.
Code:
	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()))
 
... 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 .
 
Molybdeus, I was just thinking about exactly this modification. Can you please verify that the Python code that is discussed here worked, especially with regard to those last distinctions between the attacker/defender and winner/loser? I want to be sure the right tile is adjusted.

Thank you!
 
Top Bottom