pushMission not working for the AI

Bad Player

Deity
Joined
Oct 31, 2005
Messages
3,534
Location
(Bris)Vegas!
Hi, in CvEventManager.py of FFH2 I added some code for my scenario to make the AI and player units move towards a particular tile. I put the code in the section def onUnitCreated. The code makes the human ("Elohim" civ) move towards the target tile but the AI ignores the pushMission code. I tried to debug this by adding a line to create a barbarian hunter on the map if the program reads the section for one of the AI civs - and it does read it! However it seems to ignore the pushMission command.

To clarify, the onUnitCreated should run for any unit created by being built in a city or placed via WB (which is what I did to test the units) - as opposed to onUnitBuilt which is only for city built units.

My code is in blue.

Code:
	def onUnitCreated(self, argsList):
		'Unit Completed'
		unit = argsList[0]
		player = PyPlayer(unit.getOwner())
		pPlayer = gc.getPlayer(unit.getOwner())
		iChanneling2 = gc.getInfoTypeForString('PROMOTION_CHANNELING2')
		iChanneling3 = gc.getInfoTypeForString('PROMOTION_CHANNELING3')

		if unit.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_ADEPT'):
			iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_AIR'))
			if iNum > 1:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_AIR1'), True)
				if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_AIR2'), True)
					if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_AIR3'), True)
			iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_BODY'))
			if iNum > 1:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BODY1'), True)
				if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BODY2'), True)
					if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BODY3'), True)
			iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_CHAOS'))
			if iNum > 1:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHAOS1'), True)
				if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHAOS2'), True)
					if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHAOS3'), True)
			iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_DEATH'))
			if iNum > 1:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH1'), True)
				if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH2'), True)
					if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH3'), True)
			iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_EARTH'))
			if iNum > 1:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_EARTH1'), True)
				if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_EARTH2'), True)
					if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_EARTH3'), True)
			iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_ENCHANTMENT'))
			if iNum > 1:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENCHANTMENT1'), True)
				if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENCHANTMENT2'), True)
					if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENCHANTMENT3'), True)
			iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_ENTROPY'))
			if iNum > 1:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY1'), True)
				if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY2'), True)
					if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY3'), True)
			iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_FIRE'))
			if iNum > 1:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_FIRE1'), True)
				if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_FIRE2'), True)
					if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_FIRE3'), True)
			iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_ICE'))
			if iNum > 1:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ICE1'), True)
				if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ICE2'), True)
					if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ICE3'), True)
			iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_LAW'))
			if iNum > 1:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LAW1'), True)
				if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LAW2'), True)
					if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LAW3'), True)
			iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_LIFE'))
			if iNum > 1:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LIFE1'), True)
				if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LIFE2'), True)
					if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LIFE3'), True)
			iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_METAMAGIC'))
			if iNum > 1:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_METAMAGIC1'), True)
				if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_METAMAGIC2'), True)
					if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_METAMAGIC3'), True)
			iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_MIND'))
			if iNum > 1:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MIND1'), True)
				if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MIND2'), True)
					if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MIND3'), True)
			iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_NATURE'))
			if iNum > 1:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_NATURE1'), True)
				if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_NATURE2'), True)
					if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_NATURE3'), True)
			iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_SHADOW'))
			if iNum > 1:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SHADOW1'), True)
				if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SHADOW2'), True)
					if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SHADOW3'), True)
			iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_SPIRIT'))
			if iNum > 1:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SPIRIT1'), True)
				if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SPIRIT2'), True)
					if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SPIRIT3'), True)
			iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_SUN'))
			if iNum > 1:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SUN1'), True)
				if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SUN2'), True)
					if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SUN3'), True)
			iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_WATER'))
			if iNum > 1:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WATER1'), True)
				if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WATER2'), True)
					if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WATER3'), True)

		if unit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ELEMENTAL')):
			if pPlayer.getNumBuilding(gc.getInfoTypeForString('BUILDING_TOWER_OF_THE_ELEMENTS')) > 0:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), True)

		if unit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_UNDEAD')):
			if pPlayer.getNumBuilding(gc.getInfoTypeForString('BUILDING_TOWER_OF_NECROMANCY')) > 0:
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), True)

#UNITAI for Adepts and Terraformers
		if ((not pPlayer.isHuman()) and (not pPlayer.isBarbarian())):
			if unit.getUnitType() == gc.getInfoTypeForString('UNIT_DEVOUT'):
				numberterraformer=0
				for pUnit in player.getUnitList():
					if pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_DEVOUT'):
						if pUnit.getUnitAIType() == gc.getInfoTypeForString('UNITAI_TERRAFORMER'):
							numberterraformer = numberterraformer+1
				if 	numberterraformer<(pPlayer.getNumCities()*CyGame().getGlobalCounter()/100):
					unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_TERRAFORMER'))
				elif numberterraformer<3:
					unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_TERRAFORMER'))

			numTreeTerraformer=0
			if unit.getUnitType() == gc.getInfoTypeForString('UNIT_PRIEST_OF_LEAVES'):
				neededTreeTerraformer = 1
				if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_LJOSALFAR') or pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_SVARTALFAR'):
					neededTreeTerraformer = neededTreeTerraformer + (pPlayer.getNumCities() / 3)
				for pUnit in player.getUnitList():
					if pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_PRIEST_OF_LEAVES'):
						if pUnit.getUnitAIType() == gc.getInfoTypeForString('UNITAI_TERRAFORMER'):
							numTreeTerraformer = numTreeTerraformer+1
				if numTreeTerraformer < neededTreeTerraformer:
					unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_TERRAFORMER'))

			if unit.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_ADEPT'):

				bCanMageTerraform = false
				if pPlayer.countOwnedBonuses(gc.getInfoTypeForString('BONUS_MANA_WATER'), False) > 0:
					bCanMageTerraform = true
				elif pPlayer.countOwnedBonuses(gc.getInfoTypeForString('BONUS_MANA_SUN'), False) > 0:
					bCanMageTerraform = true

				numbermageterrafomer = (pPlayer.AI_getNumAIUnits(gc.getInfoTypeForString('UNITAI_TERRAFORMER')) - numTreeTerraformer)
				numbermanaupgrade = pPlayer.AI_getNumAIUnits(gc.getInfoTypeForString('UNITAI_MANA_UPGRADE'))

				bHasAI = false
				canupgrademana = false

				if pPlayer.isHasTech(gc.getInfoTypeForString('TECH_SORCERY')):
					canupgrademana=true
				elif pPlayer.isHasTech(gc.getInfoTypeForString('TECH_ALTERATION')):
					canupgrademana=true
				elif pPlayer.isHasTech(gc.getInfoTypeForString('TECH_DIVINATION')):
					canupgrademana=true
				elif pPlayer.isHasTech(gc.getInfoTypeForString('TECH_ELEMENTALISM')):
					canupgrademana=true
				elif pPlayer.isHasTech(gc.getInfoTypeForString('TECH_NECROMANCY')):
					canupgrademana=true


				if numbermanaupgrade == 0:
					unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_MANA_UPGRADE'))
					bHasAI = true
				if canupgrademana:
					if (pPlayer.countOwnedBonuses(gc.getInfoTypeForString('BONUS_MANA'), False) > (numbermanaupgrade * 2)):
						unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_MANA_UPGRADE'))
						bHasAI = true

				if bHasAI == false:
					if bCanMageTerraform:
						if numbermageterrafomer < 2:
							unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_TERRAFORMER'))
							bHasAI = true

				if bHasAI == false:
					pPlot = unit.plot()
					if (pPlayer.AI_getNumAIUnits(gc.getInfoTypeForString('UNITAI_MAGE')) < (pPlayer.getNumCities() / 2)):
						unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_MAGE'))
					elif pPlot.area().getAreaAIType(pPlayer.getTeam()) == AreaAITypes.AREAAI_DEFENSIVE:
						unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_MAGE'))
					else:
						unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_WARWIZARD'))
		
[COLOR="Blue"]
		if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_BANNOR'):
			unit.getGroup().pushMission(MissionTypes.MISSION_MOVE_TO, 67, 28, 0, False, False, MissionAITypes.NO_MISSIONAI, unit.plot(), unit)
		if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_ELOHIM'):
			unit.getGroup().pushMission(MissionTypes.MISSION_MOVE_TO, 67, 28, 0, False, False, MissionAITypes.NO_MISSIONAI, unit.plot(), unit)
		if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_KURIOTATES'):
			unit.getGroup().pushMission(MissionTypes.MISSION_MOVE_TO, 67, 28, 0, False, False, MissionAITypes.NO_MISSIONAI, unit.plot(), unit)
		if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_LUCHUIRP'):
			unit.getGroup().pushMission(MissionTypes.MISSION_MOVE_TO, 67, 28, 0, False, False, MissionAITypes.NO_MISSIONAI, unit.plot(), unit)
		if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_LJOSALFAR'):
			unit.getGroup().pushMission(MissionTypes.MISSION_MOVE_TO, 67, 28, 0, False, False, MissionAITypes.NO_MISSIONAI, unit.plot(), unit)
			#cf.addUnit(gc.getInfoTypeForString('UNIT_HUNTER'))[/COLOR]
		
		


		if CyGame().getWBMapScript():
			sf.onUnitCreated(unit)

		if (not self.__LOG_UNITBUILD):
			return
 
Thanks for the tip, I tried but pushMoveToMission was doing the exact same thing as pushMission. I also tried putting the code into the onUnitBuilt section but again, it only affected the human player (Elohim) and not the AI civs! :confused:
 
Where is your unit.plot() defined?

Edit: nevermind, it's not the problem.
 
Not really your answer, but one word of advice.

That whole chunk of repetitive codes around 100 lines can be shortened to less than 10 lines.
Code:
			lCheckThis = ["AIR", "BODY", "CHAOS"]
			for item in lCheckThis:
				iNum = pPlayer.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_' + item))
				if iNum > 1:
					unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_" + item + '1'), True)
					if (iNum > 2 and unit.isHasPromotion(iChanneling2)):
						unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_' + item + '2'), True)
						if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
							unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_' + item + '3'), True)

Easier to edit when I want to add a 4th Promotion without modifying 10 times.
 
Platyping and isenchine - that code was written by Kael, I only added the blue code at the end.


isechine - when I read the code at the top it seems to define unit from argsList[0].

At the start of CvEventManager it has the line
'unitCreated' : CvEventManager.onUnitCreated.__get__(self,CvEventManager),
 
The problem is that after you push that mission, the AI checks its status in the DLL code and decides to do something else. If you want that sort of granular control over what particular units are doing, you have to run the checks on every turn. And I think this is in regards to your scenario, in which case this check should be put in the scenario python file instead of CvEventManager.
 
Thanks Tholal for explaining what's going wrong!!! :)

I think the work around I will try is to give a new promotion called StackofDoom in the onUnitCreated section and then somewhere else search all units for the StackofDoom promotion and if they have that promotion, then give them the pushMission command.

I am thinking that the def AI_unitUpdate section could be appropriate (in CvGameUtils.py) since it checks every unit anyway. It would be similar to the existing code: def AI_unitUpdate only checks barbarian units!
Code:
	def AI_unitUpdate(self,argsList):
		pUnit = argsList[0]
		pPlot = pUnit.plot()

		if pUnit.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_GIANT_SPIDER'):
			iX = pUnit.getX()
			iY = pUnit.getY()
			for iiX in range(iX-1, iX+2, 1):
				for iiY in range(iY-1, iY+2, 1):
					pLoopPlot = CyMap().plot(iiX,iiY)
					for i in range(pLoopPlot.getNumUnits()):
						if pLoopPlot.getUnit(i).getOwner() != pUnit.getOwner():
							return 0
			pUnit.getGroup().pushMission(MissionTypes.MISSION_SKIP, 0, 0, 0, False, False, MissionAITypes.NO_MISSIONAI, pUnit.plot(), pUnit)
			return 1

		if pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_ACHERON'):
			if pPlot.isVisibleEnemyUnit(pUnit.getOwner()):
				pUnit.cast(gc.getInfoTypeForString('SPELL_BREATH_FIRE'))

		return False




