[eINFO] Production rules

This is something completely new in FE that we couldn't do in E:wom. Production rules basically allow us to attach one kind of production to something else. That's how tech, production and gildar work in cities; population produces those things.

For more examples, see CityResourceEffectDefs.xml in the installation directory.

 

To set up a new production rule, there are three steps that need to be taken. Below, you will find the XML to produce 1 metal for every earth shard connected to, or in the city.

    <CityResourceEffectDef InternalName="EarthManaEffectOnMetal">
        <InputResource>EarthMana</InputResource>
        <OutputResource>Metal</OutputResource>
        <ResourceForMultiplierOnInput>MetalPerEarthMana</ResourceForMultiplierOnInput>
        <EffectType>Harvest</EffectType>
    </CityResourceEffectDef>

    <PlayerAbilityType InternalName="A_Additive_MetalPerEarthMana">
        <DisplayName>Base Research Per Earth Mana</DisplayName>
        <Description>How much Metal each unit of Earth mana produces.</Description>
        <Icon>Icon_Level.png</Icon>
        <DefaultValue>1</DefaultValue>
    </PlayerAbilityType>

    <ResourceType InternalName="MetalPerEarthMana">
        <DisplayName>Metal per Earth mana</DisplayName>
        <Description>Amount of Metal each unit of Earth Mana produces.</Description>
        <Type>MetalPerEarthMana</Type>
        <IconColor>0,0,0</IconColor>
        <!--<Icon>Gfx//Icons//dude_icon.png</Icon>-->
        <Icon>Gfx//Icons//Icon_Population.png</Icon>
        <HideInHiergamenon>1</HideInHiergamenon>
        <ModelColor>0,0,0</ModelColor>
        <Worth>0</Worth>
        <Global>0</Global>
        <Stored>0</Stored>
        <Rarity>0.0</Rarity>
        <Shared>0</Shared>
        <TradedByCaravans>0</TradedByCaravans>
        <ShownInGlobalDisplay>0</ShownInGlobalDisplay>
        <Medallions InternalName="Population_Res_Medallions">
            <All>Res_Ores_Plains.png</All>
        </Medallions>
    </ResourceType>

The steps are in no particular order.

The CityResourceEffectDef is what defines which productions are linked. As you can see in the example, we are linking EarthMana to Metal. This creates a "go-between" production of "MetalPerEarthMana".

The PlayerAbilityType allows us to globally modify this "MetalPerEarthMana". The default value is set to 1; 1 metal for each earth shard. If it was 2, there would be 2 metal for each earth shard. The internalname is crucial, it has to be A_Additive_*. If this wasn't a mod example, I wouldn't set it to default 1.

The ResourceType is also needed. Even though we are just creating a go-between of two different resources, we still need to create this kind of resourcetype. Note that the Internalname is not important here, rather the <Type> is what is important.

All put into action:

 

 

After this rule has been set up, we can also modify the values using different things. For example, a building that can only be built in a city with an earth shard, and produces 1 metal, might have this:

        <GameModifier>
            <ModType>Resource</ModType>
            <Attribute>MetalPerEarthMana</Attribute>
            <Value>1</Value>
            <PerTurn>1</PerTurn>
            <Provides>+1 metal per earth shard</Provides>
        </GameModifier>

or we might globally affect it like other similar things, for example in a faction bonus or a high-level earth spell (this gives 1 metal per earth shard faction-wide):

        <GameModifier>
            <ModType>Player</ModType>
            <Attribute>AbilityBonus</Attribute>
            <StrVal>A_Additive_MetalPerEarthMana</StrVal>
            <Value>1</Value>
        </GameModifier>

 

The game also has support for making one type of production lower another one by a percentage (like Unrest lowers production). See CityResourceEffectDefs.xml in the installation directory.

19,847 views 16 replies
Reply #1 Top

Great information! Thanks for sharing!

Reply #2 Top

That would open up many possibilities!

Reply #3 Top

Fantastic. Thanks for this. I just set up a GrowthperFood rule that increases city growth by 1 for every 50 excess food. Works beautifully. 

Reply #4 Top

Now see, that's just straight up a good idea. Although there might be balance issues, it certainly sounds logical.

Reply #5 Top

Would it be possible to make unrest increase with the number of cities controlled, and if not could something similar be done instead like global population?

I will try experimenting by making a custom global resource called cities.

Reply #6 Top

Funny this thread got bumped again, because I was just researching where the ResearchPerPopulation and ProductionPerPopulation default values were set in the xml (took me forever) but I re-stumbled on this along the way.  It really is a great mechanic that could lead to some interesting possibilities.

Reply #7 Top

Well I got the city resource working fine but I'm still trying to figure out how to use the global amount of cities instead of the amount produced locally.

Reply #8 Top

When dealing with global values, you must use A_Additive_Unrest. For example, the OnyxThrone improvement gives you -30% unrest in all your cities.

 

