EventManager onAirBomb or onAirStrike?

JDPElGrillo

Chieftain
Joined
Aug 20, 2015
Messages
72
Hello,

I'm currently working on a mod where Missiles can be loaded with Warheads (a new special unit class) to affect their behavior using getTransportUnit().

I'm working in the Event Manager, and I'm having some difficulty figuring out what callback to work with. From testing, it doesn't appear that Missiles (or other Air units) actually use onCombatResult, and onUnitLost doesn't store plot data, as unit.getX()/unit.getY() don't return useful values.

Ideally there'd be a callback for things like onBombard, onAirStrike, or onAirBomb, but they currently don't exist in the Event Manager. Is this where I'd have to learn to use the SDK, or am I missing something that would make this doable with just Python?

Thanks in advance! I'm sadly aware that I've only stumbled upon Civ4 modding recently, and that this forum has seen more active days. Searching through the archives has been extremely helpful, though, and I'm glad to have the resources available.
 
Well, turns out getTransportUnit() doesn't do what I thought it did. For that matter, I'm not entirely sure what it does do. Same goes for isCargo().

Instead, I've stumbled upon a working solution, but it's rather inelegant (and will require adding some more checks). It uses CyInterface().getMouseOverPlot() like so:

Code:
	def onUnitLost(self, argsList):
		'Unit Lost'
		unit = argsList[0]
		player = PyPlayer(unit.getOwner())
		pPlayer = gc.getPlayer(unit.getOwner())
##Biochemical Warhead Start ##
		if unit.getUnitType() == gc.getInfoTypeForString('UNIT_BIOCHEMICAL_WARHEAD'):
			if pPlayer.isTurnActive():
				pPlot = CyInterface().getMouseOverPlot()		
				if pPlot.isCity():
					city = pPlot.getPlotCity()
					if city.getOwner() != unit.getOwner():
						if city.getFood() >= 10:
							city.changeFood(-10)
						elif city.getPopulation() >= 2:
							iMaxFood = (city.getPopulation() * 2) + 20
							city.setFood(iMaxFood)
							city.changePopulation(-1)
##Biochemical Warhead End ##
##Incendiary Warhead Start ##
		if unit.getUnitType() == gc.getInfoTypeForString('UNIT_INCENDIARY_WARHEAD'):
			if pPlayer.isTurnActive():
				pPlot = CyInterface().getMouseOverPlot()		
				if pPlot.isCity():
					city = pPlot.getPlotCity()
					if city.getOwner() != unit.getOwner():
						if city.getProduction() >= 20:
							city.changeProduction(-20)
						else:
							city.setProduction(0)
							city.setOccupationTimer(1)
##Incendiary Warhead End ##
		if (not self.__LOG_UNITLOST):
			return
		CvUtil.pyPrint('%s was lost by Player %d Civilization %s' 
			%(PyInfo.UnitInfo(unit.getUnitType()).getDescription(), player.getID(), player.getCivilizationName()))

The problem that immediately came to mind is that if you select some Warheads, hover the mouse over an enemy city, and use the DELETE key to disband, it'll satisfy all of the conditions and reduce that city's food or production. Now I'm fairly certain that wouldn't have come up without me mentioning it, but it still bugs me. Any ideas as to how to close that loophole?
 
getTransportUnit does what it is supposed to do.
Get the Unique ID of the unit, not the Unit Type ID.
 
Back
Top Bottom