[GS] Building that gives 1 additional amenity from each type of improved "food" luxury

Zarathustrani

Chieftain
Joined
Oct 28, 2017
Messages
3
Hey guys, I'm still pretty new to modding and have been racking my brain over this. I was hoping someone might be able to help out.

Basically, I want to have a building that gives extra food and production to improved "food resources"(CLASS_NEW_BUILDING_FOOD) and an amenity for each type of luxury " food resource" improved in the city (and only apply the extra amenity to that city). This is the code I currently have but doesn't seem to work for amenities, and my adjustment (see below the code) just makes it apply to ALL improved luxuries.

Any suggestions?
I'd be grateful for any advice and thanks in advance.


INSERT OR IGNORE INTO Tags
(Tag , Vocabulary)
VALUES
('CLASS_NEW_BUILDING_FOOD' , 'RESOURCE_CLASS');

INSERT OR IGNORE INTO TypeTags
(Type , Tag)
VALUES
('RESOURCE_WHEAT' , 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_CATTLE' , 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_RICE' , 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_SALT' , 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_DEER' , 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_BANANAS' , 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_CRABS' , 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_SHEEP' , 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_CITRUS' , 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_COCOA' , 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_COFFEE' , 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_SPICES' , 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_SUGAR' , 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_TEA' , 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_TRUFFLES', 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_WINE' , 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_OLIVES' , 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_HONEY' , 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_MAIZE' , 'CLASS_NEW_BUILDING_FOOD'),
('RESOURCE_FISH' , 'CLASS_NEW_BUILDING_FOOD');

INSERT OR IGNORE INTO Modifiers
(ModifierId , ModifierType , SubjectRequirementSetId)
VALUES
('NEW_BUILDING_TAG_FOOD' , 'MODIFIER_SINGLE_CITY_ATTACH_MODIFIER' , 'CITY_HAS_NEW_BUILDING' ),
('NEW_BUILDING_TAG_FOOD_MODIFIER' , 'MODIFIER_CITY_PLOT_YIELDS_ADJUST_PLOT_YIELD' , 'PLOT_HAS_TAG_FOOD_RESOURCE_REQUIREMENTS'),
('NEW_BUILDING_TAG_PROD' , 'MODIFIER_SINGLE_CITY_ATTACH_MODIFIER' , 'CITY_HAS_NEW_BUILDING' ),
('NEW_BUILDING_TAG_PROD_MODIFIER' , 'MODIFIER_CITY_PLOT_YIELDS_ADJUST_PLOT_YIELD' , 'PLOT_HAS_TAG_FOOD_RESOURCE_REQUIREMENTS'),
('NEW_BUILDING_TAG_AMEN_MODIFIER' , 'MODIFIER_SINGLE_CITY_ADJUST_EXTRA_AMENITY_FOR_LUXURY_DIVERSITY' , NULL);

INSERT OR IGNORE INTO ModifierArguments
(ModifierId , Name , Value)
VALUES
('NEW_BUILDING_TAG_FOOD' , 'ModifierId' , 'NEW_BUILDING_TAG_FOOD_MODIFIER' ),
('NEW_BUILDING_TAG_FOOD_MODIFIER' , 'YieldType' , 'YIELD_FOOD' ),
('NEW_BUILDING_TAG_FOOD_MODIFIER' , 'Amount' , '1' ),
('NEW_BUILDING_TAG_PROD' , 'ModifierId' , 'NEW_BUILDING_TAG_PROD_MODIFIER' ),
('NEW_BUILDING_TAG_PROD_MODIFIER' , 'YieldType' , 'YIELD_PRODUCTION' ),
('NEW_BUILDING_TAG_PROD_MODIFIER' , 'Amount' , '1' ),
('NEW_BUILDING_TAG_AMEN_MODIFIER' , 'Amount' , '1' );

INSERT OR IGNORE INTO Requirements -- Validation of requirements --
(RequirementId , RequirementType)
VALUES
('REQUIRES_PLOT_HAS_TAG_FOOD_RESOURCE' , 'CLASS_NEW_BUILDING_FOOD'),
('REQUIRES_IMPROVEMENT' , 'REQUIREMENT_REQUIREMENTSET_IS_MET'),
('REQUIRES_CITY_HAS_NEW_BUILDING' , 'REQUIREMENT_CITY_HAS_BUILDING');

INSERT OR IGNORE INTO RequirementArguments -- Sets specific requirements --
(RequirementId , Name , Value)
VALUES
('REQUIRES_PLOT_HAS_TAG_FOOD_RESOURCE' , 'Tag' , 'CLASS_FERTILITY_RITES_FOOD'),
('REQUIRES_IMPROVEMENT' , 'RequirementSetId' , 'PLOT_HAS_AN_IMPROVEMENT'),
('REQUIRES_CITY_HAS_NEW_BUILDING' , 'BuildingType' , 'BUILDING_NEW_BUILDING');

