ASAD PAVEL
← ARCHIVE

Making a Factory Survive Its Own Warp

A Friday-Facts-style postmortem of Warptorio 0.4.4: cloning a platform, correcting fluid boxes, freezing trains, baking boss prototypes, and keeping multiplayer votes honest.

Warptorio puts your whole factory on a platform that warps between planets. Every jump moves the physical factory to a new surface, but the factory is more than tiles and entities. It also has fluid networks, train schedules, spidertron remotes, research progress, circuit connections, and rendering state.

Moving the tiles is easy. Keeping everything built on top of them working is the hard part.

This post is about Warptorio 0.4.4, the merged release of the edge branch. The official changelog is dated 2026-10-03. It spans 72 commits beyond 0.4.3 and targets Factorio: Space Age 2.1. Warptorio is developed by Venca123; this update was contributed by me. You can find it on the repository and the mod portal.

Most of 0.4.4 is not a headline feature. It is the unglamorous work of making one very large operation, the warp, trustworthy. Here is what that took.

One warp, in full

A warp touches more systems than most Factorio mods ever need to. The shape of it is:

flowchart TD
  A[Vote or timer] --> B[Countdown]
  B --> C[Pause research]
  C --> D[Snapshot state]
  D --> E[Clone ground platform to new surface]
  E --> F[Restore fluids and trains]
  F --> G[Resume research]
  G --> H[Reconnect power]

The interesting part is the middle. Factorio does not give you an atomic transaction for moving a factory between surfaces. You have to simulate one, and the simulation only works if you know exactly which pieces the engine will copy and which pieces it will silently leave behind.

The platform itself moves through a single LuaSurface.clone_brush call. It takes the source surface, the destination surface, and an explicit list of source positions. That list is not a rectangle. It is the tiles for the current platform shape, rebuilt from cached shape offsets. A non-square platform must not drag planet terrain in from the corners of its bounding box.

The call clones tiles and entities, clears destination entities and decoratives first, and keeps decoratives off the platform. expand_map makes sure the destination chart exists. source_positions keeps the clone to the platform footprint.

Then there is the part people forget about when they first design a mod like this: clone_brush does not know anything about Lua state. It will not restore train schedules, spidertron remotes, research progress, or rendering objects. It also copies fluid boxes in a state that has to be corrected after the fact. That split is the whole design problem.

Bosses the engine will actually scale

Bosses used to be part of wave spawning. They now live in modules/boss_system.lua, which handles spawning, tracking, chart tags, loot, and cleanup.

The engine takes max health from the prototype, not the entity, so you cannot scale one biter into a boss at runtime, especially with quality variants. Warptorio bakes the scaled health and collision box into a separate boss prototype at the data stage. The larger collision box also makes the boss show up properly on the map.

At runtime a small registry tracks each boss by unit number, quality, and chart tag. It is swept once per second; on death the entry is removed, loot drops with the boss’s quality, and warptorio-boss-died fires. Planet-bound variants come from other enemy mods, and 0.4.4 caps bosses at 16, triples health, halves the normal flood during boss waves, and guarantees a boss every 10th wave. Boss chance ramps to 50%, with one extra boss every 20 warps.

Revealing the platform one animation at a time

Platform construction lives in two modules. platform_builder.lua handles geometry and entity placement; platform_animation.lua handles the queue and the build animations. The animation itself was copied from Space Age: at the data stage Warptorio takes build_animations from space-platform-foundation, applies them to its custom ground-platform tile, and creates per-direction warptorio-platform-build-anim-* explosion prototypes from those layers.

The important decision is that expansion does not stamp every tile at once. Warptorio sorts new tiles by distance from the center, then reveals them as their build animations finish. The queue uses a spawn budget rather than a fixed timer. A small upgrade gets a minimum of 240 ticks. A large one targets roughly six ticks per tile but still respects expand_lock_ticks. The budget accumulates over time and spawns at most 64 animations per tick, so the wave keeps moving without spawning thousands of animations in one tick and calling it a day.

A fully expanded Warptorio ground platform with the factory core, perimeter defenses, and connector tiles
A ground platform built up over many warps. The shape is why the clone needs an explicit tile list, not a rectangle.

