Attaching Unit-granting Modifier to a Building

FungeonKeeper

Chieftain
Joined
Apr 17, 2021
Messages
7
I cannot figure out what the problem is.
What I'm trying to do is to make the barracks building give an anti-cavalry unit when built. So far, it hasn't worked. As in, I build a barracks and nothing happens.
Here's the code:
Code:
INSERT INTO BuildingModifiers    (BuildingType,    ModifierId)
VALUES    ('BUILDING_BARRACKS',    'BK_BARRACKS_CREATE_AC');
INSERT INTO Modifiers    (ModifierId,    ModifierType,    RunOnce,    Permanent)
VALUES    ('BK_BARRACKS_CREATE_AC',    'MODIFIER_PLAYER_CITIES_GRANT_UNIT_BY_CLASS',    TRUE,    TRUE);
INSERT INTO ModifierArguments    (ModifierId,    Name,    Value)
VALUES    ('BK_BARRACKS_CREATE_AC',    'UnitPromotionClassType',    'PROMOTION_CLASS_ANTI_CAVALRY'),
        ('BK_BARRACKS_CREATE_AC',    'Amount',    '1');
Thought process:
Spoiler :
This code is mostly based on the free spy from the intelligence agency (Expansion1_Buildings.xml), but using the ModifierType from Victoria's free melee unit (Leaders.xml) with the Statue of Zeus's unit creation also as a reference (Byzantium_Gaul_Buildings.xml).
I don't know how RunOnce and Permanent work, so it's possible that's the problem, but I'm not sure what they should be set to. The GOV_ADD_SPY_UNIT only specifies that RunOnce is true, and TRAIT_FREE_MELEE_UNIT_NON_HOME_CONTINENT sets Permanent to true, but setting both to true in this case hasn't worked. I've tried a few combinations without success.
 
SQL does not make use of true or false, capitalized or otherwise. Boolean true in SQL is stated with 1 -- boolean false is stated with 0

MODIFIER_PLAYER_CITIES_GRANT_UNIT_BY_CLASS is not going to work correctly for completion of a specific building in a specific city. The reason this ModifierType works for Victoria is because of the entire way the modifier and its requirements are specified
Code:
		<Row>
			<ModifierId>TRAIT_FREE_MELEE_UNIT_NON_HOME_CONTINENT</ModifierId>
			<ModifierType>MODIFIER_PLAYER_CITIES_GRANT_UNIT_BY_CLASS</ModifierType>
			<Permanent>true</Permanent>
			<SubjectRequirementSetId>CITY_FOUNDED_ON_NON_HOME_CONTINENT_REQUIREMENTS</SubjectRequirementSetId>
		</Row>
You need a modifier type that is single city.

Statue of Zeus uses MODIFIER_SINGLE_CITY_GRANT_UNIT_IN_CITY for all three of the types of units given, and then states the amount of each in table ModifierArguments.

A quick inspection of the database turns up these three types of Modifiers:
Code:
ModifierType		CollectionType		EffectType
MODIFIER_SINGLE_CITY_GRANT_UNIT_BY_CLASS_IN_NEAREST_CITY	COLLECTION_UNIT_NEAREST_OWNER_CITY	EFFECT_GRANT_UNIT_BY_CLASS
MODIFIER_SINGLE_CITY_GRANT_UNIT_IN_CITY		COLLECTION_OWNER	EFFECT_GRANT_UNIT_IN_CITY
MODIFIER_SINGLE_CITY_GRANT_UNIT_IN_NEAREST_CITY		COLLECTION_UNIT_NEAREST_OWNER_CITY	EFFECT_GRANT_UNIT_IN_CITY
The first would be close to what you are after, but only close. If the encampment is actually closer to some other city than the one that owns the encampment (and the newly-created barracks) the unit might very well be granted in that other city. This is further complicated by the fact that the "CollectionType" is referring to a unit that triggers the effect of the modifier (COLLECTION_UNIT_NEAREST_OWNER_CITY). The first and last of the three ModifierTypes (the ones that have COLLECTION_UNIT_NEAREST_OWNER_CITY) are triggered either by a unit stepping on a goody hut or from a Great Person being activated -- it is these two units which are being used to judge "nearest city".
 
Last edited:
Back
Top Bottom