User:Kernelmethod/Sandbox: Difference between revisions

Jump to navigation Jump to search
No edit summary
(Finish up the population tables section)
Line 1: Line 1:
== Introduction ==
Welcome! If you're looking to learn how to write mods for Caves of Qud, this tutorial is a good place to start.
Welcome! If you're looking to learn how to write mods for Caves of Qud, this tutorial is a good place to start.


Line 23: Line 25:


This mod won't require any scripting, so you don't need to know anything about C#. However, I'd recommend that you play through a good chunk of Caves of Qud before you try your hand at modding. It's helpful to be able to refer to existing creatures and items when creating new ones.
This mod won't require any scripting, so you don't need to know anything about C#. However, I'd recommend that you play through a good chunk of Caves of Qud before you try your hand at modding. It's helpful to be able to refer to existing creatures and items when creating new ones.
=== Source code ===


You can find the source for the final version of the mod here: https://github.com/TrashMonks/Snapjaw-Mages
You can find the source for the final version of the mod here: https://github.com/TrashMonks/Snapjaw-Mages
Line 703: Line 707:
== Controlling spawning: population tables ==
== Controlling spawning: population tables ==


We've successfully added our mages and given them magical tomes. There's still one thing missing: our mages currently won't spawn in-game unless we use wishes.
{| style = "margin: 1em;font-family:Source Code Pro;"
| style = "padding:0em 1em;"| [[File:Sprouting orb.png|40px]]
| style= "color:#155352" | <
| style = "border:1px solid #155352;padding:0.5em 1em;" | Well, it looks like I can wish for a <code>Pyovya_SnapjawMage_Fire Tome</code> or a <code>Pyovya_SnapjawMage_Ice Mage</code>. But I can't find them anywhere in the game!
|}
 
That's because there's one thing we're still missing: we haven't told Caves of Qud when and where our new mages should spawn!


Caves of Qud uses '''''population tables''''' to decide when to spawn different items and creatures. Here's an example of one such population table (which you can find in the game data in <code>PopulationTables.xml</code>):
Caves of Qud uses '''''population tables''''' to decide when to spawn different items and creatures. Here's an example of one such population table (which you can find in the game data in <code>PopulationTables.xml</code>):
Line 784: Line 794:
| style = "padding:0em 1em;"| [[File:Mopango_pilgrim.png|40px]]
| style = "padding:0em 1em;"| [[File:Mopango_pilgrim.png|40px]]
| style= "color:#155352" | <
| style= "color:#155352" | <
| style = "border:1px solid #155352;padding:0.5em 1em;" | We need to specify <code>Load="Merge"</code> to tell Caves of Qud that we want to merge new XML into an existing table called (for example) <code>SnapjawParty0</code>. This prevents us from creating a new population table called <code>SnapjawParty0</code> that overwrites the old one.
| style = "border:1px solid #155352;padding:0.5em 1em;" | We need to specify <code>Load="Merge"</code> to tell Caves of Qud that we want to merge new XML into an existing table. This prevents us from creating a new population table like (for example) <code>SnapjawParty0</code> that overwrites the old one.


It's possible to use <code>Load="Merge"</code> to modify the contents of most of the game's XML files.
It's possible to use <code>Load="Merge"</code> to modify the contents of most of the game's XML files.
Line 855: Line 865:
=== Creating new tables ===
=== Creating new tables ===


Having two mages appear alongside every party of snapjaws feels like a lot -- ideally, we'd have ''either'' one fire mage ''or'' one ice mage show up. We could try using <code>Chance</code> to reduce the probability of each type of mage showing up, for example:
Having two mages appear alongside every party of snapjaws feels like a lot -- ideally, we'd have either one fire mage or one ice mage show up. We could try using <code>Chance</code> to reduce the probability of each type of mage showing up, for example:


<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
Line 864: Line 874:
But all that does is give us a 50% chance of spawning a fire mage, ''and'' a 50% chance of spawning an ice mage. That means that there's a 25% chance that ''both'' mages show up, and a 25% chance that ''neither'' mage shows up.
But all that does is give us a 50% chance of spawning a fire mage, ''and'' a 50% chance of spawning an ice mage. That means that there's a 25% chance that ''both'' mages show up, and a 25% chance that ''neither'' mage shows up.


