This commit is contained in:
Frank
2021-01-02 01:21:45 +01:00
parent c0fc649f8b
commit 7b7605e501
2 changed files with 65 additions and 45 deletions

View File

@@ -3,8 +3,7 @@
-- === -- ===
-- --
-- ### Author: **FlightControl** -- ### Author: **FlightControl**
-- -- ### Contributions: **funkyfranky**
-- ### Contributions:
-- --
-- === -- ===
-- --
@@ -52,13 +51,6 @@
-- --
-- @field #CLIENT -- @field #CLIENT
CLIENT = { CLIENT = {
ONBOARDSIDE = {
NONE = 0,
LEFT = 1,
RIGHT = 2,
BACK = 3,
FRONT = 4
},
ClassName = "CLIENT", ClassName = "CLIENT",
ClientName = nil, ClientName = nil,
ClientAlive = false, ClientAlive = false,
@@ -73,20 +65,13 @@ CLIENT = {
--- Finds a CLIENT from the _DATABASE using the relevant DCS Unit. --- Finds a CLIENT from the _DATABASE using the relevant DCS Unit.
-- @param #CLIENT self -- @param #CLIENT self
-- @param #string ClientName Name of the DCS **Unit** as defined within the Mission Editor. -- @param DCS#Unit DCSUnit The DCS unit of the client.
-- @param #string ClientBriefing Text that describes the briefing of the mission when a Player logs into the Client. -- @param #boolean Error Throw an error message.
-- @return #CLIENT -- @return #CLIENT The CLIENT found in the _DATABASE.
-- @usage function CLIENT:Find(DCSUnit, Error)
-- -- Create new Clients.
-- local Mission = MISSIONSCHEDULER.AddMission( 'Russia Transport Troops SA-6', 'Operational', 'Transport troops from the control center to one of the SA-6 SAM sites to activate their operation.', 'Russia' )
-- Mission:AddGoal( DeploySA6TroopsGoal )
--
-- Mission:AddClient( CLIENT:FindByName( 'RU MI-8MTV2*HOT-Deploy Troops 1' ):Transport() )
-- Mission:AddClient( CLIENT:FindByName( 'RU MI-8MTV2*RAMP-Deploy Troops 3' ):Transport() )
-- Mission:AddClient( CLIENT:FindByName( 'RU MI-8MTV2*HOT-Deploy Troops 2' ):Transport() )
-- Mission:AddClient( CLIENT:FindByName( 'RU MI-8MTV2*RAMP-Deploy Troops 4' ):Transport() )
function CLIENT:Find( DCSUnit, Error )
local ClientName = DCSUnit:getName() local ClientName = DCSUnit:getName()
local ClientFound = _DATABASE:FindClient( ClientName ) local ClientFound = _DATABASE:FindClient( ClientName )
if ClientFound then if ClientFound then
@@ -123,7 +108,9 @@ function CLIENT:FindByName( ClientName, ClientBriefing, Error )
if ClientFound then if ClientFound then
ClientFound:F( { ClientName, ClientBriefing } ) ClientFound:F( { ClientName, ClientBriefing } )
ClientFound:AddBriefing( ClientBriefing )
ClientFound:AddBriefing(ClientBriefing)
ClientFound.MessageSwitch = true ClientFound.MessageSwitch = true
return ClientFound return ClientFound
@@ -138,13 +125,18 @@ end
-- @param #CLIENT self -- @param #CLIENT self
-- @param #string ClientName Name of the client unit. -- @param #string ClientName Name of the client unit.
-- @return #CLIENT self -- @return #CLIENT self
function CLIENT:Register( ClientName ) function CLIENT:Register(ClientName)
local self = BASE:Inherit( self, UNIT:Register( ClientName ) ) -- #CLIENT -- Inherit unit.
local self = BASE:Inherit( self, UNIT:Register(ClientName )) -- #CLIENT
self:F( ClientName ) -- Set client name.
self.ClientName = ClientName self.ClientName = ClientName
-- Message switch.
self.MessageSwitch = true self.MessageSwitch = true
-- Alive2.
self.ClientAlive2 = false self.ClientAlive2 = false
return self return self
@@ -184,16 +176,19 @@ end
--- Get player name(s). --- Get player name(s).
-- @param #CLIENT self -- @param #CLIENT self
-- @return #table List of player names. -- @return #table List of player names or an empty table `{}`.
function CLIENT:GetPlayers() function CLIENT:GetPlayers()
return self.Players return self.Players
end end
--- Get name of player. --- Get name of player.
-- @param #CLIENT self -- @param #CLIENT self
-- @return # -- @return #string Player name or `nil`.
function CLIENT:GetPlayer() function CLIENT:GetPlayer()
return self.Players[1] if #self.Players>0 then
return self.Players[1]
end
return nil
end end
--- Remove player. --- Remove player.
@@ -297,21 +292,29 @@ end
function CLIENT:_AliveCheckScheduler( SchedulerName ) function CLIENT:_AliveCheckScheduler( SchedulerName )
self:F3( { SchedulerName, self.ClientName, self.ClientAlive2, self.ClientBriefingShown, self.ClientCallBack } ) self:F3( { SchedulerName, self.ClientName, self.ClientAlive2, self.ClientBriefingShown, self.ClientCallBack } )
env.info("FF client alive scheduler")
if self:IsAlive() then if self:IsAlive() then
if self.ClientAlive2 == false then if self.ClientAlive2 == false then
-- Show briefing.
self:ShowBriefing() self:ShowBriefing()
-- Callback function.
if self.ClientCallBack then if self.ClientCallBack then
self:T("Calling Callback function") self:T("Calling Callback function")
self.ClientCallBack( self, unpack( self.ClientParameters ) ) self.ClientCallBack( self, unpack( self.ClientParameters ) )
end end
-- Alive.
self.ClientAlive2 = true self.ClientAlive2 = true
end end
else else
if self.ClientAlive2 == true then if self.ClientAlive2 == true then
self.ClientAlive2 = false self.ClientAlive2 = false
end end
end end
return true return true
@@ -344,10 +347,14 @@ function CLIENT:GetDCSGroup()
--self:F(self.ClientName) --self:F(self.ClientName)
if ClientUnit then if ClientUnit then
local ClientGroup = ClientUnit:getGroup() local ClientGroup = ClientUnit:getGroup()
if ClientGroup then if ClientGroup then
self:T3( "ClientGroup = " .. self.ClientName ) self:T3( "ClientGroup = " .. self.ClientName )
if ClientGroup:isExist() and UnitData:getGroup():isExist() then if ClientGroup:isExist() and UnitData:getGroup():isExist() then
if ClientGroup:getID() == UnitData:getGroup():getID() then if ClientGroup:getID() == UnitData:getGroup():getID() then
self:T3( "Normal logic" ) self:T3( "Normal logic" )
self:T3( self.ClientName .. " : group found!" ) self:T3( self.ClientName .. " : group found!" )
@@ -355,15 +362,22 @@ function CLIENT:GetDCSGroup()
self.ClientGroupName = ClientGroup:getName() self.ClientGroupName = ClientGroup:getName()
return ClientGroup return ClientGroup
end end
else else
-- Now we need to resolve the bugs in DCS 1.5 ... -- Now we need to resolve the bugs in DCS 1.5 ...
-- Consult the database for the units of the Client Group. (ClientGroup:getUnits() returns nil) -- Consult the database for the units of the Client Group. (ClientGroup:getUnits() returns nil)
self:T3( "Bug 1.5 logic" ) self:T3( "Bug 1.5 logic" )
local ClientGroupTemplate = _DATABASE.Templates.Units[self.ClientName].GroupTemplate local ClientGroupTemplate = _DATABASE.Templates.Units[self.ClientName].GroupTemplate
self.ClientGroupID = ClientGroupTemplate.groupId self.ClientGroupID = ClientGroupTemplate.groupId
self.ClientGroupName = _DATABASE.Templates.Units[self.ClientName].GroupName self.ClientGroupName = _DATABASE.Templates.Units[self.ClientName].GroupName
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 -- else
-- error( "Client " .. self.ClientName .. " not found!" ) -- error( "Client " .. self.ClientName .. " not found!" )
@@ -388,22 +402,22 @@ function CLIENT:GetDCSGroup()
end end
end end
-- Nothing could be found :(
self.ClientGroupID = nil self.ClientGroupID = nil
self.ClientGroupUnit = nil self.ClientGroupName = nil
return nil return nil
end end
-- TODO: Check DCS#Group.ID
--- Get the group ID of the client. --- Get the group ID of the client.
-- @param #CLIENT self -- @param #CLIENT self
-- @return DCS#Group.ID -- @return #number DCS#Group ID.
function CLIENT:GetClientGroupID() function CLIENT:GetClientGroupID()
local ClientGroup = self:GetDCSGroup() -- This updates the ID.
self:GetDCSGroup()
--self:F( self.ClientGroupID ) -- Determined in GetDCSGroup()
return self.ClientGroupID return self.ClientGroupID
end end
@@ -413,15 +427,15 @@ end
-- @return #string -- @return #string
function CLIENT:GetClientGroupName() function CLIENT:GetClientGroupName()
local ClientGroup = self:GetDCSGroup() -- This updates the group name.
self:GetDCSGroup()
self:T( self.ClientGroupName ) -- Determined in GetDCSGroup()
return self.ClientGroupName return self.ClientGroupName
end end
--- Returns the UNIT of the CLIENT. --- Returns the UNIT of the CLIENT.
-- @param #CLIENT self -- @param #CLIENT self
-- @return Wrapper.Unit#UNIT -- @return Wrapper.Unit#UNIT The client UNIT or `nil`.
function CLIENT:GetClientGroupUnit() function CLIENT:GetClientGroupUnit()
self:F2() self:F2()
@@ -429,7 +443,7 @@ function CLIENT:GetClientGroupUnit()
self:T( self.ClientDCSUnit ) self:T( self.ClientDCSUnit )
if ClientDCSUnit then -- and ClientDCSUnit:isExist() then if ClientDCSUnit and ClientDCSUnit:isExist() then
local ClientUnit=_DATABASE:FindUnit( self.ClientName ) local ClientUnit=_DATABASE:FindUnit( self.ClientName )
return ClientUnit return ClientUnit
end end

View File

@@ -103,12 +103,18 @@ UNIT = {
--- Create a new UNIT from DCSUnit. --- Create a new UNIT from DCSUnit.
-- @param #UNIT self -- @param #UNIT self
-- @param #string UnitName The name of the DCS unit. -- @param #string UnitName The name of the DCS unit.
-- @return #UNIT -- @return #UNIT self
function UNIT:Register( UnitName ) function UNIT:Register( UnitName )
-- Inherit CONTROLLABLE.
local self = BASE:Inherit( self, CONTROLLABLE:New( UnitName ) ) local self = BASE:Inherit( self, CONTROLLABLE:New( UnitName ) )
-- Set unit name.
self.UnitName = UnitName self.UnitName = UnitName
-- Set event prio.
self:SetEventPriority( 3 ) self:SetEventPriority( 3 )
return self return self
end end