Skip to content

Commit

Permalink
UnitviewDetail.lua: Introduce total DPS calculations (#6424)
Browse files Browse the repository at this point in the history
## Description of the proposed changes
Shows a DPS total for all weapons not categorized as 'Anti Air' or 'Anti
Navy' in the additional unit details displayed when `Show Armament
Detail in Build Menu` is enabled in the settings.
- Useful for units with multiple weapons of this type, such as the
Uashavoh (Seraphim Destroyer), Ythotha or the Mongoose.
- Accounts for multiple instances of the same weapon being present.
Example: the Fatboy is correctly displayed as having a total DPS of
4000.
- ~~Also introduce a DPS/M calculation; I do not believe this is
calulcated anywhere in th UI or the unit databases.~~

## Checklist
- [x] Changes are annotated, including comments where useful.
- [x] Changes are documented in the changelog for the next game version.
- [x] Remove the entry if the unit only has 'Anti Air' or 'Anti Navy'
weapons, or no weapons at all.
- [x] Improve the naming of the stats.
- [x] Split the ground DPS stat into direct fire and indirect fire DPS.
  • Loading branch information
Basilisk3 authored Oct 19, 2024
1 parent 7538fe1 commit abb0e12
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 7 deletions.
5 changes: 5 additions & 0 deletions changelog/snippets/features.6424.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- (#6424) Calculate DPS totals in the additional unit details displayed when `Show Armament Detail in Build Menu` is enabled in the settings. This is useful for summarizing or comparing the stats of units with multiple instances of the same weapon, or multiple weapons of a similar type. If the unit only possesses one valid weapon, the total is not calculated.

- For example, the Ythotha (Seraphim Experimental Assault Bot), which has multiple weapons, is now displayed as possessing a combined total of `3794` direct fire DPS. This is displayed in an additional field in the UI, the stats of the individual weapons of the unit remain accessible in the same locations as before.

- (#6424) Do not display the Mole's Target Tracker in the additional unit details displayed when `Show Armament Detail in Build Menu` is enabled.
4 changes: 4 additions & 0 deletions loc/US/strings_db.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6767,6 +6767,10 @@ uvd_0014="Damage: %.8g - %.8g, Splash: %.3g - %.3g"
uvd_0015="Damage: %.8g x%d, Splash: %.3g"
uvd_0016="Enhancements: %d"
uvd_0017="Transport Speed Reduction: %.3g"
uvd_0018="Total Direct Fire DPS: %d"
uvd_0019="Total Indirect Fire DPS: %d"
uvd_0020="Total Anti Navy DPS: %d"
uvd_0021="Total Anti Air DPS: %d"

uvd_DPS="(DPS: %d)"
uvd_ManualFire="(Manual Fire)"
Expand Down
52 changes: 47 additions & 5 deletions lua/ui/game/unitviewDetail.lua
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ function WrapAndPlaceText(bp, builder, descID, control)
if not table.empty(bp.Weapon) then
local weapons = {upgrades = {normal = {}, death = {}},
basic = {normal = {}, death = {}}}
local totalWeaponCount = 0
for _, weapon in bp.Weapon do
if not weapon.WeaponCategory then continue end
local dest = weapons.basic
Expand All @@ -563,11 +564,18 @@ function WrapAndPlaceText(bp, builder, descID, control)
else
dest[weapon.DisplayName] = {info = weapon, count = 1}
end
if not dest.death then
totalWeaponCount = totalWeaponCount + 1
end
end
for k, v in weapons do
if not table.empty(v.normal) or not table.empty(v.death) then
table.insert(blocks, {color = UIUtil.fontColor, lines = {LOC('<LOC uvd_'..k..'>')..':'}})
end
local totalDirectFireDPS = 0
local totalIndirectFireDPS = 0
local totalNavalDPS = 0
local totalAADPS = 0
for name, weapon in v.normal do
local info = weapon.info
local weaponDetails1 = LOCStr(name)..' ('..LOCStr(info.WeaponCategory)..') '
Expand Down Expand Up @@ -653,10 +661,23 @@ function WrapAndPlaceText(bp, builder, descID, control)
CycleTime = CycleTime + FiringCooldown
end

local DPS = 0
if not info.ManualFire and info.WeaponCategory ~= 'Kamikaze' and info.WeaponCategory ~= 'Defense' then
--Round DPS, or else it gets floored in string.format.
local DPS = MATH_IRound(Damage * CycleProjs / CycleTime)
DPS = MATH_IRound(Damage * CycleProjs / CycleTime)
weaponDetails1 = weaponDetails1..LOCF('<LOC uvd_DPS>', DPS)
-- Do not calulcate the DPS total if the unit only has one valid weapon.
if totalWeaponCount > 1 then
if (info.WeaponCategory == 'Direct Fire' or info.WeaponCategory == 'Direct Fire Naval' or info.WeaponCategory == 'Direct Fire Experimental') and not info.IgnoreIfDisabled then
totalDirectFireDPS = totalDirectFireDPS + DPS * weapon.count
elseif info.WeaponCategory == 'Indirect Fire' or info.WeaponCategory == 'Missile' or info.WeaponCategory == 'Artillery' or info.WeaponCategory == 'Bomb' then
totalIndirectFireDPS = totalIndirectFireDPS + DPS * weapon.count
elseif info.WeaponCategory == 'Anti Navy' then
totalNavalDPS = totalNavalDPS + DPS * weapon.count
elseif info.WeaponCategory == 'Anti Air' then
totalAADPS = totalAADPS + DPS * weapon.count
end
end
end

-- Avoid saying a unit fires a salvo when it in fact has a constant rate of fire
Expand All @@ -681,7 +702,6 @@ function WrapAndPlaceText(bp, builder, descID, control)
Damage, info.DamageRadius, info.MinRadius, info.MaxRadius, CycleTime)
end


end
if weapon.count > 1 then
weaponDetails1 = weaponDetails1..' x'..weapon.count
Expand Down Expand Up @@ -723,11 +743,33 @@ function WrapAndPlaceText(bp, builder, descID, control)
weaponDetails = weaponDetails..' x'..weapon.count
end
table.insert(lines, weaponDetails)
table.insert(blocks, {color = 'FFFF0000', lines = lines})
end
if not table.empty(v.normal) or not table.empty(v.death) then
table.insert(lines, '')

-- Only display the totalDPS stats if they are greater than 0.
-- Prevent the totalDPS stats from being displayed under the 'Upgrades' tab and avoid the doubling of empty lines.
local upgradesAvailable = not table.empty(weapons.upgrades.normal) or not table.empty(weapons.upgrades.death)
if k == 'basic' then
if totalDirectFireDPS > 0 then
table.insert(blocks, {color = 'FFA600', lines = {LOCF('<LOC uvd_0018>', totalDirectFireDPS)}})
end
if totalIndirectFireDPS > 0 then
table.insert(blocks, {color = 'FFA600', lines = {LOCF('<LOC uvd_0019>', totalIndirectFireDPS)}})
end
if totalNavalDPS > 0 then
table.insert(blocks, {color = 'FFA600', lines = {LOCF('<LOC uvd_0020>', totalNavalDPS)}})
end
if totalAADPS > 0 then
table.insert(blocks, {color = 'FFA600', lines = {LOCF('<LOC uvd_0021>', totalAADPS)}})
end
if not upgradesAvailable then
table.insert(blocks, {color = UIUtil.fontColor, lines = {''}}) -- Empty line
end
end
-- Avoid the doubling of empty lines when the unit has upgrades.
if upgradesAvailable then
table.insert(blocks, {color = UIUtil.fontColor, lines = {''}}) -- Empty line
end
table.insert(blocks, {color = 'FFFF0000', lines = lines})
end
end
end
Expand Down
1 change: 0 additions & 1 deletion units/URL0101/URL0101_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ UnitBlueprint{
TargetPriorities = { "ALLUNITS" },
TargetRestrictDisallow = "UNTARGETABLE",
Turreted = false,
WeaponCategory = "Missile",
},
},
Wreckage = {
Expand Down
2 changes: 1 addition & 1 deletion units/XSL0303/XSL0303_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ UnitBlueprint{
TurretYawRange = 180,
TurretYawSpeed = 125,
Turreted = true,
WeaponCategory = "Indirect Fire",
WeaponCategory = "Direct Fire",
},
{
Audio = {
Expand Down

0 comments on commit abb0e12

Please sign in to comment.