prefab sectionals and searching on wait
This commit is contained in:
parent
8664a8e066
commit
a3b4688608
2 changed files with 35 additions and 23 deletions
|
|
@ -20,7 +20,7 @@ pub struct PrefabBuilder {
|
||||||
depth: i32,
|
depth: i32,
|
||||||
history: Vec<Map>,
|
history: Vec<Map>,
|
||||||
mode: PrefabMode,
|
mode: PrefabMode,
|
||||||
spawns: Vec<(usize, String)>,
|
spawn_list: Vec<(usize, String)>,
|
||||||
previous_builder: Option<Box<dyn MapBuilder>>,
|
previous_builder: Option<Box<dyn MapBuilder>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,11 +28,6 @@ impl MapBuilder for PrefabBuilder {
|
||||||
fn build_map(&mut self, rng: &mut RandomNumberGenerator) {
|
fn build_map(&mut self, rng: &mut RandomNumberGenerator) {
|
||||||
return self.build(rng);
|
return self.build(rng);
|
||||||
}
|
}
|
||||||
fn spawn_entities(&mut self, ecs: &mut World) {
|
|
||||||
for entity in self.spawns.iter() {
|
|
||||||
spawner::spawn_entity(ecs, &(&entity.0, &entity.1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Getters
|
// Getters
|
||||||
fn get_map(&mut self) -> Map {
|
fn get_map(&mut self) -> Map {
|
||||||
return self.map.clone();
|
return self.map.clone();
|
||||||
|
|
@ -40,6 +35,9 @@ impl MapBuilder for PrefabBuilder {
|
||||||
fn get_starting_pos(&mut self) -> Position {
|
fn get_starting_pos(&mut self) -> Position {
|
||||||
return self.starting_position.clone();
|
return self.starting_position.clone();
|
||||||
}
|
}
|
||||||
|
fn get_spawn_list(&self) -> &Vec<(usize, String)> {
|
||||||
|
return &self.spawn_list;
|
||||||
|
}
|
||||||
// Mapgen visualisation stuff
|
// Mapgen visualisation stuff
|
||||||
fn get_snapshot_history(&self) -> Vec<Map> {
|
fn get_snapshot_history(&self) -> Vec<Map> {
|
||||||
return self.history.clone();
|
return self.history.clone();
|
||||||
|
|
@ -64,7 +62,7 @@ impl PrefabBuilder {
|
||||||
depth: new_depth,
|
depth: new_depth,
|
||||||
history: Vec::new(),
|
history: Vec::new(),
|
||||||
mode: PrefabMode::Sectional { section: prefab_sections::UNDERGROUND_FORT },
|
mode: PrefabMode::Sectional { section: prefab_sections::UNDERGROUND_FORT },
|
||||||
spawns: Vec::new(),
|
spawn_list: Vec::new(),
|
||||||
previous_builder,
|
previous_builder,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -98,15 +96,7 @@ impl PrefabBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_sectional(&mut self, section: &prefab_sections::PrefabSection, rng: &mut RandomNumberGenerator) {
|
pub fn apply_sectional(&mut self, section: &prefab_sections::PrefabSection, rng: &mut RandomNumberGenerator) {
|
||||||
// Build the map
|
|
||||||
let prev_builder = self.previous_builder.as_mut().unwrap();
|
|
||||||
prev_builder.build_map(rng);
|
|
||||||
self.starting_position = prev_builder.get_starting_pos();
|
|
||||||
self.map = prev_builder.get_map().clone();
|
|
||||||
self.take_snapshot();
|
|
||||||
|
|
||||||
use prefab_sections::*;
|
use prefab_sections::*;
|
||||||
|
|
||||||
let string_vec = PrefabBuilder::read_ascii_to_vec(section.template);
|
let string_vec = PrefabBuilder::read_ascii_to_vec(section.template);
|
||||||
|
|
||||||
// Place the new section
|
// Place the new section
|
||||||
|
|
@ -123,7 +113,26 @@ impl PrefabBuilder {
|
||||||
VerticalPlacement::Center => chunk_y = (self.map.height / 2) - (section.height as i32 / 2),
|
VerticalPlacement::Center => chunk_y = (self.map.height / 2) - (section.height as i32 / 2),
|
||||||
VerticalPlacement::Bottom => chunk_y = (self.map.height - 1) - section.height as i32,
|
VerticalPlacement::Bottom => chunk_y = (self.map.height - 1) - section.height as i32,
|
||||||
}
|
}
|
||||||
println!("{},{}", chunk_x, chunk_y);
|
|
||||||
|
// Build the map
|
||||||
|
let prev_builder = self.previous_builder.as_mut().unwrap();
|
||||||
|
prev_builder.build_map(rng);
|
||||||
|
self.starting_position = prev_builder.get_starting_pos();
|
||||||
|
self.map = prev_builder.get_map().clone();
|
||||||
|
// Iterate previous spawn list, culling entities within new section
|
||||||
|
for entity in prev_builder.get_spawn_list().iter() {
|
||||||
|
let idx = entity.0;
|
||||||
|
let x = idx as i32 % self.map.width;
|
||||||
|
let y = idx as i32 / self.map.width;
|
||||||
|
if x < chunk_x
|
||||||
|
|| x > (chunk_x + section.width as i32)
|
||||||
|
|| y < chunk_y
|
||||||
|
|| y > (chunk_y + section.height as i32)
|
||||||
|
{
|
||||||
|
self.spawn_list.push((idx, entity.1.to_string()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.take_snapshot();
|
||||||
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
for ty in 0..section.height {
|
for ty in 0..section.height {
|
||||||
|
|
@ -151,23 +160,23 @@ impl PrefabBuilder {
|
||||||
}
|
}
|
||||||
'g' => {
|
'g' => {
|
||||||
self.map.tiles[idx] = TileType::Floor;
|
self.map.tiles[idx] = TileType::Floor;
|
||||||
self.spawns.push((idx, "goblin".to_string()));
|
self.spawn_list.push((idx, "goblin".to_string()));
|
||||||
}
|
}
|
||||||
'o' => {
|
'o' => {
|
||||||
self.map.tiles[idx] = TileType::Floor;
|
self.map.tiles[idx] = TileType::Floor;
|
||||||
self.spawns.push((idx, "orc".to_string()));
|
self.spawn_list.push((idx, "orc".to_string()));
|
||||||
}
|
}
|
||||||
'^' => {
|
'^' => {
|
||||||
self.map.tiles[idx] = TileType::Floor;
|
self.map.tiles[idx] = TileType::Floor;
|
||||||
self.spawns.push((idx, "bear trap".to_string()));
|
self.spawn_list.push((idx, "bear trap".to_string()));
|
||||||
}
|
}
|
||||||
'%' => {
|
'%' => {
|
||||||
self.map.tiles[idx] = TileType::Floor;
|
self.map.tiles[idx] = TileType::Floor;
|
||||||
self.spawns.push((idx, "rations".to_string()));
|
self.spawn_list.push((idx, "rations".to_string()));
|
||||||
}
|
}
|
||||||
'!' => {
|
'!' => {
|
||||||
self.map.tiles[idx] = TileType::Floor;
|
self.map.tiles[idx] = TileType::Floor;
|
||||||
self.spawns.push((idx, "health potion".to_string()));
|
self.spawn_list.push((idx, "health potion".to_string()));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
rltk::console::log(format!("Unknown glyph loading map: {}", (ch as u8) as char));
|
rltk::console::log(format!("Unknown glyph loading map: {}", (ch as u8) as char));
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ pub fn try_next_level(ecs: &mut World) -> bool {
|
||||||
|
|
||||||
fn skip_turn(ecs: &mut World) -> bool {
|
fn skip_turn(ecs: &mut World) -> bool {
|
||||||
let player_entity = ecs.fetch::<Entity>();
|
let player_entity = ecs.fetch::<Entity>();
|
||||||
let viewshed_components = ecs.read_storage::<Viewshed>();
|
let mut viewsheds = ecs.write_storage::<Viewshed>();
|
||||||
let monsters = ecs.read_storage::<Monster>();
|
let monsters = ecs.read_storage::<Monster>();
|
||||||
let worldmap_resource = ecs.fetch::<Map>();
|
let worldmap_resource = ecs.fetch::<Map>();
|
||||||
let hunger_clocks = ecs.read_storage::<HungerClock>();
|
let hunger_clocks = ecs.read_storage::<HungerClock>();
|
||||||
|
|
@ -202,7 +202,7 @@ fn skip_turn(ecs: &mut World) -> bool {
|
||||||
let mut can_heal = true;
|
let mut can_heal = true;
|
||||||
|
|
||||||
// Check viewshed for monsters nearby. If we can see a monster, we can't heal.
|
// Check viewshed for monsters nearby. If we can see a monster, we can't heal.
|
||||||
let viewshed = viewshed_components.get(*player_entity).unwrap();
|
let viewshed = viewsheds.get_mut(*player_entity).unwrap();
|
||||||
for tile in viewshed.visible_tiles.iter() {
|
for tile in viewshed.visible_tiles.iter() {
|
||||||
let idx = worldmap_resource.xy_idx(tile.x, tile.y);
|
let idx = worldmap_resource.xy_idx(tile.x, tile.y);
|
||||||
for entity_id in worldmap_resource.tile_content[idx].iter() {
|
for entity_id in worldmap_resource.tile_content[idx].iter() {
|
||||||
|
|
@ -215,6 +215,8 @@ fn skip_turn(ecs: &mut World) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Dirty viewshed (so we search for hidden tiles whenever we wait)
|
||||||
|
viewshed.dirty = true;
|
||||||
|
|
||||||
// Check player's hunger state - if we're hungry or worse, we can't heal.
|
// Check player's hunger state - if we're hungry or worse, we can't heal.
|
||||||
let player_hunger_clock = hunger_clocks.get(*player_entity);
|
let player_hunger_clock = hunger_clocks.get(*player_entity);
|
||||||
|
|
@ -244,6 +246,7 @@ fn skip_turn(ecs: &mut World) -> bool {
|
||||||
} else {
|
} else {
|
||||||
gamelog::Logger::new().append("You wait a turn.").log();
|
gamelog::Logger::new().append("You wait a turn.").log();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue