IntervalSpawningSystem{} fix, and mobs randomly move
This commit is contained in:
parent
5276bb6e34
commit
b5e3880a33
5 changed files with 61 additions and 28 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{gamelog, raws, spawner, Clock, Map, RandomNumberGenerator, TakingTurn};
|
||||
use crate::{gamelog, raws, spawner, Clock, Map, RandomNumberGenerator, TakingTurn, LOG_SPAWNING};
|
||||
use specs::prelude::*;
|
||||
|
||||
const TRY_SPAWN_CHANCE: i32 = 70;
|
||||
|
|
@ -17,12 +17,14 @@ pub fn try_spawn_interval(ecs: &mut World) {
|
|||
let mut rng = ecs.write_resource::<rltk::RandomNumberGenerator>();
|
||||
for (_c, _t) in (&clock, &turns).join() {
|
||||
if rng.roll_dice(1, TRY_SPAWN_CHANCE) == 1 {
|
||||
rltk::console::log("Trying spawn.");
|
||||
try_spawn = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if try_spawn {
|
||||
if LOG_SPAWNING {
|
||||
rltk::console::log("SPAWNINFO: Trying spawn.");
|
||||
}
|
||||
spawn_random_mob_in_free_nonvisible_tile(ecs);
|
||||
}
|
||||
}
|
||||
|
|
@ -32,6 +34,9 @@ fn spawn_random_mob_in_free_nonvisible_tile(ecs: &mut World) {
|
|||
let available_tiles = populate_unblocked_nonvisible_tiles(&map);
|
||||
let difficulty = (map.difficulty + gamelog::get_event_count("player_level")) / 2;
|
||||
if available_tiles.len() == 0 {
|
||||
if LOG_SPAWNING {
|
||||
rltk::console::log("SPAWNINFO: No free tiles; not spawning anything..");
|
||||
}
|
||||
return;
|
||||
}
|
||||
let mut rng = ecs.write_resource::<RandomNumberGenerator>();
|
||||
|
|
@ -41,6 +46,9 @@ fn spawn_random_mob_in_free_nonvisible_tile(ecs: &mut World) {
|
|||
let y = idx as i32 / map.width;
|
||||
std::mem::drop(map);
|
||||
std::mem::drop(rng);
|
||||
if LOG_SPAWNING {
|
||||
rltk::console::log(format!("SPAWNINFO: Spawning {} at {}, {}.", key, x, y));
|
||||
}
|
||||
raws::spawn_named_entity(&raws::RAWS.lock().unwrap(), ecs, &key, raws::SpawnType::AtPosition { x, y }, difficulty);
|
||||
}
|
||||
|
||||
|
|
@ -56,5 +64,5 @@ fn populate_unblocked_nonvisible_tiles(map: &Map) -> Vec<usize> {
|
|||
|
||||
fn get_random_idx_from_possible_tiles(rng: &mut rltk::RandomNumberGenerator, area: Vec<usize>) -> usize {
|
||||
let idx = if area.len() == 1 { 0usize } else { (rng.roll_dice(1, area.len() as i32) - 1) as usize };
|
||||
return idx;
|
||||
return area[idx];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue