rust/lib-hwengine-future/src/ai/mod.rs
branchtransitional_engine
changeset 16049 db18f1a30b0c
parent 16040 6c5b3c576fc6
equal deleted inserted replaced
16048:67469603872a 16049:db18f1a30b0c
     1 mod action;
     1 mod action;
       
     2 pub mod ammo;
     2 
     3 
     3 use std::collections::HashMap;
       
     4 use integral_geometry::Point;
       
     5 use crate::GameField;
     4 use crate::GameField;
     6 use action::*;
     5 use action::*;
       
     6 use integral_geometry::Point;
       
     7 use std::collections::HashMap;
     7 
     8 
     8 pub struct Target {
     9 pub struct Target {
     9     point: Point,
    10     point: Point,
    10     health: i32,
    11     health: i32,
    11     radius: u32,
    12     radius: u32,
    12     density: f32,
    13     density: f32,
    13 
       
    14 }
    14 }
    15 
    15 
    16 pub struct Hedgehog {
    16 pub struct Hedgehog {
    17     pub(crate) x: f32,
    17     pub(crate) x: f32,
    18     pub(crate) y: f32,
    18     pub(crate) y: f32,
       
    19     pub(crate) ammo: [u32; ammo::AmmoType::Count as usize],
       
    20 
    19 }
    21 }
    20 
    22 
    21 pub struct AI<'a> {
    23 pub struct AI<'a> {
    22     game_field: &'a GameField,
    24     game_field: &'a GameField,
       
    25     ammo: [u32; ammo::AmmoType::Count as usize],
    23     targets: Vec<Target>,
    26     targets: Vec<Target>,
    24     team: Vec<Hedgehog>,
    27     team: Vec<Hedgehog>,
    25     planned_actions: Option<Actions>,
    28     planned_actions: Option<Actions>,
    26 }
    29 }
    27 
    30 
    51 
    54 
    52 impl<'a> AI<'a> {
    55 impl<'a> AI<'a> {
    53     pub fn new(game_field: &'a GameField) -> AI<'a> {
    56     pub fn new(game_field: &'a GameField) -> AI<'a> {
    54         Self {
    57         Self {
    55             game_field,
    58             game_field,
       
    59             ammo: [0; ammo::AmmoType::Count as usize],
    56             targets: vec![],
    60             targets: vec![],
    57             team: vec![],
    61             team: vec![],
    58             planned_actions: None,
    62             planned_actions: None,
    59         }
    63         }
       
    64     }
       
    65 
       
    66     pub fn set_available_ammo(&mut self, ammo: [u32; ammo::AmmoType::Count as usize]) {
       
    67         self.ammo = ammo;
    60     }
    68     }
    61 
    69 
    62     pub fn get_team_mut(&mut self) -> &mut Vec<Hedgehog> {
    70     pub fn get_team_mut(&mut self) -> &mut Vec<Hedgehog> {
    63         &mut self.team
    71         &mut self.team
    64     }
    72     }
    65 
    73 
    66     pub fn walk(hedgehog: &Hedgehog) {
    74     pub fn walk(hedgehog: &Hedgehog) {
    67         let mut stack = Vec::<usize>::new();
    75         let mut stack = Vec::<usize>::new();
    68         let mut waypoints = Waypoints::default();
    76         let mut waypoints = Waypoints::default();
    69 
    77 
    70         waypoints.add_keypoint(Waypoint{
    78         waypoints.add_keypoint(Waypoint {
    71             x: hedgehog.x,
    79             x: hedgehog.x,
    72             y: hedgehog.y,
    80             y: hedgehog.y,
    73             ticks: 0,
    81             ticks: 0,
    74             damage: 0,
    82             damage: 0,
    75             previous_point: None,
    83             previous_point: None,
    76         });
    84         });
    77 
    85 
    78         while let Some(wp) = stack.pop() {
    86         while let Some(wp) = stack.pop() {}
    79 
       
    80         }
       
    81     }
    87     }
    82 
    88 
    83     pub fn have_plan(&self) -> bool {
    89     pub fn have_plan(&self) -> bool {
    84         self.planned_actions.is_some()
    90         self.planned_actions.is_some()
    85     }
    91     }