There is an ugly edge case. Entities in inactive chunks may not advance their animation lifecycle the way you expect. If you wait for those animations to complete, the queue can wait forever. So Warptorio treats an animation as finished after anim_max_ticks (600 ticks, or 10 seconds) and places the tile directly. It is a fallback, not a fix, and it is the kind of thing you only discover after a player expands into a corner you never tested.

Repair uses the same queue, but selects edge tiles and works inward in configurable batches of 1, 5, or 10 tiles per interval.

The capacitor upgrade that ate its own circuit wires

Capacitor capacity research replaces the power entity. Destroy and recreate it naively and its circuit wires go with it, so the platform can quietly lose its circuit network after a capacity upgrade. That is the sort of bug that shows up ten warps later as “the lamps stopped working”.

power_tick.lua captures both ends of every connected wire before the upgrade. It records the connector IDs and the partner entity, not just the wire object. Then it destroys and recreates the capacitor in place and reconnects on the following tick.

Two details matter. The reconnection uses defines.wire_origin.player so the rebuilt connection behaves like a hand-placed wire; without it the connection can exist but render badly. And the one-tick delay matters too: wires recreated immediately can render hidden or visually broken, while the delayed ones become normal player wires. That delay is an observed workaround, not a documented engine requirement, so if you copy this approach, verify it against your Factorio version. power_tick.lua also restores the cross-surface links between the ground, factory, and garden capacitors.

Pausing research without losing it

Platform research used to keep labs draining science packs during a warp. The new research_pause.lua pauses it properly by writing the current normalized progress into LuaTechnology.saved_progress, clearing the research queue, and restoring it after the warp.

The invariant to get right is units. saved_progress is a 0–1 fraction in Factorio 2.1, while LuaTechnology.research_unit_count is a unit count and LuaForce.research_progress is a fraction. You cannot mix them. Warptorio copies force.research_progress straight in, capped just below completion with math.min(force.research_progress, 0.999999). Do not add unit counts to the fraction. If you adapt this for another Factorio version, check whether saved_progress is a fraction or a unit count there. And do not just clear current_research: that loses progress. saved_progress is the only reliable way to pause research without consuming packs or resetting the bar.

What the clone brush does not copy

Fluids

Fluids are the clearest example. On an Electromagnetic plant running Electrolyte, I have seen electrolyte end up in the holmium solution box and holmium solution in the electrolyte box. It only happens after a warp, when one pipe is empty and the other has fluid, and the cloned building is rotated once compared to a normal placement. I hit it several times on both 2.0 and 2.1, roughly every hour of play, a year apart, so it is not a version regression.

Other players reported the same swap, and at the time the maintainer had no fix and suggested pumps. The theory that fits: placement rotates the building after the pipes and fluid exist, and fluid spreads instantly, so the contents equalize.

The 0.4.4 approach snapshots each fluid box by relative position before the clone brush runs, then restores exactly one copy after the platform clone is complete. The key is position rounded to 0.1 tile relative to the surface offset, so it covers any fluid-bearing entity. The rotation theory is still the best explanation, not a proven fact.

Trains

Trains warp between the ground platform, the factory floor, and the garden floor. The garden is Warptorio’s optional biochamber area. Several details matter:

  • Fluid trains keep their 1:1 pump/wagon alignment.
  • The destination track is checked before the train moves.
  • Trains bound for the ground floor during a warp are queued and retried, so they do not arrive on a floor that is being replaced.
  • A full destination station used to leave a train stopped with no self-recovery; the retry system now re-queues it.
  • Garden-floor warps warn if the required garden technology is missing.
  • Remote drivers are kicked out of remote view.
  • Physical riders still block the warp.

Before 0.4.4, ground-floor trains could come back from a clone in manual mode, usually unnoticed until a train quietly stopped late in a run. Now train.lua snapshots each carriage’s mode, speed, state, schedule index, and schedule records before the clone brush runs, with positions relative to the surface offset. During replacement, ground-bound trains are frozen at zero speed. After the platform clone completes, it matches cloned trains by carriage position with a 1.0 tile tolerance and sends them to their recorded station at their recorded speed. A captured record is consumed once, so two cloned trains cannot claim the same source record; trains that were not waiting at a station resume moving.

The warp flash and trail in the video are rendering objects, so they live in storage. A module-level table would be rebuilt empty when a client loads the save.

A train arriving through the warp. The flash and trail are rendering objects restored from storage, not part of the cloned surface.

Spidertrons

Spidertron remotes live in player quickbars, and after a clone those remotes still point at the old, deleted spidertrons. The obvious restore is to record each spidertron’s position, find the entity at the same position on the destination surface, and overwrite the quickbar remote. That breaks in two places: the remote may select spidertrons on several surfaces, and the saved slot may not be on the visible quickbar page.

So spidertron.lua scans all 10 quickbar pages and every slot up to player.quick_bar_width, the number of slots in a quickbar row. For each remote it splits the selection into spidertrons that were not on the source platform and must stay selected, and relative positions of spidertrons that should be replaced by clones on the destination. The nearest clone inside a 1.5 tile radius wins. The final write is wrapped in pcall so one rejected slot cannot abort the rest, and the filter quality defaults to "normal" because quickbar remote filters are quality-aware.

Teleport effects

The player teleport effect was ported from the Ultracube mod under GPLv3. It uses a three-layer glow blast, sixteen shockwave rings, a spark burst, and a delayed boom. It is short-lived on purpose: the effect should read as an event, not leave permanent rendering objects behind.

The floor pads also charge before firing, with a progress bar above the player. The delay prevents instant teleportation and accidental pad triggers and is configurable with the warptorio_teleport-delay startup setting. The bar is not a GUI element; it is a string of filled and empty block characters drawn in the world above the player, so it follows them.

The charge delay and its on-screen bar. It is drawn in the world, not as a GUI, so it moves with the player.

Multiplayer is where the state bugs show up

Warptorio is often played on servers, so state consistency matters more than visual polish.

Votes are the first place it shows. New players and AFK players can no longer skew a warp vote. The defaults are one hour of playtime and five minutes of AFK. Admins bypass eligibility, and an admin warp is a shift-double-click within one second. A disconnect cleans the player’s vote, and a failed warp resets stale vote state.

A passed vote starts a five-second countdown rather than warping immediately, drawn on every active floor. On the first planet, a chat warning fires 60 seconds before the Nauvis time limit forces a warp, and the timer changes color as time runs out. These are small things, but they are the difference between a server arguing about a warp and a server understanding one.

GUIs and constant combinators are expensive when written every tick, so the 0.4.4 pass writes GUI labels only when the value changes, uses a state key for the warp combinator, caches per-entity combinator slots and platform pad shapes, and removes dead tile stamps.

The warp combinator uses fixed slots:

Slot Signal Meaning
1 T Time before forced warp
2 W Wave count
3 V Time before next wave
4 A Warp count
5 J 1 while warping
6 D Seconds left in transition
7 Current planet Planet signal
8 Next planet Planet signal

Fixed slots matter. Indexing off #parameters allowed the next planet to slide into the current planet slot when the current signal was absent. That changed what a slot meant and left stale values behind. The update path also avoids writing 60 times per second: it builds a state key from remaining time, wave index, wave time, warp count, transition state, and current/next planet, and returns early if the key is unchanged. Each combinator then has a per-slot cache, so even a real update only writes slots whose type:name:count key changed.

Minimap, speech bubbles, and an events API

The normal character minimap is not useful while you are inside the factory or garden floor, because those are separate surfaces. modules/minimap.lua replaces it with a pinned view of the ground platform. It hides the built-in minimap while you are on an interior floor, restores the previous setting when you leave, and keeps the frame pinned when resolution or UI scale changes. Scroll-wheel and zoom shortcuts adjust the scale, a shortcut toggle and the warptorio-ground-minimap runtime-per-user setting let players disable it, and clicking the minimap switches to remote view on the ground surface. The zoom factor and toggle state are keyed by player index in storage, so they survive a save and stay per-player.

M.chart handles chart reveal. It calls force.chart around the platform center, then expands the radius to the platform radius plus boss_reveal (340 tiles). Without that, the enlarged boss dots and skull tags stay off-chart until the boss is already at the platform.

Warptorio also uses Factorio’s speech-bubble entity for short feedback that belongs on the player or train rather than in chat. The source field is what makes the bubble follow the character or train instead of staying at a fixed world position. Bubbles cover warp and teleport rejections, cooldowns, missing tech, platform animation, already-voted feedback, vehicle teleport blocks, roboport blocking, container and collector placement, and train warp warnings. If a player has no character, notify falls back to game.print; colored errors keep their color.

