-- ***************************************************************************** -- ** CAPZone Training ** -- ********************************************************* function wipeCapZone(objCAPZone) while (#(objCAPZone.objFlightGroups) > 0) do Jtff_log.debug(string.format("Wipe CAP Zone : %s, before wipe remaining flight groups: %d", objCAPZone.customconfig.name, #(objCAPZone.objFlightGroups)),"CAP_ZONE_TRAINING") if objCAPZone.objFlightGroups[1].MissionPatrol then objCAPZone.objFlightGroups[1].MissionPatrol.markerOn = false if objCAPZone.objFlightGroups[1].MissionPatrol.marker then objCAPZone.objFlightGroups[1].MissionPatrol.marker:Remove() end end objCAPZone.objFlightGroups[1]:Destroy() objCAPZone.objFlightGroups[1]:__Stop(10) table.remove(objCAPZone.objFlightGroups, 1) Jtff_log.debug(string.format("Wipe CAP Zone : %s, after wipe remaining flight groups: %d", objCAPZone.customconfig.name, #(objCAPZone.objFlightGroups)),"CAP_ZONE_TRAINING") end objCAPZone.objFlightGroups = {} -- fctKillSpawnObject(objCAPZone.objSpawn) trigger.action.outText('CAP Training Zone '..(objCAPZone.customconfig.name)..' cleaned !!', 30) Jtff_log.info(string.format("Wipe CAP Zone : %s", objCAPZone.customconfig.name),"CAP_ZONE_TRAINING") end function startCapZone(params) local objCAPZone = params[1] local effectiveForce = params[2] or 2 objCAPZone.objSpawn:InitGrouping(effectiveForce) local AICapGroup = objCAPZone.objSpawn:SpawnInZone(objCAPZone.objPatrolZone, true ) end CAPZoneArray = {} MenuCoalitionCAPZoneBlue = MENU_COALITION:New(coalition.side.BLUE, "Hostile CAP Zones", MenuCoalition[coalition.side.BLUE]) MenuCoalitionCAPZoneRed = MENU_COALITION:New(coalition.side.RED, "Hostile CAP Zones", MenuCoalition[coalition.side.RED]) local compteur = #CAPZoneArray for index, capzoneconfig in ipairs(TrainingCAPConfig) do if capzoneconfig.enable == true then compteur = compteur + 1 Jtff_log.info(string.format("creation CAP Zone : %s", capzoneconfig.name),"CAP_ZONE_TRAINING") objCapZone = {} objCapZone.objFlightGroups = {} objCapZone.objSpawn = SPAWN:New(capzoneconfig.CAPGoups[1]) :InitSkill(capzoneconfig.skill) :InitRandomizeTemplate(capzoneconfig.CAPGoups) :OnSpawnGroup(function(SpawnGroup, objCapZone) -- ****************************************************** -- ** OnGroupSpawn : Setup FlightGroup and mission ** -- ****************************************************** -- **********************Flight GroupSetup************************* Jtff_log.info(string.format("Group spawned : %s - %s", SpawnGroup:GetName(), SpawnGroup:GetTypeName()),"CAP_ZONE_TRAINING") local flightgroup = FLIGHTGROUP:New(SpawnGroup) Jtff_log.debug(string.format("FlightGroup created from group %s", SpawnGroup:GetName()),"CAP_ZONE_TRAINING") flightgroup:SetFuelCriticalThreshold(15) flightgroup:SetFuelLowThreshold(25) flightgroup:SetOutOfAAMRTB(true) flightgroup:SetFuelCriticalRTB(true) flightgroup:SetFuelLowRTB(true) flightgroup:SetAllowAfterburner() flightgroup:SetDetection(true) Jtff_log.debug(string.format("FlightGroup %s goes nose hot !", SpawnGroup:GetName()),"CAP_ZONE_TRAINING") flightgroup:SetVerbosity(JTFF_verbosity_levels[JTFF_LOGLEVEL]) function flightgroup:OnAfterDead(From, Event, To) self:CancelAllMissions() self.MissionPatrol.markerOn = false if self.MissionPatrol.marker then self.MissionPatrol.marker:Remove() end self.MissionPatrol:Stop() self.MissionPatrol = nil Jtff_log.debug(string.format("Zone %s: FlightGroup %s Dead !", objCapZone.customconfig.name, SpawnGroup:GetName()),"CAP_ZONE_TRAINING") self:__Stop(10) end function flightgroup:OnAfterRTB(From, Event, To, airbase) Jtff_log.debug(string.format("Zone %s: FlightGroup %s is RTB to %s !", objCapZone.customconfig.name, SpawnGroup:GetName(), airbase:GetName()),"CAP_ZONE_TRAINING") self:CancelAllMissions() self.MissionPatrol.markerOn = false if self.MissionPatrol.marker then self.MissionPatrol.marker:Remove() end self.MissionPatrol:Stop() for index, curFlightGroup in ipairs(objCapZone.objFlightGroups) do if curFlightGroup:GetName() == self:GetName() then table.remove(objCapZone.objFlightGroups, index) break end end end if objCapZone.customconfig.airBaseName and AIRBASE:FindByName(objCapZone.customconfig.airBaseName) then flightgroup:SetHomebase(AIRBASE:FindByName(objCapZone.customconfig.airBaseName)) end -- *********************Mission Setup****************************** flightgroup.MissionPatrol = AUFTRAG:NewPATROL_RACETRACK( objCapZone.objPatrolZone:GetRandomCoordinate(), objCapZone.customconfig.capParameters.patrolAltitude, objCapZone.customconfig.capParameters.patrolSpeed, objCapZone.customconfig.capParameters.patrolHeading, objCapZone.customconfig.capParameters.patrolLegLength, ENUMS.Formation.FixedWing.LineAbreast.Group ) flightgroup.MissionPatrol:SetName( string.format('MISSION_CAP_PATROL_%s_%d', objCapZone.customconfig.name, #objCapZone.objFlightGroups + 1) ) flightgroup.MissionPatrol:SetEngageDetected( 150, {"All"}, objCapZone.objEngageZone ) if objCapZone.customconfig.coalitionCAP == coalition.side.RED then flightgroup.MissionPatrol:SetEnableMarkers(coalition.side.BLUE) else flightgroup.MissionPatrol:SetEnableMarkers(coalition.side.RED) end flightgroup.MissionPatrol.markerOn = (JTFF_verbosity_levels[JTFF_LOGLEVEL] >= 1) flightgroup.MissionPatrol:UpdateMarker() flightgroup.MissionPatrol:SetDuration((10*60*60)) flightgroup.MissionPatrol:SetVerbosity(JTFF_verbosity_levels[JTFF_LOGLEVEL]) -- ****************************Mission Add to FlightGroup********************** flightgroup:AddMission(flightgroup.MissionPatrol) flightgroup:MissionStart(flightgroup.MissionPatrol) table.insert(objCapZone.objFlightGroups, flightgroup) Jtff_log.debug(string.format("FlightGroup %s is assigned mission %s", SpawnGroup:GetName(), flightgroup.MissionPatrol:GetName()),"CAP_ZONE_TRAINING") end, objCapZone) -- ****************************************** -- ** Set Patrol Zone ** -- ****************************************** if capzoneconfig.patrolZoneGroupName then objCapZone.objPatrolZone = ZONE_POLYGON:New( 'CAP_PATROL_ZONE_'..capzoneconfig.name, GROUP:FindByName(capzoneconfig.patrolZoneGroupName)) Jtff_log.info(string.format("Patrol zone Polygon created : %s", objCapZone.objPatrolZone:GetName()),"CAP_ZONE_TRAINING") else if capzoneconfig.patrolZoneName then objCapZone.objPatrolZone = ZONE:New(capzoneconfig.patrolZoneName) end end -- ****************************************** -- ** Set Engage Zone ** -- ****************************************** if capzoneconfig.engageZoneGroupName then objCapZone.objEngageZone = ZONE_POLYGON:New( 'CAP_ENGAGE_ZONE_'..capzoneconfig.name, GROUP:FindByName(capzoneconfig.engageZoneGroupName)) Jtff_log.info(string.format("Engage zone Polygon created : %s", objCapZone.objEngageZone:GetName()),"CAP_ZONE_TRAINING") else if capzoneconfig.engageZoneName then objCapZone.objEngageZone = ZONE:New(capzoneconfig.engageZoneName) end end -- ****************************************** -- ** Draw Engage Zone ** -- ****************************************** if capzoneconfig.coalitionCAP == coalition.side.RED then if ((capzoneconfig.drawzone == true) or false or (JTFF_verbosity_levels[JTFF_LOGLEVEL] >= 5)) then objCapZone.objEngageZone:DrawZone( coalition.side.BLUE, {1,0,0}, 1, {1,0,0}, 0.10, 4, true, nil ) objCapZone.objEngageZone:GetCoordinate():TextToAll( "CAP Training " .. capzoneconfig.name, coalition.side.BLUE, {1,0,0}, 1, {1,0,0}, 0, 20, true ) end else if ((capzoneconfig.drawzone == true) or false or (JTFF_verbosity_levels[JTFF_LOGLEVEL] >= 5)) then objCapZone.objEngageZone:DrawZone( coalition.side.RED, {1,0,0}, 1, {1,0,0}, 0.10, 4, true, nil ) objCapZone.objEngageZone:GetCoordinate():TextToAll( "CAP Training " .. capzoneconfig.name, coalition.side.RED, {1,0,0}, 1, {1,0,0}, 0, 20, true ) end end -- ***************************************** -- ** Set Custom Config ** -- ***************************************** objCapZone.customconfig = capzoneconfig CAPZoneArray[compteur] = objCapZone -- ****************************************** -- ** Set Menu Commands ** -- ****************************************** if capzoneconfig.coalitionCAP == coalition.side.RED then MENU_COALITION_COMMAND:New( coalition.side.BLUE, string.format("Zone %s : Spawn %d Hostile(s)", capzoneconfig.name, 1), MenuCoalitionCAPZoneBlue, startCapZone, {CAPZoneArray[compteur], 1} ) MENU_COALITION_COMMAND:New( coalition.side.BLUE, string.format("Zone %s : Spawn %d Hostile(s)", capzoneconfig.name, 2), MenuCoalitionCAPZoneBlue, startCapZone, {CAPZoneArray[compteur], 2} ) MENU_COALITION_COMMAND:New( coalition.side.BLUE, string.format("Zone %s : Spawn %d Hostile(s)", capzoneconfig.name, 4), MenuCoalitionCAPZoneBlue, startCapZone, {CAPZoneArray[compteur], 4} ) MENU_COALITION_COMMAND:New( coalition.side.BLUE, string.format("Zone %s : Clean", capzoneconfig.name), MenuCoalitionCAPZoneBlue, wipeCapZone, CAPZoneArray[compteur] ) else MENU_COALITION_COMMAND:New( coalition.side.RED, string.format("Zone %s : Spawn %d Hostile(s)", capzoneconfig.name, 1), MenuCoalitionCAPZoneRed, startCapZone, {CAPZoneArray[compteur], 1} ) MENU_COALITION_COMMAND:New( coalition.side.RED, string.format("Zone %s : Spawn %d Hostile(s)", capzoneconfig.name, 2), MenuCoalitionCAPZoneRed, startCapZone, {CAPZoneArray[compteur], 2} ) MENU_COALITION_COMMAND:New( coalition.side.RED, string.format("Zone %s : Spawn %d Hostile(s)", capzoneconfig.name, 4), MenuCoalitionCAPZoneRed, startCapZone, {CAPZoneArray[compteur], 4} ) MENU_COALITION_COMMAND:New( coalition.side.RED, string.format("Zone %s : Clean", capzoneconfig.name), MenuCoalitionCAPZoneRed, wipeCapZone, CAPZoneArray[compteur] ) end end end if #CAPZoneArray == 0 then MenuCoalitionCAPZoneBlue:Remove() MenuCoalitionCAPZoneRed:Remove() end