This commit is contained in:
Sven Van de Velde
2016-05-22 10:30:22 +02:00
parent 7e375c4895
commit b78187aaff
11 changed files with 940 additions and 464 deletions

View File

@@ -82,13 +82,9 @@ DATABASE = {
ClientsByID = {},
},
DCSUnits = {},
DCSUnitsAlive = {},
DCSGroups = {},
DCSGroupsAlive = {},
Units = {},
UnitsAlive = {},
Groups = {},
GroupsAlive = {},
NavPoints = {},
Statics = {},
Players = {},
@@ -171,180 +167,38 @@ function DATABASE:FindUnit( UnitName )
return UnitFound
end
--- Finds a Unit based on the Unit Name.
--- Adds a Unit based on the Unit Name in the DATABASE.
-- @param #DATABASE self
-- @param Unit#UNIT UnitToAdd
-- @return Unit#UNIT The added Unit.
function DATABASE:AddUnit( UnitToAdd )
function DATABASE:AddUnit( DCSUnit, DCSUnitName )
self.Units[UnitToAdd.UnitName] = UnitToAdd
return self.Units[UnitToAdd.UnitName]
self.DCSUnits[DCSUnitName] = DCSUnit
self.Units[DCSUnitName] = UNIT:Register( DCSUnitName )
end
--- Builds a set of units of coalitons.
-- Possible current coalitions are red, blue and neutral.
--- Deletes a Unit from the DATABASE based on the Unit Name.
-- @param #DATABASE self
-- @param #string Coalitions Can take the following values: "red", "blue", "neutral".
-- @return #DATABASE self
function DATABASE:FilterCoalitions( Coalitions )
if not self.Filter.Coalitions then
self.Filter.Coalitions = {}
end
if type( Coalitions ) ~= "table" then
Coalitions = { Coalitions }
end
for CoalitionID, Coalition in pairs( Coalitions ) do
self.Filter.Coalitions[Coalition] = Coalition
end
return self
function DATABASE:DeleteUnit( DCSUnitName )
self.DCSUnits[DCSUnitName] = nil
end
--- Builds a set of units out of categories.
-- Possible current categories are plane, helicopter, ground, ship.
--- Finds a CLIENT based on the ClientName.
-- @param #DATABASE self
-- @param #string Categories Can take the following values: "plane", "helicopter", "ground", "ship".
-- @return #DATABASE self
function DATABASE:FilterCategories( Categories )
if not self.Filter.Categories then
self.Filter.Categories = {}
end
if type( Categories ) ~= "table" then
Categories = { Categories }
end
for CategoryID, Category in pairs( Categories ) do
self.Filter.Categories[Category] = Category
end
return self
-- @param #string ClientName
-- @return Client#CLIENT The found CLIENT.
function DATABASE:FindClient( ClientName )
local ClientFound = self.Clients[ClientName]
return ClientFound
end
--- Builds a set of units of defined unit types.
-- Possible current types are those types known within DCS world.
--- Adds a CLIENT based on the ClientName in the DATABASE.
-- @param #DATABASE self
-- @param #string Types Can take those type strings known within DCS world.
-- @return #DATABASE self
function DATABASE:FilterTypes( Types )
if not self.Filter.Types then
self.Filter.Types = {}
end
if type( Types ) ~= "table" then
Types = { Types }
end
for TypeID, Type in pairs( Types ) do
self.Filter.Types[Type] = Type
end
return self
function DATABASE:AddClient( ClientName )
self.Clients[ClientName] = CLIENT:Register( ClientName )
end
--- Builds a set of units of defined countries.
-- Possible current countries are those known within DCS world.
-- @param #DATABASE self
-- @param #string Countries Can take those country strings known within DCS world.
-- @return #DATABASE self
function DATABASE:FilterCountries( Countries )
if not self.Filter.Countries then
self.Filter.Countries = {}
end
if type( Countries ) ~= "table" then
Countries = { Countries }
end
for CountryID, Country in pairs( Countries ) do
self.Filter.Countries[Country] = Country
end
return self
end
--- Builds a set of units of defined unit prefixes.
-- All the units starting with the given prefixes will be included within the set.
-- @param #DATABASE self
-- @param #string Prefixes The prefix of which the unit name starts with.
-- @return #DATABASE self
function DATABASE:FilterUnitPrefixes( Prefixes )
if not self.Filter.UnitPrefixes then
self.Filter.UnitPrefixes = {}
end
if type( Prefixes ) ~= "table" then
Prefixes = { Prefixes }
end
for PrefixID, Prefix in pairs( Prefixes ) do
self.Filter.UnitPrefixes[Prefix] = Prefix
end
return self
end
--- Builds a set of units of defined group prefixes.
-- All the units starting with the given group prefixes will be included within the set.
-- @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:FilterGroupPrefixes( Prefixes )
if not self.Filter.GroupPrefixes then
self.Filter.GroupPrefixes = {}
end
if type( Prefixes ) ~= "table" then
Prefixes = { Prefixes }
end
for PrefixID, Prefix in pairs( Prefixes ) do
self.Filter.GroupPrefixes[Prefix] = Prefix
end
return self
end
--- Starts the filtering.
-- @param #DATABASE self
-- @return #DATABASE self
function DATABASE:FilterStart()
if _DATABASE then
-- OK, we have a _DATABASE
-- Now use the different filters to build the set.
-- We first take ALL of the Units of the _DATABASE.
self:E( { "Adding Database Datapoints with filters" } )
for DCSUnitName, DCSUnit in pairs( _DATABASE.DCSUnits ) do
if self:_IsIncludeDCSUnit( DCSUnit ) then
self:E( { "Adding Unit:", DCSUnitName } )
self.DCSUnits[DCSUnitName] = _DATABASE.DCSUnits[DCSUnitName]
self.Units[DCSUnitName] = _DATABASE.Units[DCSUnitName]
if _DATABASE.DCSUnitsAlive[DCSUnitName] then
self.DCSUnitsAlive[DCSUnitName] = _DATABASE.DCSUnitsAlive[DCSUnitName]
self.UnitsAlive[DCSUnitName] = _DATABASE.UnitsAlive[DCSUnitName]
end
end
end
for DCSGroupName, DCSGroup in pairs( _DATABASE.DCSGroups ) do
--if self:_IsIncludeDCSGroup( DCSGroup ) then
self:E( { "Adding Group:", DCSGroupName } )
self.DCSGroups[DCSGroupName] = _DATABASE.DCSGroups[DCSGroupName]
self.Groups[DCSGroupName] = _DATABASE.Groups[DCSGroupName]
--end
if _DATABASE.DCSGroupsAlive[DCSGroupName] then
self.DCSGroupsAlive[DCSGroupName] = _DATABASE.DCSGroupsAlive[DCSGroupName]
self.GroupsAlive[DCSGroupName] = _DATABASE.GroupsAlive[DCSGroupName]
end
end
for DCSUnitName, Client in pairs( _DATABASE.Clients ) do
self:E( { "Adding Client for Unit:", DCSUnitName } )
self.Clients[DCSUnitName] = _DATABASE.Clients[DCSUnitName]
end
else
self:E( "There is a structural error in MOOSE. No _DATABASE has been defined! Cannot build this custom DATABASE." )
end
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:
-- SpawnCountryID, SpawnCategoryID
@@ -471,7 +325,7 @@ end
-- @return #DATABASE self
function DATABASE:_RegisterDatabase()
local CoalitionsData = { AlivePlayersRed = coalition.getGroups( coalition.side.RED ), AlivePlayersBlue = coalition.getGroups( coalition.side.BLUE ) }
local CoalitionsData = { GroupsRed = coalition.getGroups( coalition.side.RED ), GroupsBlue = coalition.getGroups( coalition.side.BLUE ) }
for CoalitionId, CoalitionData in pairs( CoalitionsData ) do
for DCSGroupId, DCSGroup in pairs( CoalitionData ) do
@@ -481,42 +335,28 @@ function DATABASE:_RegisterDatabase()
self:E( { "Register Group:", DCSGroup, DCSGroupName } )
self.DCSGroups[DCSGroupName] = DCSGroup
self.Groups[DCSGroupName] = GROUP:New( DCSGroup )
if self:_IsAliveDCSGroup(DCSGroup) then
self:E( { "Register Alive Group:", DCSGroup, DCSGroupName } )
self.DCSGroupsAlive[DCSGroupName] = DCSGroup
self.GroupsAlive[DCSGroupName] = self.Groups[DCSGroupName]
end
for DCSUnitId, DCSUnit in pairs( DCSGroup:getUnits() ) do
local DCSUnitName = DCSUnit:getName()
self:E( { "Register Unit:", DCSUnit, DCSUnitName } )
self.DCSUnits[DCSUnitName] = DCSUnit
self:AddUnit( UNIT:Register( DCSUnit ) )
--self.Units[DCSUnitName] = UNIT:Register( DCSUnit )
if self:_IsAliveDCSUnit(DCSUnit) then
self:E( { "Register Alive Unit:", DCSUnit, DCSUnitName } )
self.DCSUnitsAlive[DCSUnitName] = DCSUnit
self.UnitsAlive[DCSUnitName] = self.Units[DCSUnitName]
end
self:AddUnit( DCSUnit, DCSUnitName )
end
else
self:E( "Group does not exist: " .. DCSGroup )
self:E( { "Group does not exist: ", DCSGroup } )
end
for ClientName, ClientTemplate in pairs( self.Templates.ClientsByName ) do
self.Clients[ClientName] = CLIENT:New( ClientName )
end
end
end
for ClientName, ClientTemplate in pairs( self.Templates.ClientsByName ) do
self:E( { "Adding Client:", ClientName } )
self:AddClient( ClientName )
end
return self
end
--- Events
--- Handles the OnBirth event for the alive units set.
@@ -527,11 +367,8 @@ function DATABASE:_EventOnBirth( Event )
if Event.IniDCSUnit then
if self:_IsIncludeDCSUnit( Event.IniDCSUnit ) then
self.DCSUnits[Event.IniDCSUnitName] = Event.IniDCSUnit
self.DCSUnitsAlive[Event.IniDCSUnitName] = Event.IniDCSUnit
self:AddUnit( UNIT:Register( Event.IniDCSUnit ) )
--self.Units[Event.IniDCSUnitName] = UNIT:Register( Event.IniDCSUnit )
self:AddUnit( Event.IniDCSUnit, Event.IniDCSUnitName )
--if not self.DCSGroups[Event.IniDCSGroupName] then
-- self.DCSGroups[Event.IniDCSGroupName] = Event.IniDCSGroupName
-- self.DCSGroupsAlive[Event.IniDCSGroupName] = Event.IniDCSGroupName
@@ -549,9 +386,8 @@ function DATABASE:_EventOnDeadOrCrash( Event )
self:F( { Event } )
if Event.IniDCSUnit then
if self.DCSUnitsAlive[Event.IniDCSUnitName] then
self.DCSUnits[Event.IniDCSUnitName] = nil
self.DCSUnitsAlive[Event.IniDCSUnitName] = nil
if self.DCSUnits[Event.IniDCSUnitName] then
self:DeleteUnit( Event.IniDCSUnitName )
end
end
end
@@ -639,10 +475,10 @@ end
-- @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:ForEachDCSUnitAlive( IteratorFunction, ... )
function DATABASE:ForEachDCSUnit( IteratorFunction, ... )
self:F( arg )
self:ForEach( IteratorFunction, arg, self.DCSUnitsAlive )
self:ForEach( IteratorFunction, arg, self.DCSUnits )
return self
end
@@ -850,7 +686,6 @@ function DATABASE:TraceDatabase()
self:F()
self:T( { "DCSUnits:", self.DCSUnits } )
self:T( { "DCSUnitsAlive:", self.DCSUnitsAlive } )
end