Here's what we can do instead: let's define a ''new'' population table. This table will be set up so that whenever we sample an item from the table, we will either pick a fire mage, ''or'' we'll pick an ice mage:
Instead, we'll define a new population table. This table will be set up so that whenever we sample from it, we either pick a fire mage or an ice mage:


<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
Line 875: Line 885:
</syntaxhighlight>
</syntaxhighlight>


By giving the <code>Mages</code> group <code>Style="pickone"</code>, we're telling the game "whenever we pick an item from the <code>Pyovya_SnapjawMage_Mages</code> table, we want to pick ''one of'' the items listed in our <code>Mages</code> group".
By giving the <code>Mages</code> group <code>Style="pickone"</code>, we're telling the game "whenever we pick an item from the <code>Pyovya_SnapjawMage_Mages</code> table, we want to pick just one of the items listed in our <code>Mages</code> group".
Now we can change the XML that we merged into the <code>SnapjawParty</code> tables to sample from our new table instead. Our final <code>Populations.xml</code> table will look like this:
 
<syntaxhighlight lang="xml">
<?xml version="1.0" encoding="utf-8" ?>
<populations>
  <population Name="Pyovya_SnapjawMage_Mages">
    <group Name="Mages" Style="pickone">
      <object Number="1" Blueprint="Pyovya_SnapjawMage_Fire Mage" />
      <object Number="1" Blueprint="Pyovya_SnapjawMage_Ice Mage" />
    </group>
  </population>
 
  <population Name="SnapjawParty0" Load="Merge">
    <group Name="Creatures" Load="Merge">
      <table Name="Pyovya_SnapjawMage_Mages" />
    </group>
  </population>
 
  <population Name="SnapjawParty1" Load="Merge">
    <group Name="Creatures" Load="Merge">
      <table Name="Pyovya_SnapjawMage_Mages" />
    </group>
  </population>
 
  <population Name="SnapjawParty1-with-Warlord" Load="Merge">
    <group Name="Creatures" Load="Merge">
      <table Name="Pyovya_SnapjawMage_Mages" />
    </group>
  </population>
 
  <population Name="SnapjawParty0" Load="Merge">
    <group Name="Creatures" Load="Merge">
      <table Name="Pyovya_SnapjawMage_Mages" />
    </group>
  </population>
</populations>
</syntaxhighlight>
 
After this change, snapjaw parties that we run across will only have one mage rather than two.


=== Dynamic population tables ===
=== Dynamic population tables ===


So far, the tables we've been working with have been '''''static''''' -- they're pre-defined based on the contents of <code>PopulationTables.xml</code>. It's also possible to generate a '''''dynamic''''' population table, by giving creatures and items a <code>DynamicObjectsTable</code> tag.
So far, the tables we've been working with have been '''''static''''' -- they're pre-defined based on the contents of <code>PopulationTables.xml</code>. It's also possible to generate a '''''dynamic''''' population table, by giving creatures and items a <code>DynamicObjectsTable</code> tag. For instance, let's take a look at the definition of {{favilink|shrewd baboon}} in the game's <code>ObjectBlueprints/Creatures.xml</code>:
 
<syntaxhighlight lang="xml">
<object Name="Shrewd Baboon" Inherits="Baboon">
  <part Name="Render" DisplayName="shrewd baboon" ColorString="&amp;B" />
  <stat Name="AV" Value="3" />
  <stat Name="Intelligence" Boost="1" />
  <stat Name="Hitpoints" Value="20" />
  <property Name="Role" Value="Leader" />
  <tag Name="DynamicObjectsTable:Baboons" />
</object>
</syntaxhighlight>
 
The <code>&lt;tag Name="DynamicObjectsTable:Baboons" /&gt;</code> XML at the end adds the shrewd baboon to the "Baboons" dynamic table.
 
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'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>:
 
<syntaxhighlight lang="xml">
<tag Name="DynamicObjectsTable:Snapjaws" />
</syntaxhighlight>
 
[[File:Snapjaw Mages -- travelnote fire mage.webp|600px]]
[[File:Snapjaw_Mages_--_legendary_fire_mage.webp|600px]]


== Conclusion ==
== Conclusion ==