Skip to main content

Simulator reference

The simulator runs game engine behavior headlessly under a Lua driver, with a staged world and observable infrastructure boundaries. Use it to test scenarios, compare behavior, and calibrate outcomes; the simulator foundations describe its design.

Glossary​

  • Driver: the Lua script that stages a world and acts on it.
  • Cube: a driver script of faces that assert a specification and end in a verdict.
  • Face: one scenario inside a cube; a failing face does not stop the others.
  • Forge: a Lua module the server loads at boot and keeps for the whole process; see How Forge modules work. Its tables are reached through forge.sys.game.*.
  • Differential gate: a comparison of two recorded runs, classified against declared expectations.
  • Boundary: the simulated edge to network, database, disk and clock.

The engine is private.

Running cubes​

Use the cube runner with cube names to select runs. With no names, it runs the cubes in its table. --jobs N sets the number of parallel jobs; --kill-orphans requests termination of existing simulator processes. Identify those processes before using the flag: it kills them forcefully.

The runner returns:

Exit codeMeaning
0At least one cube passed, and none failed or lacked a verdict.
1A cube failed.
2A name is unknown, a cube is missing or has no verdict, no work was selected, or staging failed.
3Existing simulator processes were found, or survived the requested orphan kill.

Read each cube's verdict and failure lines from its output. The runner records the process exit code, but classifies the cube by its output. A driver error also produces a process-level exit code of 1; that is distinct from the runner's aggregate exit code.

Cube shape​

A cube groups assertions into faces. Each face runs under pcall, so a failure is recorded and the remaining faces can run. Prove that the setup is live before checking its result, and include a negative control.

A cube is one Lua file with four parts: a header that lists the faces, the fixtures and the run line; two helpers, check (raises on a false condition) and test (runs a face under pcall and records it); the faces; and the verdict lines. Nothing in the engine asserts for you, the cube carries its own helpers.

local T = { pass = 0, fail = 0, notes = {} }

local function check(cond, msg)
if cond then T.pass = T.pass + 1 else error("CHECK FAILED: " .. msg, 2) end
end

