MNAI-U: unofficial build & bugfixes

I noticed something in Advanced Start mode that does not seem right to me.

If you pay to add an improvement to a tile and then change your mind, you can remove the improvement and get a refund.
However, if you decide that you would rather have a different improvement on the tile and add it without first manually deleting the previous improvement, you pay the full cost for the new improvement without getting any refund for the improvement that gets deleted in the process even if you subsequently remove the improvement added to replace the first one.

---
I also had an advanced start game as the Illians where there was only a single tile where it was possible to place a city. That is because the start position was near Letum Frigus, but I'd used python to disable city founding too close to the improvement that becomes a city of its own with the completion of the White Hand ritual.

It seems like the advanced start code could be tweaked to give a player a decent starting area of a lot of the default area is made unavailable do to pPlot.isFoundDisabled() or preexisting barbarian cities in the area.

---

In my modmod I'm noticing a lot more dogpiles and declarations of war cased by one player bribing another. It seems like that should be scaled back, particularly in cases where the player paying the bribe to make another player declare war on a third is not at war with the third and doesn't not even have bad relations towards the third player.

It also really seems like a player (including human player) conducting trade or a peace negotiation with another player ought to be able to offer a declaration of war against a third player with whom the other player was already at war.

----
It still seems like the AI ought to invest more in buildings, especially those that are unit prereqs, instead of lots of low level units.

---
I'm sure I've mentioned this before, but I really wish that the <bPermanentUnitCreate>1 tag did not make the summoned unit start immobilized and limit the number to equal the number of units with the spell's prereq promotions. Those could be separate tags, but I would not normally want to use them for summons. Several of my permanent summons are for priests, so checking for promotions but not religion type is stupid. It seems like instead limiting the permanent summons to one (or two with twincast) with the same caster as the summoner would make more sense, which is why I do so using python. I'd like a couple of tier 4 spells summoning unlimited permanent units though.

----

Would it be possible for def canBuild(self,argsList): to pass on the unit building an improvement so I could block or allow some build types based on the units promotions, race, religion, level, duration, etc?
 
Apologies for the late reply. I now also checked the AI; it's definitely using "Lead by Warlord", although ineffeficiently, since it still assumes the standard BtS behaviour. For example, since you can't split a GG from a unit in BtS, it waits until wartime before leading units. I'll made a note to try to improve that in the future.

I'll try to answer your individual points, but I feel we're talking past each other to some degree.

Great, thanks very much, and sorry if I'm missing any other things in what you said before that I failed to address.

Such a spell indeed does not exist, so you won't find it in the pedia or the XML (the ability comes from the <LeaderPromotion> tag in CIV4UnitInfos.xml instead). "Special abilities" in the pedia are just spells on the technical side.

Ah, that does clarify what's going on there for me and what you said in your first reply to me. Thank you!

I don't understand what you mean, sorry. Which unit combat types are you talking about?

Which spell are you talking about now? The "Join Commander" spell? How do you know that the AI is canceling the spell?

As mentioned above, this is probably because the AI thinks it has to save its generals for later. I think if their in a war on the same continent, they should use the GG.

Here I again don't know which spell you're talking about.

I am speaking of all units that have a combat type assigned (such as UNITCOMBAT_MELEE): because the ones without a combat type cannot use Great Generals as far as I can tell. It sounds like you were expecting specific unit combat types involved by what I said, and I'm sorry if I misled you. As for the "spell" I meant, though, in both instances where you were confused by my reply above, I am apparently instead speaking of the ability you mentioned tied to the <LeaderPromotion> tag that leads to the unit acquiring the "Lead by Warlord" promotion. I was not intending to refer in any way to Great Commanders or the "Join Commander" spell (and I apologize, perhaps the way I answered in my reply added confusion as I was trying to be very specific about the Great Generals as the problem only, but then I apparently deleted the sentence clarifying that...lot of good that did for you). The way I can tell the AI is trying to do something with this is that the Great General and usually the first unit in the stack will both have "Has Casted" marked in single player in the WorldBuilder even when they have no other possible option for what could have been cast...which is why I thought "Lead by Warlord" must be from a spell since I don't know how else that could be getting marked. The units do not have this "Has Casted" if I delete the Great General and proceed to the next turn, for instance (whereas they do if I leave the Great General): so this is just a deduction I made based on process of elimination.

