Merge pull request #81 from FlightControl-Master/AI-Balancer

- Replaced range test for unit to range test for players.
- Ensure that players database is properly populated.
- Fixed some documentation.
- Removed smoke from trigger.
- Fixed name of RandomPointVec2 to RandomVec2 and fixed in all usages.
This commit is contained in:
Sven Van de Velde 2016-06-20 13:14:00 +02:00 committed by GitHub
commit ca950e1599
13 changed files with 247 additions and 238 deletions

View File

@ -152,29 +152,29 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
-- If there is a CLIENT, the AI stays engaged and will not return.
-- If there is no CLIENT within the self.ReturnTresholdRange, then the unit will return to the Airbase return method selected.
local ClientInZone = { Value = false }
local PlayerInRange = { Value = false }
local RangeZone = ZONE_RADIUS:New( 'RangeZone', AIGroup:GetPointVec2(), self.ReturnTresholdRange )
self:E( RangeZone )
_DATABASE:ForEachUnit(
_DATABASE:ForEachPlayer(
--- @param Unit#UNIT RangeTestUnit
function( RangeTestUnit, RangeZone, AIGroup, ClientInZone )
self:E( { ClientInZone, RangeTestUnit.UnitName, RangeZone.ZoneName } )
function( RangeTestUnit, RangeZone, AIGroup, PlayerInRange )
self:E( { PlayerInRange, RangeTestUnit.UnitName, RangeZone.ZoneName } )
if RangeTestUnit:IsInZone( RangeZone ) == true then
self:E( "in zone" )
if RangeTestUnit:GetCoalition() ~= AIGroup:GetCoalition() then
self:E( "in range" )
ClientInZone.Value = true
PlayerInRange.Value = true
end
end
end,
--- @param Zone#ZONE_RADIUS RangeZone
-- @param Group#GROUP AIGroup
function( RangeZone, AIGroup, ClientInZone )
function( RangeZone, AIGroup, PlayerInRange )
local AIGroupTemplate = AIGroup:GetTemplate()
if ClientInZone.Value == false then
if PlayerInRange.Value == false then
if self.ToHomeAirbase == true then
local WayPointCount = #AIGroupTemplate.route.points
local SwitchWayPointCommand = AIGroup:CommandSwitchWayPoint( 1, WayPointCount, 1 )
@ -193,7 +193,7 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
end
end
end
, RangeZone, AIGroup, ClientInZone
, RangeZone, AIGroup, PlayerInRange
)
end

View File

@ -8,12 +8,12 @@
--
-- * UNITS
-- * GROUPS
-- * players
-- * alive players
-- * CLIENTS
-- * alive CLIENTS
-- * AIRPORTS
-- * PLAYERSJOINED
-- * PLAYERS
--
-- On top, for internal MOOSE administration purposes, the DATBASE administers the Unit and Gruop templates as defined within the Mission Editor.
-- On top, for internal MOOSE administration purposes, the DATBASE administers the Unit and Group TEMPLATES as defined within the Mission Editor.
--
-- Moose will automatically create one instance of the DATABASE class into the **global** object _DATABASE.
-- Moose refers to _DATABASE within the framework extensively, but you can also refer to the _DATABASE object within your missions if required.
@ -26,11 +26,13 @@
--
-- * @{#DATABASE.ForEachUnit}: Calls a function for each @{UNIT} it finds within the DATABASE.
-- * @{#DATABASE.ForEachGroup}: Calls a function for each @{GROUP} it finds within the DATABASE.
-- * @{#DATABASE.ForEachPlayer}: Calls a function for each player it finds within the DATABASE.
-- * @{#DATABASE.ForEachPlayerAlive}: Calls a function for each alive player it finds within the DATABASE.
-- * @{#DATABASE.ForEachPlayer}: Calls a function for each alive player it finds within the DATABASE.
-- * @{#DATABASE.ForEachPlayerJoined}: Calls a function for each joined player it finds within the DATABASE.
-- * @{#DATABASE.ForEachClient}: Calls a function for each @{CLIENT} it finds within the DATABASE.
-- * @{#DATABASE.ForEachClientAlive}: Calls a function for each alive @{CLIENT} it finds within the DATABASE.
--
--
-- ===
--
-- @module Database
-- @author FlightControl
@ -49,9 +51,8 @@ DATABASE = {
STATICS = {},
GROUPS = {},
PLAYERS = {},
PLAYERSALIVE = {},
PLAYERSJOINED = {},
CLIENTS = {},
CLIENTSALIVE = {},
AIRBASES = {},
NavPoints = {},
}
@ -238,9 +239,8 @@ function DATABASE:AddPlayer( UnitName, PlayerName )
if PlayerName then
self:E( { "Add player for unit:", UnitName, PlayerName } )
self.PLAYERS[PlayerName] = PlayerName
self.PLAYERSALIVE[PlayerName] = PlayerName
self.CLIENTSALIVE[PlayerName] = self:FindClient( UnitName )
self.PLAYERS[PlayerName] = UNIT:FindByName( UnitName )
self.PLAYERSJOINED[PlayerName] = PlayerName
end
end
@ -250,8 +250,7 @@ function DATABASE:DeletePlayer( PlayerName )
if PlayerName then
self:E( { "Clean player:", PlayerName } )
self.PLAYERSALIVE[PlayerName] = nil
self.CLIENTSALIVE[PlayerName] = nil
self.PLAYERS[PlayerName] = nil
end
end
@ -547,10 +546,10 @@ end
function DATABASE:_EventOnPlayerEnterUnit( Event )
self:F2( { Event } )
if Event.IniDCSUnit then
local PlayerName = Event.IniDCSUnit:getPlayerName()
if not self.PLAYERSALIVE[PlayerName] then
self:AddPlayer( Event.IniDCSUnitName, PlayerName )
if Event.IniUnit then
local PlayerName = Event.IniUnit:GetPlayerName()
if not self.PLAYERS[PlayerName] then
self:AddPlayer( Event.IniUnitName, PlayerName )
end
end
end
@ -562,9 +561,9 @@ end
function DATABASE:_EventOnPlayerLeaveUnit( Event )
self:F2( { Event } )
if Event.IniDCSUnit then
local PlayerName = Event.IniDCSUnit:getPlayerName()
if self.PLAYERSALIVE[PlayerName] then
if Event.IniUnit then
local PlayerName = Event.IniUnit:GetPlayerName()
if self.PLAYERS[PlayerName] then
self:DeletePlayer( PlayerName )
end
end
@ -644,7 +643,7 @@ function DATABASE:ForEachGroup( IteratorFunction, ... )
end
--- Iterate the DATABASE and call an iterator function for each player, providing the player name and optional parameters.
--- Iterate the DATABASE and call an iterator function for each **ALIVE** player, providing the player name and optional parameters.
-- @param #DATABASE self
-- @param #function IteratorFunction The function that will be called when there is an player in the database. The function needs to accept the player name.
-- @return #DATABASE self
@ -657,14 +656,14 @@ function DATABASE:ForEachPlayer( IteratorFunction, ... )
end
--- Iterate the DATABASE and call an iterator function for each **alive** player, providing the Unit of the player and optional parameters.
--- Iterate the DATABASE and call an iterator function for each player who has joined the mission, providing the Unit of the player and optional parameters.
-- @param #DATABASE self
-- @param #function IteratorFunction The function that will be called when there is an alive player in the database. The function needs to accept a UNIT parameter.
-- @param #function IteratorFunction The function that will be called when there is was a player in the database. The function needs to accept a UNIT parameter.
-- @return #DATABASE self
function DATABASE:ForEachPlayerAlive( IteratorFunction, ... )
function DATABASE:ForEachPlayerJoined( IteratorFunction, ... )
self:F2( arg )
self:ForEach( IteratorFunction, arg, self.PLAYERSALIVE )
self:ForEach( IteratorFunction, arg, self.PLAYERSJOINED )
return self
end
@ -681,18 +680,6 @@ function DATABASE:ForEachClient( IteratorFunction, ... )
return self
end
--- Iterate the DATABASE and call an iterator function for each **ALIVE** CLIENT, providing the CLIENT to the function and optional parameters.
-- @param #DATABASE self
-- @param #function IteratorFunction The function that will be called when there is an alive CLIENT in the database. The function needs to accept a CLIENT parameter.
-- @return #DATABASE self
function DATABASE:ForEachClientAlive( IteratorFunction, ... )
self:F2( arg )
self:ForEach( IteratorFunction, arg, self.CLIENTSALIVE )
return self
end
function DATABASE:_RegisterTemplates()
self:F2()

View File

@ -45,10 +45,14 @@ local _EVENTCODES = {
-- @field weapon
-- @field IniDCSUnit
-- @field IniDCSUnitName
-- @field Unit#UNIT IniUnit
-- @field #string IniUnitName
-- @field IniDCSGroup
-- @field IniDCSGroupName
-- @field TgtDCSUnit
-- @field TgtDCSUnitName
-- @field Unit#UNIT TgtUnit
-- @field #string TgtUnitName
-- @field TgtDCSGroup
-- @field TgtDCSGroupName
-- @field Weapon
@ -470,6 +474,8 @@ function EVENT:onEvent( Event )
Event.IniDCSUnit = Event.initiator
Event.IniDCSGroup = Event.IniDCSUnit:getGroup()
Event.IniDCSUnitName = Event.IniDCSUnit:getName()
Event.IniUnitName = Event.IniDCSUnitName
Event.IniUnit = UNIT:FindByName( Event.IniDCSUnitName )
Event.IniDCSGroupName = ""
if Event.IniDCSGroup and Event.IniDCSGroup:isExist() then
Event.IniDCSGroupName = Event.IniDCSGroup:getName()
@ -480,6 +486,8 @@ function EVENT:onEvent( Event )
Event.TgtDCSUnit = Event.target
Event.TgtDCSGroup = Event.TgtDCSUnit:getGroup()
Event.TgtDCSUnitName = Event.TgtDCSUnit:getName()
Event.TgtUnitName = Event.TgtDCSUnitName
Event.TgtUnit = UNIT:FindByName( Event.TgtDCSUnitName )
Event.TgtDCSGroupName = ""
if Event.TgtDCSGroup and Event.TgtDCSGroup:isExist() then
Event.TgtDCSGroupName = Event.TgtDCSGroup:getName()

View File

@ -1451,7 +1451,7 @@ function GROUP:TaskLandAtZone( Zone, Duration, RandomPoint )
local Point
if RandomPoint then
Point = Zone:GetRandomPointVec2()
Point = Zone:GetRandomVec2()
else
Point = Zone:GetPointVec2()
end
@ -2207,7 +2207,7 @@ function GROUP:TaskRouteToZone( Zone, Randomize, Speed, Formation )
local ZonePoint
if Randomize then
ZonePoint = Zone:GetRandomPointVec2()
ZonePoint = Zone:GetRandomVec2()
else
ZonePoint = Zone:GetPointVec2()
end

View File

@ -202,7 +202,7 @@ function PATROLZONE:NewPatrolRoute()
true
)
ToTargetPointVec3:SmokeRed()
--ToTargetPointVec3:SmokeRed()
PatrolRoute[#PatrolRoute+1] = ToTargetRoutePoint

View File

@ -644,7 +644,7 @@ function SPAWN:SpawnInZone( Zone, ZoneRandomize, SpawnIndex )
local ZonePoint
if ZoneRandomize == true then
ZonePoint = Zone:GetRandomPointVec2()
ZonePoint = Zone:GetRandomVec2()
else
ZonePoint = Zone:GetPointVec2()
end
@ -654,7 +654,7 @@ function SPAWN:SpawnInZone( Zone, ZoneRandomize, SpawnIndex )
-- Apply SpawnFormation
for UnitID = 1, #SpawnTemplate.units do
local ZonePointUnit = Zone:GetRandomPointVec2()
local ZonePointUnit = Zone:GetRandomVec2()
SpawnTemplate.units[UnitID].x = ZonePointUnit.x
SpawnTemplate.units[UnitID].y = ZonePointUnit.y
self:T( 'SpawnTemplate.units['..UnitID..'].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units['..UnitID..'].y = ' .. SpawnTemplate.units[UnitID].y )

View File

@ -321,7 +321,7 @@ end
--- Returns a random location within the zone.
-- @param #ZONE_RADIUS self
-- @return DCSTypes#Vec2 The random location within the zone.
function ZONE_RADIUS:GetRandomPointVec2()
function ZONE_RADIUS:GetRandomVec2()
self:F( self.ZoneName )
local Point = {}

View File

@ -1,5 +1,5 @@
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20160619_1502' )
env.info( 'Moose Generation Timestamp: 20160620_1310' )
local base = _G
Include = {}
@ -3350,10 +3350,14 @@ local _EVENTCODES = {
-- @field weapon
-- @field IniDCSUnit
-- @field IniDCSUnitName
-- @field Unit#UNIT IniUnit
-- @field #string IniUnitName
-- @field IniDCSGroup
-- @field IniDCSGroupName
-- @field TgtDCSUnit
-- @field TgtDCSUnitName
-- @field Unit#UNIT TgtUnit
-- @field #string TgtUnitName
-- @field TgtDCSGroup
-- @field TgtDCSGroupName
-- @field Weapon
@ -3775,6 +3779,8 @@ function EVENT:onEvent( Event )
Event.IniDCSUnit = Event.initiator
Event.IniDCSGroup = Event.IniDCSUnit:getGroup()
Event.IniDCSUnitName = Event.IniDCSUnit:getName()
Event.IniUnitName = Event.IniDCSUnitName
Event.IniUnit = UNIT:FindByName( Event.IniDCSUnitName )
Event.IniDCSGroupName = ""
if Event.IniDCSGroup and Event.IniDCSGroup:isExist() then
Event.IniDCSGroupName = Event.IniDCSGroup:getName()
@ -3785,6 +3791,8 @@ function EVENT:onEvent( Event )
Event.TgtDCSUnit = Event.target
Event.TgtDCSGroup = Event.TgtDCSUnit:getGroup()
Event.TgtDCSUnitName = Event.TgtDCSUnit:getName()
Event.TgtUnitName = Event.TgtDCSUnitName
Event.TgtUnit = UNIT:FindByName( Event.TgtDCSUnitName )
Event.TgtDCSGroupName = ""
if Event.TgtDCSGroup and Event.TgtDCSGroup:isExist() then
Event.TgtDCSGroupName = Event.TgtDCSGroup:getName()
@ -5632,7 +5640,7 @@ function GROUP:TaskLandAtZone( Zone, Duration, RandomPoint )
local Point
if RandomPoint then
Point = Zone:GetRandomPointVec2()
Point = Zone:GetRandomVec2()
else
Point = Zone:GetPointVec2()
end
@ -6388,7 +6396,7 @@ function GROUP:TaskRouteToZone( Zone, Randomize, Speed, Formation )
local ZonePoint
if Randomize then
ZonePoint = Zone:GetRandomPointVec2()
ZonePoint = Zone:GetRandomVec2()
else
ZonePoint = Zone:GetPointVec2()
end
@ -8244,7 +8252,7 @@ end
--- Returns a random location within the zone.
-- @param #ZONE_RADIUS self
-- @return DCSTypes#Vec2 The random location within the zone.
function ZONE_RADIUS:GetRandomPointVec2()
function ZONE_RADIUS:GetRandomVec2()
self:F( self.ZoneName )
local Point = {}
@ -9395,12 +9403,12 @@ end
--
-- * UNITS
-- * GROUPS
-- * players
-- * alive players
-- * CLIENTS
-- * alive CLIENTS
-- * AIRPORTS
-- * PLAYERSJOINED
-- * PLAYERS
--
-- On top, for internal MOOSE administration purposes, the DATBASE administers the Unit and Gruop templates as defined within the Mission Editor.
-- On top, for internal MOOSE administration purposes, the DATBASE administers the Unit and Group TEMPLATES as defined within the Mission Editor.
--
-- Moose will automatically create one instance of the DATABASE class into the **global** object _DATABASE.
-- Moose refers to _DATABASE within the framework extensively, but you can also refer to the _DATABASE object within your missions if required.
@ -9413,11 +9421,13 @@ end
--
-- * @{#DATABASE.ForEachUnit}: Calls a function for each @{UNIT} it finds within the DATABASE.
-- * @{#DATABASE.ForEachGroup}: Calls a function for each @{GROUP} it finds within the DATABASE.
-- * @{#DATABASE.ForEachPlayer}: Calls a function for each player it finds within the DATABASE.
-- * @{#DATABASE.ForEachPlayerAlive}: Calls a function for each alive player it finds within the DATABASE.
-- * @{#DATABASE.ForEachPlayer}: Calls a function for each alive player it finds within the DATABASE.
-- * @{#DATABASE.ForEachPlayerJoined}: Calls a function for each joined player it finds within the DATABASE.
-- * @{#DATABASE.ForEachClient}: Calls a function for each @{CLIENT} it finds within the DATABASE.
-- * @{#DATABASE.ForEachClientAlive}: Calls a function for each alive @{CLIENT} it finds within the DATABASE.
--
--
-- ===
--
-- @module Database
-- @author FlightControl
@ -9436,9 +9446,8 @@ DATABASE = {
STATICS = {},
GROUPS = {},
PLAYERS = {},
PLAYERSALIVE = {},
PLAYERSJOINED = {},
CLIENTS = {},
CLIENTSALIVE = {},
AIRBASES = {},
NavPoints = {},
}
@ -9625,9 +9634,8 @@ function DATABASE:AddPlayer( UnitName, PlayerName )
if PlayerName then
self:E( { "Add player for unit:", UnitName, PlayerName } )
self.PLAYERS[PlayerName] = PlayerName
self.PLAYERSALIVE[PlayerName] = PlayerName
self.CLIENTSALIVE[PlayerName] = self:FindClient( UnitName )
self.PLAYERS[PlayerName] = UNIT:FindByName( UnitName )
self.PLAYERSJOINED[PlayerName] = PlayerName
end
end
@ -9637,8 +9645,7 @@ function DATABASE:DeletePlayer( PlayerName )
if PlayerName then
self:E( { "Clean player:", PlayerName } )
self.PLAYERSALIVE[PlayerName] = nil
self.CLIENTSALIVE[PlayerName] = nil
self.PLAYERS[PlayerName] = nil
end
end
@ -9934,10 +9941,10 @@ end
function DATABASE:_EventOnPlayerEnterUnit( Event )
self:F2( { Event } )
if Event.IniDCSUnit then
local PlayerName = Event.IniDCSUnit:getPlayerName()
if not self.PLAYERSALIVE[PlayerName] then
self:AddPlayer( Event.IniDCSUnitName, PlayerName )
if Event.IniUnit then
local PlayerName = Event.IniUnit:GetPlayerName()
if not self.PLAYERS[PlayerName] then
self:AddPlayer( Event.IniUnitName, PlayerName )
end
end
end
@ -9949,9 +9956,9 @@ end
function DATABASE:_EventOnPlayerLeaveUnit( Event )
self:F2( { Event } )
if Event.IniDCSUnit then
local PlayerName = Event.IniDCSUnit:getPlayerName()
if self.PLAYERSALIVE[PlayerName] then
if Event.IniUnit then
local PlayerName = Event.IniUnit:GetPlayerName()
if self.PLAYERS[PlayerName] then
self:DeletePlayer( PlayerName )
end
end
@ -10031,7 +10038,7 @@ function DATABASE:ForEachGroup( IteratorFunction, ... )
end
--- Iterate the DATABASE and call an iterator function for each player, providing the player name and optional parameters.
--- Iterate the DATABASE and call an iterator function for each **ALIVE** player, providing the player name and optional parameters.
-- @param #DATABASE self
-- @param #function IteratorFunction The function that will be called when there is an player in the database. The function needs to accept the player name.
-- @return #DATABASE self
@ -10044,14 +10051,14 @@ function DATABASE:ForEachPlayer( IteratorFunction, ... )
end
--- Iterate the DATABASE and call an iterator function for each **alive** player, providing the Unit of the player and optional parameters.
--- Iterate the DATABASE and call an iterator function for each player who has joined the mission, providing the Unit of the player and optional parameters.
-- @param #DATABASE self
-- @param #function IteratorFunction The function that will be called when there is an alive player in the database. The function needs to accept a UNIT parameter.
-- @param #function IteratorFunction The function that will be called when there is was a player in the database. The function needs to accept a UNIT parameter.
-- @return #DATABASE self
function DATABASE:ForEachPlayerAlive( IteratorFunction, ... )
function DATABASE:ForEachPlayerJoined( IteratorFunction, ... )
self:F2( arg )
self:ForEach( IteratorFunction, arg, self.PLAYERSALIVE )
self:ForEach( IteratorFunction, arg, self.PLAYERSJOINED )
return self
end
@ -10068,18 +10075,6 @@ function DATABASE:ForEachClient( IteratorFunction, ... )
return self
end
--- Iterate the DATABASE and call an iterator function for each **ALIVE** CLIENT, providing the CLIENT to the function and optional parameters.
-- @param #DATABASE self
-- @param #function IteratorFunction The function that will be called when there is an alive CLIENT in the database. The function needs to accept a CLIENT parameter.
-- @return #DATABASE self
function DATABASE:ForEachClientAlive( IteratorFunction, ... )
self:F2( arg )
self:ForEach( IteratorFunction, arg, self.CLIENTSALIVE )
return self
end
function DATABASE:_RegisterTemplates()
self:F2()
@ -18239,7 +18234,7 @@ function SPAWN:SpawnInZone( Zone, ZoneRandomize, SpawnIndex )
local ZonePoint
if ZoneRandomize == true then
ZonePoint = Zone:GetRandomPointVec2()
ZonePoint = Zone:GetRandomVec2()
else
ZonePoint = Zone:GetPointVec2()
end
@ -18249,7 +18244,7 @@ function SPAWN:SpawnInZone( Zone, ZoneRandomize, SpawnIndex )
-- Apply SpawnFormation
for UnitID = 1, #SpawnTemplate.units do
local ZonePointUnit = Zone:GetRandomPointVec2()
local ZonePointUnit = Zone:GetRandomVec2()
SpawnTemplate.units[UnitID].x = ZonePointUnit.x
SpawnTemplate.units[UnitID].y = ZonePointUnit.y
self:T( 'SpawnTemplate.units['..UnitID..'].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units['..UnitID..'].y = ' .. SpawnTemplate.units[UnitID].y )
@ -21324,7 +21319,7 @@ function PATROLZONE:NewPatrolRoute()
true
)
ToTargetPointVec3:SmokeRed()
--ToTargetPointVec3:SmokeRed()
PatrolRoute[#PatrolRoute+1] = ToTargetRoutePoint
@ -21538,29 +21533,29 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
-- If there is a CLIENT, the AI stays engaged and will not return.
-- If there is no CLIENT within the self.ReturnTresholdRange, then the unit will return to the Airbase return method selected.
local ClientInZone = { Value = false }
local PlayerInRange = { Value = false }
local RangeZone = ZONE_RADIUS:New( 'RangeZone', AIGroup:GetPointVec2(), self.ReturnTresholdRange )
self:E( RangeZone )
_DATABASE:ForEachUnit(
_DATABASE:ForEachPlayer(
--- @param Unit#UNIT RangeTestUnit
function( RangeTestUnit, RangeZone, AIGroup, ClientInZone )
self:E( { ClientInZone, RangeTestUnit.UnitName, RangeZone.ZoneName } )
function( RangeTestUnit, RangeZone, AIGroup, PlayerInRange )
self:E( { PlayerInRange, RangeTestUnit.UnitName, RangeZone.ZoneName } )
if RangeTestUnit:IsInZone( RangeZone ) == true then
self:E( "in zone" )
if RangeTestUnit:GetCoalition() ~= AIGroup:GetCoalition() then
self:E( "in range" )
ClientInZone.Value = true
PlayerInRange.Value = true
end
end
end,
--- @param Zone#ZONE_RADIUS RangeZone
-- @param Group#GROUP AIGroup
function( RangeZone, AIGroup, ClientInZone )
function( RangeZone, AIGroup, PlayerInRange )
local AIGroupTemplate = AIGroup:GetTemplate()
if ClientInZone.Value == false then
if PlayerInRange.Value == false then
if self.ToHomeAirbase == true then
local WayPointCount = #AIGroupTemplate.route.points
local SwitchWayPointCommand = AIGroup:CommandSwitchWayPoint( 1, WayPointCount, 1 )
@ -21579,7 +21574,7 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
end
end
end
, RangeZone, AIGroup, ClientInZone
, RangeZone, AIGroup, PlayerInRange
)
end

View File

@ -1,5 +1,5 @@
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20160619_1502' )
env.info( 'Moose Generation Timestamp: 20160620_1310' )
local base = _G
Include = {}
@ -3350,10 +3350,14 @@ local _EVENTCODES = {
-- @field weapon
-- @field IniDCSUnit
-- @field IniDCSUnitName
-- @field Unit#UNIT IniUnit
-- @field #string IniUnitName
-- @field IniDCSGroup
-- @field IniDCSGroupName
-- @field TgtDCSUnit
-- @field TgtDCSUnitName
-- @field Unit#UNIT TgtUnit
-- @field #string TgtUnitName
-- @field TgtDCSGroup
-- @field TgtDCSGroupName
-- @field Weapon
@ -3775,6 +3779,8 @@ function EVENT:onEvent( Event )
Event.IniDCSUnit = Event.initiator
Event.IniDCSGroup = Event.IniDCSUnit:getGroup()
Event.IniDCSUnitName = Event.IniDCSUnit:getName()
Event.IniUnitName = Event.IniDCSUnitName
Event.IniUnit = UNIT:FindByName( Event.IniDCSUnitName )
Event.IniDCSGroupName = ""
if Event.IniDCSGroup and Event.IniDCSGroup:isExist() then
Event.IniDCSGroupName = Event.IniDCSGroup:getName()
@ -3785,6 +3791,8 @@ function EVENT:onEvent( Event )
Event.TgtDCSUnit = Event.target
Event.TgtDCSGroup = Event.TgtDCSUnit:getGroup()
Event.TgtDCSUnitName = Event.TgtDCSUnit:getName()
Event.TgtUnitName = Event.TgtDCSUnitName
Event.TgtUnit = UNIT:FindByName( Event.TgtDCSUnitName )
Event.TgtDCSGroupName = ""
if Event.TgtDCSGroup and Event.TgtDCSGroup:isExist() then
Event.TgtDCSGroupName = Event.TgtDCSGroup:getName()
@ -5632,7 +5640,7 @@ function GROUP:TaskLandAtZone( Zone, Duration, RandomPoint )
local Point
if RandomPoint then
Point = Zone:GetRandomPointVec2()
Point = Zone:GetRandomVec2()
else
Point = Zone:GetPointVec2()
end
@ -6388,7 +6396,7 @@ function GROUP:TaskRouteToZone( Zone, Randomize, Speed, Formation )
local ZonePoint
if Randomize then
ZonePoint = Zone:GetRandomPointVec2()
ZonePoint = Zone:GetRandomVec2()
else
ZonePoint = Zone:GetPointVec2()
end
@ -8244,7 +8252,7 @@ end
--- Returns a random location within the zone.
-- @param #ZONE_RADIUS self
-- @return DCSTypes#Vec2 The random location within the zone.
function ZONE_RADIUS:GetRandomPointVec2()
function ZONE_RADIUS:GetRandomVec2()
self:F( self.ZoneName )
local Point = {}
@ -9395,12 +9403,12 @@ end
--
-- * UNITS
-- * GROUPS
-- * players
-- * alive players
-- * CLIENTS
-- * alive CLIENTS
-- * AIRPORTS
-- * PLAYERSJOINED
-- * PLAYERS
--
-- On top, for internal MOOSE administration purposes, the DATBASE administers the Unit and Gruop templates as defined within the Mission Editor.
-- On top, for internal MOOSE administration purposes, the DATBASE administers the Unit and Group TEMPLATES as defined within the Mission Editor.
--
-- Moose will automatically create one instance of the DATABASE class into the **global** object _DATABASE.
-- Moose refers to _DATABASE within the framework extensively, but you can also refer to the _DATABASE object within your missions if required.
@ -9413,11 +9421,13 @@ end
--
-- * @{#DATABASE.ForEachUnit}: Calls a function for each @{UNIT} it finds within the DATABASE.
-- * @{#DATABASE.ForEachGroup}: Calls a function for each @{GROUP} it finds within the DATABASE.
-- * @{#DATABASE.ForEachPlayer}: Calls a function for each player it finds within the DATABASE.
-- * @{#DATABASE.ForEachPlayerAlive}: Calls a function for each alive player it finds within the DATABASE.
-- * @{#DATABASE.ForEachPlayer}: Calls a function for each alive player it finds within the DATABASE.
-- * @{#DATABASE.ForEachPlayerJoined}: Calls a function for each joined player it finds within the DATABASE.
-- * @{#DATABASE.ForEachClient}: Calls a function for each @{CLIENT} it finds within the DATABASE.
-- * @{#DATABASE.ForEachClientAlive}: Calls a function for each alive @{CLIENT} it finds within the DATABASE.
--
--
-- ===
--
-- @module Database
-- @author FlightControl
@ -9436,9 +9446,8 @@ DATABASE = {
STATICS = {},
GROUPS = {},
PLAYERS = {},
PLAYERSALIVE = {},
PLAYERSJOINED = {},
CLIENTS = {},
CLIENTSALIVE = {},
AIRBASES = {},
NavPoints = {},
}
@ -9625,9 +9634,8 @@ function DATABASE:AddPlayer( UnitName, PlayerName )
if PlayerName then
self:E( { "Add player for unit:", UnitName, PlayerName } )
self.PLAYERS[PlayerName] = PlayerName
self.PLAYERSALIVE[PlayerName] = PlayerName
self.CLIENTSALIVE[PlayerName] = self:FindClient( UnitName )
self.PLAYERS[PlayerName] = UNIT:FindByName( UnitName )
self.PLAYERSJOINED[PlayerName] = PlayerName
end
end
@ -9637,8 +9645,7 @@ function DATABASE:DeletePlayer( PlayerName )
if PlayerName then
self:E( { "Clean player:", PlayerName } )
self.PLAYERSALIVE[PlayerName] = nil
self.CLIENTSALIVE[PlayerName] = nil
self.PLAYERS[PlayerName] = nil
end
end
@ -9934,10 +9941,10 @@ end
function DATABASE:_EventOnPlayerEnterUnit( Event )
self:F2( { Event } )
if Event.IniDCSUnit then
local PlayerName = Event.IniDCSUnit:getPlayerName()
if not self.PLAYERSALIVE[PlayerName] then
self:AddPlayer( Event.IniDCSUnitName, PlayerName )
if Event.IniUnit then
local PlayerName = Event.IniUnit:GetPlayerName()
if not self.PLAYERS[PlayerName] then
self:AddPlayer( Event.IniUnitName, PlayerName )
end
end
end
@ -9949,9 +9956,9 @@ end
function DATABASE:_EventOnPlayerLeaveUnit( Event )
self:F2( { Event } )
if Event.IniDCSUnit then
local PlayerName = Event.IniDCSUnit:getPlayerName()
if self.PLAYERSALIVE[PlayerName] then
if Event.IniUnit then
local PlayerName = Event.IniUnit:GetPlayerName()
if self.PLAYERS[PlayerName] then
self:DeletePlayer( PlayerName )
end
end
@ -10031,7 +10038,7 @@ function DATABASE:ForEachGroup( IteratorFunction, ... )
end
--- Iterate the DATABASE and call an iterator function for each player, providing the player name and optional parameters.
--- Iterate the DATABASE and call an iterator function for each **ALIVE** player, providing the player name and optional parameters.
-- @param #DATABASE self
-- @param #function IteratorFunction The function that will be called when there is an player in the database. The function needs to accept the player name.
-- @return #DATABASE self
@ -10044,14 +10051,14 @@ function DATABASE:ForEachPlayer( IteratorFunction, ... )
end
--- Iterate the DATABASE and call an iterator function for each **alive** player, providing the Unit of the player and optional parameters.
--- Iterate the DATABASE and call an iterator function for each player who has joined the mission, providing the Unit of the player and optional parameters.
-- @param #DATABASE self
-- @param #function IteratorFunction The function that will be called when there is an alive player in the database. The function needs to accept a UNIT parameter.
-- @param #function IteratorFunction The function that will be called when there is was a player in the database. The function needs to accept a UNIT parameter.
-- @return #DATABASE self
function DATABASE:ForEachPlayerAlive( IteratorFunction, ... )
function DATABASE:ForEachPlayerJoined( IteratorFunction, ... )
self:F2( arg )
self:ForEach( IteratorFunction, arg, self.PLAYERSALIVE )
self:ForEach( IteratorFunction, arg, self.PLAYERSJOINED )
return self
end
@ -10068,18 +10075,6 @@ function DATABASE:ForEachClient( IteratorFunction, ... )
return self
end
--- Iterate the DATABASE and call an iterator function for each **ALIVE** CLIENT, providing the CLIENT to the function and optional parameters.
-- @param #DATABASE self
-- @param #function IteratorFunction The function that will be called when there is an alive CLIENT in the database. The function needs to accept a CLIENT parameter.
-- @return #DATABASE self
function DATABASE:ForEachClientAlive( IteratorFunction, ... )
self:F2( arg )
self:ForEach( IteratorFunction, arg, self.CLIENTSALIVE )
return self
end
function DATABASE:_RegisterTemplates()
self:F2()
@ -18239,7 +18234,7 @@ function SPAWN:SpawnInZone( Zone, ZoneRandomize, SpawnIndex )
local ZonePoint
if ZoneRandomize == true then
ZonePoint = Zone:GetRandomPointVec2()
ZonePoint = Zone:GetRandomVec2()
else
ZonePoint = Zone:GetPointVec2()
end
@ -18249,7 +18244,7 @@ function SPAWN:SpawnInZone( Zone, ZoneRandomize, SpawnIndex )
-- Apply SpawnFormation
for UnitID = 1, #SpawnTemplate.units do
local ZonePointUnit = Zone:GetRandomPointVec2()
local ZonePointUnit = Zone:GetRandomVec2()
SpawnTemplate.units[UnitID].x = ZonePointUnit.x
SpawnTemplate.units[UnitID].y = ZonePointUnit.y
self:T( 'SpawnTemplate.units['..UnitID..'].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units['..UnitID..'].y = ' .. SpawnTemplate.units[UnitID].y )
@ -21324,7 +21319,7 @@ function PATROLZONE:NewPatrolRoute()
true
)
ToTargetPointVec3:SmokeRed()
--ToTargetPointVec3:SmokeRed()
PatrolRoute[#PatrolRoute+1] = ToTargetRoutePoint
@ -21538,29 +21533,29 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
-- If there is a CLIENT, the AI stays engaged and will not return.
-- If there is no CLIENT within the self.ReturnTresholdRange, then the unit will return to the Airbase return method selected.
local ClientInZone = { Value = false }
local PlayerInRange = { Value = false }
local RangeZone = ZONE_RADIUS:New( 'RangeZone', AIGroup:GetPointVec2(), self.ReturnTresholdRange )
self:E( RangeZone )
_DATABASE:ForEachUnit(
_DATABASE:ForEachPlayer(
--- @param Unit#UNIT RangeTestUnit
function( RangeTestUnit, RangeZone, AIGroup, ClientInZone )
self:E( { ClientInZone, RangeTestUnit.UnitName, RangeZone.ZoneName } )
function( RangeTestUnit, RangeZone, AIGroup, PlayerInRange )
self:E( { PlayerInRange, RangeTestUnit.UnitName, RangeZone.ZoneName } )
if RangeTestUnit:IsInZone( RangeZone ) == true then
self:E( "in zone" )
if RangeTestUnit:GetCoalition() ~= AIGroup:GetCoalition() then
self:E( "in range" )
ClientInZone.Value = true
PlayerInRange.Value = true
end
end
end,
--- @param Zone#ZONE_RADIUS RangeZone
-- @param Group#GROUP AIGroup
function( RangeZone, AIGroup, ClientInZone )
function( RangeZone, AIGroup, PlayerInRange )
local AIGroupTemplate = AIGroup:GetTemplate()
if ClientInZone.Value == false then
if PlayerInRange.Value == false then
if self.ToHomeAirbase == true then
local WayPointCount = #AIGroupTemplate.route.points
local SwitchWayPointCommand = AIGroup:CommandSwitchWayPoint( 1, WayPointCount, 1 )
@ -21579,7 +21574,7 @@ function AIBALANCER:_ClientAliveMonitorScheduler()
end
end
end
, RangeZone, AIGroup, ClientInZone
, RangeZone, AIGroup, PlayerInRange
)
end

View File

@ -86,13 +86,13 @@
<ul>
<li>UNITS</li>
<li>GROUPS</li>
<li>players</li>
<li>alive players</li>
<li>CLIENTS</li>
<li>alive CLIENTS</li>
<li>AIRPORTS</li>
<li>PLAYERSJOINED</li>
<li>PLAYERS</li>
</ul>
<p>On top, for internal MOOSE administration purposes, the DATBASE administers the Unit and Gruop templates as defined within the Mission Editor.</p>
<p>On top, for internal MOOSE administration purposes, the DATBASE administers the Unit and Group TEMPLATES as defined within the Mission Editor.</p>
<p>Moose will automatically create one instance of the DATABASE class into the <strong>global</strong> object _DATABASE.
Moose refers to _DATABASE within the framework extensively, but you can also refer to the _DATABASE object within your missions if required.</p>
@ -105,13 +105,15 @@ The following iterator methods are currently available within the DATABASE:</p>
<ul>
<li><a href="##(DATABASE).ForEachUnit">DATABASE.ForEachUnit</a>: Calls a function for each <a href="UNIT.html">UNIT</a> it finds within the DATABASE.</li>
<li><a href="##(DATABASE).ForEachGroup">DATABASE.ForEachGroup</a>: Calls a function for each <a href="GROUP.html">GROUP</a> it finds within the DATABASE.</li>
<li><a href="##(DATABASE).ForEachPlayer">DATABASE.ForEachPlayer</a>: Calls a function for each player it finds within the DATABASE.</li>
<li><a href="##(DATABASE).ForEachPlayerAlive">DATABASE.ForEachPlayerAlive</a>: Calls a function for each alive player it finds within the DATABASE.</li>
<li><a href="##(DATABASE).ForEachPlayer">DATABASE.ForEachPlayer</a>: Calls a function for each alive player it finds within the DATABASE.</li>
<li><a href="##(DATABASE).ForEachPlayerJoined">DATABASE.ForEachPlayerJoined</a>: Calls a function for each joined player it finds within the DATABASE.</li>
<li><a href="##(DATABASE).ForEachClient">DATABASE.ForEachClient</a>: Calls a function for each <a href="CLIENT.html">CLIENT</a> it finds within the DATABASE.</li>
<li><a href="##(DATABASE).ForEachClientAlive">DATABASE.ForEachClientAlive</a>: Calls a function for each alive <a href="CLIENT.html">CLIENT</a> it finds within the DATABASE.
</li>
<li><a href="##(DATABASE).ForEachClientAlive">DATABASE.ForEachClientAlive</a>: Calls a function for each alive <a href="CLIENT.html">CLIENT</a> it finds within the DATABASE.</li>
</ul>
<hr/>
<h2>Global(s)</h2>
<table class="function_list">
<tr>
@ -169,12 +171,6 @@ The following iterator methods are currently available within the DATABASE:</p>
<td class="name" nowrap="nowrap"><a href="##(DATABASE).CLIENTS">DATABASE.CLIENTS</a></td>
<td class="summary">
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(DATABASE).CLIENTSALIVE">DATABASE.CLIENTSALIVE</a></td>
<td class="summary">
</td>
</tr>
<tr>
@ -247,12 +243,6 @@ The following iterator methods are currently available within the DATABASE:</p>
<td class="name" nowrap="nowrap"><a href="##(DATABASE).ForEachClient">DATABASE:ForEachClient(IteratorFunction, ...)</a></td>
<td class="summary">
<p>Iterate the DATABASE and call an iterator function for each CLIENT, providing the CLIENT to the function and optional parameters.</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(DATABASE).ForEachClientAlive">DATABASE:ForEachClientAlive(IteratorFunction, ...)</a></td>
<td class="summary">
<p>Iterate the DATABASE and call an iterator function for each <strong>ALIVE</strong> CLIENT, providing the CLIENT to the function and optional parameters.</p>
</td>
</tr>
<tr>
@ -264,13 +254,13 @@ The following iterator methods are currently available within the DATABASE:</p>
<tr>
<td class="name" nowrap="nowrap"><a href="##(DATABASE).ForEachPlayer">DATABASE:ForEachPlayer(IteratorFunction, ...)</a></td>
<td class="summary">
<p>Iterate the DATABASE and call an iterator function for each player, providing the player name and optional parameters.</p>
<p>Iterate the DATABASE and call an iterator function for each <strong>ALIVE</strong> player, providing the player name and optional parameters.</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(DATABASE).ForEachPlayerAlive">DATABASE:ForEachPlayerAlive(IteratorFunction, ...)</a></td>
<td class="name" nowrap="nowrap"><a href="##(DATABASE).ForEachPlayerJoined">DATABASE:ForEachPlayerJoined(IteratorFunction, ...)</a></td>
<td class="summary">
<p>Iterate the DATABASE and call an iterator function for each <strong>alive</strong> player, providing the Unit of the player and optional parameters.</p>
<p>Iterate the DATABASE and call an iterator function for each player who has joined the mission, providing the Unit of the player and optional parameters.</p>
</td>
</tr>
<tr>
@ -340,7 +330,7 @@ The following iterator methods are currently available within the DATABASE:</p>
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(DATABASE).PLAYERSALIVE">DATABASE.PLAYERSALIVE</a></td>
<td class="name" nowrap="nowrap"><a href="##(DATABASE).PLAYERSJOINED">DATABASE.PLAYERSJOINED</a></td>
<td class="summary">
</td>
@ -622,20 +612,6 @@ The following iterator methods are currently available within the DATABASE:</p>
</dd>
</dl>
<dl class="function">
<dt>
<em></em>
<a id="#(DATABASE).CLIENTSALIVE" >
<strong>DATABASE.CLIENTSALIVE</strong>
</a>
</dt>
<dd>
</dd>
</dl>
<dl class="function">
@ -943,38 +919,6 @@ self</p>
<dl class="function">
<dt>
<a id="#(DATABASE).ForEachClientAlive" >
<strong>DATABASE:ForEachClientAlive(IteratorFunction, ...)</strong>
</a>
</dt>
<dd>
<p>Iterate the DATABASE and call an iterator function for each <strong>ALIVE</strong> CLIENT, providing the CLIENT to the function and optional parameters.</p>
<h3>Parameters</h3>
<ul>
<li>
<p><code><em>#function IteratorFunction </em></code>:
The function that will be called when there is an alive CLIENT in the database. The function needs to accept a CLIENT parameter.</p>
</li>
<li>
<p><code><em> ... </em></code>: </p>
</li>
</ul>
<h3>Return value</h3>
<p><em><a href="##(DATABASE)">#DATABASE</a>:</em>
self</p>
</dd>
</dl>
<dl class="function">
<dt>
<a id="#(DATABASE).ForEachGroup" >
<strong>DATABASE:ForEachGroup(IteratorFunction, ...)</strong>
</a>
@ -1013,7 +957,7 @@ self</p>
</dt>
<dd>
<p>Iterate the DATABASE and call an iterator function for each player, providing the player name and optional parameters.</p>
<p>Iterate the DATABASE and call an iterator function for each <strong>ALIVE</strong> player, providing the player name and optional parameters.</p>
<h3>Parameters</h3>
<ul>
@ -1039,20 +983,20 @@ self</p>
<dl class="function">
<dt>
<a id="#(DATABASE).ForEachPlayerAlive" >
<strong>DATABASE:ForEachPlayerAlive(IteratorFunction, ...)</strong>
<a id="#(DATABASE).ForEachPlayerJoined" >
<strong>DATABASE:ForEachPlayerJoined(IteratorFunction, ...)</strong>
</a>
</dt>
<dd>
<p>Iterate the DATABASE and call an iterator function for each <strong>alive</strong> player, providing the Unit of the player and optional parameters.</p>
<p>Iterate the DATABASE and call an iterator function for each player who has joined the mission, providing the Unit of the player and optional parameters.</p>
<h3>Parameters</h3>
<ul>
<li>
<p><code><em>#function IteratorFunction </em></code>:
The function that will be called when there is an alive player in the database. The function needs to accept a UNIT parameter.</p>
The function that will be called when there is was a player in the database. The function needs to accept a UNIT parameter.</p>
</li>
<li>
@ -1299,8 +1243,8 @@ DBObject = DATABASE:New()</code></pre>
<dt>
<em></em>
<a id="#(DATABASE).PLAYERSALIVE" >
<strong>DATABASE.PLAYERSALIVE</strong>
<a id="#(DATABASE).PLAYERSJOINED" >
<strong>DATABASE.PLAYERSJOINED</strong>
</a>
</dt>
<dd>

View File

@ -321,6 +321,18 @@
<td class="name" nowrap="nowrap"><a href="##(EVENTDATA).IniDCSUnitName">EVENTDATA.IniDCSUnitName</a></td>
<td class="summary">
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(EVENTDATA).IniUnit">EVENTDATA.IniUnit</a></td>
<td class="summary">
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(EVENTDATA).IniUnitName">EVENTDATA.IniUnitName</a></td>
<td class="summary">
</td>
</tr>
<tr>
@ -345,6 +357,18 @@
<td class="name" nowrap="nowrap"><a href="##(EVENTDATA).TgtDCSUnitName">EVENTDATA.TgtDCSUnitName</a></td>
<td class="summary">
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(EVENTDATA).TgtUnit">EVENTDATA.TgtUnit</a></td>
<td class="summary">
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(EVENTDATA).TgtUnitName">EVENTDATA.TgtUnitName</a></td>
<td class="summary">
</td>
</tr>
<tr>
@ -1592,6 +1616,34 @@ The self instance of the class for which the event is.</p>
</dd>
</dl>
<dl class="function">
<dt>
<em><a href="Unit.html##(UNIT)">Unit#UNIT</a></em>
<a id="#(EVENTDATA).IniUnit" >
<strong>EVENTDATA.IniUnit</strong>
</a>
</dt>
<dd>
</dd>
</dl>
<dl class="function">
<dt>
<em>#string</em>
<a id="#(EVENTDATA).IniUnitName" >
<strong>EVENTDATA.IniUnitName</strong>
</a>
</dt>
<dd>
</dd>
</dl>
<dl class="function">
@ -1644,6 +1696,34 @@ The self instance of the class for which the event is.</p>
</dd>
</dl>
<dl class="function">
<dt>
<em><a href="Unit.html##(UNIT)">Unit#UNIT</a></em>
<a id="#(EVENTDATA).TgtUnit" >
<strong>EVENTDATA.TgtUnit</strong>
</a>
</dt>
<dd>
</dd>
</dl>
<dl class="function">
<dt>
<em>#string</em>
<a id="#(EVENTDATA).TgtUnitName" >
<strong>EVENTDATA.TgtUnitName</strong>
</a>
</dt>
<dd>
</dd>
</dl>
<dl class="function">

View File

@ -376,7 +376,7 @@
</td>
</tr>
<tr>
<td class="name" nowrap="nowrap"><a href="##(ZONE_RADIUS).GetRandomPointVec2">ZONE_RADIUS:GetRandomPointVec2()</a></td>
<td class="name" nowrap="nowrap"><a href="##(ZONE_RADIUS).GetRandomVec2">ZONE_RADIUS:GetRandomVec2()</a></td>
<td class="summary">
<p>Returns a random location within the zone.</p>
</td>
@ -1200,8 +1200,8 @@ The radius of the zone.</p>
<dl class="function">
<dt>
<a id="#(ZONE_RADIUS).GetRandomPointVec2" >
<strong>ZONE_RADIUS:GetRandomPointVec2()</strong>
<a id="#(ZONE_RADIUS).GetRandomVec2" >
<strong>ZONE_RADIUS:GetRandomVec2()</strong>
</a>
</dt>
<dd>