Requirements help for civ trait

Ketto

Chieftain
Joined
Feb 2, 2021
Messages
3
EDIT: assume that Civtraits and TraitModifiers are already initialised

Hello everyone,

I'm trying to have a requirement on a civ trait for a custom civ of mine. I'm having trouble with the requirements. I've tested the code below and the problem only arises when I try to include any form of requirements

INSERT INTO Modifiers
(ModifierId, ModifierType, RunOnce, Permanent, SubjectRequirementSetId )
VALUES
('MODIFIER_AETERNUM_IMPERIUM_BUILDING_EXTRA_PRODUCTION', 'MODIFIER_PLAYER_CITIES_ADJUST_CITY_YIELD_MODIFIER', 0, 1, 'KETTONIA_GRANARY_AND_MONUMENT');

INSERT INTO ModifierArguments
(ModifierId, Name, Value )
VALUES
('MODIFIER_AETERNUM_IMPERIUM_BUILDING_EXTRA_PRODUCTION', 'YieldType', 'YIELD_PRODUCTION' ),
('MODIFIER_AETERNUM_IMPERIUM_BUILDING_EXTRA_PRODUCTION', 'Amount', '20' ),


INSERT INTO RequirementSets
(RequirementSetId, RequirementSetType )
VALUES
('KETTONIA_GRANARY_AND_MONUMENT', 'REQUIREMENT_TEST_ALL' );

INSERT INTO RequirementSetRequirements
(RequirementSetId, RequirementId )
VALUES
('KETTONIA_GRANARY_AND_MONUMENT', 'KETTONIA_GRANARY_AND_MONUMENT_REQUIREMENT');

INSERT INTO Requirements
(RequirementId, RequirementType )
VALUES
('KETTONIA_GRANARY_AND_MONUMENT_REQUIREMENT', 'REQUIREMENT_CITY_HAS_BUILDING' ),
('KETTONIA_GRANARY_AND_MONUMENT_REQUIREMENT', 'REQUIREMENT_CITY_HAS_BUILDING' );

INSERT INTO RequirementArguments
(RequirementId, Name, Value )
VALUES
('KETTONIA_GRANARY_AND_MONUMENT_REQUIREMENT', 'BuildingType', 'BUILDING_GRANARY' ),
('KETTONIA_GRANARY_AND_MONUMENT_REQUIREMENT', 'BuildingType', 'BUILDING_MONUMENT' );

What I want to happen is that player cities with both a granary and monument get +20% production. As I said earlier, the modifiers themselves work, its only when the requirements start getting involved that I cannot load. Below is the most recent log