I apologize for taking so long to reply, but I did some additional testing across four games in single player and this is what I found: you are correct that the AI is eventually using the Great Generals when going to war in single player in some cases (in multi-player I literally can go four hundred to eight hundred turns and the AI can go to war multiple times in that span and still never attach the Great General to any of its units...and while unattached the cost maintenance gets to be quite the burden with more than 8 Great Generals just standing around depending on civics). More obviously as a consequence of what you stated about following original BtS programming seems to be things such as when Hidden Nationality units are effectively at war with an AI the AI never attaches Great Generals because war is not declared...however, less obvious things are also problems with the AI here as the Great Generals are not being reliably used when created during a war where they have high War Weariness, when a war is triggered automatically by an event, when the war was incited by another AI or player asking the AI to declare war on another player or AI, or if the Great General was the only unit created in the city for more than one turn without any units in the city for the Great General to be attached to then when units later move back to the city the Great General still never seems to get attached. However, I have noticed this behavior in multi-player changes based on which players they are going to war with: if the player in the top player slot is at war the Great Generals will attach...but if the player is not in the top player slot (i.e.: player 2 at game creation/lobby) it appears the Great Generals almost never meet whatever conditions are being checked to attach. Since I'm using the top player when I create a game and I'm usually the most peaceful and least war-mongering-type player in any multi-player game...this may be why we are seeing this problem more in our games. I can't confirm anything about the AI behavior for sure, though: so these are just my speculations. If you have a recommendation for how I could test this more thoroughly I'd be happy to bring you back more data on this. (smile)

Finally, on another topic...I second what MagisterCultuum said regarding:
1. Advanced Start should probably preclude the Barbarian World game option as sometimes you really can end up with almost no tiles to build except 1 due to the pre-placed Barbarian cities. This can lead to a disastrous start for a player in a multi-player game that's a major hassle to restart for everyone. Alternatively, the Barbarian World cities could instead be founded on turn 1 rather than turn 0 perhaps with some changes to how that option works.
2. Advanced Start does not refund improvements when built over with a different improvement first. I'm not sure if this is something that you can actually change with a mod as this happens in BtS also.
3. The crazy amount of declarations of war caused by one player or AI bribing another AI should indeed be scaled back or even prohibited in cases where the player or AI paying the bribe to make another AI declare war is not at war with that civilization and has Neutral, Pleased or Friendly relations towards the party against whom the war has been incited.
4. The AI should give greater weight to buildings, especially those that are required to build units or heroes unique to their civilization, instead of building so many low level units that share a combat type or weakness that can be easily exploited. As an aside, I think if logic were instituted to limit to a maximum of 4 to 6 units of the same unit type (not necessarily combat type as unique units sometimes compensate for a like combat type with other unusual bonuses that minimize their weaknesses) in a stack, that the units AI used to take on foes may not be so monolithic and easy to defeat (i.e.: stack of doom countered by Shock promotions alone). An exception could be made for the unique units of a civilization because they often have superior match-ups regardless at the equivalent tech/power level they become available. However, these are not simple changes and would take a lot of play to determine what is best I think.
5. In addition, the AI should give less weight to building National Units where the comparative Combat Strength of the unit types are strictly inferior to the opposition and the National Units are being used offensively rather than defensively (i.e.: the AI keeps making defensive National Units to attack superior combat strength units).
 
Last edited:
If you pay to add an improvement to a tile and then change your mind, you can remove the improvement and get a refund.
Thanks for the report, will be fixed in the next version.

It seems like the advanced start code could be tweaked to give a player a decent starting area of a lot of the default area is made unavailable do to pPlot.isFoundDisabled() or preexisting barbarian cities in the area.
The area where you can settle in AS is mostly determined by visibility, which in turn is a rectangle of radius ADVANCED_START_SIGHT_RANGE around the starting plot. The starting plot is determined by mapscript and seems complicated to robustly change. You should probably just increase ADVANCED_START_SIGHT_RANGE in your mod. You still cannot found cities on a plot that is closer to another player's starting plot than yours, so this isn't a perfect solution.

In my modmod I'm noticing a lot more dogpiles and declarations of war cased by one player bribing another. It seems like that should be scaled back, particularly in cases where the player paying the bribe to make another player declare war on a third is not at war with the third and doesn't not even have bad relations towards the third player.
This is quite complicated. From what I can gather, the following major things are different in MNAI (compared to BtS). Say we have an AI X that is considering to declare war on Y as a trade deal to Z.

  • X is always willing if X remembers that Y declared war on X before. This is regardless of the attitude from X to either Y or Z, which seems silly.
  • If the Aggressive AI option is on, then Y ignores attitude to Z. This is also dubious.
  • X is always willing if X is planning on going to war with Y anyway. This seems fine, even though it might throw X into the war too early.

All these changes are from the "Ruthless AI" modcomp by Afforess, which Tholal merged. It seems to make the AI largely ignore attitude, which I think most players don't want. I'm thinking of putting all these changes behind a "Ruthless AI" option, as is done in other mods.
In the meantime, you should try disabling "Aggressive AI", if you haven't already.

