OpenCiv3 Documentation

repository·Development·Indexed 20 days ago

https://github.com/c7-game/openciv3

An open-source, mod-oriented remake of Civilization III built with Godot and C#. The project includes the C7 Engine for gameplay mechanics, C7GameData for state management, and specialized libraries such as QueryCiv3 for parsing .SAV and .BIQ files, ConvertCiv3Media for processing PCX and FLC media, and Blast for decompression. It features a directory-based game mode loading system supporting rulesets, textures, and behaviors with addon layering.

Tokens
4.3K
Snippets
15
Records
31
Agent score
68%

What's inside OpenCiv3

  1. Overview of QueryCiv3

    Development

    QueryCiv3 is a C# assembly used to parse Civilization III .SAV (Save) or .BIQ (Scenario) files. It works by identifying the offsets of 4-character section headers (such as GAME, TILE, or CITY) and allowing you to retrieve specific data from the file stream based on those offsets.

    Security Note: The classes SaveData, BicData, and Civ3File do not support direct file path constructors. This is an intentional design choice to prevent unintended system access when these classes are exposed to user-made Lua scripts.

  2. Overview of OpenCiv3 repository structure

    Development

    The repository is organized into several specialized subfolders that handle core engine logic, game data, and legacy Civ3 compatibility:

    • C7: The core game running on the Godot engine.
    • C7Engine: Contains game mechanics and AI logic.
    • C7GameData: Stores native game data (intended for disk persistence).
    • EngineTests: Contains tests for the engine logic.
    • Blast: An Apache-2.0 library for decompressing PKWare DCL (used by QueryCiv3 for Civ3 BIQ and SAV files).
    • ConvertCiv3Media: A library for reading images and animations from Civilization III.
    • QueryCiv3: A data reader for Civ3 BIQ and SAV files that fetches data based on offsets from labeled section headers.
  3. Overview of Blast implementation

    Development
    Blast is a compression algorithm implementation included in this repository. The code is a port/copy of the implementation found in the James Telfer repository. It is based on an original algorithm by PKWare and a C implementation found within the ZLib source tree.
  4. Project structure overview

    Development

    The repository contains the following key components:

    • Fonts/: Contains the font files used for text rendering in Godot.
    • main_menu.tscn & MainMenu.cs: The primary startup scene and the logic for the main menu.
    • C7Game.tscn & Game.cs: An early prototype map view that can be accessed via the main menu.
  5. Use ReadCiv3Data.ConvertCiv3Media to convert Civ3 media

    Development
    The ReadCiv3Data.ConvertCiv3Media class library is used to convert Civilization III media formats (PCX and FLC) into palette and image byte arrays. These arrays are designed to be easily translatable into other image formats such as PNG, Godot textures, or Unity textures.
  6. Understand the C7 Game Data architecture

    Development

    The C7GameData namespace serves as the master copy of the game state. It is designed to store all top-level game objects and their sub-objects, such as units, maps, and cities.

    Data Flow Model:

    • The UI interacts with the C7 Engine.
    • The C7 Engine is responsible for reading from and updating the C7 Game Data.
    • C7 Game Data acts as the single source of truth for the current state of the game.
  7. How game mode loading and composition works

    Development

    OpenCiv3 uses a directory-based loading scheme where a playable scenario (a "game mode") is composed of three components: a ruleset, textures, and behaviors.

    A game mode is defined by a base directory and zero or more "addon" directories layered on top. This layering is applied uniformly across all three components:

    1. Base Loading: The engine loads the base directory. For rulesets, it looks for ruleset.json first, then ruleset.lua (which must evaluate to a table). For textures and behaviors, it loads textures.lua and behaviors.lua respectively.
    2. Addon Layering: For each directory in the addonPaths list, the engine looks for a matching script. Addon scripts must return a function with the signature table -> table. This function is called with the current state of the component, and its return value becomes the new state.
    3. Finalization: The composed ruleset is converted to JSON for SaveGame compatibility, while textures and behaviors remain as Lua tables for the BehaviorEngine and texture loader.

    This allows addons to be incremental, composable transforms that only need to provide the specific scripts they intend to modify.

    -- Example of an addon ruleset.lua
    return function(civ3_ruleset)
      -- ...mutate civ3_ruleset...
      return civ3_ruleset
    end
  8. Use EntryPoints to invoke engine methods

    Development
    To interact with the C7 Engine from the game or UI, use the methods located in the EntryPoints folder. This folder is specifically designated as the public interface for the engine, separating high-level invocations from the engine's internal helper methods and complex calculations.
  9. Understand the C7 Engine architecture

    Development

    The C7 Engine serves as the core gameplay mechanic layer of the project. It is designed to be decoupled from the UI and the game data to facilitate maintenance and potential networking implementations.

    • UI (C7 folder): Invokes engine methods when a player takes an action.
    • C7 Engine: Processes actions, updates the game state, and returns results (e.g., combat outcomes).
    • C7 Game Data: Stores the actual state of the game and is interacted with by the engine.
  10. Configure JetBrains Rider for OpenCiv3 development

    Development

    Rider provides strong C# support and Godot integration.

    1. Install JetBrains Rider.
    2. Install the Godot Support plugin.
    3. Open the solution file at C7/C7.sln.
    4. Create a Godot 4 .NET Executable run configuration. This configuration must point to your local Godot executable and the C7 project directory.
  11. Configure the CIV3_HOME environment variable

    Development

    OpenCiv3 requires access to Civilization III game files.

    • Windows (64-bit): The application automatically retrieves the installation folder from the Windows registry.
    • macOS/Linux: You must manually provide the path to your Civilization III installation by setting the CIV3_HOME environment variable to the top-level installation folder. If using the Steam version, this folder is typically named Sid Meier's Civilization III Complete.

    After setting the variable, launch Godot Mono from the same terminal session.

    export CIV3_HOME=/path/to/civ3