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

UnitPerks grant Promotions

Discussion in 'CivBE - Code Snippets' started by Machiavelli24, May 9, 2015.

  1. Machiavelli24

    Machiavelli24 Mod creator

    Joined:
    May 9, 2012
    Messages:
    818
    Compatibility
    This code is compatible with vanilla Beyond Earth. It is not compatible with Rising Tide. I am working on an update.

    CivFanatics Download
    Workshop Download

    What it does
    This mod contains code that defines a new XML table. By adding entries to this table mod makers can have UnitUpgrades grant Promotions. This works identically for UnitPerks that are inherently part of unit upgrades and UnitPerks that are choices. If an end-user is playing with multiple mods that use this snippet it will work properly.

    UnitPerks_UGP_FreePromotions: <PerkType, PromotionType>
    Any unit with the PerkType will automatically be given the PromotionType.

    How to incorporate into your mod
    Copy the "UnitPerks Grant Promotions", "UnitCreatedEvent" and "UnitUpgradedEvent" directory and all its contents to your mod. "UnitPerks Grant Promotions" will only work if you are also using the "UnitCreatedEvent" and "UnitUpgradedEvent" snippets. 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.

    In the UI folder UnitUpgradePopup.lua will need to be added via "InGameUIAddin" and have VFS set to true. It will replace the existing UnitUpgradePopup.lua. Without it the help text from the promotions will not show up when a player is looking at perks in the unit upgrade UI (but the promotions will still be granted).

    How to use
    Add entries to one of the UnitPerks_UGP_FreePromotions table.

    How it works
    A collection of functions detect when a player creates a new unit or a unit is upgraded. When one of these happen it looks for all UnitPerks the unit has and gives the unit any promotions that match those UnitPerks in the UnitPerks_UGP_FreePromotions table. The algorithm does not poll every turn and units will be given the promotion right away, not next turn.

    Limitations
    If a UnitUpgrade does not change the art style of a unit (currently all in game UnitUpgrades do change the art of a unit) this code may not grant units that existed during the upgrade any promotions associated.
     

Share This Page