Modding:Encounters and Population

From Caves of Qud Wiki
Revision as of 22:53, 23 November 2020 by Egocarib (talk | contribs) (add dynamic table example)
Jump to navigation Jump to search
This article is a stub. You can help Caves of Qud Wiki by expanding it.
This article is a stub. You can help Caves of Qud Wiki by expanding it.

This page is about modding. See the modding overview for an abstract on modding.
This page is about modding. See the modding overview for an abstract on modding.

There are two primary population systems in Caves of Qud, the legacy EncounterTables.xml system, and the ZoneTemplates.xml+PopulationTables.xml system. Encounter tables are an older system and we prefer to use zone templates + population tables these days, but much of the game is still populated via EncounterTables.xml.

Like ObjectTables, EncounterTables.xml supports Load="Merge" in the object root tag. This will append entries to that particular table instead of overwriting.

Population tables currently do not support XML modding, but many zone template encounters draw objects from dynamically created population tables. Check out the following tags in ObjectBlueprints.xml to see them in use: DynamicObjectsTable, ExcludeFromDynamicEncounters. Some dynamic population tables are created based on the base type of the object, so new objects will begin appearing immediately in areas generated with dynamic population tables unless they are tagged with ExcludeFromDynamicEncounters.

The unaffiliated cave systems are the only areas currently heavily populated with the template+population system.

Extending Encounter Tables

You may add new entries to existing encounter tables by including EncounterTables.xml in your mod, using an existing table name and setting the Load="Merge" property on the encountertable tag.

Adding "My New Ammo" to the "Ammo 1" built-in encounter table

<encountertables>
  <encountertable Name="Ammo 1" Load="Merge">
    <objects>
      <object Chance="100" Number="3d6" Blueprint="My New Ammo"></object>
    </objects>
  </encountertable>
</encountertables>

Additional Info

This article may need cleanup to meet quality standards.
Please help improve this page by editing it.

Reason: "The information from the Steam thread needs to be integrated into this article."

This article may need cleanup to meet quality standards.
Please help improve this page by editing it.

Reason: "The information from the Steam thread needs to be integrated into this article."

Here's a thread on Steam where Brian discusses using encounter and population tables: http://steamcommunity.com/app/333640/discussions/3/358415738194955181/

Modifying Existing Populations

To modify existing populations, use PopulationManager.cs to load the changes on game boot up.

// Helper method to fudge into the most common/simple pop tables.
public static bool AddToPopTable(string table, params PopulationItem[] items) {
    PopulationInfo info;
    if (!PopulationManager.Populations.TryGetValue(table, out info))
        return false;
        
    // If this is a single group population, add to that group.
    if (info.Items.Count == 1 && info.Items[0] is PopulationGroup) { 
        var group = info.Items[0] as PopulationGroup;
        group.Items.AddRange(items);
        return true;
    }

    info.Items.AddRange(items);
    return true;
}

// Usage in IPart constructor slapped on dummy XML object
public class SomeInitialiser : IPart
{
    public SomeInitialiser() {
        AddToPopTable("RandomLiquid", new PopulationObject { Blueprint = "SomeLiquid" });
        AddToPopTable("RandomFaction", new PopulationObject { Blueprint = "SomeFaction" });
        AddToPopTable("LairOwners_Saltdunes", new PopulationTable { Name = "DynamicObjectsTable:SomeCreature", Weight = 5 });
    }
}

Dynamic Tables

The game sometimes uses dynamically generated population tables, which are constructed from objects in ObjectBlueprints.xml.

For example, XRL.World.Parts.PsionicDervish may select an object from the DynamicInheritsTable:BaseLongBlade:Tier5, DynamicInheritsTable:BaseLongBlade:Tier7, or DynamicInheritsTable:BaseLongBlade:Tier9 tables depending on the type of dervish. This table will select any item that inherits from "BaseLongBlade" as long as it does not have the ExcludeFromDynamicEncounters tag. For dynamic tables of this type with a tier, the game will strongly weight items of the specified tier, but items of other tiers can also be selected.

For example, DynamicInheritsTable:BaseLongBlade:Tier5 will give a weight of 1000 to items of the specified tier, a weight of 100 to items one tier above or below that, a weight of 10 to items two tiers above or below that, and a weight of 1 to all other items. This results in a population table being constructed by the game similar to the following:

Item Weight
bronze long sword 1
bronze two-handed sword 1
iron long sword 1
two-handed iron long sword 1
steel long sword 1
two-handed steel long sword 1
carbide long sword 10
two-handed carbide long sword 10
folded carbide long sword 100
two-handed folded carbide long sword 100
fullerite long sword 1000
two-handed fullerite long sword 1000
crysteel long sword 100
crysteel great sword 100
flawless crysteel long sword 10
flawless crysteel great sword 10
zetachrome long sword 1
two-handed zetachrome long sword 1
vibro blade 1000