made the switch to using bracket-lib directly, instead of rltk wrapper
this should solve the build issues; it makes using the non-crashing github build a lot easier, because it lets the explicit rltk dependency be removed.
This commit is contained in:
parent
455b8f2d80
commit
85efe13dc5
93 changed files with 1528 additions and 770 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{ EntityMoved, Map, Position, TakingTurn, Telepath, Viewshed, WantsToApproach };
|
||||
use rltk::prelude::*;
|
||||
use bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
|
||||
pub struct ApproachAI {}
|
||||
|
|
@ -39,7 +39,9 @@ impl<'a> System<'a> for ApproachAI {
|
|||
&turns,
|
||||
).join() {
|
||||
turn_done.push(entity);
|
||||
let target_idxs = if let Some(paths) = get_adjacent_unblocked(&map, approach.idx as usize) {
|
||||
let target_idxs = if
|
||||
let Some(paths) = get_adjacent_unblocked(&map, approach.idx as usize)
|
||||
{
|
||||
paths
|
||||
} else {
|
||||
continue;
|
||||
|
|
@ -47,9 +49,12 @@ impl<'a> System<'a> for ApproachAI {
|
|||
let mut path: Option<NavigationPath> = None;
|
||||
let idx = map.xy_idx(pos.x, pos.y);
|
||||
for tar_idx in target_idxs {
|
||||
let potential_path = rltk::a_star_search(idx, tar_idx, &mut *map);
|
||||
let potential_path = a_star_search(idx, tar_idx, &mut *map);
|
||||
if potential_path.success && potential_path.steps.len() > 1 {
|
||||
if path.is_none() || potential_path.steps.len() < path.as_ref().unwrap().steps.len() {
|
||||
if
|
||||
path.is_none() ||
|
||||
potential_path.steps.len() < path.as_ref().unwrap().steps.len()
|
||||
{
|
||||
path = Some(potential_path);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{ Chasing, EntityMoved, Map, Position, TakingTurn, Telepath, Viewshed };
|
||||
use rltk::prelude::*;
|
||||
use bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
use std::collections::HashMap;
|
||||
use super::approach_ai_system::get_adjacent_unblocked;
|
||||
|
|
@ -26,8 +26,16 @@ impl<'a> System<'a> for ChaseAI {
|
|||
);
|
||||
|
||||
fn run(&mut self, data: Self::SystemData) {
|
||||
let (mut turns, mut chasing, mut positions, mut map, mut viewsheds, mut telepaths, mut entity_moved, entities) =
|
||||
data;
|
||||
let (
|
||||
mut turns,
|
||||
mut chasing,
|
||||
mut positions,
|
||||
mut map,
|
||||
mut viewsheds,
|
||||
mut telepaths,
|
||||
mut entity_moved,
|
||||
entities,
|
||||
) = data;
|
||||
let mut targets: HashMap<Entity, (i32, i32)> = HashMap::new();
|
||||
let mut end_chase: Vec<Entity> = Vec::new();
|
||||
// For every chasing entity with a turn, look for a valid target position,
|
||||
|
|
@ -67,9 +75,12 @@ impl<'a> System<'a> for ChaseAI {
|
|||
let mut path: Option<NavigationPath> = None;
|
||||
let idx = map.xy_idx(pos.x, pos.y);
|
||||
for tar_idx in target_idxs {
|
||||
let potential_path = rltk::a_star_search(idx, tar_idx, &mut *map);
|
||||
let potential_path = a_star_search(idx, tar_idx, &mut *map);
|
||||
if potential_path.success && potential_path.steps.len() > 1 {
|
||||
if path.is_none() || potential_path.steps.len() < path.as_ref().unwrap().steps.len() {
|
||||
if
|
||||
path.is_none() ||
|
||||
potential_path.steps.len() < path.as_ref().unwrap().steps.len()
|
||||
{
|
||||
path = Some(potential_path);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,16 @@
|
|||
use crate::{ tile_walkable, EntityMoved, Map, MoveMode, Movement, Position, TakingTurn, Telepath, Viewshed };
|
||||
use crate::{
|
||||
tile_walkable,
|
||||
EntityMoved,
|
||||
Map,
|
||||
MoveMode,
|
||||
Movement,
|
||||
Position,
|
||||
TakingTurn,
|
||||
Telepath,
|
||||
Viewshed,
|
||||
};
|
||||
use specs::prelude::*;
|
||||
use bracket_lib::prelude::*;
|
||||
|
||||
// Rolling a 1d8+x to decide where to move, where x are the number
|
||||
// of dice rolls in which they will remian stationary. i.e. If this
|
||||
|
|
@ -16,7 +27,7 @@ impl<'a> System<'a> for DefaultAI {
|
|||
WriteStorage<'a, Viewshed>,
|
||||
WriteStorage<'a, Telepath>,
|
||||
WriteStorage<'a, EntityMoved>,
|
||||
WriteExpect<'a, rltk::RandomNumberGenerator>,
|
||||
WriteExpect<'a, RandomNumberGenerator>,
|
||||
Entities<'a>,
|
||||
);
|
||||
|
||||
|
|
@ -85,7 +96,9 @@ impl<'a> System<'a> for DefaultAI {
|
|||
let idx = map.xy_idx(pos.x, pos.y);
|
||||
pos.x = x;
|
||||
pos.y = y;
|
||||
entity_moved.insert(entity, EntityMoved {}).expect("Unable to insert EntityMoved");
|
||||
entity_moved
|
||||
.insert(entity, EntityMoved {})
|
||||
.expect("Unable to insert EntityMoved");
|
||||
crate::spatial::move_entity(entity, idx, dest_idx);
|
||||
viewshed.dirty = true;
|
||||
if let Some(is_telepath) = telepaths.get_mut(entity) {
|
||||
|
|
@ -102,7 +115,9 @@ impl<'a> System<'a> for DefaultAI {
|
|||
if !crate::spatial::is_blocked(path[1] as usize) {
|
||||
pos.x = (path[1] as i32) % map.width;
|
||||
pos.y = (path[1] as i32) / map.width;
|
||||
entity_moved.insert(entity, EntityMoved {}).expect("Unable to insert EntityMoved");
|
||||
entity_moved
|
||||
.insert(entity, EntityMoved {})
|
||||
.expect("Unable to insert EntityMoved");
|
||||
let new_idx = map.xy_idx(pos.x, pos.y);
|
||||
crate::spatial::move_entity(entity, idx, new_idx);
|
||||
viewshed.dirty = true;
|
||||
|
|
@ -112,7 +127,7 @@ impl<'a> System<'a> for DefaultAI {
|
|||
path.remove(0);
|
||||
} else {
|
||||
// If the path is blocked, recalculate a new path to the same waypoint.
|
||||
let path = rltk::a_star_search(
|
||||
let path = a_star_search(
|
||||
map.xy_idx(pos.x, pos.y) as i32,
|
||||
map.xy_idx(
|
||||
(path[path.len() - 1] as i32) % map.width,
|
||||
|
|
@ -121,7 +136,9 @@ impl<'a> System<'a> for DefaultAI {
|
|||
&mut *map
|
||||
);
|
||||
if path.success && path.steps.len() > 1 {
|
||||
move_mode.mode = Movement::RandomWaypoint { path: Some(path.steps) };
|
||||
move_mode.mode = Movement::RandomWaypoint {
|
||||
path: Some(path.steps),
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -132,7 +149,7 @@ impl<'a> System<'a> for DefaultAI {
|
|||
let target_y = rng.roll_dice(1, map.height - 2);
|
||||
let idx = map.xy_idx(target_x, target_y);
|
||||
if tile_walkable(map.tiles[idx]) {
|
||||
let path = rltk::a_star_search(
|
||||
let path = a_star_search(
|
||||
map.xy_idx(pos.x, pos.y) as i32,
|
||||
map.xy_idx(target_x, target_y) as i32,
|
||||
&mut *map
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use crate::{
|
|||
TakingTurn,
|
||||
Confusion,
|
||||
};
|
||||
use rltk::prelude::*;
|
||||
use bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
use crate::config::CONFIG;
|
||||
use crate::data::events::*;
|
||||
|
|
@ -126,7 +126,7 @@ impl<'a> System<'a> for EnergySystem {
|
|||
if entity == *player {
|
||||
*runstate = RunState::AwaitingInput;
|
||||
} else {
|
||||
let distance = rltk::DistanceAlg::Pythagoras.distance2d(
|
||||
let distance = DistanceAlg::Pythagoras.distance2d(
|
||||
*player_pos,
|
||||
Point::new(pos.x, pos.y)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{ EntityMoved, Map, Position, TakingTurn, Telepath, Viewshed, WantsToFlee };
|
||||
use rltk::prelude::*;
|
||||
use bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
|
||||
pub struct FleeAI {}
|
||||
|
|
@ -39,7 +39,13 @@ impl<'a> System<'a> for FleeAI {
|
|||
turn_done.push(entity);
|
||||
let my_idx = map.xy_idx(pos.x, pos.y);
|
||||
map.populate_blocked();
|
||||
let flee_map = DijkstraMap::new(map.width as usize, map.height as usize, &fleeing.indices, &*map, 100.0);
|
||||
let flee_map = DijkstraMap::new(
|
||||
map.width as usize,
|
||||
map.height as usize,
|
||||
&fleeing.indices,
|
||||
&*map,
|
||||
100.0
|
||||
);
|
||||
let flee_target = DijkstraMap::find_highest_exit(&flee_map, my_idx, &*map);
|
||||
if let Some(flee_target) = flee_target {
|
||||
if !crate::spatial::is_blocked(flee_target as usize) {
|
||||
|
|
@ -50,7 +56,9 @@ impl<'a> System<'a> for FleeAI {
|
|||
}
|
||||
pos.x = (flee_target as i32) % map.width;
|
||||
pos.y = (flee_target as i32) / map.width;
|
||||
entity_moved.insert(entity, EntityMoved {}).expect("Unable to insert EntityMoved");
|
||||
entity_moved
|
||||
.insert(entity, EntityMoved {})
|
||||
.expect("Unable to insert EntityMoved");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{ gamelog, gui::renderable_colour, Name, Quips, Renderable, TakingTurn, Viewshed };
|
||||
use rltk::prelude::*;
|
||||
use bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
|
||||
pub struct QuipSystem {}
|
||||
|
|
@ -19,8 +19,18 @@ impl<'a> System<'a> for QuipSystem {
|
|||
|
||||
fn run(&mut self, data: Self::SystemData) {
|
||||
let (entities, mut quips, names, renderables, turns, player_pos, viewsheds, mut rng) = data;
|
||||
for (entity, quip, name, viewshed, _turn) in (&entities, &mut quips, &names, &viewsheds, &turns).join() {
|
||||
if !quip.available.is_empty() && viewshed.visible_tiles.contains(&player_pos) && rng.roll_dice(1, 6) == 1 {
|
||||
for (entity, quip, name, viewshed, _turn) in (
|
||||
&entities,
|
||||
&mut quips,
|
||||
&names,
|
||||
&viewsheds,
|
||||
&turns,
|
||||
).join() {
|
||||
if
|
||||
!quip.available.is_empty() &&
|
||||
viewshed.visible_tiles.contains(&player_pos) &&
|
||||
rng.roll_dice(1, 6) == 1
|
||||
{
|
||||
let quip_index = if quip.available.len() == 1 {
|
||||
0
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::{
|
|||
Item,
|
||||
Prop,
|
||||
};
|
||||
use rltk::prelude::*;
|
||||
use bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
use crate::data::events::*;
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use crate::{
|
|||
WantsToApproach,
|
||||
WantsToFlee,
|
||||
};
|
||||
use rltk::prelude::*;
|
||||
use bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
use std::collections::HashSet;
|
||||
|
||||
|
|
@ -81,10 +81,16 @@ impl<'a> System<'a> for VisibleAI {
|
|||
}
|
||||
reactions.sort_by(|(a, _, _), (b, _, _)| {
|
||||
let (a_x, a_y) = (a % (map.width as usize), a / (map.width as usize));
|
||||
let dist_a = DistanceAlg::PythagorasSquared.distance2d(Point::new(a_x, a_y), Point::new(pos.x, pos.y));
|
||||
let dist_a = DistanceAlg::PythagorasSquared.distance2d(
|
||||
Point::new(a_x, a_y),
|
||||
Point::new(pos.x, pos.y)
|
||||
);
|
||||
let dist_a_estimate = dist_a as i32;
|
||||
let (b_x, b_y) = (b % (map.width as usize), b / (map.width as usize));
|
||||
let dist_b = DistanceAlg::PythagorasSquared.distance2d(Point::new(b_x, b_y), Point::new(pos.x, pos.y));
|
||||
let dist_b = DistanceAlg::PythagorasSquared.distance2d(
|
||||
Point::new(b_x, b_y),
|
||||
Point::new(pos.x, pos.y)
|
||||
);
|
||||
let dist_b_estimate = dist_b as i32;
|
||||
return dist_b_estimate.cmp(&dist_a_estimate);
|
||||
});
|
||||
|
|
@ -96,7 +102,9 @@ impl<'a> System<'a> for VisibleAI {
|
|||
wants_to_approach
|
||||
.insert(entity, WantsToApproach { idx: reaction.0 as i32 })
|
||||
.expect("Error inserting WantsToApproach");
|
||||
chasing.insert(entity, Chasing { target: reaction.2 }).expect("Unable to insert Chasing");
|
||||
chasing
|
||||
.insert(entity, Chasing { target: reaction.2 })
|
||||
.expect("Unable to insert Chasing");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
@ -108,7 +116,9 @@ impl<'a> System<'a> for VisibleAI {
|
|||
}
|
||||
}
|
||||
if !flee.is_empty() {
|
||||
wants_to_flee.insert(entity, WantsToFlee { indices: flee }).expect("Unable to insert");
|
||||
wants_to_flee
|
||||
.insert(entity, WantsToFlee { indices: flee })
|
||||
.expect("Unable to insert");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue