diff --git a/Documentation/DCSCoalitionObject.html b/Documentation/DCSCoalitionObject.html
index e0a1741e8..8f4146e80 100644
--- a/Documentation/DCSCoalitionObject.html
+++ b/Documentation/DCSCoalitionObject.html
@@ -73,6 +73,12 @@
CoalitionObject |
+ |
+
+
+ | coalition |
+
+
|
@@ -88,6 +94,38 @@
CoalitionObject:getCountry() |
Returns object country.
+ |
+
+
+
+
+
+
+
+
@@ -105,6 +143,20 @@
+
+
+
+-
+
+ #coalition
+
+coalition
+
+
+-
+
+
+
@@ -124,7 +176,7 @@
Return value
-#coalition.side:
+DCSTypes#coalition.side:
@@ -145,11 +197,68 @@
#country.id:
+
+
+
+
+ Field(s)
+
+-
+
+ #coalition.side
+
+coalition.side
+
+
+-
+
+
+
-
+ Field(s)
+
+-
+
+
+coalition.side.BLUE
+
+
+-
+
+
+
+
+
+
+-
+
+
+coalition.side.NEUTRAL
+
+
+-
+
+
+
+
+
+
+-
+
+
+coalition.side.RED
+
+
+-
+
+
+
+
+
+
diff --git a/Documentation/Database.html b/Documentation/Database.html
index 0e988cba7..cb2bdddb7 100644
--- a/Documentation/Database.html
+++ b/Documentation/Database.html
@@ -68,7 +68,70 @@
Administers the Initial Sets of the Mission Templates as defined within the Mission Editor.
-Administers the Spawning of new Groups within the DCSRTE and administers these new Groups within the DATABASE object(s).
+Mission designers can use the DATABASE class to build sets of units belonging to certain:
+
+
+ - coalitions
+ - categories
+ - countries
+ - unit types
+ - starting with certain prefix strings.
+
+
+ Note that this is an initial filter set. More to follow, like zones etc.
+
+
+DATABASE construction methods:
+Create a new DATABASE object with the DATABASE.New method:
+
+
+
+
+DATABASE filter criteria:
+You can set filter criteria to define the set of units within the database.
+Filter criteria are defined by:
+
+
+
+Once the filter criteria have been set for the DATABASE, you can start filtering using:
+
+
+
+Planned filter criteria within development are (so these are not yet available):
+
+
+
+
+DATABASE iterators:
+Once the filters have been defined and the DATABASE has been built, you can iterate the database with the available iterator methods.
+The iterator methods will walk the DATABASE set, and call for each element within the set a function that you provide.
+The following iterator methods are currently available within the DATABASE:
+
+
+
+Planned iterators methods in development are (so these are not yet available):
+
+
Global(s)
- | DATABASE.ActivePlayers |
+ DATABASE.AlivePlayers |
|
@@ -109,6 +166,90 @@
DATABASE.ClientsByName |
+ |
+
+
+ | DATABASE.DCSGroups |
+
+
+ |
+
+
+ | DATABASE.DCSGroupsAlive |
+
+
+ |
+
+
+ | DATABASE.DCSUnits |
+
+
+ |
+
+
+ | DATABASE.DCSUnitsAlive |
+
+
+ |
+
+
+ | DATABASE.Filter |
+
+
+ |
+
+
+ | DATABASE:FilterCategory(Categories) |
+
+ Builds a set of units out of categories.
+ |
+
+
+ | DATABASE:FilterCoalition(Coalitions) |
+
+ Builds a set of units of coalitons.
+ |
+
+
+ | DATABASE:FilterCountries(Countries) |
+
+ Builds a set of units of defined countries.
+ |
+
+
+ | DATABASE:FilterGroupPrefix(Prefixes) |
+
+ Builds a set of units of defined group prefixes.
+ |
+
+
+ | DATABASE.FilterMeta |
+
+
+ |
+
+
+ | DATABASE:FilterStart() |
+
+ Starts the filtering.
+ |
+
+
+ | DATABASE:FilterType(Types) |
+
+ Builds a set of units of defined unit types.
+ |
+
+
+ | DATABASE:FilterUnitPrefix(Prefixes) |
+
+ Builds a set of units of defined unit prefixes.
+ |
+
+
+ | DATABASE:ForEachAliveUnit(IteratorFunction, ...) |
+
+ Interate the DATABASE and call an interator function for each alive unit, providing the Unit and optional parameters.
|
@@ -132,13 +273,19 @@
| DATABASE:New() |
- Creates a new DATABASE Object to administer the Groups defined and alive within the DCSRTE.
+Creates a new DATABASE object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names.
|
| DATABASE.Players |
+ |
+
+
+ | DATABASE:ScanEnvironment() |
+
+
|
@@ -157,12 +304,42 @@
| DATABASE.Statics |
+ |
+
+
+ | DATABASE:TraceDatabase() |
+
+ Traces the current database contents in the log ...
|
| DATABASE.Units |
+ |
+
+
+ | DATABASE:_EventOnBirth(Event) |
+
+ Handles the OnBirth event for the alive units set.
+ |
+
+
+ | DATABASE:_EventOnDeadOrCrash(Event) |
+
+ Handles the OnDead or OnCrash event for alive units set.
+ |
+
+
+ | DATABASE:_IsAliveDCSUnit(DCSUnit) |
+
+
+ |
+
+
+ | DATABASE:_IsIncludeDCSUnit(DCSUnit) |
+
+
|
@@ -186,20 +363,6 @@
-
-
-
--
-
- Database#DATABASE
-
-_Database
-
-
--
-
-
-
@@ -213,8 +376,8 @@
-
-DATABASE.ActivePlayers
+
+DATABASE.AlivePlayers
@@ -263,6 +426,320 @@
+
+
+
+-
+
+
+
+DATABASE.DCSGroups
+
+
+-
+
+
+
+
+
+
+-
+
+
+
+DATABASE.DCSGroupsAlive
+
+
+-
+
+
+
+
+
+
+-
+
+
+
+DATABASE.DCSUnits
+
+
+-
+
+
+
+
+
+
+-
+
+
+
+DATABASE.DCSUnitsAlive
+
+
+-
+
+
+
+
+
+
+-
+
+
+
+DATABASE.Filter
+
+
+-
+
+
+
+
+
+
+-
+
+
+DATABASE:FilterCategory(Categories)
+
+
+-
+
+
Builds a set of units out of categories.
+
+
+Possible current categories are plane, helicopter, ground, ship.
+
+ Parameter
+
+ Return value
+
+#DATABASE:
+self
+
+
+
+
+-
+
+
+DATABASE:FilterCoalition(Coalitions)
+
+
+-
+
+
Builds a set of units of coalitons.
+
+
+Possible current coalitions are red, blue and neutral.
+
+ Parameter
+
+ Return value
+
+#DATABASE:
+self
+
+
+
+
+-
+
+
+DATABASE:FilterCountries(Countries)
+
+
+-
+
+
Builds a set of units of defined countries.
+
+
+Possible current countries are those known within DCS world.
+
+ Parameter
+
+ Return value
+
+#DATABASE:
+self
+
+
+
+
+-
+
+
+DATABASE:FilterGroupPrefix(Prefixes)
+
+
+-
+
+
Builds a set of units of defined group prefixes.
+
+
+All the units starting with the given group prefixes will be included within the set.
+
+ Parameter
+
+ Return value
+
+#DATABASE:
+self
+
+
+
+
+-
+
+
+
+DATABASE.FilterMeta
+
+
+-
+
+
+
+
+
+
+-
+
+
+DATABASE:FilterStart()
+
+
+-
+
+
Starts the filtering.
+
+ Return value
+
+#DATABASE:
+self
+
+
+
+
+-
+
+
+DATABASE:FilterType(Types)
+
+
+-
+
+
Builds a set of units of defined unit types.
+
+
+Possible current types are those types known within DCS world.
+
+ Parameter
+
+ Return value
+
+#DATABASE:
+self
+
+
+
+
+-
+
+
+DATABASE:FilterUnitPrefix(Prefixes)
+
+
+-
+
+
Builds a set of units of defined unit prefixes.
+
+
+All the units starting with the given prefixes will be included within the set.
+
+ Parameter
+
+ Return value
+
+#DATABASE:
+self
+
+
+
+
+-
+
+
+DATABASE:ForEachAliveUnit(IteratorFunction, ...)
+
+
+-
+
+
Interate the DATABASE and call an interator function for each alive unit, providing the Unit and optional parameters.
+
+ Parameters
+
+ Return value
+
+#DATABASE:
+self
+
@@ -323,12 +800,12 @@
-
-
Creates a new DATABASE Object to administer the Groups defined and alive within the DCSRTE.
+Creates a new DATABASE object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names.
Return value
+#DATABASE:
-DATABASE
Usage:
-- Define a new DATABASE Object. This DBObject will contain a reference to all Group and Unit Templates defined within the ME and the DCSRTE.
@@ -348,6 +825,19 @@ DBObject = DATABASE:New()
+
+
+
+-
+
+
+DATABASE:ScanEnvironment()
+
+
+-
+
+
+
@@ -414,6 +904,27 @@ This method is used by the SPAWN class.
+
+
+
+-
+
+
+DATABASE:TraceDatabase()
+
+
+-
+
+
Traces the current database contents in the log ...
+
+
+(for debug reasons).
+
+ Return value
+
+#DATABASE:
+self
+
@@ -428,6 +939,100 @@ This method is used by the SPAWN class.
+
+
+
+-
+
+
+DATABASE:_EventOnBirth(Event)
+
+
+-
+
+
Handles the OnBirth event for the alive units set.
+
+ Parameter
+
+
+
+
+-
+
+
+DATABASE:_EventOnDeadOrCrash(Event)
+
+
+-
+
+
Handles the OnDead or OnCrash event for alive units set.
+
+ Parameter
+
+
+
+
+-
+
+
+DATABASE:_IsAliveDCSUnit(DCSUnit)
+
+
+-
+
+
+
+
Parameter
+
+ Return value
+
+#DATABASE:
+self
+
+
+
+
+-
+
+
+DATABASE:_IsIncludeDCSUnit(DCSUnit)
+
+
+-
+
+
+
+
Parameter
+
+ Return value
+
+#DATABASE:
+self
+
diff --git a/Documentation/Escort.html b/Documentation/Escort.html
index a75e3f26f..9855f9944 100644
--- a/Documentation/Escort.html
+++ b/Documentation/Escort.html
@@ -1835,6 +1835,7 @@ self
-
+
ESCORT.ReportTargetsScheduler
diff --git a/Documentation/Event.html b/Documentation/Event.html
index 9e5bd862b..eaa58b863 100644
--- a/Documentation/Event.html
+++ b/Documentation/Event.html
@@ -73,12 +73,6 @@
| EVENT |
- |
-
-
- | _EVENTDISPATCHER |
-
- Declare the event dispatcher based on the EVENT class
|
@@ -389,20 +383,6 @@
-
-
-
--
-
- #EVENT
-
-_EVENTDISPATCHER
-
-
--
-
-
Declare the event dispatcher based on the EVENT class
-
diff --git a/Documentation/Spawn.html b/Documentation/Spawn.html
index 21d159c33..49bc1e57f 100644
--- a/Documentation/Spawn.html
+++ b/Documentation/Spawn.html
@@ -89,52 +89,58 @@ Groups will follow the following naming structure when spawned at run-time:
Some additional notes that need to be remembered:
- Templates are actually groups defined within the mission editor, with the flag "Late Activation" set. As such, these groups are never used within the mission, but are used by the #SPAWN module.
- It is important to defined BEFORE you spawn new groups, a proper initialization of the SPAWN instance is done with the options you want to use.
- When designing a mission, NEVER name groups using a "#" within the name of the group Spawn Template(s), or the SPAWN module logic won't work anymore.
- SPAWN object construction methods:
- Create a new SPAWN object with the SPAWN.New or the SPAWN.NewWithAlias methods:
- SPAWN.New: Creates a new SPAWN object taking the name of the group that functions as the Template.
+ - Templates are actually groups defined within the mission editor, with the flag "Late Activation" set. As such, these groups are never used within the mission, but are used by the #SPAWN module.
+ - It is important to defined BEFORE you spawn new groups, a proper initialization of the SPAWN instance is done with the options you want to use.
+ - When designing a mission, NEVER name groups using a "#" within the name of the group Spawn Template(s), or the SPAWN module logic won't work anymore.
+
+
+SPAWN construction methods:
+Create a new SPAWN object with the SPAWN.New or the SPAWN.NewWithAlias methods:
+
+
+ - SPAWN.New: Creates a new SPAWN object taking the name of the group that functions as the Template.
It is important to understand how the SPAWN class works internally. The SPAWN object created will contain internally a list of groups that will be spawned and that are already spawned.
The initialization functions will modify this list of groups so that when a group gets spawned, ALL information is already prepared when spawning. This is done for performance reasons.
So in principle, the group list will contain all parameters and configurations after initialization, and when groups get actually spawned, this spawning can be done quickly and efficient.
-
- SPAWN object initialization methods:
- A spawn object will behave differently based on the usage of initialization methods:
- SPAWN.Limit: Limits the amount of groups that can be alive at the same time and that can be dynamically spawned.
- SPAWN.RandomizeRoute: Randomize the routes of spawned groups.
- SPAWN.RandomizeTemplate: Randomize the group templates so that when a new group is spawned, a random group template is selected from one of the templates defined.
- SPAWN.Uncontrolled: Spawn plane groups uncontrolled.
- SPAWN.Array: Make groups visible before they are actually activated, and order these groups like a batallion in an array.
- SPAWN.Repeat: Re-spawn groups when they land at the home base. Similar functions are SPAWN.RepeatOnLanding and SPAWN.RepeatOnEngineShutDown.
- SPAWN object spawning methods:
- Groups can be spawned at different times and methods:
- SPAWN.Spawn: Spawn one new group based on the last spawned index.
- SPAWN.ReSpawn: Re-spawn a group based on a given index.
- SPAWN.SpawnScheduled: Spawn groups at scheduled but randomized intervals. You can use SPAWN.SpawnScheduleStart and SPAWN.SpawnScheduleStop to start and stop the schedule respectively.
- SPAWN.SpawnFromUnit: Spawn a new group taking the position of a UNIT.
- SPAWN.SpawnInZone: Spawn a new group in a ZONE.
-
+SPAWN initialization methods:
+A spawn object will behave differently based on the usage of initialization methods:
+
+
+
+SPAWN spawning methods:
+Groups can be spawned at different times and methods:
+
+
Note that SPAWN.Spawn and SPAWN.ReSpawn return a GROUP#GROUP.New object, that contains a reference to the DCSGroup object.
You can use the GROUP object to do further actions with the DCSGroup.
-
- - SPAWN object cleaning:
-
- Sometimes, it will occur during a mission run-time, that ground or especially air objects get damaged, and will while being damged stop their activities, while remaining alive.
- In such cases, the SPAWN object will just sit there and wait until that group gets destroyed, but most of the time it won't,
- and it may occur that no new groups are or can be spawned as limits are reached.
- To prevent this, a SPAWN.CleanUp initialization method has been defined that will silently monitor the status of each spawned group.
- Once a group has a velocity = 0, and has been waiting for a defined interval, that group will be cleaned or removed from run-time.
- There is a catch however :-) If a damaged group has returned to an airbase within the coalition, that group will not be considered as "lost"...
- In such a case, when the inactive group is cleaned, a new group will Re-spawned automatically.
- This models AI that has succesfully returned to their airbase, to restart their combat activities.
- Check the SPAWN.CleanUp for further info.
-
+SPAWN object cleaning:
+Sometimes, it will occur during a mission run-time, that ground or especially air objects get damaged, and will while being damged stop their activities, while remaining alive.
+In such cases, the SPAWN object will just sit there and wait until that group gets destroyed, but most of the time it won't,
+and it may occur that no new groups are or can be spawned as limits are reached.
+To prevent this, a SPAWN.CleanUp initialization method has been defined that will silently monitor the status of each spawned group.
+Once a group has a velocity = 0, and has been waiting for a defined interval, that group will be cleaned or removed from run-time.
+There is a catch however :-) If a damaged group has returned to an airbase within the coalition, that group will not be considered as "lost"...
+In such a case, when the inactive group is cleaned, a new group will Re-spawned automatically.
+This models AI that has succesfully returned to their airbase, to restart their combat activities.
+Check the SPAWN.CleanUp for further info.
Global(s)
@@ -2052,7 +2058,7 @@ Nothing found
- TODO Need to delete this... _Database does this now ...
+ TODO Need to delete this... _DATABASE does this now ...
Parameter
diff --git a/Moose/Database.lua b/Moose/Database.lua
index 075d2b83f..bdada4e5e 100644
--- a/Moose/Database.lua
+++ b/Moose/Database.lua
@@ -1,8 +1,61 @@
--- Administers the Initial Sets of the Mission Templates as defined within the Mission Editor.
--- Administers the Spawning of new Groups within the DCSRTE and administers these new Groups within the DATABASE object(s).
+-- Mission designers can use the DATABASE class to build sets of units belonging to certain:
+--
+-- * coalitions
+-- * categories
+-- * countries
+-- * unit types
+-- * starting with certain prefix strings.
+--
+-- Note that this is an initial filter set. More to follow, like zones etc.
+--
+--
+-- DATABASE construction methods:
+-- =================================
+-- Create a new DATABASE object with the @{#DATABASE.New} method:
+--
+-- * @{#DATABASE.New}: Creates a new DATABASE object.
+--
+--
+-- DATABASE filter criteria:
+-- =========================
+-- You can set filter criteria to define the set of units within the database.
+-- Filter criteria are defined by:
+--
+-- * @{#DATABASE.FilterCoalitions}: Builds the DATABASE with the units belonging to the coalition(s).
+-- * @{#DATABASE.FilterCategories}: Builds the DATABASE with the units belonging to the category(ies).
+-- * @{#DATABASE.FilterTypes}: Builds the DATABASE with the units belonging to the unit type(s).
+-- * @{#DATABASE.FilterCountries}: Builds the DATABASE with the units belonging to the country(ies).
+-- * @{#DATABASE.FilterUnitPrefixes}: Builds the DATABASE with the units starting with the same prefix string(s).
+--
+-- Once the filter criteria have been set for the DATABASE, you can start filtering using:
+--
+-- * @{#DATABASE.FilterStart}: Starts the filtering of the units within the database.
+--
+-- Planned filter criteria within development are (so these are not yet available):
+--
+-- * @{#DATABASE.FilterGroupPrefixes}: Builds the DATABASE with the groups of the units starting with the same prefix string(s).
+-- * @{#DATABASE.FilterZones}: Builds the DATABASE with the units within a @{Zone#ZONE}.
+--
+--
+-- DATABASE iterators:
+-- ===================
+-- Once the filters have been defined and the DATABASE has been built, you can iterate the database with the available iterator methods.
+-- The iterator methods will walk the DATABASE set, and call for each element within the set a function that you provide.
+-- The following iterator methods are currently available within the DATABASE:
+--
+-- * @{#DATABASE.ForEachAliveUnit}: Calls a function for each alive unit it finds within the DATABASE.
+--
+-- Planned iterators methods in development are (so these are not yet available):
+--
+-- * @{#DATABASE.ForEachUnit}: Calls a function for each unit contained within the DATABASE.
+-- * @{#DATABASE.ForEachGroup}: Calls a function for each group contained within the DATABASE.
+-- * @{#DATABASE.ForEachUnitInZone}: Calls a function for each unit within a certain zone contained within the DATABASE.
+--
-- @module Database
-- @author FlightControl
+
Include.File( "Routines" )
Include.File( "Base" )
Include.File( "Menu" )
@@ -89,7 +142,7 @@ end
-- @param #DATABASE self
-- @param #string Coalitions Can take the following values: "red", "blue", "neutral".
-- @return #DATABASE self
-function DATABASE:FilterCoalition( Coalitions )
+function DATABASE:FilterCoalitions( Coalitions )
if not self.Filter.Coalitions then
self.Filter.Coalitions = {}
end
@@ -107,7 +160,7 @@ end
-- @param #DATABASE self
-- @param #string Categories Can take the following values: "plane", "helicopter", "ground", "ship".
-- @return #DATABASE self
-function DATABASE:FilterCategory( Categories )
+function DATABASE:FilterCategories( Categories )
if not self.Filter.Categories then
self.Filter.Categories = {}
end
@@ -125,7 +178,7 @@ end
-- @param #DATABASE self
-- @param #string Types Can take those type strings known within DCS world.
-- @return #DATABASE self
-function DATABASE:FilterType( Types )
+function DATABASE:FilterTypes( Types )
if not self.Filter.Types then
self.Filter.Types = {}
end
@@ -161,7 +214,7 @@ end
-- @param #DATABASE self
-- @param #string Prefixes The prefix of which the unit name starts with.
-- @return #DATABASE self
-function DATABASE:FilterUnitPrefix( Prefixes )
+function DATABASE:FilterUnitPrefixes( Prefixes )
if not self.Filter.UnitPrefixes then
self.Filter.UnitPrefixes = {}
end
@@ -179,7 +232,7 @@ end
-- @param #DATABASE self
-- @param #string Prefixes The prefix of which the group name where the unit belongs to starts with.
-- @return #DATABASE self
-function DATABASE:FilterGroupPrefix( Prefixes )
+function DATABASE:FilterGroupPrefixes( Prefixes )
if not self.Filter.GroupPrefixes then
self.Filter.GroupPrefixes = {}
end
@@ -204,10 +257,10 @@ function DATABASE:FilterStart()
for UnitRegistrationID, UnitRegistration in pairs( _DATABASE.Units ) do
self:T( UnitRegistration )
local DCSUnit = Unit.getByName( UnitRegistration.UnitName )
- if self:IsIncludeDCSUnit( DCSUnit ) then
+ if self:_IsIncludeDCSUnit( DCSUnit ) then
self.DCSUnits[DCSUnit:getName()] = DCSUnit
end
- if self:IsAliveDCSUnit( DCSUnit ) then
+ if self:_IsAliveDCSUnit( DCSUnit ) then
self.DCSUnitsAlive[DCSUnit:getName()] = DCSUnit
end
end
@@ -218,155 +271,6 @@ function DATABASE:FilterStart()
return self
end
----
--- @param #DATABASE self
--- @param DCSUnit#Unit DCSUnit
--- @return #DATABASE self
-function DATABASE:IsIncludeDCSUnit( DCSUnit )
- self:F( DCSUnit )
- local DCSUnitInclude = true
-
- if self.Filter.Coalitions then
- local DCSUnitCoalition = false
- for CoalitionID, CoalitionName in pairs( self.Filter.Coalitions ) do
- self:T( { "Coalition:", DCSUnit:getCoalition(), self.FilterMeta.Coalitions[CoalitionName], CoalitionName } )
- if self.FilterMeta.Coalitions[CoalitionName] and self.FilterMeta.Coalitions[CoalitionName] == DCSUnit:getCoalition() then
- DCSUnitCoalition = true
- end
- end
- DCSUnitInclude = DCSUnitInclude and DCSUnitCoalition
- end
-
- if self.Filter.Categories then
- local DCSUnitCategory = false
- for CategoryID, CategoryName in pairs( self.Filter.Categories ) do
- self:T( { "Category:", DCSUnit:getDesc().category, self.FilterMeta.Categories[CategoryName], CategoryName } )
- if self.FilterMeta.Categories[CategoryName] and self.FilterMeta.Categories[CategoryName] == DCSUnit:getDesc().category then
- DCSUnitCategory = true
- end
- end
- DCSUnitInclude = DCSUnitInclude and DCSUnitCategory
- end
-
- if self.Filter.Types then
- local DCSUnitType = false
- for TypeID, TypeName in pairs( self.Filter.Types ) do
- self:T( { "Type:", DCSUnit:getTypeName(), TypeName } )
- if TypeName == DCSUnit:getTypeName() then
- DCSUnitType = true
- end
- end
- DCSUnitInclude = DCSUnitInclude and DCSUnitType
- end
-
- if self.Filter.Countries then
- local DCSUnitCountry = false
- for CountryID, CountryName in pairs( self.Filter.Countries ) do
- self:T( { "Country:", DCSUnit:getCountry(), CountryName } )
- if country.id[CountryName] == DCSUnit:getCountry() then
- DCSUnitCountry = true
- end
- end
- DCSUnitInclude = DCSUnitInclude and DCSUnitCountry
- end
-
- if self.Filter.UnitPrefixes then
- local DCSUnitPrefix = false
- for UnitPrefixId, UnitPrefix in pairs( self.Filter.UnitPrefixes ) do
- self:T( { "Unit Prefix:", string.find( DCSUnit:getName(), UnitPrefix, 1 ), UnitPrefix } )
- if string.find( DCSUnit:getName(), UnitPrefix, 1 ) then
- DCSUnitPrefix = true
- end
- end
- DCSUnitInclude = DCSUnitInclude and DCSUnitPrefix
- end
-
- self:T( DCSUnitInclude )
- return DCSUnitInclude
-end
-
----
--- @param #DATABASE self
--- @param DCSUnit#Unit DCSUnit
--- @return #DATABASE self
-function DATABASE:IsAliveDCSUnit( DCSUnit )
- self:F( DCSUnit )
- local DCSUnitAlive = false
- if DCSUnit and DCSUnit:isExist() and DCSUnit:isActive() then
- if self.DCSUnits[DCSUnit:getName()] then
- DCSUnitAlive = true
- end
- end
- self:T( DCSUnitAlive )
- return DCSUnitAlive
-end
-
-
-function DATABASE:ScanEnvironment()
- self:F()
-
- self.Navpoints = {}
- self.Units = {}
- --Build routines.db.units and self.Navpoints
- for coa_name, coa_data in pairs(env.mission.coalition) do
-
- if (coa_name == 'red' or coa_name == 'blue') and type(coa_data) == 'table' then
- --self.Units[coa_name] = {}
-
- ----------------------------------------------
- -- build nav points DB
- self.Navpoints[coa_name] = {}
- if coa_data.nav_points then --navpoints
- for nav_ind, nav_data in pairs(coa_data.nav_points) do
-
- if type(nav_data) == 'table' then
- self.Navpoints[coa_name][nav_ind] = routines.utils.deepCopy(nav_data)
-
- self.Navpoints[coa_name][nav_ind]['name'] = nav_data.callsignStr -- name is a little bit more self-explanatory.
- self.Navpoints[coa_name][nav_ind]['point'] = {} -- point is used by SSE, support it.
- self.Navpoints[coa_name][nav_ind]['point']['x'] = nav_data.x
- self.Navpoints[coa_name][nav_ind]['point']['y'] = 0
- self.Navpoints[coa_name][nav_ind]['point']['z'] = nav_data.y
- end
- end
- end
- -------------------------------------------------
- if coa_data.country then --there is a country table
- for cntry_id, cntry_data in pairs(coa_data.country) do
-
- local countryName = string.lower(cntry_data.name)
- --self.Units[coa_name][countryName] = {}
- --self.Units[coa_name][countryName]["countryId"] = cntry_data.id
-
- if type(cntry_data) == 'table' then --just making sure
-
- for obj_type_name, obj_type_data in pairs(cntry_data) do
-
- if obj_type_name == "helicopter" or obj_type_name == "ship" or obj_type_name == "plane" or obj_type_name == "vehicle" or obj_type_name == "static" then --should be an unncessary check
-
- local category = obj_type_name
-
- if ((type(obj_type_data) == 'table') and obj_type_data.group and (type(obj_type_data.group) == 'table') and (#obj_type_data.group > 0)) then --there's a group!
-
- --self.Units[coa_name][countryName][category] = {}
-
- for group_num, GroupTemplate in pairs(obj_type_data.group) do
-
- if GroupTemplate and GroupTemplate.units and type(GroupTemplate.units) == 'table' then --making sure again- this is a valid group
- self:_RegisterGroup( GroupTemplate )
- end --if GroupTemplate and GroupTemplate.units then
- end --for group_num, GroupTemplate in pairs(obj_type_data.group) do
- end --if ((type(obj_type_data) == 'table') and obj_type_data.group and (type(obj_type_data.group) == 'table') and (#obj_type_data.group > 0)) then
- end --if obj_type_name == "helicopter" or obj_type_name == "ship" or obj_type_name == "plane" or obj_type_name == "vehicle" or obj_type_name == "static" then
- end --for obj_type_name, obj_type_data in pairs(cntry_data) do
- end --if type(cntry_data) == 'table' then
- end --for cntry_id, cntry_data in pairs(coa_data.country) do
- end --if coa_data.country then --there is a country table
- end --if coa_name == 'red' or coa_name == 'blue' and type(coa_data) == 'table' then
- end --for coa_name, coa_data in pairs(mission.coalition) do
-
- return self
-end
--- Instantiate new Groups within the DCSRTE.
-- This method expects EXACTLY the same structure as a structure within the ME, and needs 2 additional fields defined:
@@ -461,7 +365,7 @@ function DATABASE:_EventOnBirth( Event )
self:F( { Event } )
if Event.IniDCSUnit then
- if self:IsIncludeDCSUnit( Event.IniDCSUnit ) then
+ if self:_IsIncludeDCSUnit( Event.IniDCSUnit ) then
self.DCSUnits[Event.IniDCSUnitName] = Event.IniDCSUnit
self.DCSUnitsAlive[Event.IniDCSUnitName] = Event.IniDCSUnit
end
@@ -490,64 +394,189 @@ function DATABASE:ForEachAliveUnit( IteratorFunction, ... )
self:F( arg )
local function CoRoutine()
+ local Count = 0
for DCSUnitID, DCSUnit in pairs( self.DCSUnitsAlive ) do
self:T2( DCSUnit )
IteratorFunction( DCSUnit, unpack( arg ) )
- coroutine.yield()
+ Count = Count + 1
+ if Count % 10 == 0 then
+ coroutine.yield( false )
+ end
end
return true
end
local co = coroutine.create( CoRoutine )
- while true do
+ local function Schedule()
+
local status, res = coroutine.resume( co )
- self:T2( { status, res } )
+ self:T( { status, res } )
if status == false then
error( res )
end
- if res == true then
- break
+ if res == false then
+ timer.scheduleFunction( Schedule, {}, timer.getTime() + 0.001 )
end
end
+
+ timer.scheduleFunction( Schedule, {}, timer.getTime() + 1 )
return self
end
---- Interate the DATABASE and call an interator function for each unit, providing the UNIT and optional parameters.
--- @param #DATABASE self
--- @param #function IteratorFunction The function that will be called when there is an alive unit in the database. The function needs to accept a UNIT parameter.
--- @return #DATABASE self
-function DATABASE:ForEachAliveUnit( IteratorFunction, ... )
- self:F( arg )
-
- local function CoRoutine()
- for DCSUnitID, DCSUnit in pairs( self.DCSUnits ) do
- self:T2( DCSUnit )
- IteratorFunction( DCSUnit, unpack( arg ) )
- coroutine.yield()
- end
- return true
- end
-
- local co = coroutine.create( CoRoutine )
-
- while true do
- local status, res = coroutine.resume( co )
- self:T2( { status, res } )
-
- if status == false then
- error( res )
- end
- if res == true then
- break
- end
- end
-
+function DATABASE:ScanEnvironment()
+ self:F()
+
+ self.Navpoints = {}
+ self.Units = {}
+ --Build routines.db.units and self.Navpoints
+ for coa_name, coa_data in pairs(env.mission.coalition) do
+
+ if (coa_name == 'red' or coa_name == 'blue') and type(coa_data) == 'table' then
+ --self.Units[coa_name] = {}
+
+ ----------------------------------------------
+ -- build nav points DB
+ self.Navpoints[coa_name] = {}
+ if coa_data.nav_points then --navpoints
+ for nav_ind, nav_data in pairs(coa_data.nav_points) do
+
+ if type(nav_data) == 'table' then
+ self.Navpoints[coa_name][nav_ind] = routines.utils.deepCopy(nav_data)
+
+ self.Navpoints[coa_name][nav_ind]['name'] = nav_data.callsignStr -- name is a little bit more self-explanatory.
+ self.Navpoints[coa_name][nav_ind]['point'] = {} -- point is used by SSE, support it.
+ self.Navpoints[coa_name][nav_ind]['point']['x'] = nav_data.x
+ self.Navpoints[coa_name][nav_ind]['point']['y'] = 0
+ self.Navpoints[coa_name][nav_ind]['point']['z'] = nav_data.y
+ end
+ end
+ end
+ -------------------------------------------------
+ if coa_data.country then --there is a country table
+ for cntry_id, cntry_data in pairs(coa_data.country) do
+
+ local countryName = string.lower(cntry_data.name)
+ --self.Units[coa_name][countryName] = {}
+ --self.Units[coa_name][countryName]["countryId"] = cntry_data.id
+
+ if type(cntry_data) == 'table' then --just making sure
+
+ for obj_type_name, obj_type_data in pairs(cntry_data) do
+
+ if obj_type_name == "helicopter" or obj_type_name == "ship" or obj_type_name == "plane" or obj_type_name == "vehicle" or obj_type_name == "static" then --should be an unncessary check
+
+ local category = obj_type_name
+
+ if ((type(obj_type_data) == 'table') and obj_type_data.group and (type(obj_type_data.group) == 'table') and (#obj_type_data.group > 0)) then --there's a group!
+
+ --self.Units[coa_name][countryName][category] = {}
+
+ for group_num, GroupTemplate in pairs(obj_type_data.group) do
+
+ if GroupTemplate and GroupTemplate.units and type(GroupTemplate.units) == 'table' then --making sure again- this is a valid group
+ self:_RegisterGroup( GroupTemplate )
+ end --if GroupTemplate and GroupTemplate.units then
+ end --for group_num, GroupTemplate in pairs(obj_type_data.group) do
+ end --if ((type(obj_type_data) == 'table') and obj_type_data.group and (type(obj_type_data.group) == 'table') and (#obj_type_data.group > 0)) then
+ end --if obj_type_name == "helicopter" or obj_type_name == "ship" or obj_type_name == "plane" or obj_type_name == "vehicle" or obj_type_name == "static" then
+ end --for obj_type_name, obj_type_data in pairs(cntry_data) do
+ end --if type(cntry_data) == 'table' then
+ end --for cntry_id, cntry_data in pairs(coa_data.country) do
+ end --if coa_data.country then --there is a country table
+ end --if coa_name == 'red' or coa_name == 'blue' and type(coa_data) == 'table' then
+ end --for coa_name, coa_data in pairs(mission.coalition) do
+
return self
end
+
+---
+-- @param #DATABASE self
+-- @param DCSUnit#Unit DCSUnit
+-- @return #DATABASE self
+function DATABASE:_IsIncludeDCSUnit( DCSUnit )
+ self:F( DCSUnit )
+ local DCSUnitInclude = true
+
+ if self.Filter.Coalitions then
+ local DCSUnitCoalition = false
+ for CoalitionID, CoalitionName in pairs( self.Filter.Coalitions ) do
+ self:T( { "Coalition:", DCSUnit:getCoalition(), self.FilterMeta.Coalitions[CoalitionName], CoalitionName } )
+ if self.FilterMeta.Coalitions[CoalitionName] and self.FilterMeta.Coalitions[CoalitionName] == DCSUnit:getCoalition() then
+ DCSUnitCoalition = true
+ end
+ end
+ DCSUnitInclude = DCSUnitInclude and DCSUnitCoalition
+ end
+
+ if self.Filter.Categories then
+ local DCSUnitCategory = false
+ for CategoryID, CategoryName in pairs( self.Filter.Categories ) do
+ self:T( { "Category:", DCSUnit:getDesc().category, self.FilterMeta.Categories[CategoryName], CategoryName } )
+ if self.FilterMeta.Categories[CategoryName] and self.FilterMeta.Categories[CategoryName] == DCSUnit:getDesc().category then
+ DCSUnitCategory = true
+ end
+ end
+ DCSUnitInclude = DCSUnitInclude and DCSUnitCategory
+ end
+
+ if self.Filter.Types then
+ local DCSUnitType = false
+ for TypeID, TypeName in pairs( self.Filter.Types ) do
+ self:T( { "Type:", DCSUnit:getTypeName(), TypeName } )
+ if TypeName == DCSUnit:getTypeName() then
+ DCSUnitType = true
+ end
+ end
+ DCSUnitInclude = DCSUnitInclude and DCSUnitType
+ end
+
+ if self.Filter.Countries then
+ local DCSUnitCountry = false
+ for CountryID, CountryName in pairs( self.Filter.Countries ) do
+ self:T( { "Country:", DCSUnit:getCountry(), CountryName } )
+ if country.id[CountryName] == DCSUnit:getCountry() then
+ DCSUnitCountry = true
+ end
+ end
+ DCSUnitInclude = DCSUnitInclude and DCSUnitCountry
+ end
+
+ if self.Filter.UnitPrefixes then
+ local DCSUnitPrefix = false
+ for UnitPrefixId, UnitPrefix in pairs( self.Filter.UnitPrefixes ) do
+ self:T( { "Unit Prefix:", string.find( DCSUnit:getName(), UnitPrefix, 1 ), UnitPrefix } )
+ if string.find( DCSUnit:getName(), UnitPrefix, 1 ) then
+ DCSUnitPrefix = true
+ end
+ end
+ DCSUnitInclude = DCSUnitInclude and DCSUnitPrefix
+ end
+
+ self:T( DCSUnitInclude )
+ return DCSUnitInclude
+end
+
+---
+-- @param #DATABASE self
+-- @param DCSUnit#Unit DCSUnit
+-- @return #DATABASE self
+function DATABASE:_IsAliveDCSUnit( DCSUnit )
+ self:F( DCSUnit )
+ local DCSUnitAlive = false
+ if DCSUnit and DCSUnit:isExist() and DCSUnit:isActive() then
+ if self.DCSUnits[DCSUnit:getName()] then
+ DCSUnitAlive = true
+ end
+ end
+ self:T( DCSUnitAlive )
+ return DCSUnitAlive
+end
+
+
--- Traces the current database contents in the log ... (for debug reasons).
-- @param #DATABASE self
-- @return #DATABASE self
diff --git a/Moose/Routines.lua b/Moose/Routines.lua
index f91e24e45..4f12b2222 100644
--- a/Moose/Routines.lua
+++ b/Moose/Routines.lua
@@ -449,14 +449,14 @@ end
do
-- THE MAIN FUNCTION -- Accessed 100 times/sec.
routines.main = function()
- timer.scheduleFunction(routines.main, {}, timer.getTime() + 0.1) --reschedule first in case of Lua error
+ timer.scheduleFunction(routines.main, {}, timer.getTime() + 2) --reschedule first in case of Lua error
----------------------------------------------------------------------------------------------------------
--area to add new stuff in
routines.do_scheduled_functions()
end -- end of routines.main
- timer.scheduleFunction(routines.main, {}, timer.getTime() + 0.1)
+ timer.scheduleFunction(routines.main, {}, timer.getTime() + 2)
end
diff --git a/Moose/Spawn.lua b/Moose/Spawn.lua
index 6049f554b..be92d9ea0 100644
--- a/Moose/Spawn.lua
+++ b/Moose/Spawn.lua
@@ -21,8 +21,8 @@
-- * It is important to defined BEFORE you spawn new groups, a proper initialization of the SPAWN instance is done with the options you want to use.
-- * When designing a mission, NEVER name groups using a "#" within the name of the group Spawn Template(s), or the SPAWN module logic won't work anymore.
--
--- 1. SPAWN object construction methods:
--- -------------------------------------
+-- SPAWN construction methods:
+-- ===========================
-- Create a new SPAWN object with the @{#SPAWN.New} or the @{#SPAWN.NewWithAlias} methods:
--
-- * @{#SPAWN.New}: Creates a new SPAWN object taking the name of the group that functions as the Template.
@@ -31,8 +31,8 @@
-- The initialization functions will modify this list of groups so that when a group gets spawned, ALL information is already prepared when spawning. This is done for performance reasons.
-- So in principle, the group list will contain all parameters and configurations after initialization, and when groups get actually spawned, this spawning can be done quickly and efficient.
--
--- 2. SPAWN object initialization methods:
--- ---------------------------------------
+-- SPAWN initialization methods:
+-- =============================
-- A spawn object will behave differently based on the usage of initialization methods:
--
-- * @{#SPAWN.Limit}: Limits the amount of groups that can be alive at the same time and that can be dynamically spawned.
@@ -42,8 +42,8 @@
-- * @{#SPAWN.Array}: Make groups visible before they are actually activated, and order these groups like a batallion in an array.
-- * @{#SPAWN.Repeat}: Re-spawn groups when they land at the home base. Similar functions are @{#SPAWN.RepeatOnLanding} and @{#SPAWN.RepeatOnEngineShutDown}.
--
--- 2. SPAWN object spawning methods:
--- ---------------------------------
+-- SPAWN spawning methods:
+-- =======================
-- Groups can be spawned at different times and methods:
--
-- * @{#SPAWN.Spawn}: Spawn one new group based on the last spawned index.
@@ -55,8 +55,8 @@
-- Note that @{#SPAWN.Spawn} and @{#SPAWN.ReSpawn} return a @{GROUP#GROUP.New} object, that contains a reference to the DCSGroup object.
-- You can use the @{GROUP} object to do further actions with the DCSGroup.
--
--- 3. SPAWN object cleaning:
--- -------------------------
+-- SPAWN object cleaning:
+-- =========================
-- Sometimes, it will occur during a mission run-time, that ground or especially air objects get damaged, and will while being damged stop their activities, while remaining alive.
-- In such cases, the SPAWN object will just sit there and wait until that group gets destroyed, but most of the time it won't,
-- and it may occur that no new groups are or can be spawned as limits are reached.
diff --git a/Moose/Zone.lua b/Moose/Zone.lua
index eb16cf63a..c1ef13b25 100644
--- a/Moose/Zone.lua
+++ b/Moose/Zone.lua
@@ -46,9 +46,10 @@ function ZONE:GetRandomPointVec2()
local Point = {}
local Zone = trigger.misc.getZone( self.ZoneName )
-
- Point.x = Zone.point.x + math.random( Zone.radius * -1, Zone.radius )
- Point.y = Zone.point.z + math.random( Zone.radius * -1, Zone.radius )
+
+ local angle = math.random() * math.pi*2;
+ Point.x = Zone.point.x + math.cos( angle ) * math.random() * Zone.radius;
+ Point.y = Zone.point.z + math.sin( angle ) * math.random() * Zone.radius;
self:T( { Zone, Point } )
diff --git a/Test Missions/Moose_Test_DATABASE/Moose_Test_DATABASE.lua b/Test Missions/Moose_Test_DATABASE/Moose_Test_DATABASE.lua
index eae574cdc..88f76d82a 100644
--- a/Test Missions/Moose_Test_DATABASE/Moose_Test_DATABASE.lua
+++ b/Test Missions/Moose_Test_DATABASE/Moose_Test_DATABASE.lua
@@ -2,21 +2,21 @@ Include.File( 'Database' )
Include.File( 'Spawn' )
DBBluePlanes = DATABASE:New()
- :FilterCoalition( "blue" )
- :FilterCategory( "plane" )
+ :FilterCoalitions( "blue" )
+ :FilterCategories( "plane" )
:FilterStart()
DBRedVehicles = DATABASE:New()
- :FilterCoalition( "red" )
- :FilterCategory( "ground" )
+ :FilterCoalitions( "red" )
+ :FilterCategories( "ground" )
:FilterStart()
DBShips = DATABASE:New()
- :FilterCategory( "ship" )
+ :FilterCategories( "ship" )
:FilterStart()
DBBelgium = DATABASE:New()
- :FilterCategory( "helicopter" )
+ :FilterCategories( "helicopter" )
:FilterCountries( "BELGIUM" )
:FilterStart()
@@ -25,7 +25,7 @@ DBNorthKorea = DATABASE:New()
:FilterStart()
DBKA50Vinson = DATABASE:New()
- :FilterType( { "Ka-50", "VINSON" } )
+ :FilterTypes( { "Ka-50", "VINSON" } )
:FilterStart()
DBBluePlanes:TraceDatabase()
@@ -51,6 +51,14 @@ GroupRU_Vehicle = SpawnRU_Vehicle:Spawn()
SpawnRU_Ship = SPAWN:New( 'Database Spawn Test RUSSIA Ship')
GroupRU_Ship = SpawnRU_Ship:Spawn()
+SpawnUS_AttackVehicle = SPAWN:New( 'Database Spawn Test USA Attack Vehicle' )
+SpawnRU_AttackVehicle = SPAWN:New( 'Database Spawn Test RUSSIA Attack Vehicle' )
+
+for i = 1, 10 do
+ GroupRU_AttackVehicle = SpawnRU_AttackVehicle:SpawnInZone( ZONE:New("Spawn Zone RU"), true)
+ GroupUS_AttackVehicle = SpawnUS_AttackVehicle:SpawnInZone( ZONE:New("Spawn Zone US"), true)
+end
+
--DBBlue:TraceDatabase()
routines.scheduleFunction( DBBluePlanes.TraceDatabase, { DBBluePlanes }, 1 )
diff --git a/Test Missions/Moose_Test_DATABASE/Moose_Test_DATABASE.miz b/Test Missions/Moose_Test_DATABASE/Moose_Test_DATABASE.miz
index 592177f6b..8942d4325 100644
Binary files a/Test Missions/Moose_Test_DATABASE/Moose_Test_DATABASE.miz and b/Test Missions/Moose_Test_DATABASE/Moose_Test_DATABASE.miz differ