Skip to content
Merged
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.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# September
- [Laser weapons] given a tiny AoE to be able to damage small units in shallow water. As a side-effect, they can deal AoE damage to stacked air units.
- [Vertical launcher weapons] keep a higher trajectory when approaching their target and drop from higher angles to avoid terrain and other blockers.
- [T1 Air Constructors] -10 buildpower
- [Grunt, Pawn, Goblin] Script improvements. No longer fire sideways when switching targets mid-shot or going in and out of range
- [Mobile Jammers]
Expand Down
2 changes: 1 addition & 1 deletion luarules/gadgets/unit_custom_weapons_verticalize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ end

local math_max = math.max

local Verticalize = VFS.Include("modules/verticalize.lua")
local Verticalize = require("modules/verticalize")
local getVerticalizeWeapon = Verticalize.getVerticalizeWeapon
local getAscendHeight = Verticalize.getAscendHeight
local newProjectile = Verticalize.newProjectile
Expand Down
14 changes: 0 additions & 14 deletions luaui/Widgets/api_unit_tracker_gl4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,10 @@ local numVisibleUnits = 0

local unitDefIgnore = {}

local factoryUnitDefIDs = {} -- key unitdefid, internalname

local lastknownunitpos = {} -- table on unitID to {x,y,z}

local gameFrame = spGetGameFrame()

for unitDefID, unitDef in pairs(UnitDefs) do
if unitDef.customParams and unitDef.customParams.nohealthbars then
--unitDefIgnore[unitDefID] = true
end --ignore debug units
if unitDef.isFactory then
factoryUnitDefIDs[unitDefID] = unitDef.name
end
end

--- GL4 STUFF ---

local InstanceVBOTable = gl.InstanceVBOTable
Expand Down Expand Up @@ -483,9 +472,6 @@ end
function widget:UnitFinished(unitID, unitDefID, unitTeam) -- todo, this should probably add-remove a unit
widget:UnitDestroyed(unitID, unitDefID, unitTeam, nil, nil, nil, nil, "UnitFinished")
widget:UnitCreated(unitID, unitDefID, unitTeam, nil, "UnitFinished")
if unitTeam == myTeamID and factoryUnitDefIDs[unitDefID] then
widgetHandler:AddSpadsMessage("UnitFinished:" .. tostring(factoryUnitDefIDs[unitDefID]))
end
end

function widget:UnitTaken(unitID, unitDefID, oldTeam, newTeam) --1. this is only called when one if my units gets captured
Expand Down
26 changes: 15 additions & 11 deletions luaui/Widgets/gui_attack_aoe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

local spGetMyTeamID = Spring.GetLocalTeamID
local spGetGroundHeight = Spring.GetGroundHeight
local spGetGroundExtremes = Spring.GetGroundExtremes
local spGetActiveCommand = Spring.GetActiveCommand
local spGetCameraPosition = Spring.GetCameraPosition
local spGetMouseState = Spring.GetMouseState
Expand All @@ -58,12 +59,11 @@
local spIsAboveMiniMap = Spring.IsAboveMiniMap
local spTraceRayGroundBetweenPositions = Spring.TraceRayGroundBetweenPositions

local Starburst = VFS.Include("modules/starburst.lua")
local Starburst = require("modules/starburst")
local getStarburstWeapon = Starburst.getStarburstWeapon
local newStarburst = Starburst.newStarburst
local stepStarburst = Starburst.stepStarburst

local Verticalize = VFS.Include("modules/verticalize.lua")
local Verticalize = require("modules/verticalize")
local getVerticalizeWeapon = Verticalize.getVerticalizeWeapon
local getLaunchTrajectory = Verticalize.getLaunchTrajectory

Expand Down Expand Up @@ -529,7 +529,8 @@
-- The engine decrements uptime before the first trajectory update.
local ascentFrames = max(0, ceil(weaponInfo.uptime * Config.General.gameSpeed) - 1)
local starburstWeapon = weaponInfo.starburst
local starburst = newStarburst(dirX, dirY, dirZ, weaponInfo.startVelocity, ascentFrames, true)
local speed, turnToTarget = weaponInfo.startVelocity, true
local _, _, _, groundMax = spGetGroundExtremes()

