mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-17 03:11:28 +00:00
RH, GROUP
This commit is contained in:
@@ -907,7 +907,7 @@ function RESCUEHELO:onafterStart(From, Event, To)
|
|||||||
-- Use an uncontrolled aircraft group.
|
-- Use an uncontrolled aircraft group.
|
||||||
self.helo=GROUP:FindByName(self.helogroupname)
|
self.helo=GROUP:FindByName(self.helogroupname)
|
||||||
|
|
||||||
if self.helo:IsAlive() then
|
if self.helo and self.helo:IsAlive() then
|
||||||
|
|
||||||
-- Start uncontrolled group.
|
-- Start uncontrolled group.
|
||||||
self.helo:StartUncontrolled()
|
self.helo:StartUncontrolled()
|
||||||
@@ -1020,7 +1020,7 @@ function RESCUEHELO:onafterStatus(From, Event, To)
|
|||||||
else
|
else
|
||||||
|
|
||||||
-- Send helo back to base.
|
-- Send helo back to base.
|
||||||
self:RTB()
|
self:RTB(self.airbase)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1211,7 +1211,9 @@ function RESCUEHELO:onafterReturned(From, Event, To, airbase)
|
|||||||
self.helo:InitModex(self.modex)
|
self.helo:InitModex(self.modex)
|
||||||
|
|
||||||
-- Respawn helo at current airbase.
|
-- Respawn helo at current airbase.
|
||||||
self.helo:RespawnAtCurrentAirbase()
|
if self.helo and self.helo:IsAlive() then
|
||||||
|
self:ScheduleOnce(5, self.helo.RespawnAtCurrentAirbase, self.helo)
|
||||||
|
end
|
||||||
|
|
||||||
-- Restart the formation.
|
-- Restart the formation.
|
||||||
self:__Run(10)
|
self:__Run(10)
|
||||||
|
|||||||
@@ -1773,110 +1773,115 @@ end
|
|||||||
function GROUP:RespawnAtCurrentAirbase(SpawnTemplate, Takeoff, Uncontrolled) -- R2.4
|
function GROUP:RespawnAtCurrentAirbase(SpawnTemplate, Takeoff, Uncontrolled) -- R2.4
|
||||||
self:F2( { SpawnTemplate, Takeoff, Uncontrolled} )
|
self:F2( { SpawnTemplate, Takeoff, Uncontrolled} )
|
||||||
|
|
||||||
-- Get closest airbase. Should be the one we are currently on.
|
if self and self:IsAlive() then
|
||||||
local airbase=self:GetCoordinate():GetClosestAirbase()
|
|
||||||
|
|
||||||
if airbase then
|
|
||||||
self:F2("Closest airbase = "..airbase:GetName())
|
|
||||||
else
|
|
||||||
self:E("ERROR: could not find closest airbase!")
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
-- Takeoff type. Default hot.
|
|
||||||
Takeoff = Takeoff or SPAWN.Takeoff.Hot
|
|
||||||
|
|
||||||
-- Coordinate of the airbase.
|
|
||||||
local AirbaseCoord=airbase:GetCoordinate()
|
|
||||||
|
|
||||||
-- Spawn template.
|
|
||||||
SpawnTemplate = SpawnTemplate or self:GetTemplate()
|
|
||||||
|
|
||||||
if SpawnTemplate then
|
-- Get closest airbase. Should be the one we are currently on.
|
||||||
|
local airbase=self:GetCoordinate():GetClosestAirbase()
|
||||||
local SpawnPoint = SpawnTemplate.route.points[1]
|
|
||||||
|
|
||||||
-- These are only for ships.
|
|
||||||
SpawnPoint.linkUnit = nil
|
|
||||||
SpawnPoint.helipadId = nil
|
|
||||||
SpawnPoint.airdromeId = nil
|
|
||||||
|
|
||||||
-- Aibase id and category.
|
|
||||||
local AirbaseID = airbase:GetID()
|
|
||||||
local AirbaseCategory = airbase:GetDesc().category
|
|
||||||
|
|
||||||
if AirbaseCategory == Airbase.Category.SHIP or AirbaseCategory == Airbase.Category.HELIPAD then
|
if airbase then
|
||||||
SpawnPoint.linkUnit = AirbaseID
|
self:F2("Closest airbase = "..airbase:GetName())
|
||||||
SpawnPoint.helipadId = AirbaseID
|
else
|
||||||
elseif AirbaseCategory == Airbase.Category.AIRDROME then
|
self:E("ERROR: could not find closest airbase!")
|
||||||
SpawnPoint.airdromeId = AirbaseID
|
return nil
|
||||||
end
|
end
|
||||||
|
-- Takeoff type. Default hot.
|
||||||
|
Takeoff = Takeoff or SPAWN.Takeoff.Hot
|
||||||
|
|
||||||
SpawnPoint.type = GROUPTEMPLATE.Takeoff[Takeoff][1] -- type
|
-- Coordinate of the airbase.
|
||||||
SpawnPoint.action = GROUPTEMPLATE.Takeoff[Takeoff][2] -- action
|
local AirbaseCoord=airbase:GetCoordinate()
|
||||||
|
|
||||||
-- Get the units of the group.
|
-- Spawn template.
|
||||||
local units=self:GetUnits()
|
SpawnTemplate = SpawnTemplate or self:GetTemplate()
|
||||||
|
|
||||||
local x
|
if SpawnTemplate then
|
||||||
local y
|
|
||||||
for UnitID=1,#units do
|
local SpawnPoint = SpawnTemplate.route.points[1]
|
||||||
|
|
||||||
|
-- These are only for ships.
|
||||||
|
SpawnPoint.linkUnit = nil
|
||||||
|
SpawnPoint.helipadId = nil
|
||||||
|
SpawnPoint.airdromeId = nil
|
||||||
|
|
||||||
|
-- Aibase id and category.
|
||||||
|
local AirbaseID = airbase:GetID()
|
||||||
|
local AirbaseCategory = airbase:GetDesc().category
|
||||||
|
|
||||||
|
if AirbaseCategory == Airbase.Category.SHIP or AirbaseCategory == Airbase.Category.HELIPAD then
|
||||||
|
SpawnPoint.linkUnit = AirbaseID
|
||||||
|
SpawnPoint.helipadId = AirbaseID
|
||||||
|
elseif AirbaseCategory == Airbase.Category.AIRDROME then
|
||||||
|
SpawnPoint.airdromeId = AirbaseID
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
SpawnPoint.type = GROUPTEMPLATE.Takeoff[Takeoff][1] -- type
|
||||||
|
SpawnPoint.action = GROUPTEMPLATE.Takeoff[Takeoff][2] -- action
|
||||||
|
|
||||||
|
-- Get the units of the group.
|
||||||
|
local units=self:GetUnits()
|
||||||
|
|
||||||
|
local x
|
||||||
|
local y
|
||||||
|
for UnitID=1,#units do
|
||||||
|
|
||||||
|
local unit=units[UnitID] --Wrapper.Unit#UNIT
|
||||||
|
|
||||||
|
-- Get closest parking spot of current unit. Note that we look for occupied spots since the unit is currently sitting on it!
|
||||||
|
local Parkingspot, TermialID, Distance=unit:GetCoordinate():GetClosestParkingSpot(airbase)
|
||||||
|
|
||||||
local unit=units[UnitID] --Wrapper.Unit#UNIT
|
--Parkingspot:MarkToAll("parking spot")
|
||||||
|
self:T2(string.format("Closest parking spot distance = %s, terminal ID=%s", tostring(Distance), tostring(TermialID)))
|
||||||
-- Get closest parking spot of current unit. Note that we look for occupied spots since the unit is currently sitting on it!
|
|
||||||
local Parkingspot, TermialID, Distance=unit:GetCoordinate():GetClosestParkingSpot(airbase)
|
|
||||||
|
|
||||||
--Parkingspot:MarkToAll("parking spot")
|
|
||||||
self:T2(string.format("Closest parking spot distance = %s, terminal ID=%s", tostring(Distance), tostring(TermialID)))
|
|
||||||
|
|
||||||
-- Get unit coordinates for respawning position.
|
|
||||||
local uc=unit:GetCoordinate()
|
|
||||||
--uc:MarkToAll(string.format("re-spawnplace %s terminal %d", unit:GetName(), TermialID))
|
|
||||||
|
|
||||||
SpawnTemplate.units[UnitID].x = uc.x --Parkingspot.x
|
|
||||||
SpawnTemplate.units[UnitID].y = uc.z --Parkingspot.z
|
|
||||||
SpawnTemplate.units[UnitID].alt = uc.y --Parkingspot.y
|
|
||||||
|
|
||||||
SpawnTemplate.units[UnitID].parking = TermialID
|
|
||||||
SpawnTemplate.units[UnitID].parking_id = nil
|
|
||||||
|
|
||||||
--SpawnTemplate.units[UnitID].unitId=nil
|
|
||||||
end
|
|
||||||
|
|
||||||
--SpawnTemplate.groupId=nil
|
|
||||||
|
|
||||||
SpawnPoint.x = SpawnTemplate.units[1].x --x --AirbaseCoord.x
|
|
||||||
SpawnPoint.y = SpawnTemplate.units[1].y --y --AirbaseCoord.z
|
|
||||||
SpawnPoint.alt = SpawnTemplate.units[1].alt --AirbaseCoord:GetLandHeight()
|
|
||||||
|
|
||||||
SpawnTemplate.x = SpawnTemplate.units[1].x --x --AirbaseCoord.x
|
|
||||||
SpawnTemplate.y = SpawnTemplate.units[1].y --y --AirbaseCoord.z
|
|
||||||
|
|
||||||
-- Set uncontrolled state.
|
|
||||||
SpawnTemplate.uncontrolled=Uncontrolled
|
|
||||||
|
|
||||||
-- Set radio frequency and modulation.
|
|
||||||
if self.InitRespawnRadio then
|
|
||||||
SpawnTemplate.communication=self.InitRespawnRadio
|
|
||||||
end
|
|
||||||
if self.InitRespawnFreq then
|
|
||||||
SpawnTemplate.frequency=self.InitRespawnFreq
|
|
||||||
end
|
|
||||||
if self.InitRespawnModu then
|
|
||||||
SpawnTemplate.modulation=self.InitRespawnModu
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Destroy old group.
|
|
||||||
self:Destroy(false)
|
|
||||||
|
|
||||||
-- Spawn new group.
|
|
||||||
_DATABASE:Spawn(SpawnTemplate)
|
|
||||||
|
|
||||||
-- Reset events.
|
-- Get unit coordinates for respawning position.
|
||||||
self:ResetEvents()
|
local uc=unit:GetCoordinate()
|
||||||
|
--uc:MarkToAll(string.format("re-spawnplace %s terminal %d", unit:GetName(), TermialID))
|
||||||
return self
|
|
||||||
|
SpawnTemplate.units[UnitID].x = uc.x --Parkingspot.x
|
||||||
|
SpawnTemplate.units[UnitID].y = uc.z --Parkingspot.z
|
||||||
|
SpawnTemplate.units[UnitID].alt = uc.y --Parkingspot.y
|
||||||
|
|
||||||
|
SpawnTemplate.units[UnitID].parking = TermialID
|
||||||
|
SpawnTemplate.units[UnitID].parking_id = nil
|
||||||
|
|
||||||
|
--SpawnTemplate.units[UnitID].unitId=nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--SpawnTemplate.groupId=nil
|
||||||
|
|
||||||
|
SpawnPoint.x = SpawnTemplate.units[1].x --x --AirbaseCoord.x
|
||||||
|
SpawnPoint.y = SpawnTemplate.units[1].y --y --AirbaseCoord.z
|
||||||
|
SpawnPoint.alt = SpawnTemplate.units[1].alt --AirbaseCoord:GetLandHeight()
|
||||||
|
|
||||||
|
SpawnTemplate.x = SpawnTemplate.units[1].x --x --AirbaseCoord.x
|
||||||
|
SpawnTemplate.y = SpawnTemplate.units[1].y --y --AirbaseCoord.z
|
||||||
|
|
||||||
|
-- Set uncontrolled state.
|
||||||
|
SpawnTemplate.uncontrolled=Uncontrolled
|
||||||
|
|
||||||
|
-- Set radio frequency and modulation.
|
||||||
|
if self.InitRespawnRadio then
|
||||||
|
SpawnTemplate.communication=self.InitRespawnRadio
|
||||||
|
end
|
||||||
|
if self.InitRespawnFreq then
|
||||||
|
SpawnTemplate.frequency=self.InitRespawnFreq
|
||||||
|
end
|
||||||
|
if self.InitRespawnModu then
|
||||||
|
SpawnTemplate.modulation=self.InitRespawnModu
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Destroy old group.
|
||||||
|
self:Destroy(false)
|
||||||
|
|
||||||
|
-- Spawn new group.
|
||||||
|
_DATABASE:Spawn(SpawnTemplate)
|
||||||
|
|
||||||
|
-- Reset events.
|
||||||
|
self:ResetEvents()
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
else
|
||||||
|
self:E("WARNING: GROUP is not alive!")
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user