If you desire to add unrest according to cities, I would recommend you add a similar stat to the cityhubs.

    <ImprovementType InternalName="CityHub1">

       <GameModifier>
            <ModType>Player</ModType>
            <Attribute>AbilityBonus</Attribute>
            <StrVal>A_Additive_Unrest</StrVal>
            <Value>-30</Value>
            <Provides>-30% Unrest in all your cities</Provides>
        </GameModifier>

</ImprovementType>

This xml is enough to cause every level 1 city to give you -30% unrest. In E:wom, abilitybonuses in improvementtypes that upgraded were not handled correctly - gladly, this appears to have changed.

A word of caution - consider how the AI will react to adding unrest for every city. Will it understand it? Or will it just keep building?

Reply #9 Top

I'm assuming it doesn't know. That's why I am going to keep the penalty low and shift some other numbers around. It's just going to be a small penalty, say 3-5% for every city after the first.  I will probably also change gallows to a normal building and add some other stuff in order to make it possible to negate the penalty. It's just supposed to be a small penalty on multiple cities which you can spend gold and tech to negate.

Reply #10 Top

@ DSRaider to make an unrestpernumberofcities rule add this to all five levels of your city hub improvements:

        <GameModifier>
            <ModType>Resource</ModType>
            <Attribute>NumberofCities</Attribute>
            <Value>1</Value>
            <PerTurn>1</PerTurn>
        </GameModifier>

And this to a resourcetype file:

    <ResourceType InternalName="NumberofCities01">
        <DisplayName>Number of Cities</DisplayName>
        <Type>NumberofCities</Type>
        <IconColor>0,0,0</IconColor>
        <Icon>Gfx//Icons//Ledger_CityLevel_Icon.png</Icon>
        <HideInHiergamenon>1</HideInHiergamenon>
        <ShownInGlobalDisplay>0</ShownInGlobalDisplay>
        <Global>1</Global>
        <Stored>0</Stored>
        <Shared>0</Shared>
        <TradedByCaravans>0</TradedByCaravans>
        <RummagedPerTurn>0.01</RummagedPerTurn>
    </ResourceType>

I haven't tested it, but you should now have a hidden NumberofCities Resource that is always equal to your number of cities and you should be able to use it to create the sort of production rule you are looking for.

 EDITED - This doesn't work. It collects the right number of cities, but since the rule processes them inside a city, it uses the local number of cities, which is 1.

 

 

Reply #11 Top

I noticed a small limitation with these rules. If you have a rule that says resource B comes from only A, you cannot have a resource that says C comes from B. Even if you produce 10 A, and therefore 10 B, you will still produce 0 C.

Edit: This may not be true. However, for some reason, I can't make a rule from research->something new.

Reply #12 Top

Heavenfall (and other modders), are these production rules still hooked up? I found the CityResourceEffectDefs.xml, but I couldn't find the xml files where they were used (so a <PlayerAbilityType InternalName="A_Additive_*"> tag that calls those CityResourceEffectDefs).

Reply #13 Top

CorePlayerAbilities.xml. I have several of these rules still working in my mod so they are definitely hooked up.

Reply #14 Top

Heavenfall, after using your guide to check some stuff-

First of all, thanks! But you should make a pass to make this a bit more coherent for earth-->metal.

    <CityResourceEffectDef InternalName="EarthManaEffectOnMetal">
        <InputResource>EarthMana</InputResource>
        <OutputResource>Metal</OutputResource>
        <ResourceForMultiplierOnInput>MetalPerEarthMana</ResourceForMultiplierOnInput>
        <EffectType>Harvest</EffectType>
    </CityResourceEffectDef>

    <PlayerAbilityType InternalName="A_Additive_MetalPerEarthMana">
        <DisplayName>Base Research Per Earth Mana</DisplayName>
        <Description>How much Metal each unit of Earth mana produces.</Description>
        <Icon>Icon_Level.png</Icon>
        <DefaultValue>1</DefaultValue>
    </PlayerAbilityType>

    <ResourceType InternalName="MetalPerEarthMana">
        <DisplayName>Metal per Earth mana</DisplayName>
        <Description>Amount of Metal each unit of Earth Mana produces.</Description>
        <Type>MetalPerEarthMana</Type>
        <IconColor>0,0,0</IconColor>
        <!--<Icon>Gfx//Icons//dude_icon.png</Icon>-->
        <Icon>Gfx//Icons//Icon_Population.png</Icon>
        <HideInHiergamenon>1</HideInHiergamenon>
        <ModelColor>0,0,0</ModelColor>
        <Worth>0</Worth>
        <Global>0</Global>
        <Stored>0</Stored>
        <Rarity>0.0</Rarity>
        <Shared>0</Shared>
        <TradedByCaravans>0</TradedByCaravans>
        <ShownInGlobalDisplay>0</ShownInGlobalDisplay>
        <Medallions InternalName="Population_Res_Medallions">
            <All>Res_Ores_Plains.png</All>
        </Medallions>
    </ResourceType>

End of quote

While the code itself was good, this should allow any new comer to understand better what is going on, as you didn't change part of the descriptions.

Cheers mate!

Reply #15 Top

Thank you for this, Heavenfall, this helps out immensely!

Reply #16 Top

@Raledon updated it.