town -> woods -> one floor of dungeon; infinite dungeon elsewhere

just trying things out.
This commit is contained in:
Llywelwyn 2023-08-27 03:43:25 +01:00
parent 486807fc84
commit 02be487334
10 changed files with 72 additions and 18 deletions

View file

@ -2,5 +2,9 @@ pub const ID_PREVIOUS_LEVEL: i32 = -5;
pub const ID_NEXT_LEVEL: i32 = -6;
pub const ID_OVERMAP: i32 = 1;
pub const ID_TOWN: i32 = 10;
pub const ID_TOWN2: i32 = ID_TOWN + 1;
pub const ID_TOWN3: i32 = ID_TOWN + 2;
pub const ID_INFINITE: i32 = 1000;

View file

@ -82,3 +82,5 @@ pub const TO_OVERMAP_GLYPH: char = '<';
pub const TO_OVERMAP_COLOUR: (u8, u8, u8) = (205, 127, 50);
pub const TO_TOWN_GLYPH: char = 'o';
pub const TO_TOWN_COLOUR: (u8, u8, u8) = (205, 127, 50);
pub const TO_INFINITE_GLYPH: char = '*';
pub const TO_INFINITE_COLOUR: (u8, u8, u8) = (205, 127, 50);

View file

@ -11,6 +11,8 @@ use crate::{
Pools,
Name,
Blind,
HungerClock,
HungerState,
};
use crate::gui::with_article;
use crate::data::visuals::{ DEFAULT_PARTICLE_LIFETIME, LONG_PARTICLE_LIFETIME };
@ -277,5 +279,15 @@ pub fn entity_death(ecs: &mut World, effect: &EffectSpawner, target: Entity) {
source_pools.mana.current += mana_gained;
}
}
} else {
if target == *player {
if let Some(hc) = ecs.read_storage::<HungerClock>().get(target) {
if hc.state == HungerState::Starving {
gamelog::record_event(EVENT::PLAYER_DIED("You starved to death!".to_string()));
}
} else {
gamelog::record_event(EVENT::PLAYER_DIED("You died from unknown causes!".to_string()));
}
}
}
}

View file

@ -218,6 +218,7 @@ fn transition_to_existing_map(ecs: &mut World, new_id: i32, offset: i32, from_ti
TileType::ToOvermap => {
match worldmap_resource.id {
ID_TOWN => TileType::ToTown,
ID_INFINITE => TileType::ToInfinite,
_ => panic!("Tried to transition to overmap from somewhere unaccounted for!"),
}
}
@ -279,6 +280,11 @@ fn transition_to_new_map(ecs: &mut World, new_id: i32) -> Vec<Map> {
let up_idx = builder.build_data.map.xy_idx(pos.x, pos.y);
builder.build_data.map.tiles[up_idx] = TileType::UpStair;
}
} else if old_map.overmap && !builder.build_data.map.overmap {
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.

View file

@ -90,6 +90,7 @@ pub fn get_default_theme_renderables(idx: usize, map: &Map, debug: Option<bool>)
TileType::ImpassableMountain => { glyph = rltk::to_cp437(IMPASSABLE_MOUNTAIN_GLYPH); bg = RGB::named(IMPASSABLE_MOUNTAIN_COLOUR); offsets = IMPASSABLE_MOUNTAIN_OFFSETS }
TileType::ToOvermap => { glyph = rltk::to_cp437(TO_OVERMAP_GLYPH); fg = RGB::named(TO_OVERMAP_COLOUR); bg = RGB::named(DEFAULT_BG_COLOUR); bg_main_col = false; }
TileType::ToTown => { glyph = rltk::to_cp437(TO_TOWN_GLYPH); fg = RGB::named(TO_TOWN_COLOUR); bg = RGB::named(DEFAULT_BG_COLOUR); bg_main_col = false; }
TileType::ToInfinite => { glyph = rltk::to_cp437(TO_INFINITE_GLYPH); fg = RGB::named(TO_INFINITE_COLOUR); bg = RGB::named(DEFAULT_BG_COLOUR); bg_main_col = true; }
}
return (glyph, fg, bg, offsets, bg_main_col);
}

View file

