From dada08e548beff050e22aa25449e7a896c1a82cc Mon Sep 17 00:00:00 2001 From: GoogleFrog Date: Sat, 18 Sep 2021 17:02:24 +1000 Subject: [PATCH] Fix fire towards toggle. Remove Reaver from mex firing. Fixes #4513. --- LuaRules/Configs/mex_shoot_defs.lua | 8 ++--- LuaRules/Gadgets/unit_target_on_the_move.lua | 32 +++++++++++--------- LuaRules/Gadgets/unit_ward_fire.lua | 12 +++++--- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/LuaRules/Configs/mex_shoot_defs.lua b/LuaRules/Configs/mex_shoot_defs.lua index 870e4a4577..4c31c90a82 100644 --- a/LuaRules/Configs/mex_shoot_defs.lua +++ b/LuaRules/Configs/mex_shoot_defs.lua @@ -1,8 +1,8 @@ local defs = { - { - name = "cloakriot", - fireHeight = 0, - }, + --{ + -- name = "cloakriot", + -- fireHeight = 0, + --}, { name = "vehriot", searchRange = 180, diff --git a/LuaRules/Gadgets/unit_target_on_the_move.lua b/LuaRules/Gadgets/unit_target_on_the_move.lua index 8c272aec64..6a55f2083c 100644 --- a/LuaRules/Gadgets/unit_target_on_the_move.lua +++ b/LuaRules/Gadgets/unit_target_on_the_move.lua @@ -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 @@ -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] @@ -241,19 +236,28 @@ 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 @@ -261,7 +265,7 @@ 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 @@ -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 diff --git a/LuaRules/Gadgets/unit_ward_fire.lua b/LuaRules/Gadgets/unit_ward_fire.lua index 7f26a35937..9deef89941 100644 --- a/LuaRules/Gadgets/unit_ward_fire.lua +++ b/LuaRules/Gadgets/unit_ward_fire.lua @@ -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