Skip to content

Commit

Permalink
Improve performance of weaponry (FAForever#3857)
Browse files Browse the repository at this point in the history
Sanitizes weapon statistics that relate to the target check interval, retargeting and target priorities. In turn, some units are more responsive and others are less responsive.
  • Loading branch information
Garanas authored Jun 6, 2022
1 parent 3030487 commit c36b413
Show file tree
Hide file tree
Showing 223 changed files with 292 additions and 1,057 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"nuxt.isNuxtApp": false
}
4 changes: 4 additions & 0 deletions lua/system/Blueprints.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ doscript("/lua/system/blueprints-ai.lua")
doscript("/lua/system/blueprints-lod.lua")
doscript("/lua/system/blueprints-projectiles.lua")
doscript("/lua/system/blueprints-units.lua")
doscript("/lua/system/blueprints-weapons.lua")

--- Load in the pre game data that is defined in the lobby through the preference file.
local function LoadPreGameData()
Expand Down Expand Up @@ -799,6 +800,9 @@ function PostModBlueprints(all_bps)
SetUnitThreatValues(all_bps.Unit)
BlueprintLoaderUpdateProgress()

local ok, msg = pcall(ProcessWeapons, all_bps.Unit)
LOG(repr(msg))

-- re-computes all the LODs of various entities to match the LOD with the size of the entity.
CalculateLODs(all_bps)
BlueprintLoaderUpdateProgress()
Expand Down
4 changes: 2 additions & 2 deletions lua/system/blueprints-units.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ local function PostProcessUnit(unit)
-- guarantee that the table exists
unit.AI = unit.AI or { }

-- if it is set then we use that - allows balance team to make adjustments as they see fit
if not unit.AI.GuardScanRadius then
-- if it is set then we use that - allows us to make adjustments as we see fit
if unit.AI.GuardScanRadius == nil then

-- structures don't need this value set
if isStructure or isDummy then
Expand Down
155 changes: 155 additions & 0 deletions lua/system/blueprints-weapons.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@

local weaponTargetCheckUpperLimit = 6000

local function ProcessWeapon(unit, weapon)

-- - pre-compute flags

local isAir = false
local isStructure = false
local isBomber = false
local isExperimental = false
local isTech3 = false
local isTech2 = false
if unit.Categories then
for k, category in unit.Categories do
isStructure = isStructure or (category == "STRUCTURE")
isAir = isAir or (category == "AIR")
isBomber = isBomber or (category == "BOMBER")
isTech2 = isTech2 or (category == "TECH2")
isTech3 = isTech3 or (category == "TECH3")
isExperimental = isExperimental or (category == "EXPERIMENTAL")
end
end

-- - process weapon

-- Death weapons of any kind
if weapon.DamageType == "DeathExplosion" or weapon.Label == "DeathWeapon" or weapon.Label == "DeathImpact" then
weapon.TargetCheckInterval = weaponTargetCheckUpperLimit
weapon.AlwaysRecheckTarget = false
weapon.DummyWeapon = true
weapon.ManualFire = true
weapon.TrackingRadius = 0.0
return
end

-- Tactical, strategical missile defenses and torpedo defenses
if weapon.RangeCategory == "UWRC_Countermeasure" then
weapon.TargetCheckInterval = 0.4
weapon.AlwaysRecheckTarget = false
weapon.TrackingRadius = 1.10
weapon.DummyWeapon = false
weapon.ManualFire = false
return
end

-- manual launch of tactical and strategic missiles
if weapon.ManualFire then
weapon.TargetCheckInterval = weaponTargetCheckUpperLimit
weapon.AlwaysRecheckTarget = false
weapon.TrackingRadius = 0.0
return
end

-- # process target check interval

-- if it is set then we use that - allows us to make adjustments as we see fit
if weapon.TargetCheckInterval == nil then

local intervalByRateOfFire = 0.5 * (1 / (weapon.RateOfFire or 1))
local intervalByRadius = (weapon.MaxRadius or 10) / 30
weapon.TargetCheckInterval = math.min(intervalByRateOfFire, intervalByRadius)

-- clamp value to something sane
if weapon.TargetCheckInterval < 0.4 and (not isExperimental) then
weapon.TargetCheckInterval = 0.4
end

-- clamp value to something sane
if weapon.TargetCheckInterval < 0.2 then
weapon.TargetCheckInterval = 0.2
end

-- clamp value to something sane
if weapon.TargetCheckInterval > 3 then
weapon.TargetCheckInterval = 3
end
end

-- # 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

-- by default, give every unit a 5% target checking radius
weapon.TrackingRadius = 1.05

-- remove target tracking radius for non-aa weaponry part of structures
if isStructure and (weapon.RangeCategory ~= "UWRC_AntiAir") then
weapon.TrackingRadius = 1.0
end

-- give anti air a larger track radius
if weapon.RangeCategory == "UWRC_AntiAir" then
weapon.TrackingRadius = 1.15
end

-- add significant target checking radius for bombers
if isBomber then
weapon.TrackingRadius = 1.25
end

end

-- # process target rechecking

-- if it is set then we use that - allows us to make adjustments as we see fit
if weapon.AlwaysRecheckTarget == nil then

-- 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 target rechecking for artillery and weapons with a very large attack radius
if weapon.RangeCategory == "UWRC_IndirectFire" or
weapon.MaxRadius > 50 and (weapon.RangeCategory ~= "UWRC_AntiNavy") then
weapon.AlwaysRecheckTarget = true
end

-- always allow anti air weapons attached to structures to retarget, as otherwise they may be stuck on a scout
if isStructure and weapon.RangeCategory == "UWRC_AntiAir" then
weapon.AlwaysRecheckTarget = true
end

-- always allow experimentals to retarget
if isExperimental then
weapon.AlwaysRecheckTarget = true
end
end

-- # sanitize values

-- do not allow the 'bomb weapon' of bombers to suddenly retarget, as then they won't drop their bomb when they do
if weapon.NeedToComputeBombDrop then
weapon.AlwaysRecheckTarget = false
end

weapon.TargetCheckInterval = 0.1 * math.floor(10 * weapon.TargetCheckInterval)
weapon.TrackingRadius = 0.1 * math.floor(10 * weapon.TrackingRadius)
end

function ProcessWeapons(units)
for k, unit in units do
if unit.Weapon then
LOG("Processing: " .. unit.BlueprintId .. " (" .. tostring(unit.General.UnitName) .. ")")
for k, weapon in unit.Weapon do
ProcessWeapon(unit, weapon)

