Skip to content

Commit

Permalink
Make assisters start repairing shields immediately (#6464)
Browse files Browse the repository at this point in the history
Assist orders take 7-11 ticks to react to the shield being damaged, but by issuing a repair order when the shield gets damaged this shortens to 1 tick
  • Loading branch information
lL1l1 authored Dec 11, 2024
1 parent 73ed88e commit 8f68350
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog/snippets/balance.6464.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- (#6464) Make engineers assisting a shield start repairing the shield in 0.1 seconds instead of 0.7 to 1.1 seconds.
41 changes: 37 additions & 4 deletions lua/shield.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ local MathSqrt = math.sqrt
local MathMin = math.min

local TableAssimilate = table.assimilate
local TableGetn = table.getn
local TableEmpty = table.empty

-- cache globals
local Warp = Warp
Expand All @@ -59,6 +61,9 @@ local ArmyGetHandicap = ArmyGetHandicap
local CoroutineYield = coroutine.yield
local CreateEmitterAtBone = CreateEmitterAtBone
local _c_CreateShield = _c_CreateShield
local IssueClearCommands = IssueClearCommands
local IssueRepair = IssueRepair
local IssueGuard = IssueGuard

-- cache cfunctions
local EntityGetHealth = _G.moho.entity_methods.GetHealth
Expand Down Expand Up @@ -87,6 +92,8 @@ local EntitySetParentOffset = _G.moho.entity_methods.SetParentOffset
local UnitSetScriptBit = _G.moho.unit_methods.SetScriptBit
local UnitIsUnitState = _G.moho.unit_methods.IsUnitState
local UnitRevertCollisionShape = _G.moho.unit_methods.RevertCollisionShape
local UnitGetGuards = _G.moho.unit_methods.GetGuards
local UnitGetCommandQueue = _G.moho.unit_methods.GetCommandQueue

local IEffectOffsetEmitter = _G.moho.IEffect.OffsetEmitter

Expand Down Expand Up @@ -356,7 +363,7 @@ Shield = ClassShield(moho.shield_methods, Entity) {

--- Retrieves allied shields that overlap with this shield, caches the results per tick
-- @param self A shield that we're computing the overlapping shields for
-- @param tick Optional parameter, represents the game tick. Used to determine if we need to refresh the cash
-- @param tick Optional parameter, represents the game tick. Used to determine if we need to refresh the cache
GetOverlappingShields = function(self, tick)

-- allow the game tick to be send to us, saves cycles
Expand Down Expand Up @@ -509,6 +516,12 @@ Shield = ClassShield(moho.shield_methods, Entity) {
self:ApplyDamage(instigator, amount, vector, damageType, true)
end,

---@param self Shield
---@param instigator Unit
---@param amount number
---@param vector Vector
---@param dmgType DamageType
---@param doOverspill boolean
ApplyDamage = function(self, instigator, amount, vector, dmgType, doOverspill)

-- cache information used throughout the function
Expand Down Expand Up @@ -565,12 +578,32 @@ Shield = ClassShield(moho.shield_methods, Entity) {

-- do damage logic for shield

if self.Owner ~= instigator then
local owner = self.Owner
if owner ~= instigator then
local absorbed = self:OnGetDamageAbsorption(instigator, amount, dmgType)

-- take some damage
EntityAdjustHealth(self, instigator, -absorbed)

-- force guards to start repairing in 1 tick instead of waiting for them to react 7-11 ticks
if tick > owner.tickIssuedShieldRepair then
owner.tickIssuedShieldRepair = tick
local guards = UnitGetGuards(owner)
if not TableEmpty(guards) then
-- filter out guards with something queued after the shield assist order, as to not delete clear their queue
for i, guard in guards do
if TableGetn(UnitGetCommandQueue(guard)) >= 2 then
guards[i] = nil
end
end

-- For the filtered guards, clear their assist order, order repair, then re-add the assist order after
IssueClearCommands(guards)
IssueRepair(guards, owner)
IssueGuard(guards, owner)
end
end

-- check to spawn impact effect
local r = Random(1, self.Size)
if dmgType ~= "ShieldSpill"
Expand Down Expand Up @@ -684,8 +717,8 @@ Shield = ClassShield(moho.shield_methods, Entity) {
end,

--- Called when a shield collides with a projectile to check if the collision is valid
-- @param self The shield we're checking the collision for
-- @param other The projectile we're checking the collision with
---@param self Shield The shield we're checking the collision for
---@param other Projectile The projectile we're checking the collision with
OnCollisionCheck = function(self, other)

-- special logic when it is a projectile to simulate air crashes
Expand Down
1 change: 1 addition & 0 deletions lua/sim/Unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ local cUnitGetBuildRate = cUnit.GetBuildRate
---@field ReclaimTimeMultiplier? number
---@field CaptureTimeMultiplier? number
---@field PlatoonHandle? Platoon
---@field tickIssuedShieldRepair number? # Used by shields to keep track of when this unit's guards were ordered to start shield repair instantly
Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent, DebugUnitComponent) {

IsUnit = true,
Expand Down

0 comments on commit 8f68350

Please sign in to comment.