Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions changelog/snippets/other.7045.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- (#7045) Document engine-side details of `UnitWeapon:CanFire()`.
3 changes: 2 additions & 1 deletion engine/Core/Blueprints/WeaponBlueprint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@
--- sets `AlwaysRecheckTarget = false` and prevents automatic target resetting
--- so that bombers don't retarget halfway through a bombing run
---@field NeedToComputeBombDrop? boolean
--- if the unit is set as "busy" while the weapon charges
--- If the unit is set as "busy" while the weapon charges/reloads/fires. Set to `true` to allow
--- other weapons to fire/unit actions to occur while this weapon is working.
Comment on lines 215 to +217
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Clarify the “busy” wording to avoid ambiguity.

The current phrasing reads like a sentence fragment and can be interpreted as contradictory. Consider making it explicit that this field controls whether the unit is set as “busy” during charge/reload/fire.

✏️ Suggested wording tweak
---- If the unit is set as "busy" while the weapon charges/reloads/fires. Set to `true` to allow
---- other weapons to fire/unit actions to occur while this weapon is working.
+--- Controls whether the unit is set as "busy" while the weapon charges/reloads/fires. Set to `true` to allow
+--- other weapons to fire/unit actions to occur while this weapon is working.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
---@field NeedToComputeBombDrop? boolean
--- if the unit is set as "busy" while the weapon charges
--- If the unit is set as "busy" while the weapon charges/reloads/fires. Set to `true` to allow
--- other weapons to fire/unit actions to occur while this weapon is working.
---@field NeedToComputeBombDrop? boolean
--- Controls whether the unit is set as "busy" while the weapon charges/reloads/fires. Set to `true` to allow
--- other weapons to fire/unit actions to occur while this weapon is working.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@engine/Core/Blueprints/WeaponBlueprint.lua` around lines 215 - 217, The
comment for the optional field NeedToComputeBombDrop? is ambiguous and reads
like a fragment; update its docstring to explicitly state that this boolean
controls whether the unit is marked as "busy" during the weapon's
charge/reload/fire cycle (true = unit is set busy and cannot perform other
actions; false = weapon activity does not mark the unit busy). Locate the doc
comment above the NeedToComputeBombDrop? field in WeaponBlueprint.lua and
replace the current wording with this clear, self-contained explanation
referencing the charge/reload/fire phases.

---@field NotExclusive? boolean
---@field NoPause any unused
--- The damage that the inner ring of the nuke does in each segment. The outer damage will also end
Expand Down
21 changes: 20 additions & 1 deletion engine/Sim/UnitWeapon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,26 @@ local UnitWeapon = {}
function UnitWeapon:BeenDestroyed()
end

--- Returns true if the weapon is aiming at the target as allowed by the FiringTolerance blueprint value and the target is within the weapon's range
--- `UnitWeapon:CanFire` calls this engine `CanFire` function that is used in the firing cycle, alongside
--- the self-explanatory `HasTarget`, `HasSiloAmmo`, and `TargetSolutionStatusGun() == TRS_Available` calls.
---
--- Here is the list of conditions for the engine `CanFire`, written in pseudo-lua with underscores ("_") for engine fields.
--- It can return early in the list, as indicated by the return statements. If no return is reached, it returns false.
--- !unit:IsStunned()
--- !unit:IsUnitState("Busy")
--- !unit.Blueprint.Air.CanFly or unit.Layer == "Air"
--- !unit.Blueprint.AI.NeedUnpack or unit:IsUnitState("Immobile")
--- Check if the weapon's below/above water firing restrictions.
--- if !unit.Blueprint.Air.Winged then return weapon._AimOnTarget end -- aim on target in terms of firing tolerance
--- !weapon.Blueprint.AutoInitiateAttackCommand or unit:_GetSpeed() >= 0.25 * unit.Blueprint.MaxAirSpeed * unit._SpeedMult
--- if !weapon.Blueprint.NeedToComputeBombDrop or !weapon:_HasTarget() then return weapon._AimOnTarget end
--- unit.IsUnitState("MakingAttackRun")
--- if weapon:_UnitIsInBombDropZone() then reutrn weapon._AimOnTarget end --Involves weapon BombDropThreshold and unit PredictAheadForBombDrop
Comment on lines +26 to +40
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix typos/inconsistent call style in pseudo-code.

There’s a misspelling and one method call that deviates from the rest of the block, which can confuse readers or lead to copy/paste errors.

✏️ Suggested doc fixes
---- Check if the weapon's below/above water firing restrictions.
+--- Check if the weapon meets below/above water firing restrictions.
---- unit.IsUnitState("MakingAttackRun")
+--- unit:IsUnitState("MakingAttackRun")
---- if weapon:_UnitIsInBombDropZone() then reutrn weapon._AimOnTarget end --Involves weapon BombDropThreshold and unit PredictAheadForBombDrop
+--- if weapon:_UnitIsInBombDropZone() then return weapon._AimOnTarget end -- Involves weapon BombDropThreshold and unit PredictAheadForBombDrop
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@engine/Sim/UnitWeapon.lua` around lines 26 - 40, The pseudo-code in the
UnitWeapon:CanFire comment has a typo and an inconsistent call style; fix
"reutrn" to "return" and make method calls consistent (use colon form for
instance methods like unit:IsStunned(), unit:IsUnitState("Busy"),
unit:IsUnitState("Immobile"), unit:IsUnitState("MakingAttackRun") and keep
unit:_GetSpeed() if it’s private; ensure weapon calls use consistent naming like
weapon:_HasTarget() and weapon:_UnitIsInBombDropZone() and return
weapon._AimOnTarget where indicated; also clarify the Winged check to read "if
not unit.Blueprint.Air.Winged then return weapon._AimOnTarget end" and keep
comments about BombDropThreshold and PredictAheadForBombDrop unchanged.


--- Returns true if the weapon has a target and it can fire at it, identical to the engine's firing conditions.
---
--- This includes having a target, ammo, a firing solution for the target, aiming within firing tolerance, unit
--- not being busy or stunned, and a list of other conditions based on blueprint values.
---@return boolean
function UnitWeapon:CanFire()
end
Expand Down
Loading