From Caves of Qud Wiki
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. This includes both static mapped content (such as the Joppa village layout) as well as dynamic zone builders (such as the builders that are used to generate underground caves).

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. These hooks are particularly useful if you're planning to add dynamically generated content similar to villages, lairs, sultan historical sites, etc, because they give you access to the same data that the core game uses to create that kind of content.

XML Structure

Worlds.xml has the following general structure:

XML Tag Description
  <world> auto merged with the game definition if the world with this Name was already defined (the primary game 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> Use the given population table to generate creatures and items in the zone.
        <map> Use the provided map (an .rpm file) for the zone.

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.


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
    public class YourJoppaWorldBuilderExtension : IJoppaWorldBuilderExtension
        public override void OnBeforeBuild(JoppaWorldBuilder builder)
            //The game calls this method before JoppaWorld generation takes place. JoppaWorld generation includes the creation of lairs, historic ruins, villages, and more.

        public override void OnAfterBuild(JoppaWorldBuilder builder)
            //The game calls this method after JoppaWorld generation takes place.


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.

Worldgen design patterns

Dynamic secret generation at worldgen

A common use case for IJoppaWorldBuilderExtension / IWorldBuilderExtension is to dynamically add secrets to random locations on the map. In the base game this task is performed by JoppaWorldBuilder, and covers things like

and so on.

In general, the steps for adding your own secret to Qud's map are as follows:

  1. Create your own world builder extension class inheriting from (most likely) IJoppaWorldBuilderExtension.
  2. In the OnAfterBuild method, grab a random mutable block of terrain using either AddMutableEncounterToTerrain or popMutableLocationOfTerrain.
  3. Add zone builders (see Modding:Zone Builders) to the zone that will add any creatures, objects, and structures to the zone that you see fit.
  4. Use AddSecret to add a corresponding secret to the location.
  5. (Optional) If you want to make the secret findable while traversing the world map, get the TerrainTravel part on the block of terrain that you popped and add a new EncounterEntry to it.

The code example below demonstrates how we would go through these steps to add a secret creature to a random hills tile.

using XRL;
using XRL.World;
using XRL.World.WorldBuilders;
using XRL.World.ZoneBuilders;

namespace YourMod.YourNamespace
    public class YourJoppaWorldBuilderExtension : IJoppaWorldBuilderExtension
        public override void OnAfterBuild(JoppaWorldBuilder builder)
            var location = builder.popMutableLocationOfTerrain("Hills", centerOnly: false);
            var zoneID = builder.ZoneIDFromXY("JoppaWorld", location.X, location.Y);

            // Change these parameters as appropriate for the secret that you're
            // adding.
            // - The second parameter affects how the secret appears in the journal
            // - The third parameter affects which factions will sell the secret.
            // - The fourth parameter affects the category under which the secret
            //   shows up in the journal.
            // - The fifth parameter is the ID for the secret, which can be revealed
            //   using e.g. the revealsecret wish.
            var secret = builder.AddSecret(
                "the location of Secret Creature",
                new string[2] { "lair", "robot" },

            // Add zone builders to the zone.
            // Each zone builder has a different priority (the integer parameter that
            // is passed in). Builders with lower priority run before builders with
            // higher priority.
            var zoneManager = The.ZoneManager;

            // Add some roads to the north and south
            zoneManager.AddZoneBuilder(zoneID, ZoneBuilderPriority.LATE, nameof(RoadNorthMouth));
            zoneManager.AddZoneBuilder(zoneID, ZoneBuilderPriority.LATE, nameof(RoadSouthMouth));

            // Add an object to the zone
            // Replace "Oboroqoru" with the object ID of the creature you want to add
            var creature = GameObject.Create("Oboroqoru");
            zoneManager.AddZonePostBuilder(zoneID, nameof(AddObjectBuilder), "Object", zoneManager.CacheObject(creature));

            // You can also set various properties on the zone, if you wish.
            zoneManager.SetZoneName(zoneID, "lair of My Creature", Article: "the", Proper: true);
            zoneManager.SetZoneIncludeStratumInZoneDisplay(zoneID, false);
            zoneManager.SetZoneProperty(zoneID, "NoBiomes", "Yes");

Refer to the source of JoppaWorldBuilder for more examples.