INSERT OR IGNORE INTO RequirementSets -- Indicate whether one has to be true or all --
(RequirementSetId , RequirementSetType)
VALUES
('PLOT_HAS_TAG_FOOD_RESOURCE_REQUIREMENTS' , 'REQUIREMENTSET_TEST_ALL'),
('PLOT_HAS_AN_IMPROVEMENT' , 'REQUIREMENTSET_TEST_ANY'),
('CITY_HAS_NEW_BUILDING' , 'REQUIREMENTSET_TEST_ALL');

INSERT OR IGNORE INTO RequirementSetRequirements -- Adds the specific requirements into a set --
(RequirementSetId , RequirementId)
VALUES
('PLOT_HAS_TAG_FOOD_RESOURCE_REQUIREMENTS' , 'REQUIRES_PLOT_HAS_TAG_FOOD_RESOURCE'),
('PLOT_HAS_TAG_FOOD_RESOURCE_REQUIREMENTS' , 'REQUIRES_IMPROVEMENT'),
('PLOT_HAS_AN_IMPROVEMENT' , 'REQUIRES_PLOT_HAS_FARM'),
('PLOT_HAS_AN_IMPROVEMENT' , 'REQUIRES_PLOT_HAS_FISHINGBOATS'),
('PLOT_HAS_AN_IMPROVEMENT' , 'REQUIRES_PLOT_HAS_PASTURE'),
('PLOT_HAS_AN_IMPROVEMENT' , 'REQUIRES_PLOT_HAS_PLANTATION'),
('PLOT_HAS_AN_IMPROVEMENT' , 'REQUIRES_PLOT_HAS_CAMP'),
('PLOT_HAS_AN_IMPROVEMENT' , 'REQUIRES_PLOT_HAS_MINE'),
('CITY_HAS_NEW_BUILDING' , 'REQUIRES_CITY_HAS_NEW_BUILDING');

INSERT OR IGNORE INTO BuildingModifiers
(BuildingType, ModifierId) VALUES
('BUILDING_NEW_BUILDING','NEW_BUILDING_TAG_FOOD'),
('BUILDING_NEW_BUILDING','NEW_BUILDING_TAG_PROD'),
('BUILDING_NEW_BUILDING','NEW_BUILDING_TAG_AMEN_MODIFIER');


INSERT OR IGNORE INTO Modifiers
(ModifierId , ModifierType , SubjectRequirementSetId)
VALUES
('NEW_BUILDING_TAG_FOOD' , 'MODIFIER_SINGLE_CITY_ATTACH_MODIFIER' , 'CITY_HAS_NEW_BUILDING' ),
('NEW_BUILDING_TAG_FOOD_MODIFIER' , 'MODIFIER_CITY_PLOT_YIELDS_ADJUST_PLOT_YIELD' , 'PLOT_HAS_TAG_FOOD_RESOURCE_REQUIREMENTS'),
('NEW_BUILDING_TAG_PROD' , 'MODIFIER_SINGLE_CITY_ATTACH_MODIFIER' , 'CITY_HAS_NEW_BUILDING' ),
('NEW_BUILDING_TAG_PROD_MODIFIER' , 'MODIFIER_CITY_PLOT_YIELDS_ADJUST_PLOT_YIELD' , 'PLOT_HAS_TAG_FOOD_RESOURCE_REQUIREMENTS'),
('NEW_BUILDING_TAG_AMEN_MODIFIER' , 'MODIFIER_SINGLE_CITY_ADJUST_EXTRA_AMENITY_FOR_LUXURY_DIVERSITY' , NULL);
 
You cannot invent RequirementTypes. so this is no go
Code:
INSERT OR IGNORE INTO Requirements -- Validation of requirements --
(RequirementId , RequirementType)
VALUES
('REQUIRES_PLOT_HAS_TAG_FOOD_RESOURCE' , 'CLASS_NEW_BUILDING_FOOD'),

Hint #1 -- You don't need to go through NEW_BUILDING_TAG_FOOD and then use that to attach a different modifier to the city. One Modifier will do
Code:
<GameData>
	<Requirements>
		<Replace>
			<RequirementId>REQUIRES_STONE_IN_PLOT_LRS</RequirementId>
			<RequirementType>REQUIREMENT_PLOT_RESOURCE_TYPE_MATCHES</RequirementType>
		</Replace>
	</Requirements>
	<RequirementArguments>
		<Replace>
			<RequirementId>REQUIRES_STONE_IN_PLOT_LRS</RequirementId>
			<Name>ResourceType</Name>
			<Value>RESOURCE_STONE</Value>
		</Replace>
	</RequirementArguments>
	<RequirementSets>
		<Replace>
			<RequirementSetType>REQUIREMENTSET_TEST_ALL</RequirementSetType>
			<RequirementSetId>RESOURCE_IS_STONE_LRS</RequirementSetId>
		</Replace>
	</RequirementSets>
	<RequirementSetRequirements>
		<Replace>
			<RequirementId>REQUIRES_STONE_IN_PLOT_LRS</RequirementId>
			<RequirementSetId>RESOURCE_IS_STONE_LRS</RequirementSetId>
		</Replace>
	</RequirementSetRequirements>
	<Modifiers>
		<Replace ModifierId="BUILDING_LRS_ADD_STONE_PRODUCTION_1" ModifierType="MODIFIER_CITY_PLOT_YIELDS_ADJUST_PLOT_YIELD" SubjectRequirementSetId="RESOURCE_IS_STONE_LRS" />
	</Modifiers>
	<ModifierArguments>
		<Replace ModifierId="BUILDING_LRS_ADD_STONE_PRODUCTION_1" Name="Amount" Value="1" />
		<Replace ModifierId="BUILDING_LRS_ADD_STONE_PRODUCTION_1" Name="YieldType" Value="YIELD_PRODUCTION" />
	</ModifierArguments>
	<BuildingModifiers>
		<!--Adjust City Yield-->
		<Row>
			<BuildingType>BUILDING_STONEWORKS_LRS</BuildingType>
			<ModifierId>BUILDING_LRS_ADD_STONE_PRODUCTION_1</ModifierId>
		</Row>
	</BuildingModifiers>