The release adds eight custom events. They are registered as data-stage custom-event prototypes, so other mods do not need a specific load order. At runtime, events.raise looks up defines.events[name] and calls script.raise_event. Subscribing is just script.on_event, with no remote call and no load-order handshake:

local warp_finished = defines.events["warptorio-warp-finished"]
if warp_finished then
  script.on_event(warp_finished, function(event)
    game.print("Arrived on " .. event.surface)
  end)
end

If your mod works without Warptorio, guard the lookup: the event ID is nil when the mod is absent.

The eight events are warptorio-warp-started, warptorio-warp-finished, warptorio-planet-chosen, warptorio-wave-spawned, warptorio-boss-spawned, warptorio-boss-died, warptorio-game-over, and warptorio-game-win. Surface fields are surface name strings, not LuaSurface objects, so event.surface is safe to concatenate. get_events returns a plain array of names for discovery; the order is not guaranteed because it is collected from a table. The implementation lives in modules/events.lua and shared.lua.

Smaller fixes that still matter

Nukes no longer create lava tiles. Warp cleanup restores frozen-* tiles and replaces lava with the ground tile. Garden floor tiles cannot be mined. Inventory cleanup no longer crashes on a warp container. Repair Turret compatibility was fixed, Krastorio 2 spaced-out compatibility was restored, refined concrete no longer grants a movement speed boost, and water tiles are walkable for players and enemies. The release also adds new platform research: ground 6–8, factory 6–7, infinite reactor, infinite biolab limit, and warp-time-5.

There is also an admin-only /warpcheat panel for testing. It can force a warp, set the next planet, clean or repair the platform, pause waves, spawn a boss wave, and toggle teleporter-zone visualization.

Warptorio warpcheat admin panel with navigation, platform, research, wave, and container controls
The admin-only warpcheat panel used for development testing. It exists because testing a warp loop by hand is not realistic.

Release notes

Warptorio 0.4.4 is the merged release. The source history contains intermediate version numbers from the edge branch, but those were development iterations, not separate releases.

If you are upgrading a save, test it on a copy first. This release touches boss prototypes, platform construction, research state, train routing, and fluid handling. It is not a drop-in patch for a heavily modded base.

Why this release matters

0.4.4 is less about one headline feature than about making the warp loop trustworthy. Surface cloning is only one part of the problem. The hard part is coordinating every subsystem that points at the cloned world, then proving that each one still works after the move.

If you play Warptorio on a server, the most useful feedback right now is a save and a description of what looked wrong after a warp: a train that lost its schedule, a fluid box with the wrong amount, a circuit network that came back disconnected. Those reports are how the next batch of edge cases gets found. The repository is the place for issues, and the mod portal is where the release is.

FAQ

What is Warptorio?

Warptorio is a Factorio Space Age mod where your entire factory sits on a platform that jumps between planets. Version 0.4.4 is the release that merged the edge branch into one version.

Why do bosses need separate prototypes?

The prototype's maximum health cannot be reliably scaled on an individual runtime entity, especially with quality variants. Warptorio creates enlarged boss prototypes at the data stage so health scaling and map visibility work reliably.

How do other mods subscribe to Warptorio events?

Warptorio defines eight custom events as data-stage custom-event prototypes. Other mods look up defines.events[name], skip it when nil, and subscribe with script.on_event; no load-order handshake or remote call is needed.

Why does the platform rebuild gradually?

Platform expansion is a queued animation system. New tiles are revealed as their build animations finish, which keeps large upgrades smooth and avoids freezing the warp engine on a single tile stamp.

What happens to trains during a warp?

Ground-bound trains are frozen before the clone. After the clone, Warptorio restores their mode, speed, schedule, and state, then lets moving trains continue at their previous speed.

How does Warptorio preserve fluid contents?

It snapshots each fluid box by relative position, empties the source boxes, clones the platform, and restores exactly one copy. That keeps the clone from rebalancing or duplicating fluid contents.

Does Warptorio 0.4.4 support multiplayer?

Yes. Votes exclude new and AFK players, remote drivers leave remote view before a warp, and GUI, combinator, and minimap state are stored per player.

COMMENTS

GitHub sign-in required. Keep it useful.