View Full Version : Changing AI attitude


gautam
Feb 08, 2006, 10:34 PM
Hi,

I am trying to change the AI's attitude towards the player in python but it seems like whatever I try it jsut doesn't work. I have the following code but it never gets into the if loop




def changeAIAttitude(self, iPlayer):

# change the AI attitude towards the active player
player = gc.getPlayer(iPlayer)

if(player.isHuman() == False):
player = gc.getPlayer(iPlayer)


# get the attitude of the AI to player
attitude = player.AI_getAttitude(gc.getPlayer(0).getID())
print "Change AI Attitude called"


# Never gets in here
# whatever the attitude - do something
if(attitude != AttitudeTypes.ATTITUDE_FURIOUS):
iAttitude = player.AI_getAttitudeExtra(gc.getPlayer(0).getID() )
print "Attitude"
print attitude

player.AI_changeAttitudeExtra(gc.getPlayer(0).getI D(), 100)
print "Attitude"
print player.AI_getAttitudeExtra(gc.getPlayer(0).getID() )

return


It never seems to go into the inner if loop. Also is there a function called AI_changeAttitude by any chance ? I didn't find it on
http://civilization4.net/files/modding/PythonAPI/

Are there any other ways to modify the AI attitude in runtime.

Thanks

Shqype
Feb 08, 2006, 11:15 PM
If anything it should be setAttitude....

gautam
Feb 08, 2006, 11:32 PM
Hi,

I searched the PyHelpers.py file and also the site http://civilization4.net/files/modding/PythonAPI/. The only attitude options are with get functions and the AI_changeAttitudeExtra(PlayerType eIndex, INT iChange) function. Nothing at all with set. Thats why I was wondering if there is a way to force a change of the AI attitude.

Thanks

snarko
Feb 09, 2006, 01:50 AM
This isn't what is causing your problem but you have "player = gc.getPlayer(iPlayer)" twice.


Weird that it doesn't get further than the if. You're comparing an int (attitude) to a string (AttitudeTypes.ATTITUDE_FURIOUS which is the same as "ATTITUDE_FURIOUS") so they should never be the same, thus always returning true because of the !.

What happends if you put a print between the if statement and where you give a value to iAttitude? Does it get printed?

gautam
Feb 09, 2006, 03:14 AM
I tried getInfoTypeFromString("ATTITUDE_FURIOUS") as well and it gave an error of some CyGlobalContext and ATTIDUE_FURIOUS not found or something.

But I will try what you asked and post soon.

Thanks