• We are currently performing site maintenance, parts of civfanatics are currently offline, but will come back online in the coming days (this includes any time you see the message "account suspended"). For more updates please see here.

CvPlayerAI.cpp and CvPlayer.cpp Discrepancy?

LPlate2

Warlord
Joined
Dec 27, 2018
Messages
299
Hi,

I'm trying to implement some diplomacy code and I currently have the following in CvPlayer.AI (there is more but the rest is commented out for my bughunting).
Code:
int CvPlayerAI::AI_getPolicyAttitude(PlayerTypes ePlayer) const
{
   int iDiploTheist = 0;
   for (int iI = 0; iI < GC.getNumTechInfos(); iI++)
   {
       if (GET_TEAM(getTeam()).isHasTech((TechTypes)iI))
       {
           if (GC.getTechInfo((TechTypes)iI).isDiploTheist())
           {
               iDiploTheist += 1;
           }
       }
   }
   return iDiploTheist;
}

Note: isDiploTheist is checking whether I've assigned a 1 value to bDiploTheist to the Tech in CIV4TechInfos.

The value from this is displayed due to CVGameTextMgr.cpp, which has the following,
Code:
       iAttitudeChange = kPlayer.AI_getPolicyAttitude(eTargetPlayer);
       if ((iAttitudeChange > 0) && (iPass == 0))
       {
           szTempBuffer.Format(SETCOLR L"%s" ENDCOLR, TEXT_COLOR("COLOR_POSITIVE_TEXT"), gDLL->getText("TXT_KEY_MISC_ATTITUDE_POLICIES", iAttitudeChange).GetCString());
           szBuffer.append(NEWLINE);
           szBuffer.append(szTempBuffer);
       }
       if ((iAttitudeChange < 0) && (iPass == 0))
       {
           szTempBuffer.Format(SETCOLR L"%s" ENDCOLR, TEXT_COLOR("COLOR_NEGATIVE_TEXT"), gDLL->getText("TXT_KEY_MISC_ATTITUDE_POLICIES_NEGATIVE", iAttitudeChange).GetCString());
           szBuffer.append(NEWLINE);
           szBuffer.append(szTempBuffer);
       }

The code did not seem to be doing what I wanted, so I created a mirror function in CvPlayer.cpp.
Code:
int CvPlayer::getDiploCountTest() const
{
   int iDiploTheist = 0;

   for (int iI = 0; iI < GC.getNumTechInfos(); iI++)
   {
       if (GET_TEAM(getTeam()).isHasTech((TechTypes)iI))
       {
           if (GC.getTechInfo((TechTypes)iI).isDiploTheist())
           {
               iDiploTheist += 1;
           }
       }
   }
   return iDiploTheist;
}
and exposed this to python.

The value that this calculates is being displayed to me on the main screen as I added some lines in onEndPlayerTurn to display it
Code:
       if pPlayer.isHuman():
           iPolicies = pPlayer.getDiploCountTest()
           CyInterface().addMessage(CyGame().getActivePlayer(),True,2,"Number of policies of interest is, %d" %(iPolicies),'',0,'',ColorTypes(8),0,0,True,True)

Within the game I've given myself some of the relevant techs.
The CvPlayerAI.cpp calculated result from AI_getPolicyAttitude(PlayerTypes ePlayer), when I'm looking at the foreign advisor is 0 (i.e. no values displayed). (Testing with writing positive or negative values directly showed that the CvGameTextMgr code is working as it should)
The CvPlayer.cpp calculates the result of getDiploCountTest() as 5 (which is the correct number given the techs that I'd given).

---
The code in the two files is essentially identical, so why doesn't CvPlayerAI.cpp work as I want it to?
Am I incorrect in thinking that GET_TEAM(getTeam()) should return the same result when used in CvPlayerAI.cpp and CvPlayer.cpp?
 
I am as stumped as you are. Are you sure that pPlayer in Python and eTargetPlayer are the same player?
 
Many mods, including Master of Mana, use a cache for CvPlayerAI::AI_getAttitudeVal. That cache may have to be invalidated (CvPlayerAI::AI_invalidateAttitudeCache) when a DiploTheist tech is acquired by any team. That said, the relations breakdown ("+5 from policies" or so) isn't cached, so this part should work correctly in any case.
 
I am as stumped as you are. Are you sure that pPlayer in Python and eTargetPlayer are the same player?

... and we have a winner. I was mistaken as to which was the CvPlayerAI and which was the ePlayer. I’ve changed GET_TEAM(getTeam()) to GET_TEAM(GET_PLAYER(ePlayer).getTeam()). It’s working better now.
 
Back
Top Bottom