bracket_algorithm_traits/
basemap.rs

1//! # `BaseMap`
2//!
3//! `BaseMap` provides map traits required for path-finding and field-of-view operations. Implement these
4//! if you want to use these features from `bracket-lib`.
5//!
6//! `is_opaque` specifies is you can see through a tile, required for field-of-view.
7//!
8//! `get_available_exits` lists the indices to which one can travel from a given tile, along with a relative
9//! cost of each exit. Required for path-finding.
10//!
11//! `get_pathing_distance` allows you to implement your heuristic for determining remaining distance to a
12//! target.
13
14use smallvec::SmallVec;
15
16/// Implement this trait to support path-finding functions.
17pub trait BaseMap {
18    /// True is you cannot see through the tile, false otherwise. Default implementation
19    /// always returns true, and is provided so you don't have to implement it if you
20    /// aren't using it.
21    fn is_opaque(&self, _idx: usize) -> bool {
22        true
23    }
24
25    /// Return a vector of tile indices to which one can path from the idx.
26    /// These do NOT have to be contiguous - if you want to support teleport pads, that's awesome.
27    /// Default implementation is provided that proves an empty list, in case you aren't using
28    /// it.
29    ///
30    /// Note that you should never return the current tile as an exit. The A* implementation
31    /// really doesn't like that.
32    fn get_available_exits(&self, _idx: usize) -> SmallVec<[(usize, f32); 10]> {
33        SmallVec::new()
34    }
35
36    /// Return the distance you would like to use for path-finding. Generally, Pythagoras distance (implemented in geometry)
37    /// is fine, but you might use Manhattan or any other heuristic that fits your problem.
38    /// Default implementation returns 1.0, which isn't what you want but prevents you from
39    /// having to implement it when not using it.
40    fn get_pathing_distance(&self, _idx1: usize, _idx2: usize) -> f32 {
41        1.0
42    }
43}