AI-Behavior

Ploeperpengel

academic precarity
Joined
Feb 2, 2006
Messages
4,748
Location
Berlin
I figured this might be useful for poeple trying to affect the AI with xml settings, this why I post it here.

Informative links:

http://forums.civfanatics.com/showthread.php?t=145867&highlight=dogpile

http://forums.civfanatics.com/showthread.php?t=177450

http://modiki.apolyton.net/index.php?title=LeaderheadInfos

Info added by Gerikes:

Here's what I was able to dig up. Some of it is pretty general, because the code is sometimes tough to read. So, I've given what I think is the best idea of what they do. If you want any more specific detail on anything just ask. I took the ones I thought would be most useful for war and peace.

iBaseAttitude:
Base diplomacy attitude (+/- value) toward another civ at any time.

iBasePeaceWeight:
Base weight that this civ values peace. Only affects the civ's attitude towards other AI's.

iPeaceWeightRand:
A random number from 0 to this number is added to their peace weight at the beginning of the game.

iWarmongerRespect:
The smaller of two AI civ's iWarmongerRespect value is added to each of the civ's attitude. So, a civ of -1 and a civ of 5 means that each civ will have a -1 towards each other.

iRefuseToTalkWarThreshold:
If the number of turns the AI is at war is less than this value, the AI will refuse to talk to another civ.
This value is doubled if the AI team was the one who declared war.

iMaxWarRand:
The chance that a civ might try to begin planning a war this turn. Every turn, the civ has a 1 in X chance of considering planning. The lower the number, the more likely they will consider to begin planning. If it does consider it, it will find the target it hates the most and start planning war on them. There is a chance that the AI will consider to begin planning but not find a valid target they actually want to attack. In this case, they will not start planning against anyone.

Once a civ does begins planning, I think it will declare war once it's planning is done. Five turns elapse after planning begins before the civ will declare a limited war (small skirmishes, etc.). Ten turns elapse after planning begins before the civ will declare a total war (much larger force used, puts more resources into the war).


iMaxWarNearbyPowerRatio:
The percentage of their total power a civ will use when determining if it's stronger than another country that is "nearby" (which I believe means they share the same continent). This only is used when determining if the AI will start a total war. Thus, a value of 200 means the AI will consider itself twice as strong than it really is when determine it's strength vs. another civ. An AI civ only declares war with another civ if it thinks it's stronger.

iMaxWarDistantPowerRatio:
Same as iMaxWarNearbyPowerRatio, but this applies to civ's that are not nearby (are not on the same continent).

iMaxWarMinAdjacentLandPercent:
Of the three "passes" used in checking if a total war will start to be planned, this is the first (after this comes checking if it's a nearby civ using the iMaxWarNearbyPowerRatio calculations, then if it's a far civ using the iMaxWarDistantPowerRatio calculations). This is a percent value. If the percent of an AI civ's total plots that are adjacent with another civ is greater than this value, then the AI civ will consider the other civ for a total war.

iLimitedWarRand:
This is like iMaxWarRand, but is for limited wars. Limited wars, being less risky, have a better shot of being started, so this number will for Civ4 be smaller than iMaxWarRand (since a smaller number means a better chance.

iLimitedWarPowerRatio:
Like iMaxWar____PowerRatio, this will give a percentage bonus to what the AI thinks of it's power when it's trying to determine if it's stronger than another. It doesn't seem as if an AI will declare a limited war against an enemy that isn't considered "nearby", so there only is one value for this.

iDogpileWarRand:
There's limited war, total war, and dogpile war. This works just like iLimitedWarRand and iTotalWarRand, except it will make the civ consider starting to plan a dogpile war. This means that the AI will attempt to start a war with a team whose power is low compared the AI civ's power AND to the power of teams that are currently at war with the possible target.

iMakePeaceRand:
The chances a civ will consider making peace with one of it's enemies. Every turn, the civ has a 1 in X random shot of deciding to try to make peace, where X is iMakePeaceRand. It will go through each team it's at war with and decide whether they want to try to declare peace. If they decide that they do, they go through the steps of declaring peace.

How they determine if they want peace.

1.) They have to be able to contact the enemy civ.
2.) AI_isChosenWar is true. This is true only if the AI's war plan against the team is not WARPLAN_ATTACKED or WARPLAN_RECENTLY_ATTACK. These are what a war plan against an enemy civ start as if the enemy civ was the one who declared war. After awhile, a war that a civ is in that is of the war plan WARPLAN_ATTACKED will eventually (after some turns) become one of the other war plans, which will allow this criterion to be met.
3.) The war counter is past 20. One point is added to the war counter every turn. I'm assuming that other factors add to the war counter as well.

If any one of the following is true, than they will try to make peace:
4a.) The war counter is over 50.
4b.) The war counter is over 30 (40 for a total war) and
The end war value for this team is between half of the end war value for the other team and double the end war value for the other team.
4c.) The war is a dogpile war and this civ is the only civ left at war with the enemy (the enemy is no longer being "dogpiled."

The end war value is a value that takes multiple factors in to come up with a number that represents how good of an idea it is to end a war against a specific team. The higher the number, the better the proposal of peace is. So, for 4b, if a team's end war value is too low, it doesn't gain as much as the other team from peace. However, I'm not sure why they would want to declare peace if their value is more than twice the others. My only thought is that if the other civ's end war value is really low, then in the process of making peace they can ask for some good stuff.


iDeclareWarTradeRand:
This seems to only have an affect on how an AI negotiates with other AI civs. It is the chance that an AI will try to make a trade with another AI to declare war on one of it's enemies. Every turn, for each AI player that the AI civ can talk with, it has a one in X chance of trying to make a trade for war with that player against one of the teams the ai civ is at war with.

iDemandRebukedSneakProb:
Every time an AI civ has one of it's demands rejected, there is a percentage chance that the AI will start planning a limited war against the rejecter. This is a percentage chance, so 100 means that the civ will always start planning after not reciving a demand.

iDemandRebukedWarProb:
This is the probability that a Civ will immediately declare war immediately after one of their demands are rejected. That would be unlike the last tag, but instead of being sneaky and start planning, then launch a war later, the civ instead declares war immediately.

iRazeCityProb:
The probability (percent) that the AI civ will raze a city upon conquering it, if they don't deam it keepable by many other factors.

iBuildUnitProb:
The probability (percent) that the AI will build a unit at a city.

The actual total probability is this number plus twice the amount of production experience a unit recieves at that city.

This total is then halfed if the Civ is considered to be having financial troubles.

This whole process is one in a few for determining if a city will make a unit. Here is the full list of criteria (if one of these is true, then the city will be set to build a unit):

1.) The civ is in a land war.
2.) The civ has less than 4 cities and the game has not progressed 60 turns yet.
3.) The unit probability test above passes.
3.) The civ is human and it is the first turn (I'm not sure why that code is there).


iBaseAttackOddsChange:
iAttackOddsChangeRand:

Every turn, the AI will set a variable that is their "attack odds change". This varaible is used to add or subtract from attack odds of a battle. I don't think this changes the actual odds of the battle per se, but instead will change what the AI THINK that the battle odds are, so that they are more or less willing to do attacks every turn.

The attack odds changed is calculated by adding the iBaesAttackOddsChange to the sum of TWO random numbers from 0 to the iAttackOddsChangeRand. I doubt you can make iAttackOddsChangeRand negative.
 
The problem is that alot of these tags have very tight limits. Some go from 0 to 2, others -2 to 2.

I think I changed every one of those values at least once. ;)
 
The Excel file I have from Isak has the upper and lower limits on the side. He knows more than I do!

edit - I have no way of attaching the file, but can email it if anyone wants it.
 
woodelf said:
The Excel file I have from Isak has the upper and lower limits on the side. He knows more than I do!

edit - I have no way of attaching the file, but can email it if anyone wants it.

Is it because it can't be attached due to the filename? You can't pull the "rename to .txt" trick :p

If not, then gerikes@gmail.com


I'll try to make a really value that's outside the limit and step through the code using the debugger. I should be able to see if at any time the limits cause changed to my value.
 
woodelf said:
Email away Gerikes. Let me know how you make out.

I changed Akabar's iMaxWarRand to 1 (the min in the excel spreadsheet said it was 50). When the code got to where it gets that value, it was still 1 (meaning, every time it checked for total war, it would pass, since it was a 1 in 1 chance). So, there are no limits. I think the min and max on the spreadsheet are just the minimum and maximum values found in the vanilla game.
 
Ploeperpengel said:
Ah good. In this case I will play with negativ ipeaceweights as well. Or am I to hasty?

You can make the base peace weight negative, but don't make any values with "rand" in the name negative.

All the "rand" values are put into a random number generator, which generate random numbers from 0 to that number. All those number are converted to unsigned long variables (and because of the way binary numbers work, a negative signed integer would be equivelant to a VERY high positive unsigned integer). So, you'd be getting random values in the thousands.

So, for the peace weights, if you want to have a range of -5 to -3, don't make the base -3 and the rand -2! Make the base -5 and the rand 2.
 
Oh, I was looking more into the "nearby" factors. I was wrong about how "nearby" means just on the same continent. That's what I thought the function AI_isLandTarget meant, but not quite.

What it DOES do is check is see if

1.) The two teams have at least 8 adjacent plots, or
2.) The possible enemy team has any cities in any of the ai Civ's "Primary" areas.

A primary area is any area that has at least 3 cities or the civ's capital city. However, I'm still at a loss as to what an "area" is. I know it's a collection of plots, but I'm not sure how the size of the collection of plots are considered, or if areas overlap or whatever. I've always kind of ignored this since area mostly has to do with how the AI works, and I never really dealt much with the AI.

Edit Ok, I figured out what an area is. Bad news. An area is a collection of plots that are either land or water. Thus, an ocean is one area. A continent is another area. If you have a two large continents with oceans dividing them but at one point they come within one oceanic plot of each other, then the each continent has it's own area. If you go into worldbuilder and put a land plot there, both of those land masses become part of one area.

This is important for AI because that one small change will completely change how the AI thinks of a civ as "local" or not. So, it looks like a "nearby" enemy is an enemy on the same continent after all.
 
Top Bottom