Attitude threshold for accepting Vassalage.

Afforess

The White Wizard
Joined
Jul 31, 2007
Messages
12,239
Location
Austin, Texas
I'm trying to add an attitude threshold for the AI, so that they won't accept vassals if they are angry with the leader. I think I added it right, and codeblocks compiles fine, but ingame, the AI still accepts vassalage, even if our relations are -100. The code I am looking at is CvPlayerAI.cpp, and is this section.

Code:
                                            if (!bOffered)
                                            {
                                                setTradeItem(&item, TRADE_VASSAL);

                                                if (canTradeItem((PlayerTypes)iI, item, true))
                                                {
                                                    ourList.clear();
                                                    theirList.clear();

                                                    ourList.insertAtEnd(item);

                                                   [COLOR=Blue] if (GET_PLAYER((PlayerTypes)iI).AI_getAttitude((PlayerTypes)iI) < ATTITUDE_ANNOYED )
                                                    {[/COLOR]
                                                        if (GET_PLAYER((PlayerTypes)iI).isHuman())
                                                        {
                                                            if (!(abContacted[GET_PLAYER((PlayerTypes)iI).getTeam()]))
                                                            {
                                                                AI_changeContactTimer(((PlayerTypes)iI), CONTACT_PERMANENT_ALLIANCE, GC.getLeaderHeadInfo(getPersonalityType()).getContactDelay(CONTACT_PERMANENT_ALLIANCE));
                                                                pDiplo = new CvDiploParameters(getID());
                                                                FAssertMsg(pDiplo != NULL, "pDiplo must be valid");
                                                                pDiplo->setDiploComment((DiploCommentTypes)GC.getInfoTypeForString("AI_DIPLOCOMMENT_OFFER_VASSAL"));
                                                                pDiplo->setAIContact(true);
                                                                pDiplo->setOurOfferList(theirList);
                                                                pDiplo->setTheirOfferList(ourList);
    /*************************************************************************************************/
    /** REVOLUTIONDCM_MOD                         02/04/08                            Glider1        */
    /**                                                                                              */
    /**                                                                                              */
    /*************************************************************************************************/
                                                                // RevolutionDCM start - new diplomacy option
                                                                AI_beginDiplomacy(pDiplo, (PlayerTypes)iI);
                                                                // gDLL->beginDiplomacy(pDiplo, (PlayerTypes)iI);
                                                                // RevolutionDCM end
    /*************************************************************************************************/
    /** REVOLUTIONDCM_MOD                         END                                 Glider1        */
    /*************************************************************************************************/                                                            abContacted[GET_PLAYER((PlayerTypes)iI).getTeam()] = true;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            bool bAccepted = true;
                                                            TeamTypes eMasterTeam = GET_PLAYER((PlayerTypes)iI).getTeam();
                                                            for (int iTeam = 0; iTeam < MAX_CIV_TEAMS; iTeam++)
                                                            {
                                                                if (GET_TEAM((TeamTypes)iTeam).isAlive())
                                                                {
                                                                if (iTeam != getTeam() && iTeam != eMasterTeam && atWar(getTeam(), (TeamTypes)iTeam) && !atWar(eMasterTeam, (TeamTypes)iTeam))
                                                                {
                                                                    if (GET_TEAM(eMasterTeam).AI_declareWarTrade((TeamTypes)iTeam, getTeam(), false) != NO_DENIAL)
                                                                    {
                                                                        bAccepted = false;
                                                                        break;
                                                                    }
                                                                }
                                                            }
                                                            }

                                                            if (bAccepted)
                                                            {
                                                                GC.getGameINLINE().implementDeal(getID(), ((PlayerTypes)iI), &ourList, &theirList);
                                                            }
                                                        }    
                                                    [COLOR=Blue]}
                                                    else
                                                    break;[/COLOR]
                                                }
                                            }

Everything in blue is what I changed. What exactly am I missing?
 
I haven't messed with the SDK at all, but just from the above chunk of code it looks like "getID()" might return the current player's ID (and "getTeam()" the current player's team).

Perhaps somebody who knows for sure will show up.
 
You may also have the comparison backwards: "< ATTITUDE_ANNOYED"
But, according to the python interface doc
Code:
 -1 = NO_ATTITUDE
  0 = ATTITUDE_FURIOUS
  1 = ATTITUDE_ANNOYED
  2 = ATTITUDE_CAUTIOUS
  3 = ATTITUDE_PLEASED
  4 = ATTITUDE_FRIENDLY
  5 = NUM_ATTITUDE_TYPES

So you are doing the processing only if they are furious or undefined (the attitude towards themselves may well be NO_ATTITUDE).
 
I haven't messed with the SDK at all, but just from the above chunk of code it looks like "getID()" might return the current player's ID (and "getTeam()" the current player's team).

Perhaps somebody who knows for sure will show up.

Can anyone confirm or deny this? I have no C++ experience, I just made this code from trial and error. (Mostly error.)
 
If this CvPlayerAI is offering to become the vassal of player iI, try this:

Code:
if (AI_getAttitude((PlayerTypes)iI) > ATTITUDE_ANNOYED )

This will cause it to only offer vassalage if they at least Cautious towards player iI.
 
If this CvPlayerAI is offering to become the vassal of player iI, try this:

Code:
if (AI_getAttitude((PlayerTypes)iI) > ATTITUDE_ANNOYED )
This will cause it to only offer vassalage if they at least Cautious towards player iI.

What about for the human player? I want the AI to reject the vassalage offer if the AI's attitude to the player is annoyed or worse.
 
AI_getAttitude() doesn't care whether the target player is human or not--it returns the AI's attitude toward them either way. I assume this function isn't called for humans in the first place, so you shouldn't need to check if "this player" is human or not.
 
Top Bottom