question: private void toggleStealth ( ) { initialize ( ) ; int total_bv , known_bv , known_range , known_count , trigger_range ; int new_stealth ; for ( Entity check_ent : game . getEntitiesVector ( ) ) { if ( ( check_ent . getOwnerId ( ) == localPlayerNumber ) && ( check_ent instanceof Mech ) ) { if ( check_ent . hasStealth ( ) && ( check_ent . getPosition ( ) != null ) ) { for ( Mounted mEquip : check_ent . getMisc ( ) ) { MiscType mtype = ( MiscType ) mEquip . getType ( ) ; if ( mtype . hasFlag ( MiscType . F_STEALTH ) ) { trigger_range = 13 + Compute . randomInt ( 7 ) ; if ( check_ent . heat > trigger_range ) { new_stealth = 0 ; } else { total_bv = 0 ; known_bv = 0 ; known_range = 0 ; known_count = 0 ; for ( Entity test_ent : game . getEntitiesVector ( ) ) { if ( check_ent . isEnemyOf ( test_ent ) ) { total_bv += test_ent . calculateBattleValue ( ) ; if ( test_ent . isVisibleToEnemy ( ) ) { known_count ++ ; known_bv += test_ent . calculateBattleValue ( ) ; known_range += Compute . effectiveDistance ( game , check_ent , test_ent ) ; } } } if ( ( known_count == 0 ) || ( known_bv < ( total_bv / 2 ) ) ) { new_stealth = 1 ; } else { if ( ( known_range / known_count ) <= ( 5 + Compute . randomInt ( 5 ) ) ) { new_stealth = 0 ; } else { new_stealth = 1 ; } } } mEquip . setMode ( new_stealth ) ; sendModeChange ( check_ent . getId ( ) , check_ent . getEquipmentNum ( mEquip ) , new_stealth ) ; break ; } } } } } }
target:  If the unit has stealth armor, turning it off is probably a good idea if most of the enemy force is at 'short' range or if in danger of overheating