[1660144.584] [Localization]: StartupErrorMessages.xml
[1660144.584] [Localization]: Input XML does not contain database entry tags. GameData, GameInfo or Database
[1660155.655] [Localization]: Validating Foreign Key Constraints...
[1660155.656] [Localization]: Passed Validation.
[1660155.671] [Configuration]: Validating Foreign Key Constraints...
[1660155.672] [Configuration]: Passed Validation.
[1660157.151] [FullTextSearch]: Initializing FullTextSearch
[1660158.808] [Gameplay]: Validating Foreign Key Constraints...
[1660158.819] [Gameplay]: Passed Validation.
[1660161.028] [Configuration] ERROR: FOREIGN KEY constraint failed
[1660161.029] [Configuration] ERROR: FOREIGN KEY constraint failed
[1660161.250] [Configuration]: Validating Foreign Key Constraints...
[1660161.250] [Configuration] ERROR: Invalid Reference on InputActionDefaultGestures.ActionId - "Toggle5movement" does not exist in InputActions
[1660161.250] [Configuration]: Failed Validation.
[1660161.644] [Configuration] ERROR: Failed to Backup Database.
[1660162.296] [HallofFame]: Database found. Checking versions...
[1660162.298] [HallofFame]: Database is up-to-date!
[1660176.850] [FullTextSearch]: FTS - Creating Context
[1660182.700] [Configuration] ERROR: FOREIGN KEY constraint failed
[1660182.700] [Configuration] ERROR: FOREIGN KEY constraint failed
[1660182.720] [Configuration]: Validating Foreign Key Constraints...
[1660182.720] [Configuration] ERROR: Invalid Reference on InputActionDefaultGestures.ActionId - "Toggle5movement" does not exist in InputActions
[1660182.720] [Configuration]: Failed Validation.
[1660183.101] [Configuration] ERROR: Failed to Backup Database.
[1660188.310] [Gameplay] ERROR: UNIQUE constraint failed: Requirements.RequirementId
[1660188.310] [Gameplay] ERROR: UNIQUE constraint failed: Requirements.RequirementId
[1660188.876] [Localization] ERROR: near "(": syntax error
[1660189.034] [Gameplay] ERROR: FOREIGN KEY constraint failed
[1660189.034] [Gameplay] ERROR: FOREIGN KEY constraint failed
[1660189.035] [Gameplay]: Validating Foreign Key Constraints...
[1660189.049] [Gameplay] ERROR: Invalid Reference on RequirementSetRequirements.RequirementId - "KETTONIA_GRANARY_AND_MONUMENT_REQUIREMENT" does not exist in Requirements
[1660189.057] [Gameplay]: Failed Validation.
[1660192.380] [Configuration] ERROR: FOREIGN KEY constraint failed
[1660192.380] [Configuration] ERROR: FOREIGN KEY constraint failed
[1660193.536] [Configuration]: Validating Foreign Key Constraints...
[1660193.536] [Configuration] ERROR: Invalid Reference on InputActionDefaultGestures.ActionId - "Toggle5movement" does not exist in InputActions
[1660193.536] [Configuration]: Failed Validation.
[1660194.007] [Configuration] ERROR: Failed to Backup Database.
[1660194.366] [FullTextSearch]: FTS - Creating Context

Note: I am using the cheatpanel mod to test things easily. However, it has been working well with the modifiers so I have deduced that the root problem are the requirements.

Any help would be appreciated. Thank you!
 
Code:
INSERT INTO Requirements
(RequirementId, RequirementType )
VALUES
('KETTONIA_GRANARY_AND_MONUMENT_REQUIREMENT', 'REQUIREMENT_CITY_HAS_BUILDING' ),
('KETTONIA_GRANARY_AND_MONUMENT_REQUIREMENT', 'REQUIREMENT_CITY_HAS_BUILDING' );
Causes this error message
Code:
[1660188.310] [Gameplay] ERROR: UNIQUE constraint failed: Requirements.RequirementId
[1660188.310] [Gameplay] ERROR: UNIQUE constraint failed: Requirements.RequirementId
As soon as the game attempts to read the lines specified, the error is generated and nothing else within the file is executed.

There can only ever be one row in table "Requirements" with the same designation for column "RequirementId".

You need to alter as follows:
Code:
INSERT INTO RequirementSetRequirements
(RequirementSetId, RequirementId )
VALUES
('KETTONIA_GRANARY_AND_MONUMENT', 'REQUIRES_KETTONIA_GRANARY'),
('KETTONIA_GRANARY_AND_MONUMENT', 'REQUIRES_KETTONIA_MONUMENT');

INSERT INTO Requirements
(RequirementId, RequirementType )
VALUES
('REQUIRES_KETTONIA_GRANARY', 'REQUIREMENT_CITY_HAS_BUILDING' ),
('REQUIRES_KETTONIA_MONUMENT', 'REQUIREMENT_CITY_HAS_BUILDING' );


INSERT INTO RequirementArguments
(RequirementId, Name, Value )
VALUES
('REQUIRES_KETTONIA_GRANARY', 'BuildingType', 'BUILDING_GRANARY' ),
('REQUIRES_KETTONIA_MONUMENT', 'BuildingType', 'BUILDING_MONUMENT' );
However you may still run into issues because the ModifierType MODIFIER_PLAYER_CITIES_ADJUST_CITY_YIELD_MODIFIER is a player-level modifier and it might not parse correctly that each individual city must have both of these two buildings in order to implement the effect. Often what is necessary is to use two modifiers:
  1. A player level modifier that uses MODIFIER_PLAYER_CITIES_ATTACH_MODIFIER. This modifier will specify in table ModifierArguments the modifier to be attached to individual cities mentioned in step 2.
  2. A city level modifier that uses MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER that does the actual work, has the RequirmentSetId attached to it, and specifies the ModifierArguments
Before going the two-step method fix the fatal code error and determine whether the game will properly parse the requirements as needing to apply individually in specific cities.

A Player-Level modifier that attaches a second modifier to all cities of that player:
Code:
INSERT INTO Modifiers
(ModifierId, ModifierType )
VALUES
('KARNAK_FLOODPLAIN_PRODUCTION', 'MODIFIER_PLAYER_CITIES_ATTACH_MODIFIER' );

INSERT INTO ModifierArguments
(ModifierId, Name, Value )
VALUES
('KARNAK_FLOODPLAIN_PRODUCTION', 'ModifierId', 'KARNAK_FLOODPLAIN_PRODUCTION_MODIFIER' );
The second city-level modifier
Code:
INSERT INTO Modifiers
(ModifierId, ModifierType, SubjectRequirementSetId )
VALUES
('KARNAK_FLOODPLAIN_PRODUCTION_MODIFIER', 'MODIFIER_CITY_PLOT_YIELDS_ADJUST_PLOT_YIELD', 'PLOT_HAS_FLOODPLAINS_REQUIREMENTS_LRS' );

INSERT INTO ModifierArguments
(ModifierId, Name, Value )
VALUES
('KARNAK_FLOODPLAIN_PRODUCTION_MODIFIER', 'YieldType', 'YIELD_PRODUCTION' )
('KARNAK_FLOODPLAIN_PRODUCTION_MODIFIER', 'Amount', '1' );

INSERT INTO RequirementSets
(RequirementSetId, RequirementSetType )
VALUES
('PLOT_HAS_FLOODPLAINS_REQUIREMENTS_LRS', 'REQUIREMENTSET_TEST_ANY' );

INSERT INTO RequirementSetRequirements
(RequirementSetId, RequirementId )
VALUES
('PLOT_HAS_FLOODPLAINS_REQUIREMENTS_LRS', 'REQUIRES_PLOT_HAS_DESERT_FLOODPLAINS_LRS' ),
('PLOT_HAS_FLOODPLAINS_REQUIREMENTS_LRS', 'REQUIRES_PLOT_HAS_GRASSLAND_FLOODPLAINS_LRS' ),
('PLOT_HAS_FLOODPLAINS_REQUIREMENTS_LRS', 'REQUIRES_PLOT_HAS_PLAINS_FLOODPLAINS_LRS' );

INSERT INTO Requirements
(RequirementType, RequirementId )
VALUES
('REQUIREMENT_PLOT_FEATURE_TYPE_MATCHES', 'REQUIRES_PLOT_HAS_DESERT_FLOODPLAINS_LRS' ),
('REQUIREMENT_PLOT_FEATURE_TYPE_MATCHES', 'REQUIRES_PLOT_HAS_GRASSLAND_FLOODPLAINS_LRS' ),
('REQUIREMENT_PLOT_FEATURE_TYPE_MATCHES', 'REQUIRES_PLOT_HAS_PLAINS_FLOODPLAINS_LRS' );

INSERT INTO RequirementArguments
(RequirementId, Name, Value )
VALUES
('REQUIRES_PLOT_HAS_DESERT_FLOODPLAINS_LRS', 'FeatureType', 'FEATURE_FLOODPLAINS' ),
('REQUIRES_PLOT_HAS_GRASSLAND_FLOODPLAINS_LRS', 'FeatureType', 'FEATURE_FLOODPLAINS_GRASSLAND' ),
('REQUIRES_PLOT_HAS_PLAINS_FLOODPLAINS_LRS', 'FeatureType', 'FEATURE_FLOODPLAINS_PLAINS' );
In this example I am using REQUIREMENTSET_TEST_ANY and I am adjusting city plot yields, but the basic logic of the 2-step method is the same.
 
