Progress on the AI_PATROLZONE!!! Working test mission!!!

This commit is contained in:
Sven Van de Velde
2016-08-21 10:56:56 +02:00
parent 3861362ed9
commit a800531ea0
89 changed files with 2115 additions and 55817 deletions

View File

@@ -1,11 +1,32 @@
local US_PlanesClientSet = SET_CLIENT:New():FilterCountries( "USA" ):FilterCategories( "plane" ):FilterStart()
local US_PlanesSpawn1 = SPAWN:New( "AI US 1" )
local US_PlanesSpawn2 = SPAWN:New( "AI US 2" )
local US_AIBalancer = AIBALANCER:New( US_PlanesClientSet, { US_PlanesSpawn1, US_PlanesSpawn2 } )
local US_PlanesSpawn1 = SPAWN:New( "AI US 1" ):InitCleanUp( 90 )
local US_PlanesSpawn2 = SPAWN:New( "AI US 2" ):InitCleanUp( 90 )
local US_AIBalancer = AIBALANCER:New( US_PlanesClientSet )
US_AIBalancer:OnNewAI(
function( AIGroup )
AIGroup = US_PlanesSpawn1:Spawn()
local AIPatrolZone = AI_PATROLZONE:New( 3000, 6000, 900, 1100 )
AIPatrolZone:ManageFuel( 0.2, 180 )
AIGroup:SetTask( AIPatrolZone )
AIPatrolZone:OnRTB(
function( AIGroup )
AIGroup = US_PlanesSpawn1:Spawn()
end
)
end
)
local RU_PlanesClientSet = SET_CLIENT:New():FilterCountries( "RUSSIA" ):FilterCategories( "plane" ):FilterStart()
local RU_PlanesSpawn = SPAWN:New( "AI RU" )
local RU_PlanesSpawn = SPAWN:New( "AI RU" ):InitCleanUp( 90 )
local RU_AIBalancer = AIBALANCER:New( RU_PlanesClientSet, RU_PlanesSpawn )
local RU_AirbasesSet = SET_AIRBASE:New():FilterCoalitions("red"):FilterStart()

View File

