Skip to content

Commit 18cb327

Browse files
authored
Annotate fields related to bombs (#6181)
1 parent 1fb8bc7 commit 18cb327

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

changelog/snippets/other.6181.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- (#6181) Annotate fields and functions related to bomb projectiles.

engine/Core/Blueprints/ProjectileBlueprint.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
---@field LeadTarget boolean
6767
--- Whether projectiles should try to stay underwater. Applies only to tracking projectiles.
6868
---@field StayUnderwater boolean
69-
--- if the projectile is initially affected by gravity
69+
--- if the projectile is initially affected by gravity (-4.9 ogrids/second/second)
7070
---@field UseGravity boolean
7171
--- projectile will detonate when going above this height above ground
7272
---@field DetonateAboveHeight number
@@ -133,7 +133,8 @@
133133
---@field MaxZigZag number
134134
--- frequency of zig-zag directional changes, in seconds
135135
---@field ZigZagFrequency number
136-
--- realistic free fall ordinance type weapon
136+
--- When true and weapon muzzle velocity is 0, the projectile's horizontal velocity is set in the direction of the target with the speed of the weapon firing the projectile.
137+
--- Used for realistic free fall ordinance type weapons like bombs
137138
---@field RealisticOrdinance boolean
138139
--- bombs that always drop stright down
139140
---@field StraightDownOrdinance boolean

engine/Core/Blueprints/WeaponBlueprint.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
---@field BeamLifetime number
5252
--- if the weapon will only fire when underwater
5353
---@field BelowWaterFireOnly? boolean
54-
--- threshold to release point before releasing ordnance
54+
--- Distance from bomb firing solution's position to the target's position within which the weapon will fire
5555
---@field BombDropThreshold? number
5656
--- information about the bonuses added to the weapon when it reaches a specific veterancy level
5757
---@field Buffs BlueprintBuff[]

engine/Sim/Projectile.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ end
9090
function Projectile:SetAcceleration(accel)
9191
end
9292

93-
--- Define the ballistic acceleration value, increases velocity in the current direction.
93+
--- Set the vertical (gravitational) acceleration of the projectile. Default is -4.9, which is expected by the engine's weapon targeting and firing
9494
---@param accel number
9595
function Projectile:SetBallisticAcceleration(accel)
9696
end

lua/sim/weapons/DefaultProjectileWeapon.lua

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,14 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) {
187187
proj:SetBallisticAcceleration(-self:CalculateBallisticAcceleration(proj))
188188
end,
189189

190+
--- Returns the positive downwards acceleration needed for a projectile to hit its target when travelling at the same speed as the unit launching it (for bombs)
190191
---@param self DefaultProjectileWeapon
191192
---@param projectile Projectile
192193
---@return number
193194
CalculateBallisticAcceleration = function(self, projectile)
194195
local launcher = projectile:GetLauncher()
195196
if not launcher then -- fail-fast
196-
return 4.75
197+
return 4.9 -- Return the default gravity value if some calculations fail
197198
end
198199

199200
local UnitGetVelocity = UnitGetVelocity
@@ -225,15 +226,15 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) {
225226
if self.Blueprint.MuzzleSalvoSize <= 1 then
226227
-- do the calculation but skip any cache or salvo logic
227228
if not targetPos then
228-
return 4.75
229+
return 4.9
229230
end
230231
if target and not target.IsProp then
231232
targetVelX, _, targetVelZ = UnitGetVelocity(target)
232233
end
233234
local targetPosX, targetPosZ = targetPos[1], targetPos[3]
234235
local distVel = VDist2(projVelX, projVelZ, targetVelX, targetVelZ)
235236
if distVel == 0 then
236-
return 4.75
237+
return 4.9
237238
end
238239
local distPos = VDist2(projPosX, projPosZ, targetPosX, targetPosZ)
239240
do
@@ -243,14 +244,14 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) {
243244
end
244245
end
245246
if distPos == 0 then
246-
return 4.75
247+
return 4.9
247248
end
248249
local time = distPos / distVel
249250
projPosY = projPosY - GetSurfaceHeight(targetPosX + time * targetVelX, targetPosZ + time * targetVelZ)
250251
return 200 * projPosY / (time * time)
251252
else -- otherwise, calculate & cache a couple things the first time only
252253
data = {
253-
lastAccel = 4.75,
254+
lastAccel = 4.9,
254255
targetPos = targetPos,
255256
}
256257
if target then
@@ -283,19 +284,19 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) {
283284
local GetSurfaceHeight = GetSurfaceHeight
284285
local MathSqrt = math.sqrt
285286
local spread = self.AdjustedSalvoDelay * (self.SalvoSpreadStart + self.CurrentSalvoNumber)
286-
-- nominal acceleration is 4.75; however, bomb clusters adjust the time it takes to land
287+
-- default gravitational acceleration is 4.9; however, bomb clusters adjust the time it takes to land
287288
-- so we convert the acceleration to time to add the spread and convert back:
288289
-- h = unitY - surfaceY => h2 = 0.5 * (unitY - surfaceHeight(unitX, unitZ))
289-
-- t = sqrt(2 h / a) + spread => t = sqrt(4 / 4.75 * h2) + spread
290+
-- t = sqrt(2 h / a) + spread => t = sqrt(4 / 4.9 * h2) + spread
290291
-- a = 0.5 h / t^2 => a = h2 / t^2
291292
local halfHeight = 0.5 * (projPosY - GetSurfaceHeight(projPosX, projPosZ))
292-
if halfHeight < 0.01 then return 4.75 end
293-
local time = MathSqrt(0.842105263158 * halfHeight) + spread
293+
if halfHeight < 0.01 then return 4.9 end
294+
local time = MathSqrt(0.816326530612 * halfHeight) + spread
294295

295296
-- now that we know roughly when we'll land, we can find a better guess for where
296297
-- we'll land, and thus guess the true falling height better as well
297298
halfHeight = 0.5 * (projPosY - GetSurfaceHeight(projPosX + time * projVelX, projPosX + time * projVelX))
298-
time = MathSqrt(0.842105263158 * halfHeight) + spread
299+
time = MathSqrt(0.816326530612 * halfHeight) + spread
299300

300301
local acc = halfHeight / (time * time)
301302
data.lastAccel = acc
@@ -306,8 +307,8 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) {
306307
-- velocity will eventually need to multiplied by 10 due to being per tick instead of per second
307308
local distVel = VDist2(projVelX, projVelZ, targetVelX, targetVelZ)
308309
if distVel == 0 then
309-
data.lastAccel = 4.75
310-
return 4.75
310+
data.lastAccel = 4.9
311+
return 4.9
311312
end
312313
local targetPosX, targetPosZ = targetPos[1], targetPos[3]
313314

@@ -324,8 +325,8 @@ DefaultProjectileWeapon = ClassWeapon(Weapon) {
324325
local time = distPos / distVel
325326
local adjustedTime = time + self.AdjustedSalvoDelay * (self.SalvoSpreadStart + self.CurrentSalvoNumber)
326327
if adjustedTime == 0 then
327-
data.lastAccel = 4.75
328-
return 4.75
328+
data.lastAccel = 4.9
329+
return 4.9
329330
end
330331

331332
-- If we have a target, targetPos may have updated now.

0 commit comments

Comments
 (0)