local function test(name, fn)
local ok, err = pcall(fn)
if ok then
T.notes[#T.notes + 1] = "ok " .. name
else
T.fail = T.fail + 1
T.notes[#T.notes + 1] = string.format("FAIL %-56s %s", name, tostring(err))
end
end

test("A1 the setup is live", function()
local vid = sim.spawn_pc({ job = "warrior", level = 30, x = 24000, y = 25600 })
check(vid ~= nil and vid > 0, "spawn_pc must return a live vid")
end)

for _, line in ipairs(T.notes) do print(line) end
print("")
print(string.format(" checks passed: %d tests failed: %d", T.pass, T.fail))
print(T.fail == 0 and " SKELETON FACES A1-A1 SOLVED" or " CUBE INCOMPLETE")

Start the file with a comment that lists each face on one line, the fixtures it loads, and the command that runs it. A binding that returns nothing is read back through its getter; never wrap it in check.

Verdict rules​

Who prints what:

SourceFinal line
A cube<NAME> FACES a-b SOLVED, or CUBE INCOMPLETE
A unit script<NAME>_OK or <NAME>_FAILED
Eitherchecks passed: N tests failed: N, and one FAIL line per failed face

The runner reads the output and applies these rules in order; the first match wins. The process exit code is not part of the verdict, because each face runs under pcall.

OrderConditionVerdict
1Last token is CUBE INCOMPLETE or _FAILED, or tests failed: N with N not 0, or any FAIL lineFAIL
2Last token is SOLVED or _OK, or tests failed: 0PASS
3None of the aboveNO VERDICT

Failure beats success: a cube that prints SOLVED after a FAIL line still fails.

Compare the check count with the last run. A passing verdict with fewer checks may mean that a face or assertion no longer runs.

Binding areas​

The simulator registers more than 200 bindings under sim. This table is an index of areas and names.

AreaNames
World and lifecycleseed, step, reset, fork_scenario, child_exit, timeline, report, bench, pulse, log, map_index, leak_check, kill, destroy (removes the PC, the logout), sync, set_event_flag, set_quest_flag, quest_flag
PC and partyspawn_pc, pc_pos, pc_place, pc_hp, pc_att, set_empire, party_enable, party_join, party_link, party_guild_group, party_alive
Combat and observationattack, cast_skill, use_skill, client_hit, mob_skill, mob_skill_info, shoot, affects, points, point, flags, skill_state, can_target
Guild and empireguild_create, guild_join, guild_set_name, guild_set_skill, guild_gold, guild_war, empire_gold, intracore_deliver
Footprint, land, and deploymentfootprint_new, footprint_apply, footprint_cells, land_register, land_grid, land_apply_cell, land_apply_land, land_land, deploy_proto_load, deploy_apply, deploy_get, deploy_process, unit_apply, unit_get
Map, movement, and assetsmap_block_of, map_watch, map_request, input_split_probe, asset_png, asset_upload, client_move, route_search, route_stats
Gates and passagegate_open, gate_close, gate_state; passage also provides canvas and survey functions
Spectatorspectator_camera, spectator_cycle, spectator_invalidate, spectator_state, spectator_metrics
Wire and DBcapture, packets, client_message, peer_deliver, peer_message, db_on, db_insert, db_put, db_delete, db_get, db_rows, db_forward, db_deliver, db_log, db_stats
Codecstruct_define, struct_size, struct_encode, struct_decode
Forge and questquest_boot, quest_login, forge_has_processor, quest_info
Real linksdb_linked, db_link_stats, db_link_pump, db_link_drop, db_send, peer_count, p2p_send, p2p_stats
Records and timebg_open, bg_close, bg_probe, bg_note, data_dir, advance_time

Selected contracts:

BindingBehavior
sim.step([pulses = 1])Drives pulses and returns no Lua values. It does not advance global time.
sim.advance_time(seconds)Advances global time and drives each second's pulses. Negative input raises an error.
sim.spawn_pc{ x=, y=, job= \| player_file=, ... }Spawns a PC and returns its VID. Options include map, immortal, bonuses, items, skill, buff, and hp.
sim.destroy(vid)Removes the PC, which is the simulator's logout. Returns false when the VID is unknown.
sim.set_empire(vid, empire)Sets and returns the resulting empire integer.
sim.party_enable(boolean)Sets and returns whether party admission is enabled.
sim.party_join(leader_vid, guest_vid)Resolves the party join policy and the common admission condition, then admits directly. Returns a numeric party admission error. It does not replay the invite dialog or acceptance path.
sim.quest_boot()Returns boot_init_ok, boot_ok. A false boot-event return can mean no quest handled the event.
sim.quest_login(vid)Establishes the quest-loaded state required for PC quest events.
sim.forge_has_processor(ns, header[, kind])Checks for a registered processor. Kind 1 selects peer processors.
sim.fork_scenario()Returns true in the child, allowing a scenario to run in an isolated process.
sim.child_exit()Flushes output and exits the child.
sim.client_message(vid, ns, header[, payload[, client_handler]]) -> boolDelivers a Luna client message. It does not carry the legacy party invite packet.
sim.peer_message(peer, ns, header, payload, receipt)Invokes the peer processor path.
sim.packetsReads captured packets; the DB capture cannot be drained while the in-process DB is open.
sim.captureControls packet capture at the simulated boundary.

Real and simulated boundaries​

AreaReal behaviorSimulated or selected boundary
GameEngine managers, rules, quest VM, and game entry pointsA Lua driver stages the world and drives the scenario.
TimeEngine events and character updatesThe driver advances pulses and global time separately.
NetworkPacket handling and engine writesCaptured buffers are the default; real DB and peer links are optional.
DatabaseGameplay issues serialized requestsAn in-process DB supplies configured answers, or a real headless DB link can be used.
ContentForge artifacts, quest objects, and protosThe driver chooses and stages the data.

A staged world proves behavior under that setup. It does not by itself prove that the setup represents a live world.

Harness families​

A differential gate starts with a manifest; the probe runner resets and stages each probe and emits records that a diff classifies. Keep fixture identity, build flavor and manifest order consistent across comparable runs, because the pulse count accumulates across resets. A cube states expected behavior as assertions and prints a verdict; see Write and run a cube. Calibration tunes toward an objective rather than comparing two records. The foundations explain why each exists.

C++ registration​

The bindings are registered natively in C++. A cube uses the registered table; it does not register these bindings in Lua.

RegistrarArea
Main simulator tableWorld, lifecycle, characters, combat, time, and other simulator operations
WirePacket capture and message delivery
DatabaseSimulated DB operations
CodecStructure definition and encoding
PassagePassage, canvas, and survey operations

Pitfalls​

A probe passes without measuring the behavior. Missing SP, an uncast buff, the wrong skill class, an untriggered condition, or a damage floor can produce plausible observations. Assert the preconditions and use the probe's liveness check.

PC quest events never reach Lua. A spawned PC needs quest-loaded state. Call sim.quest_login(vid) before testing its quest events.

A Forge table exists but its processor is absent. A forge can have a game artifact and a quest object, and some processors register only through the quest object at boot. Stage both the compiled Forge artifact and quest object, call sim.quest_boot(), and check sim.forge_has_processor.

A cooldown never expires. sim.step drives pulses without moving global time. Use sim.advance_time for a gate based on global time.

An affect-duration assertion has an unexpected result. Affect durations tick once per second through the engine's own affect event as live; keep a control probe that reads the rate beside anything that depends on a duration.

A successful land update fails its check. sim.land_apply_land returns no value. Read the applied state back with sim.land_land and assert on that.

DB packet capture refuses to drain. The in-process DB needs the captured messages to answer requests. Inspect DB statistics and logs instead.

A real DB link fails while the DB double is enabled. Capturing an armed DB descriptor can swallow the socket handshake. Use the in-process DB or the real DB link, not both.

A linked DB does not respond after stepping pulses. Pulses do not wait for real socket I/O. Use sim.db_link_pump(ms) to pump the linked DB.

An observation uses a stale character. A character can be destroyed after death. Resolve it by VID each time you need it.

Point traversal stops early. The points table omits zero entries, so gaps can truncate array traversal. Use the named point accessor or deliberate numeric indices.

A received-message count passes for the wrong message. An unrelated DB or peer message can increment the generic count. Check the expected header in by_header.

A party admission test claims to cover an invite. sim.party_join exercises direct admission and its policy checks, but bypasses the invite and acceptance handlers. Drive and observe those handlers when the full invite path is the behavior under test.

See also​