Sid Meier's Civilization V

Sid Meier's Civilization V

Not enough ratings
Policies Grant Buildings [snippet for mod makers]
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
5.070 KB
May 24, 2014 @ 4:27pm
Sep 1, 2014 @ 8:02pm
9 Change Notes ( view )

Subscribe to download
Policies Grant Buildings [snippet for mod makers]

In 1 collection by Machiavelli
Machiavelli's snippets for mod makers
6 items
Description
For mod makers.

What it does
This mod contains code that defines three new XML tables. By adding entries to these tables mod makers can have Social Policies grant buildings in cities. If an end-user is playing with multiple mods that use this snippet it will work properly.

Policy_PGB_FreeBuildingClass: <PolicyType, BuildingClass>
The building will be granted to every city.

Policy_PGB_FreeBuildingClassCapital: <PolicyType, BuildingClass>
The building will be granted to only the capital. If the capital moves (due to conquest) the building automatically moves.

Policy_PGB_FreeBuildingClassCityStates: <PolicyType, BuildingClassType>
The building will be granted to captured city-states.

Compatibility
This code is compatible with Vanillia, Gods & Kings, and Brave New World.

This code is identical to what is used in "Reform and Rule".

How to incorporate into your mod
Copy the "Policies grant buildings" directory and all its contents to your mod. Have the XML file update the database (via the Action tab) and set the LUA file as an "InGameUIAddin" (via the Content tab).

Make sure the XML files from this snippet that create the table update the database before any files attempt to add entries into the tables for this snippet.

How to use
Add entries to one of the three tables: Policy_FreeBuildingClass, Policy_FreeBuildingClassCapital and Policy_FreeBuildingClassCityState.

These buildings should have cost=-1, nukeImmune=true and NeverCapture=true.

How it works
A collection of functions detect when a player adopts a policy, founds a city or conquers a city. When one of those events happen the code creates a list of buildings it needs to add for each city and fires off an event. Each table listens for that event and adds its own buildings to the list. Once the list is complete the code adds the buildings to the city or cities. If policies become blocked (usually due to a player switching ideology) the buildings associated with those policies are removed from the player's cities at the start of their next turn.

How to add new tables
By using the LUA in Policy_PGB_FreeBuildingClassCityState.lua as a starting point you can (with minimal lua) easily add support for additional tables (such as, Policy_PGB_FreeBuildingClassCoastal). Tables you add in this way will work correctly even if an end-user is playing with another mod that uses this snippet but does not include your table. If you have any questions on how to add support for another table contact me and I'll help you out.

CivFanatics Download[forums.civfanatics.com]
18 Comments
Lunar Magister Oct 22, 2019 @ 4:21pm 
Nevermind. I got it to work. It was either I had to copy the name/description, or my method of testing (Using the ingame-editor) that was faulty. When I adopted the policy without ingame editor it worked.
Lunar Magister Oct 21, 2019 @ 9:23pm 
I have 4 lua files from your mod. Policies grant Buildings.lua, Policy_PGB_FreeBuildingClass_Table.lua, Policy_PGB_FreeBuildingClassCapital_Table.lua, and Policy_PGB_FreeBuildingClassCityState_Table.lua. I have set them all as InGameUIAddin in the content tab. All four are in a folder I called LUA.

I believe the problem must be how I arranged the folders? I don't have to import them into vhs do I? When I open your mod I see a folder called "Shared." Am I just supposed to import that into my mod?
Lunar Magister Oct 21, 2019 @ 9:23pm 
Hello, Machiavelli. I am having difficulty incorporating this into my mod.

I have made sure to have the xml file, (PGB_TABLES.xml) update the database, and I also made it first. My mod just has 2 folders, xml and lua. PGB_TABLES.xml I have put in the xml folder.
I also put 2 GoldMerchant_Example.xml in this folder and had it update the database. The building shows up in game when spawning it with ingame editor, and I confirm that its effect works, however adopting entrepreneurship does not spawn it.

Machiavelli  [author] Aug 27, 2019 @ 7:33am 
Yes
SuperJedi224 Aug 26, 2019 @ 5:48pm 
Does the Policy_PGB_FreeBuildingClass tag apply to cities that are founded after selecting the policy?
VICTOR Oct 29, 2017 @ 3:21pm 
Thank you, BTW a friendly reminder, buidings granted by policies have ignored commands like prerequisite buildings (Building_ClassesNeededInCity), which makes me having a PGB in every city even w/o the prerequisite building, hope you may fix it if you have spare time ;)
Machiavelli  [author] Oct 27, 2017 @ 8:54pm 
The 3 examples are inserted into the table by a file not in the "Policies grant buildings" directory. Delete that file, or leave it behind when you copy the "Policies grant buildings" directory into your mod to disable them.
VICTOR Oct 27, 2017 @ 12:29pm 
How can I deactivate the default three examples?
Civitar Jun 5, 2014 @ 12:31am 
OK. Thanks for the reply!
Machiavelli  [author] Jun 4, 2014 @ 1:18pm 
Ender, if you want a building or unit that can not be constructed until a player has a specific policy you can use the "CanConstruct" and "CanTrain" lua functions. Just add a player.HasPolicy check if the building/unit is of the restricted class.