Updating Health Level Bonuses

Ustgar

Chieftain
Joined
Jan 24, 2010
Messages
6
Hello,

I'm new to modding so I'm probably making some noob mistake. I'm trying to modify health level bonuses. As a test, I'm trying to make it so starting at health level 5 (rather than the default 20) you begin to receive bonuses to culture. This is my XML:

<?xml version="1.0" encoding="utf-8"?>
<!-- Created by ModBuddy on 11/1/2015 11:29:00 AM -->
<GameData>
<HealthLevels>
<Update>
<Where Type ="HEALTH_LEVEL_BONUS_CULTURE"/>
<Set HealthStart ="5"/>
</Update>
</HealthLevels>
</GameData>


This is the relevant section of the Database.log file:

[50249.218] UNIQUE constraint failed: HealthLevels.HealthStart
[50249.218] While executing - 'UPDATE HealthLevels SET "HealthStart" = ? WHERE "Type" = ?;'
[50249.218] Database::XMLSerializer (HealthLevels.xml): There was an error executing the update statement! See Database.log for details.
[50249.218] UNIQUE constraint failed: HealthLevels.HealthStart
[50249.218] In XMLSerializer while updating table HealthLevels from file HealthLevels.xml.
[50251.640]

What am I doing wrong?
 
Code is correct, but I've had some problems with the health levels in the past, for some reason it seems like that the HealthLevels-Table can't be updated properly, neither with XML nor with SQL.

A (not very clean) workaround is to just use the <Replace>-Tag:

Code:
<HealthLevels>
	<Replace>
		<Type>HEALTH_LEVEL_BONUS_CULTURE</Type>
		<Help>TXT_KEY_HEALTH_LEVEL_BONUS_HELP</Help>
		<HealthStart>5</HealthStart>
		<HealthEnd>40</HealthEnd>
	</Replace>
</HealthLevels>
That method is not possible for all tables - at least not without fixing the IDs afterwards, as replacing an entry basically deletes the original entry and creates a new one with a new ID, leaving a gap that can crash the game in other scenarios - but it works in this case.

There may be better solutions that I'm not aware of.
 
Thanks you so much for your input!

I tried the XML you posted above and it worked. However, for some reason it had the side effect of removing the normal health production bonuses. I added in the following XML:

Code:
<Replace>
	<Type>HEALTH_LEVEL_BONUS_PRODUCTION</Type>
	<Help>TXT_KEY_HEALTH_LEVEL_BONUS_HELP</Help>
	<HealthStart>6</HealthStart>
	<HealthEnd>25</HealthEnd>
</Replace>

And that restored the original health level production bonus functionality. Seems very odd that I need to do that. And, as you mentioned, this isn't a particularly clean solution.

How do you go about fixing the IDs of a table you replace?

edit:

I modified my XML to try to change the growth bonuses as well. Now the growth bonuses are working, but the culture and production bonuses have been removed. Any idea why this is?

Here is my current XML:

Code:
<GameData>
	<HealthLevels>
		<Replace>
			<Type>HEALTH_LEVEL_BONUS_CULTURE</Type>
			<Help>TXT_KEY_HEALTH_LEVEL_BONUS_HELP</Help>
			<HealthStart>5</HealthStart>
			<HealthEnd>40</HealthEnd>
		</Replace>
		<Replace>
			<Type>HEALTH_LEVEL_BONUS_PRODUCTION</Type>
			<Help>TXT_KEY_HEALTH_LEVEL_BONUS_HELP</Help>
			<HealthStart>5</HealthStart>
			<HealthEnd>25</HealthEnd>
		</Replace>
		<Replace>
			<Type>HEALTH_LEVEL_BONUS_GROWTH</Type>
			<Help>TXT_KEY_HEALTH_LEVEL_BONUS_HELP</Help>
			<HealthStart>5</HealthStart>
			<HealthEnd>45</HealthEnd>
			<CityGrowthModifierPerPoint>10</CityGrowthModifierPerPoint>
			<OutpostGrowthModifierPerPoint>5</OutpostGrowthModifierPerPoint>
		</Replace>
	</HealthLevels>
</GameData>
 
Fixing IDs via SQL:
Code:
CREATE TABLE IDRemapper ( id INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT );
INSERT INTO IDRemapper (Type) SELECT Type FROM HealthLevels ORDER BY ID;
UPDATE Buildings SET ID =	( SELECT IDRemapper.id-1 FROM IDRemapper WHERE HealthLevels.Type = IDRemapper.Type);
DROP TABLE IDRemapper;
(Example from here: http://forums.civfanatics.com/showthread.php?t=463429)

That may already fix the other issue as well.
 
Top Bottom