Some stuff

This commit is contained in:
Frank 2021-01-02 23:53:36 +01:00
parent 417af6a93c
commit 3358f98bc4
5 changed files with 119 additions and 40 deletions

View File

@ -1078,11 +1078,14 @@ do -- CARGO_REPRESENTABLE
local self = BASE:Inherit( self, CARGO:New( Type, Name, 0, LoadRadius, NearRadius ) ) -- #CARGO_REPRESENTABLE local self = BASE:Inherit( self, CARGO:New( Type, Name, 0, LoadRadius, NearRadius ) ) -- #CARGO_REPRESENTABLE
self:F( { Type, Name, LoadRadius, NearRadius } ) self:F( { Type, Name, LoadRadius, NearRadius } )
local Desc = CargoObject:GetDesc() -- Descriptors.
self:I( { Desc = Desc } ) local Desc=CargoObject:GetDesc()
self:T({Desc=Desc})
-- Weight.
local Weight = math.random( 80, 120 ) local Weight = math.random( 80, 120 )
-- Adjust weight..
if Desc then if Desc then
if Desc.typeName == "2B11 mortar" then if Desc.typeName == "2B11 mortar" then
Weight = 210 Weight = 210
@ -1091,14 +1094,9 @@ do -- CARGO_REPRESENTABLE
end end
end end
-- Set weight.
self:SetWeight( Weight ) self:SetWeight( Weight )
-- local Box = CargoUnit:GetBoundingBox()
-- local VolumeUnit = ( Box.max.x - Box.min.x ) * ( Box.max.y - Box.min.y ) * ( Box.max.z - Box.min.z )
-- self:I( { VolumeUnit = VolumeUnit, WeightUnit = WeightUnit } )
--self:SetVolume( VolumeUnit )
return self return self
end end

View File

@ -46,14 +46,17 @@ do -- CARGO_UNIT
-- @param #number NearRadius (optional) -- @param #number NearRadius (optional)
-- @return #CARGO_UNIT -- @return #CARGO_UNIT
function CARGO_UNIT:New( CargoUnit, Type, Name, LoadRadius, NearRadius ) function CARGO_UNIT:New( CargoUnit, Type, Name, LoadRadius, NearRadius )
local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoUnit, Type, Name, LoadRadius, NearRadius ) ) -- #CARGO_UNIT
self:I( { Type, Name, LoadRadius, NearRadius } )
self:T( CargoUnit ) -- Inherit CARGO_REPRESENTABLE.
local self = BASE:Inherit( self, CARGO_REPRESENTABLE:New( CargoUnit, Type, Name, LoadRadius, NearRadius ) ) -- #CARGO_UNIT
-- Debug info.
self:T({Type=Type, Name=Name, LoadRadius=LoadRadius, NearRadius=NearRadius})
-- Set cargo object.
self.CargoObject = CargoUnit self.CargoObject = CargoUnit
self:T( self.ClassName ) -- Set event prio.
self:SetEventPriority( 5 ) self:SetEventPriority( 5 )
return self return self

View File

