• Civilization 7 has been announced. For more info please check the forum here .

Handicap XML changes giving me fits!

Barghaest

King
Joined
Apr 18, 2011
Messages
758
Okay, if I directly alter the XML (not via mod) I can alter Handicap settings just fine and see their effects in game; however, trying to get my mod to do so is giving me fits.

I've tried the following:

Spoiler :

<HandicapInfos>
<Update>
<Where Type="HANDICAP_PRINCE" />
<Set>
<HappinessDefault>15</HappinessDefault>
<RouteCostPercent>80</RouteCostPercent>
<UnitCostPercent>80</UnitCostPercent>
<BuildingCostPercent>80</BuildingCostPercent>
<BarbarianBonus>10</BarbarianBonus>
<AIBarbarianBonus>10</AIBarbarianBonus>
<AIUnhappinessPercent>91</AIUnhappinessPercent>
<AIGrowthPercent>91</AIGrowthPercent>
<AITrainPercent>91</AITrainPercent>
<AIConstructPercent>91</AIConstructPercent>
<AICreatePercent>91</AICreatePercent>
<AIBuildingCostPercent>91</AIBuildingCostPercent>
<AIUnitCostPercent>91</AIUnitCostPercent>
</Set>
</Update>
</HandicapInfos>


(With other entries for other handicaps as well) and the only thing that takes effect is the Happiness change. I can mouse over happiness and see the 15 for Difficulty. There is no visible change to Unit Maintenance and it still shows +40% in the preview when I attack barbarians.

When I did these as direct xml adjustments before attempting to package my mod, mousing over the Unit, Building or Route sections of the Economic Overview (F2) would have the additional line "You are paying 80% of normal because of your difficulty setting" and combat previews with barbs showed +10%.

I have tried using SQL and the same thing happens (even when I do a single update for each line).

I have tried using <Delete/> and re-entering each entry using <Row> in place of <Update> (and the missing areas I did NOT change with Update) and the game has a CTD when trying to build the world.... logs say "ERROR: Game does not contain valid handicap!!" in GameCore.log (despite the fact I re-added each entry).

I get the same issue if I do not use <Delete/> and instead use <Replace> pasting the entries exactly from the default game xml just altering specific lines. I've tried including and not including <ID>0</ID> in the Settler setting with no effect on outcome.

So, has anyone managed to alter additional settings in the Handicaps besides just Happiness? (I can alter the other subsections fine, as I have removed all AI Free Tech and tested my mod on Immortal and 50 turns in both my empire and the AI all had only 1 tech when the summary screen appeared).

I could possibly believe the Unit maintenance discount and barbarian bonus were display issues; however, they display properly in Solo play when I alter the xml directly and my mod has no UI changes (not running any others either until I get mine fully functional) and runs no LUA script. Pure XML (except my one attempt to alter handicap via SQL).

EDIT: Ran a few more tests using IGE and editing the core game files. Using IGE to check on other Civs proved my changes to their number of starting units was functioning (so I suspect the other AI changes are as well) and modding the core files and reloading a save in my mod turned out the combat preview and unit maintenance are display issues (since the combat outcome 18 damage to barb and 48 to my scouts was identical with and without core xml changes but preview showed correctly when I altered core xml directly).

This will still be an issue for people who use my mod without a UI upgrade that corrects the issues and I find it quite annoying myself.
 
Do you have <GameData> tags around the entire thing? I guess you must have if some of it works. If only happiness changes kicks in, one would assume something is wrong with the way you write multiple lines after each other in the same update tag. Have you tried separating them into different tags?
 
If you delete a handicap and add a new one, you should assign an ID to the new one the same as the ID of the old one (you can check the IDs when viewing the database). If you don't do it, it places the one you added after the last one, which creates a "hole" in the table where the deleted handicap was, which causes the error you described.

I don't know why the code you posted doesn't work, perhaps there is an issue with multiple elements in <Set> (I usually use SQL for such changes).
 
Do you have <GameData> tags around the entire thing? I guess you must have if some of it works. If only happiness changes kicks in, one would assume something is wrong with the way you write multiple lines after each other in the same update tag. Have you tried separating them into different tags?

Yes, I have them in a section of <GameData> and it's not that only the Happiness changes kick in... all of the changes appear to be function after several tests but the combat preview for attacking Barbarian units still displays old values (after multiple tests I've concluded it IS using the new values but the preview is still referencing the old values) but if I change the bonus vs barbs associated with Honor opener, the preview adjusts THAT just fine.

I do not understand why or how this is happening. If I alter the game xml files directly (open it in notepad and manually change the value) the combat preview shows correctly, so these values aren't hardcoded. So why does altering them with a mod not alter the preview?

If you delete a handicap and add a new one, you should assign an ID to the new one the same as the ID of the old one (you can check the IDs when viewing the database). If you don't do it, it places the one you added after the last one, which creates a "hole" in the table where the deleted handicap was, which causes the error you described.

I don't know why the code you posted doesn't work, perhaps there is an issue with multiple elements in <Set> (I usually use SQL for such changes).

Tried that. If I delete all the handicaps and re-paste exactly as they are in Handicapinfos.xml (with Settler having <ID>0</ID>) I still get a CTD. There is something quirky about the way it attempts to access Handicap information in game when modded. And the code I posted IS working, just for some reason elements of the UI are ignoring modded values. I've tried using bc1's Enhanced UI to see if his changes to UI clear up the problems, they do not. I've tried using WHarold's Enhanced DLL to see if any of his bugfixes helped, they did not.

Eventually I'll find some UI mod for combat preview and see if it helps, but once I discovered the actual changes were working just UI was somehow pulling unmodded values for display I moved on to work on a few other more critical issues with my mod.

Even using SQL to changes values one at a time had no effect on the combat preview values. I was thinking of using an SQL formula to set the BarbarianBonus to (25-(ID*5)) so Settler would 25, Emperor 0, and Deity -10 to see if that works on preview.

But currently:
UPDATE HandicapInfos SET BarbarianBonus=10 WHERE Type="HANDICAP_PRINCE";

Does not change the combat preview while going into:
Sid Meyer's Civilization V/Assets/DLC/Expansion2/Gameplay/XML/GameInfo/CIV5HandicapInfos.xml
and manually changing the entry under HANDICAP_PRINCE to <BarbarianBonus>10</BarbarianBonus> does affect the combat preview. So wherever it's sticking the modded value is used to calculate the actual combat but not used to display on the combat preview.
 
UPDATE:

Okay, after extensive testing, here's my theory... when the game loads up, it loads all the info from the xml into a virtual area I'll call "Current Game Data". Any mods adjust the values in this virtual area. In the case of the combat preview glitch, when it goes to look up BarbarianBonus for your current Handicap, it references the actual xml file (or perhaps another virtual area that can't be touched by mods) instead of "Current Game Data".

This issue is further compounded by some actual game calculations referencing the files instead of the modded "Current Game Data" (one case in particular is FaithPercent from GameSpeeds.xml - you can mod that with XML or SQL and it's moot, the game still references the Gamespeeds.xml file when calculating that... so no matter if you change FaithPercent for Marathon to 100 or 5000, you'll still need 30 Faith for the first pantheon and 600 for first prophet - unless you open up the .xml file in the game directory and manually adjust the value there).

So, I had three options for bypassing this issue.

#1 - Create custom gamespeeds/handicaps and leave instructions with the mod as to how to select them and warning not to try using the default game ones.
#2 - Include copies of core game .xml and instructions for users of mod to overwrite their files by putting these in particular directory (most accurate correction however most inconvenient for user as they'd have to keep swapping out files when switching from mod to vanilla and anytime game patches or verifies local content).
#3 - Scrap the idea of including multiple game speeds and just include one and alter Faith and Espionage settings under Defines. Not my preferred choice but a fallback if all else fails.

So, I went with #1. It's ugly but it works. And I have to settle for all game speeds having the same faith costs since default for FaithPercent is 100 and no amount of XML or SQL modding can alter that... I'm just hoping that SpyRatePercent isn't still "hardcoded" the same way or attempting espionage in my mod will be completely impossible unless I resort to Option #2 or #3 (and SpyRatePercent having this issue was why I gave up my attempts at packaging my mod back after G&K released...)

Of course, there's another option of diving into DLL to see if this bug can be fixed there; however, I have no experience with DLLs and currently lack a program to properly open one.
 
It's interesting what you say about the combat preview and other UI areas displaying incorrect values - perhaps the UI somehow uses the old values from before the mod changes... I haven't tested it, but I will need to do it when making my mod. Btw, if you want to make changes to the UI, in most cases you don't have to make changes to the DLL code - most of the UI code is located in XML and Lua files - see assets\UI and assets\DLC\expansion2\UI folders (as with the XML files, if a file is not present in the expansion folder, the vanilla version is used).

The "virtual area" you write about is the game database. It's located in My Documents\My Games\Sid Meier's Civilization 5\cache\Civ5DebugDatabase.db. You can view it using any of the tools that can open SQLite files (I use the SQLite manager add-on for Mozilla Firefox browser). Viewing the database is IMO absolutely necessary to understand Civ5 modding and avoid possible problems (another necessary thing is to enable logging and database validation and check database.log for errors).

If you view the database, you can see that all handicaps have IDs - only 0 for Settler is assigned in the XML, but the other ones have IDs too, assigned automatically by SQLite - Chieftain has 1, Warlord has 2, and so on. So if you delete Prince (ID 3), when you re-add it, you should give it <ID>3</ID>. Without it, it's placed after all existing handicaps (ID 9 if you use BNW).

(I don't think it will help you with your problem, but I think you should know how it all works :))
 
Yeah, I was aware of the ID issue and it didn't fix the problem. Somewhere the game keeps trying to access original handicaps and throws up errors if you have deleted them even if you've put the IDs on your replacements.

Haven't bothered trying to view the actual database file, but I had the impression it would be somewhere in My Documents or my Virtual Memory area...

As for modding the UI, was aware most of the changes could be done via LUA, but not sure that'll fix the issue since I've tried a few UI mods (like bc1's) and still same issues. I did discover there apparently a +25% bonus vs barbarians that is hidden (doesn't show up in combat preview but if you do the math on Effective Combat Strength compared to your default for the unit it's always 25% higher when fighting barbarians - at least on my current game playing Mongols haven't tested another Civ yet - and I can't find any references to it in the GlobalDefines).
 
IIRC the hidden +25% bonus vs barbarians applies only when the Raging Barbarians option is active.
 
IIRC the hidden +25% bonus vs barbarians applies only when the Raging Barbarians option is active.

AHA! That's it then, I always use Raging Barbarians because it gives more camps for me to farm for early gold (and keeps me occupied clearing the hordes so the slow pace games I play don't get too dull in the early parts when there's little else to do).
 
IIRC the hidden +25% bonus vs barbarians applies only when the Raging Barbarians option is active.

And before anyone asks how to change it, it's hard-coded

Code:
if(GC.getGame().isOption(GAMEOPTION_RAGING_BARBARIANS)) {
    iModifier += 25;
}

(twice in CvUnit.cpp)
 
Top Bottom