Skip to content

Commit

Permalink
Redefine idle_orders in_combat
Browse files Browse the repository at this point in the history
Now it passes if either the unit has a cooldown active
(It attacked recently), or an enemy is targeting it and close enough to
attack.
  • Loading branch information
neivv committed Mar 20, 2019
1 parent 3b31b16 commit f987e0e
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 40 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ byteorder = "1.1"
chrono = "0.4"
directories = "1.0.2"
fern = "0.5"
fxhash = "0.2.1"
lazy_static = "1.0"
libc = "0.2"
log = "0.4"
Expand Down
8 changes: 8 additions & 0 deletions bw_dat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ impl UnitId {
pub fn rclick_action(&self) -> u8 {
self.get(28) as u8
}

pub fn sight_range(&self) -> u32 {
self.get(24)
}
}

#[derive(Eq, PartialEq, Copy, Clone)]
Expand Down Expand Up @@ -409,6 +413,10 @@ impl WeaponId {
pub fn label(&self) -> u32 {
self.get(0)
}

pub fn max_range(&self) -> u32 {
self.get(5)
}
}

impl UpgradeId {
Expand Down
30 changes: 30 additions & 0 deletions src/bw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,36 @@ pub fn distance(a: Point, b: Point) -> u32 {
}
}

pub fn rect_distance(a: &Rect, b: &Rect) -> u32 {
let horizontal_overlap = a.left < b.right && a.right > b.left;
let vertical_overlap = a.top < b.bottom && a.bottom > b.top;
let x_diff = match horizontal_overlap {
true => 0,
false => match a.left < b.left {
true => b.left - a.right,
false => a.left - b.right,
},
};
let y_diff = match vertical_overlap {
true => 0,
false => match a.top < b.top {
true => b.top - a.bottom,
false => a.top - b.bottom,
},
};

distance(
Point {
x: 0,
y: 0,
},
Point {
x: x_diff,
y: y_diff,
},
)
}

pub fn town_array_start() -> *mut AiTown {
let ptr = samase::active_towns();
if ptr.is_null() {
Expand Down
Loading

0 comments on commit f987e0e

Please sign in to comment.