How to determine if Gods & Kings (or any other DLC) is present from within your mod

General Tso

Panzer General
Joined
Oct 12, 2007
Messages
1,548
Location
U. S. of A.
I needed a way to determine if God & Kings is present so I could disable certain controls in my mod. I found something that looks like it will work so I thought I would post what I found in case anybody else was looking for the same thing. I would also be interested in seeing if it works as expected on other people's systems. Especially those who do not have Gods & Kings. Here's the code if anybody else is interested.

Code:
for _, id in ipairs(ContentManager.GetAllPackageIDs()) do
    print("\n-----------------------------------------------------------------------------------------");
    print("id = ", id);
			
    local description = Locale.Lookup(ContentManager.GetPackageDescription(id));
    print("description = ", description);

    local isActive = ContentManager.IsActive(id, ContentType.GAMEPLAY);
    print("isActive = ", isActive);
			
    if id == "0E3751A1-F840-4E1B-9706-519BF484E59D" then
        print("Expansion is present!");
    end
end

I found the original code in UI\FrontEnd\PremiumContentMenu.lua
 
From within Lua I use

Code:
local isGandK = (GameInfoTypes.UNITCOMBAT_NAVALMELEE ~= nil)

and SQL

Code:
AND EXISTS (SELECT Value FROM Defines WHERE Name='MAX_HIT_POINTS' AND Value=100);
 
From within Lua I use

Code:
local isGandK = (GameInfoTypes.UNITCOMBAT_NAVALMELEE ~= nil)

and SQL

Code:
AND EXISTS (SELECT Value FROM Defines WHERE Name='MAX_HIT_POINTS' AND Value=100);

Yes, and I use similar things for the other DLCs (i.e. checking to see if a CIVILIZATION_DENMARK is in the database to determine whether the Denmark DLC is owned by the player).

Nevertheless, General Tso's code seems to be more precise.
 
Code:
local isGandK = ContentManager.IsActive("0E3751A1-F840-4E1B-9706-519BF484E59D", ContentType.GAMEPLAY)

would be the Lua equivalent, but that would still leave you testing for specific values in SQL
 
I'm not sure if I understand what you are saying. The code that I posted allows you to cycle through every DLC that the user has installed so there's no need to check anything via SQL. Or am I missing something? Which is totally possible and would be par for the course. :lol:
 
I'm not sure if I understand what you are saying. The code that I posted allows you to cycle through every DLC that the user has installed so there's no need to check anything via SQL. Or am I missing something? Which is totally possible and would be par for the course. :lol:

If you want to create a new unit that works with both vanilla and G&K it will need different combat values (at the very least, and possibly different promotions), so you will need to create the unit (with XML say) with all the common attributes and then select specific values depending on whether or not G&K is being used via SQL

For example

Code:
MechInfantry.xml
<Units>
  <Row>
    <!-- Most values are common between vanilla and G&K -->
    <Class>UNITCLASS_MECH_INFANTRY</Class>
    <Type>UNIT_MECH_INFANTRY</Type>
    <PrereqTech>TECH_NUCLEAR_FISSION</PrereqTech> <!-- This is the vanilla value, it is overwritten by SQL for G&K -->
    <Combat>80</Combat> <!-- This is the vanilla value, it is overwritten by SQL for G&K -->
    <Cost>650</Cost>
    <Moves>3</Moves>
    <CombatClass>UNITCOMBAT_GUN</CombatClass>
    <!-- etc -->
  </Row>
</Units>

MechInfantry.sql (executes after the above xml is added to the game database)
-- Gods and Kings update
UPDATE Units SET Combat=120, PrereqTech='TECH_PARTICLE_PHYSICS' WHERE Type='UNIT_MECH_INFANTRY' AND EXISTS (SELECT Value FROM Defines WHERE Name='MAX_HIT_POINTS' AND Value=100);

The same is true for culture buildings - where you need to let an XML file trying to add a culture value for vanilla fail and use SQL to inject the correct culture yield values for G&K - see http://forums.civfanatics.com/showthread.php?t=468374
 
Ah. I see what you are saying. I was only concerned about changes made in Lua. I wasn't thinking about adding anything via XML or SQL. All I was going to do was enable or disable some UI controls depending on which version existed so I wasn't thinking about the data values for units etc... At the moment that stuff is more or less invisible to my mod.

As it ended up I found a way around my problem by adding a call to GameEvents.PlayerDoTurn for non G&K users while G&K users will still be handled by GameEvents.PlayerCityFounded so I don't need to worry about whether G&K is installed at this time. But I have a feeling I'll need the things I learned in this thread in the future.
 
Back
Top Bottom