Real World Data for the Splash Damage Script#8
Open
TheMime3 wants to merge 25 commits intowheelyjoe:devfrom
Open
Real World Data for the Splash Damage Script#8TheMime3 wants to merge 25 commits intowheelyjoe:devfrom
TheMime3 wants to merge 25 commits intowheelyjoe:devfrom
Conversation
Added SA-5 TR
with help from user "Magnum" on dcs forum: https://forums.eagle.ru/topic/289290-splash-damage-20-script-make-explosions-better/#comment-4857466
added weapons to explTable added new option rocket_multiplier
Add some data Kerv
Update Splash_Damage_2_0.lua
Update Splash_Damage_2_0.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
--assert(loadfile("C:\Users\spenc\OneDrive\Documents\Eclipe_LDT\dcs splash damage\src\mist.lua"))()
--[[
2 October 2020
FrozenDroid:
28 October 2020
FrozenDroid:
21 December 2021
spencershepard (GRIMM):
SPLASH DAMAGE 2.0:
-Added blast wave effect to add timed and scaled secondary explosions on top of game objects
-object geometry within blast wave changes damage intensity
-damage boost for structures since they are hard to kill, even if very close to large explosions
-increased some rocket values in explTable
-missing weapons from explTable will display message to user and log to DCS.log so that we can add what's missing
-damage model for ground units that will disable their weapons and ability to move with partial damage before they are killed
-added options table to allow easy adjustments before release
-general refactoring and restructure
--]]
--21 December 2022
--Gator:
-- Added Real World Values based off data of kill radius of a MK82 Bomb
-- 500lb bomb is 197 with 89kg of TNT. All other values are based off the real world weight of explosives in kg
----[[ ##### SCRIPT CONFIGURATION ##### ]]----
splash_damage_options = {
["static_damage_boost"] = 100, --apply extra damage to Unit.Category.STRUCTUREs with wave explosions
["wave_explosions"] = true, --secondary explosions on top of game objects, radiating outward from the impact point and scaled based on size of object and distance from weapon impact point
["larger_explosions"] = true, --secondary explosions on top of weapon impact points, dictated by the values in the explTable
["damage_model"] = true, --allow blast wave to affect ground unit movement and weapons
["blast_search_radius"] = 5000, --this is the max size of any blast wave radius, since we will only find objects within this zone
["cascade_damage_threshold"] = 5, --if the calculated blast damage doesn't exeed this value, there will be no secondary explosion damage on the unit. If this value is too small, the appearance of explosions far outside of an expected radius looks incorrect.
["game_messages"] = false, --enable some messages on screen
["blast_stun"] = false, --not implemented
["unit_disabled_health"] = 90, --if health is below this value after our explosions, disable its movement
["unit_cant_fire_health"] = 80, --if health is below this value after our explosions, set ROE to HOLD to simulate damage weapon systems
["infantry_cant_fire_health"] = 90, --if health is below this value after our explosions, set ROE to HOLD to simulate severe injury
["debug"] = false, --enable debugging messages
["weapon_missing_message"] = true, --false disables messages alerting you to weapons missing from the explTable
}
local script_enable = 1
refreshRate = 0.1
----[[ ##### End of SCRIPT CONFIGURATION ##### ]]----
--500lb bomb is 197 based on 89kg of TNT
--2000lb bomb is 1000 based on 1400kg of TNT
--Hydra rockets are 4 based on 2kg of TNT
explTable = {
["BGM_109B"] = 1000,
["BGM_109C"] = 1000,
["AIM_120C"] = 44,
["AIM_120B"] = 48,
["AIM_9X"] = 20,
["AIM_9M"] = 20,
["AIM_9L"] = 20,
["AGM_88"] = 150,
["AGR_20A"] = 4,
["BLU_97B"] = 50,
["BLU_108"] = 50,
["CBU_105"] = 1,
["CBU_97"] = 1,
["CBU_87"] = 1,
["CBU_103"] = 10,
["AGR_20_M282"] = 14,
["FAB_100"] = 45,
["FAB_250"] = 100,
["FAB_250M54TU"]= 100,
["FAB_500"] = 213,
["FAB_1500"] = 675,
["BetAB_500"] = 98,
["BetAB_500ShP"]= 107,
["KH-66_Grom"] = 108,
["M_117"] = 405,
["Mk_81"] = 97,
["Mk_82"] = 197,
["AN_M64"] = 275,
["Mk_83"] = 447,
["Mk_84"] = 1000,
["MK_82AIR"] = 197,
["MK_82SNAKEYE"]= 197,
["GBU_10"] = 1000,
["GBU_12"] = 197,
["GBU_54B"] = 197,
["GBU_16"] = 274,
["KAB_1500Kr"] = 675,
["KAB_500Kr"] = 213,
["KAB_500"] = 213,
["GBU_31"] = 1000,
["GBU_31_V_3B"] = 1000,
["GBU_31_V_2B"] = 1000,
["GBU_31_V_4B"] = 1000,
["GBU_32_V_2B"] = 202,
["GBU_54_V_1B"] = 197,
["GBU_38"] = 197,
["AGM_62"] = 400,
["AGM_65D"] = 134,
["AGM_65L"] = 134,
["AGM_65G"] = 319,
["AGM_65H"] = 134,
["AGM_65K"] = 134,
["GBU_24"] = 1000,
["X_23"] = 111,
["X_23L"] = 111,
["X_28"] = 160,
["X_25ML"] = 89,
["X_25MP"] = 89,
["X_25MR"] = 140,
["X_58"] = 140,
["X_29L"] = 320,
["X_29T"] = 320,
["X_29TE"] = 320,
["AGM_84E"] = 797,
["AGM_88C"] = 197,
["AGM_122"] = 25,
["AGM_123"] = 996,
["AGM_130"] = 2007,
["AGM_119"] = 288,
["AGM_154C"] = 10,
["S-24A"] = 24,
["S-25OF"] = 194,
["S-25OFM"] = 150,
["S-25O"] = 150,
["S_25L"] = 190,
["S-5M"] = 1,
["C_8"] = 4,
["C_8OFP2"] = 3,
["C_13"] = 21,
["C_24"] = 123,
["C_25"] = 151,
["HYDRA_70M15"] = 14,
["Zuni_127"] = 5,
["ARAKM70BHE"] = 4,
["BR_500"] = 197,
["Rb 05A"] = 217,
["HEBOMB"] = 40,
["HEBOMBD"] = 40,
["MK-81SE"] = 60,
["AN-M57"] = 56,
["AN-M64"] = 180,
["AN-M65"] = 295,
["AN-M66A2"] = 536,
["HYDRA_70_M151"] = 14,
["HYDRA_70_MPP_APKWS"] = 14,
["HYDRA_70_MK5"] = 14,
["Vikhr_M"] = 14,
}
----[[ ##### HELPER/UTILITY FUNCTIONS ##### ]]----
local function tableHasKey(table,key)
return table[key] ~= nil
end
local function debugMsg(str)
if splash_damage_options.debug == true then
trigger.action.outText(str , 5)
end
end
local function gameMsg(str)
if splash_damage_options.game_messages == true then
trigger.action.outText(str , 5)
end
end
local function getDistance(point1, point2)
local x1 = point1.x
local y1 = point1.y
local z1 = point1.z
local x2 = point2.x
local y2 = point2.y
local z2 = point2.z
local dX = math.abs(x1-x2)
local dZ = math.abs(z1-z2)
local distance = math.sqrt(dXdX + dZdZ)
return distance
end
local function getDistance3D(point1, point2)
local x1 = point1.x
local y1 = point1.y
local z1 = point1.z
local x2 = point2.x
local y2 = point2.y
local z2 = point2.z
local dX = math.abs(x1-x2)
local dY = math.abs(y1-y2)
local dZ = math.abs(z1-z2)
local distance = math.sqrt(dXdX + dZdZ + dY*dY)
return distance
end
local function vec3Mag(speedVec)
local mag = speedVec.xspeedVec.x + speedVec.yspeedVec.y+speedVec.z*speedVec.z
mag = math.sqrt(mag)
--trigger.action.outText("X = " .. speedVec.x ..", y = " .. speedVec.y .. ", z = "..speedVec.z, 10)
--trigger.action.outText("Speed = " .. mag, 1)
return mag
end
local function lookahead(speedVec)
local speed = vec3Mag(speedVec)
local dist = speed * refreshRate * 1.5
return dist
end
----[[ ##### End of HELPER/UTILITY FUNCTIONS ##### ]]----
WpnHandler = {}
tracked_weapons = {}
function track_wpns()
-- env.info("Weapon Track Start")
for wpn_id_, wpnData in pairs(tracked_weapons) do
if wpnData.wpn:isExist() then -- just update speed, position and direction.
wpnData.pos = wpnData.wpn:getPosition().p
wpnData.dir = wpnData.wpn:getPosition().x
wpnData.speed = wpnData.wpn:getVelocity()
--wpnData.lastIP = land.getIP(wpnData.pos, wpnData.dir, 50)
else -- wpn no longer exists, must be dead.
-- trigger.action.outText("Weapon impacted, mass of weapon warhead is " .. wpnData.exMass, 2)
local ip = land.getIP(wpnData.pos, wpnData.dir, lookahead(wpnData.speed)) -- terrain intersection point with weapon's nose. Only search out 20 meters though.
local impactPoint
if not ip then -- use last calculated IP
impactPoint = wpnData.pos
-- trigger.action.outText("Impact Point:\nPos X: " .. impactPoint.x .. "\nPos Z: " .. impactPoint.z, 2)
else -- use intersection point
impactPoint = ip
-- trigger.action.outText("Impact Point:\nPos X: " .. impactPoint.x .. "\nPos Z: " .. impactPoint.z, 2)
end
--env.info("Weapon is gone") -- Got to here --
--trigger.action.outText("Weapon Type was: ".. wpnData.name, 20)
if splash_damage_options.larger_explosions == true then
--env.info("triggered explosion size: "..getWeaponExplosive(wpnData.name))
trigger.action.explosion(impactPoint, getWeaponExplosive(wpnData.name))
--trigger.action.smoke(impactPoint, 0)
end
--if wpnData.cat == Weapon.Category.ROCKET then
blastWave(impactPoint, splash_damage_options.blast_search_radius, wpnData.ordnance, getWeaponExplosive(wpnData.name))
--end
tracked_weapons[wpn_id_] = nil -- remove from tracked weapons first.
end
end
-- env.info("Weapon Track End")
end
function onWpnEvent(event)
if event.id == world.event.S_EVENT_SHOT then
if event.weapon then
local ordnance = event.weapon
local weapon_desc = ordnance:getDesc()
if string.find(ordnance:getTypeName(), "weapons.shells") then
debugMsg("event shot, but not tracking: "..ordnance:getTypeName())
return --we wont track these types of weapons, so exit here
end
end
end
local function protectedCall(...)
local status, retval = pcall(...)
if not status then
env.warning("Splash damage script error... gracefully caught! " .. retval, true)
end
end
function WpnHandler:onEvent(event)
protectedCall(onWpnEvent, event)
end
function explodeObject(table)
local point = table[1]
local distance = table[2]
local power = table[3]
trigger.action.explosion(point, power)
end
function getWeaponExplosive(name)
if explTable[name] then
return explTable[name]
else
return 0
end
end
--controller is only at group level for ground units. we should itterate over the group and only apply effects if health thresholds are met by all units in the group
function modelUnitDamage(units)
--debugMsg("units table: "..mist.utils.tableShow(units))
for i, unit in ipairs(units)
do
--debugMsg("unit table: "..mist.utils.tableShow(unit))
if unit:isExist() then --if units are not already dead
local health = (unit:getLife() / unit:getDesc().life) * 100
--debugMsg(unit:getTypeName().." health %"..health)
if unit:hasAttribute("Infantry") == true and health > 0 then --if infantry
if health <= splash_damage_options.infantry_cant_fire_health then
---disable unit's ability to fire---
unit:getController():setOption(AI.Option.Ground.id.ROE , AI.Option.Ground.val.ROE.WEAPON_HOLD)
end
end
if unit:getDesc().category == Unit.Category.GROUND_UNIT == true and unit:hasAttribute("Infantry") == false and health > 0 then --if ground unit but not infantry
if health <= splash_damage_options.unit_cant_fire_health then
---disable unit's ability to fire---
unit:getController():setOption(AI.Option.Ground.id.ROE , AI.Option.Ground.val.ROE.WEAPON_HOLD)
gameMsg(unit:getTypeName().." weapons disabled")
end
if health <= splash_damage_options.unit_disabled_health and health > 0 then
---disable unit's ability to move---
unit:getController():setTask({id = 'Hold', params = { }} )
unit:getController():setOnOff(false)
gameMsg(unit:getTypeName().." disabled")
end
end
end
end
function blastWave(_point, _radius, weapon, power)
local foundUnits = {}
local volS = {
id = world.VolumeType.SPHERE,
params = {
point = _point,
radius = _radius
}
}
local ifFound = function(foundObject, val)
if foundObject:getDesc().category == Unit.Category.GROUND_UNIT and foundObject:getCategory() == Object.Category.UNIT then
foundUnits[#foundUnits + 1] = foundObject
end
if foundObject:getDesc().category == Unit.Category.GROUND_UNIT then --if ground unit
if splash_damage_options.blast_stun == true then
--suppressUnit(foundObject, 2, weapon)
end
end
if splash_damage_options.wave_explosions == true then
local obj = foundObject
local obj_location = obj:getPoint()
local distance = getDistance(_point, obj_location)
local timing = distance/500
if obj:isExist() then
end
return true
end
world.searchObjects(Object.Category.UNIT, volS, ifFound)
world.searchObjects(Object.Category.STATIC, volS, ifFound)
world.searchObjects(Object.Category.SCENERY, volS, ifFound)
world.searchObjects(Object.Category.CARGO, volS, ifFound)
--world.searchObjects(Object.Category.BASE, volS, ifFound)
if splash_damage_options.damage_model == true then
local id = timer.scheduleFunction(modelUnitDamage, foundUnits, timer.getTime() + 1.5) --allow some time for the game to adjust health levels before running our function
end
end
if (script_enable == 1) then
gameMsg("SPLASH DAMAGE 2 SCRIPT RUNNING")
timer.scheduleFunction(function()
protectedCall(track_wpns)
return timer.getTime() + refreshRate
end,
{},
timer.getTime() + refreshRate
)
world.addEventHandler(WpnHandler)
end