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
m (Add information about the <map> tag.)
m (Use hills instead of jungle since RoadNorthMouth / RoadSouthMouth won't really have any effect on the latter)
 
(3 intermediate revisions by the same user not shown)
Line 81: 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