LOG(" - Weapon label: " .. tostring(weapon.DisplayName))
LOG(" - - WeaponCheckinterval: " .. tostring(weapon.TargetCheckInterval))
LOG(" - - AlwaysRecheckTarget: " .. tostring(weapon.AlwaysRecheckTarget))
LOG(" - - TrackingRadius: " .. tostring(weapon.TrackingRadius))
end
end
end
end
3 changes: 1 addition & 2 deletions units/DAA0206/DAA0206_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ UnitBlueprint {
RateOfFire = 10,
SlavedToBody = true,
SlavedToBodyArcRange = 35,
TargetCheckInterval = 999999,
TargetPriorities = {
'TECH4',
'TECH3 STRUCTURE',
Expand All @@ -290,7 +289,6 @@ UnitBlueprint {
'ALLUNITS',
},
TargetRestrictDisallow = 'UNTARGETABLE',
TrackingRadius = 0.5,
TurretBoneMuzzle = 'DAA0206',
TurretBonePitch = 'DAA0206',
TurretBoneYaw = 'DAA0206',
Expand All @@ -303,6 +301,7 @@ UnitBlueprint {
TurretYawSpeed = 720,
Turreted = true,
WeaponCategory = 'Kamikaze',
ManualFire = true,
},
{
AboveWaterTargetsOnly = true,
Expand Down
2 changes: 0 additions & 2 deletions units/DAL0310/DAL0310_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ UnitBlueprint {
RateOfFire = 0.5,
SlavedToBody = true,
SlavedToBodyArcRange = 5,
TargetCheckInterval = 0.75,
TargetPriorities = {
'SHIELD',
'PERSONALSHIELD',
Expand All @@ -285,7 +284,6 @@ UnitBlueprint {
'ALLUNITS',
},
TargetRestrictDisallow = 'UNTARGETABLE',
TrackingRadius = 1.15,
TurretBoneMuzzle = 'Turret_Barrel',
TurretBonePitch = 'Turret_Barrel',
TurretBoneYaw = 'Turret',
Expand Down
5 changes: 0 additions & 5 deletions units/DALK003/DALK003_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,14 @@ UnitBlueprint {
},
},
RateOfFire = 0.5,
TargetCheckInterval = 1,
TargetPriorities = {
'ALLUNITS'
},
TargetRestrictDisallow = 'UNTARGETABLE',
TrackingRadius = 1.2,
Turreted = false,
SlavedToBody = false,
},
{
AlwaysRecheckTarget = true,
Audio = {
Fire = Sound {
Bank = 'UALWeapon',
Expand Down Expand Up @@ -301,7 +298,6 @@ UnitBlueprint {
RangeCategory = 'UWRC_AntiAir',
RateOfFire = 0.1667,
SlavedToBody = false,
TargetCheckInterval = 0.3,
TargetPriorities = {
'AIR MOBILE EXPERIMENTAL',
'AIR MOBILE TECH3 BOMBER',
Expand All @@ -312,7 +308,6 @@ UnitBlueprint {
'ALLUNITS'
},
TargetRestrictDisallow = 'UNTARGETABLE',
TrackingRadius = 1.4,
TurretDualManipulators = false,
TurretPitch = 0,
TurretPitchRange = 0,
Expand Down
21 changes: 10 additions & 11 deletions units/DEA0202/DEA0202_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ UnitBlueprint {
},
Weapon = {
{
-- sim-performance related values
TargetCheckInterval = 0.4,
AlwaysRecheckTarget = false,
TrackingRadius = 1.1,

Audio = {
Fire = Sound {
Bank = 'UEAWeapon',
Expand Down Expand Up @@ -329,7 +334,6 @@ UnitBlueprint {
RateOfFire = 1,
SlavedToBody = true,
SlavedToBodyArcRange = 50,
TargetCheckInterval = 1,
TargetPriorities = {
'AIR MOBILE TECH3 BOMBER',
'AIR MOBILE BOMBER',
Expand All @@ -340,7 +344,6 @@ UnitBlueprint {
},
TargetRestrictDisallow = 'UNTARGETABLE,LAND,STRUCTURE,NAVAL',
TargetRestrictOnlyAllow = 'AIR',
TrackingRadius = 1.25,
TurretBoneMuzzle = 'Left_Muzzle',
TurretBonePitch = 'Left_Muzzle',
TurretBoneYaw = 'Left_Muzzle',
Expand All @@ -357,6 +360,11 @@ UnitBlueprint {
WeaponUnpacks = false,
},
{
-- sim-performance related values
TargetCheckInterval = 0.4,
AlwaysRecheckTarget = false,
TrackingRadius = 1.1,

Audio = {
Fire = Sound {
Bank = 'UEAWeapon',
Expand Down Expand Up @@ -405,18 +413,11 @@ UnitBlueprint {
RateOfFire = 1,
SlavedToBody = true,
SlavedToBodyArcRange = 50,
TargetCheckInterval = 1,
TargetPriorities = {
'AIR MOBILE TECH3 BOMBER',
'AIR MOBILE BOMBER',
'AIR MOBILE GROUNDATTACK',
'AIR MOBILE TRANSPORTATION',
'AIR MOBILE',
'ALLUNITS'
},
TargetRestrictDisallow = 'UNTARGETABLE,LAND,STRUCTURE,NAVAL',
TargetRestrictOnlyAllow = 'AIR',
TrackingRadius = 1.25,
TurretBoneMuzzle = 'Right_Muzzle',
TurretBonePitch = 'Right_Muzzle',
TurretBoneYaw = 'Right_Muzzle',
Expand Down Expand Up @@ -488,13 +489,11 @@ UnitBlueprint {
RateOfFire = 0.1,
SkipReadyState = true,
StopOnPrimaryWeaponBusy = true,
TargetCheckInterval = 1,
TargetPriorities = {
'STRUCTURE',
'ALLUNITS'
},
TargetRestrictDisallow = 'UNTARGETABLE',
TrackingRadius = 1.25,
TurretDualManipulators = false,
TurretPitch = -90,
TurretPitchRange = 20,
Expand Down
4 changes: 0 additions & 4 deletions units/DEL0204/DEL0204_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ UnitBlueprint {
RackSlavedToTurret = false,
RangeCategory = 'UWRC_DirectFire',
RateOfFire = 1,
TargetCheckInterval = 0.25,
TargetPriorities = {
'TECH3 MOBILE',
'TECH2 MOBILE',
Expand All @@ -295,7 +294,6 @@ UnitBlueprint {
'ALLUNITS',
},
TargetRestrictDisallow = 'UNTARGETABLE',
TrackingRadius = 1.15,
TurretBoneMuzzle = 'Left_Arm_Barrel_Muzzle',
TurretBonePitch = 'Left_Arm_B01',
TurretBoneYaw = 'Torso',
Expand Down Expand Up @@ -359,7 +357,6 @@ UnitBlueprint {
RackSlavedToTurret = false,
RangeCategory = 'UWRC_DirectFire',
RateOfFire = 0.15,
TargetCheckInterval = 0.5,
TargetPriorities = {
'TECH1 MOBILE',
'TECH2 MOBILE',
Expand All @@ -368,7 +365,6 @@ UnitBlueprint {
'ALLUNITS',
},
TargetRestrictDisallow = 'UNTARGETABLE',
TrackingRadius = 1.15,
TurretBoneMuzzle = 'Right_Arm_B02_Muzzle',
TurretBonePitch = 'Right_Arm_B01',
TurretBoneYaw = 'Right_Arm_B01',
Expand Down
Loading

0 comments on commit c36b413

Please sign in to comment.