[BNW] I need help for making a trait.

GreatBayethe

Chieftain
Joined
Jul 12, 2017
Messages
24
I'd like to make a trait that +1 faith per building that yields faith. But I don't know how to check the number of them. Can anybody help me?
 
You can check it yourself, though we can utilise the effects of Neuschwanstein to obtain exactly what we want:
Code:
<Building_BuildingClassYieldChanges>
    <Row>
        <BuildingType>BUILDING_NEUSCHWANSTEIN</BuildingType>
        <BuildingClassType>BUILDINGCLASS_CASTLE</BuildingClassType>
        <YieldType>YIELD_GOLD</YieldType>
        <YieldChange>3</YieldChange>
    </Row>
</Building_BuildingClassYieldChanges>
As you can see, it provides +3 Gold to each castle. We can change the amount and yield pretty easily, though specifying which buildings should gain faith is the hard part, as only buildings that already produce faith should obtain the bonus.

Tables that always cause a building to provide a yield that we can consider would be:
- Building_YieldChanges
- Building_YieldModifiers
- Building_YieldChangesPerPop

Hence we want all buildings that provide a yield this way to have an element in the <Building_BuildingClassYieldChanges> in the form of:
Code:
<Building_BuildingClassYieldChanges>
    <Row>
        <BuildingType>BUILDING_GB_DUMMY_MORE_FAITH</BuildingType>
        <BuildingClassType>BUILDINGCLASS_WHATEVER</BuildingClassType>
        <YieldType>YIELD_FAITH</YieldType>
        <YieldChange>1</YieldChange>
    </Row>
</Building_BuildingClassYieldChanges>

We can hardcode all buildings manually, though that's a hassle to do (and Lord Whoward would not approve of that).
Hence, we can use SQL to generate these things for us!

Code:
INSERT INTO Building_BuildingClassYieldChanges
                (BuildingType,                  BuildingClassType, YieldType,       YieldChange)
SELECT DISTINCT 'BUILDING_GB_DUMMY_MORE_FAITH', BuildingClass,      'YIELD_FAITH',  1
FROM Building_YieldChanges
INNER JOIN Buildings ON (Building_YieldChanges.BuildingType == Buildings.Type)
WHERE GreatWorkCount >= 0 AND YieldType = "YIELD_FAITH" AND Yield > 0;
-- Dummy Buildings have their GreatWorkCount set to -1; we want to exclude those

Note that this includes (national) wonders, which you can remove by changing the last two lines of the previous code block to:
Code:
-- [snipped code]
INNER JOIN BuildingClasses ON (Buildings.BuildingClass == BuildingClasses.Type)
WHERE GreatWorkCount >= 0 AND YieldType = "YIELD_FAITH" AND Yield > 0 AND MaxGlobalInstances < 0 AND MaxPlayerInstances != 1 AND MaxTeamInstances != 1;
-- != 1 as buildings like the Recycling centre are not National Wonders but can still be constructed only a restricted number of times

We have however not considered unique buildings! The above code would give +1 Faith if there is any building (including other civ's unique buildings) that produces faith! We can easily fix this by changing the last two lines of the original code:
Code:
-- [snipped code]
INNER JOIN BuildingClasses ON (Buildings.BuildingClass == BuildingClasses.Type)
WHERE GreatWorkCount >= 0 AND YieldType = "YIELD_FAITH" AND Yield > 0 AND DefaultBuilding == Buildings.Type;
With this fix, it is for example no longer the case that Etheopia's Stele gives +1 Faith to the monument.

But what if we introduce a unique building that produces faith!?
Well, we can add it manually as follows (which is by far the easiest method as we know which buildings we introduce):
Code:
INSERT INTO Building_BuildingClassYieldChanges
        (BuildingType,                      BuildingClassType,              YieldType,      YieldChange)
VALUES  ('BUILDING_GB_DUMMY_MORE_FAITH',    'MY_OVERRIDE_BUILDINGCLASS',    'YIELD_FAITH',  1);

We then repeat the process for the two other tables.

Spoiler :

Though if you really wanted it in a single SQL-statement you could use the following code.
Example for CIVILIZATION_INDONESIA with their Candi providing Faith while the default Garden does not:
Code:
INSERT INTO Building_BuildingClassYieldChanges
                (BuildingType,                  BuildingClassType, YieldType,       YieldChange)
SELECT DISTINCT "BUILDING_GB_DUMMY_MORE_FAITH", BuildingClass,      "YIELD_FAITH",  1
FROM Building_YieldChanges
INNER JOIN Buildings ON (Building_YieldChanges.BuildingType == Buildings.Type)
INNER JOIN BuildingClasses ON (Buildings.BuildingClass == BuildingClasses.Type)
LEFT JOIN Civilization_BuildingClassOverrides ON (Civilization_BuildingClassOverrides.BuildingType == Buildings.Type)
WHERE GreatWorkCount >= 0 AND YieldType = "YIELD_FAITH" AND Yield > 0
    AND (CivilizationType == "CIVILIZATION_INDONESIA" OR
      (CivilizationType IS NULL AND DefaultBuilding == Buildings.Type
           AND Buildings.Type NOT IN
          (SELECT BuildingType FROM Civilization_BuildingClassOverrides WHERE CivilizationType == "CIVILIZATION_INDONESIA")
      ));
This will create the following entries in the database:
MLTN9el.png



Note that the above code does NOT work for buildings that (conditionally) produce faith through:
- Building_BuildingClassYieldChanges
- Belief_BuildingClassYieldChanges
- Policy_BuildingClassYieldChanges
- Policy_BuildingClassYieldModifiers
- Building_TechEnhancedYieldChanges
- Building_YieldChangesPerReligion

If you consider these important enough then you'll need to use more Lua (though that decision is up to you)

You will however need to use Lua anyway to grant a single copy of this building to your civ (while accounting for city captures).
The free building of Carthage's trait cannot be used in your case as that would grant your building in every city (which would stack the effect!).
 
Back
Top Bottom