From b2ff4c30b8309dd7d18f1ae314f4b3083dcce6bd Mon Sep 17 00:00:00 2001 From: rt Date: Wed, 28 Nov 2018 01:55:17 +0100 Subject: [PATCH] qfix #6090 --- rts/Game/GameHelper.cpp | 7 +++++-- rts/Sim/Weapons/Weapon.cpp | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/rts/Game/GameHelper.cpp b/rts/Game/GameHelper.cpp index d0ee3f35242..d06c651f5ab 100644 --- a/rts/Game/GameHelper.cpp +++ b/rts/Game/GameHelper.cpp @@ -649,7 +649,7 @@ void CGameHelper::GenerateWeaponTargets(const CWeapon* weapon, const CUnit* avoi const float3 testPos; const float aimPosHeight = weapon->aimFromPos.y; - const float minMapHeight = std::max(0.0f, readMap->GetInitMinHeight()); + const float minMapHeight = std::max(0.0f, readMap->GetCurrMinHeight()); // how much damage the weapon deals over 1 second const float secDamage = weaponDmg->GetDefault() * weapon->salvoSize / weapon->reloadTime * GAME_SPEED; @@ -657,7 +657,10 @@ void CGameHelper::GenerateWeaponTargets(const CWeapon* weapon, const CUnit* avoi const float baseRange = weapon->range; const float rangeBoost = weapon->autoTargetRangeBoost; - const float scanRadius = weapon->GetRange2D(rangeBoost, (aimPosHeight - minMapHeight) * heightMod); + // find theoretical maximum range based on height above lowest point on map + // FIXME: root becomes negative for cannons collapsing range to 0, not legit + // const float scanRadius = weapon->GetRange2D(rangeBoost, (aimPosHeight - minMapHeight) * heightMod); + const float scanRadius = baseRange + rangeBoost + (aimPosHeight - minMapHeight) * heightMod; // [0] := default, [1,2,3,4,5,6] := target is {avoidee, in bad category, crashing, last attacker, paralyzed, outside unboosted range} constexpr float tgtPriorityMults[] = {1.0f, 10.0f, 100.0f, 1000.0f, 0.5f, 4.0f, 100000.0f}; diff --git a/rts/Sim/Weapons/Weapon.cpp b/rts/Sim/Weapons/Weapon.cpp index 6b92faa5a7f..5345aad6899 100644 --- a/rts/Sim/Weapons/Weapon.cpp +++ b/rts/Sim/Weapons/Weapon.cpp @@ -1183,9 +1183,9 @@ float CWeapon::GetStaticRange2D(const CWeapon* w, const WeaponDef* wd, float mod float CWeapon::GetRange2D(float boost, float ydiff) const { - const float rangeSq = Square(range + boost); - const float ydiffSq = Square(ydiff); - const float root = rangeSq - ydiffSq; + const float rangeSq = Square(range + boost); // c^2 (hyp) + const float ydiffSq = Square(ydiff); // b^2 (opp) + const float root = rangeSq - ydiffSq; // a^2 (adj) return (math::sqrt(std::max(root, 0.0f))); }