README.md

Scheme Logistics Game — scaffold #

A small R7RS Scheme + raylib scaffold for a transport/economy/build-out simulation.

Every subsystem is an R7RS define-library with an explicit import/export boundary. src/core/ knows nothing about raylib; rendering and input live under src/platform/.

Current vertical slice #

  • deterministic terrain with water, coasts, plains, forests, hills, mountains and rivers
  • cities, towns, farms, mines, factories and ports
  • code-native site icons, rail tracks, moving trains and ships
  • goods with logistics properties such as bulk, liquid, perishable, refrigerated, fragile, hazardous
  • simple city consumption and industry production
  • simple shortage pressure and population growth/decline
  • capacity-limited automatic freight across built infrastructure
  • freight revenue based on delivered quantity and each good's base price
  • per-day rail maintenance that increases with squared route distance
  • one vehicle dispatched per connection per day, moving at a fixed distance per day
  • freight-revenue batches paid only when their vehicle arrives
  • rail and sea connections
  • graph routing helper (shortest distance over compatible modes)
  • raylib map renderer
  • three hand-authored challenge maps with population targets and deadlines
  • pause / single-step controls
  • drag from one site to another to build a rail connection
  • headless smoke test for the simulation

This is deliberately not yet a full train simulator. A connection currently represents available infrastructure; individual trains, consists, schedules, terminal capacity and cargo assignment belong in the next layer.

Nix development environment #

The repository includes a flake and .envrc. The flake owns CHICKEN, raylib, the raylib egg, and the R7RS compatibility egg required by the pinned CHICKEN 5.4 toolchain. You do not need to install CHICKEN eggs globally.

With direnv:

direnv allow

Or directly:

nix develop

Inside the development shell:

make run
make test
make build
make icons
make challenge-editor
make format
make format-check

make build produces build/scheme-logistics-game. make icons produces build/icon-catalog.svg.

Formatting and pre-commit #

The development shell pins all formatting tools. Scheme files are formatted by the lightweight schemat executable; Nix files are formatted by nixfmt.

Format the tree or verify that it is already formatted with:

make format
make format-check

Install the repository's local, offline pre-commit hooks once per clone:

make hooks

The hooks autoformat staged Scheme and Nix files before a commit. If a hook changes a file, inspect and stage the formatted result, then commit again. The configuration uses only tools from the Nix development shell; it does not download hook environments.

Complete Nix build #

Build the game and run the complete R7RS test suite as part of the derivation:

nix build

The result is available as:

./result/bin/scheme-logistics-game

You can also build-and-run in one command:

nix run

And evaluate the flake checks with:

nix flake check

The default package contains the compiled game and its compiled R7RS libraries. All eggs are provided by pinned nixpkgs inputs, so the package build does not call chicken-install or access the network.

For an interpreted debug run, compile the project libraries once and then run the ordinary R7RS program directly. Direnv exposes build/modules as CHICKEN's project library repository:

make libraries
csi -R r7rs -s src/main.scm

The interpreted run displays an FPS counter; compiled builds omit it.

Non-Nix setup #

Outside Nix, CHICKEN 5 requires both the r7rs and raylib eggs. CHICKEN 6 has R7RS support built into core, but raylib must still be available. The raylib egg expects pkg-config --libs raylib to succeed:

chicken-install r7rs raylib
make run

Controls #

  • Space: pause/unpause
  • N: advance one simulation day while paused
  • 1, 2, 3: load one of the authored challenge maps
  • 0: load the procedural sandbox
  • left-drag from one site to another: preview its price and build a rail connection
  • Esc: quit

Layout #

src/
  main.scm                 game loop / composition root
  core/
    model.scm              data constructors/accessors
    goods.scm              cargo definitions and properties
    generator.scm          deterministic world generator
    terrain.scm            deterministic terrain generator
    economy.scm            production, consumption, growth
    logistics.scm          capacity-limited automatic freight
    objectives.scm         population-target deadline evaluation
    levels.scm             hand-authored challenge maps
    routing.scm            graph/path helpers
    simulation.scm         world tick orchestration
  platform/
    raylib.scm             rendering + player input

tests/
  *.scm                    simulation, terrain, levels and viability tests

tools/
  generate-icon-catalog.scm  SVG icon review-sheet generator

Intended next systems #

  1. Replace abstract link throughput with individual trains/ships and rolling-stock compatibility.
  2. Introduce cargo lots with origin, destination, age, temperature requirements and value decay.
  3. Add local prices and transport contracts so shortages create profitable routes.
  4. Add terminal capacity/transshipment costs.
  5. Let industries appear/expand/close based on input access, output markets and transport quality.
  6. Add track capacity, directional blocks and junction congestion only once vehicle movement exists.

The core design target is: the economy creates logistics problems, and solving logistics problems reshapes the economy.