It also really seems like a player (including human player) conducting trade or a peace negotiation with another player ought to be able to offer a declaration of war against a third player with whom the other player was already at war.
Agreed. Do you have a save where it is not possible?

It still seems like the AI ought to invest more in buildings, especially those that are unit prereqs, instead of lots of low level units.
Agreed, I have that on my list. I'd probably still recommend playing with the "AI no Building Requirements" option.

I'm sure I've mentioned this before, but I really wish that the <bPermanentUnitCreate>1 tag did not make the summoned unit start immobilized and limit the number to equal the number of units with the spell's prereq promotions. Those could be separate tags, but I would not normally want to use them for summons. Several of my permanent summons are for priests, so checking for promotions but not religion type is stupid. It seems like instead limiting the permanent summons to one (or two with twincast) with the same caster as the summoner would make more sense, which is why I do so using python. I'd like a couple of tier 4 spells summoning unlimited permanent units though.
The part about checking religion type is planned. Tracking the summoner of a unit would require some more changes and is too much of a gameplay change for my taste.

Would it be possible for def canBuild(self,argsList): to pass on the unit building an improvement so I could block or allow some build types based on the units promotions, race, religion, level, duration, etc?
Changing the existing signatures is cumbersome, but I will add a new canUnitBuild() callback (or I at least put it in the TODO list).


Its only one change: Change '0' to 'MOVE_THROUGH_ENEMY' in the right place. Unfortunately bolding doesnt seem to work inside code.

No, I didnt test it. I cant compile it. Is there some easy way to compile it under Linux? I found https://forums.civfanatics.com/threads/compiling-the-dll-on-linux.658833/ but does that work with this mod?
I believe that guide works. I know I successfully compiled MNAI on linux once, but in the end using a virtual machine was more convenient. Anyway, I'll test out the change myself.

The way I can tell the AI is trying to do something with this is that the Great General and usually the first unit in the stack will both have "Has Casted" marked in single player in the WorldBuilder even when they have no other possible option for what could have been cast...which is why I thought "Lead by Warlord" must be from a spell since I don't know how else that could be getting marked. The units do not have this "Has Casted" if I delete the Great General and proceed to the next turn, for instance (whereas they do if I leave the Great General): so this is just a deduction I made based on process of elimination.
I see, interesting.

I apologize for taking so long to reply, but I did some additional testing across four games in single player and this is what I found: you are correct that the AI is eventually using the Great Generals when going to war in single player in some cases (in multi-player I literally can go four hundred to eight hundred turns and the AI can go to war multiple times in that span and still never attach the Great General to any of its units...and while unattached the cost maintenance gets to be quite the burden with more than 8 Great Generals just standing around depending on civics).
Okay, then it might be a multiplayer problem. In any case, I think I should just remove upkeep costs from GGs; it won't matter for players, as they'll use them to lead some unit immediately.

More obviously as a consequence of what you stated about following original BtS programming seems to be things such as when Hidden Nationality units are effectively at war with an AI the AI never attaches Great Generals because war is not declared...however, less obvious things are also problems with the AI here as the Great Generals are not being reliably used when created during a war where they have high War Weariness, when a war is triggered automatically by an event, when the war was incited by another AI or player asking the AI to declare war on another player or AI, or if the Great General was the only unit created in the city for more than one turn without any units in the city for the Great General to be attached to then when units later move back to the city the Great General still never seems to get attached. However, I have noticed this behavior in multi-player changes based on which players they are going to war with: if the player in the top player slot is at war the Great Generals will attach...but if the player is not in the top player slot (i.e.: player 2 at game creation/lobby) it appears the Great Generals almost never meet whatever conditions are being checked to attach. Since I'm using the top player when I create a game and I'm usually the most peaceful and least war-mongering-type player in any multi-player game...this may be why we are seeing this problem more in our games. I can't confirm anything about the AI behavior for sure, though: so these are just my speculations. If you have a recommendation for how I could test this more thoroughly I'd be happy to bring you back more data on this. (smile)
Thanks for sharing your observations. I'll get back to this if/when I look into improving GG AI.

Finally, on another topic...I second what MagisterCultuum said regarding:
1. Advanced Start should probably preclude the Barbarian World game option as sometimes you really can end up with almost no tiles to build except 1 due to the pre-placed Barbarian cities. This can lead to a disastrous start for a player in a multi-player game that's a major hassle to restart for everyone. Alternatively, the Barbarian World cities could instead be founded on turn 1 rather than turn 0 perhaps with some changes to how that option works.
I'll check if I can increase the minimum distance of barbarian cities to starting plots when AS is on.

4. The AI should give greater weight to buildings, especially those that are required to build units or heroes unique to their civilization, instead of building so many low level units that share a combat type or weakness that can be easily exploited. As an aside, I think if logic were instituted to limit to a maximum of 4 to 6 units of the same unit type (not necessarily combat type as unique units sometimes compensate for a like combat type with other unusual bonuses that minimize their weaknesses) in a stack, that the units AI used to take on foes may not be so monolithic and easy to defeat (i.e.: stack of doom countered by Shock promotions alone). An exception could be made for the unique units of a civilization because they often have superior match-ups regardless at the equivalent tech/power level they become available. However, these are not simple changes and would take a lot of play to determine what is best I think.
Yeah, that's too complicated for me to even consider at this point. I also suspect that army composition might improve if the AI were to build more of the required buildings.

5. In addition, the AI should give less weight to building National Units where the comparative Combat Strength of the unit types are strictly inferior to the opposition and the National Units are being used offensively rather than defensively (i.e.: the AI keeps making defensive National Units to attack superior combat strength units).
I guess the AI shouldn't such units offensively in any case. Which units are you talking about specifically?
 
Thanks for the report, will be fixed in the next version.
You mean giving us refunds for the improvements that get removed when we add other improvements, or not letting us get refunds the way we can now? I hope you mean the former.

The area where you can settle in AS is mostly determined by visibility, which in turn is a rectangle of radius ADVANCED_START_SIGHT_RANGE around the starting plot. The starting plot is determined by mapscript and seems complicated to robustly change. You should probably just increase ADVANCED_START_SIGHT_RANGE in your mod. You still cannot found cities on a plot that is closer to another player's starting plot than yours, so this isn't a perfect solution.
I had no idea such a define exists. It did not appear in the FfH2 global defines files, but I found it in the main BtS file and copied from there.

I found a bunch of other advanced start defines there too which I'm playing around with a bit.

It seems to be that ADVANCED_START_CITY_PLACEMENT_MAX_RANGE matters a lot more than ADVANCED_START_SIGHT_RANGE. If I increase the sight range but set ADVANCED_START_CITY_PLACEMENT_MAX_RANGE to 1 then there are only 9 tiles to choose from for a city at most. What surprised me that that setting ADVANCED_START_CITY_PLACEMENT_MAX_RANGE to 0 let be build cities pretty much anywhere. There are still unavailable areas near the starting locations of other players, but I found I was able to build a lot of cities far from any starting location and completely surround some other players.

When I tried setting ADVANCED_START_ALLOW_UNITS_OUTSIDE_CITIES to 1 instead of 0 I found I could place a lot of units like scouts and workers on tiles outside of cities, but that others like adepts still had to be inside cities. I assume this means it still checks for building prereqs on the tile's own city and not just in the nearest city.

What really surprised me was that when I clicked the "Build Improvements (Automated)" button I found that the game added a lot of copies of units that no one should ever be able to build at all. I talking hundreds of Great Engineers, Odios, Greysons, Abaddons, Mary Morbuses, and other Heroes that have a cost of -1 and are only supposed to show up from events or spells cast on unique features. Such units did not appear on the list of those I could add manually, but if I clicked the automate building again more would show up.

That did not happen again after setting ADVANCED_START_ALLOW_UNITS_OUTSIDE_CITIES back to 0.


By the way, why is it that you cannot purchase visibility until after settling a city?

Tracking the summoner of a unit would require some more changes and is too much of a gameplay change for my taste.
I don't mind tracking the summoner as I have been in python, or adding a "returns True" python prereq to let a spell have unlimited summons, but it does really annoy me how the permanent summons start immobilized.


I'm wondering if maybe the Barbarian World Option in Advanced Start games should maybe just treat the Barbarians like other players, giving them their own starting location and points to build cities for themselves. I think the barbs are technically player #50, so they would add their cities after everyone else's and not limit where earlier players can put their cities.
 
Last edited:
By the way, why is it that you cannot purchase visibility until after settling a city?
This might be handled in the exe, I didn't find a relevant piece of code in the DLL.

but it does really annoy me how the permanent summons start immobilized.
That's fair, I'll put it on the TODO list.

I'm wondering if maybe the Barbarian World Option in Advanced Start games should maybe just treat the Barbarians like other players, giving them their own starting location and points to build cities for themselves. I think the barbs are technically player #50, so they would add their cities after everyone else's and not limit where earlier players can put their cities.
I think having all barbarian cities in one spot would not be desirable for Barbarian *World*. I'll see if I can just add a (configurable) minimum distance to starting locations.

EDIT:
You mean giving us refunds for the improvements that get removed when we add other improvements, or not letting us get refunds the way we can now? I hope you mean the former.
The former.
 
Last edited:
I think I should just remove upkeep costs from GGs; it won't matter for players, as they'll use them to lead some unit immediately. Thanks for sharing your observations. I'll get back to this if/when I look into improving GG AI.

Thanks! I'm super curious: how would you remove upkeep costs from GG's without modifying the DLL? If you can remove upkeep costs, then I'd suggest at the same time that the following also have upkeep/maintenance removed:

Athame
Black Mirror
Crown of Ahkarien
Crown of Command
Empty Bier
Gela
Godslayer
Golden Hammer
Healing Salve
Infernal Grimoire
Jade Torc
Nether Blade
Orthus' Axe
Pieces of Barnaxus
Potion of Invisibility
Potion of Restoration
Rod of Winds
Scorched Staff
Staff of Souls
Syliven's Perfect Lyre
The Dragon's Hoard
Timor Mask
Treasure Chest
War

Note that there has been some kind of attempt to already reduce upkeep on equipment/items/treasure, which works 100% within your own units' Cultural Borders because upon creation they directly add +1 to the "free support for <X>" (population dependent at approx. 0.24 free support/pop. + BASE_UNIT_SUPPORT) under "Unit Cost;" however, because of incomplete implementation they do not add +1 to the "free supply for <Y>" (typically 4) under "Unit Supply," which is why Treasure Chests and Items cost extra maintenance/upkeep/supply when abroad outside their owner's cultural borders.

In addition, there are some other units without a UNITCOMBAT set (or that are just marked as a "non-combat" unit) beyond Great Generals that human players tend to use/upgrade/settle immediately, but which AI inefficiently dawdle with or accumulate at cost which you might consider as well (listed roughly in the order these can be a problem for AI in long-term cost): Great Commander, Supplies (I believe mostly this is due to them not having any "Force Build" options as they are all "Build" options instead), Great Engineer, Great Prophet, Great Sage, Elephant (esp. on maps where large numbers are generated and captured but not upgraded), Great Merchant and Great Artist (the last two are really only a problem if they get trapped somewhere).

Finally, along these same lines (but stretching the boundaries of a "bug fix"): Barbarians manage better in Civ4 BTS, because primarily they do not have to sustain so many Animal units that are not expended attacking cities like the non-Animal Barbarian units so frequently are and aren't logically/logistically controlled by Barbarian "civilization" either. One way to achieve this would be to reduce the maintenance cost of maintaining animal units (which other than Giant Spiders human players tend to settle fairly quickly either as Bears or with Carnivals), which could be done by giving Barbarians a unique civic option for Membership or something, but if you have a direct way to modify unit cost/support/supply/upkeep/maintenance then you may have other ways to achieve this.

I'll check if I can increase the minimum distance of barbarian cities to starting plots when AS is on.

Thanks!

Yeah, that's too complicated for me to even consider at this point. I also suspect that army composition might improve if the AI were to build more of the required buildings.

One way to discourage the AI from over-building units instead of hard limits is to simply use the <iInstanceCostModifier>0</iInstanceCostModifier> to set a percentage higher than 0 as these are currently unused in MNAI/FFH. For military units, this is represented by the additional cost in a civilization to draw from a population suitable candidates who can be trained to perform in a specific role. As increasing numbers of candidates are trained and units created, the pool of those with natural talent who learn the fastest and are easiest to train will be reduced and the effort to train them goes up from the remaining population reserve. From a gameplay perspective, AI does value production (which is why it creates so many more units on Marathon because of the +200% cost increase instead of +300% for buildings) and should therefore be self-limiting as the cost of the units increases with more simultaneous active units of that kind in play. This would also inherently encourage more diverse stacks while not requiring much gameplay tampering for reasonable cost modifiers.

I guess the AI shouldn't such units offensively in any case. Which units are you talking about specifically?

The worst offenders are for sure the Royal Guards throughout total gameplay progression, but in particular in the late game Crossbowmen are terribly mis-matched when the AI doesn't even have access to Copper or Iron, and any National Units like Shadows with penalty to attacking Cities should not be used offensively to attack cities by the AI in the late game either.
 
Last edited:
I'm noticing some strange behavior related to miscasting delayed spells.

When a spell is miscasted the miscast effect triggers instantly, whereas I think it would probably make more sense for it to happen after the same delay as the positive effect of the spell would.

After miscasting a delayed spell with <bIgnoreHasCasted>1 you can immediately try to cast it again.

Sometimes after multiple attempted castings the spell gets successfully casted without any delay.

Sometimes after failing to cast a delay cast spell the spell becomes unavailable to the unit. The unit can move around to other tiles where it should be able to cast but the spell won't show up. The ability to cast that spell will however come back after the unit successfully casts a different delayed casting spell.

(My modmod has several spells (including multiple versions of Bloom, Vitalize, lairs explorations, Craft Construct, Craft Automaton, Overgrowth, etc) which have <bHasCasted>0</bHasCasted>, <bIgnoreHasCasted>1</bIgnoreHasCasted>, and <iDelay> of 1 or more.

I've mostly noticed this with the great prophet Talia Gossam, who in my modmod gets Nature Affinity which allows Bloom and Divine+Unblemished religion type which allows Vitalize.)
 
Note that there has been some kind of attempt to already reduce upkeep on equipment/items/treasure, which works 100% within your own units' Cultural Borders because upon creation they directly add +1 to the "free support for <X>" (population dependent at approx. 0.24 free support/pop. + BASE_UNIT_SUPPORT) under "Unit Cost;" however, because of incomplete implementation they do not add +1 to the "free supply for <Y>" (typically 4) under "Unit Supply," which is why Treasure Chests and Items cost extra maintenance/upkeep/supply when abroad outside their owner's cultural borders.
Very interesting.

In addition, there are some other units without a UNITCOMBAT set (or that are just marked as a "non-combat" unit) beyond Great Generals that human players tend to use/upgrade/settle immediately, but which AI inefficiently dawdle with or accumulate at cost which you might consider as well (listed roughly in the order these can be a problem for AI in long-term cost): Great Commander, Supplies (I believe mostly this is due to them not having any "Force Build" options as they are all "Build" options instead), Great Engineer, Great Prophet, Great Sage, Elephant (esp. on maps where large numbers are generated and captured but not upgraded), Great Merchant and Great Artist (the last two are really only a problem if they get trapped somewhere).
I agree on everything except elephants, since those are actual combat units that make at least some sense to amass.

Finally, along these same lines (but stretching the boundaries of a "bug fix"): Barbarians manage better in Civ4 BTS, because primarily they do not have to sustain so many Animal units that are not expended attacking cities like the non-Animal Barbarian units so frequently are and aren't logically/logistically controlled by Barbarian "civilization" either. One way to achieve this would be to reduce the maintenance cost of maintaining animal units (which other than Giant Spiders human players tend to settle fairly quickly either as Bears or with Carnivals), which could be done by giving Barbarians a unique civic option for Membership or something, but if you have a direct way to modify unit cost/support/supply/upkeep/maintenance then you may have other ways to achieve this.
I'm pretty certain barbs don't pay upkeep costs at all.

One way to discourage the AI from over-building units instead of hard limits is to simply use the <iInstanceCostModifier>0</iInstanceCostModifier> to set a percentage higher than 0 as these are currently unused in MNAI/FFH. For military units, this is represented by the additional cost in a civilization to draw from a population suitable candidates who can be trained to perform in a specific role. As increasing numbers of candidates are trained and units created, the pool of those with natural talent who learn the fastest and are easiest to train will be reduced and the effort to train them goes up from the remaining population reserve. From a gameplay perspective, AI does value production (which is why it creates so many more units on Marathon because of the +200% cost increase instead of +300% for buildings) and should therefore be self-limiting as the cost of the units increases with more simultaneous active units of that kind in play. This would also inherently encourage more diverse stacks while not requiring much gameplay tampering for reasonable cost modifiers.
Too much of a balance change again, sorry. :)

The worst offenders are for sure the Royal Guards throughout total gameplay progression, but in particular in the late game Crossbowmen are terribly mis-matched when the AI doesn't even have access to Copper or Iron, and any National Units like Shadows with penalty to attacking Cities should not be used offensively to attack cities by the AI in the late game either.
Thanks, I'll keep an eye out for this behavior.

When a spell is miscasted the miscast effect triggers instantly, whereas I think it would probably make more sense for it to happen after the same delay as the positive effect of the spell would.
Agreed. I made note of the other bugs, too.
 
I'm pretty certain barbs don't pay upkeep costs at all.

