mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Optimizations and register the database
This commit is contained in:
@@ -161,6 +161,28 @@ function DATABASE:New()
|
||||
return self
|
||||
end
|
||||
|
||||
--- Finds a Unit based on the Unit Name.
|
||||
-- @param #DATABASE self
|
||||
-- @param #string UnitName
|
||||
-- @return Unit#UNIT The found Unit.
|
||||
function DATABASE:FindUnit( UnitName )
|
||||
|
||||
local UnitFound = self.Units[UnitName]
|
||||
return UnitFound
|
||||
end
|
||||
|
||||
--- Finds a Unit based on the Unit Name.
|
||||
-- @param #DATABASE self
|
||||
-- @param Unit#UNIT UnitToAdd
|
||||
-- @return Unit#UNIT The added Unit.
|
||||
function DATABASE:AddUnit( UnitToAdd )
|
||||
|
||||
self.Units[UnitToAdd.UnitName] = UnitToAdd
|
||||
return self.Units[UnitToAdd.UnitName]
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Builds a set of units of coalitons.
|
||||
-- Possible current coalitions are red, blue and neutral.
|
||||
-- @param #DATABASE self
|
||||
@@ -472,7 +494,8 @@ function DATABASE:_RegisterDatabase()
|
||||
self:E( { "Register Unit:", DCSUnit, DCSUnitName } )
|
||||
|
||||
self.DCSUnits[DCSUnitName] = DCSUnit
|
||||
self.Units[DCSUnitName] = UNIT:New( DCSUnit )
|
||||
self:AddUnit( UNIT:Register( DCSUnit ) )
|
||||
--self.Units[DCSUnitName] = UNIT:Register( DCSUnit )
|
||||
|
||||
if self:_IsAliveDCSUnit(DCSUnit) then
|
||||
self:E( { "Register Alive Unit:", DCSUnit, DCSUnitName } )
|
||||
@@ -506,7 +529,8 @@ function DATABASE:_EventOnBirth( Event )
|
||||
if self:_IsIncludeDCSUnit( Event.IniDCSUnit ) then
|
||||
self.DCSUnits[Event.IniDCSUnitName] = Event.IniDCSUnit
|
||||
self.DCSUnitsAlive[Event.IniDCSUnitName] = Event.IniDCSUnit
|
||||
self.Units[Event.IniDCSUnitName] = UNIT:New( Event.IniDCSUnit )
|
||||
self:AddUnit( UNIT:Register( Event.IniDCSUnit ) )
|
||||
--self.Units[Event.IniDCSUnitName] = UNIT:Register( Event.IniDCSUnit )
|
||||
|
||||
--if not self.DCSGroups[Event.IniDCSGroupName] then
|
||||
-- self.DCSGroups[Event.IniDCSGroupName] = Event.IniDCSGroupName
|
||||
|
||||
@@ -452,8 +452,8 @@ function MISSILETRAINER:_EventShot( Event )
|
||||
local Client = self.DBClients[TrainerTargetDCSUnitName]
|
||||
if Client then
|
||||
|
||||
local TrainerSourceUnit = UNIT:New(TrainerSourceDCSUnit)
|
||||
local TrainerTargetUnit = UNIT:New(TrainerTargetDCSUnit)
|
||||
local TrainerSourceUnit = UNIT:New( TrainerSourceDCSUnit )
|
||||
local TrainerTargetUnit = UNIT:New( TrainerTargetDCSUnit )
|
||||
|
||||
if self.MessagesOnOff == true and self.AlertsLaunchesOnOff == true then
|
||||
|
||||
|
||||
107
Moose/Unit.lua
107
Moose/Unit.lua
@@ -50,23 +50,44 @@ UNIT = {
|
||||
-- @field Blue
|
||||
|
||||
|
||||
--- Create a new UNIT from DCSUnit.
|
||||
--- Finds the Unit from the _DATABASE.
|
||||
-- @param #UNIT self
|
||||
-- @param DCSUnit#Unit DCSUnit
|
||||
-- @return Unit#UNIT
|
||||
function UNIT:New( DCSUnit )
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
self:F( DCSUnit )
|
||||
|
||||
if DCSUnit then
|
||||
self.UnitName = DCSUnit:getName()
|
||||
return self
|
||||
if DCSUnit then
|
||||
local UnitName = DCSUnit:getName()
|
||||
if _DATABASE then
|
||||
local UnitFound = _DATABASE:FindUnit( UnitName )
|
||||
if UnitFound then
|
||||
return UnitFound
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.UnitName = nil
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Create a new UNIT from DCSUnit.
|
||||
-- @param #UNIT self
|
||||
-- @param DCSUnit#Unit DCSUnit
|
||||
-- @param Database#DATABASE Database
|
||||
-- @return Unit#UNIT
|
||||
function UNIT:Register( DCSUnit )
|
||||
|
||||
if DCSUnit then
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
self:F( DCSUnit )
|
||||
self.UnitName = DCSUnit:getName()
|
||||
return self
|
||||
end
|
||||
|
||||
self.UnitName = nil
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Create a new UNIT from a Unit Name.
|
||||
-- @param #UNIT self
|
||||
-- @param #string Unit Name
|
||||
@@ -95,9 +116,9 @@ function UNIT:GetDCSUnit()
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Returns coalition of the object.
|
||||
--- Returns coalition of the Unit.
|
||||
-- @param Unit#UNIT self
|
||||
-- @return #DCSCoalitionObject#coalition.side
|
||||
-- @return DCSCoalitionObject#coalition.side
|
||||
function UNIT:GetCoalition()
|
||||
self:F( self.UnitName )
|
||||
|
||||
@@ -110,9 +131,26 @@ function UNIT:GetCoalition()
|
||||
end
|
||||
|
||||
return nil
|
||||
|
||||
end
|
||||
|
||||
--- Returns country of the Unit.
|
||||
-- @param Unit#UNIT self
|
||||
-- @return DCScountry#country.id The country identifyer.
|
||||
function UNIT:GetCountry()
|
||||
self:F( self.UnitName )
|
||||
|
||||
local DCSUnit = self:GetDCSUnit()
|
||||
|
||||
if DCSUnit then
|
||||
local UnitCountry = DCSUnit:getCountry()
|
||||
self:T( UnitCountry )
|
||||
return UnitCountry
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
--- Returns unit object by the name assigned to the unit in Mission Editor.
|
||||
-- If there is unit with such name or the unit is destroyed the function will return nil.
|
||||
-- The function provides access to non-activated units too.
|
||||
@@ -420,6 +458,8 @@ end
|
||||
|
||||
|
||||
function UNIT:GetPositionVec3()
|
||||
self:F( self.UnitName )
|
||||
|
||||
local DCSUnit = self:GetDCSUnit()
|
||||
|
||||
if DCSUnit then
|
||||
@@ -431,6 +471,55 @@ function UNIT:GetPositionVec3()
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Returns the unit's velocity vector.
|
||||
-- @param Unit#UNIT self
|
||||
-- @return DCSTypes#Vec3 Velocity Vector
|
||||
function UNIT:GetVelocity()
|
||||
self:F( self.UnitName )
|
||||
|
||||
local DCSUnit = self:GetDCSUnit()
|
||||
|
||||
if DCSUnit then
|
||||
local UnitVelocityVec3 = DCSUnit:getVelocity()
|
||||
self:T( UnitVelocityVec3 )
|
||||
return UnitVelocityVec3
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Returns true if the Unit is in air.
|
||||
-- @param Unit#UNIT self
|
||||
-- @return #boolean true if in the air.
|
||||
function UNIT:InAir()
|
||||
self:F( self.UnitName )
|
||||
|
||||
local DCSUnit = self:GetDCSUnit()
|
||||
|
||||
if DCSUnit then
|
||||
local UnitInAir = DCSUnit:inAir()
|
||||
self:T( UnitInAir )
|
||||
return UnitInAir
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
function UNIT:GetPositionVec3()
|
||||
self:F( self.UnitName )
|
||||
|
||||
local DCSUnit = self:GetDCSUnit()
|
||||
|
||||
if DCSUnit then
|
||||
local UnitPos = DCSUnit:getPosition().p
|
||||
self:T( UnitPos )
|
||||
return UnitPos
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
function UNIT:OtherUnitInRadius( AwaitUnit, Radius )
|
||||
self:F( { self.UnitName, AwaitUnit.UnitName, Radius } )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user