for frame = 1, 512 do
if targetMoves then
Expand All @@ -546,14 +547,19 @@
return tx, ty, tz, pathCount
end

stepStarburst(
starburst,
dirX, dirY, dirZ, speed, ascentFrames, turnToTarget = stepStarburst(
starburstWeapon,
dirX,
dirY,
dirZ,
speed,
ascentFrames,
turnToTarget,
targetDX / targetLength,
targetDY / targetLength,
targetDZ / targetLength
)
if not starburst.turnToTarget and not targetMoves then
if not turnToTarget and not targetMoves then
local hitDistance, hitX, hitY, hitZ = spTraceRayGroundBetweenPositions(px, py, pz, tx, ty, tz, false)
if hitDistance and hitDistance + 8 < targetLength then
pathCount = pathCount + 1
Expand All @@ -565,10 +571,8 @@
return tx, ty, tz, pathCount
end

local speed = starburst.speed
dirX, dirY, dirZ = starburst.dirX, starburst.dirY, starburst.dirZ
local nextX, nextY, nextZ = px + dirX * speed, py + dirY * speed, pz + dirZ * speed
local groundY = spGetGroundHeight(nextX, nextZ)
local groundY = nextY < groundMax and spGetGroundHeight(nextX, nextZ)
if groundY and nextY < groundY then
local hitDistance, hitX, hitY, hitZ =
spTraceRayGroundBetweenPositions(px, py, pz, nextX, nextY, nextZ, false)
Expand All @@ -582,7 +586,7 @@
return hitX, hitY, hitZ, pathCount
end
end
if not starburst.turnToTarget and targetLength <= speed + 8 then
if not turnToTarget and targetLength <= speed + 8 then
pathCount = pathCount + 1
pathX[pathCount], pathY[pathCount], pathZ[pathCount] = tx, ty, tz
return tx, ty, tz, pathCount
Expand Down Expand Up @@ -2346,7 +2350,7 @@
if not weaponInfo.mobile then
uy = uy + spGetUnitRadius(aimingUnitID)
end
aimData.source.x, aimData.source.y, aimData.source.z = ux, uy, uz

Check warning on line 2353 in luaui/Widgets/gui_attack_aoe.lua

View workflow job for this annotation

GitHub Actions / emmylua_check

assign-type-mismatch

Cannot assign `number` to `integer`.

if not weaponInfo.waterWeapon and ty < 0 then
ty = 0
Expand Down Expand Up @@ -2505,7 +2509,7 @@

function widget:Update(dt)
local pulsePhase = State.pulsePhase + dt
State.pulsePhase = pulsePhase - floor(pulsePhase)

Check warning on line 2512 in luaui/Widgets/gui_attack_aoe.lua

View workflow job for this annotation

GitHub Actions / emmylua_check

assign-type-mismatch

Cannot assign `number` to `integer`.

if State.isMonitoringStockpile then
if State.isStockpileForManualFire then
Expand All @@ -2515,7 +2519,7 @@
end
end

State.selChangedSec = State.selChangedSec + dt

Check warning on line 2522 in luaui/Widgets/gui_attack_aoe.lua

View workflow job for this annotation

GitHub Actions / emmylua_check

assign-type-mismatch

Cannot assign `number` to `integer`.
if State.selectionChanged and State.selChangedSec > 0.15 then
State.selChangedSec = 0
State.selectionChanged = nil
Expand Down
6 changes: 4 additions & 2 deletions luaui/Widgets/gui_attackrange_gl4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ local unitOnOffable = {}
local unitOnOffName = {}
local unitDefRangeScale = {}
local unitIsStrafingAir = {}
local unitIsSubmarine = {}
for udid, ud in pairs(UnitDefs) do
unitBuilder[udid] = ud.isBuilder and (ud.canAssist or ud.canReclaim) and not (ud.isFactory and #ud.buildOptions > 0)
if unitBuilder[udid] then
Expand All @@ -224,6 +225,7 @@ for udid, ud in pairs(UnitDefs) do
unitMaxWeaponRange[udid] = ud.maxWeaponRange
unitOnOffable[udid] = ud.onOffable
unitIsStrafingAir[udid] = ud.isStrafingAirUnit
unitIsSubmarine[udid] = ud.moveDef.isSubmarine
if ud.customParams.onoffname then
unitOnOffName[udid] = ud.customParams.onoffname
end
Expand Down Expand Up @@ -407,8 +409,8 @@ local function initializeUnitDefRing(unitDefID)
--spEcho("weapons[weaponNum].maxAngleDif",weapons[weaponNum].maxAngleDif, maxangledif)
--for k,v in pairs(weapons[weaponNum]) do spEcho(k,v)end
elseif
-- Strafing aircraft use weapondef tolerance (WeaponDefs.maxAngle, radians) as a forward fire cone.
unitIsStrafingAir[unitDefID]
-- Strafing aircraft / subs use weapondef tolerance (WeaponDefs.maxAngle, radians) as a forward fire cone.
(unitIsStrafingAir[unitDefID] or unitIsSubmarine[unitDefID])
and not skipArc
and not weaponDef.turret
and weaponDef.type ~= "StarburstLauncher"
Expand Down
26 changes: 15 additions & 11 deletions luaui/Widgets/gui_projectile_target_aoe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
local spGetProjectileTimeToLive = Spring.GetProjectileTimeToLive
local spGetProjectileOwnerID = Spring.GetProjectileOwnerID
local spGetGroundHeight = Spring.GetGroundHeight
local spGetGroundExtremes = Spring.GetGroundExtremes
local spTraceRayGroundBetweenPositions = Spring.TraceRayGroundBetweenPositions
local spGetMyAllyTeamID = Spring.GetLocalAllyTeamID
local spGetProjectileTeamID = Spring.GetProjectileTeamID
Expand All @@ -51,12 +52,11 @@
local spIsSphereInView = Spring.IsSphereInView
local spGetCameraPosition = Spring.GetCameraPosition

local Starburst = VFS.Include("modules/starburst.lua")
local Starburst = require("modules/starburst")
local getStarburstWeapon = Starburst.getStarburstWeapon
local newStarburst = Starburst.newStarburst
local stepStarburst = Starburst.stepStarburst

local Verticalize = VFS.Include("modules/verticalize.lua")
local Verticalize = require("modules/verticalize")
local getVerticalizeWeapon = Verticalize.getVerticalizeWeapon
local getInFlightImpact = Verticalize.getInFlightImpact

Expand Down Expand Up @@ -647,7 +647,8 @@
end

local starburstWeapon = weaponInfo.starburst
local starburst = newStarburst(dirX, dirY, dirZ, velocityLength, ascentFrames, turnToTarget)
local speed = velocityLength
local _, _, _, groundMax = spGetGroundExtremes()

local remainingTimeToLive = spGetProjectileTimeToLive(proID)
local maxFrames = min(remainingTimeToLive or 512, 512)
Expand All @@ -668,26 +669,29 @@
return tx, ty, tz, false
end

stepStarburst(
starburst,
dirX, dirY, dirZ, speed, ascentFrames, turnToTarget = stepStarburst(
starburstWeapon,
dirX,
dirY,
dirZ,
speed,
ascentFrames,
turnToTarget,
targetDX / targetLength,
targetDY / targetLength,
targetDZ / targetLength
)

if not starburst.turnToTarget and not targetMoves then
if not turnToTarget and not targetMoves then
local hitDistance, hitX, hitY, hitZ = spTraceRayGroundBetweenPositions(simX, simY, simZ, tx, ty, tz, false)
if hitDistance and hitDistance + 8 < targetLength then
return hitX, hitY, hitZ, true
end
return tx, ty, tz, false
end

local speed = starburst.speed
dirX, dirY, dirZ = starburst.dirX, starburst.dirY, starburst.dirZ
local nextX, nextY, nextZ = simX + dirX * speed, simY + dirY * speed, simZ + dirZ * speed
local groundY = spGetGroundHeight(nextX, nextZ)
local groundY = nextY < groundMax and spGetGroundHeight(nextX, nextZ)
if groundY and nextY < groundY then
local hitDistance, hitX, hitY, hitZ =
spTraceRayGroundBetweenPositions(simX, simY, simZ, nextX, nextY, nextZ, false)
Expand All @@ -699,7 +703,7 @@
return hitX, hitY, hitZ, true
end
end
if not starburst.turnToTarget and targetLength <= speed + 8 then
if not turnToTarget and targetLength <= speed + 8 then
return tx, ty, tz, false
end
simX, simY, simZ = nextX, nextY, nextZ
Expand Down Expand Up @@ -729,7 +733,7 @@
weaponInfo.verticalize,
weaponInfo.starburst,
{ px, py, pz },
{ vx, vy, vz, speed },

Check warning on line 736 in luaui/Widgets/gui_projectile_target_aoe.lua

View workflow job for this annotation

GitHub Actions / emmylua_check

assign-type-mismatch

Cannot assign `number?` to `number`.

Check warning on line 736 in luaui/Widgets/gui_projectile_target_aoe.lua

View workflow job for this annotation

GitHub Actions / emmylua_check

assign-type-mismatch

Cannot assign `number?` to `number`.

Check warning on line 736 in luaui/Widgets/gui_projectile_target_aoe.lua

View workflow job for this annotation

GitHub Actions / emmylua_check

assign-type-mismatch

Cannot assign `number?` to `number`.
elapsedFrames,
{ aimX, aimY, aimZ },
{ aimX, max(spGetGroundHeight(aimX, aimZ), 0), aimZ }
Expand Down
42 changes: 29 additions & 13 deletions modules/starburst.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,44 @@ local function newStarburst(dirX, dirY, dirZ, speed, ascentFrames, turnToTarget)
}
end

---@param starburst Starburst
---@param weapon StarburstWeapon
---@param dirX number
---@param dirY number
---@param dirZ number
---@param speed number
---@param ascentFrames integer
---@param turnToTarget boolean
---@param targetDirX number
---@param targetDirY number
---@param targetDirZ number `targetDir` is the unit vector from the projectile to its target
local function stepStarburst(starburst, weapon, targetDirX, targetDirY, targetDirZ)
local speed = starburst.speed

if starburst.ascentFrames > 0 then
starburst.speed = math_min(speed + weapon.acceleration, weapon.speedMax)
starburst.ascentFrames = starburst.ascentFrames - 1
return
---@return number dirX
---@return number dirY
---@return number dirZ
---@return number speed
---@return integer ascentFrames
---@return boolean turnToTarget
local function stepStarburst(
weapon,
dirX,
dirY,
dirZ,
speed,
ascentFrames,
turnToTarget,
targetDirX,
targetDirY,
targetDirZ
)
if ascentFrames > 0 then
return dirX, dirY, dirZ, math_min(speed + weapon.acceleration, weapon.speedMax), ascentFrames - 1, turnToTarget
end

local dirX, dirY, dirZ = starburst.dirX, starburst.dirY, starburst.dirZ
local directionDotTarget = dirX * targetDirX + dirY * targetDirY + dirZ * targetDirZ
local steerRate
if starburst.turnToTarget then
if turnToTarget then
if directionDotTarget > turnToTargetDot then
dirX, dirY, dirZ = targetDirX, targetDirY, targetDirZ
starburst.turnToTarget = false
turnToTarget = false
else
steerRate = weapon.turnRate
end
Expand Down Expand Up @@ -111,8 +128,7 @@ local function stepStarburst(starburst, weapon, targetDirX, targetDirY, targetDi
end
end

starburst.dirX, starburst.dirY, starburst.dirZ = dirX, dirY, dirZ
starburst.speed = speed
return dirX, dirY, dirZ, speed, ascentFrames, turnToTarget
end

return {
Expand Down
36 changes: 25 additions & 11 deletions modules/verticalize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ local distance2DSquared = math.distance2dSquared
local quadraticRoots = math.quadraticRoots

local spGetGroundHeight = Spring.GetGroundHeight
local spGetGroundExtremes = Spring.GetGroundExtremes
local spTraceRayGroundBetweenPositions = Spring.TraceRayGroundBetweenPositions

local Vectors = VFS.Include("common/vectors.lua")
local Vectors = require("common/vectors")
local dirUp = Vectors.dirUp
local slerp = Vectors.slerp

local Starburst = VFS.Include("modules/starburst.lua")
local Starburst = require("modules/starburst")
local newStarburst = Starburst.newStarburst
local stepStarburst = Starburst.stepStarburst

Expand Down Expand Up @@ -472,6 +473,10 @@ local function simulateToImpact(
)
local x, y, z = position[1], position[2], position[3]
local aimX, aimY, aimZ = aim[1], aim[2], aim[3]
local dirX, dirY, dirZ = starburst.dirX, starburst.dirY, starburst.dirZ
local speed, ascentFrames, turnToTarget = starburst.speed, starburst.ascentFrames, starburst.turnToTarget
local _, _, _, groundMax = spGetGroundExtremes()
local collisionHeightMax = math_max(groundMax, 0.0)

local pathX, pathY, pathZ
local pathCount = 0
Expand All @@ -483,13 +488,12 @@ local function simulateToImpact(

for frame = 0, simulationFramesMax do
if checkFrame and frame >= checkFrame then
local speed = starburst.speed
local nextFrame
repeat
phasePosition[1], phasePosition[2], phasePosition[3] = x, y, z
phaseVelocity[1] = starburst.dirX * speed
phaseVelocity[2] = starburst.dirY * speed
phaseVelocity[3] = starburst.dirZ * speed
phaseVelocity[1] = dirX * speed
phaseVelocity[2] = dirY * speed
phaseVelocity[3] = dirZ * speed
phaseVelocity[4] = speed
nextFrame = updateFlightPhase(projectile, phasePosition, phaseVelocity, frame)
until not nextFrame or nextFrame > frame
Expand All @@ -505,15 +509,25 @@ local function simulateToImpact(
local dx, dy, dz = aimX - x, aimY - y, aimZ - z
local length = math_sqrt(dx * dx + dy * dy + dz * dz)
if length > 0 then
stepStarburst(starburst, starburstWeapon, dx / length, dy / length, dz / length)
dirX, dirY, dirZ, speed, ascentFrames, turnToTarget = stepStarburst(
starburstWeapon,
dirX,
dirY,
dirZ,
speed,
ascentFrames,
turnToTarget,
dx / length,
dy / length,
dz / length
)
end
local speed = starburst.speed
x, y, z = x + starburst.dirX * speed, y + starburst.dirY * speed, z + starburst.dirZ * speed
x, y, z = x + dirX * speed, y + dirY * speed, z + dirZ * speed
end

local groundY = spGetGroundHeight(x, z)
local groundY = y < collisionHeightMax and spGetGroundHeight(x, z)
local hitX, hitY, hitZ
if y < groundY then
if groundY and y < groundY then
local _
_, hitX, hitY, hitZ = spTraceRayGroundBetweenPositions(x0, y0, z0, x, y, z, false)
if not hitX then
Expand Down
2 changes: 0 additions & 2 deletions units/ArmShips/T2/armsubk.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ return {
[1] = {
badtargetcategory = "HOVER NOTSHIP",
def = "ARMSMART_TORPEDO",
maindir = "0 0 1",
maxangledif = 180,
onlytargetcategory = "NOTHOVER",
},
},
Expand Down
2 changes: 0 additions & 2 deletions units/ArmShips/armsub.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ return {
[1] = {
badtargetcategory = "HOVER NOTSHIP",
def = "TORPEDO",
maindir = "0 0 1",
maxangledif = 110,
onlytargetcategory = "NOTHOVER",
},
},
Expand Down
2 changes: 0 additions & 2 deletions units/CorShips/T2/corshark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ return {
[1] = {
badtargetcategory = "HOVER NOTSHIP",
def = "ARMSMART_TORPEDO",
maindir = "0 0 1",
maxangledif = 180,
onlytargetcategory = "NOTHOVER",
},
},
Expand Down
Loading
Loading