</GameData>
The presence of the building itself in the city acts as its own "CITY_HAS_BUILDING" so you don't need the circular logic of a Building giving a modifier which modifier then requires the city has that same building in order for the modifier to then enact itself.

Hint # 2 -- REQUIREMENTSET_TEST_ANY

Then add a Plot Has Resource Type Requirement for each of the resources you see as being "Food" resources. You add these requirements to the Set under table RequirementSetRequirements. There's no need to go through an intermediary of creating a new resource tag or resource class type since the amount of work required to do that will be the same as you will do to just directly add requirements to the SET.

Hint # 3 -- The RequirementSet should do the heavy lifting of when to apply the effect of the modifier

  1. Since you want both "food resource" and "improved plot" then you want one original RequirementSet attached to the Modifier. This RequirementSet should be TEST_ALL
  2. You add two requirements to this original RequirementSet -- one is that the plot must be improved, and the second is that a second RequirementSet is Met
  3. The Second RequirementSet uses TEST_ANY and has attached to it all the sub-level requirements for the plot resource type matching that you see as being "food" resources.
Also:
Code:
INSERT OR REPLACE INTO
And make sure everything new you are adding is actually unique to anything already within the database. See the example XML code where I have added my initials to every tag that is not a hard-coded tag within the game's systems such as REQUIREMENTSET_TEST_ALL or REQUIREMENT_PLOT_RESOURCE_TYPE_MATCHES
 
Last edited:
I don't see anything wrong with the Amenities code. But the EffectType does not appear to be one that you can adjust the effect based on a Plot-Related Requirement -- it is just applied the same way all the time ON or OFF so the only requirement types you could add to the modifier would be city-level or player-level requirements like a player has a specific tech or a city is coastal or something similar.

DynamicModifiers
Code:
ModifierType	|	CollectionType	|	EffectType
MODIFIER_SINGLE_CITY_ADJUST_EXTRA_AMENITY_FOR_LUXURY_DIVERSITY	|	COLLECTION_OWNER	|	EFFECT_ADJUST_CITY_EXTRA_AMENITY_FOR_LUXURY_DIVERSITY
There may some hints for you in the code for the Temple of Artemis since this adds extra amenity directly to nearby cities but the source of the extra amenity is actually the ImprovementTypes that are associated with the Temple of Artemis -- and in this case a City Has Building additional requirement would be appropriate because the source of the modifier would be the improvement rather than the city building. This is about as close as you can get to making the extra amenity plot-resource related in terms of adding extra amenity for having diversity of nearby resources.
 
Last edited:
I don't see anything wrong with the Amenities code. But the EffectType does not appear to be one that you can adjust the effect based on a Plot-Related Requirement -- it is just applied the same way all the time ON or OFF so the only requirement types you could add to the modifier would be city-level or player-level requirements like a player has a specific tech or a city is coastal or something similar.

DynamicModifiers
Code:
ModifierType    |    CollectionType    |    EffectType
MODIFIER_SINGLE_CITY_ADJUST_EXTRA_AMENITY_FOR_LUXURY_DIVERSITY    |    COLLECTION_OWNER    |    EFFECT_ADJUST_CITY_EXTRA_AMENITY_FOR_LUXURY_DIVERSITY
There may some hints for you in the code for the Temple of Artemis since this adds extra amenity directly to nearby cities but the source of the extra amenity is actually the ImprovementTypes that are associated with the Temple of Artemis -- and in this case a City Has Building additional requirement would be appropriate because the source of the modifier would be the improvement rather than the city building. This is about as close as you can get to making the extra amenity plot-resource related in terms of adding extra amenity for having diversity of nearby resources.

Ah, thanks man! These hints are really helpful for improving my code. I'm mostly learning from other mods, so I might be taking over some bad habits from that.

I had looked at Artemis before but couldn't figure out how to use that because it would stack indefinitely or only once instead of once per type, but I just figured out I can make several modifiers for each improved luxury "food" resource and then cap the stacks to 1.

So just to make sure I get this right... when I attach the modifier to the building, the building is the owner? So it would work if I limit the owner stacking to 1 for each modifier?
 
Top Bottom