@ -411,7 +411,6 @@ do -- cargo
local Groups = UTILS.DeepCopy( self.GROUPS ) -- This is a very important statement. CARGO_GROUP:New creates a new _DATABASE.GROUP entry, which will confuse the loop. I searched 4 hours on this to find the bug! local Groups = UTILS.DeepCopy( self.GROUPS ) -- This is a very important statement. CARGO_GROUP:New creates a new _DATABASE.GROUP entry, which will confuse the loop. I searched 4 hours on this to find the bug!
for CargoGroupName, CargoGroup in pairs( Groups ) do for CargoGroupName, CargoGroup in pairs( Groups ) do
self:I( { Cargo = CargoGroupName } )
if self:IsCargo( CargoGroupName ) then if self:IsCargo( CargoGroupName ) then
local CargoInfo = CargoGroupName:match("#CARGO(.*)") local CargoInfo = CargoGroupName:match("#CARGO(.*)")
local CargoParam = CargoInfo and CargoInfo:match( "%((.*)%)") local CargoParam = CargoInfo and CargoInfo:match( "%((.*)%)")
@ -755,46 +754,96 @@ end
--- Get static group template. --- Get static group template.
-- @param #DATABASE self -- @param #DATABASE self
-- @param #string StaticName Name of the static -- @param #string StaticName Name of the static.
-- @return #table Static template table. -- @return #table Static template table.
function DATABASE:GetStaticGroupTemplate( StaticName ) function DATABASE:GetStaticGroupTemplate( StaticName )
local StaticTemplate = self.Templates.Statics[StaticName].GroupTemplate if self.Templates.Statics[StaticName] then
return StaticTemplate, self.Templates.Statics[StaticName].CoalitionID, self.Templates.Statics[StaticName].CategoryID, self.Templates.Statics[StaticName].CountryID local StaticTemplate = self.Templates.Statics[StaticName].GroupTemplate
return StaticTemplate, self.Templates.Statics[StaticName].CoalitionID, self.Templates.Statics[StaticName].CategoryID, self.Templates.Statics[StaticName].CountryID
else
self:E("ERROR: Static group template does NOT exist for static "..tostring(StaticName))
return nil
end
end end
--- @param #DATABASE self --- Get static unit template.
-- @param #DATABASE self
-- @param #string StaticName Name of the static.
-- @return #table Static template table.
function DATABASE:GetStaticUnitTemplate( StaticName ) function DATABASE:GetStaticUnitTemplate( StaticName )
local UnitTemplate = self.Templates.Statics[StaticName].UnitTemplate if self.Templates.Statics[StaticName] then
return UnitTemplate, self.Templates.Statics[StaticName].CoalitionID, self.Templates.Statics[StaticName].CategoryID, self.Templates.Statics[StaticName].CountryID local UnitTemplate = self.Templates.Statics[StaticName].UnitTemplate
return UnitTemplate, self.Templates.Statics[StaticName].CoalitionID, self.Templates.Statics[StaticName].CategoryID, self.Templates.Statics[StaticName].CountryID
else
self:E("ERROR: Static unit template does NOT exist for static "..tostring(StaticName))
return nil
end
end end
--- Get group name from unit name.
-- @param #DATABASE self
-- @param #string UnitName Name of the unit.
-- @return #string Group name.
function DATABASE:GetGroupNameFromUnitName( UnitName ) function DATABASE:GetGroupNameFromUnitName( UnitName )
return self.Templates.Units[UnitName].GroupName if self.Templates.Units[UnitName] then
return self.Templates.Units[UnitName].GroupName
else
self:E("ERROR: Unit template does not exist for unit "..tostring(UnitName))
return nil
end
end end
--- Get group template from unit name.
-- @param #DATABASE self
-- @param #string UnitName Name of the unit.
-- @return #table Group template.
function DATABASE:GetGroupTemplateFromUnitName( UnitName ) function DATABASE:GetGroupTemplateFromUnitName( UnitName )
return self.Templates.Units[UnitName].GroupTemplate if self.Templates.Units[UnitName] then
return self.Templates.Units[UnitName].GroupTemplate
else
self:E("ERROR: Unit template does not exist for unit "..tostring(UnitName))
return nil
end
end end
--- Get coalition ID from client name.
-- @param #DATABASE self
-- @param #string ClientName Name of the Client.
-- @return #number Coalition ID.
function DATABASE:GetCoalitionFromClientTemplate( ClientName ) function DATABASE:GetCoalitionFromClientTemplate( ClientName )
return self.Templates.ClientsByName[ClientName].CoalitionID return self.Templates.ClientsByName[ClientName].CoalitionID
end end
--- Get category ID from client name.
-- @param #DATABASE self
-- @param #string ClientName Name of the Client.
-- @return #number Category ID.
function DATABASE:GetCategoryFromClientTemplate( ClientName ) function DATABASE:GetCategoryFromClientTemplate( ClientName )
return self.Templates.ClientsByName[ClientName].CategoryID return self.Templates.ClientsByName[ClientName].CategoryID
end end
--- Get country ID from client name.
-- @param #DATABASE self
-- @param #string ClientName Name of the Client.
-- @return #number Country ID.
function DATABASE:GetCountryFromClientTemplate( ClientName ) function DATABASE:GetCountryFromClientTemplate( ClientName )
return self.Templates.ClientsByName[ClientName].CountryID return self.Templates.ClientsByName[ClientName].CountryID
end end
--- Airbase --- Airbase
--- Get coalition ID from airbase name.
-- @param #DATABASE self
-- @param #string AirbaseName Name of the airbase.
-- @return #number Coalition ID.
function DATABASE:GetCoalitionFromAirbase( AirbaseName ) function DATABASE:GetCoalitionFromAirbase( AirbaseName )
return self.AIRBASES[AirbaseName]:GetCoalition() return self.AIRBASES[AirbaseName]:GetCoalition()
end end
--- Get category from airbase name.
-- @param #DATABASE self
-- @param #string AirbaseName Name of the airbase.
-- @return #number Category.
function DATABASE:GetCategoryFromAirbase( AirbaseName ) function DATABASE:GetCategoryFromAirbase( AirbaseName )
return self.AIRBASES[AirbaseName]:GetCategory() return self.AIRBASES[AirbaseName]:GetCategory()
end end
@ -890,7 +939,7 @@ function DATABASE:_RegisterStatics()
if DCSStatic:isExist() then if DCSStatic:isExist() then
local DCSStaticName = DCSStatic:getName() local DCSStaticName = DCSStatic:getName()
self:I( { "Register Static:", DCSStaticName } ) self:I(string.format("Register Static: %s", tostring(DCSStaticName)))
self:AddStatic( DCSStaticName ) self:AddStatic( DCSStaticName )
else else
self:E( { "Static does not exist: ", DCSStatic } ) self:E( { "Static does not exist: ", DCSStatic } )
@ -921,7 +970,7 @@ function DATABASE:_RegisterAirbases()
local airbaseUID=airbase:GetID(true) local airbaseUID=airbase:GetID(true)
-- Debug output. -- Debug output.
local text=string.format("Register Airbase: %s (ID=%d UID=%d), category=%s, parking=%d [", tostring(DCSAirbaseName), airbaseID, airbaseUID, AIRBASE.CategoryName[airbase.category], airbase.NparkingTotal) local text=string.format("Register %s: %s (ID=%d UID=%d), parking=%d [", AIRBASE.CategoryName[airbase.category], tostring(DCSAirbaseName), airbaseID, airbaseUID, airbase.NparkingTotal)
for _,terminalType in pairs(AIRBASE.TerminalType) do for _,terminalType in pairs(AIRBASE.TerminalType) do
if airbase.NparkingTerminal and airbase.NparkingTerminal[terminalType] then if airbase.NparkingTerminal and airbase.NparkingTerminal[terminalType] then
text=text..string.format("%d=%d ", terminalType, airbase.NparkingTerminal[terminalType]) text=text..string.format("%d=%d ", terminalType, airbase.NparkingTerminal[terminalType])
@ -1025,19 +1074,29 @@ end
-- @param #DATABASE self -- @param #DATABASE self
-- @param Core.Event#EVENTDATA Event -- @param Core.Event#EVENTDATA Event
function DATABASE:_EventOnDeadOrCrash( Event ) function DATABASE:_EventOnDeadOrCrash( Event )
self:F2( { Event } )
if Event.IniDCSUnit then if Event.IniDCSUnit then
local name=Event.IniDCSUnitName local name=Event.IniDCSUnitName
if Event.IniObjectCategory == 3 then if Event.IniObjectCategory == 3 then
---
-- STATICS
---
if self.STATICS[Event.IniDCSUnitName] then if self.STATICS[Event.IniDCSUnitName] then
self:DeleteStatic( Event.IniDCSUnitName ) self:DeleteStatic( Event.IniDCSUnitName )
end end
else else
if Event.IniObjectCategory == 1 then if Event.IniObjectCategory == 1 then
---
-- UNITS
---
-- Delete unit. -- Delete unit.
if self.UNITS[Event.IniDCSUnitName] then if self.UNITS[Event.IniDCSUnitName] then
self:DeleteUnit(Event.IniDCSUnitName) self:DeleteUnit(Event.IniDCSUnitName)
@ -1053,8 +1112,15 @@ function DATABASE:_EventOnDeadOrCrash( Event )
end end
end end
-- Add airbase if it was spawned later in the mission.
local airbase=self.AIRBASES[Event.IniDCSUnitName] --Wrapper.Airbase#AIRBASE
if airbase and (airbase:IsHelipad() or airbase:IsShip()) then
self:DeleteAirbase(Event.IniDCSUnitName)
end
end end
-- Account destroys.
self:AccountDestroys( Event ) self:AccountDestroys( Event )
end end

