Modding:Worlds: Difference between revisions

Jump to navigation Jump to search
m
Use hills instead of jungle since RoadNorthMouth / RoadSouthMouth won't really have any effect on the latter
mNo edit summary
m (Use hills instead of jungle since RoadNorthMouth / RoadSouthMouth won't really have any effect on the latter)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Modding Info}}
{{Modding Info}}


<code>Worlds.xml</code> 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.
<code>Worlds.xml</code> 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.
The game's primary "world", called JoppaWorld, contains most of the game content, but it is theoretically possible to add additional worlds.
Line 21: Line 21:
| 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)
| 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)
|-
|-
| <code>&nbsp;&nbsp;&nbsp;&nbsp;<nowiki><builder></nowiki></code>
| <code><nowiki><builder></nowiki></code>
| 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).
| 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).
|-
|-
Line 37: Line 37:
|-
|-
| <code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki><population></nowiki></code>
| <code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki><population></nowiki></code>
| Not supported or loaded by code (looks like it may have been previously, because there is a <nowiki><population></nowiki> tag included in the game's default Worlds.xml).
| Use the given population table to generate creatures and items in the zone.
|-
| <code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki><encounter></nowiki></code>
| Encounters to apply to the zone. These are loaded from EncounterTables.xml.
|-
| <code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki><feature></nowiki></code>
| Loaded by the game but currently not implemented or used for any purpose.
|-
|-
| <code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki><map></nowiki></code>
| <code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki><map></nowiki></code>
|  
| Use the provided map (an <code>.rpm</code> file) for the zone.
|-
|-
|}
|}
Line 87: Line 81:
The format is pretty much identical to JoppaWorldBuilderExtension above, except that the attribute is <code>[WorldBuilderExtension]</code> and the interface is <code>IWorldBuilderExtension</code>.
The format is pretty much identical to JoppaWorldBuilderExtension above, except that the attribute is <code>[WorldBuilderExtension]</code> and the interface is <code>IWorldBuilderExtension</code>.


== Worldgen design patterns ==
=== Dynamic secret generation at worldgen ===
A common use case for <code>IJoppaWorldBuilderExtension</code> / <code>IWorldBuilderExtension</code> is to dynamically add secrets to random locations on the map. In the base game this task is performed by <code>JoppaWorldBuilder</code>, and covers things like
* placing {{favilink|Bey Lah}} in a random {{favilink|flower fields}} tile;
* placing the snapjaw who wields {{favilink|Stopsvalinn}} to a random {{favilink|desert canyons}} tile;
* placing the lairs of the [[Girsh Nephilim]] and adding zonebuilders for each of those layers;
and so on.
In general, the steps for adding your own secret to Qud's map are as follows:
# Create your own world builder extension class inheriting from (most likely) <code>IJoppaWorldBuilderExtension</code>.
# In the <code>OnAfterBuild</code> method, grab a random mutable block of terrain using either <code>AddMutableEncounterToTerrain</code> or <code>popMutableLocationOfTerrain</code>.
# 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.
# Use <code>AddSecret</code> to add a corresponding secret to the location.
# (Optional) If you want to make the secret findable while traversing the world map, get the <code>TerrainTravel</code> part on the block of terrain that you popped and add a new <code>EncounterEntry</code> to it.
The code example below demonstrates how we would go through these steps to add a secret creature to a random hills tile.
<syntaxhighlight lang="csharp">
using XRL;
using XRL.World;
using XRL.World.WorldBuilders;
using XRL.World.ZoneBuilders;
namespace YourMod.YourNamespace
{
    [JoppaWorldBuilderExtension]
    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(
                zoneID,
                "the location of Secret Creature",
                new string[2] { "lair", "robot" },
                "Lairs",
                "$myname_mymod_mysecret"
            );
            // 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");
        }
    }
}
</syntaxhighlight>
Refer to the source of <code>JoppaWorldBuilder</code> for more examples.


{{Modding Navbox}}
{{Modding Navbox}}


[[Category: Modding]]
[[Category: Modding]]

Navigation menu