AI to Player Diplomacy in the turn order Edit
AI to Player Diplomacy covers all interactions started by the AI player towards the human player. After the Next Turn button was pressed, all AI players cast spells, then move their troops according to the turn order. Whether they can attack another player, or cast a hostile spell is controlled by the Hostility variable. After all AI players finished their turns, the AI players might show up in the mirror and talk to the human player. This might be a Diplomatic Reaction's message part, or a proposal for a trade or treaty. After all AI players used or passed their chance to talk, end of turn adjustments of temporal diplomatic variables happen, and other turn based diplomacy effects, like natural relations gravitation happens, finally the turn ends and the human player's new turn starts. In the 1.50 unofficial patch, the AI players get to cast spells and move troops on an individual basis, so the first AI player casts spells, and moves troops, then the second, etc. In 1.40 and earlier, the AI players all took their turns simultaneously in a sense : First they all finished their spellcasting and issued orders to troops, then all troops moved in the order of their owner's turn order, by executing previously assigned orders, disregarding any change on the overland map cause by troops moving prior to them. As such, if two AI players decided to attack the human player's city, and the first one was successful, the second still proceeded with the attack, risking a war with an unintended other AI player. In the 1.40 patch, the AI is able to retract the move upon execution if there is a Wizard's Pact or Alliance with the target in place, however, it is not able to do so in case of a Peace Treaty or it being a target with no treaty status at all.
AI to Player Diplomacy is only valid towards the human player, and this process is completely skipped towards other AI players. Instead, the AI to AI Diplomacy process is executed.
AI to Player Diplomacy decision process Edit
For the rest of the explanation, we'll refer to the message stored from the human player's previous turn from a Diplomatic Reaction as the "queued Diplomatic Message" and its strength (the amount of change in Visible Relations it cause) as the "Strongest Event".
First, the AI checks if the human player has been banished. If yes, the entire process is skipped and the queued Diplomatic Message is cleared, because the human player is not present to talk to.
Secondly, the AI checks if there is Diplomatic Contact with the human player. If there isn't, the AI greets the player this turn instead of showing any queued Diplomatic Message, and considers Diplomatic Contact to be established. The greeting message is selected based on the AI player's personality, each personality having a set group of texts, without any overlapping. Third, the AI checks if the treaty status is Final War. This treaty status is unimplemented in the game, and if probably a leftover which was not removed when they copied over the system from Master of Orion, so this check never does anything. Then the AI checks another unused variable, and if it is nonzero, sets the queued Diplomatic Message to a message type that never normally appears in the game, and grants a gold reward towards the player. The trigger for this feature is not implemented, and although the text refers to a gold reward, it isn't awarded to the player. However, the 1.50 patch enables this event as a possible Diplomatic Reaction, which is able to grant the gold reward as well, although at the time the event is queued, not at the time the message appears on the player's screen. Next, the AI checks if the queued Diplomatic Message is a Declaration of War. If yes, no further decisions are made, and processing jumps to displaying the message immediately. Thanks to this jump the following bugs were not able to prevent Declarations of War from showing up, although they did prevent almost every other AI to Player interaction.
Before process continues to the meaningful parts of the decisions process,
is calculated. Lowest Interest refers to the smallest value of Peace Interest, Treaty Interest and Trade Interest. Note that adding Visible Relations really happens twice, and is not done through a multiplication of 2. This might be a bug.
If X>=-100, the rest of the procedure is skipped and the queued Diplomatic Message is cleared immediately. In order for X to be below -100, either the AI has to be exhausted from excessive treaty and trade offers in Player to AI Diplomacy, or the Visible Relation needs to be very low. Even in these cases, the AI also needs to be a low enough Personality Modifier to qualify for this extremely low limit. In other words, unless they AI is really hating the player or is annoyed by them, they'll not bother to consider any contact at all, either negative or positive. This is most certainly a bug, and the intended purpose of this check is unknown. Either is was supposed to only work for negative diplomacy, or it was supposed to check for X<=-100 to ignore the player instead of X>=-100. Whichever is the case, the 1.50 unoffical patch completely removes this check because the individual decisions afterwards all have their own, very similar checks, sometimes even two or three, making this one redundant and unnecessary.
Afterwards, the AI checks if the Strongest Event was negative. If yes, processing continues in Negative Diplomacy.
If the AI is currently at War with the player and random(1-100)+30<= Peace Interest then process goes to Peace Diplomacy. However, even if there is a war, if this random based check fails, process continues towards Positive Diplomacy, which is most certainly a bug. The unofficial 1.50 patch removes this check completely, instead during War, the process always continues by the Peace Diplomacy.
Next, if the Warning Counter is zero, Event Strength is increased by 3. Afterwards, if random(1-100)< Event Strength AND random(1-4)=1 the process continues towards Positive Diplomacy. This check was replaced in the 1.50 unofficial patch, see Positive Diplomacy for details.
If neither happens, the AI checks if they need to ask the player to Declare War on another AI player, but never proceeds with such a request, in fact, it is completely unimplemented, not even the text is available in the LBX files. Despite this, the 1.50 unofficial patch implements this request, see War Request.
In any of these cases, afterwards, if there is no queued message or offer, in other words the AI decided to remain silent, the Need for War check is ran towards the human player. Then, still only if the AI remained silent, including any message from the Need for War check, the AI will check if any unit is in the range of their cities, violating a Wizard's Pact or Alliance. If yes, they'll queue a warning message on first offense and execute a Diplomatic Reaction of strength -5, do nothing on second, and take a Break Treaty action on the third. This action is executed twice, once for both involved players, meaning both are considered the "guilty" party for the broken treaty. These have to be consecutive turns where the check occurs, if there is any turn without a violating units, it resets to the first warning. If there is no treaty in place, but there are units in range of the AI's towns, there is a 5% chance to generate a Diplomatic Reaction with a strength of -(random(1-5)), which has a 20% chance to contain a warning message, and 80% chance to contain no message at all.
Negative Diplomacy Edit
First, if random(1-75)>=abs(Greatest Event) then the queued Diplomatic Message is cleared and no further action is taken. The 1.50 unofficial patch changes this to random(1-25) making sure that strong negative events won't ever go unnoticed. In all versions of the game however, if the Warning Counter is nonzero, this check is skipped and the game proceeds with Negative Diplomacy.
Next, If the Strongest Event is zero, the entire following process is skipped. The 1.50 patch removes this check because it does nothing : Negative Diplomacy cannot happen unites the strongest event was negative!
If there is a War ongoing, proceed to Peace Diplomacy instead. However, negative events are ignored during war, so Peace Diplomacy will not get entered through Negative Diplomacy anyway, even though the two share a procedure.
After this, is Visible Relation is<=-75 immediately Declare War and queue a war declaration message. Otherwise, continue.
Check Hidden Relation + Visible Relation + Personality Modifier - random(1-100) + Treaty Interest <=-100. If false, do not clear the queued message, but end the procedure. The message (warning) will be shown, but there are no further consequences at all. In the unofficial 1.50 patch, this check is changed to Hidden Relation + Visible Relation + Personality Modifier - random(1-100) + Treaty Interest/2 <0 instead, making it much more likely for the warning to matter, as the original formula was far too forgiving. As it contains the temporal variable, Treaty Interest, it is actually much more likely for the AI to be unforgiving if they have been bombarded with offers in Player to AI Diplomacy previously until they got annoyed by it and ended the audience. The patch halves the influence of this effect, but it is still relevant.
Next, check the Warning Counter. If it is still zero, then set it to 1 and there are no further consequences, but the warning message is, of course, not cleared and will be shown.
Otherwise, increase the Warning Counter by one. If there is a Wizard's Pact or Alliance in effect, perform a Break Treaty action. The guilty party will be the AI player, despite whichever provocation caused this to happen. In the 1.50 patch, the queued message will be upgraded from "stop doing X, or I break the treaty" to "Due to X, our treaty is broken". In earlier versions, a generic "I've decided to break the treaty (no reason at all given)" message is used instead.
If there was no treaty to break, abs(Greatest Event)- (Personality Modifier/2) > random(1-100) is checked. If true, Declare War immediately and replace the queued message with a generic war declaration message. In the 1.50 unofficial patch however, a new formula is used here as well : if abs(Greatest Event)+4*(Warning Counter)>random(1-100) then War is declared. This new formula eliminates the effect of personality from this choice, as it already played a role in the previous check where the AI decided to just say the warning without any immediate consequence. If it already reached this point there is no need to still reconsider due to personality. More importantly, consecutive warnings now matter : While the old system allowed the player to get away with low strength warnings most of the time, often resulting in the AI to repeat the warning every turn without ever Declaring War, the most obvious case being maintaining a hostile global enchantment like Armageddon, in the new system, such case will usually result in an actual War breaking out in less than 10 warnings. Note that although bugs usually prevented the warnings from showing up in earlier versions, if they did, they indeed did so every turn. I've only encountered this behavior once, in which case an AI player complained about an enchantment repeatedly until I attacked them and started a War myself.
Peace Diplomacy Edit
First, if the Strongest Event is zero, the entire following process is skipped. However, during war, Diplomatic Reactions and negative events are automatically cancelled without effect, and there are no sources of positive events in the game (see Positive Diplomacy). As such, the AI is never able to offer a Peace Treaty. The 1.50 unofficial patch removes this check.
Next the AI calculates Hidden Relation + Visible Relation + Personality Modifier + random(1-100) + Peace Interest>=50. If true, there is an 1/8 chance to offer a Peace Treaty. If random(100)<=30*AI population/Player population then the AI will also offer gold or a spell. Note that this means the AI is more likely to offer if they control a larger empire than the player, which is most likely a bug, although due to the previous bug, it won't actually happen anyway. This check is done the opposite direction in Positive Diplomacy. For the details on the offer, refer to Positive Diplomacy "9.", as the process is identical.
In the 1.50 unofficial patch however, although the formula checked is identical, the variable Peace Interest has a completely different meaning, causing the offer to work in an entirely different way, and making sure the AI will only bother to offer or accept peace if the human player has an army with a relevant total power. See Peace Interest for details. Additionally, the offer subtracts 100 from the used Peace Interest variable if an offer is made, to prevent offer spam. The check for a gold or spell offer is altered the same way as in Positive Diplomacy, checking Military Power instead of population and turns the formula to work in the correct direction : the weaker the AI is compared to the player, the more likely they'll try to offer something to buy peace. The new formula is random(100)>= 60*(AI Military power)/Player Military Power, and the chance for spell/gold is 50-50%. For the amount of gold and other details, see Positive Diplomacy "9." and "10."
Positive Diplomacy Edit
First, the AI checks if the Warning Counter is greater than zero. If yes, then the Warning Counter is set to zero. However, to trigger Positive Diplomacy at all, it is required to either have the Warning Counter at zero, or the Strongest Event to be larger than 1. Unfortunately, the first would mean there is no need to reset the counter to zero, and the latter is impossible : The game contains no Diplomatic Reactions that are positive and able to queue a Diplomatic Message at the same time! All existing Diplomatic Reactions that have an associated message are negative. The only Diplomatic Reactions that are positive are Aura of Majesty, or trading spells during Player to AI Diplomacy, neither of which are able to queue a message, they are both "silent" improvements to Visible Relation.
Due to this, and the extremely low chance of success : (3/100)*(1/4) = 3/400), if and only if the Warning Counter is still zero, the 1.50 unofficial patch completely replaces the trigger process. If Event Strength+2>(random(1-7), process continues with either clearing the Warning Counter if present, or Positive Diplomacy if not. This means there is a 1/7 chance per turn for the AI to consider offering something to the player, or clear the effect of previous warning messages sent in Negative Diplomacy unless a positive event happens, in which case the chance is higher. Note that although such events are absent normally, the 1.50 patch also adds two such events, making this possible.
Once the processing enters the Positive Diplomacy, the AI does the following checks in order to decide if any offers to the player need to be made :
(Note that the previously explained check for requiring a bad relationship will pretty much always prevent any of these from happening, even if by some miracle, the game gets this far in the process, passing the 3/400 chance as well)
- If there is a queued Diplomatic Message, there is a 50% chance that the message stays in the queue and the process is skipped.
- If Visible Relation >15 then Hidden Relation + Visible Relation + Personality Modifier + random(1-100) + Treaty Interest > 50 is checked and if true, a Wizard's Pact will be offered to the player. Considering this sum is extremely likely to be over 50, the 1.50 patch changes the formula to be Hidden Relation + 2*Visible Relation + Personality Modifier - random(1-100) + Treaty Interest > 120. This is somewhat harder to pass, ensuring the AI players will not always immediately offer the treaty the first time they can. It's important to mention this uses the same Treaty Interest variable as Player to AI diplomacy, despite the AI being the one asking here and the variable being asymmetric. This makes sense as in both cases the AI is the one making the decision of whether to accept, or propose the treaty according to the formula.
- If Visible Relation >50 then Hidden Relation + Visible Relation + Personality Modifier + random(1-100) + Treaty Interest > 100 is checked and if true, an Alliance will be offered to the player. Considering this sum is extremely likely to be over 100, the 1.50 patch changes the formula to be Hidden Relation + 2*Visible Relation + Personality Modifier - random(1-100) + Treaty Interest > 200. This is somewhat harder to pass, ensuring the AI players will not always immediately offer the treaty the first time they can. It's important to mention this uses the same Treaty Interest variable as Player to AI diplomacy, despite the AI being the one asking here and the variable being asymmetric. This makes sense as in both cases the AI is the one making the decision of whether to accept, or propose the treaty according to the formula. In other to quality this offer, an additional condition needs to be met : Either the player has to always have a Wizard's Pact with the AI wizard, or one has to be queued as an offer for this turn from "2."
- If no Treaty was selected, there is a long calculation of unknown purpose which fills variables that are never used for anything. This is assumed to be for some unintended feature, most likely the Trade Treaty of Master of Orion or some other feature not existing in Master of Magic. Removal of this code allows the 1.50 patch to implement missing features and fix all bugs in "5."
- If Hidden Relation + Visible Relation + Personality Modifier + random(1-100) >25, the AI will attempt to request a trade. The spell they ask for and the spells they are willing to offer in exchange has to have a specific ratio of Trade Desirability. Unfortunately, this part of game code contains many severe bugs. First, better relation results in worse trade offers. However, this already severe bug has no effect at all, as an even more severe bug cancels it out! The list of spells the AI builds of spells having a value equal or higher to desired is assembled from a list containing every spell that has a value equal or lower than this value. A such, only spells of a value exactly equal to the amount will be possible candidates for the trade. If the AI fails to find a spell to ask for, or offer in exchange, they will not offer a trade. Additionally, if the trade is offered, and the player accepts it, the AI will not receive the spell from the trade, so at the next opportunity, they'll try to trade for it again, this time giving another spell to the player for free. Due to the extreme severity and amount of bugs, this part was significantly changed in the 1.50 patch, the following way : First, Hidden Relation + Visible Relation + Personality Modifier + random(1-100) >35 and Trade Interest>50 are checked. If both are true, a trade offer is attempted. X= Min (30, Trade Interest/5) +25 If Alliance + Hidden Relation + Visible Relation /2 + Personality Modifier /2 + random(1-40) -80 is calculated. If X>0 the Y=20000/(200+X), otherwise Y=100-X are calculated. The spells offered in the trade must be no more than Y times as valuable as the one the AI is asking for. If no spell pair available for trade fulfills this condition, no offer is made. If more than 4 spells are valid for the player to take, only 4 of those will be offered.
- If there still is no offer selected to be done, the AI checks if the player controls more total Population in their cities as they do. If yes, they offer a Wizard's Pact regardless of everything else, yes this means even if they hate the player! This is an awful strategic decision as a larger, more prospering empire should be a more desirable target for war instead of getting ignored. If anything, the AI should attempt to attack players who overextend and favor population instead of military units too much. Of course, due to previously mentioned issues, the game never reaches this point to do so, but it would have been bad if it did. The 1.50 patch completely changes this decision. First of all, it is moved to be done prior to "5.", replacing the useless "4.". First, there is a check for Visible Relations>-50, if this check is failed, no offer for Wizard's Pact is made, no matter how powerful the human player might be. Afterwards the AI compares 1.5*AI total Military Power in the astrologer with the human player's Military Power. If the AI's side is less, meaning the player's Military Power exceeds the AI by more than 50%, the Wizard's Pact is offered to ensure the survival of the AI and buy time to build up armies.
- If a trade offer is to be made, Trade Interest of both players towards each other is set to 0, although only one of this variable pair is ever used.
- If the total population controlled by the player exceeds zero (which is only added to prevent a division by zero, as this is not a likely scenario in the game), and a Wizard's Pact or Alliance is being offered, and the AI's personality is neither Maniacal nor Ruthless, check random(1-100)<=30*Player total population / AI total population. If true, and random(1-8)=1, the AI will consider to throw in gold or a spell with the offer. This check is replaced in the 1.50 patch to use astrologer Military Strength instead of population, as that is a more accurate measurement of the actual threat level of the human player. Additionally the 1/8 chance is changed to be a 1/4 chance.
- If the previous point decided to offer something, there is a 25% chance to offer a spell. If no valid spell is found, nothing will be offered. There is a 75% chance to offer gold equal to Turn Count +(player total population /(1+random(1-3)), rounded down to the nearest 25. In the 1.50 unofficial patch, this amount is changed to 20*random(1-10)+(Total AI gold in treasury/8).
- Although this happens after this entire process is completed, it should be mentioned here that gold offered by the AI is not subtracted from their treasury. Additionally, even if they decided to offer the gold or a spell, they will first ask for the treaty without mentioning this. Only if the player actually refuses, will the AI ask "and what if we also offered <x>?". Furthermore this is buggy : The player will receive the offered goods even if the conversation does not reach the point for the offer to be made due to the player accepting for free. Additionally, the spell name (or gold amount, I not longer remember, maybe even both) is left empty in the conversation. the 1.50 patch fixes these two bugs, but the player still has to refuse the initial offer to get the better offer. Note that these bugs are never encountered in the earlier version of the game anyway because bugs explained previously almost always prevent the AI from making the offer in the first place.
- If the AI does try to offer anything to the player, they'll first check if the player has an Alliance with any other AI they are at War with themselves. If yes, they'll demand from the player to break that Alliance first before presenting the offer. Upon refusal, and immediate penalty of 40 Visible Relations ignoring any modifiers is applied to the player in the 1.50 unofficial patch. In earlier versions of the game, the penalty was setting the Visible Relations to -100, however, since offers were never made due to bugs, this never happened. This is the only way for an offer from Positive Diplomacy to produce a negative effect to the player. In all other cases, refusing the offer results in no penalty at all.
War Request Edit
Although completely unimplemented in the 1.40 and earlier versions of the game, the 1.50 unofficial patch adds this feature. An AI player can demand from the human player to Declare War on another AI player if and only if they are in an Alliance with the human player and at War with the other AI player. In this case, they expect the human player to honor the Alliance and join the War. In this situation, every turn when this procedure is executed, there is a 1/40 chance for the AI to request the player to join the War. If the player refuses, their Visible Relation with the AI immediately drops by 50 (ignoring any modifiers) and there still is a 1/40 chance for the request to be repeated on any of the following turns. This is the only potentially not beneficial effect of an Alliance.