User:Kernelmethod/Sandbox: Difference between revisions

m Fix typo
Shorten the dynamic tables section a bit, add a reference to the Modding:Encounters and Population page
Line 961: Line 961:
Caves of Qud primarily uses dynamic tables when it needs to be be able to get one of a particular type of item or creature -- for instance, a random type of [[energy cell]] or a random type of [[goatfolk]]. This is useful, for example, for identifying what creatures are able to own a lair.
Caves of Qud primarily uses dynamic tables when it needs to be be able to get one of a particular type of item or creature -- for instance, a random type of [[energy cell]] or a random type of [[goatfolk]]. This is useful, for example, for identifying what creatures are able to own a lair.


There are several ways to create a dynamic table. One way is to add <code>DynamicObjectsTable</code>, as in the snippet for shrewd baboon. It's also possible to get added to a table by being descended from a base object and using <code>DynamicInheritsTable</code>. Consider, for instance, the <code>GritGateWorkbench</code> population table, used to generate the contents of the {{favilink|workbench|plural}} that appear in {{favilink|Grit Gate}}:
There are several ways to create a dynamic table:


<syntaxhighlight lang="xml">
* Through <code>DynamicObjectsTable</code>, such as the <code>DynamicObjectsTable:Baboons</code> table in the previous example. These tables contain all objects explicitly tagged as belonging to that table.
<population Name="GritGateWorkbench">
* Through the use of <code>DynamicInheritsTable</code>. These tables include all objects that inherit from another object. This inheritance doesn't need to be direct -- for example, even though {{favilink|shrewd baboon}} doesn't inherit from <code>Creature</code> (it inherits from <code>Baboon</code>), it would still fall under the dynamic inherits table for <code>Creature</code> since <code>Baboon</code> inherits from <code>BaseApe</code>, which in turn inherits from <code>Humanoid</code>, and which finally inherits from <code>Creature</code>.
  <group Name="GritGateWorkbench" Style="pickeach">
* Through a <code>DynamicSemanticTable</code>. A dynamic semantic table contains all objects that fall into several intersecting categories, such as "medical" and "furniture".
    <table Name="DynamicInheritsTable:Tool" Chance="15" />
    <table Name="Junk {zonetier}" Chance="15" />
    <table Name="DynamicObjectsTable:EnergyCells" Chance="15" />
  </group>
</population>
</syntaxhighlight>


This population table has a 15% chance of generating an item from the <code>DynamicInheritsTable:Tool</code> table, which includes any item that is descended (through inheritance) from <code>Tool</code>. This includes {{favilink|basic toolkit|plural}}, {{favilink|advanced toolkit|plural}}, {{favilink|pickaxe|plural}}, and several other items.
Finally, it's also possible to exclude an object from a dynamic table by using <code>ExcludeFromDynamicEncounters</code>. Check out the [[Modding:Encounters and Population]] page for more information on how dynamic tables work.


{| style = "margin: 1em;font-family:Source Code Pro;"
{| style = "margin: 1em;font-family:Source Code Pro;"
Line 980: Line 974:
| style = "border:1px solid #155352;padding:0.5em 1em;" | Because snapjaw mages are descended from the Snapjaw object, which in turn ultimately descends from the Creature object, it turns out that snapjaw mages were already included in some population tables before we started writing <code>PopulationTables.xml</code>! In particular, snapjaw mages could appear in the <code>DynamicInheritsTable:Creatures</code> table, although the probability of them being generated was pretty low.
| style = "border:1px solid #155352;padding:0.5em 1em;" | Because snapjaw mages are descended from the Snapjaw object, which in turn ultimately descends from the Creature object, it turns out that snapjaw mages were already included in some population tables before we started writing <code>PopulationTables.xml</code>! In particular, snapjaw mages could appear in the <code>DynamicInheritsTable:Creatures</code> table, although the probability of them being generated was pretty low.
|}
|}
The third and final way of creating dynamic tables is through the use of <code>DynamicSemanticTable</code>. Here, a dynamic "semantic" table includes all objects with a given <code>stag</code>. To understand this, consider the population table for the ruined ward section of {{favilink|Bethesda Susa}}:
<syntaxhighlight lang="xml">
<population Name="BethesdaSusaRuinedWard">
  <!-- Skipping over most of the contents of this table... -->
  <table Chance="80" Number="1-8" Name="DynamicSemanticTable:Medical,Furniture:4:6" Hint="AlongWall" />
  <table Chance="60" Number="1-4" Name="DynamicSemanticTable:Professional,Furniture:2:5" Hint="AlongWall" />
  <table Chance="5" Number="1-3" Name="DynamicSemanticTable:Torture,Furniture:1:5" Hint="AlongWall" />
  <table Chance="5" Number="1-2" Name="DynamicSemanticTable:Child,Furniture:1:5" Hint="AlongWall" />
  <table Chance="5" Number="1-2" Name="DynamicSemanticTable:Normality,Furniture" Hint="AlongWall" />
</population>
</syntaxhighlight>
Picking out one line of this, <code>DynamicSemanticTable:Medical,Furniture:4:6</code> is a dynamic table which includes objects that have both <code>&lt;stag Name="Medical" /&gt;</code> and <code>&lt;stag Name="Furniture" /&gt;</code> in their definition. The <code>4:6</code> bit will weight objects whose tier is 4 or whose tech tier is 6 more heavily than others.
{| style = "margin: 1em;font-family:Source Code Pro;"
| style = "padding:0em 1em;"| [[File:Mopango_pilgrim.png|40px]]
| style= "color:#155352" | <
| style = "border:1px solid #155352;padding:0.5em 1em;" | You can always use the <code>population:generate</code> wish to see what objects are in a given population table. For example, <code>population:generate:DynamicSemanticTable:Medical,Furniture#50</code> will sample from the "Medical,Furniture" dynamic semantic table 50 times, and show you how many times different objects were randomly sampled.
|}
Finally, it's worth pointing one can ''exclude'' an object from dynamic tables. You can add <code>&lt;tag Name="ExcludeFromDynamicEncounters" /&gt;</code> to a creature in <code>Creatures.xml</code> to ensure that that creature isn't added to any dynamic tables. This is especially helpful when creating unique or rare NPCs, whom you wouldn't just want showing up in the middle of a random zone.


Returning to our mod: there's a <code>Snapjaws</code> dynamic table that we can add our mages to. Doing so is fairly straightforward: open up <code>Creatures.xml</code> and add the following tag at the end of the definition of <code>Pyovya_SnapjawMage_Fire Mage</code> and <code>Pyovya_SnapjawMage_Ice Mage</code>:
Returning to our mod: there's a <code>Snapjaws</code> dynamic table that we can add our mages to. Doing so is fairly straightforward: open up <code>Creatures.xml</code> and add the following tag at the end of the definition of <code>Pyovya_SnapjawMage_Fire Mage</code> and <code>Pyovya_SnapjawMage_Ice Mage</code>: