mirror of
https://github.com/FlightControl-Master/MOOSE_MISSIONS.git
synced 2025-08-15 10:37:46 +00:00
WEAPON Demos
- Added demos for weapon class
This commit is contained in:
parent
87036368e4
commit
292006147c
@ -0,0 +1,51 @@
|
||||
---
|
||||
-- WEAPON: Track Bomb
|
||||
--
|
||||
-- An F-15E is tasked to drop a Mk-82 bomb at
|
||||
-- the old airfield near Kobuleti.
|
||||
--
|
||||
-- We monitor the SHOT event and track the bomb
|
||||
-- until it impacts.
|
||||
--
|
||||
-- The impact point is marked with red smoke
|
||||
-- and a mark on the F10 map is shown.
|
||||
---
|
||||
|
||||
-- Some message on screen.
|
||||
local text="Starting Weapon Test mission"
|
||||
MESSAGE:New(text, 120):ToLog():ToAll()
|
||||
|
||||
|
||||
-- Create an event handler that monitors the SHOT event.
|
||||
local handler=EVENTHANDLER:New()
|
||||
handler:HandleEvent(EVENTS.Shot)
|
||||
|
||||
|
||||
--- Function called on shot event.
|
||||
function handler:OnEventShot(EventData)
|
||||
local eventdata=EventData --Core.Event#EVENTDATA
|
||||
|
||||
-- Nil check if we have a weapon in the eventdata table.
|
||||
if eventdata and eventdata.weapon then
|
||||
|
||||
-- Debug info.
|
||||
MESSAGE:New(string.format("Captured SHOT Event from unit=%s", eventdata.IniUnitName), 60):ToAll():ToLog()
|
||||
|
||||
-- Create a new WEAPON object from the DCS weapon object in the event data.
|
||||
local weapon=WEAPON:New(eventdata.weapon)
|
||||
|
||||
-- Mark impact point on F10 map.
|
||||
weapon:SetMarkImpact(true)
|
||||
|
||||
-- Smoke impact point.
|
||||
weapon:SetSmokeImpact(true)
|
||||
|
||||
-- Strart tracking the weapon.
|
||||
weapon:StartTrack()
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Active group.
|
||||
GROUP:FindByName("F-15E Bombing"):Activate()
|
||||
Binary file not shown.
@ -0,0 +1,85 @@
|
||||
---
|
||||
-- WEAPON: Track AA Missile
|
||||
--
|
||||
-- An F-15C is tasked to shoot down a MiG-29 drone
|
||||
-- with an AIM-120B AMRAAM.
|
||||
--
|
||||
-- We monitor the SHOT event and track the missile
|
||||
-- until it impacts.
|
||||
--
|
||||
-- During the tracking, we monitor the current target
|
||||
-- of the missile and print out some parameters like
|
||||
-- its speed and distance to the target to the DCS log file.
|
||||
--
|
||||
-- You will find that the missile does not have a target when lauched.
|
||||
-- It will aquire the target after some time during flight, aka go "pitbull".
|
||||
--
|
||||
-- The impact point is marked with red smoke
|
||||
-- and a mark on the F10 map is shown.
|
||||
---
|
||||
|
||||
-- Some message on screen.
|
||||
local text="Starting Weapon Test mission"
|
||||
MESSAGE:New(text, 120):ToLog():ToAll()
|
||||
|
||||
|
||||
-- Create an event handler that monitors the SHOT event.
|
||||
local handler=EVENTHANDLER:New()
|
||||
handler:HandleEvent(EVENTS.Shot)
|
||||
|
||||
--- Function called when a tracked weapon impacts.
|
||||
local function WeaponTrack(Weapon)
|
||||
local weapon=Weapon --Wrapper.Weapon#WEAPON
|
||||
|
||||
-- Get the target of the weapon.
|
||||
local target=weapon:GetTarget() --Wrapper.Unit#UNIT
|
||||
|
||||
-- Get Speed of weapon.
|
||||
local speed=weapon:GetSpeed()
|
||||
|
||||
-- Get target info.
|
||||
local targetName=weapon:GetTargetName()
|
||||
local targetDist=weapon:GetTargetDistance() or -100
|
||||
|
||||
-- Some info
|
||||
local text=string.format("T=%.3f: Tracking weapon Type=%s, speed=%.1f m/s, target=%s, dist=%.1f m", timer.getTime(), weapon:GetTypeName(), speed, targetName, targetDist)
|
||||
env.info(text)
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- Function called on shot event.
|
||||
function handler:OnEventShot(EventData)
|
||||
local eventdata=EventData --Core.Event#EVENTDATA
|
||||
|
||||
-- Nil check if we have a weapon in the eventdata table.
|
||||
if eventdata and eventdata.weapon then
|
||||
|
||||
-- Debug info.
|
||||
MESSAGE:New(string.format("Captured SHOT Event from unit=%s", eventdata.IniUnitName), 60):ToAll():ToLog()
|
||||
|
||||
-- Create a new WEAPON object from the DCS weapon object in the event data.
|
||||
local weapon=WEAPON:New(eventdata.weapon)
|
||||
|
||||
-- Mark impact point on F10 map.
|
||||
weapon:SetMarkImpact(true)
|
||||
|
||||
-- Smoke impact point.
|
||||
weapon:SetSmokeImpact(true)
|
||||
|
||||
-- Set function that is called during tracking of the weapon.
|
||||
-- This function is called on every position update of the weapon, i.e very often!
|
||||
weapon:SetFuncTrack(WeaponTrack)
|
||||
|
||||
-- Strart tracking the weapon.
|
||||
weapon:StartTrack()
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Active group.
|
||||
GROUP:FindByName("F-15C AA"):Activate()
|
||||
|
||||
-- Active target.
|
||||
GROUP:FindByName("MiG-29 Drone"):Activate()
|
||||
Binary file not shown.
@ -0,0 +1,93 @@
|
||||
---
|
||||
-- WEAPON: Track AA Missile
|
||||
--
|
||||
-- An F-16CM Pilot lost control over his aircraft.
|
||||
-- Unfortunately, his current course is guiding him
|
||||
-- directly towards an SA-10 site.
|
||||
--
|
||||
-- We monitor the SHOT event and track the missiles
|
||||
-- from the SAM site and use our latest secret weapon
|
||||
-- (don't ask, it's really secret) to destroy the
|
||||
-- missilies before they reach the aircraft.
|
||||
---
|
||||
|
||||
-- Some message on screen.
|
||||
local text="Starting Weapon Test mission"
|
||||
MESSAGE:New(text, 120):ToLog():ToAll()
|
||||
|
||||
|
||||
-- Create an event handler that monitors the SHOT event.
|
||||
-- NOTE that the event handler should be global here. If local, it gets garbage collected! Not sure why...
|
||||
handler=EVENTHANDLER:New()
|
||||
handler:HandleEvent(EVENTS.Shot)
|
||||
|
||||
--- Function called when a tracked weapon impacts.
|
||||
local function WeaponTrack(Weapon)
|
||||
local weapon=Weapon --Wrapper.Weapon#WEAPON
|
||||
|
||||
-- Get the target of the weapon.
|
||||
local target=weapon:GetTarget() --Wrapper.Unit#UNIT
|
||||
|
||||
-- Get Speed of weapon.
|
||||
local speed=weapon:GetSpeed()
|
||||
|
||||
-- Get type name of weapon.
|
||||
local typeName=weapon:GetTargetName()
|
||||
|
||||
-- Get target info.
|
||||
local targetName=weapon:GetTargetName()
|
||||
local targetDist=weapon:GetTargetDistance() or -100
|
||||
|
||||
|
||||
-- Some info
|
||||
local text=string.format("T=%.3f: Tracking weapon %s Type=%s, speed=%.1f m/s, target=%s, dist=%.1f m", timer.getTime(), weapon.name, typeName, speed, targetName, targetDist)
|
||||
env.info(text)
|
||||
|
||||
if targetDist>0 and targetDist<100 then
|
||||
|
||||
-- Message to screen.
|
||||
MESSAGE:New(string.format("Destroying missile %s from %s", typeName, weapon.launcherName), 60):ToAll():ToLog()
|
||||
|
||||
-- Destroy weapon.
|
||||
weapon:Destroy()
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- Function called on shot event.
|
||||
function handler:OnEventShot(EventData)
|
||||
local eventdata=EventData --Core.Event#EVENTDATA
|
||||
|
||||
-- Debug info.
|
||||
MESSAGE:New(string.format("Captured SHOT Event from unit=%s", tostring(eventdata.IniUnitName)), 60):ToAll():ToLog()
|
||||
|
||||
-- Nil check if we have a weapon in the eventdata table.
|
||||
if eventdata and eventdata.weapon then
|
||||
|
||||
-- Debug info.
|
||||
MESSAGE:New(string.format("Captured SHOT Event from unit=%s GOT WEAPON", tostring(eventdata.IniUnitName)), 60):ToAll():ToLog()
|
||||
|
||||
-- Create a new WEAPON object from the DCS weapon object in the event data.
|
||||
local weapon=WEAPON:New(eventdata.weapon)
|
||||
|
||||
-- Set function that is called during tracking of the weapon.
|
||||
-- This function is called on every position update of the weapon, i.e very often!
|
||||
weapon:SetFuncTrack(WeaponTrack)
|
||||
|
||||
-- Small timer step.
|
||||
weapon:SetTimeStepTrack(0.005)
|
||||
|
||||
-- Strart tracking the weapon.
|
||||
weapon:StartTrack()
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Active group.
|
||||
GROUP:FindByName("SA-10"):Activate()
|
||||
|
||||
-- Active group.
|
||||
GROUP:FindByName("F-16 Flyby"):Activate()
|
||||
Binary file not shown.
@ -0,0 +1,82 @@
|
||||
---
|
||||
-- WEAPON: Track Shell
|
||||
--
|
||||
-- An SPH M109 Paladin is doing target practice
|
||||
-- and tasks to fire one life shell at the old
|
||||
-- runway at Kobuleti.
|
||||
--
|
||||
-- We monitor the SHOT event and track the shell
|
||||
-- until it impacts.
|
||||
--
|
||||
-- The impact point is marked with red smoke
|
||||
-- and a mark on the F10 map is shown.
|
||||
--
|
||||
-- We also use a callback function "WeaponImpact",
|
||||
-- which is called when the shell has impacted
|
||||
-- and check if the shell fell into a zone "X".
|
||||
---
|
||||
|
||||
-- Some message on screen.
|
||||
local text="Starting Weapon Test mission"
|
||||
MESSAGE:New(text, 120):ToLog():ToAll()
|
||||
|
||||
|
||||
-- Create an event handler that monitors the SHOT event.
|
||||
local handler=EVENTHANDLER:New()
|
||||
handler:HandleEvent(EVENTS.Shot)
|
||||
|
||||
--- Function called when a tracked weapon impacts.
|
||||
local function WeaponImpact(Weapon, Zone)
|
||||
local weapon=Weapon --Wrapper.Weapon#WEAPON
|
||||
local zone=Zone --Core.Zone#ZONE_RADIUS
|
||||
|
||||
-- Get impact coordinate of weapon.
|
||||
local impactcoord=weapon:GetImpactCoordinate()
|
||||
|
||||
if impactcoord then
|
||||
|
||||
-- Check if impact was inside the target zone.
|
||||
local inzone=zone:IsCoordinateInZone(impactcoord)
|
||||
|
||||
if inzone then
|
||||
-- Display message to all and in log file.
|
||||
MESSAGE:New(string.format("Weapon %s impacted inside Zone %s! Well, done team of %s", weapon:GetTypeName(), zone:GetName(), weapon.launcherName), 60):ToLog():ToAll()
|
||||
else
|
||||
-- Display message to all and in log file.
|
||||
MESSAGE:New(string.format("Weapon %s impacted OUTSIDE Zone %s! Team of %s has to do some extra practice sessions", weapon:GetTypeName(), zone:GetName(), weapon.launcherName), 60):ToLog():ToAll()
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
--- Function called on shot event.
|
||||
function handler:OnEventShot(EventData)
|
||||
local eventdata=EventData --Core.Event#EVENTDATA
|
||||
|
||||
-- Nil check if we have a weapon in the eventdata table.
|
||||
if eventdata and eventdata.weapon then
|
||||
|
||||
-- Debug info.
|
||||
MESSAGE:New(string.format("Captured SHOT Event from unit=%s", eventdata.IniUnitName), 60):ToAll():ToLog()
|
||||
|
||||
-- Create a new WEAPON object from the DCS weapon object in the event data.
|
||||
local weapon=WEAPON:New(eventdata.weapon)
|
||||
|
||||
-- Mark impact point on F10 map.
|
||||
weapon:SetMarkImpact(true)
|
||||
|
||||
-- Smoke impact point.
|
||||
weapon:SetSmokeImpact(true)
|
||||
|
||||
-- Set function that is called on weapon impact. We also pass the zone as parameter to show how additional parameters are handled.
|
||||
weapon:SetFuncImpact(WeaponImpact, ZONE:FindByName("X"))
|
||||
|
||||
-- Strart tracking the weapon.
|
||||
weapon:StartTrack()
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Active group.
|
||||
GROUP:FindByName("Paladin"):Activate()
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user