View File

@ -820,7 +820,7 @@ do -- Event Creation
-- @param #EVENT self -- @param #EVENT self
-- @param AI.AI_Cargo#AI_CARGO Cargo The Cargo created. -- @param AI.AI_Cargo#AI_CARGO Cargo The Cargo created.
function EVENT:CreateEventNewCargo( Cargo ) function EVENT:CreateEventNewCargo( Cargo )
self:I( { Cargo } ) self:F( { Cargo } )
local Event = { local Event = {
id = EVENTS.NewCargo, id = EVENTS.NewCargo,

View File

@ -4705,7 +4705,8 @@ do -- SET_AIRBASE
if _DATABASE then if _DATABASE then
-- We use the BaseCaptured event, which is generated by DCS when a base got captured. -- We use the BaseCaptured event, which is generated by DCS when a base got captured.
self:HandleEvent( EVENTS.BaseCaptured ) self:HandleEvent(EVENTS.BaseCaptured)
self:HandleEvent(EVENTS.Dead)
-- We initialize the first set. -- We initialize the first set.
for ObjectName, Object in pairs( self.Database ) do for ObjectName, Object in pairs( self.Database ) do
@ -4720,10 +4721,9 @@ do -- SET_AIRBASE
return self return self
end end
--- Starts the filtering. --- Base capturing event.
-- @param #SET_AIRBASE self -- @param #SET_AIRBASE self
-- @param Core.Event#EVENT EventData -- @param Core.Event#EVENT EventData
-- @return #SET_AIRBASE self
function SET_AIRBASE:OnEventBaseCaptured(EventData) function SET_AIRBASE:OnEventBaseCaptured(EventData)
-- When a base got captured, we reevaluate the set. -- When a base got captured, we reevaluate the set.
@ -4739,24 +4739,36 @@ do -- SET_AIRBASE
end end
--- Dead event.
-- @param #SET_AIRBASE self
-- @param Core.Event#EVENT EventData
function SET_AIRBASE:OnEventDead(EventData)
local airbaseName, airbase=self:FindInDatabase(EventData)
if airbase and airbase:IsShip() or airbase:IsHelipad() then
self:RemoveAirbasesByName(airbaseName)
end
end
--- Handles the Database to check on an event (birth) that the Object was added in the Database. --- Handles the Database to check on an event (birth) that the Object was added in the Database.
-- This is required, because sometimes the _DATABASE birth event gets called later than the SET_BASE birth event! -- This is required, because sometimes the _DATABASE birth event gets called later than the SET_BASE birth event!
-- @param #SET_AIRBASE self -- @param #SET_AIRBASE self
-- @param Core.Event#EVENTDATA Event -- @param Core.Event#EVENTDATA Event Event data.
-- @return #string The name of the AIRBASE -- @return #string The name of the AIRBASE.
-- @return #table The AIRBASE -- @return Wrapper.Airbase#AIRBASE The AIRBASE object.
function SET_AIRBASE:AddInDatabase( Event ) function SET_AIRBASE:AddInDatabase( Event )
self:F3( { Event } )
return Event.IniDCSUnitName, self.Database[Event.IniDCSUnitName] return Event.IniDCSUnitName, self.Database[Event.IniDCSUnitName]
end end
--- Handles the Database to check on any event that Object exists in the Database. --- Handles the Database to check on any event that Object exists in the Database.
-- This is required, because sometimes the _DATABASE event gets called later than the SET_BASE event or vise versa! -- This is required, because sometimes the _DATABASE event gets called later than the SET_BASE event or vise versa!
-- @param #SET_AIRBASE self -- @param #SET_AIRBASE self
-- @param Core.Event#EVENTDATA Event -- @param Core.Event#EVENTDATA Event Event data.
-- @return #string The name of the AIRBASE -- @return #string The name of the AIRBASE.
-- @return #table The AIRBASE -- @return Wrapper.Airbase#AIRBASE The AIRBASE object.
function SET_AIRBASE:FindInDatabase( Event ) function SET_AIRBASE:FindInDatabase( Event )
self:F3( { Event } ) self:F3( { Event } )