Advertisement
Pr0nogo

Untitled

Aug 9th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. pub unsafe fn start_building_hook(
  2. builder: *mut bw::Unit,
  3. orig: &Fn(*mut bw::Unit)->u32,
  4. ) -> u32 {
  5. let result = orig(builder);
  6. let builder = match Unit::from_ptr(builder) {
  7. Some(s) => s,
  8. None => return result,
  9. };
  10. let game = Game::get();
  11. let globals = Globals::get("start building hook");
  12. let unit_search = UnitSearch::from_bw();
  13. let assume_pushing_units = globals.ai_mode[builder.player() as usize].move_from_baselayout;
  14. if builder.player()>=8 {
  15. return orig(builder);
  16. }
  17. if assume_pushing_units {
  18. let ok = check_placement(game, &unit_search, builder,
  19. ((*builder.0).order_target_pos.x as i16)/32,
  20. ((*builder.0).order_target_pos.y as i16)/32,
  21. builder.id(),
  22. assume_pushing_units,
  23. (*builder.0).order_target_pos);
  24. let area = bw::Rect {
  25. left: (builder.position().x).saturating_sub(32),
  26. top: (builder.position().y).saturating_sub(32),
  27. right: (builder.position().x) + (builder.id().placement().width as i16 / 2).saturating_add(32),
  28. bottom: (builder.position().y) + (builder.id().placement().height as i16 / 2).saturating_add(32),
  29. };
  30. let units = unit_search
  31. .search_iter(&area)
  32. .filter(|u| u.burrowed() && *u!=builder);
  33. for unit in units {
  34. bw::unburrow(unit.0);
  35. }
  36. if ok
  37. {
  38. return 1;
  39. }
  40. }
  41. result
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement