public static bool CheckWeapon(this Vessel vessel, Vessel target, bool considerAircrafts) { if (target.isAlive == false) { return(false); } // Target is aircraft. if (target.vesselType == EVesselType.AIRCRAFT) { // We don't allow ships to engage aircrafts actively in this game. // Exception is: vessels that carry kamikaze fighters. (anti-air missiles) if (vessel.vesselType != EVesselType.AIRCRAFT) { return(considerAircrafts && vessel.CheckAircraft(target)); } // If this aircraft is a fighter, never engage other aircrafts actively. if ((vessel as Aircraft).aircraftType != EAircraftType.FIGHTER) { return(false); } return(vessel.CheckRange(target, EWeaponType.ANTI_AIR)); } else if (target.vesselType == EVesselType.SS) { // If this vessel has kamikaze asw bombers. (anti-sub missiles) if (vessel.vesselType != EVesselType.AIRCRAFT) { if (considerAircrafts && vessel.CheckAircraft(target)) { return(true); } } // Only vessels that have aswPower > 0 can attack subs. if (vessel.aswPower == 0) { return(false); } if (vessel.vesselType == EVesselType.AIRCRAFT) { return(CheckRange(vessel, target, EWeaponType.AERIAL_ASW)); } else { return(CheckRange(vessel, target, EWeaponType.ASW)); } } else { // Aircraft to Surface. if (vessel.vesselType == EVesselType.AIRCRAFT) { bool canFire = false; canFire |= CheckRange(vessel, target, EWeaponType.BOMB); canFire |= CheckRange(vessel, target, EWeaponType.AERIAL_TORPEDO); return(canFire); } else { bool canFire = false; canFire |= (considerAircrafts && vessel.CheckAircraft(target)); canFire |= CheckRange(vessel, target, EWeaponType.GUN); canFire |= CheckRange(vessel, target, EWeaponType.TORPEDO); return(canFire); } } }