From 486807fc845c6a97ea88e4a92c8ab69b7c17c9db Mon Sep 17 00:00:00 2001 From: Llywelwyn Date: Sun, 27 Aug 2023 03:13:58 +0100 Subject: [PATCH] names to file --- src/data/mod.rs | 1 + src/data/names.rs | 4 ++++ src/map/dungeon.rs | 9 +++------ src/map_builders/forest.rs | 11 ++++++++++- src/map_builders/mod.rs | 13 +++++++++++-- src/map_builders/town.rs | 13 ++++++++++++- 6 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 src/data/names.rs diff --git a/src/data/mod.rs b/src/data/mod.rs index e7cc75b..8abda34 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -4,3 +4,4 @@ pub mod messages; pub mod char_create; pub mod events; pub mod ids; +pub mod names; diff --git a/src/data/names.rs b/src/data/names.rs new file mode 100644 index 0000000..76d44a1 --- /dev/null +++ b/src/data/names.rs @@ -0,0 +1,4 @@ +pub const NAME_OVERMAP: &str = "WORLD MAP"; +pub const NAME_DUNGEON_RANDOM: &str = "the dungeon"; +pub const NAME_STARTER_TOWN: &str = "TOWN NAME"; +pub const NAME_FOREST_BUILDER: &str = "the woods outside of town"; diff --git a/src/map/dungeon.rs b/src/map/dungeon.rs index ea707fc..4d92499 100644 --- a/src/map/dungeon.rs +++ b/src/map/dungeon.rs @@ -272,16 +272,13 @@ fn transition_to_new_map(ecs: &mut World, new_id: i32) -> Vec { { let mut worldmap_resource = ecs.write_resource::(); old_map = worldmap_resource.clone(); - if !old_map.overmap { + // If there is zero overmap involvement, place an upstair where we ended up. + // Otherwise, this should be hand-placed. + if !old_map.overmap && !builder.build_data.map.overmap { if let Some(pos) = &builder.build_data.starting_position { let up_idx = builder.build_data.map.xy_idx(pos.x, pos.y); builder.build_data.map.tiles[up_idx] = TileType::UpStair; } - } else { - if let Some(pos) = &builder.build_data.starting_position { - let down_idx = builder.build_data.map.xy_idx(pos.x, pos.y); - builder.build_data.map.tiles[down_idx] = TileType::ToOvermap; - } } *worldmap_resource = builder.build_data.map.clone(); // Unwrap so we get a CTD if there's no starting pos. diff --git a/src/map_builders/forest.rs b/src/map_builders/forest.rs index 1c2005a..8bdfc00 100644 --- a/src/map_builders/forest.rs +++ b/src/map_builders/forest.rs @@ -11,6 +11,7 @@ use super::{ YStart, }; use rltk::prelude::*; +use crate::data::names::*; pub fn forest_builder( new_id: i32, @@ -20,7 +21,15 @@ pub fn forest_builder( difficulty: i32, initial_player_level: i32 ) -> BuilderChain { - let mut chain = BuilderChain::new(false, new_id, width, height, difficulty, "the woods", initial_player_level); + let mut chain = BuilderChain::new( + false, + new_id, + width, + height, + difficulty, + NAME_FOREST_BUILDER, + initial_player_level + ); chain.start_with(CellularAutomataBuilder::new()); chain.with(AreaStartingPosition::new(XStart::CENTRE, YStart::CENTRE)); chain.with(CullUnreachable::new()); diff --git a/src/map_builders/mod.rs b/src/map_builders/mod.rs index eaa260f..682693d 100644 --- a/src/map_builders/mod.rs +++ b/src/map_builders/mod.rs @@ -37,6 +37,7 @@ use specs::prelude::*; use voronoi_spawning::VoronoiSpawning; use super::config::CONFIG; use super::data::ids::*; +use super::data::names::*; //use wfc::WaveFunctionCollapseBuilder; mod room_exploder; use room_exploder::RoomExploder; @@ -319,7 +320,7 @@ fn random_shape_builder(rng: &mut rltk::RandomNumberGenerator, builder: &mut Bui } fn overmap_builder() -> BuilderChain { - let mut builder = BuilderChain::new(true, ID_OVERMAP, 69, 41, 0, "the world", 1); + let mut builder = BuilderChain::new(true, ID_OVERMAP, 69, 41, 0, NAME_OVERMAP, 1); builder.start_with(PrefabBuilder::overmap()); return builder; } @@ -333,7 +334,15 @@ pub fn random_builder( initial_player_level: i32 ) -> BuilderChain { rltk::console::log(format!("DEBUGINFO: Building random (ID:{}, DIFF:{})", new_id, difficulty)); - let mut builder = BuilderChain::new(false, new_id, width, height, difficulty, "the dungeon", initial_player_level); + let mut builder = BuilderChain::new( + false, + new_id, + width, + height, + difficulty, + NAME_DUNGEON_RANDOM, + initial_player_level + ); let type_roll = rng.roll_dice(1, 2); let mut want_doors = true; match type_roll { diff --git a/src/map_builders/town.rs b/src/map_builders/town.rs index 8ebf021..f55d38b 100644 --- a/src/map_builders/town.rs +++ b/src/map_builders/town.rs @@ -1,5 +1,6 @@ use super::{ BuilderChain, BuilderMap, InitialMapBuilder, Position, TileType }; use std::collections::HashSet; +use crate::data::names::*; pub fn town_builder( new_id: i32, @@ -10,7 +11,15 @@ pub fn town_builder( initial_player_level: i32 ) -> BuilderChain { rltk::console::log(format!("DEBUGINFO: Building town (ID:{}, DIFF:{})", new_id, difficulty)); - let mut chain = BuilderChain::new(false, new_id, width, height, difficulty, "the town", initial_player_level); + let mut chain = BuilderChain::new( + false, + new_id, + width, + height, + difficulty, + NAME_STARTER_TOWN, + initial_player_level + ); chain.start_with(TownBuilder::new()); return chain; @@ -65,6 +74,8 @@ impl TownBuilder { x: build_data.width - 2, y: wall_gap_y, }); + let overmap_entrance = build_data.map.xy_idx(build_data.width - 2, wall_gap_y); + build_data.map.tiles[overmap_entrance] = TileType::ToOvermap; build_data.take_snapshot(); }