fn path_finder(
        &self,
        start_x: i64,
        start_y: i64,
        mut destination_x: i64,
        mut destination_y: i64,
        map: &Map,
        players: &[Player],
        npcs: &[Box<dyn Enemy>],
        step: i64,
        target_id: Option<Id>,
    ) -> Option<Vec<(i64, i64)>> {
        destination_x -= destination_x % step;
        destination_y -= destination_y % step;

        let destination = (destination_x, destination_y);

        let mut closed_list = Vec::new();
        let mut open_list = BinaryHeap::new();
        let mut start_node = Node::new(start_x - start_x % step, start_y - start_y % step, 0);
        start_node.compute_heuristic(&destination);
        // Since we always want the node with the lowest heuristic at each turn,
        open_list.push(Reverse(start_node));

        let mut limit = 200;
        while let Some(node) = open_list.pop() {
            limit -= 1;
            if limit == 0 {
                break;
            }
            let node = node.0;
            if node.x != self.x() || node.y != self.y() {
                closed_list.push((node.x, node.y));
            }
            if node.x == destination_x && node.y == destination_y {
                // We're done!
                // We reverse the order so we go from the last node to the first one.
                closed_list.reverse();
                return Some(closed_list);
            } else {
                let nodes = vec![
                    Node::new(node.x + step, node.y, node.cost + 1),
                    Node::new(node.x + step, node.y + step, node.cost + 1),
                    Node::new(node.x, node.y + step, node.cost + 1),
                    Node::new(node.x - step, node.y + step, node.cost + 1),
                    Node::new(node.x - step, node.y, node.cost + 1),
                    Node::new(node.x - step, node.y - step, node.cost + 1),
                    Node::new(node.x, node.y - step, node.cost + 1),
                    Node::new(node.x + step, node.y - step, node.cost + 1),
                ]
                .into_iter()
                .filter(|entry| {
                    self.character
                        .check_map_pos(map, players, npcs, entry.x, entry.y, target_id)
                        == Obstacle::None
                        && !closed_list
                            .iter()
                            .any(|entry2| entry.x == entry2.0 && entry.y == entry2.1)
                        && !open_list.iter().any(|entry2: &Reverse<Node>| {
                            *entry == entry2.0 && entry.cost >= entry2.0.cost
                        })
                })
                .collect::<Vec<_>>();
                for mut node in nodes {
                    node.compute_heuristic(&destination);
                    open_list.push(Reverse(node));
                }
            }
        }
        None
    }
/// This method is used when we encountered an obstacle only!
This method is used when we encountered an obstacle only!
This method is used when we encountered an obstacle only!
fn path_finder(
        &self,
        start_x: i64,
        start_y: i64,
        mut destination_x: i64,
        mut destination_y: i64,
        map: &Map,
        players: &[Player],
        npcs: &[Box<dyn Enemy>],
        step: i64,
        target_id: Option<Id>,
    ) -> Option<Vec<(i64, i64)>> {
        destination_x -= destination_x % step;
        destination_y -= destination_y % step;
        let destination = (destination_x, destination_y);
        let mut closed_list = Vec::new();
        let mut open_list = BinaryHeap::new();
        let mut start_node = Node::new(start_x - start_x % step, start_y - start_y % step, 0);
        start_node.compute_heuristic(&destination);
        // Since we always want the node with the lowest heuristic at each turn,
        open_list.push(Reverse(start_node));
        let mut limit = 200;
        while let Some(node) = open_list.pop() {
            limit -= 1;
            if limit == 0 {
                break;
            }
            let node = node.0;
            if node.x != self.x() || node.y != self.y() {
                closed_list.push((node.x, node.y));
            }
            if node.x == destination_x && node.y == destination_y {
                // We're done!
                // We reverse the order so we go from the last node to the first one.
                closed_list.reverse();
                return Some(closed_list);
            } else {
                let nodes = vec![
                    Node::new(node.x + step, node.y, node.cost + 1),
                    Node::new(node.x + step, node.y + step, node.cost + 1),
                    Node::new(node.x, node.y + step, node.cost + 1),
                    Node::new(node.x - step, node.y + step, node.cost + 1),
                    Node::new(node.x - step, node.y, node.cost + 1),
                    Node::new(node.x - step, node.y - step, node.cost + 1),
                    Node::new(node.x, node.y - step, node.cost + 1),
                    Node::new(node.x + step, node.y - step, node.cost + 1),
                ]
                .into_iter()
                .filter(|entry| {
                    self.character
                        .check_map_pos(map, players, npcs, entry.x, entry.y, target_id)
                        == Obstacle::None
                        && !closed_list
                            .iter()
                            .any(|entry2| entry.x == entry2.0 && entry.y == entry2.1)
                        && !open_list.iter().any(|entry2: &Reverse<Node>| {
                            *entry == entry2.0 && entry.cost >= entry2.0.cost
                        })
                })
                .collect::<Vec<_>>();
                for mut node in nodes {
                    node.compute_heuristic(&destination);
                    open_list.push(Reverse(node));
                }
            }
        }
        None
    }
fn path_finder ( & self , start_x : i64 , start_y : i64 , mut destination_x : i64 , mut destination_y : i64 , map : & Map , players : & [ Player ] , npcs : & [ Box < dyn Enemy > ] , step : i64 , target_id : Option < Id > , ) -> Option < Vec < ( i64 , i64 ) > > { destination_x -= destination_x % step ; destination_y -= destination_y % step ; let destination = ( destination_x , destination_y ) ; let mut closed_list = Vec :: new ( ) ; let mut open_list = BinaryHeap :: new ( ) ; let mut start_node = Node :: new ( start_x - start_x % step , start_y - start_y % step , 0 ) ; start_node . compute_heuristic ( & destination ) ; // Since we always want the node with the lowest heuristic at each turn, open_list . push ( Reverse ( start_node ) ) ; let mut limit = 200 ; while let Some ( node ) = open_list . pop ( ) { limit -= 1 ; if limit == 0 { break ; } let node = node . 0 ; if node . x != self . x ( ) || node . y != self . y ( ) { closed_list . push ( ( node . x , node . y ) ) ; } if node . x == destination_x && node . y == destination_y { // We're done! // We reverse the order so we go from the last node to the first one. closed_list . reverse ( ) ; return Some ( closed_list ) ; } else { let nodes = vec ! [ Node new ( node x step node y node cost 1 ) Node new ( node x step node y step node cost 1 ) Node new ( node x node y step node cost 1 ) Node new ( node x step node y step node cost 1 ) Node new ( node x step node y node cost 1 ) Node new ( node x step node y step node cost 1 ) Node new ( node x node y step node cost 1 ) Node new ( node x step node y step node cost 1 ) ] . into_iter ( ) . filter ( | entry | { self . character . check_map_pos ( map , players , npcs , entry . x , entry . y , target_id ) == Obstacle :: None && ! closed_list . iter ( ) . any ( | entry2 | entry . x == entry2 . 0 && entry . y == entry2 . 1 ) && ! open_list . iter ( ) . any ( | entry2 : & Reverse < Node > | { * entry == entry2 . 0 && entry . cost >= entry2 . 0 . cost } ) } ) . collect :: < Vec < _ > > ( ) ; for mut node in nodes { node . compute_heuristic ( & destination ) ; open_list . push ( Reverse ( node ) ) ; } } } None }
This method is used when we encountered an obstacle only!
This method is used when we encountered an obstacle only!
&self
start_x
i64
start_y
i64
destination_x
i64
destination_y
i64
map
&Map
players
&[Player]
npcs
&[Box<dyn Enemy>]
step
i64
target_id
Option<Id>