Requirements for counting collections

Infixo

Deity
Joined
Jan 9, 2016
Messages
4,012
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.
 
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. :(
 
@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).
 
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. ^^
 
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.
 
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:
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.
 
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.)
 
@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).
 
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.
 
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.
 
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?
 
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.
 
Top Bottom