map shortnames/identifiers

This commit is contained in:
Llywelwyn 2023-08-30 04:51:32 +01:00
parent 849a554055
commit 9fb791039f
12 changed files with 80 additions and 26 deletions

View file

@ -22,6 +22,7 @@ pub fn get_local_desc(id: i32) -> String {
pub fn get_local_col(id: i32) -> RGB { pub fn get_local_col(id: i32) -> RGB {
let col = match id { let col = match id {
ID_TOWN => TO_TOWN_COLOUR, ID_TOWN => TO_TOWN_COLOUR,
ID_TOWN2 => GRASS_COLOUR,
ID_OVERMAP => TO_OVERMAP_COLOUR, ID_OVERMAP => TO_OVERMAP_COLOUR,
_ => (255, 255, 255), _ => (255, 255, 255),
}; };

View file

@ -1,4 +1,8 @@
pub const NAME_OVERMAP: &str = "WORLD MAP"; pub const NAME_OVERMAP: &str = "the travel map";
pub const SHORTNAME_OVERMAP: &str = "Travel";
pub const NAME_DUNGEON_RANDOM: &str = "the dungeon"; pub const NAME_DUNGEON_RANDOM: &str = "the dungeon";
pub const NAME_STARTER_TOWN: &str = "TOWN NAME"; pub const SHORTNAME_DUNGEON_RANDOM: &str = "D";
pub const NAME_STARTER_TOWN: &str = "the town of Saff";
pub const SHORTNAME_STARTER_TOWN: &str = "Saff";
pub const NAME_FOREST_BUILDER: &str = "the woods outside of town"; pub const NAME_FOREST_BUILDER: &str = "the woods outside of town";
pub const SHORTNAME_FOREST_BUILDER: &str = "Woods";

View file

@ -12,7 +12,7 @@ pub enum FarlookResult {
pub fn show_farlook(gs: &mut State, ctx: &mut Rltk) -> FarlookResult { pub fn show_farlook(gs: &mut State, ctx: &mut Rltk) -> FarlookResult {
let runstate = gs.ecs.fetch::<RunState>(); let runstate = gs.ecs.fetch::<RunState>();
let (min_x, _max_x, min_y, _max_y, x_offset, y_offset) = get_screen_bounds(&gs.ecs, ctx); let (_min_x, _max_x, _min_y, _max_y, x_offset, y_offset) = get_screen_bounds(&gs.ecs, ctx);
ctx.print_color( ctx.print_color(
1 + x_offset, 1 + x_offset,

View file

@ -32,6 +32,7 @@ use super::{
State, State,
Viewshed, Viewshed,
BUC, BUC,
get_local_col,
}; };
use crate::data::entity::CARRY_CAPACITY_PER_STRENGTH; use crate::data::entity::CARRY_CAPACITY_PER_STRENGTH;
use rltk::prelude::*; use rltk::prelude::*;
@ -323,17 +324,12 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
// Render id // Render id
let map = ecs.fetch::<Map>(); let map = ecs.fetch::<Map>();
let id = format!("D{}", map.id); let id = if map.depth > 0 { format!("{}{}", map.short_name, map.depth) } else { format!("{}", map.short_name) };
ctx.print_color_right(70, 54, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), &id); ctx.print_color_right(70, 54, get_local_col(map.id), RGB::named(rltk::BLACK), &id);
// Render turn // Render turn
ctx.print_color_right( let turns = crate::gamelog::get_event_count(EVENT::COUNT_TURN);
64, ctx.print_color_right(69 - id.len(), 54, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), &format!("T{}", turns));
54,
RGB::named(rltk::YELLOW),
RGB::named(rltk::BLACK),
&format!("T{}", crate::gamelog::get_event_count(EVENT::COUNT_TURN))
);
// Boxes and tooltips last, so they draw over everything else. // Boxes and tooltips last, so they draw over everything else.
ctx.draw_hollow_box(0, 0, 70, 8, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK)); // Log box ctx.draw_hollow_box(0, 0, 70, 8, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK)); // Log box

View file

@ -743,7 +743,7 @@ fn main() -> rltk::BError {
// Insert calls // Insert calls
gs.ecs.insert(rltk::RandomNumberGenerator::new()); gs.ecs.insert(rltk::RandomNumberGenerator::new());
gs.ecs.insert(map::MasterDungeonMap::new()); // Master map list gs.ecs.insert(map::MasterDungeonMap::new()); // Master map list
gs.ecs.insert(Map::new(true, 1, 64, 64, 0, "New Map")); // Map gs.ecs.insert(Map::new(true, 1, 64, 64, 0, "New Map", "N", 0)); // Map
gs.ecs.insert(Point::new(0, 0)); // Player pos gs.ecs.insert(Point::new(0, 0)); // Player pos
gs.ecs.insert(gui::Ancestry::Dwarf); // ancestry gs.ecs.insert(gui::Ancestry::Dwarf); // ancestry
let player_entity = spawner::player(&mut gs.ecs, 0, 0); let player_entity = spawner::player(&mut gs.ecs, 0, 0);

View file

@ -28,6 +28,8 @@ pub struct Map {
pub additional_fg_offset: rltk::RGB, pub additional_fg_offset: rltk::RGB,
pub id: i32, pub id: i32,
pub name: String, pub name: String,
pub short_name: String,
pub depth: i32,
pub difficulty: i32, pub difficulty: i32,
pub bloodstains: HashSet<usize>, pub bloodstains: HashSet<usize>,
pub view_blocked: HashSet<usize>, pub view_blocked: HashSet<usize>,
@ -38,7 +40,16 @@ impl Map {
(y as usize) * (self.width as usize) + (x as usize) (y as usize) * (self.width as usize) + (x as usize)
} }
pub fn new<S: ToString>(overmap: bool, new_id: i32, width: i32, height: i32, difficulty: i32, name: S) -> Map { pub fn new<S: ToString>(
overmap: bool,
new_id: i32,
width: i32,
height: i32,
difficulty: i32,
name: S,
short_name: S,
depth: i32
) -> Map {
let map_tile_count = (width * height) as usize; let map_tile_count = (width * height) as usize;
crate::spatial::set_size(map_tile_count); crate::spatial::set_size(map_tile_count);
let mut map = Map { let mut map = Map {
@ -58,6 +69,8 @@ impl Map {
), ),
id: new_id, id: new_id,
name: name.to_string(), name: name.to_string(),
short_name: short_name.to_string(),
depth: depth,
difficulty: difficulty, difficulty: difficulty,
bloodstains: HashSet::new(), bloodstains: HashSet::new(),
view_blocked: HashSet::new(), view_blocked: HashSet::new(),

View file

@ -42,9 +42,9 @@ pub fn tile_opaque(tt: TileType) -> bool {
} }
pub fn tile_cost(tt: TileType) -> f32 { pub fn tile_cost(tt: TileType) -> f32 {
match tt { match tt {
TileType::Road => 0.5, TileType::Road => 0.75,
TileType::Grass => 1.1, TileType::Grass => 1.2,
TileType::ShallowWater => 1.3, TileType::ShallowWater => 1.5,
_ => 1.0, _ => 1.0,
} }
} }

View file

@ -29,6 +29,8 @@ pub fn forest_builder(
height, height,
difficulty, difficulty,
NAME_FOREST_BUILDER, NAME_FOREST_BUILDER,
SHORTNAME_FOREST_BUILDER,
0,
initial_player_level initial_player_level
); );
chain.start_with(CellularAutomataBuilder::floor(TileType::Grass)); chain.start_with(CellularAutomataBuilder::floor(TileType::Grass));

View file

@ -107,6 +107,8 @@ impl BuilderChain {
height: i32, height: i32,
difficulty: i32, difficulty: i32,
name: S, name: S,
short_name: S,
depth: i32,
initial_player_level: i32 initial_player_level: i32
) -> BuilderChain { ) -> BuilderChain {
BuilderChain { BuilderChain {
@ -114,7 +116,7 @@ impl BuilderChain {
builders: Vec::new(), builders: Vec::new(),
build_data: BuilderMap { build_data: BuilderMap {
spawn_list: Vec::new(), spawn_list: Vec::new(),
map: Map::new(overmap, new_id, width, height, difficulty, name), map: Map::new(overmap, new_id, width, height, difficulty, name, short_name, depth),
starting_position: None, starting_position: None,
rooms: None, rooms: None,
corridors: None, corridors: None,
@ -326,7 +328,7 @@ fn random_shape_builder(rng: &mut rltk::RandomNumberGenerator, builder: &mut Bui
} }
fn overmap_builder() -> BuilderChain { fn overmap_builder() -> BuilderChain {
let mut builder = BuilderChain::new(true, ID_OVERMAP, 69, 41, 0, NAME_OVERMAP, 1); let mut builder = BuilderChain::new(true, ID_OVERMAP, 69, 41, 0, NAME_OVERMAP, SHORTNAME_OVERMAP, 0, 1);
builder.start_with(PrefabBuilder::overmap()); builder.start_with(PrefabBuilder::overmap());
builder.with(Foliage::percent(TileType::Grass, 30)); builder.with(Foliage::percent(TileType::Grass, 30));
return builder; return builder;
@ -344,6 +346,7 @@ pub fn random_builder(
width: i32, width: i32,
height: i32, height: i32,
difficulty: i32, difficulty: i32,
depth: i32,
initial_player_level: i32, initial_player_level: i32,
end: bool, end: bool,
build_type: BuildType build_type: BuildType
@ -356,6 +359,8 @@ pub fn random_builder(
height, height,
difficulty, difficulty,
NAME_DUNGEON_RANDOM, NAME_DUNGEON_RANDOM,
SHORTNAME_DUNGEON_RANDOM,
depth,
initial_player_level initial_player_level
); );
let mut want_doors = true; let mut want_doors = true;
@ -421,8 +426,19 @@ pub fn level_builder(
ID_OVERMAP => overmap_builder(), ID_OVERMAP => overmap_builder(),
ID_TOWN => town_builder(new_id, rng, width, height, 0, initial_player_level), ID_TOWN => town_builder(new_id, rng, width, height, 0, initial_player_level),
ID_TOWN2 => forest_builder(new_id, rng, width, height, 1, initial_player_level), ID_TOWN2 => forest_builder(new_id, rng, width, height, 1, initial_player_level),
ID_TOWN3 => random_builder(new_id, rng, width, height, 2, initial_player_level, true, BuildType::Room), ID_TOWN3 => random_builder(new_id, rng, width, height, 2, 1, initial_player_level, true, BuildType::Room),
ID_INFINITE => random_builder(new_id, rng, width, height, 3, initial_player_level, false, BuildType::Room), _ if new_id >= ID_INFINITE =>
_ => random_builder(new_id, rng, width, height, difficulty, initial_player_level, false, BuildType::Any), random_builder(
new_id,
rng,
width,
height,
difficulty,
new_id - ID_INFINITE + 1,
initial_player_level,
false,
BuildType::Room
),
_ => random_builder(new_id, rng, width, height, difficulty, 404, initial_player_level, false, BuildType::Room),
} }
} }

View file

@ -93,7 +93,7 @@ const OVERMAP_TEMPLATE: &str =
^^^^^^^............................. ^^^^^^^.............................
^^^^^^^^........@.................. ^^^^^^^^........@..................
^^^^^^^^............................ ^^^^^^^^............................
^^^^^^^^^.............1................. ^^^^^^^^^.................1.............
^^^^^^^^^....................... ^^^^^^^^^.......................
^^^^^^^^^^................ ^^^^^^^^^^................
^^^^^^^^^^............. ^^^^^^^^^^.............

View file

@ -18,6 +18,8 @@ pub fn town_builder(
height, height,
difficulty, difficulty,
NAME_STARTER_TOWN, NAME_STARTER_TOWN,
SHORTNAME_STARTER_TOWN,
0,
initial_player_level initial_player_level
); );
chain.start_with(TownBuilder::new()); chain.start_with(TownBuilder::new());

View file

@ -37,7 +37,9 @@ impl WaveFunctionCollapseBuilder {
build_data.map.width, build_data.map.width,
build_data.map.height, build_data.map.height,
build_data.map.difficulty, build_data.map.difficulty,
&build_data.map.name &build_data.map.name,
&build_data.map.short_name,
build_data.map.depth
); );
loop { loop {
let mut solver = Solver::new(constraints.clone(), CHUNK_SIZE, &build_data.map); let mut solver = Solver::new(constraints.clone(), CHUNK_SIZE, &build_data.map);
@ -53,7 +55,16 @@ impl WaveFunctionCollapseBuilder {
} }
fn render_tile_gallery(&mut self, constraints: &[MapChunk], chunk_size: i32, build_data: &mut BuilderMap) { fn render_tile_gallery(&mut self, constraints: &[MapChunk], chunk_size: i32, build_data: &mut BuilderMap) {
build_data.map = Map::new(false, 0, build_data.width, build_data.height, 0, &build_data.map.name); build_data.map = Map::new(
false,
0,
build_data.width,
build_data.height,
0,
&build_data.map.name,
&build_data.map.short_name,
build_data.map.depth
);
let mut counter = 0; let mut counter = 0;
let mut x = 1; let mut x = 1;
let mut y = 1; let mut y = 1;
@ -69,7 +80,16 @@ impl WaveFunctionCollapseBuilder {
if y + chunk_size > build_data.map.height { if y + chunk_size > build_data.map.height {
// Move to the next page // Move to the next page
build_data.take_snapshot(); build_data.take_snapshot();
build_data.map = Map::new(false, 0, build_data.width, build_data.height, 0, &build_data.map.name); build_data.map = Map::new(
false,
0,
build_data.width,
build_data.height,
0,
&build_data.map.name,
&build_data.map.short_name,
build_data.map.depth
);
x = 1; x = 1;
y = 1; y = 1;