From b5bf24a3aaf4d5895b7991b3dd5f26ba98a58020 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 3 Jan 2022 10:57:23 -0500 Subject: [PATCH] Spawn more NPCs in the town map --- src/map_builders/town.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/map_builders/town.rs b/src/map_builders/town.rs index 876e6bc..12d48fa 100644 --- a/src/map_builders/town.rs +++ b/src/map_builders/town.rs @@ -59,6 +59,9 @@ impl TownBuilder { let building_size = self.sort_buildings(&buildings); self.building_factory(rng, build_data, &buildings, &building_size); + self.spawn_dockers(build_data, rng); + self.spawn_townsfolk(build_data, rng, &mut available_building_tiles); + // Make visible for screenshot for t in build_data.map.visible_tiles.iter_mut() { *t = true; @@ -501,4 +504,38 @@ impl TownBuilder { } } } + + fn spawn_dockers(&mut self, build_data: &mut BuilderMap, rng: &mut RandomNumberGenerator) { + for (idx, tt) in build_data.map.tiles.iter().enumerate() { + if *tt == TileType::Bridge && rng.roll_dice(1, 6) == 1 { + match rng.roll_dice(1, 3) { + 1 => build_data.spawn_list.push((idx, "Dock Worker".to_string())), + 2 => build_data + .spawn_list + .push((idx, "Wannabe Pirate".to_string())), + _ => build_data.spawn_list.push((idx, "Fisher".to_string())), + } + } + } + } + + fn spawn_townsfolk( + &mut self, + build_data: &mut BuilderMap, + rng: &mut RandomNumberGenerator, + available_building_tiles: &mut HashSet, + ) { + for idx in available_building_tiles.iter() { + if rng.roll_dice(1, 10) == 1 { + match rng.roll_dice(1, 4) { + 1 => build_data.spawn_list.push((*idx, "Peasant".to_string())), + 2 => build_data.spawn_list.push((*idx, "Drunk".to_string())), + 3 => build_data + .spawn_list + .push((*idx, "Dock Worker".to_string())), + _ => build_data.spawn_list.push((*idx, "Fisher".to_string())), + } + } + } + } }