Python AI depending of UnitAiType

Chrill

Chieftain
Joined
Aug 19, 2002
Messages
26
Location
Sweden
I've posted this somewhere else but maybe someone here can help.

I liked The J's idea of adding python "AI" to tsentoms old python promotion. However I decided to toy around and try to improve the functions, focusing on what type of AI the unit is.

However I ran into some problems with the function: getUnitAIType
I put the following code in under onUnitPromoted(self, argsList): in eventmanager.

Code:
		if not pPlayer.isHuman():
			if (iPromotion<>gc.getInfoTypeForString('PROMOTION_SURVIVAL')):
				if not pWinner.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SURVIVAL')):
					if pWinner.canAcquirePromotion(gc.getInfoTypeForString('PROMOTION_SURVIVAL')):
						if pWinner.getUnitAIType(gc.getInfoTypeForString('UNITAI_COUNTER')):
							dice = gc.getGame().getMapRand()
							result = dice.get(4, "Gold")
							if ((result==1) or (result ==2)):
								pWinner.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SURVIVAL'),True)
								pWinner.setHasPromotion(iPromotion,False)
								return

however i got this error to occur on the line:
pWinner.getUnitAIType(gc.getInfoTypeForString('UNITAI_COUNTER')):

Python Argument Types in CyUnit.getUnitAIType(CyUnit, str)
did not match C++ signature(class CyUnit {value})

I was just wondering if anybody knows exactly what the problem is here? I sure cannot figure it out...
 
CyUnit.getUnitAIType() doesn't take any parameters, but you are passing in a PromotionTypes. Instead, it returns the UnitAITypes for the given unit which you can compare against your desired value:

Code:
if pWinner.getUnitAIType() [B]== gc.getInfoTypeForString('UNITAI_COUNTER')[/B]:

Also, there is a small bug in this code. If the promotion the unit just received is the one that enables them to acquire the Survival promotion, this code will illegally give the unit the Survival promotion. Try this:

Code:
		if not pPlayer.isHuman():
			iSurvivalPromo = gc.getInfoTypeForString('PROMOTION_SURVIVAL')
			if (iPromotion<>iSurvivalPromo):
				if not pWinner.isHasPromotion(iSurvivalPromo):
					if pWinner.canAcquirePromotion(iSurvivalPromo):
						if pWinner.getUnitAIType() == gc.getInfoTypeForString('UNITAI_COUNTER'):
							dice = gc.getGame().getMapRand()
							result = dice.get(4, "Gold")
							if ((result==1) or (result ==2)):
								pWinner.setHasPromotion(iPromotion, False)
								if pWinner.canAcquirePromotion(iSurvivalPromo):
									pWinner.setHasPromotion(iSurvivalPromo, True)
								else:
									pWinner.setHasPromotion(iPromotion, True)
								return

Finally, do you know whether or not the map rand is shared among players in a multiplayer game? I know that the Soren rand is, and you should use that one when you are using random numbers to alter game events. Otherwise you'll get OOS errors.
 
CyUnit.getUnitAIType() doesn't take any parameters, but you are passing in a PromotionTypes.

Mmmhh, baah...there's a function in CvUnitInfo, which takes a promotion type and returns a bool...confusion.

Also, there is a small bug in this code. If the promotion the unit just received is the one that enables them to acquire the Survival promotion, this code will illegally give the unit the Survival promotion. Try this:

[...]

Finally, do you know whether or not the map rand is shared among players in a multiplayer game? I know that the Soren rand is, and you should use that one when you are using random numbers to alter game events. Otherwise you'll get OOS errors.

Ups, i have to change both in my 4 promotions...happy changing...
 
Top Bottom