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 transformationsmap_generator: Map generation algorithms (Fractal, Pangaea)ruleset: Game rule definitions loaded from JSON filestile_map: Map data structure and generation pipelinetile_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
- Grid system module providing coordinate systems.
- map_
generator - This module defines the
Generatortrait 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
Rulesetstruct 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
Tilestruct 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
TileMapstruct 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.