This commit is contained in:
FlightControl_Master 2017-09-29 07:03:50 +02:00
parent 57eeefcf06
commit b84d08f052
4 changed files with 27068 additions and 101 deletions

View File

@ -2502,7 +2502,7 @@ do -- SET_STATIC
function SET_STATIC:AddInDatabase( Event )
self:F3( { Event } )
if Event.IniObjectCategory == 1 then
if Event.IniObjectCategory == Object.Category.STATIC then
if not self.Database[Event.IniDCSStaticName] then
self.Database[Event.IniDCSStaticName] = STATIC:Register( Event.IniDCSStaticName )
self:T3( self.Database[Event.IniDCSStaticName] )

View File

@ -562,6 +562,118 @@ function ZONE_RADIUS:GetVec3( Height )
end
--- Scan the zone
-- @param #ZONE_RADIUS self
-- @param Coalition
function ZONE_RADIUS:Scan()
self.Coalitions = {}
local ZoneCoord = self:GetCoordinate()
local ZoneRadius = self:GetRadius()
self:E({ZoneCoord = ZoneCoord, ZoneRadius = ZoneRadius, ZoneCoordLL = ZoneCoord:ToStringLLDMS()})
local SphereSearch = {
id = world.VolumeType.SPHERE,
params = {
point = ZoneCoord:GetVec3(),
radius = ZoneRadius,
}
}
local function EvaluateZone( ZoneDCSUnit )
if ZoneDCSUnit:isExist() then
local CategoryDCSUnit = ZoneDCSUnit:getCategory()
if ( CategoryDCSUnit == Object.Category.UNIT and ZoneDCSUnit:isActive() ) or
CategoryDCSUnit == Object.Category.STATIC then
local CoalitionDCSUnit = ZoneDCSUnit:getCoalition()
self.Coalitions[CoalitionDCSUnit] = true
self:E( { Name = ZoneDCSUnit:getName(), Coalition = CoalitionDCSUnit } )
end
end
return true
end
world.searchObjects( { Object.Category.UNIT, Object.Category.STATIC }, SphereSearch, EvaluateZone )
end
function ZONE_RADIUS:CountCoalitions()
local Count = 0
for CoalitionID, Coalition in pairs( self.Coalitions ) do
Count = Count + 1
end
return Count
end
--- Is All in Zone of Coalition?
-- @param #ZONE_RADIUS self
-- @param Coalition
-- @return #boolean
function ZONE_RADIUS:IsAllInZoneOfCoalition( Coalition )
return self:CountCoalitions() == 1 and self.Coalitions[Coalition] == true
end
--- Is All in Zone of Other Coalition?
-- @param #ZONE_RADIUS self
-- @param Coalition
-- @return #boolean
function ZONE_RADIUS:IsAllInZoneOfOtherCoalition( Coalition )
self:E( { Coalitions = self.Coalitions, Count = self:CountCoalitions() } )
return self:CountCoalitions() == 1 and self.Coalitions[Coalition] == nil
end
--- Is Some in Zone of Coalition?
-- @param #ZONE_RADIUS self
-- @param Coalition
-- @return #boolean
function ZONE_RADIUS:IsSomeInZoneOfCoalition( Coalition )
return self:CountCoalitions() > 1 and self.Coalitions[Coalition] == true
end
--- Is None in Zone of Coalition?
-- @param #ZONE_RADIUS self
-- @param Coalition
-- @return #boolean
function ZONE_RADIUS:IsNoneInZoneOfCoalition( Coalition )
return self.Coalitions[Coalition] == nil
end
--- Get the Zone Coalitions.
-- Returns nil if there are none ot two coalitions in the zone!
-- @param #ZONE_RADIUS self
-- @return Coalitions
function ZONE_RADIUS:GetCoalition()
local Count = 0
local ReturnCoalition = nil
for CoalitionID, Coalition in pairs( self.Coalitions ) do
Count = Count + 1
ReturnCoalition = CoalitionID
end
if Count ~= 1 then
ReturnCoalition = nil
end
return ReturnCoalition
end
--- Searches the zone
-- @param #ZONE_RADIUS self
-- @param EvaluateFunction
@ -582,11 +694,11 @@ function ZONE_RADIUS:SearchZone( EvaluateFunction )
}
}
local function EvaluateZone( DCSZoneUnit )
local function EvaluateZone( ZoneDCSUnit )
env.info( DCSZoneUnit:getName() )
env.info( ZoneDCSUnit:getName() )
local ZoneUnit = UNIT:Find( DCSZoneUnit )
local ZoneUnit = UNIT:Find( ZoneDCSUnit )
return EvaluateFunction( ZoneUnit )
end