@ -26,6 +26,7 @@ pub enum TileType {
// To/From Overmap - ids are in src/data/ids.rs, are used in try_change_level() in src/player.rs
ToOvermap,
ToTown,
ToInfinite,
}
pub fn tile_walkable(tt: TileType) -> bool {

View file

@ -204,7 +204,7 @@ fn random_start_position(rng: &mut rltk::RandomNumberGenerator) -> (XStart, YSta
(x, y)
}
fn random_room_builder(rng: &mut rltk::RandomNumberGenerator, builder: &mut BuilderChain) {
fn random_room_builder(rng: &mut rltk::RandomNumberGenerator, builder: &mut BuilderChain, end: bool) {
let build_roll = rng.roll_dice(1, 3);
// Start with a room builder.
match build_roll {
@ -266,11 +266,13 @@ fn random_room_builder(rng: &mut rltk::RandomNumberGenerator, builder: &mut Buil
}
// Decide where to put the exit - in a room or far away, anywhere.
if !end {
let exit_roll = rng.roll_dice(1, 2);
match exit_roll {
1 => builder.with(RoomBasedStairs::new()),
_ => builder.with(DistantExit::new()),
}
}
// Decide whether to spawn entities only in rooms, or with voronoi noise.
let spawn_roll = rng.roll_dice(1, 2);
@ -280,7 +282,7 @@ fn random_room_builder(rng: &mut rltk::RandomNumberGenerator, builder: &mut Buil
}
}
fn random_shape_builder(rng: &mut rltk::RandomNumberGenerator, builder: &mut BuilderChain) -> bool {
fn random_shape_builder(rng: &mut rltk::RandomNumberGenerator, builder: &mut BuilderChain, end: bool) -> bool {
// Pick an initial builder
let builder_roll = rng.roll_dice(1, 16);
let mut want_doors = true;
@ -314,7 +316,9 @@ fn random_shape_builder(rng: &mut rltk::RandomNumberGenerator, builder: &mut Bui
// Place the exit and spawn mobs
builder.with(VoronoiSpawning::new());
if !end {
builder.with(DistantExit::new());
}
return want_doors;
}
@ -325,13 +329,21 @@ fn overmap_builder() -> BuilderChain {
return builder;
}
pub enum BuildType {
Room = 1,
Shape = 2,
Any = 3,
}
pub fn random_builder(
new_id: i32,
rng: &mut rltk::RandomNumberGenerator,
width: i32,
height: i32,
difficulty: i32,
initial_player_level: i32
initial_player_level: i32,
end: bool,
build_type: BuildType
) -> BuilderChain {
rltk::console::log(format!("DEBUGINFO: Building random (ID:{}, DIFF:{})", new_id, difficulty));
let mut builder = BuilderChain::new(
@ -343,12 +355,20 @@ pub fn random_builder(
NAME_DUNGEON_RANDOM,
initial_player_level
);
let type_roll = rng.roll_dice(1, 2);
let mut want_doors = true;
match type_roll {
1 => random_room_builder(rng, &mut builder),
match build_type {
BuildType::Room => random_room_builder(rng, &mut builder, end),
BuildType::Shape => {
want_doors = random_shape_builder(rng, &mut builder, end);
}
BuildType::Any => {
let roll = rng.roll_dice(1, 2);
match roll {
1 => random_room_builder(rng, &mut builder, end),
_ => {
want_doors = random_shape_builder(rng, &mut builder);
want_doors = random_shape_builder(rng, &mut builder, end);
}
}
}
}
@ -398,6 +418,8 @@ pub fn level_builder(
ID_OVERMAP => overmap_builder(),
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),
_ => random_builder(new_id, rng, width, height, difficulty, initial_player_level),
ID_TOWN3 => random_builder(new_id, rng, width, height, 2, initial_player_level, true, BuildType::Room),
ID_INFINITE => random_builder(new_id, rng, width, height, 3, initial_player_level, false, BuildType::Room),
_ => random_builder(new_id, rng, width, height, difficulty, initial_player_level, false, BuildType::Any),
}
}

View file

@ -180,6 +180,9 @@ impl PrefabBuilder {
'1' => {
build_data.map.tiles[idx] = TileType::ToTown;
}
'2' => {
build_data.map.tiles[idx] = TileType::ToInfinite;
}
_ => {
rltk::console::log(format!("Unknown glyph '{}' when loading overmap", ch as u8 as char));
}

View file

@ -83,10 +83,10 @@ const OVERMAP_TEMPLATE: &str =
^^^............................................................
^^^^............................................................
^^^^^...........................................................
^^^^^^^^........................................................
^^^^^^^^^.......................................................
^^^^^^^^^......................................................
^^^^^^^^^................................................
^^^^^.^^........................................................
^^^^..^^^.......................................................
^^^...^^^......................................................
^^^2.^^^^................................................
^^^^^^^^................................................
^^^^^^^.............................................
^^^^^^^...............................

View file

@ -612,6 +612,9 @@ fn try_next_level(ecs: &mut World) -> (i32, Option<TileType>) {
TileType::ToTown => {
return (ID_TOWN, Some(this_tile));
}
TileType::ToInfinite => {
return (ID_INFINITE, Some(this_tile));
}
_ => {
gamelog::Logger::new().append("You don't see a way down from here.").log();
return (0, None);