My personal thread: Clarification of certain game mechanics

Typical motive with a timer and a randomizer.

  • Will start asking only their favorite civic once they are running it themselves.
  • If you can't swap to that civic for whatever the reason, the contact won't even be started. Thus no randomizer running yet...
  • Gives +1 attitude by agreeing.
  • Subjected to memory decay, thus can be forgotten if unlucky.
 
Typical motive with a timer and a randomizer.

  • The bully won't ask tribute if there is no way to DoW the victim or is actually preparing a sneak attack (take it as WHEOOH or simply plotting war as there is no way to diferentiate type of wars).
  • The bully bullies those with whom it is ANNOYED or lower. Every leader behaves the same way.
  • The bully bullies under additional condition it has more combined powers (its power plus vassals) than the victim+its vassals+pact defense allies (and their vassals).
  • When asking gold, the amont of gold is determined on two stages. The first sees if you got more than 50 gold in treasury. If less, no tribute is triggered. The second stage compares your treasury minus 50 gold to the function AI_goldTarget() and chooses the smallest of the both.
  • The amount of gold is always rounded down at the unit. 56 is impossible, but 50, yes.
  • When asking a map, it is because you have a map worth over 100 points. The worth is calculated through AI_mapTradeVal().
  • When asking for a tech, the chosen tech is random BUT a bully NEVER asks for a monopoly tech. :)
  • When demanding a resource, the bully chooses one randomly amongst your surplus. :)

How does AI_goldTarget() work?

It's complicated. If you really want to know, see hereunder:

Spoiler :


At the base, there is no AI_goldTarget() for the first 40 turns. Of course, it doesn't matter for an Ancient start game, but if starting industrial, it's good.

Once the timer has hit the 40th turn, the function starts calculating the amount of gold the AI is willing the share. That function used for the tribute amount is somehow what the AI targets to have in its treasury. Thus, when asking a tribute, the AI only wants to get that goal done in the easy way.

The base gold is determined with number of cities, turns and the total population:

GoldStep1=3*NationCities+NationPopulation/3+NumOfTurnsSinceStart/2

It is interesting to note the NumOfTurnsSinceStart should be adjusted according to gamespeed.


Then a multiplier is added to adjust along the gamespeed:

The three XML variables are:
<iResearchPercent>67, 100, 150, 300</iResearchPercent>
<iTrainPercent>67, 100, 150, 200</iTrainPercent>
<iConstructPercent>67, 100, 150, 300</iConstructPercent>

And the values inside are ordered Quick, Normal, Epic And Marathon

The modifier is simply (the brackets [] are meaning you need to round down):

Modifier=[<iResearchPercent>+<iTrainPercent>+<iConstructPercent>]/3

Then,

GoldStep2=[GoldStep1*Modifier/100]

Spoiler :
Then, if the AI is plotting war (we can rather skip that part because sneak attack makes the bully to avoid tribute demands)

GoldStep3=1.5*GoldStep2


Then,

Spoiler :
if the AI is at the final stage of a cultural victory or ended the tech tree (in other words put the science slider at 0%):

GoldStep4=10*GoldStep3

Normally, can be ignored.


Then,
Spoiler :

an almost impossible to judge factor that adds to the last step of gold:

GoldStep5=GoldStep4+AI_goldToUpgradeAllUnits

If the AI is not confronted to any active war, AI_goldToUpgradeAllUnits is divided by two for being less important in peace times. AI_goldToUpgradeAllUnits is more or less the cost of upgrading all upgradable units available.


Then,

Spoiler :
If the bully has an active corporation (a corporation under SP is inactive per definition),

SpreadCost=[50*(100+Inflation)/50]
GoldStep6=GoldStep5+SpreadCost


Quite often, AI_goldToUpgradeAllUnits will result in strong AI treasury.

 
Typical motive with a timer and a randomizer.

The tech chosen by the dealer as an offering and the one desired is completely random. No particular attention to avoid monopoly. Not that's important given nothing stops to refuse the deal. Of course, rare are the moments where both techs will be worth the same. The difference will be added in gold where if the AI is under financial crisis, gold is valued more by them and they'll ask less. But that happens to the human in a strange way too...

Where there is an equalizer for an AI-human trade, AI-AI trade offerings are most lenient.
Inequal trades are accepted if the value is at least one increment over 2/3 of the worth of one side.
 
A typical motive with a timer and a randomizer.

In a deal of resource between a human versus an AI, the deal must be fair or at the disadvantage of the human.

Between two AI's, there is no importance given to the value of the resource. Thus the particularly revolting cases of, say, iron for a dye.

Code:
if (!(GET_PLAYER((PlayerTypes)iI).isHuman()) || (AI_bonusTradeVal(eBestReceiveBonus, ((PlayerTypes)iI), -1) >= GET_PLAYER((PlayerTypes)iI).AI_bonusTradeVal(eBestGiveBonus, getID(), 1)))
 
Typical motive with a timer and a randomizer.

This one really has nothing special.
 
This is not a typical motive with a timer and a randomizer.

First of all, bribery is only valid in the AI realms. An AI will never bribe you onto some third party (his foe against which it is battling) in the base BTS. Bribery or dogpiling is an AI process that is calculated each turn with its own RNG to happen, but in a diminishing manner. In the few first turns, the dogpiler has great chance to bribe someone and as the war stretches in time, the odd of this happening shrinks hard.
The concept of timer was established for various reasons:
  • Avoid mass trading in a way it gives no chance to the human player
  • Avoid to be nagged all the time by the AI
  • Avoid accumulating huge amounts of diplo hits
  • Others
In bribery, if the dogpiler has hit the lucky dice side and if there is an actual valid third party, the "pact" will necessarily succeeds.

Once the war has begun between the potential dogpiler and its foe, the main factors that determine the bribe odd are the XML variable iDeclareWarTradeRand and the war counter, which is the number of turns since the war has started.

Interestingly, iDeclareWarTradeRand is 40 for all leaders but Pacal. Pacal has 60 instead. Perhaps, the devs knew Pacal was a natural tech leader, allowing him to easily bribe...who knows?

Now, for the war counter ( AI_getAtWarCounter() ), the moment of the declaration has a value of 0 and the turn after is labeled 1 and so on. Just to give a reference.

The RNG for initiating a bribe is calculated via that little part of code:

Spoiler :
Code:
	if (!(GET_PLAYER((PlayerTypes)iI).isHuman()) || !(abContacted[GET_PLAYER((PlayerTypes)iI).getTeam()]))
									{
										int iDeclareWarTradeRand = GC.getLeaderHeadInfo(getPersonalityType()).getDeclareWarTradeRand();
										int iMinAtWarCounter = MAX_INT;
										for (iJ = 0; iJ < MAX_CIV_TEAMS; iJ++)
										{
											if (GET_TEAM((TeamTypes)iJ).isAlive())
											{
												if (atWar(((TeamTypes)iJ), getTeam()))
												{
													int iAtWarCounter = GET_TEAM(getTeam()).AI_getAtWarCounter((TeamTypes)iJ);
													if (GET_TEAM(getTeam()).AI_getWarPlan((TeamTypes)iJ) == WARPLAN_DOGPILE)
													{
														iAtWarCounter *= 2;
														iAtWarCounter += 5;
													}
													iMinAtWarCounter = std::min(iAtWarCounter, iMinAtWarCounter);
												}
											}
										}
										
										if (iMinAtWarCounter < 10)
										{
											iDeclareWarTradeRand *= iMinAtWarCounter;
											iDeclareWarTradeRand /= 10;
											iDeclareWarTradeRand ++;
										}
										
										if (iMinAtWarCounter < 4)
										{
											iDeclareWarTradeRand /= 4;
											iDeclareWarTradeRand ++;
										}

A mention about type of wars:
AI has several types of war and will change its behaviour according to the type of war. When the dogpiler is a victim of another AI DoWing on him/her, the type of war can easily be deduced as a defensive war ( WARPLAN_ATTACKED ). And the diplo web will show you without doubt that fact. Nevertheless, if the dogpiler has initiated the war, you can't know for sure which type of war (s)he has chosen. The WARPLAN_DOGPILE deflates the chance of a bribe. Sadly, there is no particular way to know without cheating. But a feeble way to exclude dogpiling war is when the dogpiler has equal or more than 50% more power than its potential victim.

Here starts the calculus:

If WARPLAN_DOGPILE, then the war count is approx. doubled, meaning :

Code:
ModifiedWarCount=WarCount*2+5

But we can ignore this because in practice, it is not doable to guess this type of war.
And if the potential dogpiler is a victim, then that part is easily guessed irrelevant. Again, interestingly, that modification for dogpilers turns out to be a penalty...

Then, if the war count is 0 to 9,

Code:
Odds=([COLOR="Green"][B]iDeclareWarTradeRand[/B][/COLOR]*WarCounter/10) +1

No rounding at all because all from 0 to 9, it doesn't generate any float number...
We see earlier in the WarCount, stronger is the chance of a bribe

Then, for the three first turns following the war (that is turn 0,1,2,3)

Code:
Odds2=[(Odds/4)]+1

Now, there is a rounding effect and it is rounding down.

At last, the Odd number isn't the real odd. Just like the randomizers, it is the number of faces of a virtual dice. For instance, if it gives a number of 40, then the real odds are 1/40=2.5% per turn.
In Summary, for the 52 leaders except Pacal II, the odds are:


After the third turn of war, the odds dramatically plummet.
After the 10th turn of the war, the odds remain constant for the rest of the war, that is 2.5% chance per turn the warmonger bribes someone along.

Once the dice says to the dogpiler "Go for it, bring more in the party!", the code chooses amongst the AI who can be an ally. The attitude of the dogpiler to that potential ally has a component in skewing that AI over another to be an ally, but the choice is still random.

Now remains the deal part...

To recapitulate:
  1. The game rolls for the dogpiler its will to initiate a bribe
  2. Then, the dogpiler chooses who will be its partner in war.
  3. Finally, the deal is set according to several steps.
 
Once I complete the last post, this completes the whole set of AI diplomatic moves initiated by the AI itself.
 
Damn damn damn! Will it finish once for all? Can't wait to work on Unit disband mechanics. :mad::mad:
 
Tachywaxon rocks.

Best part of this thread seriously was "there a 2000 lines of code about this..."
Spoiler :

Trololol, you really thought I'd put this here.

Big lols for that one Tachy.

What I don't understand about this thread, though, is, what this gives you, but I don't question you, but find it simply amazing, that you still find the drive to learn something about a game, you mastered long ago, and that you're giving back to the community, as life means having to adapt, while humanity is about people influencing each other.

You score in both, Tachywaxon.

Your friend,

Seraiel
 
ContactRands

From your post #173:
The virtual dice number of faces. For instance, if Catherine has 50 for demands of tribute, that means once the timer is expired, she has 1 chance out of 50 per turn to nag you for an annoying whimsical demand. Make the division and you have the odd percentage per turn for that particular motive to happen.


One thing I find odd, and that I hope you can clear up for me is this: Doesn't the RNG include zero (0) when rolling the dice?

The reason for my question is that I see Mansa Musa's ContactRand for Technology-trades is 1 (ONE). And that means he would ask to trade techs with regular intervals based on the timer only (1 out of 1 is 100% chance).

If the RNG included zero, Mansa would only have a 50 % chance to initiate a tech-trade. RNG dice = {0,1} = (N=2). That would also mean Catherine doesn't have a 2 % chance (N=50) but a 1.96 % chance (N=51) of coming up with this annoying whimsical demand of hers.

As I am currently working on adjusting the CIV4LeaderHeadInfos.xml to fit with playing Marathon speed, I would like to adjust these values to make them as equal as possible to Normal speed. (1 TimeUnit (TU) = 1 turnNormal = 3 turnsMarathon). Which means I would like to make the percent-chances of ContactRands and MemoryDecays as equal as possible to Normal speed (per TimeUnit) playing Marathon.



Yours Sincerely

Kjotleik of Norway :)
 
@Kjotlek

Hehe. How you figure it out is the same pattern as I did long ago (in fact not so long ago...half a year ago). Until a strong top dog (i.e. DanF5771) corrected me that the virtual dice of, say, 50 faces is listed from the value 0 to 49. Just like in computer engineering, we start counting at zero instead of one.

It looks like Mansa will bug you all the time once the timer expires. I did not noticed it. But I vaguely recalled someone had a value of 1. :)

============

What I don't understand about this thread, though, is, what this gives you, but I don't question you, but find it simply amazing, that you still find the drive to learn something about a game, you mastered long ago, and that you're giving back to the community, as life means having to adapt, while humanity is about people influencing each other.

Just like normal people, I do find reading the code exhausting to read, but most of the time, it is a relaxing moment of mine. As the time goes, we grow to need less reward/retribution from the community. Especially when I started fiddling in Story&Tales subforum, oh yeah, never expect any reward, retribution nor respect there. An immense learning moment somehow...I guess. :)

Also, it always bugged me there is no a place that gather all concepts that make Civ4. What is particular with Civ4 compared to most game is the huge amount of concealing done by the devs. I suppose they expected their fans to play blind, but there are so many random decisions and possibilities hidden in the lines of code. A game, for instance, like the HoMM serie, doesn't hide that much of a secret and it doesn't take long to figure it all out, but Civ4, even after a frigging 8 years still hides more arcanes. That's insane!
It's a treasure hunt...
 
@Kjotlek

Hehe. How you figure it out is the same pattern as I did long ago (in fact not so long ago...half a year ago). Until a strong top dog (i.e. DanF5771) corrected me that the virtual dice of, say, 50 faces is listed from the value 0 to 49. Just like in computer engineering, we start counting at zero instead of one.

It looks like Mansa will bug you all the time once the timer expires. I did not noticed it. But I vaguely recalled someone had a value of 1. :)


Ah, so a value of 50 DOES mean from 0 to 49, not 0 to 50. Thanks. I think I will just have to change the value of Mansa Musa to 2, then. Just to make it a bit more "realistic," if you can ever use such a word about CivIV...:D

I really don't think having a random value equalling 100% is something that should be in a game at all... :mad:



Yours Sincerely

Kjotleik of Norway :)
 
A pleasure. Don't hold yourself if you got more questions. Even if I can't unveil the riddle, I still got some hidden trump cards up my sleeves.

Or use Modding subforums, but it's quite hard to get replies there. I can't put my finger between laziness or simply ignoring non-modder questions. Not to mention they are few into the SDK.
 
A pleasure. Don't hold yourself if you got more questions. Even if I can't unveil the riddle, I still got some hidden trump cards up my sleeves.

Or use Modding subforums, but it's quite hard to get replies there. I can't put my finger between laziness or simply ignoring non-modder questions. Not to mention they are few into the SDK.


You seem to know this stuff, so I'll keep on reading in this thread when I got the time. And If a question arises I will ask it.

But now it's sunday, and almost 8 am here in Norway. So I'm off to dig my head into converting all those numbers in the beforementioned xml-file. I use the Better BUG AI mod as base, so it's not exactly compatible with standard BTS 3.19 (more tags that seems to give AI-leaders values to determine which Victory-Conditions they shall pursue... oh, my...). SDK is a bit too much for me right now...

Happy weekend!


Logging off...



Yours Sincerely

Kjotleik of Norway :)
 
Also, it always bugged me there is no a place that gather all concepts that make Civ4. What is particular with Civ4 compared to most game is the huge amount of concealing done by the devs. I suppose they expected their fans to play blind, but there are so many random decisions and possibilities hidden in the lines of code. A game, for instance, like the HoMM serie, doesn't hide that much of a secret and it doesn't take long to figure it all out, but Civ4, even after a frigging 8 years still hides more arcanes. That's insane!
It's a treasure hunt...

Yes, Civ 4 is the ultimate riddle :D
 
Your eternal enthusiasm is also a riddle. Mine is depleted. Because of stupid DoC mod.
Anyways, come to think, I shall fix that error a bunch of people (including DanF in a PM) pointed me out. Lazy me....

EDIT: In fact, there is no mystery; you're on ectasy!
 
Top Bottom