From 85428236925131826cac71fcd7e753e7593901ab Mon Sep 17 00:00:00 2001 From: FlightControl_Master Date: Sun, 8 Oct 2017 14:10:38 +0200 Subject: [PATCH] Scenery Search methods --- Moose Development/Moose/Core/Zone.lua | 68 +++++++++++++------ .../Moose/Functional/ZoneGoalCoalition.lua | 2 +- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/Moose Development/Moose/Core/Zone.lua b/Moose Development/Moose/Core/Zone.lua index f4fc8e70a..029cc8cde 100644 --- a/Moose Development/Moose/Core/Zone.lua +++ b/Moose Development/Moose/Core/Zone.lua @@ -577,10 +577,13 @@ end --- Scan the zone -- @param #ZONE_RADIUS self +-- @param ObjectCategories -- @param Coalition -function ZONE_RADIUS:Scan() +function ZONE_RADIUS:Scan( ObjectCategories ) - self.Coalitions = {} + self.ScanData = {} + self.ScanData.Coalitions = {} + self.ScanData.Scenery = {} local ZoneCoord = self:GetCoordinate() local ZoneRadius = self:GetRadius() @@ -595,41 +598,64 @@ function ZONE_RADIUS:Scan() } } - 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 } ) + local function EvaluateZone( ZoneObject ) + if ZoneObject:isExist() then + local ObjectCategory = ZoneObject:getCategory() + if ( ObjectCategory == Object.Category.UNIT and ZoneObject:isActive() ) or + ObjectCategory == Object.Category.STATIC then + local CoalitionDCSUnit = ZoneObject:getCoalition() + self.ScanData.Coalitions[CoalitionDCSUnit] = true + self:E( { Name = ZoneObject:getName(), Coalition = CoalitionDCSUnit } ) + end + if ObjectCategory == Object.Category.SCENERY then + local SceneryType = ZoneObject:getTypeName() + local SceneryName = ZoneObject:getName() + self.ScanData.Scenery[SceneryType] = self.ScanData.Scenery[SceneryType] or {} + self.ScanData.Scenery[SceneryType][SceneryName] = SCENERY:Register( SceneryName, ZoneObject ) + self:E( { SCENERY = self.ScanData.Scenery[SceneryType][SceneryName] } ) end end return true end - world.searchObjects( { Object.Category.UNIT, Object.Category.STATIC }, SphereSearch, EvaluateZone ) + world.searchObjects( ObjectCategories, SphereSearch, EvaluateZone ) end -function ZONE_RADIUS:CountCoalitions() +function ZONE_RADIUS:CountScannedCoalitions() local Count = 0 - for CoalitionID, Coalition in pairs( self.Coalitions ) do + for CoalitionID, Coalition in pairs( self.ScanData.Coalitions ) do Count = Count + 1 end return Count end + +function ZONE_RADIUS:GetScannedCoalition( Coalition ) + return self.ScanData.Coalitions[Coalition] +end + + +function ZONE_RADIUS:GetScannedSceneryType( SceneryType ) + return self.ScanData.Scenery[SceneryType] +end + + +function ZONE_RADIUS:GetScannedScenery() + return self.ScanData.Scenery +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 + return self:CountScannedCoalitions() == 1 and self:GetScannedCoalition( Coalition ) == true end @@ -639,8 +665,8 @@ end -- @return #boolean function ZONE_RADIUS:IsAllInZoneOfOtherCoalition( Coalition ) - self:E( { Coalitions = self.Coalitions, Count = self:CountCoalitions() } ) - return self:CountCoalitions() == 1 and self.Coalitions[Coalition] == nil + self:E( { Coalitions = self.Coalitions, Count = self:CountScannedCoalitions() } ) + return self:CountScannedCoalitions() == 1 and self:GetScannedCoalition( Coalition ) == nil end @@ -650,7 +676,7 @@ end -- @return #boolean function ZONE_RADIUS:IsSomeInZoneOfCoalition( Coalition ) - return self:CountCoalitions() > 1 and self.Coalitions[Coalition] == true + return self:CountScannedCoalitions() > 1 and self:GetScannedCoalition( Coalition ) == true end @@ -660,7 +686,7 @@ end -- @return #boolean function ZONE_RADIUS:IsNoneInZoneOfCoalition( Coalition ) - return self.Coalitions[Coalition] == nil + return self:GetScannedCoalition( Coalition ) == nil end @@ -669,7 +695,7 @@ end -- @return #boolean function ZONE_RADIUS:IsNoneInZone() - return self:CountCoalitions() == 0 + return self:CountScannedCoalitions() == 0 end @@ -695,11 +721,11 @@ function ZONE_RADIUS:GetCoalition() end - --- Searches the zone -- @param #ZONE_RADIUS self +-- @param ObjectCategories A list of categories, which are members of Object.Category -- @param EvaluateFunction -function ZONE_RADIUS:SearchZone( EvaluateFunction ) +function ZONE_RADIUS:SearchZone( EvaluateFunction, ObjectCategories ) local SearchZoneResult = true diff --git a/Moose Development/Moose/Functional/ZoneGoalCoalition.lua b/Moose Development/Moose/Functional/ZoneGoalCoalition.lua index 8a1eef660..83415f3fb 100644 --- a/Moose Development/Moose/Functional/ZoneGoalCoalition.lua +++ b/Moose Development/Moose/Functional/ZoneGoalCoalition.lua @@ -105,7 +105,7 @@ do -- ZoneGoal local State = self:GetState() self:E( { State = self:GetState() } ) - self.Zone:Scan() + self.Zone:Scan( { Object.Category.UNIT, Object.Category.STATIC } ) end