Resource Generator Framework

RimWorld 1.7 framework

Resource Generator Framework

Shared code for resource drill buildings. Each drill digs through a small underground grid where you pick cells, shift sideways and go deeper for bigger, rarer finds. You define the buildings in XML; the framework handles the grid, the work, the UI and the hazards.

Steam Workshop Source on GitHub

Resource Generator Framework preview image

How a drill plays

The framework adds no buildings itself. When another mod adds a drill built on it, that drill gets a Drill tab in its inspector showing the grid under it (2x2 by default, any size the modder picks). Each cell holds a resource stack, nothing, or a hazard.

Steelx62
empty
Goldx38vein
Hivehazard
Uraniumx21
?hidden

An example 3x2 grid. Veins hold double stacks, caverns half. Hidden cells show their contents only when drilled.

The player queues up to 10 actions. Each one takes work, then resolves:

Drill
Empties the grid and drops everything next to the drill. Depending on the building, the player can also drill just the leftmost column, the top row, or any single cell, for a matching share of the work. Drilling cells that hold nothing gives stone chunks.
Move left / right
Shifts the grid one column. A new column is rolled on one side and the column on the other side is lost. Every move damages the drill by half a percent of its max HP per depth level.
Drill deeper / drill up
Changes depth by one and rolls a whole new grid. Going deeper can cost materials, taken from unforbidden stacks anywhere on the map.

Manual drills are worked by pawns through a normal work type. Each pawn adds work at their Deep Drilling Speed, and a building with several interaction spots can take several pawns at once. Automatic drills add a fixed amount of work on a timer, no pawns needed. Both stop without power.

