pub unsafe fn prepare_issue_order(
    bw: &'static BwScr,
    unit: Unit,
    order: OrderId,
    x: i16,
    y: i16,
    target: Option<Unit>,
    fow_unit_id: u16,
    clear_queue: bool,
) {
    if unit.order() == order::DIE {
        return;
    }
    // Delete queued copies of this order, or all orders up to uninterruptable
    // order, if any, when `clear_queue` is set.
    let free_orders = bw.free_orders.resolve();
    let queue = bw::list::LinkedList {
        start: ptr::addr_of_mut!((**unit).order_queue_begin),
        end: ptr::addr_of_mut!((**unit).order_queue_end),
    };
    let mut allocated_order_count = bw.allocated_order_count.resolve();
    while let Some(last_queued) = queue.last() {
        let last_queued_id = OrderId((*last_queued).order_id);
        let delete = last_queued_id == order ||
            (clear_queue && last_queued_id.interruptable());
        if !delete {
            break;
        }
        if last_queued_id.icon() != 0xffff {
            (**unit).highlight_order_count = (**unit).highlight_order_count.wrapping_sub(1);
        }
        queue.remove(last_queued);
        free_orders.add(last_queued);
        allocated_order_count -= 1;
    }
    bw.allocated_order_count.write(allocated_order_count);
    if !can_allocate_order(bw, unit, order) {
        return;
    }
    // Note for people comparing this function with BW's disassembly:
    // The disassembly has checks for if order == CLOAK and logic to requeue
    // current order after cloak order, but this is dead (and broken) code,
    // and not how cloaking works, so it is not replicated here.
    if let Some(alloc) = free_orders.alloc() {
        let new_order = alloc.value();
        (*new_order).order_id = order.0;
        (*new_order).unit_id = fow_unit_id;
        (*new_order).position.x = x;
        (*new_order).position.y = y;
        (*new_order).target = target.map(|x| *x).unwrap_or(null_mut());
        alloc.append_to(&queue);
        if order.icon() != 0xffff {
            (**unit).highlight_order_count = (**unit).highlight_order_count.wrapping_add(1);
        }
        bw.allocated_order_count.write(allocated_order_count + 1);
    } else {
        warn!("Unable to allocate order");
    }
}
/// Change order allocation limits to be better what SC:R does.
Change order allocation limits to be better what SC:R does.
Change order allocation limits to be better what SC : R does .
pub unsafe fn prepare_issue_order(
    bw: &'static BwScr,
    unit: Unit,
    order: OrderId,
    x: i16,
    y: i16,
    target: Option<Unit>,
    fow_unit_id: u16,
    clear_queue: bool,
) {
    if unit.order() == order::DIE {
        return;
    }
    // Delete queued copies of this order, or all orders up to uninterruptable
    // order, if any, when `clear_queue` is set.
    let free_orders = bw.free_orders.resolve();
    let queue = bw::list::LinkedList {
        start: ptr::addr_of_mut!((**unit).order_queue_begin),
        end: ptr::addr_of_mut!((**unit).order_queue_end),
    };
    let mut allocated_order_count = bw.allocated_order_count.resolve();
    while let Some(last_queued) = queue.last() {
        let last_queued_id = OrderId((*last_queued).order_id);
        let delete = last_queued_id == order ||
            (clear_queue && last_queued_id.interruptable());
        if !delete {
            break;
        }
        if last_queued_id.icon() != 0xffff {
            (**unit).highlight_order_count = (**unit).highlight_order_count.wrapping_sub(1);
        }
        queue.remove(last_queued);
        free_orders.add(last_queued);
        allocated_order_count -= 1;
    }
    bw.allocated_order_count.write(allocated_order_count);
    if !can_allocate_order(bw, unit, order) {
        return;
    }
    // Note for people comparing this function with BW's disassembly:
    // The disassembly has checks for if order == CLOAK and logic to requeue
    // current order after cloak order, but this is dead (and broken) code,
    // and not how cloaking works, so it is not replicated here.
    if let Some(alloc) = free_orders.alloc() {
        let new_order = alloc.value();
        (*new_order).order_id = order.0;
        (*new_order).unit_id = fow_unit_id;
        (*new_order).position.x = x;
        (*new_order).position.y = y;
        (*new_order).target = target.map(|x| *x).unwrap_or(null_mut());
        alloc.append_to(&queue);
        if order.icon() != 0xffff {
            (**unit).highlight_order_count = (**unit).highlight_order_count.wrapping_add(1);
        }
        bw.allocated_order_count.write(allocated_order_count + 1);
    } else {
        warn!("Unable to allocate order");
    }
}
pub unsafe fn prepare_issue_order ( bw : & ' static BwScr , unit : Unit , order : OrderId , x : i16 , y : i16 , target : Option < Unit > , fow_unit_id : u16 , clear_queue : bool , ) { if unit . order ( ) == order :: DIE { return ; } // Delete queued copies of this order, or all orders up to uninterruptable // order, if any, when `clear_queue` is set. let free_orders = bw . free_orders . resolve ( ) ; let queue = bw :: list :: LinkedList { start : ptr :: addr_of_mut ! ( ( unit ) order_queue_begin ) , end : ptr :: addr_of_mut ! ( ( unit ) order_queue_end ) , } ; let mut allocated_order_count = bw . allocated_order_count . resolve ( ) ; while let Some ( last_queued ) = queue . last ( ) { let last_queued_id = OrderId ( ( * last_queued ) . order_id ) ; let delete = last_queued_id == order || ( clear_queue && last_queued_id . interruptable ( ) ) ; if ! delete { break ; } if last_queued_id . icon ( ) != 0xffff { ( * * unit ) . highlight_order_count = ( * * unit ) . highlight_order_count . wrapping_sub ( 1 ) ; } queue . remove ( last_queued ) ; free_orders . add ( last_queued ) ; allocated_order_count -= 1 ; } bw . allocated_order_count . write ( allocated_order_count ) ; if ! can_allocate_order ( bw , unit , order ) { return ; } // Note for people comparing this function with BW's disassembly: // The disassembly has checks for if order == CLOAK and logic to requeue // current order after cloak order, but this is dead (and broken) code, // and not how cloaking works, so it is not replicated here. if let Some ( alloc ) = free_orders . alloc ( ) { let new_order = alloc . value ( ) ; ( * new_order ) . order_id = order . 0 ; ( * new_order ) . unit_id = fow_unit_id ; ( * new_order ) . position . x = x ; ( * new_order ) . position . y = y ; ( * new_order ) . target = target . map ( | x | * x ) . unwrap_or ( null_mut ( ) ) ; alloc . append_to ( & queue ) ; if order . icon ( ) != 0xffff { ( * * unit ) . highlight_order_count = ( * * unit ) . highlight_order_count . wrapping_add ( 1 ) ; } bw . allocated_order_count . write ( allocated_order_count + 1 ) ; } else { warn ! ( " " ) ; } }
Change order allocation limits to be better what SC:R does.
Change order allocation limits to be better what SC : R does .
bw
&'static BwScr
unit
Unit
order
OrderId
x
i16
y
i16
target
Option<Unit>
fow_unit_id
u16
clear_queue
bool
bw
&'static BwScr
unit
Unit
order
OrderId
x
i16
y
i16
target
Option<Unit>
fow_unit_id
u16
clear_queue
bool