AIBOSS v0.9.0

SPAWN: Added delay for respawn on landing.
RAT v2.3.5: Fixed bug for Vmax cruise.
RECOVERYTANKER v1.0.3
RESCUEHELO v1.0.2
POSITIONABLE: Added GetOffsetCoordinate function
UNIT: Added Explode function.
This commit is contained in:
Frank 2019-01-20 02:02:22 +01:00
parent 6b85141a39
commit dd15da28b2
7 changed files with 2255 additions and 861 deletions

View File

@ -8,7 +8,7 @@
-- * Schedule spawning of new groups.
-- * Put limits on the amount of groups that can be spawned, and the amount of units that can be alive at the same time.
-- * Randomize the spawning location between different zones.
-- * Randomize the intial positions within the zones.
-- * Randomize the initial positions within the zones.
-- * Spawn in array formation.
-- * Spawn uncontrolled (for planes or helos only).
-- * Clean up inactive helicopters that "crashed".
@ -2672,7 +2672,10 @@ function SPAWN:_OnLand( EventData )
if self.RepeatOnLanding then
local SpawnGroupIndex = self:GetSpawnIndexFromGroup( SpawnGroup )
self:T( { "Landed:", "ReSpawn:", SpawnGroup:GetName(), SpawnGroupIndex } )
self:ReSpawn( SpawnGroupIndex )
--self:ReSpawn( SpawnGroupIndex )
-- Delay respawn by three seconds due to DCS 2.5.4.26368 OB bug https://github.com/FlightControl-Master/MOOSE/issues/1076
-- Bug was initially only for engine shutdown event but after ED "fixed" it, it now happens on landing events.
SCHEDULER:New(nil, self.ReSpawn, {self, SpawnGroupIndex}, 3)
end
end
end

View File

@ -546,7 +546,7 @@ RAT.id="RAT | "
--- RAT version.
-- @list version
RAT.version={
version = "2.3.4",
version = "2.3.5",
print = true,
}
@ -2446,7 +2446,7 @@ function RAT:_SetRoute(takeoff, landing, _departure, _destination, _waypoint)
local VxCruiseMax
if self.Vcruisemax then
-- User input.
VxCruiseMax = min(self.Vcruisemax, self.aircraft.Vmax)
VxCruiseMax = math.min(self.Vcruisemax, self.aircraft.Vmax)
else
-- Max cruise speed 90% of Vmax or 900 km/h whichever is lower.
VxCruiseMax = math.min(self.aircraft.Vmax*0.90, 250)

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
--
-- **Main Features:**
--
-- * Regular pattern update with respect to carrier positon.
-- * Regular pattern update with respect to carrier position.
-- * No restrictions regarding carrier waypoints and heading.
-- * Automatic respawning when tanker runs out of fuel for 24/7 operations.
-- * Tanker can be spawned cold or hot on the carrier or at any other airbase or directly in air.
@ -52,7 +52,8 @@
-- @field #boolean uncontrolledac If true, use and uncontrolled tanker group already present in the mission.
-- @field DCS#Vec3 orientation Orientation of the carrier. Used to monitor changes and update the pattern if heading changes significantly.
-- @field DCS#Vec3 orientlast Orientation of the carrier for checking if carrier is currently turning.
-- @field Core.Point#COORDINATE position Positon of carrier. Used to monitor if carrier significantly changed its position and then update the tanker pattern.
-- @field Core.Point#COORDINATE position Position of carrier. Used to monitor if carrier significantly changed its position and then update the tanker pattern.
-- @field #string alias Alias of the spawn group.
-- @extends Core.Fsm#FSM
--- Recovery Tanker.
@ -100,7 +101,7 @@
--
-- ## Takeoff Type
--
-- By default, the tanker is spawned with running engies on the carrier. The mission designer has set option to set the take off type via the @{#RECOVERYTANKER.SetTakeoff} function.
-- By default, the tanker is spawned with running engines on the carrier. The mission designer has set option to set the take off type via the @{#RECOVERYTANKER.SetTakeoff} function.
-- Or via shortcuts
--
-- * @{#RECOVERYTANKER.SetTakeoffHot}(): Will set the takeoff to hot, which is also the default.
@ -113,7 +114,7 @@
-- TexacoStennis:Start()
-- will spawn the tanker several nautical miles astern the carrier. From there it will start its pattern.
--
-- Spawning in air is not as realsitic but can be useful do avoid DCS bugs and shortcomings like aircraft crashing into each other on the flight deck.
-- Spawning in air is not as realistic but can be useful do avoid DCS bugs and shortcomings like aircraft crashing into each other on the flight deck.
--
-- **Note** that when spawning in air is set, the tanker will also not return to the boat, once it is out of fuel. Instead it will be respawned directly in air.
--
@ -177,7 +178,7 @@
-- * The aircraft carrier changes its heading by more than 5 degrees (see @{#RECOVERYTANKER.SetPatternUpdateHeading})
--
-- **Note** that updating the pattern often leads to a more or less small disruption of the perfect racetrack pattern of the tanker. This is because a new waypoint and new racetrack points
-- need to be set as DCS task. This is the reason why the pattern is not contantly updated but rather when the position or heading of the carrier changes significantly.
-- need to be set as DCS task. This is the reason why the pattern is not constantly updated but rather when the position or heading of the carrier changes significantly.
--
-- The maximum update frequency is set to 10 minutes. You can adjust this by @{#RECOVERYTANKER.SetPatternUpdateInterval}.
-- Also the pattern will not be updated whilst the carrier is turning or the tanker is currently refueling another unit.
@ -250,11 +251,16 @@ RECOVERYTANKER = {
orientation = nil,
orientlast = nil,
position = nil,
alias = nil,
}
--- Unique ID (global).
-- @field #number uid Unique ID (global).
RECOVERYTANKER.uid=0
--- Class version.
-- @field #string version
RECOVERYTANKER.version="1.0.2"
RECOVERYTANKER.version="1.0.3"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list
@ -264,7 +270,7 @@ RECOVERYTANKER.version="1.0.2"
-- DONE: Seamless change of position update. Get good updated waypoint and update position if tanker position is right. Not really possiple atm.
-- DONE: Check if TACAN mode "X" is allowed for AA TACAN stations. Nope
-- DONE: Check if tanker is going back to "Running" state after RTB and respawn.
-- DONE: Write documenation.
-- DONE: Write documentation.
-- DONE: Trace functions self:T instead of self:I for less output.
-- DONE: Make pattern update parameters (distance, orientation) input parameters.
-- DONE: Add FSM event for pattern update.
@ -302,8 +308,14 @@ function RECOVERYTANKER:New(carrierunit, tankergroupname)
-- Save self in static object. Easier to retrieve later.
self.carrier:SetState(self.carrier, "RECOVERYTANKER", self)
-- Debug log id.
self.lid=string.format("RECOVERYTANKER %s", self.carrier:GetName())
-- Increase unique ID.
RECOVERYTANKER.uid=RECOVERYTANKER.uid+1
-- Set unique spawn alias.
self.alias=string.format("%s_%s_%02d", self.carrier:GetName(), self.tankergroupname, RECOVERYTANKER.uid)
-- Log ID.
self.lid=string.format("RECOVERYTANKER %s |", self.alias)
-- Init default parameters.
self:SetAltitude()
@ -715,11 +727,8 @@ function RECOVERYTANKER:onafterStart(From, Event, To)
self:HandleEvent(EVENTS.Refueling, self._RefuelingStart) --Need explcit functions sice OnEventRefueling and OnEventRefuelingStop did not hook.
self:HandleEvent(EVENTS.RefuelingStop, self._RefuelingStop)
-- Set unique alias for spawn from tanker group name and carrier unit name.
local tankergroupalias=string.format("%s_%s", self.tankergroupname, self.carrier:GetName())
-- Spawn tanker. We need to introduce an alias in case this class is used twice. This would confuse the spawn routine.
local Spawn=SPAWN:NewWithAlias(self.tankergroupname, tankergroupalias)
local Spawn=SPAWN:NewWithAlias(self.tankergroupname, self.alias)
-- Set radio frequency and modulation.
Spawn:InitRadioCommsOnOff(true)
@ -774,7 +783,6 @@ function RECOVERYTANKER:onafterStart(From, Event, To)
-- Initialize route. self.distStern<0!
SCHEDULER:New(nil, self._InitRoute, {self, -self.distStern+UTILS.NMToMeters(3)}, 1)
--self:_InitRoute(-self.distStern+UTILS.NMToMeters(3), 1)
-- Create tanker beacon.
if self.TACANon then
@ -801,79 +809,102 @@ function RECOVERYTANKER:onafterStatus(From, Event, To)
-- Get current time.
local time=timer.getTime()
-- Get fuel of tanker.
local fuel=self.tanker:GetFuel()*100
local text=string.format("Recovery tanker %s: state=%s fuel=%.1f", self.tanker:GetName(), self:GetState(), fuel)
self:T(self.lid..text)
if self.tanker:IsAlive() then
-- Check if tanker is running and not RTBing or refueling.
if self:IsRunning() then
---------------------
-- TANKER is ALIVE --
---------------------
-- Check fuel.
if fuel<self.lowfuel then
-- Get fuel of tanker.
local fuel=self.tanker:GetFuel()*100
local text=string.format("Recovery tanker %s: state=%s fuel=%.1f", self.tanker:GetName(), self:GetState(), fuel)
self:T(self.lid..text)
-- Check if spawn in air is activated.
if self.takeoff==SPAWN.Takeoff.Air or self.respawninair then
-- Check if tanker is running and not RTBing or refueling.
if self:IsRunning() then
-- Check fuel.
if fuel<self.lowfuel then
-- Check that respawn should happen.
if self.respawn then
-- Debug message.
local text=string.format("Respawning recovery tanker %s in air.", self.tanker:GetName())
MESSAGE:New(text, 10, "DEBUG"):ToAllIf(self.Debug)
self:T(self.lid..text)
-- Set heading for respawn template.
self.tanker:InitHeading(self.tanker:GetHeading())
-- Set radio for respawn template.
self.tanker:InitRadioCommsOnOff(true)
self.tanker:InitRadioFrequency(self.RadioFreq)
self.tanker:InitRadioModulation(self.RadioModu)
-- Respawn tanker.
self.tanker=self.tanker:Respawn(nil, true)
-- Create tanker beacon and activate TACAN.
if self.TACANon then
self:_ActivateTACAN(3)
-- Check if spawn in air is activated.
if self.takeoff==SPAWN.Takeoff.Air or self.respawninair then
-- Check that respawn should happen.
if self.respawn then
-- Debug message.
local text=string.format("Respawning recovery tanker %s in air.", self.tanker:GetName())
MESSAGE:New(text, 10, "DEBUG"):ToAllIf(self.Debug)
self:T(self.lid..text)
-- Set heading for respawn template.
self.tanker:InitHeading(self.tanker:GetHeading())
-- Set radio for respawn template.
self.tanker:InitRadioCommsOnOff(true)
self.tanker:InitRadioFrequency(self.RadioFreq)
self.tanker:InitRadioModulation(self.RadioModu)
-- Respawn tanker.
self.tanker=self.tanker:Respawn(nil, true)
-- Create tanker beacon and activate TACAN.
if self.TACANon then
self:_ActivateTACAN(3)
end
-- Update Pattern in 2 seconds. Need to give a bit time so that the respawned group is in the game.
self:__PatternUpdate(2)
end
-- Update Pattern in 2 seconds. Need to give a bit time so that the respawned group is in the game.
self:__PatternUpdate(2)
else
-- Send tanker home if fuel runs low.
self:RTB(self.airbase)
end
else
-- Send tanker home if fuel runs low.
self:RTB(self.airbase)
end
else
if self.Tupdate then
--Time since last pattern update.
local dt=time-self.Tupdate
if self.Tupdate then
-- Check if pattern needs to be updated.
local updatepattern=self:_CheckPatternUpdate(dt)
-- Update pattern.
if updatepattern then
self:PatternUpdate()
--Time since last pattern update.
local dt=time-self.Tupdate
-- Check if pattern needs to be updated.
local updatepattern=self:_CheckPatternUpdate(dt)
-- Update pattern.
if updatepattern then
self:PatternUpdate()
end
end
end
end
-- Call status again in 30 seconds.
if not self:IsStopped() then
self:__Status(-30)
end
else
--------------------
-- TANKER is DEAD --
--------------------
-- Stop FSM.
self:Stop()
-- Restart FSM after 5 seconds.
if self.respawn then
self:__Start(5)
end
end
-- Call status again in 30 seconds.
if not self:IsStopped() then
self:__Status(-30)
end
end
--- On after "PatternUpdate" event. Updates the racetrack pattern of the tanker wrt the carrier position.

View File

@ -47,6 +47,8 @@
-- @field #boolean carrierstop If true, route of carrier was stopped.
-- @field #number HeloFuel0 Initial fuel of helo in percent. Necessary due to DCS bug that helo with full tank does not return fuel via API function.
-- @field #boolean rtb If true, Helo will be return to base on the next status check.
-- @field #number hid Unit ID of the helo group. (Global) Running number.
-- @field #string alias Alias of the spawn group.
-- @extends Core.Fsm#FSM
--- Rescue Helo
@ -64,7 +66,7 @@
--
-- In the mission editor you have to set up a carrier unit, which will act as "mother". In the following, this unit will be named "*USS Stennis*".
--
-- Secondly, you need to define a recue helicopter group in the mission editor and set it to "**LATE ACTIVATED**". The name of the group we'll use is "*Recue Helo*".
-- Secondly, you need to define a rescue helicopter group in the mission editor and set it to "**LATE ACTIVATED**". The name of the group we'll use is "*Recue Helo*".
--
-- The basic script is very simple and consists of only two lines.
--
@ -89,7 +91,7 @@
--
-- ## Takeoff Type
--
-- By default, the helo is spawned with running engies on the carrier. The mission designer has set option to set the take off type via the @{#RESCUEHELO.SetTakeoff} function.
-- By default, the helo is spawned with running engines on the carrier. The mission designer has set option to set the take off type via the @{#RESCUEHELO.SetTakeoff} function.
-- Or via shortcuts
--
-- * @{#RESCUEHELO.SetTakeoffHot}(): Will set the takeoff to hot, which is also the default.
@ -102,7 +104,7 @@
-- RescueheloStennis:Start()
-- will spawn the helo near the USS Stennis in air.
--
-- Spawning in air is not as realsitic but can be useful do avoid DCS bugs and shortcomings like aircraft crashing into each other on the flight deck.
-- Spawning in air is not as realistic but can be useful do avoid DCS bugs and shortcomings like aircraft crashing into each other on the flight deck.
--
-- **Note** that when spawning in air is set, the helo will also not return to the boat, once it is out of fuel. Instead it will be respawned in air.
--
@ -113,7 +115,7 @@
--
-- ## Home Base
--
-- It is possible to define a "home base" other than the aircaft carrier using the @{#RESCUEHELO.SetHomeBase}(*airbase*) function, where *airbase* is
-- It is possible to define a "home base" other than the aircraft carrier using the @{#RESCUEHELO.SetHomeBase}(*airbase*) function, where *airbase* is
-- a @{Wrapper.Airbase#AIRBASE} object or simply the name of the airbase.
--
-- For example, one could imagine a strike group, and the helo will be spawned from another ship which has a helo pad.
@ -127,7 +129,7 @@
--
-- Once the helo runs out of fuel, it will return to the USS Normandy and not the Stennis for respawning.
--
-- ## Formation Positon
-- ## Formation Position
--
-- The position of the helo relative to the mother ship can be tuned via the functions
--
@ -138,7 +140,7 @@
-- ## Rescue Operations
--
-- By default the rescue helo will start a rescue operation if an aircraft crashes or a pilot ejects in the vicinity of the carrier.
-- This is rescricted to aircraft of the same coaliton as the rescue helo. Enemy (or neutral) pilots will be left on their own.
-- This is restricted to aircraft of the same coalition as the rescue helo. Enemy (or neutral) pilots will be left on their own.
--
-- The standard "rescue zone" has a radius of 15 NM (~28 km) around the carrier. The radius can be adjusted via the @{#RESCUEHELO.SetRescueZone}(*radius*) functions,
-- where *radius* is the radius of the zone in nautical miles. If you use multiple rescue helos in the same mission, you might want to ensure that the radii
@ -214,11 +216,16 @@ RESCUEHELO = {
HeloFuel0 = nil,
rtb = nil,
carrierstop = nil,
alias = nil,
}
--- Unique ID (global).
-- @field #number uid Unique ID (global).
RESCUEHELO.uid=0
--- Class version.
-- @field #string version
RESCUEHELO.version="1.0.1"
RESCUEHELO.version="1.0.2"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list
@ -226,8 +233,8 @@ RESCUEHELO.version="1.0.1"
-- TODO: Add messages for rescue mission.
-- TODO: Add option to stop carrier while rescue operation is in progress? Done but NOT working!
-- DONE: Write documenation.
-- DONE: Add option to deactivate the rescueing.
-- DONE: Write documentation.
-- DONE: Add option to deactivate the rescuing.
-- DONE: Possibility to add already present/spawned aircraft, e.g. for warehouse.
-- DONE: Add rescue event when aircraft crashes.
-- DONE: Make offset input parameter.
@ -259,8 +266,14 @@ function RESCUEHELO:New(carrierunit, helogroupname)
-- Helo group name.
self.helogroupname=helogroupname
-- Increase ID.
RESCUEHELO.uid=RESCUEHELO.uid+1
-- Set unique spawn alias.
self.alias=string.format("%s_%s_%02d", self.carrier:GetName(), self.helogroupname, RESCUEHELO.uid)
-- Log ID.
self.lid=string.format("RESCUEHELO %s |", self.carrier:GetName())
self.lid=string.format("RESCUEHELO %s |", self.alias)
-- Init defaults.
self:SetHomeBase(AIRBASE:FindByName(self.carrier:GetName()))
@ -519,9 +532,9 @@ function RESCUEHELO:SetAltitude(alt)
return self
end
--- Set offset parallel to orienation of carrier.
--- Set offset parallel to orientation of carrier.
-- @param #RESCUEHELO self
-- @param #number distance Offset distance in meters. Default 200 m.
-- @param #number distance Offset distance in meters. Default 200 m (~660 ft).
-- @return #RESCUEHELO self
function RESCUEHELO:SetOffsetX(distance)
self.offsetX=distance or 200
@ -530,7 +543,7 @@ end
--- Set offset perpendicular to orientation to carrier.
-- @param #RESCUEHELO self
-- @param #number distance Offset distance in meters. Default 240 m.
-- @param #number distance Offset distance in meters. Default 240 m (~780 ft).
-- @return #RESCUEHELO self
function RESCUEHELO:SetOffsetZ(distance)
self.offsetZ=distance or 240
@ -631,6 +644,13 @@ function RESCUEHELO:IsStopped()
return self:is("Stopped")
end
--- Alias of helo spawn group.
-- @param #RESCUEHELO self
-- @return #string Alias of the helo.
function RESCUEHELO:GetAlias()
return self.alias
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- EVENT functions
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -668,7 +688,8 @@ function RESCUEHELO:OnEventLand(EventData)
self:T(string.format("Rescue helo %s returned from rescue operation.", groupname))
-- Respawn helo at current airbase.
self.helo=group:RespawnAtCurrentAirbase()
--self.helo=group:RespawnAtCurrentAirbase()
SCHEDULER:New(nil, group.RespawnAtCurrentAirbase, {group}, 5)
else
@ -676,7 +697,8 @@ function RESCUEHELO:OnEventLand(EventData)
-- Respawn helo at current airbase anyway.
if self.respawn then
self.helo=group:RespawnAtCurrentAirbase()
--self.helo=group:RespawnAtCurrentAirbase()
SCHEDULER:New(nil, group.RespawnAtCurrentAirbase, {group}, 5)
end
end
@ -685,7 +707,8 @@ function RESCUEHELO:OnEventLand(EventData)
-- Respawn helo at current airbase.
if self.respawn then
self.helo=group:RespawnAtCurrentAirbase()
--self.helo=group:RespawnAtCurrentAirbase()
SCHEDULER:New(nil, group.RespawnAtCurrentAirbase, {group}, 5)
end
end
@ -743,7 +766,11 @@ function RESCUEHELO:_OnEventCrashOrEject(EventData)
else
-- Error message.
self:E(self.lid..string.format("Rescue helo %s crashed!", unitname))
-- Stop FSM.
self:Stop()
end
@ -774,12 +801,9 @@ function RESCUEHELO:onafterStart(From, Event, To)
-- Delay before formation is started.
local delay=120
-- Set unique alias for spawn.
local helogroupalias=string.format("%s_%s", self.helogroupname, self.carrier:GetName())
-- Spawn helo. We need to introduce an alias in case this class is used twice. This would confuse the spawn routine.
local Spawn=SPAWN:NewWithAlias(self.helogroupname, helogroupalias)
local Spawn=SPAWN:NewWithAlias(self.helogroupname, self.alias)
-- Spawn in air or at airbase.
if self.takeoff==SPAWN.Takeoff.Air then
@ -872,58 +896,81 @@ function RESCUEHELO:onafterStatus(From, Event, To)
-- Get current time.
local time=timer.getTime()
-- Get relative fuel wrt to initial fuel of helo (DCS bug https://forums.eagle.ru/showthread.php?t=223712)
local fuel=self.helo:GetFuel()/self.HeloFuel0*100
-- Report current fuel.
local text=string.format("Rescue Helo %s: state=%s fuel=%.1f", self.helo:GetName(), self:GetState(), fuel)
MESSAGE:New(text, 10, "DEBUG"):ToAllIf(self.Debug)
self:T(self.lid..text)
-- Check if helo is running and not RTBing already or rescuing.
if self:IsRunning() then
if self.helo:IsAlive() then
-------------------
-- HELO is ALIVE --
-------------------
-- Get relative fuel wrt to initial fuel of helo (DCS bug https://forums.eagle.ru/showthread.php?t=223712)
local fuel=self.helo:GetFuel()/self.HeloFuel0*100
-- Check if fuel is low.
if fuel<self.lowfuel then
-- Report current fuel.
local text=string.format("Rescue Helo %s: state=%s fuel=%.1f", self.helo:GetName(), self:GetState(), fuel)
MESSAGE:New(text, 10, "DEBUG"):ToAllIf(self.Debug)
self:E(self.lid..text)
if self:IsRunning() then
-- Check if spawn in air is activated.
if self.takeoff==SPAWN.Takeoff.Air or self.respawninair then
-- Check if fuel is low.
if fuel<self.lowfuel then
-- Check if respawn is enabled.
if self.respawn then
-- Check if spawn in air is activated.
if self.takeoff==SPAWN.Takeoff.Air or self.respawninair then
-- Respawn helo in air.
self.helo:Respawn(nil, true)
-- Check if respawn is enabled.
if self.respawn then
end
-- Respawn helo in air.
self.helo:Respawn(nil, true)
end
else
else
-- Send helo back to base.
self:RTB()
end
end
elseif self:IsRescuing() then
if self.rtb then
-- Send helo back to base.
self:RTB()
-- Switch to false.
self.rtb=false
end
end
elseif self:IsRescuing() then
if self.rtb then
-- Send helo back to base.
self:RTB()
-- Switch to false.
self.rtb=false
-- Call status again in 30 seconds.
if not self:IsStopped() then
self:__Status(-30)
end
else
end
-- Call status again in 30 seconds.
if not self:IsStopped() then
self:__Status(-30)
end
------------------
-- HELO is DEAD --
------------------
-- Stop FSM.
self:Stop()
-- Restart FSM after 5 seconds.
if self.respawn then
self:__Start(5)
end
end
end
--- On after "Run" event. FSM will go to "Running" state. If formation is topped, it will be started again.
@ -1083,6 +1130,7 @@ end
-- @param #string Event Event.
-- @param #string To To state.
function RESCUEHELO:onafterStop(From, Event, To)
self.formation:Stop()
self:UnHandleEvent(EVENTS.Land)
self:UnHandleEvent(EVENTS.Crash)
self:UnHandleEvent(EVENTS.Ejection)

View File

@ -4,7 +4,7 @@
--
-- ### Author: **FlightControl**
--
-- ### Contributions:
-- ### Contributions: **Hardcard**, **funkyfranky**
--
-- ===
--
@ -310,6 +310,44 @@ function POSITIONABLE:GetCoordinate()
return nil
end
--- Returns a COORDINATE object, which is offset with respect to the orientation of the POSITIONABLE.
-- @param Wrapper.Positionable#POSITIONABLE self
-- @param #number x Offset in the direction "the nose" of the unit is pointing in meters. Default 0 m.
-- @param #number y Offset "above" the unit in meters. Default 0 m.
-- @param #number z Offset in the direction "the wing" of the unit is pointing in meters. z>0 starboard, z<0 port. Default 0 m.
-- @return Core.Point#COORDINATE The COORDINATE of the offset with respect to the orientation of the POSITIONABLE.
function POSITIONABLE:GetOffsetCoordinate(x,y,z)
-- Default if nil.
x=x or 0
y=y or 0
z=z or 0
-- Vectors making up the coordinate system.
local X=self:GetOrientationX()
local Y=self:GetOrientationY()
local Z=self:GetOrientationZ()
-- Offset vector: x meters ahead, z meters starboard, y meters above.
local A={x=x, y=y, z=z}
-- Scale components of orthonormal coordinate vectors.
local x={x=X.x*A.x, y=X.y*A.x, z=X.z*A.x}
local y={x=Y.x*A.y, y=Y.y*A.y, z=Y.z*A.y}
local z={x=Z.x*A.z, y=Z.y*A.z, z=Z.z*A.z}
-- Add up vectors in the unit coordinate system ==> this gives the offset vector relative the the origin of the map.
local a={x=x.x+y.x+z.x, y=x.y+y.y+z.y, z=x.z+y.z+z.z}
-- Vector from the origin of the map to the unit.
local u=self:GetVec3()
-- Translate offset vector from map origin to the unit: v=u+a.
local v={x=a.x+u.x, y=a.y+u.y, z=a.z+u.z}
-- Return the offset coordinate.
return COORDINATE:NewFromVec3(v)
end
--- Returns a random @{DCS#Vec3} vector within a range, indicating the point in 3D of the POSITIONABLE within the mission.
-- @param Wrapper.Positionable#POSITIONABLE self

View File

@ -783,6 +783,27 @@ function UNIT:GetThreatLevel()
end
--- Triggers an explosion at the coordinates of the unit.
-- @param #UNIT self
-- @param #number power Power of the explosion in kg TNT. Default 100 kg TNT.
-- @param #number delay (Optional) Delay of explosion in seconds.
-- @return #UNIT self
function UNIT:Explode(power, delay)
-- Default.
power=power or 100
-- Check if delay or not.
if delay and delay>0 then
-- Delayed call.
SCHEDULER:New(nil, self.Explode, {self, power}, delay)
else
-- Create an explotion at the coordinate of the unit.
self:GetCoordinate():Explosion(power)
end
return self
end
-- Is functions