View File

@ -25,12 +25,13 @@ PROTECT = {
--- PROTECT constructor.
-- @param #PROTECT self
-- @param Core.Zone#ZONE ProtectZone A @{Zone} object to protect.
-- @param DCSCoalition.DCSCoalition#coalition Coalition The initial coalition owning the zone.
-- @return #PROTECT
-- @usage
-- -- Protect the zone
-- ProtectZone = PROTECT:New( ZONE:New( "Zone" ) )
--
function PROTECT:New( ProtectZone )
function PROTECT:New( ProtectZone, Coalition )
local self = BASE:Inherit( self, FSM:New() ) -- #PROTECT
@ -39,22 +40,41 @@ function PROTECT:New( ProtectZone )
self.ProtectStaticSet = SET_STATIC:New()
self.CaptureUnitSet = SET_UNIT:New()
self:SetStartState( "Idle" )
self:SetStartState( "-" )
self:AddTransition( { "Idle", "Captured" }, "Protect", "Protecting" )
self:AddTransition( { "-", "Protected", "Captured" }, "Protected", "Protected" )
self:AddTransition( "Protecting", "Check", "Protecting" )
self:AddTransition( { "Protected", "Attacked" }, "Destroyed", "Destroyed" )
self:AddTransition( "Protecting", "Capture", "Captured" )
self:AddTransition( { "Protected", "Destroyed" }, "Attacked", "Attacked" )
self:AddTransition( { "Protected", "Attacked", "Destroyed" }, "Captured", "Captured" )
self:AddTransition( { "Protecting", "Captured" }, "Leave", "Idle" )
self:ScheduleRepeat( 60, 60, 0, nil, self.Status, self )
--self:ScheduleRepeat( 1, 5, 0, nil, self.CheckScheduler, self )
self:SetCoalition( Coalition )
self:__Protected( 5 )
return self
end
--- Set the owning coalition of the zone.
-- @param #PROTECT self
-- @param DCSCoalition.DCSCoalition#coalition Coalition
function PROTECT:SetCoalition( Coalition )
self.Coalition = Coalition
end
--- Get the owning coalition of the zone.
-- @param #PROTECT self
-- @return DCSCoalition.DCSCoalition#coalition Coalition
function PROTECT:GetCoalition()
return self.Coalition
end
--- Add a unit to the protection.
-- @param #PROTECT self
@ -99,6 +119,30 @@ function PROTECT:GetCaptureUnitSet()
end
function PROTECT:IsProtected()
local IsAllCoalition = self.ProtectZone:IsAllInZoneOfCoalition( self.Coalition )
self:E( { IsAllCoalition = IsAllCoalition } )
return IsAllCoalition
end
function PROTECT:IsCaptured()
local IsCaptured = self.ProtectZone:IsAllInZoneOfOtherCoalition( self.Coalition )
self:E( { IsCaptured = IsCaptured } )
return IsCaptured
end
function PROTECT:IsAttacked()
local IsSomeCoalition = self.ProtectZone:IsSomeInZoneOfCoalition( self.Coalition )
self:E( { IsSomeCoalition = IsSomeCoalition } )
return IsSomeCoalition
end
--- Check if the units are still alive.
-- @param #PROTECT self
function PROTECT:AreProtectUnitsAlive()
@ -164,21 +208,30 @@ function PROTECT:Smoke( SmokeColor )
end
function PROTECT:onafterProtect()
function PROTECT:onenterCaptured()
self:Check()
local NewCoalition = self.ProtectZone:GetCoalition()
self:E( { NewCoalition = NewCoalition } )
self:SetCoalition( NewCoalition )
end
function PROTECT:onafterCheck()
--- Check status ProtectZone.
-- @param #PROTECT self
function PROTECT:Status()
if ( self.ProtectUnitSet and self:AreProtectUnitsAlive() ) or
( self.ProtectStaticSet and self:AreProtectStaticsAlive() ) or
self:IsCaptureUnitInZone() == false then
self:__Check( -1 )
self.ProtectZone:Scan()
if self:IsProtected() then
self:Protected()
else
self:Capture()
if self:IsAttacked() then
self:Attacked()
else
if self:IsCaptured() then
self:Captured()
end
end
end
end

File diff suppressed because it is too large Load Diff