bool CTorpedoLauncher::TestTarget(const float3& pos, bool userTarget, const CUnit* unit) const { // by default we are a waterweapon, therefore: // if muzzle is above water, target position is only allowed to be IN water // if muzzle is below water, target position being valid depends on submissile // // NOTE: // generally a TorpedoLauncher has its muzzle UNDER water and can *only* fire at // targets IN water but depth-charge weapons break first part of this assumption // (as do aircraft-based launchers) // // this check used to be in the base-class but is really out of place there: any // "normal" weapon with fireSubmersed = true should be able to fire out of water // (regardless of submissile which applies only to TorpedoLaunchers) but was not // able to, see #3951 // // land- or air-based launchers cannot target anything not in water if (weaponMuzzlePos.y > 0.0f && !TargetUnitOrPositionInWater(pos, unit)) return false; // water-based launchers cannot target anything not in water unless submissile if (weaponMuzzlePos.y <= 0.0f && !weaponDef->submissile && !TargetUnitOrPositionInWater(pos, unit)) return false; return (CWeapon::TestTarget(pos, userTarget, unit)); }
bool CLightningCannon::TryTarget(const float3& pos, bool userTarget, CUnit* unit) { if (!CWeapon::TryTarget(pos, userTarget, unit)) return false; if (!weaponDef->waterweapon && TargetUnitOrPositionInWater(pos, unit)) return false; float3 dir = pos - weaponMuzzlePos; float length = dir.Length(); if (length == 0) return true; dir /= length; if (!HaveFreeLineOfFire(weaponMuzzlePos, dir, length, unit)) { return false; } if (avoidFeature && TraceRay::LineFeatureCol(weaponMuzzlePos, dir, length)) { return false; } if (avoidFriendly && TraceRay::TestAllyCone(weaponMuzzlePos, dir, length, (accuracy + sprayAngle), owner->allyteam, owner)) { return false; } if (avoidNeutral && TraceRay::TestNeutralCone(weaponMuzzlePos, dir, length, (accuracy + sprayAngle), owner)) { return false; } return true; }
bool CTorpedoLauncher::TestTarget(const float3& pos, bool userTarget, const CUnit* unit) const { // NOTE: only here for #3557 if (!TargetUnitOrPositionInWater(pos, unit)) return false; return (CWeapon::TestTarget(pos, userTarget, unit)); }
bool CStarburstLauncher::TryTarget(const float3& pos, bool userTarget, CUnit* unit) { if (!CWeapon::TryTarget(pos, userTarget, unit)) return false; if (!weaponDef->waterweapon && TargetUnitOrPositionInWater(pos, unit)) return false; const float3& wdir = weaponDef->fixedLauncher? weaponDir: UpVector; if (avoidFriendly && TraceRay::TestCone(weaponMuzzlePos, wdir, 100.0f, 0.0f, owner->allyteam, true, false, false, owner)) { return false; } if (avoidNeutral && TraceRay::TestCone(weaponMuzzlePos, wdir, 100.0f, 0.0f, owner->allyteam, false, true, false, owner)) { return false; } return true; }
bool CBeamLaser::TryTarget(const float3& pos, bool userTarget, CUnit* unit) { if (!CWeapon::TryTarget(pos, userTarget, unit)) return false; if (!weaponDef->waterweapon && TargetUnitOrPositionInWater(pos, unit)) return false; float3 dir = pos - weaponMuzzlePos; float length = dir.Length(); if (length == 0) return true; dir /= length; if (!onlyForward) { if (!HaveFreeLineOfFire(weaponMuzzlePos, dir, length, unit)) { return false; } } const float spread = (accuracy + sprayAngle) * (1.0f - owner->limExperience * weaponDef->ownerExpAccWeight); if (avoidFeature && TraceRay::LineFeatureCol(weaponMuzzlePos, dir, length)) { return false; } if (avoidFriendly && TraceRay::TestCone(weaponMuzzlePos, dir, length, spread, owner->allyteam, true, false, false, owner)) { return false; } if (avoidNeutral && TraceRay::TestCone(weaponMuzzlePos, dir, length, spread, owner->allyteam, false, true, false, owner)) { return false; } return true; }