Skip to main content

Crate civ_map_generator

Crate civ_map_generator 

Source
Expand description

§Civilization Map Generator

A map generation library for civilization-style strategy games. The algorithm is primarily based on Civilization V with references from Civilization VI.

§Features

  • Dual Hex Orientation: Supports both flat and pointy hex orientations
  • Multiple Map Types: Fractal and Pangaea generation algorithms
  • Complete Game Elements: Terrain, resources, rivers, natural wonders, civilizations, city-states
  • Data-Driven Configuration: JSON-based ruleset system

§Quick Start

use civ_map_generator::{generate_map, map_parameters::{MapParametersBuilder, WorldGrid}, ruleset::Ruleset};

// Create default world grid
let world_grid = WorldGrid::default();

// Build map parameters with custom settings
let map_parameters = MapParametersBuilder::new(world_grid)
    .seed(42)  // Optional: set seed for reproducible maps
    .build();

// Load game rules
let ruleset = Ruleset::default();

// Generate the map
let map = generate_map(&map_parameters, &ruleset);

§Adding Custom Map Types

See How to add a map type for implementation guide.

§Complete Example

For a full-featured example, see Civilization-Remastered.

§Architecture

The library is organized into several key modules:

  • grid: Hexagonal and square grid systems with coordinate transformations
  • map_generator: Map generation algorithms (Fractal, Pangaea)
  • ruleset: Game rule definitions loaded from JSON files
  • tile_map: Map data structure and generation pipeline
  • tile_component: Tile components (terrain, features, resources, etc.)

§Current Limitations

  • Only fractal and pangaea map algorithms are implemented
  • Square grid is not yet supported
  • Some map parameters are hardcoded; JSON ruleset integration is partial

§References

Re-exports§

pub use map_generator::Generator;
pub use map_parameters::MapParameters;
pub use map_parameters::MapParametersBuilder;
pub use ruleset::Ruleset;
pub use tile_map::TileMap;

Modules§

fractal
This module provides functionality for generating and manipulating fractal maps which can be used in games like Civilization.
grid
This module provides various grid implementations and utilities. It includes support for different grid types such as hexagonal and square grids, calculating distances, neighbors, and converting between grid coordinates and offset coordinates.
map_generator
This module defines the Generator trait for map generation and provides common methods for map generators.
map_parameters
This module defines the MapParameters struct that contains all the parameters for generating maps.
nation
ruleset
This module defines the Ruleset struct and its associated methods. It provides functionality to load and manage game rules from a ruleset JSON file, including beliefs, buildings, nations, policies, quests, specialists, technologies, terrain types, base terrains, features, natural wonders, tile improvements, tile resources, units, unit promotions, and unit types.
tile
This module defines the Tile struct and its associated methods. It provides functionality to interact with tiles on a map, including retrieving their properties, neighbors, and coordinates in different formats.
tile_component
This module contains the components of the tile in the map. For example, it includes the tile’s TerrainType, BaseTerrain, NationWonder, Resource, and so on.
tile_map
This module defines the TileMap struct and its associated methods. It provides functionality to manage and manipulate a map of tiles, including querying tile properties, placing resources, and managing layers of data.

Macros§

generate_common_methods
Generates common methods for a struct.

Functions§

generate_map
Generates a map based on the provided parameters and ruleset.