1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

[Lua] Having trouble with code making buildings exclusive from one another.

Discussion in 'CivBE - Modding Help & Mod Creation' started by Galgus, Oct 11, 2017.

  1. Galgus

    Galgus Emperor

    Aug 22, 2012
    Edit: The issue was a conflict with a mod I did not think would be problematic.

    I've been using code that Valessa generously put together in this thread which worked at a time if memory serves, but seems to be conflicting with something now.

    That or I messed something up, which could be quite likely.

    I haven't seen any kind of error about the changes in logs, so I don't know what to look at to troubleshoot.

    If you have any ideas on what the problem may be, I'd be grateful to hear them.

    Is it problematic that there are two SQL files updating the database?

    This is is the ModInfo folder.

    <?xml version="1.0" encoding="utf-8"?>
    <Mod id="6ea9bfd1-9019-4708-8302-6f77a98afec0" version="1">
        <Name>Distinction - Affinity Buildings Overhaul</Name>
        <Teaser>Overhauls the Afffinity building system to assign each Core and Hybrid Affinity a set of buildings that are exclusive to those</Teaser>
        <Description>Overhauls the Afffinity building system to assign each Core and Hybrid Affinity a set of buildings that are exclusive to those of other affinities, requiring only affinity level to unlock.</Description>
        <SpecialThanks>Ryika, lilgamefreek</SpecialThanks>
      <Dependencies />
      <References />
      <Blocks />
        <File md5="1E6478DB43B39D62D2FA7E08B1785920" import="0">Affinity Buildings/Harmony Build.xml</File>
        <File md5="62D49A915DEDFC15622E04FDD325573B" import="0">Affinity Buildings/HP Build.xml</File>
        <File md5="4F4FAD1FDF2721952E0675FBC4CF0292" import="0">Affinity Buildings/PS Build.xml</File>
        <File md5="ECB4C1AFB9707B5E680E64BA4A13F09C" import="0">Affinity Buildings/Purity Build.xml</File>
        <File md5="9D9BB0FAF9F9BD0E9DAFF847A3C1B884" import="0">Affinity Buildings/SH Build.xml</File>
        <File md5="EF1456E405098D5010661F69C3F49F12" import="0">Affinity Buildings/Supremacy Build.xml</File>
        <File md5="BD7071AE8107AC4430D056AC772F3BE0" import="0">Exclusivity Code/Lua/AffinityAffiliationTestScript.lua</File>
        <File md5="15F9FFE5CF3091839BC57020AFE96B30" import="0">Exclusivity Code/SQL/UpdateBuildingTable.sql</File>
        <File md5="A2D220B934880F68F5C6D7129CF80309" import="0">Modular Building Quests Resource/BuildingChoiceTemplateQuest.lua</File>
        <File md5="456CA3F098A6E5FACC45B594997402B3" import="0">Modular Building Quests Resource/BuildingQuestTable.sql</File>
          <UpdateDatabase>Modular Building Quests Resource/BuildingQuestTable.sql</UpdateDatabase>
          <UpdateDatabase>Exclusivity Code/SQL/UpdateBuildingTable.sql</UpdateDatabase>
          <UpdateDatabase>Affinity Buildings/Harmony Build.xml</UpdateDatabase>
          <UpdateDatabase>Affinity Buildings/HP Build.xml</UpdateDatabase>
          <UpdateDatabase>Affinity Buildings/PS Build.xml</UpdateDatabase>
          <UpdateDatabase>Affinity Buildings/Purity Build.xml</UpdateDatabase>
          <UpdateDatabase>Affinity Buildings/SH Build.xml</UpdateDatabase>
          <UpdateDatabase>Affinity Buildings/Supremacy Build.xml</UpdateDatabase>
        <EntryPoint type="InGameUIAddin" file="Exclusivity Code/Lua/AffinityAffiliationTestScript.lua">
          <Name>Exclusivity Code/Lua/AffinityAffiliationTestScript</Name>
        <EntryPoint type="Quest" file="Modular Building Quests Resource/BuildingChoiceTemplateQuest.lua">
          <Name>Modular Building Quests resource/BuildingChoiceTemplateQuest</Name>

    This is the UpdateBuildingTable.sql file creating a new table for buildings.

    ALTER TABLE Buildings ADD AffinityAffiliation text; 

    This is the file that checks said tables.

    GameEvents.CityCanConstruct.Add(function(iPlayer, iCity, iBuildingType)
        -- Need to convert iCity to a usable format
        local pCity = Players[iPlayer]:GetCityByID(iCity)
        -- If the Building has an Entry to the AffinityAffiliation Table then...
        if GameInfo.Buildings[iBuildingType].AffinityAffiliation ~= nil then
            -- ...go through ALL buildings that exist...
            for pBuilding in GameInfo.Buildings() do
                -- ...and check if it exists in the city.
                if pCity:IsHasBuilding(pBuilding.ID) then
                    -- If it exists, then check if it has an AffinityAffiliation entry.
                    if GameInfo.Buildings[pBuilding.ID].AffinityAffiliation ~= nil then
                        -- If it has one, then check if it's different from the building that is being checked!
                        if GameInfo.Buildings[iBuildingType].AffinityAffiliation ~= GameInfo.Buildings[pBuilding.ID].AffinityAffiliation then
                            -- If it is different finally return false!
                            return false
        -- Return true if the code above has not returned false (aka if
        -- the building has no AffinityAffiliation-entry or no building
        -- of a different group exists).
        return true

    And this is an example of the relevant sections of the affinity "Build" XML files assigning buildings the SQL's categories.

                <Where Type="BUILDING_XENOFUEL_PLANT"/>
                <Set AffinityAffiliation="AFFINITY_HARMONY"/>
                <Where Type="BUILDING_GENE_GARDEN"/>
                <Set AffinityAffiliation="AFFINITY_PURITY_HARMONY"/>

    This is a link to the problematic mod, if that makes this easier.

    It is supposed to make the buildings with affinity symbols in front of them exclusive to one another with one vanishing when a conflicting one is built.

    They have no tech requirement, so setting two affinities to level 4 to unlock the first building of three sets of affinities is a quick way to test it.
    Last edited: Oct 12, 2017
  2. Galgus

    Galgus Emperor

    Aug 22, 2012
    The issue was a conflict with a mod I did not think would be problematic.

Share This Page