AI giving a city; the inner mechanism.

Manco Capac

Friday,13 June,I Collapse
Joined
Mar 1, 2010
Messages
8,051
First I have to say I'm bad beyond human imagination in regards to code reading...
I think I might found the string of code ruling the AI behaviour about city gift or liberating.

It was found in the following directory:

C:\Program Files\2K Games\...\Beyond the Sword\CvGameCoreDLL

The file in question is CvPlayerAI.cpp.

Spoiler :
if (!(GET_TEAM(getTeam()).isAtWar(GET_PLAYER((PlayerTypes)iI).getTeam())))
{
if (AI_getAttitude((PlayerTypes)iI) >= ATTITUDE_CAUTIOUS)
{
for (pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))
{
if (pLoopCity->getPreviousOwner() != ((PlayerTypes)iI))
{
if (((pLoopCity->getGameTurnAcquired() + 4) % 20) == (GC.getGameINLINE().getGameTurn() % 20))
{
iCount = 0;
iPossibleCount = 0;

for (iJ = 0; iJ < NUM_CITY_PLOTS; iJ++)
{
pLoopPlot = plotCity(pLoopCity->getX_INLINE(), pLoopCity->getY_INLINE(), iJ);

if (pLoopPlot != NULL)
{
if (pLoopPlot->getOwnerINLINE() == iI)
{
iCount++;
}

iPossibleCount++;
}
}


if (iCount >= (iPossibleCount / 2))
{
setTradeItem(&item, TRADE_CITIES, pLoopCity->getID());

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

ourList.insertAtEnd(item);

if (GET_PLAYER((PlayerTypes)iI).isHuman())
{
//if (!(abContacted[GET_PLAYER((PlayerTypes)iI).getTeam()]))
{
pDiplo = new CvDiploParameters(getID());
FAssertMsg(pDiplo != NULL, "pDiplo must be valid");
pDiplo->setDiploComment((DiploCommentTypes)GC.getInfoTypeForString("AI_DIPLOCOMMENT_OFFER_CITY"));
pDiplo->setAIContact(true);
pDiplo->setTheirOfferList(ourList);
gDLL->beginDiplomacy(pDiplo, (PlayerTypes)iI);
abContacted[GET_PLAYER((PlayerTypes)iI).getTeam()] = true;
}
}
else
{
GC.getGameINLINE().implementDeal(getID(), ((PlayerTypes)iI), &ourList, NULL);
}
}
}
}
}
}
}


All I can say if I understood...a big if rly...the green colored lines seem to be meaningful:

if (!(GET_TEAM(getTeam()).isAtWar(GET_PLAYER((PlayerTypes)iI).getTeam())))

seems to say not under war state...

pDiplo->setDiploComment((DiploCommentTypes)GC.getInfoTypeForString("AI_DIPLOCOMMENT_OFFER_CITY"));

I have seen the corresponding XML file and the AI diplo response was about city gift.

If I understand, a CAUTIOUS AI may give cities.

It looks like the orange section is about the inner mechanism...city condition for city gift?

May a new generation DanF5771-like people helps me...pleaaase.

I expect no answer, but if some people may give some pointers, I will glad to receive it. :D
 
What exactly do you want to know?

The AI might gift a city, if it's cautions OR better.

Not sure about the first line of the orange part (must be about the time when the city was acquired :dunno:), but the rest says that the AI might offer a city to another player, if this other player owns more than the half of the plots which are possibly in the cities FC.
 
What exactly do you want to know?

What I wish to understand are the exact conditions under which the gift city needs to be and what makes the AI willing to give it away. (Somewhat a formula if there is one, including the probabilistic variable).

The AI might gift a city, if it's cautions OR better.


Not sure about the first line of the orange part (must be about the time when the city was acquired :dunno:), but the rest says that the AI might offer a city to another player, if this other player owns more than the half of the plots which are possibly in the cities FC.

More than half the plots, uh? Like an interesting OP. :)
 
The_J is correct. About the first orange line: it looks like an efficiency thing, i.e. it makes sure the check is not made every turn, but every 20 turns for a given city, and no earlier than 16 (or 20?, I suck at math) turns after the city was acquired, which makes sense because IIRC a separate liberation check is made upon city acquisition. There is no randomness at all, at least not in this part of the code.
 
Thanks both of you taking time to unravel it.
BTW, if you are curious, the original thread wherein the question was asked has received a visit from DanF5771 itself (sheer coincidence :crazyeye:).
His input explained it all!

In a nutshell, the case is closed.
 
Back
Top Bottom