Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. pub unsafe fn queues_frame_hook(queues: &mut Queues, upgrades: &mut Upgrades, ngs: &mut NewGameState, unit_search: &UnitSearch, game: Game) {
  2. use bw_dat::order::{ARCHON_WARP, DARK_ARCHON_MELD, TRAIN, UNIT_MORPH, UPGRADE};
  3. use bw_dat::unit::{ARCHON, DARK_ARCHON};
  4. queues.queue.swap_retain(|x| x.current_quantity > 0);
  5. queues.upgrade_queue
  6. .swap_retain(|x| get_new_upgrade_level_upg(game,upgrades,x.upgrade_id,x.player) <= x.level);
  7. for queue in &mut queues.queue {
  8. let mut units = unit_search
  9. .search_iter(&queue.pos)
  10. .filter(|x| queue.can_train(*x))
  11. .collect::<Vec<_>>();
  12.  
  13. for u in &mut units {
  14. if has_resources(game, u.player(), &ai::unit_cost(queue.unit_id)) {
  15. queue.current_quantity = queue.current_quantity.saturating_sub(1);
  16. match u.id().is_building() {
  17. true => {
  18. let req_ty = match queue.unit_id.0 {
  19. 7|64=>0x4,
  20. _=>0x1,
  21. };
  22. if let Some(town) = queue.town {
  23. if bw::AiTrainUnit(queue.unit_id.0 as u32, req_ty, town.0 as *mut libc::c_void, u.0) == 0 {
  24. debug!("Unable to complete legal/local unit train");
  25. }
  26. }
  27. u.issue_secondary_order(TRAIN);
  28. (*u.0).build_queue[(*u.0).current_build_slot as usize] = queue.unit_id.0;
  29. subtract_cost(game, queue.unit_id, queue.player);
  30. }
  31. false => {
  32. match queue.unit_id {
  33. ARCHON | DARK_ARCHON => {
  34. let order = match queue.unit_id {
  35. ARCHON => ARCHON_WARP,
  36. _ => DARK_ARCHON_MELD,
  37. };
  38. let find_pair = unit_search.find_nearest(u.position(), |x| {
  39. x != *u && x.id() == u.id() && x.order() != order
  40. });
  41. if let Some((unit, _distance)) = find_pair {
  42. if let Some(town) = queue.town {
  43. if bw::AiTrainUnit(queue.unit_id.0 as u32, 0x1, town.0 as *mut libc::c_void, u.0) == 0 {
  44. debug!("Unable to complete legal/local unit train");
  45. }
  46. }
  47. unit.issue_order_unit(order, *u);
  48. u.issue_order_unit(order, unit);
  49. //otherwise guard
  50. //archons have no cost
  51. }
  52. }
  53. _ => {
  54. let req_ty = match queue.unit_id.0 {
  55. 0x29=>0x4,
  56. _=>0x1,
  57. };
  58. if let Some(town) = queue.town {
  59. if bw::AiTrainUnit(queue.unit_id.0 as u32, req_ty, town.0 as *mut libc::c_void,u.0) == 0 {
  60. debug!("Unable to complete legal/local unit train");
  61. }
  62. }
  63. u.issue_order(UNIT_MORPH, u.position(), None);
  64. (*u.0).build_queue[0] = queue.unit_id.0;
  65. if let Some(town) = queue.town {
  66. if bw::AiTrainUnit(queue.unit_id.0 as u32, 0x1, town.0 as *mut libc::c_void,u.0) == 0 {
  67. debug!("Unable to complete legal/local unit train");
  68. }
  69. }
  70. subtract_cost(game, queue.unit_id, queue.player);
  71. }
  72. }
  73. }
  74. }
  75. if queue.current_quantity == 0 {
  76. break;
  77. }
  78. }
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement