Skip to content

Commit

Permalink
Remove rounding in weapon tracking radius sanitization (FAForever#6536)
Browse files Browse the repository at this point in the history
Fixes a bug where most weapons got 1.0 tracking radius because they were
set to 1.05 but floored to 1.0.
  • Loading branch information
lL1l1 authored Nov 15, 2024
1 parent 191576f commit 454dfc4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions changelog/snippets/fix.6536.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- (#6536) Fix the tracking radius for unit weapons being floored to the nearest tenth, which made units not track targets that are near the outside of their range.
- Mobile unit weapons: 1.0x of weapon range -> 1.05x
- Anti-air weapons: 1.10x -> 1.15x
- Bomber weapons: 1.2x -> 1.25x
- Structure weapons: 1x -> 1x
1 change: 1 addition & 0 deletions engine/Core/Blueprints/UnitBlueprint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
---@see SetAutoMode
---@field InitialAutoMode boolean
--- unit should unpack before firing weapon
--- Engine sets tracking radius to 1x, calls OnLostTarget when given a move order, and OnGotTarget only when not moving
---@field NeedUnpack boolean
--- this muliplier is applied when a staging platform is refueling an air unit
---@field RefuelingMultiplier number
Expand Down
13 changes: 6 additions & 7 deletions lua/system/blueprints-weapons.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

local weaponTargetCheckUpperLimit = 6000

---@param unit UnitBlueprint
---@param weapon WeaponBlueprint
---@param projectile? ProjectileBlueprint
local function ProcessWeapon(unit, weapon, projectile)
-- pre-compute flags
-- pre-compute flags
local isAir = false
local isStructure = false
local isBomber = false
Expand Down Expand Up @@ -81,7 +80,7 @@ local function ProcessWeapon(unit, weapon, projectile)
end
end

-- process target tracking radius
-- process target tracking radius

-- if it is set then we use that - allows us to make adjustments as we see fit
if weapon.TrackingRadius == nil then
Expand All @@ -99,7 +98,7 @@ local function ProcessWeapon(unit, weapon, projectile)
end

-- add significant target checking radius for bombers
if isBomber then
if isBomber then
weapon.TrackingRadius = 1.25
end
end
Expand All @@ -112,8 +111,8 @@ local function ProcessWeapon(unit, weapon, projectile)
-- by default, do not recheck targets as that is expensive when a lot of units are stacked on top of another
weapon.AlwaysRecheckTarget = false

-- allow
if weapon.RangeCategory == 'UWRC_DirectFire' or
-- allow
if weapon.RangeCategory == 'UWRC_DirectFire' or
weapon.RangeCategory == "UWRC_IndirectFire" or
weapon.MaxRadius > 50 and (weapon.RangeCategory ~= "UWRC_AntiNavy") then
weapon.AlwaysRecheckTarget = true
Expand All @@ -137,8 +136,8 @@ local function ProcessWeapon(unit, weapon, projectile)
weapon.AlwaysRecheckTarget = false
end

-- Floor target check interval to ticks
weapon.TargetCheckInterval = 0.1 * math.floor(10 * weapon.TargetCheckInterval)
weapon.TrackingRadius = 0.1 * math.floor(10 * weapon.TrackingRadius)
end

---@param allBlueprints BlueprintsTable
Expand Down

0 comments on commit 454dfc4

Please sign in to comment.