Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

AutoForge

a WFC demonstrator project that revolves around a factory that rebuilds itself while maintaining production. The player rebuilds a crawler carrying a salvage factory across the salt flats. Each settlement needs a different combination of products. The factory travels with its inventory, upgrades and scars; the player decides how it evolves.

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

AutoForge · The Roaming Foundry

Play in your browser · Build and deployment

A factory on wheels, making useful things for the towns along a broken road. Mend the deck, route material lines, relocate machinery and deliver orders. Spend carefully, earn upgrades, and keep your cargo through every refit.

Castle Game Engine is the game framework. Its browser WebAssembly target renders the 3D crawler, procedural machinery, lighting, camera and moving cargo. Pascal compiled with pas2js runs the campaign, integer simulation, independent validation and WFC workers. The phone interface is a compact HTML overlay. GitHub Actions builds the browser game and publishes successful main pushes to GitHub Pages. There are no native application targets.

Play

  • Choose Learn with the crew for hands-on practice, or take the wheel. Salvage Radio starts with either gesture when checked. ? and the menu reopen practice; leaving restores your journey, cargo, edits and repair plan.
  • Each stop needs its delivery and a crew readiness drill. Choose Spill test and tap a colored line, or use Drop a test crate for a guided target.
  • Red marks the blocked feed and its receiving machine. Plot a detour shows the green replacement without changing cargo or spending scrap. Build with Send repair crew for 3 scrap, or discard for free. Salvage removes wreckage for 2 scrap. Survey explains a machine; Beacon guides a route; Crane lifts a machine into a new bay.
  • Fire up the foundry to finish the order. Undo refunds unbuilt edits.
  • Ship gears, then unlock copper, wire, circuits, steel and motor production.
  • Choose scrap or a machine tune-up after each delivery. Later stops unlock module moves; Beacon is available immediately. Storms damage the working deck.
  • Drag to pan, pinch to zoom, or use + / − / fit. On a focused deck, arrow keys select a tile and Enter applies your tool. Menu contains help, radio volume, restart and credits. Progress and in-flight cargo save on this device.
  • Crew and machinery effects have separate volume and mute controls in the menu. Crate impacts, salvage, construction, engine starts and deliveries give audible feedback; deck action badges and shipment flashes also work muted.

Five authored town contracts lead into continuing convoy orders. The 25×15 shared deck supports ten modules, nine materials and fourteen directed links. Open ♫ for the animated boombox: Neon Circuit (electronic), Insert Coin (arcade), Low Orbit (ambient), and Salvage Gold (ragtime). The new stations rotate pairs from fourteen credited CC0 MIDI scores into merged four-voice WFC ensembles; Gold keeps the two public-domain Joplin editions. Track details, live spectrum, next mix, presets and volume are on the receiver. New 24-bar mixes follow continuously (45–72 seconds depending on tempo). Phrases may repeat. Learning sources and authored synthesis are distinguished in the credits.

Roadside Mixtape → Load a found tape imports your own MIDI song. Choose a deck sound, then Play recovered mix to hear continuing variations. The tape stays in memory for this tab; Eject or reload forgets it. No song is uploaded. See supported files and learning details.

Build and run

For contributors, agents and LLMs, read the coding guide before expanding the game. It covers Delphi mode, naming, formatting, WFC comments, licensing and compatibility.

For automatic builds and Pages deployment, see publishing.

powershell
git submodule update --init --recursive

Provide FPC 3.3.1 with its wasm32-wasip1 compiler/RTL and a configured pas2js 3.3.1 installation on PATH. Build the pinned CGE build tool using its tools/build-tool/castle-engine_compile.ps1 (from that directory), or set CASTLE_TOOL to a compatible build tool executable. Then:

powershell
./build-web.ps1
node tools/serve.mjs

Open http://localhost:4186. The distributable is build/web/, a static site. Node is only an optional development host. Game resources and fonts need no external CDN. WebGL 2 and WebAssembly are required.

The build accepts -Compiler, -RtlRoot, -RuntimeJs, -CompilerOptions, -CastleTool and -Mode debug|release. Environment equivalents include PAS2JS, PAS2JS_RTL, PAS2JS_RUNTIME and CASTLE_TOOL. CGE must also find a configured pas2js on PATH. Use -SkipWorld for application-only iterations after a successful full build.

CGE exceeds the address space of some 32-bit-host WASM compilers. Use a compiler with a 64-bit host. On Windows, tools/build-wasm-compiler.ps1 can build one from your existing FPC source, Win64 cross-compiler and configuration: supply -FpcSource, -Win64Compiler, and -FpcConfig, then prepend the resulting build/toolchain directory to PATH. It writes only ignored project build files. All toolchain locations are supplied by the environment, never embedded in source.

The build excludes unused CGE model importers through official project defines and guards an optional CacheStorage registration in generated JOB glue for Android over LAN HTTP. Neither dependency source tree is modified. It produces a gzip sidecar for the WASM. A small browser loader reads this compressed file on Pages as well as locally, then passes the original bytes to CGE. If the browser cannot decompress it or the sidecar is unavailable, ordinary WASM is the fallback. The initial compressed engine download is about 7 MB. When wasm-opt is on PATH, CGE additionally optimizes release WebAssembly. The Pages workflow currently omits it because the tested Binaryen 132 output failed browser initialization; verify compatibility before enabling it.

Phone on the same Wi-Fi

powershell
$env:HOST = '0.0.0.0'
node tools/serve.mjs

Open http://<computer-LAN-IP>:4186 on your phone. Use HTTPS hosting when sharing beyond your network. Music requires the opening gesture or Play radio in the menu. It pauses when you leave the page; tap Play radio to resume.

Verification

Provide Playwright externally (NODE_PATH can identify an existing installation) and optionally set BROWSER to Chromium. With the server running:

powershell
node tools/test-web.cjs
node tools/test-convoy.cjs
node tools/test-breakdowns.cjs
node tools/test-stations.cjs
node tools/test-radio.cjs
node tools/test-tutorial.cjs
node tools/test-tutorial-entry.cjs
node tools/test-effects.cjs
node tools/test-midi.mjs
node tools/test-mixtape.cjs
node tools/test-mixtape-stream.cjs
node tools/test-wasm-loader.cjs
node tools/render-radio.cjs

The Pascal industry suite is tests/IndustryTests.lpr; build it with ./build-web.ps1 -WithTests and your usual compiler options. tools/test-industry.cjs runs its compiled build/web/IndustryTests.js without a renderer. Browser evidence, screenshots and stereo audio auditions for all stations stay under ignored build/. Run the station test before rendering its generated samples.

See architecture, verification, design and credits. The game demonstrates constraint-driven layout and learned music; it does not establish an optimality or state-of-the-art benchmark claim.