@@ -1,8 +1,80 @@
-- This test mission models the behaviour of the AI_PATROLZONE class.
--
-- It creates a 2 AI_PATROLZONE objects with the name Patrol1 and Patrol2.
-- Patrol1 will goven a GROUP object to patrol the zone defined by PatrolZone1, within 3000 meters and 6000 meters, within a speed of 400 and 600 km/h.
-- When the GROUP object that is assigned to Patrol has fuel below 20%, the GROUP object will orbit for 60 secondes, before returning to base.
--
-- Patrol2 will goven a GROUP object to patrol the zone defined by PatrolZone2, within 600 meters and 1000 meters, within a speed of 300 and 400 km/h.
-- When the GROUP object that is assigned to Patrol has fuel below 20%, the GROUP object will orbit for 0 secondes, before returning to base.
--
-- The Patrol1 and Patrol2 object have 2 state transition functions defined, which customize the default behaviour of the RTB state.
-- When Patrol1 goes RTB, it will create a new GROUP object, that will be assigned to Patrol2.
-- When Patrol2 goes RTB, it will create a new GROUP object, that will be assgined to Patrol1.
--
-- In this way, the Patrol1 and Patrol2 objects are fluctuating the patrol pattern from PatrolZone1 and PatrolZone2 :-)
local PatrolZoneGroup = GROUP:FindByName( "Patrol Zone" )
local PatrolZone = ZONE_POLYGON:New( "PatrolZone", PatrolZoneGroup )
local PatrolGroup = GROUP:FindByName( "Patrol Group" )
local PatrolZoneGroup1 = GROUP:FindByName( "Patrol Zone 1" )
local PatrolZone1 = ZONE_POLYGON:New( "Patrol Zone 1", PatrolZoneGroup1 )
local Patrol = PATROLZONE:New( PatrolGroup, PatrolZone, 3000, 6000, 300, 600 )
Patrol:ManageFuel( 0.2, 60 )
local PatrolZoneGroup2 = GROUP:FindByName( "Patrol Zone 2" )
local PatrolZone2 = ZONE_POLYGON:New( "Patrol Zone 2", PatrolZoneGroup2 )
local PatrolSpawn = SPAWN:New( "Patrol Group" )
local PatrolGroup = PatrolSpawn:Spawn()
local Patrol1 = AI_PATROLZONE:New( PatrolZone1, 3000, 6000, 400, 600 )
Patrol1:ManageFuel( 0.2, 60 )
Patrol1:SetGroup( PatrolGroup )
Patrol1:__Start( 1, PatrolGroup )
local Patrol2 = AI_PATROLZONE:New( PatrolZone2, 600, 1000, 300, 400 )
Patrol2:ManageFuel( 0.2, 0 )
--- State transition function for the AI\_PATROLZONE **Patrol1** object
-- @param #AI_PATROLZONE self
-- @param Group#GROUP AIGroup
-- @return #boolean If false is returned, then the OnAfter state transition function will not be called.
function Patrol1:OnBeforeRTB( AIGroup )
AIGroup:MessageToRed( "Returning to base", 20 )
end
--- State transition function for the AI\_PATROLZONE **Patrol1** object
-- @param AI_PatrolZone#AI_PATROLZONE self
-- @param Group#GROUP AIGroup
function Patrol1:OnAfterRTB( AIGroup )
local NewGroup = PatrolSpawn:Spawn()
Patrol2:SetGroup( NewGroup )
Patrol2:__Start( 1, NewGroup )
end
--- State transition function for the AI\_PATROLZONE **Patrol1** object
-- @param AI_PatrolZone#AI_PATROLZONE self
-- @param Group#GROUP AIGroup
function Patrol1:OnAfterPatrol( AIGroup )
AIGroup:MessageToRed( "Patrolling in zone " .. PatrolZone1:GetName() , 20 )
end
--- State transition function for the AI\_PATROLZONE **Patrol2** object
-- @param #AI_PATROLZONE self
-- @param Group#GROUP AIGroup
-- @return #boolean If false is returned, then the OnAfter state transition function will not be called.
function Patrol2:OnBeforeRTB( AIGroup )
AIGroup:MessageToRed( "Returning to base", 20 )
end
--- State transition function for the AI\_PATROLZONE **Patrol2** object
-- @param AI_PatrolZone#AI_PATROLZONE self
-- @param Group#GROUP AIGroup
function Patrol2:OnAfterRTB( AIGroup )
local NewGroup = PatrolSpawn:Spawn()
Patrol1:SetGroup( NewGroup )
Patrol1:__Start( 1, NewGroup )
end
--- State transition function for the AI\_PATROLZONE **Patrol2** object
-- @param AI_PatrolZone#AI_PATROLZONE self
-- @param Group#GROUP AIGroup
function Patrol2:OnAfterPatrol( AIGroup )
AIGroup:MessageToRed( "Patrolling in zone " .. PatrolZone2:GetName() , 20 )
end

View File

@@ -0,0 +1,28 @@
-- This test will schedule the same function 2 times.
SpawnTest = SPAWN:New( "Test" )
TestZone = ZONE:New( "TestZone" )
local function MessageTest2()
SpawnTest:SpawnInZone( TestZone, true )
end
local function MessageTest1()
SpawnTest:SpawnInZone( TestZone, true )
-- The second after 10 seconds
SCHEDULER:New( nil, MessageTest2, {}, 5 )
-- The third after 15 seconds
SCHEDULER:New( nil, MessageTest2, {}, 10 )
end
-- The first after 5 seconds
SCHEDULER:New( nil, MessageTest1, {}, 5 )
-- The fourth after 20 seconds
SCHEDULER:New( nil, MessageTest1, {}, 20 )

View File

@@ -0,0 +1,16 @@
-- This test will schedule the same function 2 times.
SpawnTest = SPAWN:New( "Test" )
TestZone = ZONE:New( "TestZone" )
local function MessageTest()
SpawnTest:SpawnInZone( TestZone, true )
end
-- The first after 5 seconds
TestScheduler1 = SCHEDULER:New( nil, MessageTest, {}, 5 )
-- The second after 10 seconds
TestScheduler2 = SCHEDULER:New( nil, MessageTest, {}, 10 )