Skip to content

Commit

Permalink
Rework how enhancements are defined for the UEF ACU (FAForever#6513)
Browse files Browse the repository at this point in the history
  • Loading branch information
lL1l1 authored Nov 19, 2024
1 parent 0b2e701 commit e59dacf
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 39 deletions.
2 changes: 1 addition & 1 deletion changelog/snippets/other.6498.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- (#6498, #6502, #6503, #6514, #6516, #6517, #6518, #6506) Refactor the Enhancements section in the ACU/SACU scripts
- (#6498, #6502, #6503, #6514, #6516, #6517, #6518, #6506, #6513) Refactor the Enhancements section in the ACU/SACU scripts

It replaces the long if/else chain with a more modular design that is easier to maintain and hook. Each enhancement has its own dedicated function, named with the format `ProcessEnhancement[EnhancementName]`. The CreateEnhancement function now calls the appropriate enhancement function automatically by that name format.
2 changes: 1 addition & 1 deletion engine/Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function IsAlly(army1, army2)
end

--- Checks if the C-side of an object is destroyed / de-allocated
---@param entity? InternalObject
---@param entity? Destroyable
---@return boolean
function IsDestroyed(entity)
end
Expand Down
4 changes: 2 additions & 2 deletions engine/Sim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ function CreateDecal(position, heading, textureName1, textureName2, type, sizeX,
end

--- Creates an economy event for the unit that consumes resources over given time.
--- The unit shows the orange build bar for this event.
---@param unit Unit
---@param totalEnergy number
---@param totalMass number
---@param timeInSeconds number
---@param callback? fun(unit: Unit, economyEventProgress: number) # progress is (0,1]. Typically used with `Unit.SetWorkProgress` to show the orange build bar.
---@return EconomyEvent
function CreateEconomyEvent(unit, totalEnergy, totalMass, timeInSeconds)
function CreateEconomyEvent(unit, totalEnergy, totalMass, timeInSeconds, callback)
end

--- creates an emitter at an entity's bone, but does not attach the emitter to it
Expand Down
2 changes: 2 additions & 0 deletions lua/sim/Unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent, DebugUni

-- When paused we reclaim at a speed of 0, with thanks to:
-- - https://github.com/FAForever/FA-Binary-Patches/pull/19
---@diagnostic disable-next-line: param-type-mismatch
if self.EntityBeingReclaimed and (not IsDestroyed(self.EntityBeingReclaimed)) and IsProp(self.EntityBeingReclaimed) then
self:StopReclaimEffects(self.EntityBeingReclaimed)
self:StopUnitAmbientSound('ReclaimLoop')
Expand All @@ -564,6 +565,7 @@ Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent, DebugUni

-- When paused we reclaim at a speed of 0, with thanks to:
-- - https://github.com/FAForever/FA-Binary-Patches/pull/19
---@diagnostic disable-next-line: param-type-mismatch
if self.EntityBeingReclaimed and (not IsDestroyed(self.EntityBeingReclaimed)) and IsProp(self.EntityBeingReclaimed) then
self:StartReclaimEffects(self.EntityBeingReclaimed)
self:PlayUnitSound('StartReclaim')
Expand Down
Loading

0 comments on commit e59dacf

Please sign in to comment.