Skip to content

Commit

Permalink
condense VetDamage and VetInstigators into one table
Browse files Browse the repository at this point in the history
  • Loading branch information
clyfordv committed Apr 23, 2024
1 parent 5a36ba8 commit c7d2392
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lua/defaultcomponents.lua
Expand Up @@ -592,9 +592,8 @@ local VeterancyRegenBuffs = {
}

---@class VeterancyComponent
---@field VetDamage table<EntityId, number>
---@field VetDamageTaken number
---@field VetInstigators table<EntityId, Unit>
---@field VetInstigators table<Unit, number>
---@field VetExperience? number
---@field VetLevel? number
VeterancyComponent = ClassSimple {
Expand All @@ -605,7 +604,6 @@ VeterancyComponent = ClassSimple {

-- these fields are always required
self.VetDamageTaken = 0
self.VetDamage = {}
self.VetInstigators = setmetatable({}, { __mode = 'v' })

-- optionally, these fields are defined too to inform UI of our veterancy status
Expand All @@ -632,10 +630,8 @@ VeterancyComponent = ClassSimple {
self.VetDamageTaken = self.VetDamageTaken + amount
local entityId = instigator.EntityId
local vetInstigators = self.VetInstigators
local vetDamage = self.VetDamage

vetInstigators[entityId] = instigator
vetDamage[entityId] = (vetDamage[entityId] or 0) + amount
vetInstigators[instigator] = (vetInstigators[instigator] or 0) + amount
end
end,

Expand All @@ -644,12 +640,11 @@ VeterancyComponent = ClassSimple {
---@param experience? number -- override for amount of experience to be distributed
VeterancyDispersal = function(self, experience)
local vetWorth = experience or (self:GetFractionComplete() * self:GetTotalMassCost())
local vetDamage = self.VetDamage
local vetInstigators = self.VetInstigators
local vetDamageTaken = self.VetDamageTaken
for id, unit in vetInstigators do
for unit, damage in vetInstigators do
if unit.Blueprint.VetEnabled and (not IsDestroyed(unit)) then
local proportion = vetWorth * (vetDamage[id] / vetDamageTaken)
local proportion = vetWorth * (damage / vetDamageTaken)
unit:AddVetExperience(proportion)
end
end
Expand Down

0 comments on commit c7d2392

Please sign in to comment.