mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +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:
parent
5f57d4ddcd
commit
0411120551
@ -5452,9 +5452,10 @@ end
|
||||
-- @param #WAREHOUSE.Assetitem asset The asset that is dead.
|
||||
-- @param #WAREHOUSE.Pendingitem request The request of the dead asset.
|
||||
function WAREHOUSE:onafterAssetDead(From, Event, To, asset, request)
|
||||
|
||||
-- Debug message.
|
||||
local text=string.format("Asset %s from request id=%d is dead!", asset.templatename, request.uid)
|
||||
self:T(self.lid..text)
|
||||
self:_DebugMessage(text)
|
||||
|
||||
-- Here I need to get rid of the #CARGO at the end to obtain the original name again!
|
||||
local groupname=asset.spawngroupname --self:_GetNameWithOut(group)
|
||||
@ -6650,35 +6651,30 @@ end
|
||||
-- @param Wrapper.Group#GROUP deadgroup Group of unit that died.
|
||||
-- @param #WAREHOUSE.Pendingitem request Request that needs to be updated.
|
||||
function WAREHOUSE:_UnitDead(deadunit, deadgroup, request)
|
||||
--env.info("FF unit dead "..deadunit:GetName())
|
||||
self:F(self.lid.."FF unit dead "..deadunit:GetName())
|
||||
|
||||
-- Find asset.
|
||||
local asset=self:FindAssetInDB(deadgroup)
|
||||
|
||||
-- Find opsgroup.
|
||||
local opsgroup=_DATABASE:FindOpsGroup(deadgroup)
|
||||
|
||||
local groupdead=false
|
||||
if opsgroup then
|
||||
|
||||
if opsgroup:IsDead() then
|
||||
groupdead=true
|
||||
end
|
||||
|
||||
else
|
||||
-- Check if we have an opsgroup.
|
||||
if opsgroup then
|
||||
-- Handled in OPSGROUP:onafterDead() now.
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Number of alive units in group.
|
||||
local nalive=deadgroup:CountAliveUnits()
|
||||
|
||||
-- Whole group is dead?
|
||||
if nalive>0 then
|
||||
groupdead=false
|
||||
else
|
||||
groupdead=true
|
||||
end
|
||||
|
||||
-- Number of alive units in group.
|
||||
local nalive=deadgroup:CountAliveUnits()
|
||||
|
||||
-- Whole group is dead?
|
||||
local groupdead=false
|
||||
if nalive>0 then
|
||||
groupdead=false
|
||||
else
|
||||
groupdead=true
|
||||
end
|
||||
|
||||
-- Find asset.
|
||||
local asset=self:FindAssetInDB(deadgroup)
|
||||
|
||||
-- Here I need to get rid of the #CARGO at the end to obtain the original name again!
|
||||
local unitname=self:_GetNameWithOut(deadunit)
|
||||
|
||||
@ -653,7 +653,10 @@ function ARMYGROUP:Status()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
else
|
||||
-- Check damage of elements and group.
|
||||
self:_CheckDamage()
|
||||
end
|
||||
|
||||
-- Check that group EXISTS.
|
||||
@ -692,7 +695,7 @@ function ARMYGROUP:Status()
|
||||
local text=string.format("State %s: Alive=%s", fsmstate, tostring(self:IsAlive()))
|
||||
self:I(self.lid..text)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
---
|
||||
@ -707,7 +710,6 @@ function ARMYGROUP:Status()
|
||||
local name=element.name
|
||||
local status=element.status
|
||||
local unit=element.unit
|
||||
--local life=unit:GetLifeRelative() or 0
|
||||
local life,life0=self:GetLifePoints(element)
|
||||
|
||||
local life0=element.life0
|
||||
@ -927,7 +929,7 @@ function ARMYGROUP:onafterUpdateRoute(From, Event, To, n, N, Speed, Formation)
|
||||
|
||||
-- Next waypoint.
|
||||
local wp=UTILS.DeepCopy(self.waypoints[i]) --Ops.OpsGroup#OPSGROUP.Waypoint
|
||||
self:T({wp})
|
||||
|
||||
-- Speed.
|
||||
if Speed then
|
||||
wp.speed=UTILS.KnotsToMps(tonumber(Speed))
|
||||
@ -1429,6 +1431,7 @@ end
|
||||
function ARMYGROUP:onafterEngageTarget(From, Event, To, Target)
|
||||
self:T(self.lid.."Engaging Target")
|
||||
|
||||
-- Make sure this is a target.
|
||||
if Target:IsInstanceOf("TARGET") then
|
||||
self.engage.Target=Target
|
||||
else
|
||||
@ -1438,11 +1441,9 @@ function ARMYGROUP:onafterEngageTarget(From, Event, To, Target)
|
||||
-- Target coordinate.
|
||||
self.engage.Coordinate=UTILS.DeepCopy(self.engage.Target:GetCoordinate())
|
||||
|
||||
|
||||
-- Get a coordinate close to the target.
|
||||
local intercoord=self:GetCoordinate():GetIntermediateCoordinate(self.engage.Coordinate, 0.9)
|
||||
|
||||
|
||||
|
||||
-- Backup ROE and alarm state.
|
||||
self.engage.roe=self:GetROE()
|
||||
self.engage.alarmstate=self:GetAlarmstate()
|
||||
@ -1454,6 +1455,10 @@ function ARMYGROUP:onafterEngageTarget(From, Event, To, Target)
|
||||
-- ID of current waypoint.
|
||||
local uid=self:GetWaypointCurrent().uid
|
||||
|
||||
-- Set formation.
|
||||
--TODO: make this input.
|
||||
local Formation=ENUMS.Formation.Vehicle.Vee
|
||||
|
||||
-- Add waypoint after current.
|
||||
self.engage.Waypoint=self:AddWaypoint(intercoord, nil, uid, Formation, true)
|
||||
|
||||
@ -1599,8 +1604,7 @@ function ARMYGROUP:AddWaypoint(Coordinate, Speed, AfterWaypointWithID, Formation
|
||||
-- Speed in knots.
|
||||
Speed=Speed or self:GetSpeedCruise()
|
||||
|
||||
-- Formation
|
||||
|
||||
-- Formation.
|
||||
if not Formation then
|
||||
if self.formationPerma then
|
||||
Formation = self.formationPerma
|
||||
|
||||
@ -560,7 +560,7 @@ AUFTRAG.Category={
|
||||
|
||||
--- AUFTRAG class version.
|
||||
-- @field #string version
|
||||
AUFTRAG.version="0.8.3"
|
||||
AUFTRAG.version="0.8.4"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO list
|
||||
@ -1690,8 +1690,9 @@ end
|
||||
-- @param Core.Zone#ZONE Zone The patrol zone.
|
||||
-- @param #number Speed Speed in knots.
|
||||
-- @param #number Altitude Altitude in feet. Only for airborne units. Default 2000 feet ASL.
|
||||
-- @param #string Formation Formation used during patrol.
|
||||
-- @return #AUFTRAG self
|
||||
function AUFTRAG:NewPATROLZONE(Zone, Speed, Altitude)
|
||||
function AUFTRAG:NewPATROLZONE(Zone, Speed, Altitude, Formation)
|
||||
|
||||
local mission=AUFTRAG:New(AUFTRAG.Type.PATROLZONE)
|
||||
|
||||
@ -1715,6 +1716,8 @@ function AUFTRAG:NewPATROLZONE(Zone, Speed, Altitude)
|
||||
mission.categories={AUFTRAG.Category.ALL}
|
||||
|
||||
mission.DCStask=mission:GetDCSMissionTask()
|
||||
|
||||
mission.DCStask.params.formation=Formation
|
||||
|
||||
return mission
|
||||
end
|
||||
@ -3504,7 +3507,7 @@ function AUFTRAG:SetGroupStatus(opsgroup, status)
|
||||
local groupsDone=self:CheckGroupsDone()
|
||||
|
||||
-- Debug info.
|
||||
self:T2(self.lid..string.format("Setting OPSGROUP %s status to %s. IsNotOver=%s CheckGroupsDone=%s", opsgroup.groupname, self:GetGroupStatus(opsgroup), tostring(self:IsNotOver()), tostring(self:CheckGroupsDone())))
|
||||
self:T2(self.lid..string.format("Setting OPSGROUP %s status to %s. IsNotOver=%s CheckGroupsDone=%s", opsgroup.groupname, self:GetGroupStatus(opsgroup), tostring(self:IsNotOver()), tostring(groupsDone)))
|
||||
|
||||
-- Check if ALL flights are done with their mission.
|
||||
if isNotOver and groupsDone then
|
||||
|
||||
@ -31,7 +31,8 @@
|
||||
-- @field #string livery Livery of the cohort.
|
||||
-- @field #number skill Skill of cohort members.
|
||||
-- @field Ops.Legion#LEGION legion The LEGION object the cohort belongs to.
|
||||
-- @field #number Ngroups Number of asset OPS groups this cohort has.
|
||||
-- @field #number Ngroups Number of asset OPS groups this cohort has.
|
||||
-- @field #number Nkilled Number of destroyed asset groups.
|
||||
-- @field #number engageRange Mission range in meters.
|
||||
-- @field #string attribute Generalized attribute of the cohort template group.
|
||||
-- @field #table tacanChannel List of TACAN channels available to the cohort.
|
||||
@ -67,6 +68,7 @@ COHORT = {
|
||||
skill = nil,
|
||||
legion = nil,
|
||||
Ngroups = nil,
|
||||
Ngroups = 0,
|
||||
engageRange = nil,
|
||||
tacanChannel = {},
|
||||
weightAsset = 99999,
|
||||
@ -275,12 +277,10 @@ end
|
||||
|
||||
--- Set number of units in groups.
|
||||
-- @param #COHORT self
|
||||
-- @param #number nunits Number of units. Must be >=1 and <=4. Default 2.
|
||||
-- @param #number nunits Number of units. Default 2.
|
||||
-- @return #COHORT self
|
||||
function COHORT:SetGrouping(nunits)
|
||||
self.ngrouping=nunits or 2
|
||||
if self.ngrouping<1 then self.ngrouping=1 end
|
||||
if self.ngrouping>4 then self.ngrouping=4 end
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
@ -168,7 +168,7 @@ FLIGHTGROUP.Attribute = {
|
||||
|
||||
--- FLIGHTGROUP class version.
|
||||
-- @field #string version
|
||||
FLIGHTGROUP.version="0.7.0"
|
||||
FLIGHTGROUP.version="0.7.1"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO list
|
||||
@ -730,60 +730,6 @@ end
|
||||
-- Status
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
---- Update status.
|
||||
-- @param #FLIGHTGROUP self
|
||||
function FLIGHTGROUP:onbeforeStatus(From, Event, To)
|
||||
|
||||
-- First we check if elements are still alive. Could be that they were despawned without notice, e.g. when landing on a too small airbase.
|
||||
for i,_element in pairs(self.elements) do
|
||||
local element=_element --Ops.OpsGroup#OPSGROUP.Element
|
||||
|
||||
-- Check that element is not already dead or not yet alive.
|
||||
if element.status~=OPSGROUP.ElementStatus.DEAD and element.status~=OPSGROUP.ElementStatus.INUTERO then
|
||||
|
||||
-- Unit shortcut.
|
||||
local unit=element.unit
|
||||
|
||||
local isdead=false
|
||||
if unit and unit:IsAlive() then
|
||||
|
||||
-- Get life points.
|
||||
local life=unit:GetLife() or 0
|
||||
|
||||
-- Units with life <=1 are dead.
|
||||
if life<=1 then
|
||||
--env.info(string.format("FF unit %s: live<=1 in status at T=%.3f", unit:GetName(), timer.getTime()))
|
||||
isdead=true
|
||||
end
|
||||
|
||||
else
|
||||
-- Not alive any more.
|
||||
--env.info(string.format("FF unit %s: NOT alive in status at T=%.3f", unit:GetName(), timer.getTime()))
|
||||
isdead=true
|
||||
end
|
||||
|
||||
-- This one is dead.
|
||||
if isdead then
|
||||
local text=string.format("Element %s is dead at t=%.3f but has status %s! Maybe despawned without notice or landed at a too small airbase. Calling ElementDead in 60 sec to give other events a chance",
|
||||
tostring(element.name), timer.getTime(), tostring(element.status))
|
||||
self:T(self.lid..text)
|
||||
self:__ElementDead(60, element)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
if self:IsDead() then
|
||||
self:T(self.lid..string.format("Onbefore Status DEAD ==> false"))
|
||||
return false
|
||||
elseif self:IsStopped() then
|
||||
self:T(self.lid..string.format("Onbefore Status STOPPED ==> false"))
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--- Status update.
|
||||
-- @param #FLIGHTGROUP self
|
||||
function FLIGHTGROUP:Status()
|
||||
@ -845,7 +791,10 @@ function FLIGHTGROUP:Status()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
else
|
||||
-- Check damage.
|
||||
self:_CheckDamage()
|
||||
end
|
||||
|
||||
---
|
||||
|
||||
@ -45,13 +45,14 @@ LEGION = {
|
||||
|
||||
--- LEGION class version.
|
||||
-- @field #string version
|
||||
LEGION.version="0.2.0"
|
||||
LEGION.version="0.2.1"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- ToDo list
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO: Create FLEED class.
|
||||
-- DONE: Aircraft will not start hot on Alert5.
|
||||
-- DONE: OPS transport.
|
||||
-- DONE: Make general so it can be inherited by AIRWING and BRIGADE classes.
|
||||
|
||||
@ -748,6 +749,10 @@ function LEGION:onafterMissionRequest(From, Event, To, Mission)
|
||||
if Mission.missionTask then
|
||||
asset.missionTask=Mission.missionTask
|
||||
end
|
||||
|
||||
if Mission.type==AUFTRAG.Type.ALERT5 then
|
||||
asset.takeoffType=COORDINATE.WaypointType.TakeOffParking
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -1096,6 +1101,9 @@ function LEGION:onafterNewAsset(From, Event, To, asset, assignment)
|
||||
|
||||
self:T(self.lid..string.format("Asset returned to legion ==> calling LegionAssetReturned event"))
|
||||
|
||||
-- Set takeoff type in case it was overwritten for an ALERT5 mission.
|
||||
asset.takeoffType=cohort.takeoffType
|
||||
|
||||
-- Trigger event.
|
||||
self:LegionAssetReturned(cohort, asset)
|
||||
|
||||
|
||||
@ -90,7 +90,7 @@ NAVYGROUP = {
|
||||
|
||||
--- NavyGroup version.
|
||||
-- @field #string version
|
||||
NAVYGROUP.version="0.7.0"
|
||||
NAVYGROUP.version="0.7.1"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO list
|
||||
@ -760,6 +760,12 @@ function NAVYGROUP:Status(From, Event, To)
|
||||
|
||||
-- Check into wind queue.
|
||||
self:_CheckTurnsIntoWind()
|
||||
|
||||
-- Check ammo status.
|
||||
self:_CheckAmmoStatus()
|
||||
|
||||
-- Check damage of elements and group.
|
||||
self:_CheckDamage()
|
||||
|
||||
-- Check if group got stuck.
|
||||
self:_CheckStuck()
|
||||
@ -775,6 +781,9 @@ function NAVYGROUP:Status(From, Event, To)
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
-- Check damage of elements and group.
|
||||
self:_CheckDamage()
|
||||
end
|
||||
|
||||
-- Group exists but can also be inactive.
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -1097,6 +1097,14 @@ function UTILS.VecSubstract(a, b)
|
||||
return {x=a.x-b.x, y=a.y-b.y, z=a.z-b.z}
|
||||
end
|
||||
|
||||
--- Calculate the difference between two 2D vectors by substracting the x,y components from each other.
|
||||
-- @param DCS#Vec2 a Vector in 2D with x, y components.
|
||||
-- @param DCS#Vec2 b Vector in 2D with x, y components.
|
||||
-- @return DCS#Vec2 Vector c=a-b with c(i)=a(i)-b(i), i=x,y.
|
||||
function UTILS.Vec2Substract(a, b)
|
||||
return {x=a.x-b.x, y=a.y-b.y}
|
||||
end
|
||||
|
||||
--- Calculate the total vector of two 3D vectors by adding the x,y,z components of each other.
|
||||
-- @param DCS#Vec3 a Vector in 3D with x, y, z components.
|
||||
-- @param DCS#Vec3 b Vector in 3D with x, y, z components.
|
||||
@ -1105,6 +1113,14 @@ function UTILS.VecAdd(a, b)
|
||||
return {x=a.x+b.x, y=a.y+b.y, z=a.z+b.z}
|
||||
end
|
||||
|
||||
--- Calculate the total vector of two 2D vectors by adding the x,y components of each other.
|
||||
-- @param DCS#Vec2 a Vector in 2D with x, y components.
|
||||
-- @param DCS#Vec2 b Vector in 2D with x, y components.
|
||||
-- @return DCS#Vec2 Vector c=a+b with c(i)=a(i)+b(i), i=x,y.
|
||||
function UTILS.Vec2Add(a, b)
|
||||
return {x=a.x+b.x, y=a.y+b.y}
|
||||
end
|
||||
|
||||
--- Calculate the angle between two 3D vectors.
|
||||
-- @param DCS#Vec3 a Vector in 3D with x, y, z components.
|
||||
-- @param DCS#Vec3 b Vector in 3D with x, y, z components.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user