Skip to content

Commit

Permalink
Fix dual birth ai
Browse files Browse the repository at this point in the history
  • Loading branch information
neivv committed Feb 20, 2019
1 parent 8ea165c commit 9d13c1d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aise"
version = "2.21.3"
version = "2.21.4"
authors = ["Markus Heikkinen <ittevien@gmail.com>"]

[lib]
Expand Down
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,21 @@ unsafe extern fn step_order_hook(u: *mut c_void, orig: unsafe extern fn(*mut c_v
}
if let Some(ai) = temp_ai {
(*unit.0).ai = ai;
// Add ai for dual birthed units
if unit.id().flags() & 0x400 != 0 {
// Bw inserts shown units at second pos for some reason..
if let Some(other) = unit::active_units().nth(1) {
// This gets actually checked several times since the birth order lasts a few
// frames, but it should be fine.
if other.id() == unit.id() && (*other.0).ai.is_null() {
if other.player() == unit.player() {
let region = ai::ai_region(other.player(), other.position())
.expect("Unit out of bounds??");
ai::add_military_ai(other, region, false);
}
}
}
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ impl ListEntry for bw::MilitaryAi {
}
}

impl ListEntry for bw::Unit {
unsafe fn next(x: *mut Self) -> *mut *mut Self {
&mut (*x).next
}

unsafe fn prev(x: *mut Self) -> *mut *mut Self {
&mut (*x).prev
}
}

pub struct ListIter<T: ListEntry>(pub *mut T);

impl<T: ListEntry> Iterator for ListIter<T> {
Expand Down

0 comments on commit 9d13c1d

Please sign in to comment.