Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub unsafe fn queues_frame_hook(queues: &mut Queues, upgrades: &mut Upgrades, ngs: &mut NewGameState, unit_search: &UnitSearch, game: Game) {
- use bw_dat::order::{ARCHON_WARP, DARK_ARCHON_MELD, TRAIN, UNIT_MORPH, UPGRADE};
- use bw_dat::unit::{ARCHON, DARK_ARCHON};
- queues.queue.swap_retain(|x| x.current_quantity > 0);
- queues.upgrade_queue
- .swap_retain(|x| get_new_upgrade_level_upg(game,upgrades,x.upgrade_id,x.player) <= x.level);
- for queue in &mut queues.queue {
- let mut units = unit_search
- .search_iter(&queue.pos)
- .filter(|x| queue.can_train(*x))
- .collect::<Vec<_>>();
- for u in &mut units {
- if has_resources(game, u.player(), &ai::unit_cost(queue.unit_id)) {
- queue.current_quantity = queue.current_quantity.saturating_sub(1);
- match u.id().is_building() {
- true => {
- let req_ty = match queue.unit_id.0 {
- 7|64=>0x4,
- _=>0x1,
- };
- if let Some(town) = queue.town {
- if bw::AiTrainUnit(queue.unit_id.0 as u32, req_ty, town.0 as *mut libc::c_void, u.0) == 0 {
- debug!("Unable to complete legal/local unit train");
- }
- }
- u.issue_secondary_order(TRAIN);
- (*u.0).build_queue[(*u.0).current_build_slot as usize] = queue.unit_id.0;
- subtract_cost(game, queue.unit_id, queue.player);
- }
- false => {
- match queue.unit_id {
- ARCHON | DARK_ARCHON => {
- let order = match queue.unit_id {
- ARCHON => ARCHON_WARP,
- _ => DARK_ARCHON_MELD,
- };
- let find_pair = unit_search.find_nearest(u.position(), |x| {
- x != *u && x.id() == u.id() && x.order() != order
- });
- if let Some((unit, _distance)) = find_pair {
- if let Some(town) = queue.town {
- if bw::AiTrainUnit(queue.unit_id.0 as u32, 0x1, town.0 as *mut libc::c_void, u.0) == 0 {
- debug!("Unable to complete legal/local unit train");
- }
- }
- unit.issue_order_unit(order, *u);
- u.issue_order_unit(order, unit);
- //otherwise guard
- //archons have no cost
- }
- }
- _ => {
- let req_ty = match queue.unit_id.0 {
- 0x29=>0x4,
- _=>0x1,
- };
- if let Some(town) = queue.town {
- if bw::AiTrainUnit(queue.unit_id.0 as u32, req_ty, town.0 as *mut libc::c_void,u.0) == 0 {
- debug!("Unable to complete legal/local unit train");
- }
- }
- u.issue_order(UNIT_MORPH, u.position(), None);
- (*u.0).build_queue[0] = queue.unit_id.0;
- if let Some(town) = queue.town {
- if bw::AiTrainUnit(queue.unit_id.0 as u32, 0x1, town.0 as *mut libc::c_void,u.0) == 0 {
- debug!("Unable to complete legal/local unit train");
- }
- }
- subtract_cost(game, queue.unit_id, queue.player);
- }
- }
- }
- }
- if queue.current_quantity == 0 {
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement