Skip to content

Commit

Permalink
Fix fire towards toggle.
Browse files Browse the repository at this point in the history
Remove Reaver from mex firing.
Fixes #4513.
  • Loading branch information
GoogleFrog committed Sep 18, 2021
1 parent 718f4b1 commit dada08e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
8 changes: 4 additions & 4 deletions LuaRules/Configs/mex_shoot_defs.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local defs = {
{
name = "cloakriot",
fireHeight = 0,
},
--{
-- name = "cloakriot",
-- fireHeight = 0,
--},
{
name = "vehriot",
searchRange = 180,
Expand Down
32 changes: 18 additions & 14 deletions LuaRules/Gadgets/unit_target_on_the_move.lua
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ local function AllowedToFireTowards(unitID, unitData)
if enemyID and IsUnitInRange(unitID, unitData.unitDefID, weaponID, enemyID) then
return false
end

return true
end

Expand All @@ -215,24 +214,20 @@ local function TryToShootAtRange(unitID, unitDefID, weaponID, range, ux, uy, uz,

range = Spring.Utilities.GetUpperEffectiveWeaponRange(unitDefID, uy - fy, weaponID)
if range and fx*fx + fz*fz < range*range then
spSetUnitTarget(unitID, ux + fx, fy, uz + fz, false, true, -1)
--Spring.MarkerAddPoint(ux + fx, fy, uz + fz, "")
return false
return false, ux + fx, fy, uz + fz
end
return range
end

local function FireTowardsPosition(unitID, unitData, tx, ty, tz)
function GG.GetFireTowardsPos(unitID, unitDefID, tx, ty, tz, buffer)
local _, _, _, ux, uy, uz = spGetUnitPosition(unitID, true) -- my position
local vx, vy, vz, mySpeed = spGetUnitVelocity(unitID)
local unitDefID = unitData.unitDefID

-- Predict own velocity for targeting.
ux, uy, uz = ux + vx * PREDICT_MULT, uy + vy * PREDICT_MULT, uz + vz * PREDICT_MULT

-- Make target vector relative to unit position
local rx, ry, rz = tx - ux, ty - uy, tz - uz
local buffer = fireTowardsRangeBuffer[unitDefID] or setTargetRangeBuffer[unitDefID] or FIRE_TOWARDS_BUFFER

if setTargetSpeedMult[unitDefID] then
buffer = buffer + mySpeed * setTargetSpeedMult[unitDefID]
Expand All @@ -241,27 +236,36 @@ local function FireTowardsPosition(unitID, unitData, tx, ty, tz)
local flatRange, weaponID = GetUnitRange(unitID, unitDefID)
local range = Spring.Utilities.GetUpperEffectiveWeaponRange(unitDefID, -ry, weaponID)
if range and rx*rx + rz*rz < (range - buffer)*(range - buffer) then
spSetUnitTarget(unitID, tx, ty, tz, false, true, -1)
return
return tx, ty, tz
end

range = range or flatRange

local dist = math.sqrt(rx*rx + rz*rz)
local failRange = TryToShootAtRange(unitID, unitData.unitDefID, weaponID, range - buffer, ux, uy, uz, rx, rz, dist)
local failRange, fx, fy, fz = TryToShootAtRange(unitID, unitDefID, weaponID, range - buffer, ux, uy, uz, rx, rz, dist)
if failRange and failRange - buffer < range then
failRange = TryToShootAtRange(unitID, unitData.unitDefID, weaponID, failRange - buffer, ux, uy, uz, rx, rz, dist)
failRange, fx, fy, fz = TryToShootAtRange(unitID, unitDefID, weaponID, failRange - buffer, ux, uy, uz, rx, rz, dist)
end
if failRange and flatRange - (buffer + 5) < failRange then
failRange = TryToShootAtRange(unitID, unitData.unitDefID, weaponID, flatRange - (buffer + 5), ux, uy, uz, rx, rz, dist)
failRange, fx, fy, fz = TryToShootAtRange(unitID, unitDefID, weaponID, flatRange - (buffer + 5), ux, uy, uz, rx, rz, dist)
end
return fx, fy, fz
end

local function FireTowardsPosition(unitID, unitDefID, tx, ty, tz)
local buffer = fireTowardsRangeBuffer[unitDefID] or setTargetRangeBuffer[unitDefID] or FIRE_TOWARDS_BUFFER
local fx, fy, fz = GG.GetFireTowardsPos(unitID, unitDefID, tx, ty, tz, buffer)
if fx then
spSetUnitTarget(unitID, fx, fy, fz, false, true, -1)
--Spring.MarkerAddPoint(ux + fx, fy, uz + fz, "")
end
end

local function CheckFireTowardsGroundTarget(unitID, unitData, tx, ty, tz)
if not AllowedToFireTowards(unitID, unitData) then
return false
end
FireTowardsPosition(unitID, unitData, tx, ty, tz)
FireTowardsPosition(unitID, unitData.unitDefID, tx, ty, tz)
return true
end

Expand All @@ -274,7 +278,7 @@ local function CheckFireTowardsUnitTarget(unitID, unitData, enemyID)
if not tx then
return false
end
FireTowardsPosition(unitID, unitData, tx, ty, tz)
FireTowardsPosition(unitID, unitData.unitDefID, tx, ty, tz)
return true
end

Expand Down
12 changes: 8 additions & 4 deletions LuaRules/Gadgets/unit_ward_fire.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,17 @@ local function DoUnitUpdate(unitID, unitData)
end

if (not targetLeeway) or (effectiveRange + targetLeeway > predictedDist and effectiveRange + behaviour.wardFireLeeway + behaviour.wardFireEnableLeeway < predictedDist) then
local tx, tz = ux + wardFireRange*dx/predictedDist, uz + wardFireRange*dz/predictedDist
local tx, tz = ux + dx, uz + dz
local ty = math.max(0, Spring.GetGroundHeight(tx, tz)) + behaviour.wardFireHeight
local fx, fy, fz = GG.GetFireTowardsPos(unitID, unitData.unitDefID, tx, ty, tz, behaviour.wardFireLeeway)

if doDebug then
Spring.MarkerAddPoint(tx, 0, tz, "F")
Spring.MarkerAddPoint(tx, 0, tz, "T")
Spring.MarkerAddPoint(fx, 0, fz, "F")
end
if fx then
GG.SetTemporaryPosTarget(unitID, fx, fy, fz, false, UPDATE_RATE)
end
local ty = math.max(0, Spring.GetGroundHeight(tx, tz)) + behaviour.wardFireHeight
GG.SetTemporaryPosTarget(unitID, tx, ty, tz, false, UPDATE_RATE)
end
end
end
Expand Down

0 comments on commit dada08e

Please sign in to comment.