Skip to content

Commit

Permalink
qfix #6090
Browse files Browse the repository at this point in the history
  • Loading branch information
rt committed Nov 28, 2018
1 parent 984bc30 commit b2ff4c3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions rts/Game/GameHelper.cpp
Expand Up @@ -649,15 +649,18 @@ 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;
const float heightMod = weaponDef->heightmod;

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};
Expand Down
6 changes: 3 additions & 3 deletions rts/Sim/Weapons/Weapon.cpp
Expand Up @@ -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)));
}

Expand Down

0 comments on commit b2ff4c3

Please sign in to comment.