/// Determine if potential enemy is in range, if not proceed to move and rescan
Determine if potential enemy is in range, if not proceed to move and rescan
Determine if potential enemy is in range if not proceed to move and rescan
fn find_raid(mech: &impl MechInstruments) -> Vec<MechCommand> {
     match mech.last_radar_scan() {
          Some(scan) => {
               if let Some(RegisterValue::Text(enemy_id)) = mech.register_get(EBX) {
                    if let Some(enemy) = scan
                         .iter()
                         .filter(|p| p.id == *enemy_id)
                         .collect::<Vec<_>>()
                         .get(0)
                    {
                         times_up_lets_do_this(mech, enemy)
                    } else {
                         vec![
                              move_mech(mech),
                              move_mech(mech),
                              move_mech(mech),
                              mech.request_radar(),
                         ]
                    }
               } else if let Some(enemy) = scan
                    .iter()
                    .filter(|p| p.foe)
                    .filter(|p| distance_to(&mech.position(), &p.location) <= mech.primary_range())
                    .collect::<Vec<_>>()
                    .get(0)
               {
                    vec![
                         mech.fire_primary(mech.direction_to(&enemy.location)),
                         mech.move_mech(mech.direction_to(&enemy.location)),
                         mech.move_mech(mech.direction_to(&enemy.location)),
                         mech.register_set(EBX, RegisterValue::Text(enemy.id.to_string())),
                    ]
               } else {
                    vec![
                         move_mech(mech),
                         move_mech(mech),
                         move_mech(mech),
                         mech.request_radar(),
                    ]
               }
          }
          None => vec![
               move_mech(mech),
               move_mech(mech),
               move_mech(mech),
               mech.request_radar(),
          ],
     }
}
fn find_raid ( mech : & impl MechInstruments ) -> Vec < MechCommand > { match mech . last_radar_scan ( ) { Some ( scan ) => { if let Some ( RegisterValue :: Text ( enemy_id ) ) = mech . register_get ( EBX ) { if let Some ( enemy ) = scan . iter ( ) . filter ( | p | p . id == * enemy_id ) . collect :: < Vec < _ > > ( ) . get ( 0 ) { times_up_lets_do_this ( mech , enemy ) } else { vec ! [ move_mech ( mech ) move_mech ( mech ) move_mech ( mech ) mech request_radar ( ) ] } } else if let Some ( enemy ) = scan . iter ( ) . filter ( | p | p . foe ) . filter ( | p | distance_to ( & mech . position ( ) , & p . location ) <= mech . primary_range ( ) ) . collect :: < Vec < _ > > ( ) . get ( 0 ) { vec ! [ mech fire_primary ( mech direction_to ( enemy location ) ) mech move_mech ( mech direction_to ( enemy location ) ) mech move_mech ( mech direction_to ( enemy location ) ) mech register_set ( EBX RegisterValue Text ( enemy id to_string ( ) ) ) ] } else { vec ! [ move_mech ( mech ) move_mech ( mech ) move_mech ( mech ) mech request_radar ( ) ] } } None => vec ! [ move_mech ( mech ) move_mech ( mech ) move_mech ( mech ) mech request_radar ( ) ] , } }
Determine if potential enemy is in range, if not proceed to move and rescan
Determine if potential enemy is in range if not proceed to move and rescan
mech
&impl MechInstruments