mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
OPS
OPSGROUP - Added damage check for groups that are not alive. - Added `:ReturnToLegion` function. - Added `:Teleport` function LEGION - Aircraft dont start hot if on Alert5 mission AUFTRAG - Added Formation parameter to PATROLZONE (for ground only) ARMYGROUP - Set Vee formation for engage group
This commit is contained in:
@@ -888,6 +888,7 @@ end
|
||||
-- @param Ops.Legion#LEGION Legion The Legion.
|
||||
-- @return #OPSGROUP self
|
||||
function OPSGROUP:_SetLegion(Legion)
|
||||
self:T2(self.lid..string.format("Adding opsgroup to legion %s", Legion.alias))
|
||||
self.legion=Legion
|
||||
return self
|
||||
end
|
||||
@@ -1618,13 +1619,6 @@ function OPSGROUP:Despawn(Delay, NoEventRemoveUnit)
|
||||
self.scheduleIDDespawn=self:ScheduleOnce(Delay, OPSGROUP.Despawn, self, 0, NoEventRemoveUnit)
|
||||
else
|
||||
|
||||
if self.legion and not NoEventRemoveUnit then
|
||||
-- Add asset back in 10 seconds.
|
||||
self:T(self.lid..string.format("Despawning Group by adding asset to LEGION!"))
|
||||
self.legion:AddAsset(self.group, 1)
|
||||
return
|
||||
end
|
||||
|
||||
-- Debug info.
|
||||
self:T(self.lid..string.format("Despawning Group!"))
|
||||
|
||||
@@ -1656,6 +1650,30 @@ function OPSGROUP:Despawn(Delay, NoEventRemoveUnit)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Return group back to the legion it belongs to.
|
||||
-- Group is despawned and added back to the stock.
|
||||
-- @param #OPSGROUP self
|
||||
-- @param #number Delay Delay in seconds before the group will be despawned. Default immediately
|
||||
-- @return #OPSGROUP self
|
||||
function OPSGROUP:ReturnToLegion(Delay)
|
||||
|
||||
if Delay and Delay>0 then
|
||||
self.scheduleIDDespawn=self:ScheduleOnce(Delay, OPSGROUP.ReturnToLegion, self)
|
||||
else
|
||||
|
||||
if self.legion then
|
||||
-- Add asset back.
|
||||
self:T(self.lid..string.format("Adding asset back to LEGION"))
|
||||
self.legion:AddAsset(self.group, 1)
|
||||
else
|
||||
self:E(self.lid..string.format("ERROR: Group does not belong to a LEGION!"))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Destroy a unit of the group. A *Unit Lost* for aircraft or *Dead* event for ground/naval units is generated.
|
||||
-- @param #OPSGROUP self
|
||||
-- @param #string UnitName Name of the unit which should be destroyed.
|
||||
@@ -1679,6 +1697,9 @@ function OPSGROUP:DestroyUnit(UnitName, Delay)
|
||||
else
|
||||
self:CreateEventDead(EventTime, unit)
|
||||
end
|
||||
|
||||
-- Despawn unit.
|
||||
unit:destroy()
|
||||
|
||||
end
|
||||
|
||||
@@ -3595,7 +3616,6 @@ function OPSGROUP:onafterTaskExecute(From, Event, To, Task)
|
||||
|
||||
-- Speed and altitude.
|
||||
local Speed=Task.dcstask.params.speed and UTILS.MpsToKnots(Task.dcstask.params.speed) or UTILS.KmphToKnots(self.speedCruise)
|
||||
--local Speed=UTILS.KmphToKnots(Task.dcstask.params.speed or self.speedCruise)
|
||||
local Altitude=Task.dcstask.params.altitude and UTILS.MetersToFeet(Task.dcstask.params.altitude) or nil
|
||||
|
||||
local currUID=self:GetWaypointCurrent().uid
|
||||
@@ -3605,7 +3625,7 @@ function OPSGROUP:onafterTaskExecute(From, Event, To, Task)
|
||||
if self.isFlightgroup then
|
||||
wp=FLIGHTGROUP.AddWaypoint(self, Coordinate, Speed, currUID, Altitude)
|
||||
elseif self.isArmygroup then
|
||||
wp=ARMYGROUP.AddWaypoint(self, Coordinate, Speed, currUID, Formation)
|
||||
wp=ARMYGROUP.AddWaypoint(self, Coordinate, Speed, currUID, Task.dcstask.params.formation)
|
||||
elseif self.isNavygroup then
|
||||
wp=NAVYGROUP.AddWaypoint(self, Coordinate, Speed, currUID, Altitude)
|
||||
end
|
||||
@@ -3632,7 +3652,6 @@ function OPSGROUP:onafterTaskExecute(From, Event, To, Task)
|
||||
|
||||
-- Speed and altitude.
|
||||
local Speed=UTILS.MpsToKnots(Task.dcstask.params.speed) or UTILS.KmphToKnots(self.speedCruise)
|
||||
--local Speed=UTILS.KmphToKnots(Task.dcstask.params.speed or self.speedCruise)
|
||||
local Altitude=Task.dcstask.params.altitude and UTILS.MetersToFeet(Task.dcstask.params.altitude) or nil
|
||||
|
||||
--Coordinate:MarkToAll("Recon Waypoint Execute")
|
||||
@@ -4939,7 +4958,7 @@ function OPSGROUP:onafterPassingWaypoint(From, Event, To, Waypoint)
|
||||
if self.isFlightgroup then
|
||||
wp=FLIGHTGROUP.AddWaypoint(self, Coordinate, Speed, currUID, Altitude)
|
||||
elseif self.isArmygroup then
|
||||
wp=ARMYGROUP.AddWaypoint(self, Coordinate, Speed, currUID, Formation)
|
||||
wp=ARMYGROUP.AddWaypoint(self, Coordinate, Speed, currUID, task.dcstask.params.formation)
|
||||
elseif self.isNavygroup then
|
||||
wp=NAVYGROUP.AddWaypoint(self, Coordinate, Speed, currUID, Altitude)
|
||||
end
|
||||
@@ -4967,7 +4986,6 @@ function OPSGROUP:onafterPassingWaypoint(From, Event, To, Waypoint)
|
||||
|
||||
-- Speed and altitude.
|
||||
local Speed=task.dcstask.params.speed and UTILS.MpsToKnots(task.dcstask.params.speed) or UTILS.KmphToKnots(self.speedCruise)
|
||||
--local Speed=UTILS.KmphToKnots(task.dcstask.params.speed or self.speedCruise)
|
||||
local Altitude=task.dcstask.params.altitude and UTILS.MetersToFeet(task.dcstask.params.altitude) or nil
|
||||
|
||||
-- Debug.
|
||||
@@ -5796,12 +5814,19 @@ end
|
||||
function OPSGROUP:onafterElementDamaged(From, Event, To, Element)
|
||||
self:T(self.lid..string.format("Element damaged %s", Element.name))
|
||||
|
||||
if Element and Element.status~=OPSGROUP.ElementStatus.DEAD then
|
||||
|
||||
local lifepoints=Element.DCSunit:getLife()
|
||||
local lifepoint0=Element.DCSunit:getLife0()
|
||||
if Element and (Element.status~=OPSGROUP.ElementStatus.DEAD and Element.status~=OPSGROUP.ElementStatus.INUTERO) then
|
||||
|
||||
local lifepoints=0
|
||||
|
||||
self:T(self.lid..string.format("Element life %s: %.2f/%.2f", Element.name, lifepoints, lifepoint0))
|
||||
if Element.DCSunit and Element.DCSunit:isExist() then
|
||||
|
||||
-- Get life of unit
|
||||
lifepoints=Element.DCSunit:getLife()
|
||||
|
||||
-- Debug output.
|
||||
self:T(self.lid..string.format("Element life %s: %.2f/%.2f", Element.name, lifepoints, Element.life0))
|
||||
|
||||
end
|
||||
|
||||
if lifepoints<=1.0 then
|
||||
self:T(self.lid..string.format("Element %s life %.2f <= 1.0 ==> Destroyed!", Element.name, lifepoints))
|
||||
@@ -5809,10 +5834,9 @@ function OPSGROUP:onafterElementDamaged(From, Event, To, Element)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
--- On after "ElementDestroyed" event.
|
||||
-- @param #OPSGROUP self
|
||||
-- @param #string From From state.
|
||||
@@ -5851,14 +5875,6 @@ function OPSGROUP:onafterElementDead(From, Event, To, Element)
|
||||
|
||||
-- Set element status.
|
||||
self:_UpdateStatus(Element, OPSGROUP.ElementStatus.DEAD)
|
||||
|
||||
if self.legion then
|
||||
if not self:IsInUtero() then
|
||||
local asset=self.legion:GetAssetByName(self.groupname)
|
||||
local request=self.legion:GetRequestByID(asset.rid)
|
||||
self.legion:_UnitDead(Element.unit, self.group, request)
|
||||
end
|
||||
end
|
||||
|
||||
-- Check if element was lasing and if so, switch to another unit alive to lase.
|
||||
if self.spot.On and self.spot.element.name==Element.name then
|
||||
@@ -5952,6 +5968,80 @@ function OPSGROUP:onafterRespawn(From, Event, To, Template)
|
||||
|
||||
end
|
||||
|
||||
--- Teleport the group to a different location.
|
||||
-- @param #OPSGROUP self
|
||||
-- @param Core.Point#COORDINATE Coordinate Coordinate where the group is teleported to.
|
||||
-- @param #number Delay Delay in seconds before respawn happens. Default 0.
|
||||
-- @return #OPSGROUP self
|
||||
function OPSGROUP:Teleport(Coordinate, Delay)
|
||||
|
||||
if Delay and Delay>0 then
|
||||
self:ScheduleOnce(Delay, OPSGROUP.Teleport, self, Coordinate)
|
||||
else
|
||||
|
||||
-- Debug message.
|
||||
self:T(self.lid.."FF Teleporting...")
|
||||
--Coordinate:MarkToAll("Teleport "..self.groupname)
|
||||
|
||||
-- Check if we have a mission running.
|
||||
if self.currentmission>0 then
|
||||
self:T(self.lid.."Pausing current mission")
|
||||
self:PauseMission()
|
||||
end
|
||||
|
||||
-- Get copy of template.
|
||||
local Template=UTILS.DeepCopy(self.template) --DCS#Template
|
||||
|
||||
-- Template units.
|
||||
local units=Template.units
|
||||
|
||||
-- Table with teleported vectors.
|
||||
local d={}
|
||||
for i=1,#units do
|
||||
local unit=units[i]
|
||||
d[i]={x=Coordinate.x+(units[i].x-units[1].x), y=Coordinate.z+units[i].y-units[1].y}
|
||||
--COORDINATE:NewFromVec2(d[i]):MarkToAll(unit.name.." teleported")
|
||||
end
|
||||
|
||||
for i=#units,1,-1 do
|
||||
local unit=units[i]
|
||||
|
||||
-- Get element.
|
||||
local element=self:GetElementByName(unit.name)
|
||||
|
||||
if element and element.status~=OPSGROUP.ElementStatus.DEAD then
|
||||
|
||||
-- No parking.
|
||||
unit.parking=nil
|
||||
unit.parking_id=nil
|
||||
|
||||
-- Current position.
|
||||
local vec3=element.unit:GetVec3()
|
||||
|
||||
-- Current heading.
|
||||
local heading=element.unit:GetHeading()
|
||||
|
||||
-- Set new x,y.
|
||||
unit.x=d[i].x
|
||||
unit.y=d[i].y
|
||||
|
||||
-- Set altitude.
|
||||
unit.alt=Coordinate.y
|
||||
|
||||
-- Set heading.
|
||||
unit.heading=math.rad(heading)
|
||||
unit.psi=-unit.heading
|
||||
else
|
||||
table.remove(units, i)
|
||||
end
|
||||
end
|
||||
|
||||
-- Respawn from new template.
|
||||
self:_Respawn(0, Template, true)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
--- Respawn the group.
|
||||
-- @param #OPSGROUP self
|
||||
-- @param #number Delay Delay in seconds before respawn happens. Default 0.
|
||||
@@ -5967,58 +6057,60 @@ function OPSGROUP:_Respawn(Delay, Template, Reset)
|
||||
-- Debug message.
|
||||
self:T2(self.lid.."FF _Respawn")
|
||||
|
||||
-- Given template or get old.
|
||||
-- Given template or get copy of old.
|
||||
Template=Template or self:_GetTemplate(true)
|
||||
|
||||
-- Number of destroyed units.
|
||||
self.Ndestroyed=0
|
||||
|
||||
-- Check if group is currently alive.
|
||||
if self:IsAlive() then
|
||||
|
||||
---
|
||||
-- Group is ALIVE
|
||||
---
|
||||
|
||||
--[[
|
||||
|
||||
-- Get units.
|
||||
local units=self.group:GetUnits()
|
||||
|
||||
-- Loop over template units.
|
||||
for UnitID, Unit in pairs(Template.units) do
|
||||
|
||||
for _,_unit in pairs(units) do
|
||||
local unit=_unit --Wrapper.Unit#UNIT
|
||||
|
||||
if unit:GetName()==Unit.name then
|
||||
local vec3=unit:GetVec3()
|
||||
local heading=unit:GetHeading()
|
||||
Unit.x=vec3.x
|
||||
Unit.y=vec3.z
|
||||
Unit.alt=vec3.y
|
||||
Unit.heading=math.rad(heading)
|
||||
Unit.psi=-Unit.heading
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
]]
|
||||
|
||||
-- Template units.
|
||||
local units=Template.units
|
||||
|
||||
for i=#units,1,-1 do
|
||||
local unit=units[i]
|
||||
|
||||
-- Get the element.
|
||||
local element=self:GetElementByName(unit.name)
|
||||
|
||||
if element and element.status~=OPSGROUP.ElementStatus.DEAD then
|
||||
unit.parking=element.parking and element.parking.TerminalID or unit.parking
|
||||
unit.parking_id=nil
|
||||
local vec3=element.unit:GetVec3()
|
||||
local heading=element.unit:GetHeading()
|
||||
unit.x=vec3.x
|
||||
unit.y=vec3.z
|
||||
unit.alt=vec3.y
|
||||
unit.heading=math.rad(heading)
|
||||
unit.psi=-unit.heading
|
||||
|
||||
if not Reset then
|
||||
|
||||
-- Parking ID.
|
||||
unit.parking=element.parking and element.parking.TerminalID or unit.parking
|
||||
unit.parking_id=nil
|
||||
|
||||
-- Get current position vector.
|
||||
local vec3=element.unit:GetVec3()
|
||||
|
||||
-- Get heading.
|
||||
local heading=element.unit:GetHeading()
|
||||
|
||||
-- Set unit position.
|
||||
unit.x=vec3.x
|
||||
unit.y=vec3.z
|
||||
unit.alt=vec3.y
|
||||
|
||||
-- Set heading in rad.
|
||||
unit.heading=math.rad(heading)
|
||||
unit.psi=-unit.heading
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
-- Element is dead. Remove from template.
|
||||
table.remove(units, i)
|
||||
|
||||
self.Ndestroyed=self.Ndestroyed+1
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6029,7 +6121,7 @@ function OPSGROUP:_Respawn(Delay, Template, Reset)
|
||||
else
|
||||
|
||||
---
|
||||
-- Group is DESPAWNED
|
||||
-- Group is NOT ALIVE
|
||||
---
|
||||
|
||||
-- Ensure elements in utero.
|
||||
@@ -6059,8 +6151,7 @@ function OPSGROUP:_Respawn(Delay, Template, Reset)
|
||||
self.isDestroyed=false
|
||||
|
||||
|
||||
self.groupinitialized=false
|
||||
self.Ndestroyed=0
|
||||
self.groupinitialized=false
|
||||
self.wpcounter=1
|
||||
self.currentwp=1
|
||||
|
||||
@@ -6069,7 +6160,7 @@ function OPSGROUP:_Respawn(Delay, Template, Reset)
|
||||
|
||||
-- Init Group.
|
||||
self:_InitGroup(Template)
|
||||
|
||||
|
||||
-- Reset events.
|
||||
--self:ResetEvents()
|
||||
|
||||
@@ -6213,11 +6304,24 @@ function OPSGROUP:onafterDead(From, Event, To)
|
||||
else
|
||||
-- Not all assets were destroyed (despawn) ==> Add asset back to legion?
|
||||
end
|
||||
|
||||
-- Stop in 5 sec to give possible respawn attempts a chance.
|
||||
|
||||
if self.legion then
|
||||
if not self:IsInUtero() then
|
||||
|
||||
-- Get asset.
|
||||
local asset=self.legion:GetAssetByName(self.groupname)
|
||||
|
||||
-- Get request.
|
||||
local request=self.legion:GetRequestByID(asset.rid)
|
||||
|
||||
-- Trigger asset dead event.
|
||||
self.legion:AssetDead(asset, request)
|
||||
end
|
||||
|
||||
-- Stop in 5 sec to give possible respawn attempts a chance.
|
||||
self:__Stop(-5)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- On before "Stop" event.
|
||||
|
||||
Reference in New Issue
Block a user