Modding Practice: Identical Modifiers

Magil

Monarch
Joined
Sep 26, 2010
Messages
1,622
There's something I'm wondering about Civ VI modding and the modifier system. Is there a reason to use a separate modifier for each element you wish to apply it to instead of just making one modifier and apply it to each element?

Let's say you have three buildings which, among other effects, provide +25% Gold. How Civ VI base code seems to do it is make a separate modifier for each one, like BuildingOne25PercentGold, BuildingTwo25PercentGold, and BuildingThree25PercentGold, and attach it to each building appropriately. My testing, however, has shown little downside to simply making one modifier like "25PercentGold" and attach it to each building. Even if all three are built in the same city, they seem to stack correctly.

But maybe I'm missing something (something obvious?), so I'd appreciate a second pair of eyes to confirm or deny this.
 
I guess it all depends on what modifiertype you're using and what situation you are using modifiers. I do the separate modifiers for each effect when doing city states, as that is how the base game does it. Other than setting a requirementset to the 25PercentGold modifier, I don't know how you would get around using 3 separates modifiers.
 
I guess it all depends on what modifiertype you're using and what situation you are using modifiers. I do the separate modifiers for each effect when doing city states, as that is how the base game does it. Other than setting a requirementset to the 25PercentGold modifier, I don't know how you would get around using 3 separates modifiers.

For example:

Code:
      <Row>
           <BuildingType>BUILDING_MARKET</BuildingType>
           <ModifierId>25_PERCENT_GOLD</ModifierId>
       </Row>
       <Row>
           <BuildingType>BUILDING_BANK</BuildingType>
           <ModifierId>25_PERCENT_GOLD</ModifierId>
       </Row>
       <Row>
           <BuildingType>BUILDING_STOCK_EXCHANGE</BuildingType>
           <ModifierId>25_PERCENT_GOLD</ModifierId>
       </Row>

As opposed to:

Code:
      <Row>
           <BuildingType>BUILDING_MARKET</BuildingType>
           <ModifierId>MARKET_25_PERCENT_GOLD</ModifierId>
       </Row>
       <Row>
           <BuildingType>BUILDING_BANK</BuildingType>
           <ModifierId>BANK_25_PERCENT_GOLD</ModifierId>
       </Row>
       <Row>
           <BuildingType>BUILDING_STOCK_EXCHANGE</BuildingType>
           <ModifierId>STOCK_EXCHANGE_25_PERCENT_GOLD</ModifierId>
       </Row>

The latter is more how the base game does it in most cases, but I'm wondering if there's really any real downside to doing the former.
 
Probably it's done this way for debugging purposes. Also, do the same modifiers stack? Because I'd imagine that you just apply +25% Gold if a city has any of these buildings as opposed to adding the bonus for each building. I can unfortunately not test this myself right now :/
 
Probably it's done this way for debugging purposes. Also, do the same modifiers stack? Because I'd imagine that you just apply +25% Gold if a city has any of these buildings as opposed to adding the bonus for each building. I can unfortunately not test this myself right now :/

They do stack, yes. If you add the same modifier to a city multiple times through multiple effects (like through the BuildingModifiers table), it will stack.
 
They stack fine. Multiple buildings can use the same modifier, and the same building can use multiple modifiers of the same "type". So I can do this:
Code:
<BuildingModifiers>
	<!-- BUILDING_NATIONAL_MUSEUM_LRS gives a total of +10% YIELD_SCIENCE -->
	<Row BuildingType="BUILDING_NATIONAL_MUSEUM_LRS" ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_002" />
	<Row BuildingType="BUILDING_NATIONAL_MUSEUM_LRS" ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_008" />
</BuildingModifiers>
Where I have defined a "bits" set of modifiers like this:
Code:
<Modifiers>
	<!--Adjust City Yield %-->
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_001" ModifierType="MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_002" ModifierType="MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_004" ModifierType="MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_008" ModifierType="MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_016" ModifierType="MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_032" ModifierType="MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_064" ModifierType="MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_128" ModifierType="MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_256" ModifierType="MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_512" ModifierType="MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER" />
</Modifiers>
<ModifierArguments>
	<!--Adjust City Yield %-->
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_001" Name="Amount" Value="1" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_001" Name="YieldType" Value="YIELD_SCIENCE" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_002" Name="Amount" Value="2" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_002" Name="YieldType" Value="YIELD_SCIENCE" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_004" Name="Amount" Value="4" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_004" Name="YieldType" Value="YIELD_SCIENCE" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_008" Name="Amount" Value="8" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_008" Name="YieldType" Value="YIELD_SCIENCE" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_016" Name="Amount" Value="16" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_016" Name="YieldType" Value="YIELD_SCIENCE" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_032" Name="Amount" Value="32" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_032" Name="YieldType" Value="YIELD_SCIENCE" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_064" Name="Amount" Value="64" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_064" Name="YieldType" Value="YIELD_SCIENCE" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_128" Name="Amount" Value="128" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_128" Name="YieldType" Value="YIELD_SCIENCE" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_256" Name="Amount" Value="256" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_256" Name="YieldType" Value="YIELD_SCIENCE" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_512" Name="Amount" Value="512" />
	<Replace ModifierId="LRS_BUILDING_ADD_SCIENCE_YIELD_PERCENT_512" Name="YieldType" Value="YIELD_SCIENCE" />
</ModifierArguments>
Only downside I know of so far is that with MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER I cannot seem to use a CITY_HAS_BUILDING requirement like the modifier that is used by the Chichen Itza for the Culture, Production, etc, yield adjustments to Jungle Tiles. So you couldn't use these by themselves for a dummy building, for example, and then add or take away the dummy building. You can, however, set "Value" to a negative number, and the negative City Yield Modification is applied. So if you define a Positive Modifier building and a Negative Modifier building you can give and take away the effect.
 
Only downside I know of so far is that with MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER I cannot seem to use a CITY_HAS_BUILDING requirement like the modifier that is used by the Chichen Itza for the Culture, Production, etc, yield adjustments to Jungle Tiles. So you couldn't use these by themselves for a dummy building, for example, and then add or take away the dummy building. You can, however, set "Value" to a negative number, and the negative City Yield Modification is applied. So if you define a Positive Modifier building and a Negative Modifier building you can give and take away the effect.

It should work for something other than directly attaching the modifier to the building via the BuildingModifiers table. For example, you could attach it to a tech/civic or religious belief which uses MODIFIER_PLAYER_CITIES_ATTACH_MODIFIER utilizing a RequirementSet containing a REQUIREMENT_CITY_HAS_BUILDING Requirement, and the ModifierArgument for that belief can be the Modifier that uses MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER. At least, I'm pretty sure it will.
 
You can, however, set "Value" to a negative number, and the negative City Yield Modification is applied. So if you define a Positive Modifier building and a Negative Modifier building you can give and take away the effect.
Yeah, I can confirm this. I have a mod that decreases science output from scientific buildings based on the number of Campuses. I use negative modifiers and it works like a charm.
 
It should work for something other than directly attaching the modifier to the building via the BuildingModifiers table. For example, you could attach it to a tech/civic or religious belief which uses MODIFIER_PLAYER_CITIES_ATTACH_MODIFIER utilizing a RequirementSet containing a REQUIREMENT_CITY_HAS_BUILDING Requirement, and the ModifierArgument for that belief can be the Modifier that uses MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER. At least, I'm pretty sure it will.

]Only downside I know of so far is that with MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER I cannot seem to use a CITY_HAS_BUILDING requirement like the modifier that is used by the Chichen Itza for the Culture, Production, etc, yield adjustments to Jungle Tiles. So you couldn't use these by themselves for a dummy building, for example, and then add or take away the dummy building. You can, however, set "Value" to a negative number, and the negative City Yield Modification is applied. So if you define a Positive Modifier building and a Negative Modifier building you can give and take away the effect.

Just to be absolutely certain of this, I tested this as follows:

1) Made a Modifier using MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER. Increases Faith yield by 50%.
2) Used a RequirementSet containing only a single Requirement, a REQUIREMENT_CITY_HAS_BUILDING Requirement, specifying it requires a Sewer.
3) Attached the modifier to the City Center district on the DistrictModifiers table. So, the City Center gets +50% Faith with a Sewer in the city, in theory.
4) Loaded up Civ, added a Sewer to the city using Firetuner. Mouseover Faith, it shows +50% from Modifiers.
5) Removed the Sewer. Modifier's no longer there.

Seems to work doing it like that.
 
You applied the actual modifier to a District instead of a building?

That would still be do-able for most purposes. You should be able to just always add the modifier to the City Center District to simplify for a lot of effect purposes.

Could you toss up the code you used so I could comnpare to what I've been trying to do with attaching the modifier directly to a building, and so I can see what I need to do different, thanks.
 
Sure, though I deleted it afterward, I can quickly recreate it.

Note, this one uses the Monument:

Spoiler :
Code:
<Modifiers>
   <Row>
       <ModifierId>MAGIL_50_PERCENT_FAITH</ModifierId>
       <ModifierType>MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER</ModifierType>
       <SubjectRequirementSetId>MAGIL_CITY_HAS_MONUMENT_REQUIREMENTS</SubjectRequirementSetId>
   </Row>
</Modifiers>      

<ModifierArguments>
   <Row>
       <ModifierId>MAGIL_50_PERCENT_FAITH</ModifierId>
       <Name>Amount</Name>
       <Value>50</Value>
   </Row>
   <Row>
       <ModifierId>MAGIL_50_PERCENT_FAITH</ModifierId>
       <Name>YieldType</Name>
       <Value>YIELD_FAITH</Value>
   </Row>
</ModifierArguments>

<RequirementSets>
   <Row>
       <RequirementSetId>MAGIL_CITY_HAS_MONUMENT_REQUIREMENTS</RequirementSetId>
       <RequirementSetType>REQUIREMENTSET_TEST_ALL</RequirementSetType>
   </Row>
</RequirementSets>

<RequirementSetRequirements>
   <Row>
       <RequirementSetId>MAGIL_CITY_HAS_MONUMENT_REQUIREMENTS</RequirementSetId>
       <RequirementId>MAGIL_REQUIRES_CITY_HAS_MONUMENT</RequirementId>
   </Row>
</RequirementSetRequirements>

<Requirements>
   <Row>
       <RequirementId>MAGIL_REQUIRES_CITY_HAS_MONUMENT</RequirementId>
       <RequirementType>REQUIREMENT_CITY_HAS_BUILDING</RequirementType>
   </Row>
</Requirements>  

<RequirementArguments>
   <Row>
       <RequirementId>MAGIL_REQUIRES_CITY_HAS_MONUMENT</RequirementId>
       <Name>BuildingType</Name>
       <Value>BUILDING_MONUMENT</Value>
   </Row>
</RequirementArguments>

<DistrictModifiers>
   <Row>
       <DistrictType>DISTRICT_CITY_CENTER</DistrictType>
       <ModifierId>MAGIL_50_PERCENT_FAITH</ModifierId>
   </Row>
</DistrictModifiers>

I tested this and it seems to work.
 
What's wrong with attaching it to a Building I.e. Sewer?

Well, I do know if you attach it to the Building itself, the modifier won't actually remove itself if the building is somehow removed from the city (this is not usually possible during normal gameplay, but it could be using mods). With that said, I never tested both attaching it to the building AND adding a RequirementSet to check for itself, but LeeS reported an issue so I decided to try something else.
 
Last edited:
Is this some kind of bug from Firaxis, then? Modifier stays while owner is removed, strange. But good to know.

Normally this is not possible during gameplay (removing a building from a city) so it's likely Firaxis doesn't know about it. It's mainly a block if you were using a dummy building as part of a mod.
 
Yeah, that was the issue. Having the building dynamically added and removed via lua script. Although a Posi/Negi set of buildings with exactly opposite effects works. But this requires extra Buildings to implement. From a code-making perspective I don't know if it is more work one way or another for most people (defining the modifier(s) is needed anyway).
 
Works nicely to take away the effect without needing an anti-dummy. Which simplifies the logic in lua scripting, and helps keep the database cleaner of dummy buildings.
 
Last edited:
I had the same experience when adding the modifier to a building that was removed and then later added back in by lua code. In my case I attached the modifier to the CODE_OF_LAWS civic and have a requirementset that checks for the building existing in a city.

Code:
    <RequirementSets>
       <Row RequirementSetId="GOLDEN_AGE_MONUMENT_REQUIREMENTS" RequirementSetType="REQUIREMENTSET_TEST_ALL" />
   </RequirementSets>
   
   <RequirementSetRequirements>
       <Row RequirementSetId="GOLDEN_AGE_MONUMENT_REQUIREMENTS" RequirementId="REQUIRES_GOLDEN_AGE_MONUMENT" />
   </RequirementSetRequirements>
   
   <Requirements>
       <Row RequirementId="REQUIRES_GOLDEN_AGE_MONUMENT" RequirementType="REQUIREMENT_CITY_HAS_BUILDING" />
   </Requirements>
   
   <RequirementArguments>
       <Row RequirementId="REQUIRES_GOLDEN_AGE_MONUMENT" Name="BuildingType" Value="BUILDING_GOLDEN_AGE_MONUMENT" />
   </RequirementArguments>

   <Modifiers>
       <Row ModifierId="BASE_GOLDEN_AGE_CULTURE" ModifierType="MODIFIER_PLAYER_CITIES_ADJUST_CITY_YIELD_MODIFIER" SubjectRequirementSetId="GOLDEN_AGE_MONUMENT_REQUIREMENTS" />
       <Row ModifierId="BASE_GOLDEN_AGE_PRODUCTION" ModifierType="MODIFIER_PLAYER_CITIES_ADJUST_CITY_YIELD_MODIFIER" SubjectRequirementSetId="GOLDEN_AGE_MONUMENT_REQUIREMENTS" />
       <Row ModifierId="BASE_GOLDEN_AGE_SCIENCE" ModifierType="MODIFIER_PLAYER_CITIES_ADJUST_CITY_YIELD_MODIFIER" SubjectRequirementSetId="GOLDEN_AGE_MONUMENT_REQUIREMENTS" />
   </Modifiers>
   
   <ModifierArguments>
       <Row ModifierId="BASE_GOLDEN_AGE_CULTURE" Name="Amount" Value="25" />
       <Row ModifierId="BASE_GOLDEN_AGE_CULTURE" Name="YieldType" Value="YIELD_CULTURE" />
       <Row ModifierId="BASE_GOLDEN_AGE_PRODUCTION" Name="Amount" Value="25" />
       <Row ModifierId="BASE_GOLDEN_AGE_PRODUCTION" Name="YieldType" Value="YIELD_PRODUCTION" />
       <Row ModifierId="BASE_GOLDEN_AGE_SCIENCE" Name="Amount" Value="25" />
       <Row ModifierId="BASE_GOLDEN_AGE_SCIENCE" Name="YieldType" Value="YIELD_SCIENCE" />
   </ModifierArguments>

   <CivicModifiers>
       <!-- we add the base golden age modifiers to the civic to ensure we only get the one copy per player -->
       <Row CivicType="CIVIC_CODE_OF_LAWS" ModifierId="BASE_GOLDEN_AGE_CULTURE" />
       <Row CivicType="CIVIC_CODE_OF_LAWS" ModifierId="BASE_GOLDEN_AGE_PRODUCTION" />
       <Row CivicType="CIVIC_CODE_OF_LAWS" ModifierId="BASE_GOLDEN_AGE_SCIENCE" />
   </CivicModifiers>

I then have some lua code to create the GOLDEN_AGE_MONUMENT building in each city for a civilization as it enters a Golden Age, and then another function to remove the buildings from the cities. Works very nicely.
 
Back
Top Bottom