1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  3. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  4. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  5. Dismiss Notice
  6. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

Policies grant perks & buildings

Discussion in 'CivBE - Code Snippets' started by Machiavelli24, Dec 14, 2014.

  1. Machiavelli24

    Machiavelli24 Mod creator

    Joined:
    May 9, 2012
    Messages:
    818
    What it does
    This mod contains code that defines four new XML tables. By adding entries to these tables mod makers can have Virtues (aka 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, Help>
    The building will be granted to every city. The Help string will be added to the tooltip for the Virtue.

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

    Policy_PGB_FreeBuildingClassWater: <PolicyType, BuildingClassType, Help>
    The building will be granted to cities founded on the water.

    Policy_PGB_FreeBuildingClassLand: <PolicyType, BuildingClassType, Help>
    The building will be granted to cities founded on land.

    Policy_PGB_FreeBuildingClassCoastal: <PolicyType, BuildingClassType, Help>
    The building will be granted to cities founded on coasts.

    Policy_PGB_FreeBuildingClassRiver: <PolicyType, BuildingClassType, Help>
    The building will be granted to cities founded on rivers.

    Policy_PGP_FreePerk: <PolicyType, FreePlayerPerk>
    The player will be given the perk. The perk's help text will be added to the tooltip for the Virtue.

    Compatibility
    There is a vanilla version and a Rising Tide version. The vanilla version does not support all the tables listed above.

    How to incorporate into your mod
    Copy the "Policies grant buildings" directory and "Policies grant Perks" directory to your mod. Have the XML files 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.

    InfoTooltipInclude.lua will need to be added via "InGameUIAddin" and have VFS set to true. It will replace the existing InfoTooltipInclude.lua. Without it the help text will not get added to the Virtue tooltip (but buildings and perks will still be granted).

    How to use
    Add entries to one of the four tables: Policy_PGB_FreeBuildingClass, Policy_PGB_FreeBuildingClassCapital, Policy_PGB_FreeBuildingClassCoastal and Policy_PGB_FreeBuildingClassRiver.

    These buildings should have: cost=-1, ConquestProbability=0

    Or add entries to: Policy_PGP_FreePerk

    The perk's help text will be shown in the tooltip UI for the Virtue.

    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 things happen the code fires off an event for the new city (or every city a player owns when they acquire a policy) asking all the tables to add to a list of buildings that will be given to the city. 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.

    Limitations
    Synergy bonus Virtues (the depth or breadth kickers) may not work if they are granting Buildings or Perks. If this is a problem I can enhance the detection logic to make them work correctly.

    How to add new tables
    By using the LUA in Policy_PGB_FreeBuildingClassCoastal.lua as a starting point you can (with minimal lua) easily add support for additional tables. 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.
     
  2. omniclast

    omniclast Chieftain

    Joined:
    Aug 27, 2014
    Messages:
    475
    Thanks for this! I've been trying to find a simple example of how to create new tables. This is super useful.

    One thing I've noticed though -- there are separate tooltips for policy modifier tables and for policies, and the policy modifier tooltips are defined in lua rather than xml. So if you modify a policy to implement one of these tables, the tooltip will be blank when you hover over the policy in the policy tree (even if you edit the Description column for the policy).

    I noticed this because I wanted to use the SpecialistsHalfUnhealth table, but there's no tooltip for it and I can't figure out how to make one.

    Could you add in a few lines that define a tooltip for the policybuildingclass tables? That would help me figure out how to do it.
     
  3. Machiavelli24

    Machiavelli24 Mod creator

    Joined:
    May 9, 2012
    Messages:
    818
    Modifying the way the policy tool tip is generated to have it include information describing the new building tables is something I am working on. I will release an update to this snippet when it is complete.
     
  4. omniclast

    omniclast Chieftain

    Joined:
    Aug 27, 2014
    Messages:
    475
    Awesome, I appreciate it!
     
  5. Machiavelli24

    Machiavelli24 Mod creator

    Joined:
    May 9, 2012
    Messages:
    818
    I've released an updated to this snippet. It includes support for tooltips and a Policies grant Player perks table.
     
  6. Machiavelli24

    Machiavelli24 Mod creator

    Joined:
    May 9, 2012
    Messages:
    818
    I've released a Rising Tide compatible version of the snippet. It also supports new tables! Happy modding.
     

Share This Page