ai refactor, mob spawns now take into account player level, small fixes
This commit is contained in:
parent
c00418f7c8
commit
6cef899ef6
21 changed files with 301 additions and 148 deletions
|
|
@ -10,8 +10,9 @@ pub fn forest_builder(
|
|||
width: i32,
|
||||
height: i32,
|
||||
difficulty: i32,
|
||||
initial_player_level: i32,
|
||||
) -> BuilderChain {
|
||||
let mut chain = BuilderChain::new(new_id, width, height, difficulty, "Into the Woods");
|
||||
let mut chain = BuilderChain::new(new_id, width, height, difficulty, "Into the Woods", initial_player_level);
|
||||
chain.start_with(CellularAutomataBuilder::new());
|
||||
chain.with(AreaStartingPosition::new(XStart::CENTRE, YStart::CENTRE));
|
||||
chain.with(CullUnreachable::new());
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ pub struct BuilderMap {
|
|||
pub history: Vec<Map>,
|
||||
pub width: i32,
|
||||
pub height: i32,
|
||||
pub initial_player_level: i32,
|
||||
}
|
||||
|
||||
impl BuilderMap {
|
||||
|
|
@ -94,7 +95,14 @@ pub struct BuilderChain {
|
|||
}
|
||||
|
||||
impl BuilderChain {
|
||||
pub fn new<S: ToString>(new_id: i32, width: i32, height: i32, difficulty: i32, name: S) -> BuilderChain {
|
||||
pub fn new<S: ToString>(
|
||||
new_id: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
difficulty: i32,
|
||||
name: S,
|
||||
initial_player_level: i32,
|
||||
) -> BuilderChain {
|
||||
BuilderChain {
|
||||
starter: None,
|
||||
builders: Vec::new(),
|
||||
|
|
@ -107,6 +115,7 @@ impl BuilderChain {
|
|||
history: Vec::new(),
|
||||
width: width,
|
||||
height: height,
|
||||
initial_player_level: initial_player_level,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -296,9 +305,10 @@ pub fn random_builder(
|
|||
width: i32,
|
||||
height: i32,
|
||||
difficulty: i32,
|
||||
initial_player_level: i32,
|
||||
) -> BuilderChain {
|
||||
rltk::console::log(format!("DEBUGINFO: Building random (ID:{}, DIFF:{})", new_id, difficulty));
|
||||
let mut builder = BuilderChain::new(new_id, width, height, difficulty, "<PLACEHOLDER>");
|
||||
let mut builder = BuilderChain::new(new_id, width, height, difficulty, "<PLACEHOLDER>", initial_player_level);
|
||||
let type_roll = rng.roll_dice(1, 2);
|
||||
let mut want_doors = true;
|
||||
match type_roll {
|
||||
|
|
@ -339,12 +349,18 @@ pub fn random_builder(
|
|||
builder
|
||||
}
|
||||
|
||||
pub fn level_builder(new_id: i32, rng: &mut rltk::RandomNumberGenerator, width: i32, height: i32) -> BuilderChain {
|
||||
pub fn level_builder(
|
||||
new_id: i32,
|
||||
rng: &mut rltk::RandomNumberGenerator,
|
||||
width: i32,
|
||||
height: i32,
|
||||
initial_player_level: i32,
|
||||
) -> BuilderChain {
|
||||
// TODO: With difficulty and ID/depth decoupled, this can be used for branches later.
|
||||
let difficulty = new_id;
|
||||
match new_id {
|
||||
1 => town_builder(new_id, rng, width, height),
|
||||
2 => forest_builder(new_id, rng, width, height, difficulty),
|
||||
_ => random_builder(new_id, rng, width, height, difficulty),
|
||||
1 => town_builder(new_id, rng, width, height, 0, initial_player_level),
|
||||
2 => forest_builder(new_id, rng, width, height, 1, initial_player_level),
|
||||
_ => random_builder(new_id, rng, width, height, difficulty, initial_player_level),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ impl PrefabBuilder {
|
|||
}
|
||||
|
||||
fn char_to_map(&mut self, ch: char, idx: usize, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
||||
let difficulty = (build_data.map.difficulty + build_data.initial_player_level) / 2;
|
||||
match ch {
|
||||
' ' => build_data.map.tiles[idx] = TileType::Floor,
|
||||
'#' => build_data.map.tiles[idx] = TileType::Wall,
|
||||
|
|
@ -102,23 +103,23 @@ impl PrefabBuilder {
|
|||
}
|
||||
'%' => {
|
||||
build_data.map.tiles[idx] = TileType::Floor;
|
||||
build_data.spawn_list.push((idx, spawner::food_table(build_data.map.difficulty).roll(rng)));
|
||||
build_data.spawn_list.push((idx, spawner::food_table(difficulty).roll(rng)));
|
||||
}
|
||||
'!' => {
|
||||
build_data.map.tiles[idx] = TileType::Floor;
|
||||
build_data.spawn_list.push((idx, spawner::potion_table(build_data.map.difficulty).roll(rng)));
|
||||
build_data.spawn_list.push((idx, spawner::potion_table(difficulty).roll(rng)));
|
||||
}
|
||||
'/' => {
|
||||
build_data.map.tiles[idx] = TileType::Floor;
|
||||
build_data.spawn_list.push((idx, spawner::wand_table(build_data.map.difficulty).roll(rng)));
|
||||
build_data.spawn_list.push((idx, spawner::wand_table(difficulty).roll(rng)));
|
||||
}
|
||||
'?' => {
|
||||
build_data.map.tiles[idx] = TileType::Floor;
|
||||
build_data.spawn_list.push((idx, spawner::scroll_table(build_data.map.difficulty).roll(rng)));
|
||||
build_data.spawn_list.push((idx, spawner::scroll_table(difficulty).roll(rng)));
|
||||
}
|
||||
')' => {
|
||||
build_data.map.tiles[idx] = TileType::Floor;
|
||||
build_data.spawn_list.push((idx, spawner::equipment_table(build_data.map.difficulty).roll(rng)));
|
||||
build_data.spawn_list.push((idx, spawner::equipment_table(difficulty).roll(rng)));
|
||||
}
|
||||
_ => {
|
||||
rltk::console::log(format!("Unknown glyph '{}' when loading prefab", (ch as u8) as char));
|
||||
|
|
|
|||
|
|
@ -18,7 +18,13 @@ impl RoomBasedSpawner {
|
|||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
||||
if let Some(rooms) = &build_data.rooms {
|
||||
for room in rooms.iter().skip(1) {
|
||||
spawner::spawn_room(&build_data.map, rng, room, &mut build_data.spawn_list);
|
||||
spawner::spawn_room(
|
||||
&build_data.map,
|
||||
rng,
|
||||
room,
|
||||
&mut build_data.spawn_list,
|
||||
build_data.initial_player_level,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
panic!("RoomBasedSpawner only works after rooms have been created");
|
||||
|
|
|
|||
|
|
@ -18,7 +18,13 @@ impl CorridorSpawner {
|
|||
fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) {
|
||||
if let Some(corridors) = &build_data.corridors {
|
||||
for corridor in corridors.iter() {
|
||||
spawner::spawn_region(&build_data.map, rng, &corridor, &mut build_data.spawn_list);
|
||||
spawner::spawn_region(
|
||||
&build_data.map,
|
||||
rng,
|
||||
&corridor,
|
||||
&mut build_data.spawn_list,
|
||||
build_data.initial_player_level,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
panic!("CorridorSpawner only works after corridors have been created");
|
||||
|
|
|
|||
|
|
@ -1,10 +1,16 @@
|
|||
use super::{BuilderChain, BuilderMap, InitialMapBuilder, Position, TileType};
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub fn town_builder(new_id: i32, _rng: &mut rltk::RandomNumberGenerator, width: i32, height: i32) -> BuilderChain {
|
||||
let difficulty = 0;
|
||||
pub fn town_builder(
|
||||
new_id: i32,
|
||||
_rng: &mut rltk::RandomNumberGenerator,
|
||||
width: i32,
|
||||
height: i32,
|
||||
difficulty: i32,
|
||||
initial_player_level: i32,
|
||||
) -> BuilderChain {
|
||||
rltk::console::log(format!("DEBUGINFO: Building town (ID:{}, DIFF:{})", new_id, difficulty));
|
||||
let mut chain = BuilderChain::new(new_id, width, height, difficulty, "<PLACEHOLDER>");
|
||||
let mut chain = BuilderChain::new(new_id, width, height, difficulty, "<PLACEHOLDER>", initial_player_level);
|
||||
chain.start_with(TownBuilder::new());
|
||||
|
||||
return chain;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,13 @@ impl VoronoiSpawning {
|
|||
|
||||
// Spawn the entities
|
||||
for area in noise_areas.iter() {
|
||||
spawner::spawn_region(&build_data.map, rng, area.1, &mut build_data.spawn_list);
|
||||
spawner::spawn_region(
|
||||
&build_data.map,
|
||||
rng,
|
||||
area.1,
|
||||
&mut build_data.spawn_list,
|
||||
build_data.initial_player_level,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue