Smarter Orcs (a FfH II mod)

xanaqui42

King
Joined
Sep 5, 2006
Messages
780
Objective: To improve the Fall From Heaven II AI significantly.

Stable release: There is no stable release.

Unstable Release: At the Database, here.

Fair Combat Unstable Release: At the Database, here.

Source Code: Sourceforge project link.

Wiki project page: Here.

Quizzes (Input for the AI functions): Please answer some to help out with the next version(s)

Notes:

For the purposes of this mod (and the code), "AI" includes all complex decision-making done by the computer without direct human intervention. For example, automating a worker, allowing automatic determination of where your citizens will work, or giving a go to order all fall under this description. In other words, this mod should both improve the computer opponents' capabilities and reduce the advantages of micromanaging. It also should reduce the need for cheating by the AI.

Presently, while the merge with BetterAI grants numerous improvements, there are a few downsides to the AI changes there (for the purposes of FfH II).

Note that you may experience some increase in the difficulty due to this mod (or you may not); difficulty (i.e. cheat) parameters have not been changed at this time.

Note that there is some significant slowdown. You may want to try this on a size smaller of a world than you typically would use.

Note that since version 0.10, this will break saved games, both from pre-0.10 versions of this mod, and games based on FfH II 0.22h-0.23c.

Fair Combat
This is a modmodmod which increases units' hit points, and causes more rounds of combat. This has the net effect of improving the odds for the stronger unit, but making it more likely that that unit will be damaged.
 
Defects:
  1. Multiplayer: playing with any AI player (including barbarians) apparently causes an out-of sync error in relatively short order. Present since 0.10.
  2. Withdrawal: It doesn't work; withdrawal percentages are effectively 0% until this is fixed. (thanks for reporting this Sastopher; I don't know how this was uncaught for so long). Present since 0.08.
  3. War script: There is a defect in the war script. At the present time, I'm uncertain of the extent of this defect. Present since 0.16.
  4. Crash defect involving civilizations with 0 cities. Present since 0.16

0.17: (unreleased, tentative)
  1. Removal of known multiplayer out-of-sync error. Will break saved games.
  2. Settler AI much less likely to settle on top of mana resources (thus denying them the opportunity to improve it).
  3. Withdrawal fix: withdrawal percentages now function correctly.
  4. Stoneskin base number of hits is now modifiable via XML.
  5. Crash defect involving a civilization with 0 cities removed.

0.16:
  1. High Strength Fire units can add smoke to Jungle and New Forest, not Ancient Forest.
  2. Speed increases (Units, Plots general)
  3. Fair Combat (or any variant with over 100 HP) fixes: Spells die at end of combat, Goblin dies at end of Wolf Capture, Werewolves die on promotion, Rust, Convert, Cheat, Hideous Thoughts, Roar, Rebuild Barnaxus, Feed, Mokkas' Cauldron, Tar Demon split, Baby Spider Spawn, Immortal, upgrade of Wolf to Wolf Pack all scale properly.
  4. Fix to Mind Affinity.
  5. Algorithmic speedup change : City defenders.
  6. Caching speedup : unit strength. Will break saved games.
  7. Build AI crashes removed in certain rare Sprawling cases (division by 0 errors due to negative yields).
  8. Warscript now plans wars, instead of automatically executing them.
  9. Barbarian technological advancement brought more in line to Vanilla (was unchanged despite the wildly differing tech trees).
  10. Barbarian technological research now modified by game speed, world size, and start era (just like other players).
  11. Khazad AI can now build mercenaries, but only if it would have overflowing coffers afterwards.
  12. Khazad AI will not sacrifice income for technology unless it would still have overflowing coffers.
  13. Khazad AI will always attempt to obtain the next level of coffers until they are overflowing.
  14. More aggressive response to loss of units to Barbarians.
0.15:
  1. Fix to bonus evaluation when there's no capitol (may impact Hyborem).
  2. Attempted fix for multi-player synchronization issue. (Bonus evaluations weren't consistent across different players). Will break saved games.
  3. Separate "Fair Combat" version added to database.
0.14:
  1. Fix for infinite recursion due to inability to find valid art.
0.13:
  1. FIRST_STRIKE_FACTOR should now work correctly (it was broken at any setting other than the default)
  2. Minor speedup changes (cvGame colors)
0.12:
  1. Several fixes to the Culture pressure code (this is for calculating the value of Great Works for the AI).
  2. AI is less likely to sacrifice high XP units for Great Works.
  3. 0.23c merge (breaks save games)
0.11:
  1. Changed settlement code to allow the AI to grab slightly more bonuses per city.
  2. Yet more Sprawling fixes (nope, still not complete). These ones have to do with settlement activity, as well as a player-based one I injected a number of revisions ago.
  3. Changed mana selection code (via building improvements) to use the new Bonus evaluation.
  4. Fix to Great Work code for non-victory great works (essentially, if one of the threatened tiles was owned by a friendly player, the AI might completely ignore that city in favor of one that was in far less distress).
  5. Allow prophets/disciples to use great works.
  6. AI no longer must settle on initial plot.
  7. Combat change: getExtraCombatPercent/getExtraCombatPercentDefense fix ported from 0.23c
  8. Combat change: Attacker's strength is now modified by the defender's resistance. Note that at the present time, the attacker's strength can't be reduced below 0.01 by this method, so immunity isn't perfect for defenders (but it's very close).
0.10:
  1. New Bonus evaluation, including XML interface for various AI factors.
  2. Yet more Sprawling fixes (nope, still not complete).
  3. Will Break save games (needed for a defect fix).
  4. Fix for a city resource issue (hopefully now it's final - there was a problem in Vanilla with bonuses from buildings).
  5. Halved preference for cheap technologies.
Spoiler :

0.08:
  1. Fix for mana build preference by AI (this is a fix to the present code, not a change in the mechanism used).
  2. Python speedup.
  3. Stoneskin fixes (in combat odds - human, AI, and AI's estimate for a defending unit).
  4. Lifespark change (allow multiple lifesparks to sacrifice in 1 combat round).
  5. Lifespark Odds fixes (in combat odds - human, AI)
  6. Combat odds changes (default is the same, but a larger degree of possibilities via XML - GlobalDefinesAlt.xml)
    • COMBAT_DENOMINATOR - makes all combat calculations using a divisor (so in the case that this value is 10, all calculations for damage are made in tenths). Note that final damage is rounded down at the end of combat.
    • FIRST_STRIKE_FACTOR - A multiplier for number of first strikes.
    • STONESKIN_FACTOR - A multiplier for the number of hits ignored by Stoneskin
    • HEALING_FACTOR - A multiplier for unit healing, Heal, and Lifespark healing.
    • MAGIC_DAMAGE_FACTOR - a multiplier for magical damage done via doDamage. Note that any magical damage done via another means is unaffected (no such means are presently noted).
    • LIFESPARK_BASE_HEAL - the base amount of healing for a Lifespark, which is multilied by HEALING_FACTOR (and COMBAT_DENOMINATOR)
0.07:
  1. Fix for a city resource issue.
0.06:
  1. Yet another Sprawling fix.
  2. Patch for an undetermined visibility issue (essentially, we dis-allow negative visibility).
  3. Patch for an undetermined city resource issue (essentially, we dis-allow negative resources in a city).
0.05:
  1. Crash on AI's looking at attacking an undefended city with a general attack removed.
  2. Minor fix to Mana trading
0.04:
  1. Hash function change (speed improvement)
  2. Reducing Hash function calls (speed improvement)
  3. Allow trading for mana 2+ (along with draft evaluation of the value to the AI)
0.03:
  1. Merge with 0.22h
  2. A few optimizations for the unit AI (path finding for units is taking lots of time; this condenses a bit of that path finding).
  3. Fixes for Sprawling code (still incomplete).
0.02:
  1. Several crash defects fixed.
  2. XML modifications are in. They have a significant impact on the Technology choice selection in particular.
  3. Fixes for Sprawling code (size of cities).
  4. Fixes for Sacrifice the Weak (complete).
0.01:
  1. Merged FfH II 0.21f C++ code with BetterAI
  2. Fixes for Sprawling code (size of cities).
  3. Fixes for Sacrifice the Weak (number of food used per population).
  4. Some logging code is compiled out (for speed).
 
I get a CtD on ending the first turn. Any information I could collect that might help you?
 
CTD on first turn as well.

(And what a pity! I was drowning in resources on a Standard Pangaea w/ Pressed Coast-from my capital I could see: 2 Wheat, Pig, Ivory, Silk, Reagents, Incense, Gold, 2 Furs, Sheep, Mana, 2 Goody Huts, 1 Flood Plain)
 
In the event that you can get a saved game which consistently does this, yes. Otherwise, probably not. I was able to get the crash once out of a number of attempts. Hopefully, I'll be able to replicate the issue (and thus be able to fix it).
 
The CtD happens every time, every game. Sure I can send you a save game of any of those crashable games, but I think it must be a difference in between our configurations, since I really do get this crash every single time I start a game. This is 2021f, yes? I made sure to install a fresh f before copying over your gamecoredll.
 
You are correct; when I play in Full-screen mode, I get the same symptom. When I play with Full-Screen mode turned off, I get it very infrequently.

I've found a source (ViSa) that has fixed a number of defects in the BetterAI code. I'll try merging those fixes in, then see if this defect still exists. If so, I'll chase it down myself.
 
Unfortunately, it wasn't fullscreen mode that did it for me. I switched it off, restarted, and still get the same crash. I went to options and set everything to default, except fullscreen mode, restarted again, but still the same problem.

I play with the standard pangaea mapscript on tiny. I do nothing on my first turn except press the end turn button.

What else can I do to help you fix this?
 
\Documents and Settings\<Your Username>\Cid Meier's Civilization 4 should have a Civilization IV.ini file that may be of use.

In that same directory, there is a logs folder; those logs may be of use.

Probably most importantly, send my the curent .pfl file you're using from \Documents and Settings\<Your Username>\My Games\Application Data\Cid Meier's Civilization 4\Profiles

I'd suggest zipping everything up; the .pfl file in particular probably won't get past the filter here.

I guess also that at the moment, the objective is to replicate the defect consistently. Once it's found, fixing is only a matter of time.
 
Have you tried turning on asserts? (put /DFASSERT_ENABLE under "other options" in project build options)
I get several about different things when doing so. Might even help with solving the crash problem... but should atleast help with solving some bugs.
 
Okay, I've put those things into a rar archive. I couldn't be bothered to install a zipping program, but civfanatics doesn't want .rar, so just remove the .zip from the filename (or use a smart archiver that'll recognize this isn't REALLY a zip ;))

Should I compile a version with asserts on as well? Would that help?
 

Attachments

  • Sid Meier's Civilization 4.rar.zip
    16 KB · Views: 65
To both Snarko and Bringa. I did have asserts off (which was not helping the debug output), and it seems that Bringa's Civilzation.ini file is what I needed to replicate this.
 
Cool :) Soon as you find out what it is in my ini that caused the problem, do tell me!
 
Cool :) Soon as you find out what it is in my ini that caused the problem, do tell me!
I think that the better solution to that problem, should you want to try to run,
try out my .ini file (backup yours, and remove the .txt at the end before using). If that seems to work pretty well, I'd appreciate it if you'd try to figure out which line is causing the immediate problem (assuming it's a single line, the fastest method is typically to take half of each one combined into a single file, determine if that's causing the issue, then take halfway between the middle one and the end that gives you the inverse result, etc. until you're down to a single line).

Turning on asserts (for some reason I had just assumed that they were on) has pointed out the enormity of the issue. Let's start with the basics of my investigation:

The defect density of this code is high. There are two apparent major sources:
1) The merge, itself.
2) BetterAI

