From 5886dd8abe52cbc2a2e74f95a46e5ed5d4691f7a Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Thu, 26 Sep 2024 21:03:05 -0700 Subject: [PATCH 01/14] Annotate CollisionBeamEntity spec is from the disassembly strings `Disable` is from logging the `moho.CollisionBeamEntity` table (excluding what's already in `moho.entity_methods`) --- engine/Sim/CollisionBeamEntity.lua | 31 +++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/engine/Sim/CollisionBeamEntity.lua b/engine/Sim/CollisionBeamEntity.lua index 984de7b7ab..f7af8bd684 100644 --- a/engine/Sim/CollisionBeamEntity.lua +++ b/engine/Sim/CollisionBeamEntity.lua @@ -1,31 +1,40 @@ ---@meta +---@class CollisionBeamSpec +---@field Weapon Weapon # Weapon to attach to +---@field BeamBone Bone # Bone of the weapon's unit which the beam is attached to +---@field OtherBone 0 # Which bone of the beam is attached to the unit. Use 0 for a functioning beam. 1 attaches it backwards, which is practically non-functional. +---@field CollisionCheckInterval number # Interval in ticks between collision check ticks + ---@class moho.CollisionBeamEntity : moho.entity_methods local CCollisionBeamEntity = {} ---- --- CollisionBeamEntity:Enable() +--- Enables beam collision checking, which calls `CCollisionBeamEntity:OnImpact` in Lua every check. function CCollisionBeamEntity:Enable() end ---- --- CCollisionBeamEntity:GetLauncher() +--- Disables beam collision checking. +function CCollisionBeamEntity:Disable() +end + +--- Returns the unit that is responsible for creating this collision beam. +---@return Unit function CCollisionBeamEntity:GetLauncher() end ---- --- bool = CCollisionBeamEntity:IsEnabled() +---@return boolean function CCollisionBeamEntity:IsEnabled() end ---- --- CCollisionBeamEntity:SetBeamFx(beamEmitter, checkCollision) -- set an emitter to be controlled by this beam. Its length parameter will be set from the beam entity's collision distance. +--- Set an emitter to be controlled by this beam. Its length parameter will be set from the beam entity's collision distance. +---@param beamEmitter moho.IEffect # Beam type emitter +---@param checkCollision boolean function CCollisionBeamEntity:SetBeamFx(beamEmitter, checkCollision) end ---- --- beam = CreateCollisionBeam(spec)spec is a table with the following fields defined: -function CCollisionBeamEntity:__init() +---@param spec CollisionBeamSpec +---@return moho.CollisionBeamEntity +function CCollisionBeamEntity:__init(spec) end return CCollisionBeamEntity From 27e316d5bc4db457e13f75f7e2928e76977daaf1 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Thu, 26 Sep 2024 23:27:42 -0700 Subject: [PATCH 02/14] Update WeaponBlueprint BeamCollisionDelay --- engine/Core/Blueprints/WeaponBlueprint.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/engine/Core/Blueprints/WeaponBlueprint.lua b/engine/Core/Blueprints/WeaponBlueprint.lua index 72e96979f5..8b24daa446 100644 --- a/engine/Core/Blueprints/WeaponBlueprint.lua +++ b/engine/Core/Blueprints/WeaponBlueprint.lua @@ -46,8 +46,7 @@ ---@field AutoInitiateAttackCommand? boolean --- Ballistic arcs that should be used on the projectile ---@field BallisticArc? WeaponBallisticArc ---- every `X/10+1` game ticks, this beam will collide and do damage - using `0` will cause beams to ---- damage every tick +--- Interval in seconds between beam collision checks (which take 1 tick) - using `0` will cause beams to damage every tick ---@field BeamCollisionDelay number --- the amount of time the beam exists ---@field BeamLifetime number From 3d538e7b045849933ed5cced4689e6e888a93250 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Thu, 26 Sep 2024 23:35:58 -0700 Subject: [PATCH 03/14] Annotate CollisionBeam.lua --- lua/sim/CollisionBeam.lua | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/lua/sim/CollisionBeam.lua b/lua/sim/CollisionBeam.lua index 0bf3e84b39..d64fedbef4 100644 --- a/lua/sim/CollisionBeam.lua +++ b/lua/sim/CollisionBeam.lua @@ -19,7 +19,17 @@ local GetTerrainType = GetTerrainType local DefaultTerrainType = GetTerrainType(-1, -1) ---@class CollisionBeam : moho.CollisionBeamEntity +---@field unit Unit +---@field Weapon Weapon +---@field Army Army ---@field DamageTable WeaponDamageTable +---@field BeamEffectsBag moho.IEffect[] +---@field TerrainEffectsBag moho.IEffect[] +---@field FxImpactWater FileName[]? +---@field FxImpactUnderWater FileName[]? +---@field FxImpactUnit FileName[]? +---@field FxImpactAirUnit FileName[]? +---@field FxImpactLand FileName[]? ---@field Trash TrashBag CollisionBeam = Class(moho.CollisionBeamEntity) { @@ -103,7 +113,7 @@ CollisionBeam = Class(moho.CollisionBeamEntity) { ---@param self CollisionBeam ---@param instigator Unit ---@param damageData table - ---@param targetEntity? Unit + ---@param targetEntity Unit | Projectile | Prop | nil DoDamage = function(self, instigator, damageData, targetEntity) local damage = damageData.DamageAmount or 0 if damage <= 0 then return end @@ -160,7 +170,7 @@ CollisionBeam = Class(moho.CollisionBeamEntity) { AttachBeamToEntity(fxBeam, self, 0, self.Army) -- collide on start if it's a continuous beam - local weaponBlueprint = self.Weapon:GetBlueprint() + local weaponBlueprint = self.Weapon.Blueprint local bCollideOnStart = weaponBlueprint.BeamLifetime <= 0 self:SetBeamFx(fxBeam, bCollideOnStart) @@ -180,9 +190,9 @@ CollisionBeam = Class(moho.CollisionBeamEntity) { end, ---@param self CollisionBeam - ---@param army number - ---@param EffectTable string[] - ---@param EffectScale number + ---@param army Army + ---@param EffectTable FileName[]? + ---@param EffectScale number? CreateImpactEffects = function(self, army, EffectTable, EffectScale) local emit = nil EffectTable = EffectTable or {} @@ -196,8 +206,8 @@ CollisionBeam = Class(moho.CollisionBeamEntity) { end, ---@param self CollisionBeam - ---@param army number - ---@param EffectTable string[] + ---@param army Army + ---@param EffectTable FileName[] ---@param EffectScale number CreateTerrainEffects = function(self, army, EffectTable, EffectScale) local emit = nil @@ -271,13 +281,12 @@ CollisionBeam = Class(moho.CollisionBeamEntity) { end end, - -- This is called when the collision beam hits something new. Because the beam - -- is continuously detecting collisions it only executes this function when the - -- thing it is touching changes. Expect Impacts with non-physical things like - -- 'Air' (hitting nothing) and 'Underwater' (hitting nothing underwater). + --- Called by the engine while the beam is active every `CollisionCheckInterval + 1` ticks + --- or when `SetBeamFx(beamEmitter, checkCollision)` is called with `CheckCollision = true`. + --- Expect Impacts with non-physical things like 'Air' (hitting nothing) and 'Underwater' (hitting nothing underwater). ---@param self CollisionBeam ---@param impactType ImpactType - ---@param targetEntity? Unit | Prop + ---@param targetEntity Unit | Projectile | Prop | nil OnImpact = function(self, impactType, targetEntity) -- LOG('*DEBUG: COLLISION BEAM ONIMPACT ', repr(self)) -- LOG('*DEBUG: COLLISION BEAM ONIMPACT, WEAPON = ', repr(self.Weapon), 'Type = ', impactType) @@ -299,7 +308,7 @@ CollisionBeam = Class(moho.CollisionBeamEntity) { return end - self:ShowBeamSource(targetEntity) + self:ShowBeamSource(targetEntity --[[@as Unit]]) else self:HideBeamSource() end @@ -312,7 +321,7 @@ CollisionBeam = Class(moho.CollisionBeamEntity) { -- Buffs (Stun, etc) if targetEntity and IsUnit(targetEntity) then - self:DoUnitImpactBuffs(targetEntity) + self:DoUnitImpactBuffs(targetEntity --[[@as Unit]]) end -- Do Damage From 3a1cceade000e8d77824cffbe0218b11228f60b6 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Thu, 26 Sep 2024 23:36:59 -0700 Subject: [PATCH 04/14] Remove debug code in CollisionBeam --- lua/sim/CollisionBeam.lua | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/lua/sim/CollisionBeam.lua b/lua/sim/CollisionBeam.lua index d64fedbef4..63d6f005cd 100644 --- a/lua/sim/CollisionBeam.lua +++ b/lua/sim/CollisionBeam.lua @@ -288,21 +288,6 @@ CollisionBeam = Class(moho.CollisionBeamEntity) { ---@param impactType ImpactType ---@param targetEntity Unit | Projectile | Prop | nil OnImpact = function(self, impactType, targetEntity) - -- LOG('*DEBUG: COLLISION BEAM ONIMPACT ', repr(self)) - -- LOG('*DEBUG: COLLISION BEAM ONIMPACT, WEAPON = ', repr(self.Weapon), 'Type = ', impactType) - -- LOG('CollisionBeam impacted with: ' .. impactType) - -- Possible 'type' values are: - -- 'Unit' - -- 'Terrain' - -- 'Water' - -- 'Air' - -- 'UnitAir' - -- 'Underwater' - -- 'UnitUnderwater' - -- 'Projectile' - -- 'Prop' - -- 'Shield' - if impactType == 'Unit' or impactType == 'UnitAir' or impactType == 'UnitUnderwater' then if not self:GetLauncher() then return From 09980527c9564b76497d489a559be95ee69c5780 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Fri, 27 Sep 2024 00:34:37 -0700 Subject: [PATCH 05/14] Update DefaultBeamWeapon comment --- lua/sim/weapons/DefaultBeamWeapon.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lua/sim/weapons/DefaultBeamWeapon.lua b/lua/sim/weapons/DefaultBeamWeapon.lua index a153ebf51e..1d7e2ef755 100644 --- a/lua/sim/weapons/DefaultBeamWeapon.lua +++ b/lua/sim/weapons/DefaultBeamWeapon.lua @@ -1,4 +1,3 @@ - local DefaultProjectileWeapon = import("/lua/sim/defaultweapons.lua").DefaultProjectileWeapon local CollisionBeam = import("/lua/sim/collisionbeam.lua").CollisionBeam @@ -33,12 +32,11 @@ DefaultBeamWeapon = ClassWeapon(DefaultProjectileWeapon) { -- Create the beam for _, rack in bp.RackBones do for _, muzzle in rack.MuzzleBones do - local beam - beam = self.BeamType { + local beam = self.BeamType { Weapon = self, BeamBone = 0, OtherBone = muzzle, - CollisionCheckInterval = bp.BeamCollisionDelay * 10, -- Why is this multiplied by 10? IceDreamer + CollisionCheckInterval = bp.BeamCollisionDelay * 10, -- convert seconds to ticks } local beamTable = { Beam = beam, Muzzle = muzzle, Destroyables = {} } table.insert(self.Beams, beamTable) From 3ecf6729f479d5918e1500ed9a2ff2cb93459456 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Fri, 27 Sep 2024 01:00:17 -0700 Subject: [PATCH 06/14] Specify type for `beam` variable in defaultbeamweapon Type doesn't propagate without using Class(base)(spec), even though base(spec) is functional. Not sure how to fix that. --- lua/sim/weapons/DefaultBeamWeapon.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/sim/weapons/DefaultBeamWeapon.lua b/lua/sim/weapons/DefaultBeamWeapon.lua index 1d7e2ef755..84c063efa3 100644 --- a/lua/sim/weapons/DefaultBeamWeapon.lua +++ b/lua/sim/weapons/DefaultBeamWeapon.lua @@ -32,6 +32,7 @@ DefaultBeamWeapon = ClassWeapon(DefaultProjectileWeapon) { -- Create the beam for _, rack in bp.RackBones do for _, muzzle in rack.MuzzleBones do + ---@type CollisionBeam local beam = self.BeamType { Weapon = self, BeamBone = 0, From 8bb0d145f662c29fb8e0edc56c7d241255101130 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Fri, 27 Sep 2024 01:01:15 -0700 Subject: [PATCH 07/14] Annotate the beam weapon data put into units --- lua/sim/Unit.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/sim/Unit.lua b/lua/sim/Unit.lua index 94503d4e40..acf28c667f 100644 --- a/lua/sim/Unit.lua +++ b/lua/sim/Unit.lua @@ -148,6 +148,8 @@ local cUnitGetBuildRate = cUnit.GetBuildRate ---@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 ---@field Sync { id: string, army: Army } # Sync table replicated to the global sync table as to be copied to the user layer at sync time. +---@field ignoreDetectionFrom table? # Armies being given free vision to reveal beams hitting targets +---@field reallyDetectedBy table? # Armies that detected the unit without free vision and don't need intel flushed when beam weapons stop hitting Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent, DebugUnitComponent) { IsUnit = true, From f4d8e10fd21f7aedb0341d029f91b4839357bb2c Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:02:25 -0800 Subject: [PATCH 08/14] Update CollisionBeam.lua --- lua/sim/CollisionBeam.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/sim/CollisionBeam.lua b/lua/sim/CollisionBeam.lua index 63d6f005cd..1516c9aabc 100644 --- a/lua/sim/CollisionBeam.lua +++ b/lua/sim/CollisionBeam.lua @@ -282,7 +282,7 @@ CollisionBeam = Class(moho.CollisionBeamEntity) { end, --- Called by the engine while the beam is active every `CollisionCheckInterval + 1` ticks - --- or when `SetBeamFx(beamEmitter, checkCollision)` is called with `CheckCollision = true`. + --- or when `SetBeamFx(beamEmitter, checkCollision)` is called with `checkCollision = true`. --- Expect Impacts with non-physical things like 'Air' (hitting nothing) and 'Underwater' (hitting nothing underwater). ---@param self CollisionBeam ---@param impactType ImpactType From 56abcaaacdc4927f3b8417d20d134f1b2084f9a8 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Thu, 16 Jan 2025 17:07:44 -0800 Subject: [PATCH 09/14] Clean up warnings in DefaultBeamWeapon --- engine/Core.lua | 4 ++++ lua/sim/weapons/DefaultBeamWeapon.lua | 3 +++ lua/sim/weapons/DefaultProjectileWeapon.lua | 1 + lua/system/config.lua | 4 ++++ 4 files changed, 12 insertions(+) diff --git a/engine/Core.lua b/engine/Core.lua index 22177dd279..48ca60ee42 100644 --- a/engine/Core.lua +++ b/engine/Core.lua @@ -251,6 +251,10 @@ end function KillThread(thread) end +---@class thread +local thread = {} +thread.Destroy = KillThread -- Set in /lua/system/config.lua + --- Rounds a number to the nearest integer using the half-round-even rounding (banker's rules) --- This means that it returns the closest integer and tie-breaks towards even numbers --- (since a bias towards even numbers is less detrimental than an upward bias). diff --git a/lua/sim/weapons/DefaultBeamWeapon.lua b/lua/sim/weapons/DefaultBeamWeapon.lua index 84c063efa3..2ad8418f0a 100644 --- a/lua/sim/weapons/DefaultBeamWeapon.lua +++ b/lua/sim/weapons/DefaultBeamWeapon.lua @@ -5,6 +5,8 @@ local CollisionBeam = import("/lua/sim/collisionbeam.lua").CollisionBeam ---@field DisableBeamThreadInstance? thread ---@field Beams { Beam: CollisionBeam, Muzzle: string, Destroyables: table}[] ---@field BeamStarted boolean +---@field HoldFireThread? thread # deprecated +---@field ContBeamOn? boolean DefaultBeamWeapon = ClassWeapon(DefaultProjectileWeapon) { BeamType = CollisionBeam, @@ -114,6 +116,7 @@ DefaultBeamWeapon = ClassWeapon(DefaultProjectileWeapon) { -- continious beams if bp.BeamLifetime == 0 then + ---@diagnostic disable-next-line: deprecated self.HoldFireThread = self:ForkThread(self.WatchForHoldFire, beam) end diff --git a/lua/sim/weapons/DefaultProjectileWeapon.lua b/lua/sim/weapons/DefaultProjectileWeapon.lua index 40a6821df4..b575d81742 100644 --- a/lua/sim/weapons/DefaultProjectileWeapon.lua +++ b/lua/sim/weapons/DefaultProjectileWeapon.lua @@ -29,6 +29,7 @@ local MathClamp = math.clamp ---@field DropBombShortRatio? number if the weapon blueprint requests a trajectory fix, this is set to the ratio of the distance to the target that the projectile is launched short to ---@field SalvoSpreadStart? number if the weapon blueprint requests a trajectory fix, this is set to the value that centers the projectile spread for `CurrentSalvoNumber` shot on the optimal target position ---@field WeaponPackState 'Packed' | 'Unpacked' | 'Unpacking' | 'Packing' +---@field EconDrain? moho.EconomyEvent DefaultProjectileWeapon = ClassWeapon(Weapon) { FxRackChargeMuzzleFlash = {}, diff --git a/lua/system/config.lua b/lua/system/config.lua index 72b54335c2..764ff3e1f8 100644 --- a/lua/system/config.lua +++ b/lua/system/config.lua @@ -7,6 +7,7 @@ --==================================================================================== -- Disable the LuaPlus bit where you can add attributes to nil, booleans, numbers, and strings. -------------------------------------------------------------------------------------- + local function metacleanup(obj) local name = type(obj) local mmt = { @@ -28,6 +29,7 @@ metacleanup('') --==================================================================================== -- Set up a metatable for coroutines (a.k.a. threads) -------------------------------------------------------------------------------------- + local thread_mt = {Destroy = KillThread} thread_mt.__index = thread_mt function thread_mt.__newindex(_, _, _) @@ -40,6 +42,7 @@ setmetatable(getmetatable(coroutine.create(function()end)), thread_mt) -- Replace math.random with our custom random. On the sim side, this is -- a rng with consistent state across all clients. -------------------------------------------------------------------------------------- + if Random then math.random = Random end @@ -49,6 +52,7 @@ end -- Give globals an __index() with an error function. This causes an error message -- when a nonexistent global is accessed, instead of just quietly returning nil. -------------------------------------------------------------------------------------- + local globalsmeta = { __index = function(_, key) error("access to nonexistent global variable " .. repr(key), 2) From efcde59da96e5282cbc60a0da5698fb097e654a4 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Thu, 16 Jan 2025 17:08:00 -0800 Subject: [PATCH 10/14] Annotate the state functions in DefaultBeamWeapon --- lua/sim/weapons/DefaultBeamWeapon.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/sim/weapons/DefaultBeamWeapon.lua b/lua/sim/weapons/DefaultBeamWeapon.lua index 2ad8418f0a..bc2f94671f 100644 --- a/lua/sim/weapons/DefaultBeamWeapon.lua +++ b/lua/sim/weapons/DefaultBeamWeapon.lua @@ -245,6 +245,7 @@ DefaultBeamWeapon = ClassWeapon(DefaultProjectileWeapon) { -- Weapon States Section IdleState = State(DefaultProjectileWeapon.IdleState) { + ---@param self DefaultBeamWeapon Main = function(self) DefaultProjectileWeapon.IdleState.Main(self) self:PlayFxBeamEnd() @@ -253,6 +254,7 @@ DefaultBeamWeapon = ClassWeapon(DefaultProjectileWeapon) { }, WeaponPackingState = State(DefaultProjectileWeapon.WeaponPackingState) { + ---@param self DefaultBeamWeapon Main = function(self) local bp = self.Blueprint if bp.BeamLifetime > 0 then @@ -271,6 +273,7 @@ DefaultBeamWeapon = ClassWeapon(DefaultProjectileWeapon) { end, RackSalvoFireReadyState = State(DefaultProjectileWeapon.RackSalvoFireReadyState) { + ---@param self DefaultBeamWeapon Main = function(self) if not self:EconomySupportsBeam() then self:PlayFxBeamEnd() From 2df1a4aec523367b5b1db04d87997201544f3e3b Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Thu, 16 Jan 2025 17:09:20 -0800 Subject: [PATCH 11/14] Fix "continious" spelling --- lua/aibrains/components/EnergyManagerBrainComponent.lua | 2 +- lua/sim/MatchState.lua | 2 +- lua/sim/weapons/DefaultBeamWeapon.lua | 4 ++-- lua/ui/game/gamemain.lua | 2 +- lua/ui/lobby/changelogData.lua | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lua/aibrains/components/EnergyManagerBrainComponent.lua b/lua/aibrains/components/EnergyManagerBrainComponent.lua index 183f287eb6..be0e3052bb 100644 --- a/lua/aibrains/components/EnergyManagerBrainComponent.lua +++ b/lua/aibrains/components/EnergyManagerBrainComponent.lua @@ -99,7 +99,7 @@ EnergyManagerBrainComponent = ClassSimple { end end, - --- A continious thread that across the life span of the brain. Is the heart and sole of the enabling and disabling of units that are designed to eliminate excess energy. + --- A continuous thread that across the life span of the brain. Is the heart and sole of the enabling and disabling of units that are designed to eliminate excess energy. ---@param self AIBrain ToggleEnergyExcessUnitsThread = function(self) diff --git a/lua/sim/MatchState.lua b/lua/sim/MatchState.lua index ed51975a8d..6d55c127d6 100644 --- a/lua/sim/MatchState.lua +++ b/lua/sim/MatchState.lua @@ -88,7 +88,7 @@ function ObserverAfterDeath(armyIndex) end end ---- Continiously scans the game for brains being defeated or changes in alliances that can cause the game to end +--- Continuously scans the game for brains being defeated or changes in alliances that can cause the game to end local function MatchStateThread() -- determine game conditions diff --git a/lua/sim/weapons/DefaultBeamWeapon.lua b/lua/sim/weapons/DefaultBeamWeapon.lua index bc2f94671f..93a68678ed 100644 --- a/lua/sim/weapons/DefaultBeamWeapon.lua +++ b/lua/sim/weapons/DefaultBeamWeapon.lua @@ -109,12 +109,12 @@ DefaultBeamWeapon = ClassWeapon(DefaultProjectileWeapon) { -- enable the beam beam:Enable() - -- non-continious beams that just end + -- non-continuous beams that just end if bp.BeamLifetime > 0 then self:ForkThread(self.BeamLifetimeThread, beam, bp.BeamLifetime or 1) end - -- continious beams + -- continuous beams if bp.BeamLifetime == 0 then ---@diagnostic disable-next-line: deprecated self.HoldFireThread = self:ForkThread(self.WatchForHoldFire, beam) diff --git a/lua/ui/game/gamemain.lua b/lua/ui/game/gamemain.lua index 06e6ac4ddc..ce2b0a6505 100644 --- a/lua/ui/game/gamemain.lua +++ b/lua/ui/game/gamemain.lua @@ -581,7 +581,7 @@ function DeselectSelens(selection) return otherUnits, true end ---- A cache used with ObserveSelection to prevent continious table allocations +--- A cache used with ObserveSelection to prevent continuous table allocations local cachedSelection = { oldSelection = { }, newSelection = { }, diff --git a/lua/ui/lobby/changelogData.lua b/lua/ui/lobby/changelogData.lua index b33e656fbc..d3531eefa5 100644 --- a/lua/ui/lobby/changelogData.lua +++ b/lua/ui/lobby/changelogData.lua @@ -2698,7 +2698,7 @@ gamePatches = { "", "- (#4757) Fix hot build not being reset after a build order", "", - "- (#4759) Fix beam weapons continiously restarting as they ground fire", + "- (#4759) Fix beam weapons continuously restarting as they ground fire", " This also fixes the bug where beam weapons that are firing on the ground apply the damage twice", "", "- (#4763) Fix veterancy triggering before death weapons do", @@ -2911,7 +2911,7 @@ gamePatches = { " Only original campaign maps support this feature at the moment.", "", "- (#4689, #4690, #4691) Add hotkey that resembles the 'hard move' functionality introduced by Strogo", - " For those unware: it allows you to continiously issue move orders without queueing them and without accidentally converting them to ", + " For those unware: it allows you to continuously issue move orders without queueing them and without accidentally converting them to ", " patrol orders. This is particularly useful for ASF battles", "", "- (#4095) Adds a partial share game option", From 430d8ac9cf046c64f482819cdc0369bd900551a7 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Thu, 16 Jan 2025 19:29:20 -0800 Subject: [PATCH 12/14] Clean up warnings in CollisionBeam.lua --- lua/sim/CollisionBeam.lua | 3 +-- lua/sim/Unit.lua | 6 +++--- lua/sim/weapon.lua | 1 + 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lua/sim/CollisionBeam.lua b/lua/sim/CollisionBeam.lua index 1516c9aabc..f359a328dc 100644 --- a/lua/sim/CollisionBeam.lua +++ b/lua/sim/CollisionBeam.lua @@ -357,7 +357,6 @@ CollisionBeam = Class(moho.CollisionBeamEntity) { ---@param self CollisionBeam SetDamageTable = function(self) local weaponBlueprint = self.Weapon:GetBlueprint() - ---@type WeaponDamageTable self.DamageTable = {} self.DamageTable.DamageRadius = weaponBlueprint.DamageRadius self.DamageTable.DamageAmount = weaponBlueprint.Damage @@ -367,7 +366,7 @@ CollisionBeam = Class(moho.CollisionBeamEntity) { self.DamageTable.DoTTime = weaponBlueprint.DoTTime self.DamageTable.DoTPulses = weaponBlueprint.DoTPulses self.DamageTable.Buffs = weaponBlueprint.Buffs - self.CollideFriendly = self.DamageData.CollideFriendly == true + self.CollideFriendly = weaponBlueprint.CollideFriendly end, -- When this beam impacts with the target, do any buffs that have been passed to it. diff --git a/lua/sim/Unit.lua b/lua/sim/Unit.lua index acf28c667f..0a2315ce38 100644 --- a/lua/sim/Unit.lua +++ b/lua/sim/Unit.lua @@ -4333,8 +4333,8 @@ Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent, DebugUni ------------------------------------------------------------------------------------------- ---@param self Unit ---@param buffTable BlueprintBuff[] - ---@param PosEntity Vector - AddBuff = function(self, buffTable, PosEntity) + ---@param stunOrigin? Vector # Defaults to position of `self` + AddBuff = function(self, buffTable, stunOrigin) local bt = buffTable.BuffType if not bt then error('*ERROR: Tried to add a unit buff in unit.lua but got no buff table. Wierd.', 1) @@ -4351,7 +4351,7 @@ Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent, DebugUni local targets if buffTable.Radius and buffTable.Radius > 0 then -- If the radius is bigger than 0 then we will use the unit as the center of the stun blast - targets = utilities.GetTrueEnemyUnitsInSphere(self, PosEntity or self:GetPosition(), buffTable.Radius, category) + targets = utilities.GetTrueEnemyUnitsInSphere(self, stunOrigin or self:GetPosition(), buffTable.Radius, category) else -- The buff will be applied to the unit only if EntityCategoryContains(category, self) then diff --git a/lua/sim/weapon.lua b/lua/sim/weapon.lua index a2dceee73b..2f12a97a67 100644 --- a/lua/sim/weapon.lua +++ b/lua/sim/weapon.lua @@ -76,6 +76,7 @@ local WeaponMethods = moho.weapon_methods ---@field Brain AIBrain ---@field CollideFriendly boolean ---@field DamageMod number +---@field DamageModifiers number[] # Set of damage multipliers used by collision beams for the weapon ---@field DamageRadiusMod number ---@field damageTableCache WeaponDamageTable | false # Set to false when the weapon's damage is modified ---@field DisabledBuffs table From 8b865d1088aebdbdd7a41b43ad1f9f79bb32c2ca Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Thu, 16 Jan 2025 19:33:14 -0800 Subject: [PATCH 13/14] Optimize CollisionBeam `SetDamageTable` The beam is only instantiated once so we don't need to do the metatable trick we did with projectiles --- lua/sim/CollisionBeam.lua | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lua/sim/CollisionBeam.lua b/lua/sim/CollisionBeam.lua index f359a328dc..7a4a14da49 100644 --- a/lua/sim/CollisionBeam.lua +++ b/lua/sim/CollisionBeam.lua @@ -356,17 +356,20 @@ CollisionBeam = Class(moho.CollisionBeamEntity) { --- Creates a new `WeaponDamageTable` in `self.DamageTable` using the weapon blueprint ---@param self CollisionBeam SetDamageTable = function(self) - local weaponBlueprint = self.Weapon:GetBlueprint() - self.DamageTable = {} - self.DamageTable.DamageRadius = weaponBlueprint.DamageRadius - self.DamageTable.DamageAmount = weaponBlueprint.Damage - self.DamageTable.DamageType = weaponBlueprint.DamageType - self.DamageTable.DamageFriendly = weaponBlueprint.DamageFriendly - self.DamageTable.CollideFriendly = weaponBlueprint.CollideFriendly - self.DamageTable.DoTTime = weaponBlueprint.DoTTime - self.DamageTable.DoTPulses = weaponBlueprint.DoTPulses - self.DamageTable.Buffs = weaponBlueprint.Buffs - self.CollideFriendly = weaponBlueprint.CollideFriendly + local bp = self.Weapon:GetBlueprint() + local collideFriendly = bp.CollideFriendly + self.DamageTable = { + DamageRadius = bp.DamageRadius, + DamageAmount = bp.Damage, + DamageType = bp.DamageType, + DamageFriendly = bp.DamageFriendly, + CollideFriendly = collideFriendly, + DoTTime = bp.DoTTime, + DoTPulses = bp.DoTPulses, + Buffs = bp.Buffs, + } + -- Cache the table access for collision checks later + self.CollideFriendly = collideFriendly end, -- When this beam impacts with the target, do any buffs that have been passed to it. From 803709677c7e31ecca5e3969ade40eacd4be1450 Mon Sep 17 00:00:00 2001 From: lL1l1 <82986251+lL1l1@users.noreply.github.com> Date: Thu, 16 Jan 2025 19:38:18 -0800 Subject: [PATCH 14/14] Create other.6627.md --- changelog/snippets/other.6627.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/snippets/other.6627.md diff --git a/changelog/snippets/other.6627.md b/changelog/snippets/other.6627.md new file mode 100644 index 0000000000..a001aa7b5f --- /dev/null +++ b/changelog/snippets/other.6627.md @@ -0,0 +1 @@ +- (#6627) Annotate code related to collision beam entities.