Help with adding modifiers to luxuries

Demon2222

Chieftain
Joined
Feb 19, 2008
Messages
11
I'm trying to make a mod to add different modifiers and affects to different luxuries, similar to how marble adds a modifier to world wonders. So far I have Citrus gives 10% growth rate, dyes give +10 resting point to city-states, and -10% modifier to missionary and prophet costs.

When I go to test it out, none of them work. Is there something I'm doing wrong? Nothing was wrong when I debugged it.

Code:
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by ModBuddy on 7/31/2012 4:02:00 PM -->
<GameData>
	<Resources>
		<Update>
			<Set CityGrowthModifier="10"/>
			<Where Type="RESOURCE_CITRUS"/>
		</Update>
		<Update>
			<Set CityStateMinimumInfluence="10"/>
			<Where Type="RESOURCE_DYE"/>
		</Update>
		<Update>
			<Set MissionaryCostModifier="-10"/>
			<sET ProphetCostModifier="-10"/>
			<Where Type="RESOURCE_SILK"/>
		</Update>
	</Resources>
  
</GameData>
 
The column names that you use don't exist in the Resources table. So they don't have any effect, and probably cause the entire file that contains them to fail.

You can add new columns to tables, but to make them work you need to code their effects using LUA (see this thread), or, in the future, in the DLL code (it's not released yet).
 
Also, it's Set, not sET
 
Also you can only have one <Set> per <Update>, so it would be

Code:
<Set MissionaryCostModifier="-10" ProphetCostModifier="-10"/>

But see comment about inventing column names above

All these errors would be listed in the database.log file, so make sure you have logging enabled!
 
Another way of doing it is:

Code:
<Update>
     <Where Type="RESOURCE_SILK"/>
     <Set>
           <MissionaryCostModifier>-10</MissionaryCostModifier>
           <ProphetCostModifier>-10</ProphetCostModifier>
     </Set>
</Update>
 
I added some SQL to put new columns in the Resources table. Not sure if it's correct though.

I have no clue where to start with the lua code, although I suspect that I would need to use the SerialEventImprovementCreated Game Event somewhere. Anyone care to help me out?

SQL
Code:
ALTER TABLE Resources
ADD COLUMN 'CityGrowthModifier' 'CityStateMinimumInfluence' 'MissionaryCostModifier' 'ProphetCostModifier' TEXT DEFAULT NULL;

XML
Code:
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by ModBuddy on 7/31/2012 4:02:00 PM -->
<Table name="Resources">
	<Column name="CityGrowthModifier" type="integer" default="0"/>
	<Column name="CityStateMinimumInfluence" type="integer" default="0"/>
	<Column name="MissionaryCostModifier" type="integer" default="0"/>
</Table>
<GameData>
	<Resources>
		<Update>
			<Set CityGrowthModifier="10"/>
			<Where Type="RESOURCE_CITRUS"/>
		</Update>
		<Update>
			<Set CityStateMinimumInfluence="10"/>
			<Where Type="RESOURCE_DYE"/>
		</Update>
		<Update>
			<Set MissionaryCostModifier="-10" ProphetCostModifier="-10"/>
			<Where Type="RESOURCE_SILK"/>
		</Update>
	</Resources>
  
</GameData>
 
I have no clue where to start with the lua code, although I suspect that I would need to use the SerialEventImprovementCreated Game Event somewhere. Anyone care to help me out?

You suspect wrong, for two reasons.

First, SerialEventImprovementCreated is a Serial event, meaning it's designed for the UI to use; it triggers whenever the improvement artwork on the tile changes. As a result, it only triggers in four situations:
1> If you see the improvement start construction (which means it'll trigger even before the improvement exists)
2> If you see the improvement FINISH construction (so yes, it'll trigger twice for improvements you create)
3> If you see the improvement change state (i.e., it gets nuked or pillaged, or repaired afterwards)
4> If one of your units gains visibility to the hex containing that improvement, no matter how long ago the improvement was actually constructed. ("You", in this context, meaning the active player.)
So you can't use this event for something that is supposed to trigger whenever an improvement finishes construction, because AI improvements for civs on another continent wouldn't trigger it until late in the game, and then they'd all trigger at once.

But secondly, you don't WANT a trigger for when the Improvement is created; for most of the things you described, you just want to know if the improvement is present and being worked, right now. For that, you'll need to take a more accessible function (preferably PlayerDoTurn), check for the presence of the improvement using the ImprovementCount function in the Player structure, and then loop over all hexes near that player's cities to see if any of them are being worked. This is not a small amount of overhead, but it's better than most of the alternatives. Once you have the locations for all of the improvements of a given type, apply any appropriate benefits. Directly applying something like a yield bonus in Lua is messy, as the UI won't reflect the change (i.e., it might say it'll take 10 turns until the city grows, when in fact it'll grow in 5); the usual way around this is to tie the benefit to a hidden building, instead. That is, make an unbuildable (cost = -1) building that gives the growth bonus, and give or remove it based on whether the city is working that luxury; the UI will now give the correct values for growth rate and all derived quantities, even if it says the benefit is from buildings instead of resources. (That can be fixed, as well, but it's usually not worth it.)

Regardless of which event you use, though, the AI won't value it correctly. The AI won't know that your luxuries give extra benefits, so it won't consider them any more valuable than they were under the vanilla system, and that means the human player will be at a huge advantage. This is true of nearly anything done in Lua, and can often result in some severe AI behavior issues. For example, if you reduce food production across the board, to where each city is negative, and then use Lua to add a lot of Food based on various factors, then the AI will react as it would if it was starving, regardless of how much food it'll actually have at the end of the turn. There's just no easy way to explain to the AI that the starvation isn't actually a problem, since it has no way to see what your Lua will do.
 
Back
Top Bottom