I do want to make the code work in the scenario file eventually but I'm keeping it super simple to start with until I have it all worked out.
 
Unfortunately I haven't been able to make pushMission/pushMoveToMission work - the AI seems to override the pushMission command! I tried putting the pushMission in def AI_MageTurn in the file CvGameUtils.py but that didn't work either. :(

Either I modify that code I made before to give the HELD promotion and teleport them one tile at a time towards the marshalling point (more coding work!) or I teleport them directly to the marshalling point (looks unrealistic).

Noone might know how to make pushMission override the AI in the dll possibly??
 
For anything that is not instantaneous you have to make sure the AI_unitUpdate function is returning "true" or "1" to tell the DLL that the unit's turn has been done by the Python. If you don't do this and it just hits the end of the function it will return the default value of 0 (which is functionally also "false") which tells the DLL that the unit's turn was not handled by the Python function. In that case the DLL will run it's AI code for the unit and most likely make it do something other than what you just told it to do. Note that there is a "return 1" after the mission is pushed in the code you posted above. You need to do the same thing.

Final Frontier (Plus or otherwise) uses AI_unitUpdate to make the AI's construction ships go build starbases (and for FFP, sensor stations). They AI does build starbases and there is nothing in the DLL that would get them to do so. Therefore I know that this function works for AI civilizations, not just barbarians.
 
In the code I forgot to paste the last line (which is after some #comments) which is return false . Are you saying that I need to change the return false to return true? BTW I notice in the BtS CvGameUtils.py, it is return false also.


This code works if I place a Bannor (AI player) archer on the map in WB - it puts barbarian rangers on the map (my debugging system).
Code:
	def AI_unitUpdate(self,argsList):
		pUnit = argsList[0]
		pPlot = pUnit.plot()

		#Test to see if program recognises Bannor archer
		if pUnit.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_ARCHER'):
			cf.addUnit(gc.getInfoTypeForString('UNIT_RANGER'))
		
		
		if pUnit.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_GIANT_SPIDER'):
			iX = pUnit.getX()
			iY = pUnit.getY()
			for iiX in range(iX-1, iX+2, 1):
				for iiY in range(iY-1, iY+2, 1):
					pLoopPlot = CyMap().plot(iiX,iiY)
					for i in range(pLoopPlot.getNumUnits()):
						if pLoopPlot.getUnit(i).getOwner() != pUnit.getOwner():
							return 0
			pUnit.getGroup().pushMission(MissionTypes.MISSION_SKIP, 0, 0, 0, False, False, MissionAITypes.NO_MISSIONAI, pUnit.plot(), pUnit)
			return 1

		if pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_ACHERON'):
			if pPlot.isVisibleEnemyUnit(pUnit.getOwner()):
				pUnit.cast(gc.getInfoTypeForString('SPELL_BREATH_FIRE'))

		return False


However this code which searches for units with the combat 1 promotion, doesn't place any rangers which is why I thought it didn't cycle through AI players (there are warriors with combat 1 at start of game for 2 civs).
Code:
	def AI_unitUpdate(self,argsList):
		pUnit = argsList[0]
		pPlot = pUnit.plot()
		#def AI_unitUpdate only searches barbarian units not AI or human players!
		
			
		#Test to see if program recognises the combat1 promotion Alexis and Charadon warriors have - it doesn't!
		if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_COMBAT1')):
			cf.addUnit(gc.getInfoTypeForString('UNIT_RANGER'))

etc
		return False



I made a SofD promotion which isn't recognised, just like the combat1 promotion isn't recognised by the program - do you know why that might be?? :confused:
 
AI gives that unit an another mission, depending of it's UNITAI.
Try to set UNITAI_UNKNOWN to the unit. And Unit will go at the plot and stay there for ages.
 
Back
Top Bottom