Last edited:
Hey Lee S, thanks for replying

I modified my code with your advice, first fixing the error in the requirements sections and then adding a modifier which attaches modifiers to cities. below is the updated code

Code:
INSERT INTO    TraitModifiers  
        (TraitType, ModifierId        )
VALUES    ('TRAIT_CIVILIZATION_AETERNUM_IMPERIUM',        'MODIFIER_AETERNUM_IMPERIUM_GRANT_EXTRA_PRODUCTION'    ),
('TRAIT_CIVILIZATION_AETERNUM_IMPERIUM',        'MODIFIER_AETERNUM_IMPERIUM_BUILDING_EXTRA_PRODUCTION'    );

INSERT INTO    Modifiers
        (ModifierId,    ModifierType, RunOnce, Permanent,    SubjectRequirementSetId    )
VALUES    ('MODIFIER_AETERNUM_IMPERIUM_GRANT_EXTRA_PRODUCTION', 'MODIFIER_PLAYER_CITIES_ATTACH_MODIFIER',    0,        1,    null ),
        ('MODIFIER_AETERNUM_IMPERIUM_BUILDING_EXTRA_PRODUCTION', 'MODIFIER_SINGLE_CITY_ADJUST_CITY_YIELD_MODIFIER',        0, 1, 'KETTONIA_GRANARY_AND_MONUMENT');

INSERT INTO    ModifierArguments
        (ModifierId,    Name, Value)
VALUES    ('MODIFIER_AETERNUM_IMPERIUM_GRANT_EXTRA_PRODUCTION', 'ModifierId',        'MODIFIER_AETERNUM_IMPERIUM_BUILDING_EXTRA_PRODUCTION'    ),
        ('MODIFIER_AETERNUM_IMPERIUM_BUILDING_EXTRA_PRODUCTION', 'YieldType',        'YIELD_PRODUCTION'    ),
        ('MODIFIER_AETERNUM_IMPERIUM_BUILDING_EXTRA_PRODUCTION',    'Amount',    '20'                                );

The requirements code is the same except editing a bit of the text

Code:
INSERT INTO RequirementSets
        (RequirementSetId, RequirementSetType)
VALUES    ('KETTONIA_GRANARY_AND_MONUMENT',   'REQUIREMENT_TEST_ALL');

INSERT INTO RequirementSetRequirements
        (RequirementSetId,                        RequirementId)
VALUES    ('KETTONIA_GRANARY_AND_MONUMENT',        'KETTONIA_GRANARY_REQUIREMENT' ),
        ('KETTONIA_GRANARY_AND_MONUMENT',        'KETTONIA_MONUMENT_REQUIREMENT');

INSERT INTO Requirements
        (RequirementId,     RequirementType)
VALUES    ('KETTONIA_GRANARY_REQUIREMENT',                    'REQUIREMENT_CITY_HAS_BUILDING'    ),
        ('KETTONIA_MONUMENT_REQUIREMENT',                    'REQUIREMENT_CITY_HAS_BUILDING'    );

INSERT INTO RequirementArguments
        (RequirementId,     Name,    Value)
VALUES    ('KETTONIA_GRANARY_REQUIREMENT',             'BuildingType',    'BUILDING_GRANARY'    ),
        ('KETTONIA_GRANARY_REQUIREMENT',             'MustBeFunctioning',    1    ),

        ('KETTONIA_MONUMENT_REQUIREMENT',             'BuildingType',    'BUILDING_MONUMENT'    ),
        ('KETTONIA_MONUMENT_REQUIREMENT',             'MustBeFunctioning',        1    );

(I apologise for the poor setting out of code, I'm new to this forum so I'll find a way to edit it once I post)

This code allows me to load in as my civ leader however, even when I build a monument and granary, the modifier will not go into effect at all. I have also loaded an extra turn and nothing there.

thanks for helping out already though, just fixingthe source of the crashes has helped me out a lot.

EDIT: I believe the problem is in the requirements again. I commented out the requirement chunks of code and it still works

Ketto
 
Last edited:
Top Bottom