Advertisement
Pr0nogo

Untitled

Dec 24th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. /// NOTE: Differs from bw function in that it doesn't immediatly do one frame step.
  2. /// If this is called somewhere else than just zerg birth order, it should be done afterwards.
  3. pub unsafe fn add_military_ai(unit: Unit, region: *mut bw::AiRegion, always_this_region: bool) {
  4. assert!((*unit.0).ai.is_null());
  5. let region = if !always_this_region && (*region).state == 3 {
  6. // ai_region(unit.player(), unit.position()).expect("Unit out of bounds??")
  7. let regions = bw::ai_regions(unit.player() as u32);
  8. ai_region(regions, unit.position()).expect("Unit out of bounds??")
  9. } else {
  10. region
  11. };
  12.  
  13. let array = (*region).military.array;
  14. let ai = (*array).first_free;
  15. if ai.is_null() {
  16. warn!("Military ai limit");
  17. return;
  18. }
  19. ListEntry::move_to(ai, &mut (*array).first_free, &mut (*region).military.first);
  20. (*ai).ai_type = 4; // Unnecessary?
  21. (*ai).parent = unit.0;
  22. (*ai).region = region;
  23. (*unit.0).ai = ai as *mut c_void;
  24. if unit.is_air() {
  25. (*region).needed_air_strength = (*region).needed_air_strength.saturating_add(1); // Why?
  26. }
  27. match (*region).state {
  28. 1 | 2 | 8 | 9 => update_slowest_unit_in_region(region),
  29. _ => (),
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement