Modding:Worlds

From Caves of Qud Wiki
Revision as of 21:56, 9 August 2020 by Egocarib (talk | contribs) (Add info about C# interfaces)
Jump to navigation Jump to search
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.

Worlds.xml defines many of the important zones on the world map. The game's primary "world", called JoppaWorld, contains most of the game content, but it is theoretically possible to add additional worlds.

In addition to the XML, the game code includes a few hooks that a programmer can use to modify the world state during the world generation process.

XML Structure

Worlds.xml has the following general structure:

XML Tag Description
<worlds>
  <world> auto merged with the game definition if the world with this Name was already defined (the only world currently is JoppaWorld, so you want to use that if you're trying to merge into Qud's world)
    <builder> Any builder class you specify gets added to the list of builders and executed as part of world creation. Must be a class in the XRL.World.WorldBuilders namespace. The only builder used by the base game is JoppaWorldBuilder. Begin a Class name with minus (-) to remove all builders with that class from existing world definition (this would probably be a bad idea though unless you're remaking the entire world by fully replacing JoppaWorldBuilder).
    <cell> Cell nodes are completely overwritten if they have a matching Name to one that already exists in the game files. Cell nodes can inherit from other cell nodes.
      <zone> Define the specified zone or range of zones within this world cell. For example, the Rustwell is a single world cell, which includes various zone definitions for the zones included within it's 3x3 parasang area and Z depths. The game currently applies a depth cap of 49 to zone definitions (in XRL.World.ZoneManager.GetZoneBlueprint). As a result, if you define a zone definitions with a Level attribute higher than 49, those definitions are ignored.
        <builder> Builders for zones. Zones can have multiple builders, which are applied in succession to generate the zone.
        <postbuilder> Postbuilders are similar to builders, but applied afterward.
        <population> Not supported or loaded by code (looks like it may have been previously, because there is a <population> tag included in the game's default Worlds.xml).
        <encounter> Encounters to apply to the zone. These are loaded from EncounterTables.xml.
          <feature> Loaded by the game but currently not implemented or used for any purpose.
        <map>

World Generation Code

The game exposes two interfaces that a modder may hook into to apply custom logic before or after the world generation process.

JoppaWorldBuilderExtension

This interface is called before and after JoppaWorld generation.

using XRL.World.WorldBuilders;

namespace YourMod.YourNamespace
{
    //The game code instantiates an instance of this class during the JoppaWorld generation process
    [JoppaWorldBuilderExtension]
    public class YourJoppaWorldBuilderExtension : IJoppaWorldBuilderExtension
    {
        public override void OnBeforeBuild(JoppaWorldBuilder builder)
        {
            //The game calls this method before JoppaWorld genration takes place (i.e. creation of lairs, historic ruins, villages, and more)
        }

        public override void OnAfterBuild(JoppaWorldBuilder builder)
        {
            //The game calls this method after JoppaWorld genration takes place
        }
    }
}

WorldBuilderExtension

This interface is called before and after the overall world generation process runs (it is not specific to JoppaWorld).

The format is pretty much identical to JoppaWorldBuilderExtension above, except that the attribute is [WorldBuilderExtension] and the interface is IWorldBuilderExtension.