They share the same rules for gold/commerce/research as default AI: you can test this out when you look at Barbarian research progression easily on a small map with just your player civ and deleting the lone AI in the World Builder on a single player game. The more units the Barbarian civilization has, the more they pay in upkeep/maintenance/"unit cost" just like other AI civilizations. Play the same game twice on the smallest/largest mapscript size you have for Duel/Huge and set it on auto-play with Barbarian World. Take stock of what the Barbarians researched. Also, one where they have little area to spawn random Barbarian units and one where they have maximum area with One City Challenge active for the same size. In addition, you can set the Barb AI "starting" civics in "Civ4CivilizationInfos.xml" which they will never change from also. You can easily change their "<InitialCivics>" to those favoring research/free specialists in their cities and you'll see a really huge difference. Similarly, you can change to civics that all reduce unit cost or give free units and see the difference there as well (it is quite notable if the Barbarians have enough population to get a big advantage with population-dependent "free units"). The Barbarians basically are handicapped by having too many Animal AI units that don't even fall into their larger schema, especially on larger maps and with Wildlands selected because the Barbarians only build more cities proportionally to the other civiilizations: with no other AI and One City Challenge they will never build more cities because of that formula and the units generated will eliminate those additions toward research completely. Though, when settings are more favorable for Barbarian research, this is specifically why Elder Council and Library are blocked for the Barbarians (if their research was too quick they wouldn't seem as much like "Barbarians"). It's true that without trade or event access, though, that Barbarians have little use for gold itself beyond maintenance without being able to change civics to those they can rush buildings/production. They never have units disbanded just from upkeep/maintenance/"unit cost"/"unit supply," though. Once lairs are destroyed, one-time events are used up and animals disappear in a regular FFH game, the Barbarians do play more or less like in Civ4 BTS. However, if animal units can be generated the whole game (which is just more fun) they take up random generation slots that would have gone to aggressive, ready-to-win-or-die Barbarian units in addition to being a drag on the Barbarian "civilization" that otherwise doesn't exist. When the Animal AI units just lurk outside player and AI cultural borders, the Barbarian "civilization" takes a hit right in their..."civilization" bits...in ways that basically nerf Barbarians from their full potential. (smile)

As for all the other topics in your reply: you're welcome and thank you! We appreciate you working on MNAI bugs and those things which are poorly or incompletely implemented by FFH/MNAI. Hopefully the building prioritization and unit upkeep changes will make a big enough difference to improve the AI (as well as if you can address the suicide-prone defensive National Unit assaults), and I am very excited for the next MNAI release (and getting back the Somnium mini-game which is great when someone is taking much longer in multi-player). As always, a new version will shed new light on possible tweaks that would make the AI perform better.
 
Last edited:
While testing out Advanced Start tweaking from Magister's notes, I've found all the bugs he mentions are indeed present in MNAI and not just related to his modmod. Furthermore, the default max. dist. for city building is so small that the AI is incapable of building even 1 city at times and will immediately have its civilizations destroyed on turn 1. In addition, playing with Barbarian World turned Off is also a bad choice for the AI to succeed, as then many more Barbarian Warriors are generated due to the lack of Barbarian cities with units taking up random generation slots of the Barbarians, and during the first 10 turns most of the AI units abandon their cities and allow them to be ravaged by Barbarians. This means both options interact poorly with Advanced Start, which is an option that can usually give the AI significant advantages over human players with the tech. costs in FFH/MNAI. The AI needs to be fixed on this count to always leave at least 1 unit in their cities, rather than completely undefended against Barbarians.

Furthermore, the Doviello are not getting Lucian created correctly all the time: as a fail-safe, can Lucian be given a cost perhaps of 2 production (I believe a production cost of 1 will glitch on Quick speed), and be placed at the top of the Doviello AI build priority with AIWeight 300 and removing its PrereqTech of Never, that way if the World Unit isn't already taken up by a correctly pre-generated Lucian the Doviello will always create Lucian on turn 1 (or as close as possible to that) without scripting having to be run? I did find that the reason Lucian is created sometimes and not others seems to be directly related to the glitching of unavailable units depending on whether the option for units to be placed outside cities is allowed or not. This might be overridden with an AdvancedStartCost assignment also, but the AI won't put Lucian in even with a low iAdvancedStartCost and high AIWeight assigned apparently, though they will put Lucian in their starting or immediately second unit build in 100% of games I tried this way.
 
Last edited:
On the subject of barbarian researching: I appreciate you looking into this, @LightAcolyte. I checked the code and did a few short test games.
  • For each tech, barbs get 3%/turn of that tech, times the fraction of other players that already have that tech. So, if each player has a tech, barbs get it after at most 34 turns. The 3 in the formula comes from BARBARIAN_FREE_TECH_PERCENT.
  • Barbs seem to be able to get research in other ways, as you say; I was not aware of that.
  • Barbs don't change their tech slider in the way other AIs do.
  • Barbs set their tech slider to 0% to avoid disbanding units (even though they don't) every turn. In my test games, this always happened on the first turn, Barbarian World or not.
So I assume that in a usual game, barbarians set their tech slider to 0% right away and never change it. Of course, I could fix it programmatically to anything we want - the fact that
They never have units disbanded just from upkeep/maintenance/"unit cost"/"unit supply,"
means that there their gold per turn is basically meaningless (they don't get events). I suspect that the effects you observed are mostly artifical (e.g. switching civics) and do not come up in a usual game. Barbarians could have high-enough commerce to offset unit maintenance in the late game. But, as mentioned, their tech slider would presumably already at 0% at that point. So the only thing they can do to increase their science output that I can think of would be scientist specialist (do they get the required buildings?).

So, in conclusion, I think that cities and unit maintenance doesn't affect barbarian research normally (except maybe specialists), and it shouldn't. Barbarians aren't ment to be a sort of civilization working together. Even the fact that their units don't fight among each other is clearly an abstraction. Therefore, I think I'll just set the 0% research explicitely, and ignore their research/turn. Maybe I should also set the gold to 0 every turn, in case they have some use of that that I didn't think of. If barbarians seem to weak, BARBARIAN_FREE_TECH_PERCENT can be increased (this is what I did in EMM).

However, if animal units can be generated the whole game (which is just more fun) they take up random generation slots that would have gone to aggressive, ready-to-win-or-die Barbarian units
Animal spawning is completely separate from barbarian spawning in FfH, as far as I can tell from the code.

during the first 10 turns most of the AI units abandon their cities and allow them to be ravaged by Barbarians.
That's an AI bug, thanks for reporting. I put it on the TODO list. I don't think anything related to barbarians needs to be changed to offset this.

I did find that the reason Lucian is created sometimes and not others seems to be directly related to the glitching of unavailable units depending on whether the option for units to be placed outside cities is allowed or not.
Can you elaborate on the glitch? I don't know what you mean.
 
Maybe I should also set the gold to 0 every turn, in case they have some use of that that I didn't think of.
Upgrading units?
 
Good point, I'll leave their gold alone then. It's still a bit silly that their ability to upgrade depends on the number of units and cities, but I don't know a better solution.
If you wanted to you could make up a new dummy trait for the barbarian leader that has a <iUpgradeCostModifier>-100</iUpgradeCostModifier>

Alternately, you could their units a new dummy promotion with <iUpgradeDiscount>100</iUpgradeDiscount>.

A promotion could also have <bUpgradeOutsideBorders>1</bUpgradeOutsideBorders>, which would let a unit upgrade anywhere so long as at least one city anywhere in the world has its prerequisite budlings etc.

If you don't want the promotion to show up in the pedia you can use <bGraphicalOnly>1</bGraphicalOnly> and if you don't want it to be visible in the game itself you can set the <PromotionNextLevel> tag the same as <Type> tag.


I assume that if you wanted to you could also just edit the DLL so that wherever the game checks for the iUpgradeDiscount or bUpgradeOutsideBorders tags it also gives barbarian units credit as if they have them without actually needing a dummy promotion.
 
Do you want every barbarian worldwide to upgrade, though? For instance, when obtaining the longbow tech.

Unlikely to matter very much, admittedly.
 
This displays when playing as the Khazad before founding a city, with the vault display setting on:
The Dwarven Vault isn't listed as a unique building for the Khazad in the civilopedia either.
Could you make a placeholder generic Palace as the default palace so the Bannor Palace displays as a unique building for them?
 

Attachments

  • Civ4ScreenShot0000.JPG
    Civ4ScreenShot0000.JPG
    132.8 KB · Views: 45
Last edited:
I would like to ask/suggest something about the early game barbarians:
Specifically Lizardmen and Ruins can spell doom to a player in the first few rounds, depending on your location, you might end up having 3 or more ruins around you. This doesn't always (but often it does!) mean defeat, but you'll have to commit an insane amount of production to just early warriors in order to survive and eventually clear the lairs. By this time, other civs have several cities up and running. I think having lizardmen not leave their ruins (and also not spawn more than 1 or 2 per ruin) until a good amount of turns has passed, maybe 70-80 or so (early game turns are fast with often little progress), would be quite good. The other barbarians are typically more manageable, since they tend to both be weaker (skeletons, goblins) and also move slower. Some animals can be extremely strong, but at least those don't enter your borders.
Do you think it would be possible to have a "Delayed Lizardmen" or "Delayed Barbarians" option or something similar? It's a shame to turn them off, but having them on ruins a game every now and then.

----------

Oh and finally, my friend and me tend to get a lot of OOS sometimes when playing multiplayer. Sometimes it can be fixed by saving and restarting the game (a basic rejoin doesn't seem to help for more than a turn), but often it'll be unfixable (for more than 1 turn) for 20-30 turns. These are super disheartening when playing a game, since you spend 90% of your time rejoining the game. We really have no idea what could be the cause, sometimes it happens as early as turn 40, many times around 100, and other times only at 300 or 400+. And then there are games that go for the entire duration and barely go OOS at all. Curiously enough, one of those was on a giant map with 30 players (therefore including every civ, most of the time even twice), so the number of players or the civs played doesn't seem to affect it at all.
Seems to happen both when using the Steam version for MP and when downgrading to the original release and using direct IP.
 
Back
Top Bottom