fn ai_basic(monster_id: usize, tcod: &Tcod, game: &mut Game, objects: &mut [Object]) -> Ai {
    // a basic monster takes its turn. If you can see it, it can see you
    let (monster_x, monster_y) = objects[monster_id].pos();
    if tcod.fov.is_in_fov(monster_x, monster_y) {
        if objects[monster_id].distance_to(&objects[PLAYER]) >= 2.0 {
            // move towards player if far away
            let (player_x, player_y) = objects[PLAYER].pos();
            object_move_towards(monster_id, player_x, player_y, &game.map, objects);
        } else if objects[PLAYER].fighter.map_or(false, |f| f.hp > 0) {
            // close enough, attack! (if the player is still alive.)
            let (monster, player) = mut_two(monster_id, PLAYER, objects);
            monster.attack(player, game);
        }
    }
    Ai::Basic
}
/// basic ai type (follows player if in range)
basic ai type (follows player if in range)
basic ai type ( follows player if in range )
fn ai_basic(monster_id: usize, tcod: &Tcod, game: &mut Game, objects: &mut [Object]) -> Ai {
    // a basic monster takes its turn. If you can see it, it can see you
    let (monster_x, monster_y) = objects[monster_id].pos();
    if tcod.fov.is_in_fov(monster_x, monster_y) {
        if objects[monster_id].distance_to(&objects[PLAYER]) >= 2.0 {
            // move towards player if far away
            let (player_x, player_y) = objects[PLAYER].pos();
            object_move_towards(monster_id, player_x, player_y, &game.map, objects);
        } else if objects[PLAYER].fighter.map_or(false, |f| f.hp > 0) {
            // close enough, attack! (if the player is still alive.)
            let (monster, player) = mut_two(monster_id, PLAYER, objects);
            monster.attack(player, game);
        }
    }
    Ai::Basic
}
fn ai_basic ( monster_id : usize , tcod : & Tcod , game : & mut Game , objects : & mut [ Object ] ) -> Ai { // a basic monster takes its turn. If you can see it, it can see you let ( monster_x , monster_y ) = objects [ monster_id ] . pos ( ) ; if tcod . fov . is_in_fov ( monster_x , monster_y ) { if objects [ monster_id ] . distance_to ( & objects [ PLAYER ] ) >= 2.0 { // move towards player if far away let ( player_x , player_y ) = objects [ PLAYER ] . pos ( ) ; object_move_towards ( monster_id , player_x , player_y , & game . map , objects ) ; } else if objects [ PLAYER ] . fighter . map_or ( false , | f | f . hp > 0 ) { // close enough, attack! (if the player is still alive.) let ( monster , player ) = mut_two ( monster_id , PLAYER , objects ) ; monster . attack ( player , game ) ; } } Ai :: Basic }
basic ai type (follows player if in range)
basic ai type ( follows player if in range )
monster_id
usize
tcod
&Tcod
game
&mut Game
objects
&mut [Object]