K-Mod bug: at least 10 AI units completely disappeared between turns

vedg

Chieftain
Joined
Jan 14, 2014
Messages
25
Location
Ukraine
Steps to reproduce:
  1. Load the attached save with K-Mod v1.46.
  2. Examine Sumerian military units between Numidian and Amsterdam; between Lagash and Utrecht.
  3. End turn.
  4. Notice that 7 Sumerian units have disappeared from the stack that invaded from Numidian (with only 1 Vulture and one Swordsman left); 3 Sumerian units have disappeared near/in Lagash.
The only way this could have happened without a bug in game mechanics is if Gilgamesh deleted the units for some reason. If that is the case, then it's clearly a glaring AI bug: why declare war, invade with a stack and then remove most units from it?

I'm playing under Wine on GNU/Linux. Tried several different Wine versions, 32-bit and 64-bit, with no difference whatsoever.

I played this game with an edited version of Beyond the Sword/Mods/K-Mod/Assets/xml/Technologies/CIV4TechInfos.xml: replaced the only occurrence of <bMapTrading>1</bMapTrading> with <bMapTrading>0</bMapTrading> to disable map trading. Tried reverting this change, but the units still disappear on the next turn.

Tried moving my military units to tiles adjacent to the Sumerian stack near Amsterdam. The AI attacked and won, after which the entire Sumerian stack disappeared on the next turn.

Checked Sumerian/my power ratio in World Builder: the ratio dropped from 2.2 to 1.5 in one turn even though I researched no new technology, built only 2 axemen and no battle took place.
 

Attachments

  • Willem van Oranje AD-0820.CivBeyondSwordSave
    248.2 KB · Views: 241
I had a look in the debugger and it seems that the units are being disbanded due to the AI being in financial trouble.

This expression evaluates to true in CvPlayerAI::AI_doMilitary():
https://github.com/karadoc/Civ4-K-Mod/blob/master/CvGameCoreDLL/CvPlayerAI.cpp#L16123
Code:
if (!isAnarchy() && AI_isFinancialTrouble() && GET_TEAM(getTeam()).AI_getWarSuccessRating() > -30)

In AdvCiv the logic is essentially the same, except that a rate limit is applied based on the current era
https://github.com/f1rpo/AdvCiv/blob/master/CvGameCoreDLL/CvPlayerAI.cpp#L16664
 
Last edited:
I had added that per-turn limit as a precaution because the K-Mod code looked scary. It does help a bit in vedg's savegame: Instead of 14 units at once, the AI then disbands 3 units and 3 more on the next turn. Disbanding happens at the start of an AI turn, so I would guess that canceling OB upon declaring war had pushed Gilgamesh over the financial trouble threshold. I suppose the smart AI play would be to anticipate a loss of income upon declaring war (also for unit support – although the AI doesn't have to pay much for that). And AI_disbandValue should take into account nearby enemies – to give units a chance to die in combat before deleting them.
 
Yes, the current K-Mod AI behavior seems very wrong. In the next few turns Gilgamesh was building units and disbanding them right away, so I didn't even have to defend. Eventually though he discovered Machinery and then his research seems to have skyrocketed, his units started to accumulate and attack. I guess reaching the next era provides enormous bonuses to the AI. The AI shouldn't start a war while on the brink of a financial crisis and expecting the economy to improve soon. In this case Gilgamesh should clearly have researched Machinery before declaring war.
 
Top Bottom