If Vanilla Expanded Framework is loaded, resources that a nearby pipe net can store (through the drill's own pipe comp or a connector next to it) go into the net first. The rest is placed on the ground.

Depth and hazards

Every level deeper changes the trade-off:

Hazards replace a cell's contents and trigger when that cell is drilled. Their odds are set in code, not XML:

HazardChance per cell at depth dWhen drilled
Insect hive(5 + d)%, max 50%Infestation tunnels, d hives per cell
Mechanoid chamber(1 + d)%, max 30%d/2 mechanoids (at least one) that assault the colony
Methane pocket10%Explosion at the drill, radius growing with depth

Rolls run top to bottom, so each hazard's odds apply only if the ones above it missed.

Add a drill to your mod

  1. Add the framework as a dependency in About.xml. Its package ID is bambaryla.resourcegeneratorframework, and it needs Harmony.
  2. Give your building the drill comp and the drill inspector tab.
  3. For a manual drill, add a WorkGiverDef so pawns know to work it. Automatic drills (isAutomatic true) skip this.

Building

The drill-specific parts of a ThingDef. The rest (graphics, size, cost, research) is a normal building. A full example is in 1.7/Defs/example.xml.

<ThingDef ParentName="BuildingBase">
  <defName>MyMod_Drill</defName>
  <tickerType>Normal</tickerType>
  <!-- one interaction spot per worker -->
  <multipleInteractionCellOffsets>
    <li>(0,0,-2)</li>
    <li>(1,0,-2)</li>
  </multipleInteractionCellOffsets>
  <placeWorkers>
    <li>PlaceWorker_PreventInteractionSpotOverlap</li>
  </placeWorkers>
  <inspectorTabs>
    <li>BambaResourceGenerator.ITab_ResourceDrill</li>
  </inspectorTabs>
  <comps>
    <li Class="CompProperties_Power">
      <compClass>CompPowerTrader</compClass>
      <basePowerConsumption>2000</basePowerConsumption>
    </li>
    <li Class="BambaResourceGenerator.CompProperties_ResourceDrill">
      <operateJobDef>Bamba_OperateResourceDrill</operateJobDef>
      <gridWidth>3</gridWidth>
      <gridHeight>2</gridHeight>
      <preciseDrilling>1</preciseDrilling>
      <maxDepth>10</maxDepth>
      <powerPerDepth>250</powerPerDepth>
      <depthYieldMultiplierPerLevel>0.25</depthYieldMultiplierPerLevel>
      <expandDownCostDef>Steel</expandDownCostDef>
      <expandDownCostCount>50</expandDownCostCount>
      <expandDownCostCountPerDepth>25</expandDownCostCountPerDepth>
      <drillableResources>
        <li>
          <thingDef>WoodLog</thingDef>
          <amount>25~50</amount>
          <weight>1</weight>
        </li>
      </drillableResources>
    </li>
  </comps>
</ThingDef>

Work giver

One per manual drill. DrillThingDef points at your building; DrillJobDef is always Bamba_OperateResourceDrill.

<WorkGiverDef>
  <defName>MyMod_DrillAtMyDrill</defName>
  <label>drill at resource drill</label>
  <giverClass>BambaResourceGenerator.WorkGiver_DrillAtResourceDrill</giverClass>
  <workType>Mining</workType>
  <priorityInType>50</priorityInType>
  <verb>drill</verb>
  <gerund>drilling</gerund>
  <requiredCapacities>
    <li>Manipulation</li>
  </requiredCapacities>
  <canBeDoneByMechs>true</canBeDoneByMechs>
  <modExtensions>
    <li Class="BambaResourceGenerator.DefModExtension_ResourceDrill">
      <DrillThingDef>MyMod_Drill</DrillThingDef>
      <DrillJobDef>Bamba_OperateResourceDrill</DrillJobDef>
    </li>
  </modExtensions>
</WorkGiverDef>

Field reference

Every field on BambaResourceGenerator.CompProperties_ResourceDrill. Leave a field out to keep its default.

Work and automation

FieldDefaultMeaning
operateJobDefnoneSet to Bamba_OperateResourceDrill. Required for manual drills.
isAutomaticfalseThe drill works on its own instead of using pawns.
tickInterval60Automatic drills: how often, in ticks, work is added.
workPerInterval1Automatic drills: work added each interval.
workDrill600Work to drill the whole grid. A column, row or cell costs its share.
workMoveSideways300Work to shift the grid left or right.
workMoveUp300Work to go up one level.
workMoveDown600Work to go down one level.

All work costs are multiplied by the current depth and by the player's work multiplier setting.

Grid

FieldDefaultMeaning
gridWidth, gridHeight2, 2Grid size in cells. Both must be at least 1.
preciseDrilling00: drill the whole grid only. 1: also drill the leftmost column or top row. 2: also click any cell to drill it.
emptyCellChance0.3Chance a cell holds nothing.
veinChance, veinMultiplier0.1, 2Chance a resource cell is a vein, and its stack multiplier.
cavernChance, cavernMultiplier0.1, 0.5Chance a resource cell is a cavern, and its stack multiplier.
stoneChunkDef, stoneChunkCountChunkGranite, 2What drops when a drill action finds nothing at all.

Depth

FieldDefaultMeaning
minDepth, maxDepth1, 10How high and how deep the drill can go.
startDepth1Depth of a newly built drill.
powerPerDepth0Extra watts for each level past level 1, on top of basePowerConsumption.
depthYieldMultiplierPerLevel0Stacks are multiplied by 1 + depth × value.
resourceYield1Stacks are also multiplied by 1 + value × ln(depth), so this does nothing at depth 1.
expandDownCostDefnoneMaterial paid to go deeper. Leave empty for free.
expandDownCostCount, expandDownCostCountPerDepth0, 0Cost to go deeper is count + perDepth × current depth.

Resources

FieldDefaultMeaning
allowAnyDeepdrillResourcetrueInclude every ThingDef with deepCommonality above 0, weighted by it. Stack size is deepCountPerCell × 0.5 to 1.5.
isInvertWhitelistfalseWith the deep-drill pool on, makes drillableResources a blacklist instead of extra entries.
drillableResourcesnoneA list of entries with thingDef, amount (range, for example 25~50) and weight (default 1). Added to the deep-drill pool, or the only resources if allowAnyDeepdrillResource is false.

baseWorkAmount, isFixedWorkAmount, selectResourceUiIcon and the per-entry fixedWorkAmount and workAmount come from the older select-a-resource drill. They still load so old XML doesn't throw errors, but nothing reads them.

Settings and compatibility

Players get a yield multiplier and a work multiplier in the mod settings. Both apply to every drill built on the framework.

With [LFS] UI Rethemed - Core active, the Drill tab is drawn in that mod's theme. The compat code is a separate assembly loaded through LoadFolders.xml only when Core is active, so there is no hard dependency. If the themed tab throws, it falls back to the vanilla look and logs one warning.

Vanilla Expanded Framework's pipe system is picked up through reflection when it is loaded, as described above. It is not required.

Credits

Design and idea by Bambaryla. The first, basic drill was written by Shun The Witch, Sandwish and Taranchuk; the grid system is by Bambaryla. Inspired by Quarry and Omni Core Drill.