In both cases, the end result of many of these defects is a call to a method of an apparently uninstantiated class. This means that sometimes the defect is harmless; other times it causes significant damage. There are several ways I can attempt to approach this:
1) Fix this code, by using inspection-like practices. Release a new version every week (or only at the end of this process).
2) Merge with the defect fixes in ViSa. The advantages versus #1 is that it would likely be faster; the disadvantage is that new defects would likely be included in that merge.
3) Scuttle this merge. Work on other pieces of the AI, and get back to this either when BetterAI is more stable and/or I'm more familiar with the environment, code, and have better tools.

I'm tending towards #2, and then #1 for the merge issues (primarily the sprawling code). I think that the advantages of BetterAI are worth spending some time on. Let me know if you have a different opinion.
 

Attachments

  • CivilizationIV.ini.txt
    5.6 KB · Views: 69
I found it. It's this line:

; Enable voice over IP capture and playback
EnableVoice = 0

If I set this to 1, the game crashes on ending the first turn. If I set it to 0, the crash doesn't occur. I'll do some more game-testing tonight.

I don't think I've ever even USED that feature; why the hell did I have this set to 1?

Edit: after looking at xanaqui's ini, I found that this line alone cannot be the problem. He has it set to one, and apparently it's working for him. However, using my own ini, I can switch back and forth between 0 and 1 and every time get the expected behaviour (0 = everything works, 1 = crash on ending first turn). Interesting. We'd need more testers, I think.
 
Haha! Man, synchronicity rocks ;) (we posted this at pretty much exactly the same moment; when I loaded the thread your post wasn't there yet)

Oh and concerning the merit of BetterAI: I played a game with the normal BetterAI yesterday on a small map with three AIs on noble, and they KICKED MY ASS. This doesn't happen. I can do Monarch difficulty without BetterAI. Also, the city governor was really helpful. I never caught it doing something less than optimal, and many times it thought of things that hadn't occurred to me. Definitely worth investing the time.
 
Okay, I've played a 220 rounds game with this, and it's great fun. It was on noble, small pangaea with 3 other civs. I won a conquest victory without too much trouble, but there was definitely improved performance over normal FFH. The problem, as far as I can tell, was teching priorities. My enemies wasted literally hundreds of turns with useless techs (read magic techs that they didn't know how to use) so that by the time I pushed with trebuchets and hammerfists, they still had the equivalents of hunters and axemen in their cities. However, a lot of things were very cool. For instance, my clan neighbour did properly protect his border cities from me (and well, too! There were about 14 spearmen in one of them at one point, which made me discard my "kekeke dwarven soldier rush" strategy).

My next step will be to merge my xml changes with this stuff. The project on sourceforge is still "pending review".
 
Okay, I've played a 220 rounds game with this, and it's great fun. It was on noble, small pangaea with 3 other civs. I won a conquest victory without too much trouble, but there was definitely improved performance over normal FFH. The problem, as far as I can tell, was teching priorities. My enemies wasted literally hundreds of turns with useless techs (read magic techs that they didn't know how to use) so that by the time I pushed with trebuchets and hammerfists, they still had the equivalents of hunters and axemen in their cities. However, a lot of things were very cool. For instance, my clan neighbour did properly protect his border cities from me (and well, too! There were about 14 spearmen in one of them at one point, which made me discard my "kekeke dwarven soldier rush" strategy).

My next step will be to merge my xml changes with this stuff. The project on sourceforge is still "pending review".

I'm glad you were able to play this. I agree with your assessment - there were numerous improvements to the AI, but there was relatively little improvement (possibly negative improvement) in technology choices (but note that in Vanilla, the worst and the best technology choices are much closer together than they are in FfH II - which may be why Technology choices weren't completely re-vamped in BetterAI).

I agree that at the moment, adding XML flavor changes for technology would be the greatest boon we can do in a short time period; I will work on defect fixes in this merge.
 
This is a great project. FFH2's worst deficiency at the moment is its incompetent AI: after playing BetterAI in vanilla, I'm spoiled and get bored with games where it's so easy to roll over my opponents.
 
Top Bottom