[R&F] Trying to make a civ gain a trade route for each unique resource they have.

Flethan

Chieftain
Joined
Jul 11, 2018
Messages
3
I wan t a Civilization's UA to let them gain one trade route if they have one of the following resources (each, for a max of 5):
  1. Fish
  2. Crabs
  3. Whales
  4. Turtles
  5. Sheep
I got it to give you one trade route after getting fish, but it doesn't work for crab or whales.
My code is here:
Code:
==========================================================================================================================
-- Civilization Traits
-------------------------------------
INSERT INTO    CivilizationTraits
        (CivilizationType,                TraitType                            )
VALUES    ('CIVILIZATION_FLETHAN_BASQUE',    'TRAIT_CIVILIZATION_FLETHAN_BASQUE_UA'    ); -- Assigns Trait to Civilization


-------------------------------------
-- Types
-------------------------------------
INSERT INTO Types
        (Type,                                            Kind)
VALUES    ('TRAIT_CIVILIZATION_FLETHAN_BASQUE_UA',                        'KIND_TRAIT'); -- Defines Trait as, well, a Trait.

-------------------------------------
-- Traits
-------------------------------------
INSERT INTO Traits
        (TraitType,                        Name,                                        Description)
VALUES    ('TRAIT_CIVILIZATION_FLETHAN_BASQUE_UA',    'LOC_TRAIT_CIVILIZATION_FLETHAN_BASQUE_UA_NAME',        'LOC_TRAIT_CIVILIZATION_FLETHAN_BASQUE_UA_DESCRIPTION'); -- Assigns Info to the Trait such as Name and Description

-------------------------------------
-- TraitModifiers
-------------------------------------
INSERT INTO TraitModifiers
        (TraitType,        ModifierId)
VALUES    ('TRAIT_CIVILIZATION_FLETHAN_BASQUE_UA',  'FLETHAN_TRADE_ROUTE_FISH_INCREASE');
VALUES    ('TRAIT_CIVILIZATION_FLETHAN_BASQUE_UA',  'FLETHAN_TRADE_ROUTE_CRABS_INCREASE');
VALUES    ('TRAIT_CIVILIZATION_FLETHAN_BASQUE_UA',  'FLETHAN_TRADE_ROUTE_WHALES_INCREASE');
 -- Assigns the Modifier to the Trait

------------------------------------------------------------------------
-- Modifiers
------------------------------------------------------------------------
INSERT INTO Modifiers
        (ModifierId,                                    ModifierType,                                    SubjectRequirementSetId)
VALUES    ('FLETHAN_TRADE_ROUTE_FISH_INCREASE',    'MODIFIER_PLAYER_ADJUST_TRADE_ROUTE_CAPACITY',  'FLETHAN_PLAYER_HAS_RESOURCES_FISH_SET'); -- Setups the Modifier to be a Modifier adjusting the Trade Route Capacity. Also adds a ReqSet to it.
VALUES    ('FLETHAN_TRADE_ROUTE_CRABS_INCREASE',    'MODIFIER_PLAYER_ADJUST_TRADE_ROUTE_CAPACITY',  'FLETHAN_PLAYER_HAS_RESOURCES_CRABS_SET');
VALUES    ('FLETHAN_TRADE_ROUTE_WHALES_INCREASE',    'MODIFIER_PLAYER_ADJUST_TRADE_ROUTE_CAPACITY',  'FLETHAN_PLAYER_HAS_RESOURCES_WHALES_SET');

------------------------------------------------------------------------
-- Modifier Arguments
------------------------------------------------------------------------
INSERT INTO ModifierArguments
        (ModifierId,                                    Name,            Value)
VALUES    ('FLETHAN_TRADE_ROUTE_FISH_INCREASE',        'Amount',        1); -- Sets the Modifier's Value to "1" making it so the Trade Route Capacity is adjusted by "1"/
VALUES    ('FLETHAN_TRADE_ROUTE_CRABS_INCREASE',        'Amount',        1);
VALUES    ('FLETHAN_TRADE_ROUTE_WHALES_INCREASE',        'Amount',        1);

-----------------------------------------------
-- RequirementSets
-----------------------------------------------
INSERT INTO RequirementSets
        (RequirementSetId,                      RequirementSetType)
VALUES  ('FLETHAN_PLAYER_HAS_RESOURCES_FISH_SET',    'REQUIREMENTSET_TEST_ANY'   ); -- Sets the Requirement Set to Test Any.
VALUES  ('FLETHAN_PLAYER_HAS_RESOURCES_CRABS_SET',    'REQUIREMENTSET_TEST_ANY'   );
VALUES  ('FLETHAN_PLAYER_HAS_RESOURCES_WHALES_SET',    'REQUIREMENTSET_TEST_ANY'   );

-----------------------------------------------
-- RequirementSetRequirements
-----------------------------------------------
INSERT INTO RequirementSetRequirements
        (RequirementSetId,                      RequirementId)
VALUES  ('FLETHAN_PLAYER_HAS_RESOURCES_FISH_SET', 'FLETHAN_REQUIRES_PLAYER_HAS_FISH'  ); -- Assigns the Requirement to the Requirement Set.
VALUES  ('FLETHAN_PLAYER_HAS_RESOURCES_CRABS_SET', 'FLETHAN_REQUIRES_PLAYER_HAS_CRABS'  );
VALUES  ('FLETHAN_PLAYER_HAS_RESOURCES_WHALES_SET', 'FLETHAN_REQUIRES_PLAYER_HAS_WHALES'  );

-----------------------------------------------------------------------
-- Requirements
-----------------------------------------------------------------------
INSERT INTO Requirements
        (RequirementId,                        RequirementType)
VALUES    ('FLETHAN_REQUIRES_PLAYER_HAS_FISH',            'REQUIREMENT_PLAYER_HAS_RESOURCE_OWNED'); -- Makes the Requirement the "Player_Has_District" type of Requirement.
VALUES    ('FLETHAN_REQUIRES_PLAYER_HAS_CRABS',            'REQUIREMENT_PLAYER_HAS_RESOURCE_OWNED');
VALUES    ('FLETHAN_REQUIRES_PLAYER_HAS_WHALES',            'REQUIREMENT_PLAYER_HAS_RESOURCE_OWNED');

-----------------------------------------------------------------------
-- Requirement Arguments
-----------------------------------------------------------------------
INSERT INTO RequirementArguments
        (RequirementId,                        Name,            Value)
VALUES    ('FLETHAN_REQUIRES_PLAYER_HAS_FISH',        'ResourceType',        'RESOURCE_FISH'); -- Makes the District type the game looks for the "Entertainment Complex"
VALUES    ('FLETHAN_REQUIRES_PLAYER_HAS_CRABS',        'ResourceType',        'RESOURCE_CRABS');
VALUES    ('FLETHAN_REQUIRES_PLAYER_HAS_WHALES',        'ResourceType',        'RESOURCE_WHALES');
 
Last edited:
I don't have an answer right away, but a few small things stand out.
  • In the ModifierArguments table, the Value field is a string. I don't know if you can get away with using 1 instead of '1', but I never take the chance.
  • The only place in the game the REQUIREMENT_PLAYER_HAS_RESOURCE_OWNED requirementtype is used in the game is the Hattusa city state ability that grants a free copy of each resource the player does not own. All of those examples key off of Strategic resources, not Bonus or Luxury resources, so I am not sure how reliable that requirementype is when applied to those resources. There's also some weirdness with how it treats resources you have imported from trade agreements (I think it ignores them, but I'm not 100% sure of this).
 
Multiple occurances of terminating ";" followed on the next line with VALUES keyword. my understanding of SQL (but I could be wrong) is this would cause fatal syntax errors.

Generally instead of this syntax:
Code:
INSERT INTO RequirementArguments
        (RequirementId,                        Name,            Value)
VALUES    ('FLETHAN_REQUIRES_PLAYER_HAS_FISH',        'ResourceType',        'RESOURCE_FISH'); -- Makes the District type the game looks for the "Entertainment Complex"
VALUES    ('FLETHAN_REQUIRES_PLAYER_HAS_CRABS',        'ResourceType',        'RESOURCE_CRABS');
VALUES    ('FLETHAN_REQUIRES_PLAYER_HAS_WHALES',        'ResourceType',        'RESOURCE_WHALES');
I would write as:
Code:
INSERT INTO RequirementArguments
        (RequirementId,                        Name,            Value)
VALUES		('FLETHAN_REQUIRES_PLAYER_HAS_FISH',        'ResourceType',        'RESOURCE_FISH'), -- Makes the District type the game looks for the "Entertainment Complex"
		('FLETHAN_REQUIRES_PLAYER_HAS_CRABS',        'ResourceType',        'RESOURCE_CRABS'),
		('FLETHAN_REQUIRES_PLAYER_HAS_WHALES',        'ResourceType',        'RESOURCE_WHALES');
But the original code may be a usage that is not normally used but does not cause fatal syntax exceptions.

I'm pretty "fluent" in SQL but I am not an expert by any means.
 
Multiple occurances of terminating ";" followed on the next line with VALUES keyword. my understanding of SQL (but I could be wrong) is this would cause fatal syntax errors.

Generally instead of this syntax:
Code:
INSERT INTO RequirementArguments
        (RequirementId,                        Name,            Value)
VALUES    ('FLETHAN_REQUIRES_PLAYER_HAS_FISH',        'ResourceType',        'RESOURCE_FISH'); -- Makes the District type the game looks for the "Entertainment Complex"
VALUES    ('FLETHAN_REQUIRES_PLAYER_HAS_CRABS',        'ResourceType',        'RESOURCE_CRABS');
VALUES    ('FLETHAN_REQUIRES_PLAYER_HAS_WHALES',        'ResourceType',        'RESOURCE_WHALES');
I would write as:
Code:
INSERT INTO RequirementArguments
        (RequirementId,                        Name,            Value)
VALUES        ('FLETHAN_REQUIRES_PLAYER_HAS_FISH',        'ResourceType',        'RESOURCE_FISH'), -- Makes the District type the game looks for the "Entertainment Complex"
        ('FLETHAN_REQUIRES_PLAYER_HAS_CRABS',        'ResourceType',        'RESOURCE_CRABS'),
        ('FLETHAN_REQUIRES_PLAYER_HAS_WHALES',        'ResourceType',        'RESOURCE_WHALES');
But the original code may be a usage that is not normally used but does not cause fatal syntax exceptions.

I'm pretty "fluent" in SQL but I am not an expert by any means.


I wondered about this too. I've never written SQL that way but I did put it into SQLite Studio without errors, so I suppose it's an option. One possible nice about it is since all the lines end in a semi colon you could comment out any given line without causing a choke error if you forgot to change a comma to a semi colon.
 
BTW just as general good coding practice, I always code objects that have foreign key requirements so that the foreign key is established prior to the object being loaded. Mainly this means coding in this order:

  • Requirements
  • RequirementArguments (requires Requirements)
  • RequirementSets
  • RequirementSetRequirements (requires Requirements and RequirementSets)
  • Modifiers (requires RequirementSets, if SubjectRequirementSetId is set)
  • ModifierArguments
  • TraitModifiers/BuildingModifiers/PolicyModifiers etc (requires Modifiers)

I think sometimes you can get away with doing it out of that order, but I don't like to, because it won't work if you paste the code directly into a SQL editor.
 
Top Bottom