Resources as prerequisites for Buildings

UncivilizedGuy

The Village Idiot
Joined
May 24, 2012
Messages
961
Location
Land of the Lost
I spent some time studying the modifier tables over the weekend and I can't seem to find a way to make resources prerequisites for the production of buildings. The conclusion I have come to is that there needs to be a modifier type to make this happen. Can anyone confirm this?
 
You could use REQUIREMENT_PLAYER_HAS_RESOURCE_OWNED to require that the resource is available in the empire, but I suspect that's not what you're asking.

You could attempt to use REQUIREMENT_CITY_HAS_BUILDING by granting a free internal building when a city plot has a specific resource, but that would be a bit convoluted and iffy as to whether it would work.
 
You could use REQUIREMENT_PLAYER_HAS_RESOURCE_OWNED to require that the resource is available in the empire, but I suspect that's not what you're asking.

You could attempt to use REQUIREMENT_CITY_HAS_BUILDING by granting a free internal building when a city plot has a specific resource, but that would be a bit convoluted and iffy as to whether it would work.
REQUIREMENT_PLAYER_HAS_RESOURCE_OWNED Is what I was trying to use. REQUIREMENT_CITY_HAS_BUILDING would mean I need the building as a requirement for something, I don't think I can use that.
From what I can see a requirement is essentially just the prerequisite but not the action. The modifier is the action. The modifiers appear to be hard coded. There would need to be one that allows the building to be constructed.
 
Last edited:
Oh...sorry. You can add in modifiers quite easily, they're certainly not hardcoded. The items in GameEffects.xml are hardcoded, but not the items in Modifiers.xml. You could probably use an OwnerRequirementSetId on a modifier to require that the player has a resource type before allowing a building to be built.

Take a look at the modifiers used in the Beliefs.xml which permit the religious buildings to be built and base your code off that.
 
A more elaborate workaround in case that doesn't work is to grant an internal building in every player city if they have a resource and then simply require that internal building as a prerequisite for your resource buildings. That's what I was getting at in my first post.

EDIT: here's the game effect: EFFECT_GRANT_BUILDING_IN_CITY
 
Oh...sorry. You can add in modifiers quite easily, they're certainly not hardcoded. The items in GameEffects.xml are hardcoded, but not the items in Modifiers.xml. You could probably use an OwnerRequirementSetId on a modifier to require that the player has a resource type before allowing a building to be built.

Take a look at the modifiers used in the Beliefs.xml which permit the religious buildings to be built and base your code off that.
Well not the modifiers themselves but the effects of the modifiers. But yeah I'll take a look at the beliefs, thanks
 
A more elaborate workaround in case that doesn't work is to grant an internal building in every player city if they have a resource and then simply require that internal building as a prerequisite for your resource buildings. That's what I was getting at in my first post.

EDIT: here's the game effect: EFFECT_GRANT_BUILDING_IN_CITY
EFFECT_GRANT_BUILDING_IN_CITY is what I also experimented with. That effect is used for great people. But this only works if I can make the building not buildable.
 
EFFECT_GRANT_BUILDING_IN_CITY is what I also experimented with. That effect is used for great people. But this only works if I can make the building not buildable.
Well...right. You would use that effect to grant a free internal only building in every single one of your cities if you have the specified resource. Then, you can set that internal-only building as a buildingprereq for the building you've been trying to add in all along. It's a long way around to requiring a resource for your building.
 
I get what you're saying. I may give this a try. My only problem is that I've been determined to keep the Workshop a prerequisite for my specialized buildings. Wonder if I can have two buildings as a prerequisite using the modifiers, internal building and the Workshop.
 
I've not tested them yet, but (at least some of) the GameEvents from civ5 seems to exist in the lua context, if it still works the same, GameEvents.PlayerCanConstruct may help you.
 
What if you made the Workshop a prerequisite building for your invisible resource building?
 
The Great Zimbabwe wonder uses a tag for its Cattle requirement and is technically a building going by the logic in the game's code. However, that may require the building to be built in a district adjacent to the resource. It may be worth a try either way? Have you messed with that?
 
What if you made the Workshop a prerequisite building for your invisible resource building?
That's how my mod is already set up. Having resources as a requirement would be ideal though. I'm trying to ensure that the AI only builds what it needs. I've been experimenting with the modifiers without success.

@Magil: the adjacency function only works with wonders. I tested this also.

So my work around utilizes technologies and Civics. I'm adding bonus techs that get 100% boosted by improved resources. These will be expensive, dead end techs that unlock bonus buildings.
 
Now that Gameplay scripts reload when you load a saved game I'm working on a system that will allow you to specify a dummy building that should be placed in a city when that city has ResourceX within its plots. This dummy building can then be used to unlock a 'real' building, or a unit, for example.

Clean up and efficiency of code should be done sometime in the next week or so.
 
Now that Gameplay scripts reload when you load a saved game I'm working on a system that will allow you to specify a dummy building that should be placed in a city when that city has ResourceX within its plots. This dummy building can then be used to unlock a 'real' building, or a unit, for example.

Clean up and efficiency of code should be done sometime in the next week or so.
Great! Looking forward to it.
 
There doesn't seem to be a way to directly adjust the validity of a building using modifiers. However, I'm pretty sure that you can test whether a city has a particular resource with something like this:

Code:
INSERT INTO Modifiers (ModifierId, ModifierType, SubjectRequirementSetId) VALUES
('MY_MODIFIER', 'MY_MODIFIER_TYPE', 'MY_REQUIREMENTSET');

INSERT INTO RequirementSets (RequirementSetId, RequirementSetType) VALUES
('MY_REQUIREMENTSET', 'REQUIREMENTSET_TEST_ALL');

INSERT INTO RequirementSetRequirements (RequirementSet, RequirementId) VALUES
('MY_REQUIREMENTSET', 'MY_REQUIREMENT');

INSERT INTO Requirements (RequirementId, RequirementType) VALUES
('MY_REQUIREMENT', 'REQUIREMENT_COLLECTION_ANY_MET'),

INSERT INTO RequirementArguments (RequirementId, Name, Value) VALUES
('MY_REQUIREMENT', 'CollectionType', 'COLLECTION_CITY_PLOT_YIELDS'),
('MY_REQUIREMENT', 'RequirementSetId', 'PLOT_HAS_RESOURCE_X');

Now you just need to define the Requirement Set 'PLOT_HAS_RESOURCE_X'. Note that the Collection Type of 'MY_MODIFIER_TYPE' must be cities.
 
Top Bottom