mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Merge pull request #38 from FlightControl-Master/MissileTrainer
Missiletrainer
This commit is contained in:
commit
979de8901c
@ -10,6 +10,7 @@ copy /b Moose_Embedded.lua + ..\Moose\Unit.lua Moose_Embedded.l
|
|||||||
copy /b Moose_Embedded.lua + ..\Moose\Zone.lua Moose_Embedded.lua
|
copy /b Moose_Embedded.lua + ..\Moose\Zone.lua Moose_Embedded.lua
|
||||||
copy /b Moose_Embedded.lua + ..\Moose\Database.lua Moose_Embedded.lua
|
copy /b Moose_Embedded.lua + ..\Moose\Database.lua Moose_Embedded.lua
|
||||||
copy /b Moose_Embedded.lua + ..\Moose\Moose.lua Moose_Embedded.lua
|
copy /b Moose_Embedded.lua + ..\Moose\Moose.lua Moose_Embedded.lua
|
||||||
|
copy /b Moose_Embedded.lua + ..\Moose\TimeTrigger.lua Moose_Embedded.lua
|
||||||
copy /b Moose_Embedded.lua + ..\Moose\Scoring.lua Moose_Embedded.lua
|
copy /b Moose_Embedded.lua + ..\Moose\Scoring.lua Moose_Embedded.lua
|
||||||
copy /b Moose_Embedded.lua + ..\Moose\Cargo.lua Moose_Embedded.lua
|
copy /b Moose_Embedded.lua + ..\Moose\Cargo.lua Moose_Embedded.lua
|
||||||
copy /b Moose_Embedded.lua + ..\Moose\Client.lua Moose_Embedded.lua
|
copy /b Moose_Embedded.lua + ..\Moose\Client.lua Moose_Embedded.lua
|
||||||
@ -31,3 +32,4 @@ copy /b Moose_Embedded.lua + ..\Moose\Spawn.lua Moose_Embedded.l
|
|||||||
copy /b Moose_Embedded.lua + ..\Moose\Movement.lua Moose_Embedded.lua
|
copy /b Moose_Embedded.lua + ..\Moose\Movement.lua Moose_Embedded.lua
|
||||||
copy /b Moose_Embedded.lua + ..\Moose\Sead.lua Moose_Embedded.lua
|
copy /b Moose_Embedded.lua + ..\Moose\Sead.lua Moose_Embedded.lua
|
||||||
copy /b Moose_Embedded.lua + ..\Moose\Escort.lua Moose_Embedded.lua
|
copy /b Moose_Embedded.lua + ..\Moose\Escort.lua Moose_Embedded.lua
|
||||||
|
copy /b Moose_Embedded.lua + ..\Moose\MissileTrainer.lua Moose_Embedded.lua
|
||||||
|
|||||||
@ -5900,6 +5900,90 @@ _EVENTDISPATCHER = EVENT:New() -- #EVENT
|
|||||||
--- Declare the main database object, which is used internally by the MOOSE classes.
|
--- Declare the main database object, which is used internally by the MOOSE classes.
|
||||||
_DATABASE = DATABASE:New():ScanEnvironment() -- Database#DATABASE
|
_DATABASE = DATABASE:New():ScanEnvironment() -- Database#DATABASE
|
||||||
|
|
||||||
|
--- Models time events calling event handing functions.
|
||||||
|
-- @module TimeTrigger
|
||||||
|
-- @author FlightControl
|
||||||
|
|
||||||
|
Include.File( "Routines" )
|
||||||
|
Include.File( "Base" )
|
||||||
|
Include.File( "Cargo" )
|
||||||
|
Include.File( "Message" )
|
||||||
|
|
||||||
|
|
||||||
|
--- The TIMETRIGGER class
|
||||||
|
-- @type TIMETRIGGER
|
||||||
|
-- @extends Base#BASE
|
||||||
|
TIMETRIGGER = {
|
||||||
|
ClassName = "TIMETRIGGER",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
--- TIMETRIGGER constructor.
|
||||||
|
-- @param #TIMETRIGGER self
|
||||||
|
-- @param #function TimeEventFunction
|
||||||
|
-- @param #table TimeEventFunctionArguments
|
||||||
|
-- @param #number StartSeconds
|
||||||
|
-- @param #number RepeatSecondsInterval
|
||||||
|
-- @param #number RandomizationFactor
|
||||||
|
-- @param #number StopSeconds
|
||||||
|
-- @return #TIMETRIGGER
|
||||||
|
function TIMETRIGGER:New( TimeEventObject, TimeEventFunction, TimeEventFunctionArguments, StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds )
|
||||||
|
local self = BASE:Inherit( self, BASE:New() )
|
||||||
|
self:F( { TimeEventObject, TimeEventFunction, TimeEventFunctionArguments, StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds } )
|
||||||
|
|
||||||
|
self.TimeEventObject = TimeEventObject
|
||||||
|
self.TimeEventFunction = TimeEventFunction
|
||||||
|
self.TimeEventFunctionArguments = TimeEventFunctionArguments
|
||||||
|
self.StartSeconds = StartSeconds
|
||||||
|
|
||||||
|
if RepeatSecondsInterval then
|
||||||
|
self.RepeatSecondsInterval = RepeatSecondsInterval
|
||||||
|
else
|
||||||
|
self.RepeatSecondsInterval = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
if RandomizationFactor then
|
||||||
|
self.RandomizationFactor = RandomizationFactor
|
||||||
|
else
|
||||||
|
self.RandomizationFactor = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
if StopSeconds then
|
||||||
|
self.StopSeconds = StopSeconds
|
||||||
|
end
|
||||||
|
|
||||||
|
self.StartTime = timer.getTime()
|
||||||
|
|
||||||
|
self:T("Calling function" .. timer.getTime() + self.StartSeconds )
|
||||||
|
|
||||||
|
timer.scheduleFunction( self.Scheduler, self, timer.getTime() + self.StartSeconds + .01 )
|
||||||
|
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
function TIMETRIGGER:Scheduler()
|
||||||
|
self:F( self.TimeEventFunctionArguments )
|
||||||
|
|
||||||
|
local Result = self.TimeEventFunction( self.TimeEventObject, unpack( self.TimeEventFunctionArguments ) )
|
||||||
|
|
||||||
|
if Result and Result == true then
|
||||||
|
if not self.StopSeconds or ( self.StopSeconds and timer.getTime() <= self.StartTime + self.StopSeconds ) then
|
||||||
|
timer.scheduleFunction(
|
||||||
|
self.Scheduler,
|
||||||
|
self,
|
||||||
|
timer.getTime() + self.RepeatSecondsInterval * math.random( self.RandomizationFactor * self.RepeatSecondsInterval ) + 0.01
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- Scoring system for MOOSE.
|
--- Scoring system for MOOSE.
|
||||||
-- This scoring class calculates the hits and kills that players make within a simulation session.
|
-- This scoring class calculates the hits and kills that players make within a simulation session.
|
||||||
-- Scoring is calculated using a defined algorithm.
|
-- Scoring is calculated using a defined algorithm.
|
||||||
@ -14169,3 +14253,85 @@ function ESCORT:_ReportTargetsScheduler()
|
|||||||
self.ReportTargetsScheduler = nil
|
self.ReportTargetsScheduler = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
--- Provides missile training functions.
|
||||||
|
-- @module MissileTrainer
|
||||||
|
-- @author FlightControl
|
||||||
|
|
||||||
|
Include.File( "Client" )
|
||||||
|
Include.File( "TimeTrigger" )
|
||||||
|
|
||||||
|
--- The MISSILETRAINER class
|
||||||
|
-- @type MISSILETRAINER
|
||||||
|
-- @extends Base#BASE
|
||||||
|
MISSILETRAINER = {
|
||||||
|
ClassName = "MISSILETRAINER",
|
||||||
|
}
|
||||||
|
|
||||||
|
--- Creates the main object which is handling missile tracking.
|
||||||
|
-- When a missile is fired a TIMETRIGGER is set off that follows the missile. When near a certain a client player, the missile will be destroyed.
|
||||||
|
-- @param #MISSILETRAINER
|
||||||
|
-- @param #number Distance The distance in meters when a tracked missile needs to be destroyed when close to a player.
|
||||||
|
-- @return #MISSILETRAINER
|
||||||
|
function MISSILETRAINER:New( Distance )
|
||||||
|
local self = BASE:Inherit( self, BASE:New() )
|
||||||
|
self:F( Distance )
|
||||||
|
|
||||||
|
self.TimeTriggers = {}
|
||||||
|
self.TimeTriggerID = 0
|
||||||
|
|
||||||
|
self.Distance = Distance
|
||||||
|
|
||||||
|
_EVENTDISPATCHER:OnShot( self._EventShot, self )
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Detects if an SA site was shot with an anti radiation missile. In this case, take evasive actions based on the skill level set within the ME.
|
||||||
|
-- @see MISSILETRAINER
|
||||||
|
function MISSILETRAINER:_EventShot( Event )
|
||||||
|
self:F( { Event } )
|
||||||
|
|
||||||
|
local TrainerSourceDCSUnit = Event.IniDCSUnit
|
||||||
|
local TrainerSourceDCSUnitName = Event.IniDCSUnitName
|
||||||
|
local TrainerWeapon = Event.Weapon -- Identify the weapon fired
|
||||||
|
local TrainerWeaponName = Event.WeaponName -- return weapon type
|
||||||
|
|
||||||
|
self:T( "Missile Launched = " .. TrainerWeaponName )
|
||||||
|
|
||||||
|
local TrainerTargetDCSUnit = TrainerWeapon:getTarget() -- Identify target
|
||||||
|
local TrainerTargetDCSUnitName = Unit.getName( TrainerTargetDCSUnit )
|
||||||
|
local TrainerTargetDCSGroup = TrainerTargetDCSUnit:getGroup()
|
||||||
|
local TrainerTargetDCSGroupName = TrainerTargetDCSGroup:getName()
|
||||||
|
local TrainerTargetSkill = _DATABASE.Units[TrainerTargetDCSUnitName].Template.skill
|
||||||
|
|
||||||
|
self:T( TrainerTargetSkill )
|
||||||
|
|
||||||
|
if TrainerTargetSkill == "Client" or TrainerTargetSkill == "Player" then
|
||||||
|
self.TimeTriggers[#self.TimeTriggers+1] = TIMETRIGGER:New( self, self._FollowMissile, { TrainerSourceDCSUnit, TrainerWeapon, TrainerTargetDCSUnit }, 0.5, 0.05, 0 )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function MISSILETRAINER:_FollowMissile( TrainerSourceDCSUnit, TrainerWeapon, TrainerTargetDCSUnit )
|
||||||
|
self:F( { TrainerSourceDCSUnit, TrainerWeapon, TrainerTargetDCSUnit } )
|
||||||
|
|
||||||
|
local TrainerSourceUnit = UNIT:New( TrainerSourceDCSUnit )
|
||||||
|
local TrainerTargetUnit = UNIT:New( TrainerTargetDCSUnit )
|
||||||
|
|
||||||
|
local PositionMissile = TrainerWeapon:getPoint()
|
||||||
|
local PositionTarget = TrainerTargetUnit:GetPositionVec3()
|
||||||
|
|
||||||
|
local Distance = ( ( PositionMissile.x - PositionTarget.x )^2 +
|
||||||
|
( PositionMissile.y - PositionTarget.y )^2 +
|
||||||
|
( PositionMissile.z - PositionTarget.z )^2
|
||||||
|
) ^ 0.5
|
||||||
|
|
||||||
|
MESSAGE:New( "Distance Missle = " .. Distance, nil, 0.2, "/Missile" ):ToAll()
|
||||||
|
|
||||||
|
if Distance <= self.Distance then
|
||||||
|
TrainerWeapon:destroy()
|
||||||
|
MESSAGE:New( "Missle Destroyed", nil, 5, "/Missile" ):ToAll()
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|||||||
@ -1,31 +0,0 @@
|
|||||||
rem Generate Moose_Embedded.lua
|
|
||||||
|
|
||||||
copy Trace.lua ^
|
|
||||||
+ Routines.lua ^
|
|
||||||
+ Base.lua ^
|
|
||||||
+ Menu.lua ^
|
|
||||||
+ Group.lua ^
|
|
||||||
+ Unit.lua ^
|
|
||||||
+ Zone.lua ^
|
|
||||||
+ Database.lua ^
|
|
||||||
+ Cargo.lua ^
|
|
||||||
+ Client.lua ^
|
|
||||||
+ Message.lua ^
|
|
||||||
+ Stage.lua ^
|
|
||||||
+ Task.lua ^
|
|
||||||
+ GoHomeTask.lua ^
|
|
||||||
+ DestroyBaseTask.lua ^
|
|
||||||
+ DestroyGroupsTask.lua ^
|
|
||||||
+ DestroyRadarsTask.lua ^
|
|
||||||
+ DestroyUnitTypesTask.lua ^
|
|
||||||
+ PickupTask.lua ^
|
|
||||||
+ DeployTask.lua ^
|
|
||||||
+ NoTask.lua ^
|
|
||||||
+ RouteTask.lua ^
|
|
||||||
+ Mission.lua ^
|
|
||||||
+ CleanUp.lua ^
|
|
||||||
+ Spawn.lua ^
|
|
||||||
+ Movement.lua ^
|
|
||||||
+ Sead.lua ^
|
|
||||||
Moose_Embedded.lua
|
|
||||||
|
|
||||||
82
Moose/MissileTrainer.lua
Normal file
82
Moose/MissileTrainer.lua
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
--- Provides missile training functions.
|
||||||
|
-- @module MissileTrainer
|
||||||
|
-- @author FlightControl
|
||||||
|
|
||||||
|
Include.File( "Client" )
|
||||||
|
Include.File( "TimeTrigger" )
|
||||||
|
|
||||||
|
--- The MISSILETRAINER class
|
||||||
|
-- @type MISSILETRAINER
|
||||||
|
-- @extends Base#BASE
|
||||||
|
MISSILETRAINER = {
|
||||||
|
ClassName = "MISSILETRAINER",
|
||||||
|
}
|
||||||
|
|
||||||
|
--- Creates the main object which is handling missile tracking.
|
||||||
|
-- When a missile is fired a TIMETRIGGER is set off that follows the missile. When near a certain a client player, the missile will be destroyed.
|
||||||
|
-- @param #MISSILETRAINER
|
||||||
|
-- @param #number Distance The distance in meters when a tracked missile needs to be destroyed when close to a player.
|
||||||
|
-- @return #MISSILETRAINER
|
||||||
|
function MISSILETRAINER:New( Distance )
|
||||||
|
local self = BASE:Inherit( self, BASE:New() )
|
||||||
|
self:F( Distance )
|
||||||
|
|
||||||
|
self.TimeTriggers = {}
|
||||||
|
self.TimeTriggerID = 0
|
||||||
|
|
||||||
|
self.Distance = Distance
|
||||||
|
|
||||||
|
_EVENTDISPATCHER:OnShot( self._EventShot, self )
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Detects if an SA site was shot with an anti radiation missile. In this case, take evasive actions based on the skill level set within the ME.
|
||||||
|
-- @see MISSILETRAINER
|
||||||
|
function MISSILETRAINER:_EventShot( Event )
|
||||||
|
self:F( { Event } )
|
||||||
|
|
||||||
|
local TrainerSourceDCSUnit = Event.IniDCSUnit
|
||||||
|
local TrainerSourceDCSUnitName = Event.IniDCSUnitName
|
||||||
|
local TrainerWeapon = Event.Weapon -- Identify the weapon fired
|
||||||
|
local TrainerWeaponName = Event.WeaponName -- return weapon type
|
||||||
|
|
||||||
|
self:T( "Missile Launched = " .. TrainerWeaponName )
|
||||||
|
|
||||||
|
local TrainerTargetDCSUnit = TrainerWeapon:getTarget() -- Identify target
|
||||||
|
local TrainerTargetDCSUnitName = Unit.getName( TrainerTargetDCSUnit )
|
||||||
|
local TrainerTargetDCSGroup = TrainerTargetDCSUnit:getGroup()
|
||||||
|
local TrainerTargetDCSGroupName = TrainerTargetDCSGroup:getName()
|
||||||
|
local TrainerTargetSkill = _DATABASE.Units[TrainerTargetDCSUnitName].Template.skill
|
||||||
|
|
||||||
|
self:T( TrainerTargetSkill )
|
||||||
|
|
||||||
|
if TrainerTargetSkill == "Client" or TrainerTargetSkill == "Player" then
|
||||||
|
self.TimeTriggers[#self.TimeTriggers+1] = TIMETRIGGER:New( self, self._FollowMissile, { TrainerSourceDCSUnit, TrainerWeapon, TrainerTargetDCSUnit }, 0.5, 0.05, 0 )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function MISSILETRAINER:_FollowMissile( TrainerSourceDCSUnit, TrainerWeapon, TrainerTargetDCSUnit )
|
||||||
|
self:F( { TrainerSourceDCSUnit, TrainerWeapon, TrainerTargetDCSUnit } )
|
||||||
|
|
||||||
|
local TrainerSourceUnit = UNIT:New( TrainerSourceDCSUnit )
|
||||||
|
local TrainerTargetUnit = UNIT:New( TrainerTargetDCSUnit )
|
||||||
|
|
||||||
|
local PositionMissile = TrainerWeapon:getPoint()
|
||||||
|
local PositionTarget = TrainerTargetUnit:GetPositionVec3()
|
||||||
|
|
||||||
|
local Distance = ( ( PositionMissile.x - PositionTarget.x )^2 +
|
||||||
|
( PositionMissile.y - PositionTarget.y )^2 +
|
||||||
|
( PositionMissile.z - PositionTarget.z )^2
|
||||||
|
) ^ 0.5
|
||||||
|
|
||||||
|
MESSAGE:New( "Distance Missle = " .. Distance, nil, 0.2, "/Missile" ):ToAll()
|
||||||
|
|
||||||
|
if Distance <= self.Distance then
|
||||||
|
TrainerWeapon:destroy()
|
||||||
|
MESSAGE:New( "Missle Destroyed", nil, 5, "/Missile" ):ToAll()
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
84
Moose/TimeTrigger.lua
Normal file
84
Moose/TimeTrigger.lua
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
--- Models time events calling event handing functions.
|
||||||
|
-- @module TimeTrigger
|
||||||
|
-- @author FlightControl
|
||||||
|
|
||||||
|
Include.File( "Routines" )
|
||||||
|
Include.File( "Base" )
|
||||||
|
Include.File( "Cargo" )
|
||||||
|
Include.File( "Message" )
|
||||||
|
|
||||||
|
|
||||||
|
--- The TIMETRIGGER class
|
||||||
|
-- @type TIMETRIGGER
|
||||||
|
-- @extends Base#BASE
|
||||||
|
TIMETRIGGER = {
|
||||||
|
ClassName = "TIMETRIGGER",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
--- TIMETRIGGER constructor.
|
||||||
|
-- @param #TIMETRIGGER self
|
||||||
|
-- @param #function TimeEventFunction
|
||||||
|
-- @param #table TimeEventFunctionArguments
|
||||||
|
-- @param #number StartSeconds
|
||||||
|
-- @param #number RepeatSecondsInterval
|
||||||
|
-- @param #number RandomizationFactor
|
||||||
|
-- @param #number StopSeconds
|
||||||
|
-- @return #TIMETRIGGER
|
||||||
|
function TIMETRIGGER:New( TimeEventObject, TimeEventFunction, TimeEventFunctionArguments, StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds )
|
||||||
|
local self = BASE:Inherit( self, BASE:New() )
|
||||||
|
self:F( { TimeEventObject, TimeEventFunction, TimeEventFunctionArguments, StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds } )
|
||||||
|
|
||||||
|
self.TimeEventObject = TimeEventObject
|
||||||
|
self.TimeEventFunction = TimeEventFunction
|
||||||
|
self.TimeEventFunctionArguments = TimeEventFunctionArguments
|
||||||
|
self.StartSeconds = StartSeconds
|
||||||
|
|
||||||
|
if RepeatSecondsInterval then
|
||||||
|
self.RepeatSecondsInterval = RepeatSecondsInterval
|
||||||
|
else
|
||||||
|
self.RepeatSecondsInterval = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
if RandomizationFactor then
|
||||||
|
self.RandomizationFactor = RandomizationFactor
|
||||||
|
else
|
||||||
|
self.RandomizationFactor = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
if StopSeconds then
|
||||||
|
self.StopSeconds = StopSeconds
|
||||||
|
end
|
||||||
|
|
||||||
|
self.StartTime = timer.getTime()
|
||||||
|
|
||||||
|
self:T("Calling function" .. timer.getTime() + self.StartSeconds )
|
||||||
|
|
||||||
|
timer.scheduleFunction( self.Scheduler, self, timer.getTime() + self.StartSeconds + .01 )
|
||||||
|
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
function TIMETRIGGER:Scheduler()
|
||||||
|
self:F( self.TimeEventFunctionArguments )
|
||||||
|
|
||||||
|
local Result = self.TimeEventFunction( self.TimeEventObject, unpack( self.TimeEventFunctionArguments ) )
|
||||||
|
|
||||||
|
if Result and Result == true then
|
||||||
|
if not self.StopSeconds or ( self.StopSeconds and timer.getTime() <= self.StartTime + self.StopSeconds ) then
|
||||||
|
timer.scheduleFunction(
|
||||||
|
self.Scheduler,
|
||||||
|
self,
|
||||||
|
timer.getTime() + self.RepeatSecondsInterval * math.random( self.RandomizationFactor * self.RepeatSecondsInterval ) + 0.01
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
Include.File("Moose")
|
||||||
|
Include.File("MissileTrainer")
|
||||||
|
|
||||||
|
local Trainer = MISSILETRAINER:New( 200 )
|
||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user