Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnitviewDetail.lua: Introduce total DPS calculations #6424

Merged
merged 20 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) Introduce total DPS and DPS/Mass calculations 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 weapons. Previously, the DPS/Mass stat was not displayed in the UI or the unit databases, so they had to be calculated by hand.
Basilisk3 marked this conversation as resolved.
Show resolved Hide resolved

- 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
45 changes: 40 additions & 5 deletions lua/ui/game/unitviewDetail.lua
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,10 @@ function WrapAndPlaceText(bp, builder, descID, control)
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 +657,20 @@ 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)
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

-- Avoid saying a unit fires a salvo when it in fact has a constant rate of fire
Expand All @@ -681,7 +695,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 +736,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
Loading