From af1d5a71e9dedce29381bd598f6f2c7fb331fb85 Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Tue, 27 Jun 2023 17:42:07 -0400 Subject: [PATCH] Split apart unit and structure generation --- emergence_lib/src/world_gen/mod.rs | 22 +++++++++++----- ..._generation.rs => structure_generation.rs} | 26 ++++++++++++++----- 2 files changed, 35 insertions(+), 13 deletions(-) rename emergence_lib/src/world_gen/{organism_generation.rs => structure_generation.rs} (86%) diff --git a/emergence_lib/src/world_gen/mod.rs b/emergence_lib/src/world_gen/mod.rs index ebfbb20a5..8c25f430d 100644 --- a/emergence_lib/src/world_gen/mod.rs +++ b/emergence_lib/src/world_gen/mod.rs @@ -5,7 +5,9 @@ use crate::structures::structure_manifest::Structure; use crate::terrain::terrain_manifest::Terrain; use crate::units::unit_manifest::Unit; use crate::utils::noise::SimplexSettings; -use crate::world_gen::organism_generation::{generate_organisms, randomize_starting_organisms}; +use crate::world_gen::structure_generation::{ + generate_structures, generate_units, randomize_starting_organisms, +}; use crate::world_gen::terrain_generation::{ generate_landmarks, generate_terrain, initialize_water_table, }; @@ -14,7 +16,7 @@ use bevy::prelude::*; use bevy::utils::HashMap; use bevy_framepace::{FramepaceSettings, Limiter}; -mod organism_generation; +mod structure_generation; mod terrain_generation; /// Generate the world. @@ -35,7 +37,9 @@ impl Plugin for GenerationPlugin { generate_landmarks, initialize_water_table, apply_system_buffers, - generate_organisms, + generate_structures, + apply_system_buffers, + generate_units, apply_system_buffers, randomize_starting_organisms, ) @@ -256,7 +260,7 @@ mod tests { app.add_plugin(DummyManifestPlugin); app.insert_resource(GenerationConfig::testing()); app.insert_resource(GlobalRng::new(0)); - app.add_startup_systems((generate_terrain, generate_organisms).chain()); + app.add_startup_systems((generate_terrain, generate_structures).chain()); app.update(); } @@ -267,7 +271,9 @@ mod tests { app.add_plugin(DummyManifestPlugin); app.insert_resource(GenerationConfig::testing()); app.insert_resource(GlobalRng::new(0)); - app.add_startup_systems((generate_terrain, generate_organisms, generate_landmarks).chain()); + app.add_startup_systems( + (generate_terrain, generate_structures, generate_landmarks).chain(), + ); app.update(); @@ -290,7 +296,9 @@ mod tests { app.add_plugin(DummyManifestPlugin); app.insert_resource(GenerationConfig::testing()); app.insert_resource(GlobalRng::new(0)); - app.add_startup_systems((generate_terrain, generate_organisms, generate_landmarks).chain()); + app.add_startup_systems( + (generate_terrain, generate_structures, generate_landmarks).chain(), + ); app.update(); @@ -309,7 +317,7 @@ mod tests { app.add_plugin(DummyManifestPlugin); app.insert_resource(GenerationConfig::testing()); app.insert_resource(GlobalRng::new(0)); - app.add_startup_systems((generate_terrain, generate_organisms).chain()); + app.add_startup_systems((generate_terrain, generate_structures).chain()); app.update(); diff --git a/emergence_lib/src/world_gen/organism_generation.rs b/emergence_lib/src/world_gen/structure_generation.rs similarity index 86% rename from emergence_lib/src/world_gen/organism_generation.rs rename to emergence_lib/src/world_gen/structure_generation.rs index f9c0e8b46..46cf5c894 100644 --- a/emergence_lib/src/world_gen/organism_generation.rs +++ b/emergence_lib/src/world_gen/structure_generation.rs @@ -18,18 +18,16 @@ use rand::{thread_rng, Rng}; use super::GenerationConfig; -/// Create starting organisms according to [`GenerationConfig`], and randomly place them on -/// passable tiles. -pub(super) fn generate_organisms( +/// Create starting structures according to [`GenerationConfig`], and randomly place them on +/// top of the terrain. +pub(super) fn generate_structures( mut commands: Commands, config: Res, - maybe_unit_handles: Option>, - unit_manifest: Res, structure_manifest: Res, map_geometry: Res, mut rng: ResMut, ) { - info!("Generating organisms..."); + info!("Generating structures..."); // Collect out so we can mutate the height map to flatten the terrain while in the loop for voxel_pos in map_geometry.walkable_voxels() { @@ -55,7 +53,23 @@ pub(super) fn generate_organisms( } } } + } +} + +/// Create starting units according to [`GenerationConfig`], and randomly place them on +/// passable tiles. +pub(super) fn generate_units( + mut commands: Commands, + config: Res, + maybe_unit_handles: Option>, + unit_manifest: Res, + map_geometry: Res, + mut rng: ResMut, +) { + info!("Generating units..."); + // Collect out so we can mutate the height map to flatten the terrain while in the loop + for voxel_pos in map_geometry.walkable_voxels() { for (&unit_id, &chance) in &config.unit_chances { if rng.gen::() < chance { let unit_bundle = if let Some(ref unit_handles) = maybe_unit_handles {