1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Requirements for counting collections

Discussion in 'Mod Creation Help' started by Infixo, Apr 17, 2017.

  1. Infixo

    Infixo Deity

    Joined:
    Jan 9, 2016
    Messages:
    3,436
    Gender:
    Male
    Location:
    Warsaw
    There are 3 very interesting Requirement Types:
    • REQUIREMENT_COLLECTION_COUNT_ATLEAST
    • REQUIREMENT_COLLECTION_COUNT_EQUALS
    • REQUIREMENT_COLLECTION_COUNT_GREATERTHAN
    They seem pretty straightforward and actually very powerful. The game uses them very rarely, basically to count COLLECTION_MAJOR_TEAMS:
    • VICTORY_MIN_MAJOR_TEAMS, CollectionType=COLLECTION_MAJOR_TEAMS, Count=2
    • REQUIREMENT_COLLECTION_COUNT_EQUALS, CollectionType=COLLECTION_MAJOR_TEAMS, Count=1
    Question 1. Has anyone managed to actually count any other collection using those requirements? If so, pls. post an example.

    I have tried using it to create a modifier that would react to the number of buildings in the city. There's a collection COLLECTION_CITY_BUILDINGS, so it would seem easy. Well, it's not working. I can attach a modifier to either a building or a district, and put requirement into an OwnerReq or SubjectReq, but no matter what option, I always get the same message: Warning: Failed to create Requirement <REQUIRES_BUILDINGS_MORE_THAN_2> to <District: 65536, Owner: 0, City: 65536> because <Invalid Definition>. There's always <Invalid Definition>.

    Here's my definition.
    Code:
    INSERT INTO RequirementSets (RequirementSetId, RequirementSetType)
    VALUES
        ('CITY_HAS_BUILDINGS_MORE_THAN_1', 'REQUIREMENTSET_TEST_ALL'),
        ('CITY_HAS_BUILDINGS_MORE_THAN_2', 'REQUIREMENTSET_TEST_ALL'),
        ('CITY_HAS_BUILDINGS_MORE_THAN_3', 'REQUIREMENTSET_TEST_ALL');
       
    INSERT INTO RequirementSetRequirements (RequirementSetId, RequirementId)
    VALUES
        ('CITY_HAS_BUILDINGS_MORE_THAN_1', 'REQUIRES_BUILDINGS_MORE_THAN_1'),
        ('CITY_HAS_BUILDINGS_MORE_THAN_2', 'REQUIRES_BUILDINGS_MORE_THAN_2'),
        ('CITY_HAS_BUILDINGS_MORE_THAN_3', 'REQUIRES_BUILDINGS_MORE_THAN_3');
    
    INSERT INTO Requirements (RequirementId, RequirementType)
    VALUES
        ('REQUIRES_BUILDINGS_MORE_THAN_1', 'REQUIREMENT_COLLECTION_COUNT_ATLEAST'),
        ('REQUIRES_BUILDINGS_MORE_THAN_2', 'REQUIREMENT_COLLECTION_COUNT_ATLEAST'),
        ('REQUIRES_BUILDINGS_MORE_THAN_3', 'REQUIREMENT_COLLECTION_COUNT_ATLEAST');
    
    INSERT INTO RequirementArguments (RequirementId, Name, Value)
    VALUES
        ('REQUIRES_BUILDINGS_MORE_THAN_1', 'CollectionType', 'COLLECTION_CITY_BUILDINGS'),
        ('REQUIRES_BUILDINGS_MORE_THAN_1', 'Count',    '2'),
        ('REQUIRES_BUILDINGS_MORE_THAN_2', 'CollectionType', 'COLLECTION_CITY_BUILDINGS'),
        ('REQUIRES_BUILDINGS_MORE_THAN_2', 'Count',    '3'),
        ('REQUIRES_BUILDINGS_MORE_THAN_3', 'CollectionType', 'COLLECTION_CITY_BUILDINGS'),
        ('REQUIRES_BUILDINGS_MORE_THAN_3', 'Count',    '4');
    
    Question 2. Do you find any errors in these definitions? Maybe I've missed something obvious.
     
  2. Xeribulos

    Xeribulos Chieftain

    Joined:
    Aug 31, 2010
    Messages:
    46
    Location:
    near Kokytos
    Usually, you have to include new requirements in the TYPES table. Just insert the requirement with it's ID and 'KIND_REQUIREMENT', the Hash will be generated automatically.
    However, the log should specifically state that TYPES is missing the required element, so this may not actually solve the problem. :(
     
  3. Infixo

    Infixo Deity

    Joined:
    Jan 9, 2016
    Messages:
    3,436
    Gender:
    Male
    Location:
    Warsaw
    @Xeribulos Good point, however, in this case, the RequirementType is 'REQUIREMENT_COLLECTION_COUNT_ATLEAST', already available in the game (thus registered in Types). Same as two others (equals, greaterthan). And afaik you don't put RequirementSetId nor RequirementId, so the database.log is clear (no errors, no warnings).
     
  4. Xeribulos

    Xeribulos Chieftain

    Joined:
    Aug 31, 2010
    Messages:
    46
    Location:
    near Kokytos
    Yeah, you are right. I falsely assumed you'd have to declare new requirementIDs in the types table, but it only needs requirementTypes, which are hard coded anyway. ^^
     
  5. Xeribulos

    Xeribulos Chieftain

    Joined:
    Aug 31, 2010
    Messages:
    46
    Location:
    near Kokytos
    It just occurred to me that it's odd Firaxis created the "city_has_x_specialty_districts" requirement rather than using "collection_count_atleast". This might be an indicator that collections somehow don't work as expected. Just a guess.
     
  6. Infixo

    Infixo Deity

    Joined:
    Jan 9, 2016
    Messages:
    3,436
    Gender:
    Male
    Location:
    Warsaw
  7. Infixo

    Infixo Deity

    Joined:
    Jan 9, 2016
    Messages:
    3,436
    Gender:
    Male
    Location:
    Warsaw
    Made some progress on the topic, whatsoever.
    1. I confirmed that the game checks the arguments and they are ok. I.e you need CollectionType and Count.
      • Whenever I put any other argument (e.g. Amount, CollectionName, Buildings, whatever), there's an error InvalidArgument. Only the two above produce InvalidDefinition.
      • I suppose the problem is within modifier/owner/subject/requirement combination. Need to find a valid one.
    2. I actually managed to use collection_city_districts. It was attached, and with 1 district status was not_met. When I placed Campus, the one with count=2 triggered and its effects were applied to the building (saw on Reports). Next turn the game CTDed.
    3. I also managed to attach one with requirement collection_player_units. Got no errors here, but the game CTDed next turn.
    Edit. I've found what what caused CTDs. It was NOT modifier related at all, I had some wrong Texts definitions.
     
    Last edited: Apr 22, 2017
  8. Xeribulos

    Xeribulos Chieftain

    Joined:
    Aug 31, 2010
    Messages:
    46
    Location:
    near Kokytos
    Interesting.
    Have you tried attaching the modifier to the city itself, as in 'MODIFIER_PLAYER_CITIES_ATTACH_MODIFIER' with a reference to the actual modifier?
    I apologize if the question is silly, but your original post said you attached it to a building or district.
     
  9. Xeribulos

    Xeribulos Chieftain

    Joined:
    Aug 31, 2010
    Messages:
    46
    Location:
    near Kokytos
    So I just made a modifier that increases the Capital's yield based on the total number of cities, using 'COLLECTION_COUNT_AT_LEAST' and 'COLLECTION_PLAYER_CITIES'. It works like a charm! :)

    The modifier is attached to the player (trait) and the requirement is in OwnerRequirementSetId. I assume the collection must match the modifier's owner, which is not the case with 'COLLECTION_CITY_BUILDINGS' and a districtmodifier.
    (However, 'COLLECTION_DISTRICT_BUILDINGS' should work.)
     
  10. Infixo

    Infixo Deity

    Joined:
    Jan 9, 2016
    Messages:
    3,436
    Gender:
    Male
    Location:
    Warsaw
    @Xeribulos Can you post the code for this COLLECTION_PLAYER_CITIES example?

    I will try attaching it to the city itself, however I always thought that no matter if I attach it to building or district, the owner will always be the city. At least in FireTuner the owner is always listed as (district,player,city).
     
  11. Xeribulos

    Xeribulos Chieftain

    Joined:
    Aug 31, 2010
    Messages:
    46
    Location:
    near Kokytos
    This is what I have now:
    INSERT INTO TraitModifiers VALUES
    ('TRAIT_CIVILIZATION_ALL_ROADS_TO_ROME', 'TRAIT_CAPITAL_EXTRA_DISTRICT'),
    ('TRAIT_CIVILIZATION_ALL_ROADS_TO_ROME', 'TRAIT_CAPITAL_EXTRA_DISTRICT_2'),
    ('TRAIT_CIVILIZATION_ALL_ROADS_TO_ROME', 'TRAIT_CAPITAL_EXTRA_DISTRICT_3');

    INSERT INTO Modifiers VALUES
    ('TRAIT_CAPITAL_EXTRA_DISTRICT', 'MODIFIER_PLAYER_CAPITAL_EXTRA_DISTRICTS', 0, 0, 'ATLEAST_4_CITIES_REQUIREMENTS', NULL),
    ('TRAIT_CAPITAL_EXTRA_DISTRICT_2', 'MODIFIER_PLAYER_CAPITAL_EXTRA_DISTRICTS', 0, 0, 'ATLEAST_8_CITIES_REQUIREMENTS', NULL),
    ('TRAIT_CAPITAL_EXTRA_DISTRICT_3', 'MODIFIER_PLAYER_CAPITAL_EXTRA_DISTRICTS', 0, 0, 'ATLEAST_12_CITIES_REQUIREMENTS', NULL);

    INSERT INTO ModifierArguments(ModifierId, Name, Value) VALUES
    ('TRAIT_CAPITAL_EXTRA_DISTRICT', 'Amount', 1),
    ('TRAIT_CAPITAL_EXTRA_DISTRICT_2', 'Amount', 1),
    ('TRAIT_CAPITAL_EXTRA_DISTRICT_3', 'Amount', 1);

    INSERT INTO Requirements(RequirementID, RequirementType) VALUES
    ('REQUIRES_ATLEAST_4_CITIES', 'REQUIREMENT_COLLECTION_COUNT_ATLEAST'),
    ('REQUIRES_ATLEAST_8_CITIES', 'REQUIREMENT_COLLECTION_COUNT_ATLEAST'),
    ('REQUIRES_ATLEAST_12_CITIES', 'REQUIREMENT_COLLECTION_COUNT_ATLEAST');

    INSERT INTO RequirementArguments (RequirementID, Name, Value) VALUES
    ('REQUIRES_ATLEAST_4_CITIES', 'CollectionType', 'COLLECTION_PLAYER_CITIES'),
    ('REQUIRES_ATLEAST_4_CITIES', 'Count', 4),
    ('REQUIRES_ATLEAST_8_CITIES', 'CollectionType', 'COLLECTION_PLAYER_CITIES'),
    ('REQUIRES_ATLEAST_8_CITIES', 'Count', 8),
    ('REQUIRES_ATLEAST_12_CITIES', 'CollectionType', 'COLLECTION_PLAYER_CITIES'),
    ('REQUIRES_ATLEAST_12_CITIES', 'Count', 12);

    INSERT INTO RequirementSets VALUES
    ('ATLEAST_4_CITIES_REQUIREMENTS', 'REQUIREMENTSET_TEST_ALL'),
    ('ATLEAST_8_CITIES_REQUIREMENTS', 'REQUIREMENTSET_TEST_ALL'),
    ('ATLEAST_12_CITIES_REQUIREMENTS', 'REQUIREMENTSET_TEST_ALL');

    INSERT INTO RequirementSetRequirements VALUES
    ('ATLEAST_4_CITIES_REQUIREMENTS', 'REQUIRES_ATLEAST_4_CITIES'),
    ('ATLEAST_8_CITIES_REQUIREMENTS', 'REQUIRES_ATLEAST_8_CITIES'),
    ('ATLEAST_12_CITIES_REQUIREMENTS', 'REQUIRES_ATLEAST_12_CITIES');

    It's coded exactly the same way as the example I talked about earlier, which was for testing purposes.
     
    Tiramisu likes this.
  12. Infixo

    Infixo Deity

    Joined:
    Jan 9, 2016
    Messages:
    3,436
    Gender:
    Male
    Location:
    Warsaw
    Ok, I give up on COLLECTION_CITY_BUILDINGS. I was clearly unlucky to choose it for tests. Doesn't work, no matter where the modifier is attached. I tested Building, District and City. Got City itself by attaching modifiers from Game. So, for sure City was an owner, even its name was displayed as owner in FT. Also, tested for SubjectReq and OwnerReq. Nope. Nada. Always 'InvalidDefinition'.

    However, I was successful in using COLLECTION_CITY_DISTRICTS. I used it for both OwnerReq and SubjectReq, for City as Owner and District as owner. If anybody would like to use it, pls. be aware that it counts also Wonders since Wonder is actually a building placed in DISTRICT_WONDER.
     
  13. isau

    isau Deity

    Joined:
    Jan 15, 2007
    Messages:
    3,052
    Great find guys. Thanks for sharing.
     
  14. Mettpawwz

    Mettpawwz Chieftain

    Joined:
    Feb 4, 2017
    Messages:
    73
    Gender:
    Male
    Hey guys, I'm trying to make a building with the following effect: "Your first 3 farms in this city grant X additional food."

    Normally, I'd just use 3 modifiers with REQUIREMENT_COLLECTION_COUNT_EQUALS requirements (for 1 farm, 2 farms, and 3 farms) if I wanted to count something, but I'm not sure if that's possible here since I'm not sure how I'd count farms.

    Can this be done with collection counting? I gonna assume there isn't a collection for specific improvements within a host city's 3 tile range, but can anyone else think of a possible workaround?
     
  15. Infixo

    Infixo Deity

    Joined:
    Jan 9, 2016
    Messages:
    3,436
    Gender:
    Male
    Location:
    Warsaw
    You must provide a collection type which basically matches something from COLLECTION_XXX, so you can count cities, districts, etc. There's no collection for improvements but there's collection_city_plot_yields which could be used to count tiles, I suppose. Then add a requirement that tile has improvement type that matches farm in your case. Just an idea, needs testing for sure.
     

Share This Page