From 9d13c1d67ed42cd281be8cea78319b128559f45d Mon Sep 17 00:00:00 2001 From: Markus Heikkinen Date: Wed, 20 Feb 2019 04:41:53 +0200 Subject: [PATCH] Fix dual birth ai --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/lib.rs | 15 +++++++++++++++ src/list.rs | 10 ++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7281af8..adc509f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,7 +7,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "aise" -version = "2.21.3" +version = "2.21.4" dependencies = [ "backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 539fdb9..126de55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aise" -version = "2.21.3" +version = "2.21.4" authors = ["Markus Heikkinen "] [lib] diff --git a/src/lib.rs b/src/lib.rs index 76c4914..25339e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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); + } + } + } + } } } diff --git a/src/list.rs b/src/list.rs index 099a1ef..3ba896a 100644 --- a/src/list.rs +++ b/src/list.rs @@ -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(pub *mut T); impl Iterator for ListIter {