16040
|
1 |
mod action;
|
16049
|
2 |
pub mod ammo;
|
16040
|
3 |
|
16039
|
4 |
use crate::GameField;
|
16040
|
5 |
use action::*;
|
16049
|
6 |
use integral_geometry::Point;
|
|
7 |
use std::collections::HashMap;
|
16039
|
8 |
|
|
9 |
pub struct Target {
|
|
10 |
point: Point,
|
|
11 |
health: i32,
|
|
12 |
radius: u32,
|
|
13 |
density: f32,
|
|
14 |
}
|
|
15 |
|
|
16 |
pub struct Hedgehog {
|
|
17 |
pub(crate) x: f32,
|
|
18 |
pub(crate) y: f32,
|
16049
|
19 |
pub(crate) ammo: [u32; ammo::AmmoType::Count as usize],
|
|
20 |
|
16039
|
21 |
}
|
|
22 |
|
|
23 |
pub struct AI<'a> {
|
|
24 |
game_field: &'a GameField,
|
16049
|
25 |
ammo: [u32; ammo::AmmoType::Count as usize],
|
16039
|
26 |
targets: Vec<Target>,
|
|
27 |
team: Vec<Hedgehog>,
|
16040
|
28 |
planned_actions: Option<Actions>,
|
16039
|
29 |
}
|
|
30 |
|
|
31 |
#[derive(Clone)]
|
|
32 |
struct Waypoint {
|
|
33 |
x: f32,
|
|
34 |
y: f32,
|
|
35 |
ticks: usize,
|
|
36 |
damage: usize,
|
|
37 |
previous_point: Option<(usize, Action)>,
|
|
38 |
}
|
|
39 |
|
|
40 |
#[derive(Default)]
|
|
41 |
pub struct Waypoints {
|
|
42 |
key_points: Vec<Waypoint>,
|
|
43 |
points: HashMap<Point, Waypoint>,
|
|
44 |
}
|
|
45 |
|
|
46 |
impl Waypoints {
|
|
47 |
fn add_keypoint(&mut self, waypoint: Waypoint) {
|
|
48 |
let [x, y] = [waypoint.x, waypoint.y].map(|i| i as i32);
|
|
49 |
let point = Point::new(x, y);
|
|
50 |
self.key_points.push(waypoint.clone());
|
|
51 |
self.points.insert(point, waypoint);
|
|
52 |
}
|
|
53 |
}
|
|
54 |
|
|
55 |
impl<'a> AI<'a> {
|
|
56 |
pub fn new(game_field: &'a GameField) -> AI<'a> {
|
|
57 |
Self {
|
|
58 |
game_field,
|
16049
|
59 |
ammo: [0; ammo::AmmoType::Count as usize],
|
16039
|
60 |
targets: vec![],
|
|
61 |
team: vec![],
|
16040
|
62 |
planned_actions: None,
|
16039
|
63 |
}
|
|
64 |
}
|
|
65 |
|
16049
|
66 |
pub fn set_available_ammo(&mut self, ammo: [u32; ammo::AmmoType::Count as usize]) {
|
|
67 |
self.ammo = ammo;
|
|
68 |
}
|
|
69 |
|
16039
|
70 |
pub fn get_team_mut(&mut self) -> &mut Vec<Hedgehog> {
|
|
71 |
&mut self.team
|
|
72 |
}
|
|
73 |
|
|
74 |
pub fn walk(hedgehog: &Hedgehog) {
|
|
75 |
let mut stack = Vec::<usize>::new();
|
|
76 |
let mut waypoints = Waypoints::default();
|
|
77 |
|
16049
|
78 |
waypoints.add_keypoint(Waypoint {
|
16039
|
79 |
x: hedgehog.x,
|
|
80 |
y: hedgehog.y,
|
|
81 |
ticks: 0,
|
|
82 |
damage: 0,
|
|
83 |
previous_point: None,
|
|
84 |
});
|
|
85 |
|
16049
|
86 |
while let Some(wp) = stack.pop() {}
|
16039
|
87 |
}
|
16040
|
88 |
|
|
89 |
pub fn have_plan(&self) -> bool {
|
|
90 |
self.planned_actions.is_some()
|
|
91 |
}
|
|
92 |
}
|