Not a member yet? Why not Sign up today
Create an account  

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 
Anti-missile missile code (unfinished/shelved)

#1
The original intent of this script was to shoot down missiles with missiles, however I discovered several problems that I could not solve.

-Game physics limitations. Often times the game interval was not kind to 1400ms+ speed difference. Missiles could not detonate in time.
-Missile detection for medium missiles was ~700m, which was not enough time to launch one turn style and intercept.
-Higher complexity math for the new missiles.
-Re-targeting a different missile after missing a hostile missile was an idea, but i think the threat_table would have to be kept and deleting non-existent missiles instead of refreshed every poll. This might imply using a doubly linked list. I'm sure I could implement this, but the other aspects deter me.

The current code is simple: It detects enemy missiles and depending on their properties, adds them to an array.

I don't care about credit, but I told herpe I would credit him for the craft cone detection.
Feel free to copy-pasta, edit, repost, whatever. Hopefully someone finds use in this.

Code:
--This script was an attempt to simulate CIWS priority algorithm with many missile to missile assignments
--Settings
--Which AI mainframe to get the warning from
mainframeIndex = 0

--Threat values 
--A ratio used to assign local missiles to high priority enemy missiles
threat_speed = 1
threat_distance = 4 --distance should be more important than speed, generally
threat_master_gain = 20 --everything is multiplied by this then added together for the final threat val

--Formula(take the min val of): threat_master_gain * ((distance/threat_distance) + (velocity/threat_velocity))
--The lowest number in the set is considered the most lethal

--Dead enemy missile values
dead_velocity = 50 --any missile traveling under "50ms" is considered out of fuel and not a threat
dead_distance = 100 --missiles under 100m are considered sunk or too late to target
dead_alt = 1 --missiles below this alt are considered dead or sunk

function Update(I)

--BUILDING DATA FOR ENEMY MISSILES--
local num_enemy_missiles = I:GetNumberOfWarnings(mainframeIndex)
local threat_table = {}
local threat_index = 0
--Analyze enemy missiles and create a curated array of hostile missiles
for i=0, num_enemy_missiles - 1 do

enemy_missile = I:GetMissileWarning(mainframeIndex, i)
local is_lethal = true
local missileSpeed = enemy_missile.Velocity.magnitude
--Is the missile facing our craft?
--this tries to identify if our craft is within the missile projected 10 deg cone where .9848... is cos(10)             thanks herpderp for this cone detection
if not (Vector3.Dot(I:GetConstructCenterOfMass() - enemy_missile.Position, enemy_missile.Velocity) > 0.98480775301 * enemy_missile.Range * missileSpeed) then
is_lethal = false
I:LogToHud("FOX 2 DIVERTED")
end

if missileSpeed < dead_velocity or enemy_missile.Range < dead_distance or enemy_missile.Position[2] < dead_alt then
is_lethal = false
end

if not is_lethal then
I:LogToHud("non-lethal")
end

if(is_lethal) then
--Push back onto the array
threat_table[threat_index] = {}
threat_table[threat_index]["Id"] = enemy_missile.Id
threat_table[threat_index]["Pos"] = enemy_missile.Position
threat_table[threat_index]["Velocity"] = enemy_missile.Velocity
threat_table[threat_index]["Threat"] = threat_master_gain * ((enemy_missile.Range/threat_distance) + (missileSpeed/threat_speed))

threat_index = threat_index + 1
end

end
--threat_index is now the size of the table
for i=0, threat_index - 1 do
I:LogToHud(threat_table[i]["Id"])
end


--END BUILDING DATA FOR ENEMY MISSILES--




end
Reply



Messages In This Thread
Anti-missile missile code (unfinished/shelved) - by SLK18 - 2019-04-02, 01:10 AM

Forum Jump:


Users browsing this thread:
1 Guest(s)