PORTCLUB
Cabecera de Civilization (Civ Demake)
Port nativo

Civilization (Civ Demake)

Port nativo de Civilization (Civ Demake) para PC.

Civilization (Civ Demake)

Port nativo basado en su ficha de origen.

README del repositorio

Civ Demake

A small, from-scratch Civ1-style game for Windows, written in Zig. It keeps the 320x320 indexed-color look, map rules, unit movement, Goto, Settler work, cities, fog, and Civ1 combat behavior in a direct code base.

The game is a work in progress. The present part is fully playable by two local players, but it has no AI, economy, save files, sound, or full city work yet.

What is present

  • An 80x50 world with X wrap and fixed-seed map generation.
  • Terrain, coasts, rivers, resources, huts, roads, railroads, mines, irrigation, pollution, fortresses, cities, and fog.
  • All 28 Civ1 unit types, stable unit slots, movement, Goto, work orders, stacks, veteran units, Barbarians, and nuclear effects.
  • Combat rules checked against the original Win16 game.
  • A 320x320, 8-bit indexed framebuffer in a 960x960 native Windows window.
  • Water motion through palette cycling.
  • Unit movement, attack, death-burst, path, and selection-blink pictures.
  • Headless map-dump, PNG-shot, improvement, and unit test modes.

Build

The main target is Windows x86-64. Use Zig 0.17.0-dev.1441+d5181a9c9. Python is needed for the atlas build.

$zig = 'C:\zig-x86_64-windows-0.17.0-dev.1441+d5181a9c9\zig.exe'

& $zig build
& $zig build test
& $zig build -Doptimize=ReleaseSafe test
& $zig build -Doptimize=ReleaseFast

zig build puts civ.exe and atlas.bin in zig-out/bin. ReleaseFast is the small, fast production build.

Run

& $zig build run --
& $zig build run -- 0xDEADBEEF
& $zig build run -- --dump 0xC1DE1234
& $zig build run -- --shot shot.png 0xC1DE1234
& $zig build run -- --improvements-demo
& $zig build run -- --units-demo

zig build run -- first makes the program when needed and then runs it. Text after -- is sent to civ.exe.

Keys

KeyAct
Arrows, WASD, numpadMove the selected unit, or the map cursor
SpaceSelect the active player's unit under the cursor
G, then GStart Goto and set its end tile
EnterEnd the player turn
RMake a road or railroad
IMake irrigation
MMake a mine
KClean pollution
BMake a city
FMake a fortress
F10Open the unit-add menu
F11Write the map dump
F12Make a new world and reset the date

Only unit movement makes more fog tiles known.

Technical design

The game uses a direct set of small modules. There is no ECS, event bus, general render backend, or console layer.

  • World owns terrain, resources, huts, fog, improvements, regions, cities, and units.
  • MapgenScratch owns all temporary map-generation memory.
  • Pathfinder owns one shared Dial-bucket search and route.
  • Game owns players, money, turn, date, and difficulty state.
  • App owns the camera, selection, input modes, and short picture state.
  • Renderer owns the indexed framebuffer and palette. It has no Win32 calls.
  • Host owns the Win32 window, DIB, key state, clicks, and frame wait.
  • main.zig joins CLI work, headless modes, the app, and the native host.

Normal frame, update, and render work takes no allocator. Main fixed-size limits are checked at compile time: World <= 24 KiB, Pathfinder <= 8 KiB, MapgenScratch <= 128 KiB, City == 5 bytes, and Unit == 7 bytes.

Code hierarchy

This is both a code map and a dependency guide. Arrows point from a higher-level part to the lower-level part it uses.

flowchart TD
    build["build.zig<br/>build, tests, atlas step"]
    main["main.zig<br/>CLI and main loop"]
    host["host.zig<br/>Win32 host"]
    root["root.zig<br/>game module"]
    app["app.zig<br/>camera, input, modes"]

    subgraph rules["Game rules and world"]
        game["game.zig<br/>turns, dates, players"]
        unit["unit.zig<br/>movement, work, combat"]
        path["path.zig<br/>Dial-bucket routes"]
        mapgen["mapgen.zig<br/>world generation"]
        world["world.zig<br/>map and entities"]
        rng["rng.zig<br/>fixed RNG"]
        common["common.zig<br/>types and map rules"]
    end

    subgraph view["Indexed view and files"]
        render["render.zig<br/>pure 8-bit renderer"]
        atlas["atlas.zig<br/>named sprite access"]
        asset["asset.zig<br/>ATL1 loader"]
        font["font.zig<br/>8x8 text"]
        png["png.zig<br/>PNG writer"]
    end

    subgraph art["Build-time art"]
        manifest["assets/atlas.json<br/>layout source"]
        sheets["assets/atlas/*.png<br/>seven indexed sheets"]
        encoder["tools/encode_atlas.py"]
        output["atlas.bin + generated Zig layout"]
    end

    build --> main
    build --> encoder
    main --> host
    main --> root
    root --> app
    root --> rules
    root --> view

    app --> game
    app --> unit
    app --> path
    app --> world
    app --> render

    unit --> game
    unit --> path
    unit --> world
    unit --> rng
    mapgen --> world
    mapgen --> rng
    path --> world
    world --> common

    render --> atlas
    render --> asset
    render --> font
    render --> game
    render --> path
    render --> unit
    render --> world

    manifest --> encoder
    sheets --> encoder
    encoder --> output
    output --> atlas
    output --> asset

Source tree

PathPurpose
src/Game, render, platform, file, and in-module test code
assets/atlas/Seven logical indexed PNG sheets
assets/atlas.jsonSprite names, grids, sizes, and packing order
tools/Atlas import/build and font-data tools
docs/Map-generation and atlas reference notes
SPR32X32.pngOriginal art oracle; not read by a normal build
HANDOFF.mdCurrent state, hashes, and work notes

The normal build joins the seven source sheets into one compact ATL1 file and makes a Zig sprite layout from the same JSON manifest. Hand-written Zig has no packed atlas coordinates. The game loads only atlas.bin at run time.

Lines of code

Measured on 2026-07-22. LoC here means non-empty physical lines, with comments and in-module tests included. Blank lines are not included. Generated src/font_data.zig is shown on its own and is not in the hand-written total.

PartFilesLoC
Hand-written Zig in src/162,970
Zig build code148
Python tools3304
Hand-written total203,322
Generated Zig font data1100

There are 27 Zig test blocks. They live next to the code they check and run with zig build test.

More detail

Comentarios (0)

Inicia sesión para dejar un comentario.

Sé el primero en comentar sobre este juego.