Referencing AI attitude in Python

Chronis

Warlord
Joined
Feb 3, 2011
Messages
102
I want to access the "you raized my city attitude adjustment" through python.
Mainly I just want to know if it is 0 or not and use that to determine
a response.

Any tips from those more experienced on how reference this variable?
 
PHP:
for iNumMemories in range(29):###29 = Number of Memory Infos; No idea, how to get dynamically
    OldMemory = pPlayer.AI_getMemoryCount(iNumOtherPlayer,iNumMemories)
    pPlayer.AI_changeMemoryCount(iNumOtherPlayer,iNumMemories,OldMemory+5)

That code increases every memory type by +5, from one player against a certain other player.
I'm not sure what value exactly iNumMemories is, but you should probably try gc.getInfoTypeForString("MEMORY_RAZED_CITY") (to be looked up in the LeaderheadInfos.xml).
 
I believe total number of memory types should be 33 now when I was doing the world builder.
But since he only needs a specific one, yeah no need to loop through all
 
Thanks that helps.

So If I wanted to count how many civs had razed a particular civ's cities would this work?

def checkRazed( self, iPlayer, bVerbose = True ) :
iCount = 0
for idx in range(0,gc.getMAX_CIV_PLAYERS()):
razedI = gc.getInfoTypeForString("MEMORY_RAZED_CITY")
if( not razedI == 0 ) :
iCount += 1​
return iCount​
 
razedI = gc.getInfoTypeForString("MEMORY_RAZED_CITY")
just gives you the index of the raze city memory, (if that is the correct one in the first place)

You still need to use AI_getMemoryCount to check how many memories of that he has.

And what is the point of bVerbose if you don't use it
 
So I checked the dll and found it is .value("MEMORY_RAZED_CITY", MEMORY_RAZED_CITY)


Got it to work with the code below. Thanks again for the help.

def checkRazed( self, iPlayer ) :
pPlayer = gc.getPlayer(iPlayer)
iCount = 0
razedI = gc.getInfoTypeForString("MEMORY_RAZED_CITY")
for idx in range(0,gc.getMAX_CIV_PLAYERS()):

RazedMemory = pPlayer.AI_getMemoryCount(idx, razedI)
if( not RazedMemory == 0 ) :
iCount += 1​
return iCount​
 
Tested it extensively and it works :)

Now if I could pester you with one final question I would be in your debt.

I am trying to also reference war weariness in python.

In the DLL it is referred to in the following manner.
int iWarWeariness = GET_PLAYER(eTargetPlayer).getModifiedWarWearinessPercentAnger(GET_TEAM(GET_PLAYER(eTargetPlayer).getTeam()).getWarWeariness(eTeam) * std::max(0, 100 + kTeam.getEnemyWarWearinessModifier()));

However when I try the following in python
teamI = gc.getTeam(playerbI.getTeam())
wwI = gc.getWarWeariness(teamI)

I get the following error "CyGlobalContexts object has no attribute"
 
Ok so I hit a wall. I hate to be so needy but I just spent several hours on this and accomplished nothing so if I could ask for one final moment of your time this will be my final request.

I am trying to reference war weariness in python

basically I am trying to duplicate this function from the source code
iNewWarWearinessPercentAnger +=
(GET_TEAM(getTeam()).getWarWeariness((TeamTypes)iI)

I want to determine if a civ has a higher war weariness then 50 with any other civ

gc = CyGlobalContext()
ct = CyTeam()

def checkWeariness( self, iPlayer ) :
pPlayer = gc.getPlayer(iPlayer)
iCount = 0
iWeariness = 0
for idx in range(0,gc.getMAX_CIV_PLAYERS()):

playerbI = gc.getPlayer(idx)
teamI = gc.getTeam(playerbI.getTeam())
iWeariness = (teamI.ct.getWarWeariness(idx))
if( iWeariness > 50 ) :
iCount += 1​
return iCount​

I get the error "CyTeam object has no attribute ct"
 
Perfect that did it.

Thank your both for all of your help.
I realize you help people here for no benefit to yourselves and
in your free time.

I greatly appreciate it. :goodjob:
 
The "ct" is wrong. The "teamI" is already a CyTeam.

So is, for that matter, is using idx in getWarWeariness since idx is a player index and that function wants a team index. Not only that but teamI is the team of player idx so it is trying, incorrectly, to check the war weariness of a team vs. its own team. Nowhere in that check is the team of the player ID that is passed to the function. So if the "ct" issue is fixed you are still just rying to check how many teams have more than 50 WW for fighting themselves (which should never happen).

And if you loop over getMAX_CIV_PLAYERS you should probably check to see if the player is alive before you try to use it. In this case, you should probably be looping over teams (getMAX_CIV_TEAMS, also checking to see if it is "alive") since if you hit a team with 2 or more players on it you will count it for each if the team has more than the specified amount of WW when looping over the players.

I suggest that what you probably want is to get the team, call it pTeam, for player iPlayer and pPlayer and use that as the CyTeam object. Looping over the teams, ignore the team that is itself and any teams that are not actually in use. Then use pTeam.getWarWeariness(idx). You don't need to get the team, or any player on it, for idx - just use idx directly in that call (you still want to check the team object to see if it is "alive").

So something like this:
Code:
gc = CyGlobalContext()

def checkWeariness( self, iPlayer ) :
	pPlayer = gc.getPlayer(iPlayer)
	iTeam = pPlayer.getTeam()
	pTeam = gc.getTeam(iTeam)
	iCount = 0

	for idx in range(gc.getMAX_CIV_TEAMS()):
		if (idx != iTeam) and gc.getTeam(idx).isAlive():
			iWeariness = pTeam.getWarWeariness(idx)
			if( iWeariness > 50 ) :
				iCount += 1
	return iCount
There is some chance this is the the opposite of what you want (you might want the number of teams that have > 50 WW from this civ instead of what it is above which is the number of teams for which this player/team has > 50 WW).
 
Thanks that is way better code then I had I will definitely use it.

This may be a dumb question but do you have any ideas on why

pTeam.setWarWeariness(idx, 0)

Does not work. I want so set war weariness to 0 for barbarian minor civs when they
spawn into full civs but the above code does not seem to do anything. No error just does not seem to work.

in CvTeam.h in the dll setWarWeariness is defined as
void setWarWeariness(TeamTypes eIndex, int iNewValue);
 
Back
Top Bottom