mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Revised client and database logic. Still work in progress.
This commit is contained in:
parent
e71c02b885
commit
4d40f28cf8
122
Moose/Client.lua
122
Moose/Client.lua
@ -51,7 +51,7 @@ function CLIENT:New( ClientName, ClientBriefing )
|
|||||||
local self = BASE:Inherit( self, BASE:New() )
|
local self = BASE:Inherit( self, BASE:New() )
|
||||||
self:F( ClientName, ClientBriefing )
|
self:F( ClientName, ClientBriefing )
|
||||||
|
|
||||||
self.ClientName = ClientName
|
self.ClientName = ClientName
|
||||||
self:AddBriefing( ClientBriefing )
|
self:AddBriefing( ClientBriefing )
|
||||||
self.MessageSwitch = true
|
self.MessageSwitch = true
|
||||||
|
|
||||||
@ -132,9 +132,9 @@ end
|
|||||||
function CLIENT:IsAlive()
|
function CLIENT:IsAlive()
|
||||||
self:F( self.ClientName )
|
self:F( self.ClientName )
|
||||||
|
|
||||||
local ClientDCSGroup = self:GetDCSGroup()
|
local ClientUnit = Unit.getByName( self.ClientName )
|
||||||
|
|
||||||
if ClientDCSGroup then
|
if ClientUnit and ClientUnit:isExist() then
|
||||||
self:T("true")
|
self:T("true")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -176,6 +176,8 @@ function CLIENT:GetDCSGroup()
|
|||||||
-- return nil
|
-- return nil
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
|
local ClientUnit = Unit.getByName( self.ClientName )
|
||||||
|
|
||||||
local CoalitionsData = { AlivePlayersRed = coalition.getPlayers( coalition.side.RED ), AlivePlayersBlue = coalition.getPlayers( coalition.side.BLUE ) }
|
local CoalitionsData = { AlivePlayersRed = coalition.getPlayers( coalition.side.RED ), AlivePlayersBlue = coalition.getPlayers( coalition.side.BLUE ) }
|
||||||
for CoalitionId, CoalitionData in pairs( CoalitionsData ) do
|
for CoalitionId, CoalitionData in pairs( CoalitionsData ) do
|
||||||
self:T3( { "CoalitionData:", CoalitionData } )
|
self:T3( { "CoalitionData:", CoalitionData } )
|
||||||
@ -183,49 +185,49 @@ function CLIENT:GetDCSGroup()
|
|||||||
self:T3( { "UnitData:", UnitData } )
|
self:T3( { "UnitData:", UnitData } )
|
||||||
if UnitData and UnitData:isExist() then
|
if UnitData and UnitData:isExist() then
|
||||||
|
|
||||||
local ClientGroup = Group.getByName( self.ClientName )
|
--self:E(self.ClientName)
|
||||||
if ClientGroup then
|
if ClientUnit then
|
||||||
self:T3( "ClientGroup = " .. self.ClientName )
|
local ClientGroup = ClientUnit:getGroup()
|
||||||
if ClientGroup:isExist() then
|
if ClientGroup then
|
||||||
if ClientGroup:getID() == UnitData:getGroup():getID() then
|
self:T3( "ClientGroup = " .. self.ClientName )
|
||||||
self:T3( "Normal logic" )
|
if ClientGroup:isExist() then
|
||||||
self:T3( self.ClientName .. " : group found!" )
|
if ClientGroup:getID() == UnitData:getGroup():getID() then
|
||||||
return ClientGroup
|
self:T3( "Normal logic" )
|
||||||
end
|
self:T3( self.ClientName .. " : group found!" )
|
||||||
else
|
self.ClientGroupID = ClientGroup:getID()
|
||||||
-- Now we need to resolve the bugs in DCS 1.5 ...
|
self.ClientGroupName = ClientGroup:getName()
|
||||||
-- Consult the database for the units of the Client Group. (ClientGroup:getUnits() returns nil)
|
return ClientGroup
|
||||||
self:T3( "Bug 1.5 logic" )
|
end
|
||||||
local ClientUnits = _DATABASE.Templates.Groups[self.ClientName].Units
|
else
|
||||||
self:T3( { ClientUnits[1].name, env.getValueDictByKey(ClientUnits[1].name) } )
|
-- Now we need to resolve the bugs in DCS 1.5 ...
|
||||||
for ClientUnitID, ClientUnitData in pairs( ClientUnits ) do
|
-- Consult the database for the units of the Client Group. (ClientGroup:getUnits() returns nil)
|
||||||
self:T3( { tonumber(UnitData:getID()), ClientUnitData.unitId } )
|
self:T3( "Bug 1.5 logic" )
|
||||||
if tonumber(UnitData:getID()) == ClientUnitData.unitId then
|
local ClientGroupTemplate = _DATABASE.Templates.Units[self.ClientName].GroupTemplate
|
||||||
local ClientGroupTemplate = _DATABASE.Templates.Groups[self.ClientName].Template
|
self.ClientGroupID = ClientGroupTemplate.groupId
|
||||||
self.ClientID = ClientGroupTemplate.groupId
|
self.ClientGroupName = _DATABASE.Templates.Units[self.ClientName].GroupName
|
||||||
self.ClientGroupUnit = UnitData
|
self:T3( self.ClientName .. " : group found in bug 1.5 resolvement logic!" )
|
||||||
self:T3( self.ClientName .. " : group found in bug 1.5 resolvement logic!" )
|
return ClientGroup
|
||||||
return ClientGroup
|
end
|
||||||
end
|
-- else
|
||||||
end
|
-- error( "Client " .. self.ClientName .. " not found!" )
|
||||||
end
|
end
|
||||||
-- else
|
end
|
||||||
-- error( "Client " .. self.ClientName .. " not found!" )
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- For non player clients
|
-- For non player clients
|
||||||
local ClientGroup = Group.getByName( self.ClientName )
|
if ClientUnit then
|
||||||
if ClientGroup then
|
local ClientGroup = ClientUnit:getGroup()
|
||||||
self:T3( "ClientGroup = " .. self.ClientName )
|
if ClientGroup then
|
||||||
if ClientGroup:isExist() then
|
self:T3( "ClientGroup = " .. self.ClientName )
|
||||||
self:T3( "Normal logic" )
|
if ClientGroup:isExist() then
|
||||||
self:T3( self.ClientName .. " : group found!" )
|
self:T3( "Normal logic" )
|
||||||
return ClientGroup
|
self:T3( self.ClientName .. " : group found!" )
|
||||||
end
|
return ClientGroup
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
self.ClientGroupID = nil
|
self.ClientGroupID = nil
|
||||||
self.ClientGroupUnit = nil
|
self.ClientGroupUnit = nil
|
||||||
@ -242,14 +244,9 @@ function CLIENT:GetClientGroupID()
|
|||||||
|
|
||||||
if not self.ClientGroupID then
|
if not self.ClientGroupID then
|
||||||
local ClientGroup = self:GetDCSGroup()
|
local ClientGroup = self:GetDCSGroup()
|
||||||
if ClientGroup and ClientGroup:isExist() then
|
|
||||||
self.ClientGroupID = ClientGroup:getID()
|
|
||||||
else
|
|
||||||
self.ClientGroupID = self.ClientID
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self:T( self.ClientGroupID )
|
self:E( self.ClientGroupID ) -- Determined in GetDCSGroup()
|
||||||
return self.ClientGroupID
|
return self.ClientGroupID
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -261,14 +258,9 @@ function CLIENT:GetClientGroupName()
|
|||||||
|
|
||||||
if not self.ClientGroupName then
|
if not self.ClientGroupName then
|
||||||
local ClientGroup = self:GetDCSGroup()
|
local ClientGroup = self:GetDCSGroup()
|
||||||
if ClientGroup and ClientGroup:isExist() then
|
|
||||||
self.ClientGroupName = ClientGroup:getName()
|
|
||||||
else
|
|
||||||
self.ClientGroupName = self.ClientName
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self:T( self.ClientGroupName )
|
self:T( self.ClientGroupName ) -- Determined in GetDCSGroup()
|
||||||
return self.ClientGroupName
|
return self.ClientGroupName
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -276,14 +268,15 @@ end
|
|||||||
-- @param #CLIENT self
|
-- @param #CLIENT self
|
||||||
-- @return Unit#UNIT
|
-- @return Unit#UNIT
|
||||||
function CLIENT:GetClientGroupUnit()
|
function CLIENT:GetClientGroupUnit()
|
||||||
self:F()
|
self:F2()
|
||||||
|
|
||||||
local ClientGroup = self:GetDCSGroup()
|
local ClientDCSUnit = Unit.getByName( self.ClientName )
|
||||||
|
|
||||||
if ClientGroup and ClientGroup:isExist() then
|
self:T( self.ClientDCSUnit )
|
||||||
return UNIT:New( ClientGroup:getUnit(1) )
|
if ClientDCSUnit and ClientDCSUnit:isExist() then
|
||||||
else
|
local ClientUnit = _DATABASE.Units[ self.ClientName ]
|
||||||
return UNIT:New( self.ClientGroupUnit )
|
self:T2( ClientUnit )
|
||||||
|
return ClientUnit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -293,12 +286,11 @@ end
|
|||||||
function CLIENT:GetClientGroupDCSUnit()
|
function CLIENT:GetClientGroupDCSUnit()
|
||||||
self:F2()
|
self:F2()
|
||||||
|
|
||||||
local ClientGroup = self:GetDCSGroup()
|
local ClientDCSUnit = Unit.getByName( self.ClientName )
|
||||||
|
|
||||||
if ClientGroup and ClientGroup:isExist() then
|
if ClientDCSUnit and ClientDCSUnit:isExist() then
|
||||||
return ClientGroup:getUnit(1)
|
self:T2( ClientDCSUnit )
|
||||||
else
|
return ClientDCSUnit
|
||||||
return self.ClientGroupUnit
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -68,25 +68,33 @@ Include.File( "Menu" )
|
|||||||
Include.File( "Group" )
|
Include.File( "Group" )
|
||||||
Include.File( "Unit" )
|
Include.File( "Unit" )
|
||||||
Include.File( "Event" )
|
Include.File( "Event" )
|
||||||
|
Include.File( "Client" )
|
||||||
|
|
||||||
--- DATABASE class
|
--- DATABASE class
|
||||||
-- @type DATABASE
|
-- @type DATABASE
|
||||||
-- @extends Base#BASE
|
-- @extends Base#BASE
|
||||||
DATABASE = {
|
DATABASE = {
|
||||||
ClassName = "DATABASE",
|
ClassName = "DATABASE",
|
||||||
Templates = {},
|
Templates = {
|
||||||
|
Units = {},
|
||||||
|
Groups = {},
|
||||||
|
ClientsByName = {},
|
||||||
|
ClientsByID = {},
|
||||||
|
},
|
||||||
DCSUnits = {},
|
DCSUnits = {},
|
||||||
DCSUnitsAlive = {},
|
DCSUnitsAlive = {},
|
||||||
Units = {},
|
|
||||||
Groups = {},
|
|
||||||
DCSGroups = {},
|
DCSGroups = {},
|
||||||
DCSGroupsAlive = {},
|
DCSGroupsAlive = {},
|
||||||
|
Units = {},
|
||||||
|
UnitsAlive = {},
|
||||||
|
Groups = {},
|
||||||
|
GroupsAlive = {},
|
||||||
NavPoints = {},
|
NavPoints = {},
|
||||||
Statics = {},
|
Statics = {},
|
||||||
Players = {},
|
Players = {},
|
||||||
AlivePlayers = {},
|
PlayersAlive = {},
|
||||||
ClientsByName = {},
|
Clients = {},
|
||||||
ClientsByID = {},
|
ClientsAlive = {},
|
||||||
Filter = {
|
Filter = {
|
||||||
Coalitions = nil,
|
Coalitions = nil,
|
||||||
Categories = nil,
|
Categories = nil,
|
||||||
@ -142,6 +150,14 @@ function DATABASE:New()
|
|||||||
_EVENTDISPATCHER:OnDead( self._EventOnDeadOrCrash, self )
|
_EVENTDISPATCHER:OnDead( self._EventOnDeadOrCrash, self )
|
||||||
_EVENTDISPATCHER:OnCrash( self._EventOnDeadOrCrash, self )
|
_EVENTDISPATCHER:OnCrash( self._EventOnDeadOrCrash, self )
|
||||||
|
|
||||||
|
|
||||||
|
-- Add database with registered clients and already alive players
|
||||||
|
|
||||||
|
-- Follow alive players and clients
|
||||||
|
_EVENTDISPATCHER:OnPlayerEnterUnit( self._EventOnPlayerEnterUnit, self )
|
||||||
|
_EVENTDISPATCHER:OnPlayerLeaveUnit( self._EventOnPlayerLeaveUnit, self )
|
||||||
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -262,16 +278,43 @@ function DATABASE:FilterStart()
|
|||||||
-- OK, we have a _DATABASE
|
-- OK, we have a _DATABASE
|
||||||
-- Now use the different filters to build the set.
|
-- Now use the different filters to build the set.
|
||||||
-- We first take ALL of the Units of the _DATABASE.
|
-- We first take ALL of the Units of the _DATABASE.
|
||||||
for UnitRegistrationID, UnitRegistration in pairs( _DATABASE.Templates.Units ) do
|
|
||||||
self:T( UnitRegistration )
|
self:E( { "Adding Database Datapoints with filters" } )
|
||||||
local DCSUnit = Unit.getByName( UnitRegistration.UnitName )
|
for DCSUnitName, DCSUnit in pairs( _DATABASE.DCSUnits ) do
|
||||||
|
|
||||||
if self:_IsIncludeDCSUnit( DCSUnit ) then
|
if self:_IsIncludeDCSUnit( DCSUnit ) then
|
||||||
self.DCSUnits[DCSUnit:getName()] = DCSUnit
|
|
||||||
end
|
self:E( { "Adding Unit:", DCSUnitName } )
|
||||||
if self:_IsAliveDCSUnit( DCSUnit ) then
|
self.DCSUnits[DCSUnitName] = _DATABASE.DCSUnits[DCSUnitName]
|
||||||
self.DCSUnitsAlive[DCSUnit:getName()] = DCSUnit
|
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
|
||||||
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
|
else
|
||||||
self:E( "There is a structural error in MOOSE. No _DATABASE has been defined! Cannot build this custom DATABASE." )
|
self:E( "There is a structural error in MOOSE. No _DATABASE has been defined! Cannot build this custom DATABASE." )
|
||||||
end
|
end
|
||||||
@ -378,6 +421,77 @@ function DATABASE:_RegisterGroup( GroupTemplate )
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Private method that registers all alive players in the mission.
|
||||||
|
-- @param #DATABASE self
|
||||||
|
-- @return #DATABASE self
|
||||||
|
function DATABASE:_RegisterPlayers()
|
||||||
|
|
||||||
|
local CoalitionsData = { AlivePlayersRed = coalition.getPlayers( coalition.side.RED ), AlivePlayersBlue = coalition.getPlayers( coalition.side.BLUE ) }
|
||||||
|
for CoalitionId, CoalitionData in pairs( CoalitionsData ) do
|
||||||
|
for UnitId, UnitData in pairs( CoalitionData ) do
|
||||||
|
self:T3( { "UnitData:", UnitData } )
|
||||||
|
if UnitData and UnitData:isExist() then
|
||||||
|
local UnitName = UnitData:getName()
|
||||||
|
if not self.PlayersAlive[UnitName] then
|
||||||
|
self:E( { "Add player for unit:", UnitName, UnitData:getPlayerName() } )
|
||||||
|
self.PlayersAlive[UnitName] = UnitData:getPlayerName()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Private method that registers all datapoints within in the mission.
|
||||||
|
-- @param #DATABASE self
|
||||||
|
-- @return #DATABASE self
|
||||||
|
function DATABASE:_RegisterDatabase()
|
||||||
|
|
||||||
|
local CoalitionsData = { AlivePlayersRed = coalition.getGroups( coalition.side.RED ), AlivePlayersBlue = coalition.getGroups( coalition.side.BLUE ) }
|
||||||
|
for CoalitionId, CoalitionData in pairs( CoalitionsData ) do
|
||||||
|
for DCSGroupId, DCSGroup in pairs( CoalitionData ) do
|
||||||
|
|
||||||
|
local DCSGroupName = DCSGroup:getName()
|
||||||
|
|
||||||
|
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.Units[DCSUnitName] = UNIT:New( DCSUnit )
|
||||||
|
|
||||||
|
if self:_IsAliveDCSUnit(DCSUnit) then
|
||||||
|
self:E( { "Register Alive Unit:", DCSUnit, DCSUnitName } )
|
||||||
|
self.DCSUnitsAlive[DCSUnitName] = DCSUnit
|
||||||
|
self.UnitsAlive[DCSUnitName] = self.Units[DCSUnitName]
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.Templates.ClientsByName[DCSUnitName] then
|
||||||
|
self.Clients[DCSUnitName] = CLIENT:New( DCSUnitName )
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Events
|
||||||
|
|
||||||
--- Handles the OnBirth event for the alive units set.
|
--- Handles the OnBirth event for the alive units set.
|
||||||
-- @param #DATABASE self
|
-- @param #DATABASE self
|
||||||
-- @param Event#EVENTDATA Event
|
-- @param Event#EVENTDATA Event
|
||||||
@ -388,6 +502,13 @@ function DATABASE:_EventOnBirth( Event )
|
|||||||
if self:_IsIncludeDCSUnit( Event.IniDCSUnit ) then
|
if self:_IsIncludeDCSUnit( Event.IniDCSUnit ) then
|
||||||
self.DCSUnits[Event.IniDCSUnitName] = Event.IniDCSUnit
|
self.DCSUnits[Event.IniDCSUnitName] = Event.IniDCSUnit
|
||||||
self.DCSUnitsAlive[Event.IniDCSUnitName] = Event.IniDCSUnit
|
self.DCSUnitsAlive[Event.IniDCSUnitName] = Event.IniDCSUnit
|
||||||
|
self.Units[Event.IniDCSUnitName] = UNIT:New( Event.IniDCSUnit )
|
||||||
|
|
||||||
|
if not self.DCSGroups[Event.IniDCSGroupName] then
|
||||||
|
self.DCSGroups[Event.IniDCSGroupName] = Event.IniDCSGroupName
|
||||||
|
self.DCSGroupsAlive[Event.IniDCSGroupName] = Event.IniDCSGroupName
|
||||||
|
self.Groups[Event.IniDCSGroupName] = GROUP:New( Event.IniDCSGroup )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -406,18 +527,54 @@ function DATABASE:_EventOnDeadOrCrash( Event )
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Interate the DATABASE and call an interator function for each **alive** unit, providing the Unit and optional parameters.
|
--- Handles the OnPlayerEnterUnit event to fill the active players table (with the unit filter applied).
|
||||||
-- @param #DATABASE self
|
-- @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.
|
-- @param Event#EVENTDATA Event
|
||||||
|
function DATABASE:_EventOnPlayerEnterUnit( Event )
|
||||||
|
self:F( { Event } )
|
||||||
|
|
||||||
|
if Event.IniDCSUnit then
|
||||||
|
if self:_IsIncludeDCSUnit( Event.IniDCSUnit ) then
|
||||||
|
if not self.PlayersAlive[Event.IniDCSUnitName] then
|
||||||
|
self:E( { "Add player for unit:", Event.IniDCSUnitName, Event.IniDCSUnit:getPlayerName() } )
|
||||||
|
self.PlayersAlive[Event.IniDCSUnitName] = Event.IniDCSUnit:getPlayerName()
|
||||||
|
self.ClientsAlive[Event.IniDCSUnitName] = _DATABASE.Clients[ Event.IniDCSUnitName ]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Handles the OnPlayerLeaveUnit event to clean the active players table.
|
||||||
|
-- @param #DATABASE self
|
||||||
|
-- @param Event#EVENTDATA Event
|
||||||
|
function DATABASE:_EventOnPlayerLeaveUnit( Event )
|
||||||
|
self:F( { Event } )
|
||||||
|
|
||||||
|
if Event.IniDCSUnit then
|
||||||
|
if self:_IsIncludeDCSUnit( Event.IniDCSUnit ) then
|
||||||
|
if self.PlayersAlive[Event.IniDCSUnitName] then
|
||||||
|
self:E( { "Cleaning player for unit:", Event.IniDCSUnitName, Event.IniDCSUnit:getPlayerName() } )
|
||||||
|
self.PlayersAlive[Event.IniDCSUnitName] = nil
|
||||||
|
self.ClientsAlive[Event.IniDCSUnitName] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Iterators
|
||||||
|
|
||||||
|
--- Interate the DATABASE and call an interator function for the given set, providing the Object for each element within the set and optional parameters.
|
||||||
|
-- @param #DATABASE self
|
||||||
|
-- @param #function IteratorFunction The function that will be called when there is an alive player in the database.
|
||||||
-- @return #DATABASE self
|
-- @return #DATABASE self
|
||||||
function DATABASE:ForEachAliveUnit( IteratorFunction, ... )
|
function DATABASE:ForEach( IteratorFunction, arg, Set )
|
||||||
self:F( arg )
|
self:F( arg )
|
||||||
|
|
||||||
local function CoRoutine()
|
local function CoRoutine()
|
||||||
local Count = 0
|
local Count = 0
|
||||||
for DCSUnitID, DCSUnit in pairs( self.DCSUnitsAlive ) do
|
for ObjectID, Object in pairs( Set ) do
|
||||||
self:T2( DCSUnit )
|
self:T2( Object )
|
||||||
IteratorFunction( DCSUnit, unpack( arg ) )
|
IteratorFunction( Object, unpack( arg ) )
|
||||||
Count = Count + 1
|
Count = Count + 1
|
||||||
if Count % 10 == 0 then
|
if Count % 10 == 0 then
|
||||||
coroutine.yield( false )
|
coroutine.yield( false )
|
||||||
@ -437,15 +594,56 @@ function DATABASE:ForEachAliveUnit( IteratorFunction, ... )
|
|||||||
error( res )
|
error( res )
|
||||||
end
|
end
|
||||||
if res == false then
|
if res == false then
|
||||||
timer.scheduleFunction( Schedule, {}, timer.getTime() + 0.001 )
|
return true -- resume next time the loop
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
timer.scheduleFunction( Schedule, {}, timer.getTime() + 0.001 )
|
local Scheduler = SCHEDULER:New( self, Schedule, {}, 0.001, 0.001, 0 )
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Interate the DATABASE and call an interator function for each **alive** 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:ForEachDCSUnitAlive( IteratorFunction, ... )
|
||||||
|
self:F( arg )
|
||||||
|
|
||||||
|
self:ForEach( IteratorFunction, arg, self.DCSUnitsAlive )
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Interate the DATABASE and call an interator function for each **alive** player, 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.
|
||||||
|
-- @return #DATABASE self
|
||||||
|
function DATABASE:ForEachPlayer( IteratorFunction, ... )
|
||||||
|
self:F( arg )
|
||||||
|
|
||||||
|
self:ForEach( IteratorFunction, arg, self.PlayersAlive )
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Interate the DATABASE and call an interator function for each 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 player in the database. The function needs to accept a CLIENT parameter.
|
||||||
|
-- @return #DATABASE self
|
||||||
|
function DATABASE:ForEachClient( IteratorFunction, ... )
|
||||||
|
self:F( arg )
|
||||||
|
|
||||||
|
self:ForEach( IteratorFunction, arg, self.Clients )
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function DATABASE:ScanEnvironment()
|
function DATABASE:ScanEnvironment()
|
||||||
self:F()
|
self:F()
|
||||||
|
|
||||||
@ -509,6 +707,9 @@ function DATABASE:ScanEnvironment()
|
|||||||
end --if coa_name == 'red' or coa_name == 'blue' and type(coa_data) == 'table' then
|
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
|
end --for coa_name, coa_data in pairs(mission.coalition) do
|
||||||
|
|
||||||
|
self:_RegisterDatabase()
|
||||||
|
self:_RegisterPlayers()
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -596,6 +797,22 @@ function DATABASE:_IsAliveDCSUnit( DCSUnit )
|
|||||||
return DCSUnitAlive
|
return DCSUnitAlive
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---
|
||||||
|
-- @param #DATABASE self
|
||||||
|
-- @param DCSGroup#Group DCSGroup
|
||||||
|
-- @return #DATABASE self
|
||||||
|
function DATABASE:_IsAliveDCSGroup( DCSGroup )
|
||||||
|
self:F( DCSGroup )
|
||||||
|
local DCSGroupAlive = false
|
||||||
|
if DCSGroup and DCSGroup:isExist() then
|
||||||
|
if self.DCSGroups[DCSGroup:getName()] then
|
||||||
|
DCSGroupAlive = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self:T( DCSGroupAlive )
|
||||||
|
return DCSGroupAlive
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Traces the current database contents in the log ... (for debug reasons).
|
--- Traces the current database contents in the log ... (for debug reasons).
|
||||||
-- @param #DATABASE self
|
-- @param #DATABASE self
|
||||||
|
|||||||
@ -437,6 +437,32 @@ function EVENT:OnHitForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Set a new listener for an S_EVENT_PLAYER_ENTER_UNIT event.
|
||||||
|
-- @param #EVENT self
|
||||||
|
-- @param #function EventFunction The function to be called when the event occurs for the unit.
|
||||||
|
-- @param Base#BASE EventSelf The self instance of the class for which the event is.
|
||||||
|
-- @return #EVENT
|
||||||
|
function EVENT:OnPlayerEnterUnit( EventFunction, EventSelf )
|
||||||
|
self:F()
|
||||||
|
|
||||||
|
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_PLAYER_ENTER_UNIT )
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Set a new listener for an S_EVENT_PLAYER_LEAVE_UNIT event.
|
||||||
|
-- @param #EVENT self
|
||||||
|
-- @param #function EventFunction The function to be called when the event occurs for the unit.
|
||||||
|
-- @param Base#BASE EventSelf The self instance of the class for which the event is.
|
||||||
|
-- @return #EVENT
|
||||||
|
function EVENT:OnPlayerLeaveUnit( EventFunction, EventSelf )
|
||||||
|
self:F()
|
||||||
|
|
||||||
|
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_PLAYER_LEAVE_UNIT )
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function EVENT:onEvent( Event )
|
function EVENT:onEvent( Event )
|
||||||
@ -468,6 +494,7 @@ function EVENT:onEvent( Event )
|
|||||||
Event.WeaponName = Event.Weapon:getTypeName()
|
Event.WeaponName = Event.Weapon:getTypeName()
|
||||||
--Event.WeaponTgtDCSUnit = Event.Weapon:getTarget()
|
--Event.WeaponTgtDCSUnit = Event.Weapon:getTarget()
|
||||||
end
|
end
|
||||||
|
self:E( { _EVENTCODES[Event.id], Event } )
|
||||||
for ClassName, EventData in pairs( self.Events[Event.id] ) do
|
for ClassName, EventData in pairs( self.Events[Event.id] ) do
|
||||||
if Event.IniDCSUnitName and EventData.IniUnit and EventData.IniUnit[Event.IniDCSUnitName] then
|
if Event.IniDCSUnitName and EventData.IniUnit and EventData.IniUnit[Event.IniDCSUnitName] then
|
||||||
self:T2( { "Calling event function for class ", ClassName, " unit ", Event.IniDCSUnitName } )
|
self:T2( { "Calling event function for class ", ClassName, " unit ", Event.IniDCSUnitName } )
|
||||||
|
|||||||
@ -28,9 +28,34 @@ function MISSILETRAINER:New( Distance )
|
|||||||
|
|
||||||
_EVENTDISPATCHER:OnShot( self._EventShot, self )
|
_EVENTDISPATCHER:OnShot( self._EventShot, self )
|
||||||
|
|
||||||
|
self.DB = DATABASE:New():FilterStart()
|
||||||
|
self.DBClients = self.DB.Clients
|
||||||
|
self.DBUnits = self.DB.Units
|
||||||
|
|
||||||
|
self.DB:ForEachClient(
|
||||||
|
--- @param Client#CLIENT Client
|
||||||
|
function( Client )
|
||||||
|
Client:Message( "Welcome to the Missile Trainer", 10, "ID", "TEST" )
|
||||||
|
--Client.MainMenu = MENU_CLIENT:New( Client, "Missile Trainer", nil )
|
||||||
|
--Client.MenuOnOff = MENU_CLIENT:New( Client, "On/Off", Client.MainMenu )
|
||||||
|
--Client.MenuOn = MENU_CLIENT_COMMAND:New( Client, "Messages On", Client.MenuOnOff, MISSILETRAINER._MenuMessages, { MenuSelf = self, MessagesOnOff = true } )
|
||||||
|
--Client.MenuOff = MENU_CLIENT_COMMAND:New( Client, "Messages Off", Client.MenuOnOff, MISSILETRAINER._MenuMessages, { MenuSelf = self, MessagesOnOff = false } )
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
|
self.DisplayMessages = true
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function MISSILETRAINER._MenuMessages( MenuParameters )
|
||||||
|
|
||||||
|
local self = MenuParameters.MenuSelf
|
||||||
|
local MessagesOnOff = MenuParameters.MessagesOnOff
|
||||||
|
|
||||||
|
self.DisplayMessages = MessagesOnOff
|
||||||
|
end
|
||||||
|
|
||||||
--- Detects if an SA site was shot with an anti radiation missile. In this case, take evasive actions based on the skill level set within the ME.
|
--- Detects if an SA site was shot with an anti radiation missile. In this case, take evasive actions based on the skill level set within the ME.
|
||||||
-- @see MISSILETRAINER
|
-- @see MISSILETRAINER
|
||||||
function MISSILETRAINER:_EventShot( Event )
|
function MISSILETRAINER:_EventShot( Event )
|
||||||
@ -51,17 +76,23 @@ function MISSILETRAINER:_EventShot( Event )
|
|||||||
|
|
||||||
self:T( TrainerTargetSkill )
|
self:T( TrainerTargetSkill )
|
||||||
|
|
||||||
if TrainerTargetSkill == "Client" or TrainerTargetSkill == "Player" then
|
local Client = self.DBClients[TrainerTargetDCSUnitName]
|
||||||
self.Schedulers[#self.Schedulers+1] = SCHEDULER:New( self, self._FollowMissile, { TrainerSourceDCSUnit, TrainerWeapon, TrainerTargetDCSUnit }, 0.5, 0.05, 0 )
|
if Client then
|
||||||
|
local TrainerSourceUnit = UNIT:New(TrainerSourceDCSUnit)
|
||||||
|
local TrainerTargetUnit = UNIT:New(TrainerTargetDCSUnit)
|
||||||
|
self.Schedulers[#self.Schedulers+1] = SCHEDULER:New( self, self._FollowMissile, { TrainerSourceUnit, TrainerWeapon, TrainerTargetUnit, Client }, 0.5, 0.05, 0 )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function MISSILETRAINER:_FollowMissile( TrainerSourceDCSUnit, TrainerWeapon, TrainerTargetDCSUnit )
|
---
|
||||||
self:F( { TrainerSourceDCSUnit, TrainerWeapon, TrainerTargetDCSUnit } )
|
-- @param #MISSILETRAINER self
|
||||||
|
-- @param DCSUnit#Unit TrainerSourceDCSUnit
|
||||||
|
-- @param DCSWeapon#Weapon TrainerWeapon
|
||||||
|
-- @param DCSUnit#Unit TrainerTargetDCSUnit
|
||||||
|
-- @param Client#CLIENT Client
|
||||||
|
function MISSILETRAINER:_FollowMissile( TrainerSourceUnit, TrainerWeapon, TrainerTargetUnit, Client )
|
||||||
|
self:F( { TrainerSourceUnit, TrainerWeapon, TrainerTargetUnit, Client } )
|
||||||
|
|
||||||
local TrainerSourceUnit = UNIT:New( TrainerSourceDCSUnit )
|
|
||||||
local TrainerTargetUnit = UNIT:New( TrainerTargetDCSUnit )
|
|
||||||
|
|
||||||
local PositionMissile = TrainerWeapon:getPoint()
|
local PositionMissile = TrainerWeapon:getPoint()
|
||||||
local PositionTarget = TrainerTargetUnit:GetPositionVec3()
|
local PositionTarget = TrainerTargetUnit:GetPositionVec3()
|
||||||
|
|
||||||
@ -70,11 +101,17 @@ function MISSILETRAINER:_FollowMissile( TrainerSourceDCSUnit, TrainerWeapon, Tra
|
|||||||
( PositionMissile.z - PositionTarget.z )^2
|
( PositionMissile.z - PositionTarget.z )^2
|
||||||
) ^ 0.5
|
) ^ 0.5
|
||||||
|
|
||||||
MESSAGE:New( "Distance Missle = " .. Distance, nil, 0.2, "/Missile" ):ToAll()
|
if self.DisplayMessages then
|
||||||
|
self:T( Distance )
|
||||||
|
MESSAGE:New( "Distance Missile = " .. Distance, "TEST", 0.2, "ID" ):ToAll()
|
||||||
|
end
|
||||||
|
|
||||||
if Distance <= self.Distance then
|
if Distance <= self.Distance then
|
||||||
TrainerWeapon:destroy()
|
TrainerWeapon:destroy()
|
||||||
MESSAGE:New( "Missle Destroyed", nil, 5, "/Missile" ):ToAll()
|
if self.DisplayMessages then
|
||||||
|
self:T( "Destroyed" )
|
||||||
|
MESSAGE:New( "Missile Destroyed", "TEST", 5, "ID" ):ToAll()
|
||||||
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user