Working plane cargo AI dispatcher, but still need to work on the collisions on the runway etc of moving vehicles with planes...

This commit is contained in:
FlightControl 2018-08-14 21:04:11 +02:00
parent 4d7812b368
commit e4f8b5afc3
4 changed files with 31 additions and 24 deletions

View File

@ -101,7 +101,7 @@ do -- CARGO_GROUP
end end
-- Then we register the new group in the database -- Then we register the new group in the database
self.CargoGroup = GROUP:NewTemplate( GroupTemplate, GroupTemplate.CoalitionID, GroupTemplate.CategoryID, GroupTemplate.CountryID) GROUP:NewTemplate( GroupTemplate, GroupTemplate.CoalitionID, GroupTemplate.CategoryID, GroupTemplate.CountryID )
-- Now we spawn the new group based on the template created. -- Now we spawn the new group based on the template created.
self.CargoObject = _DATABASE:Spawn( GroupTemplate ) self.CargoObject = _DATABASE:Spawn( GroupTemplate )

View File

@ -374,14 +374,15 @@ do -- cargo
-- @return #DATABASE self -- @return #DATABASE self
function DATABASE:_RegisterCargos() function DATABASE:_RegisterCargos()
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( self.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( "%((.*)%)")
local CargoName1 = CargoGroupName:match("(.*)~CARGO%(.*%)") local CargoName1 = CargoGroupName:match("(.*)~CARGO%(.*%)")
local CargoName2 = CargoGroupName:match(".*~CARGO%(.*%)(.*)") local CargoName2 = CargoGroupName:match(".*~CARGO%(.*%)(.*)")
self:E({CargoName1 = CargoName1, CargoName2 = CargoName2 })
local CargoName = CargoName1 .. ( CargoName2 or "" ) local CargoName = CargoName1 .. ( CargoName2 or "" )
local Type = CargoParam and CargoParam:match( "T=([%a%d ]+),?") local Type = CargoParam and CargoParam:match( "T=([%a%d ]+),?")
local Name = CargoParam and CargoParam:match( "N=([%a%d]+),?") or CargoName local Name = CargoParam and CargoParam:match( "N=([%a%d]+),?") or CargoName
@ -459,7 +460,7 @@ end
function DATABASE:AddGroup( GroupName ) function DATABASE:AddGroup( GroupName )
if not self.GROUPS[GroupName] then if not self.GROUPS[GroupName] then
self:E( { "Add GROUP:", GroupName } ) self:I( { "Add GROUP:", GroupName } )
self.GROUPS[GroupName] = GROUP:Register( GroupName ) self.GROUPS[GroupName] = GROUP:Register( GroupName )
end end
@ -471,7 +472,7 @@ end
function DATABASE:AddPlayer( UnitName, PlayerName ) function DATABASE:AddPlayer( UnitName, PlayerName )
if PlayerName then if PlayerName then
self:E( { "Add player for unit:", UnitName, PlayerName } ) self:I( { "Add player for unit:", UnitName, PlayerName } )
self.PLAYERS[PlayerName] = UnitName self.PLAYERS[PlayerName] = UnitName
self.PLAYERUNITS[PlayerName] = self:FindUnit( UnitName ) self.PLAYERUNITS[PlayerName] = self:FindUnit( UnitName )
self.PLAYERSJOINED[PlayerName] = PlayerName self.PLAYERSJOINED[PlayerName] = PlayerName
@ -483,7 +484,7 @@ end
function DATABASE:DeletePlayer( UnitName, PlayerName ) function DATABASE:DeletePlayer( UnitName, PlayerName )
if PlayerName then if PlayerName then
self:E( { "Clean player:", PlayerName } ) self:I( { "Clean player:", PlayerName } )
self.PLAYERS[PlayerName] = nil self.PLAYERS[PlayerName] = nil
self.PLAYERUNITS[PlayerName] = nil self.PLAYERUNITS[PlayerName] = nil
end end
@ -750,7 +751,7 @@ function DATABASE:_RegisterPlayers()
local UnitName = UnitData:getName() local UnitName = UnitData:getName()
local PlayerName = UnitData:getPlayerName() local PlayerName = UnitData:getPlayerName()
if not self.PLAYERS[PlayerName] then if not self.PLAYERS[PlayerName] then
self:E( { "Add player for unit:", UnitName, PlayerName } ) self:I( { "Add player for unit:", UnitName, PlayerName } )
self:AddPlayer( UnitName, PlayerName ) self:AddPlayer( UnitName, PlayerName )
end end
end end
@ -773,13 +774,13 @@ function DATABASE:_RegisterGroupsAndUnits()
if DCSGroup:isExist() then if DCSGroup:isExist() then
local DCSGroupName = DCSGroup:getName() local DCSGroupName = DCSGroup:getName()
self:E( { "Register Group:", DCSGroupName } ) self:I( { "Register Group:", DCSGroupName } )
self:AddGroup( DCSGroupName ) self:AddGroup( DCSGroupName )
for DCSUnitId, DCSUnit in pairs( DCSGroup:getUnits() ) do for DCSUnitId, DCSUnit in pairs( DCSGroup:getUnits() ) do
local DCSUnitName = DCSUnit:getName() local DCSUnitName = DCSUnit:getName()
self:E( { "Register Unit:", DCSUnitName } ) self:I( { "Register Unit:", DCSUnitName } )
self:AddUnit( DCSUnitName ) self:AddUnit( DCSUnitName )
end end
else else
@ -789,6 +790,11 @@ function DATABASE:_RegisterGroupsAndUnits()
end end
end end
self:I("Groups:")
for GroupName, Group in pairs( self.GROUPS ) do
self:I( { "Group:", GroupName } )
end
return self return self
end end
@ -798,7 +804,7 @@ end
function DATABASE:_RegisterClients() function DATABASE:_RegisterClients()
for ClientName, ClientTemplate in pairs( self.Templates.ClientsByName ) do for ClientName, ClientTemplate in pairs( self.Templates.ClientsByName ) do
self:E( { "Register Client:", ClientName } ) self:I( { "Register Client:", ClientName } )
self:AddClient( ClientName ) self:AddClient( ClientName )
end end
@ -809,14 +815,14 @@ end
function DATABASE:_RegisterStatics() function DATABASE:_RegisterStatics()
local CoalitionsData = { GroupsRed = coalition.getStaticObjects( coalition.side.RED ), GroupsBlue = coalition.getStaticObjects( coalition.side.BLUE ) } local CoalitionsData = { GroupsRed = coalition.getStaticObjects( coalition.side.RED ), GroupsBlue = coalition.getStaticObjects( coalition.side.BLUE ) }
self:E( { Statics = CoalitionsData } ) self:I( { Statics = CoalitionsData } )
for CoalitionId, CoalitionData in pairs( CoalitionsData ) do for CoalitionId, CoalitionData in pairs( CoalitionsData ) do
for DCSStaticId, DCSStatic in pairs( CoalitionData ) do for DCSStaticId, DCSStatic in pairs( CoalitionData ) do
if DCSStatic:isExist() then if DCSStatic:isExist() then
local DCSStaticName = DCSStatic:getName() local DCSStaticName = DCSStatic:getName()
self:E( { "Register Static:", DCSStaticName } ) self:I( { "Register Static:", DCSStaticName } )
self:AddStatic( DCSStaticName ) self:AddStatic( DCSStaticName )
else else
self:E( { "Static does not exist: ", DCSStatic } ) self:E( { "Static does not exist: ", DCSStatic } )
@ -836,7 +842,7 @@ function DATABASE:_RegisterAirbases()
local DCSAirbaseName = DCSAirbase:getName() local DCSAirbaseName = DCSAirbase:getName()
self:E( { "Register Airbase:", DCSAirbaseName, DCSAirbase:getID() } ) self:I( { "Register Airbase:", DCSAirbaseName, DCSAirbase:getID() } )
self:AddAirbase( DCSAirbaseName ) self:AddAirbase( DCSAirbaseName )
end end
end end
@ -866,9 +872,8 @@ function DATABASE:_EventOnBirth( Event )
Event.IniUnit = self:FindUnit( Event.IniDCSUnitName ) Event.IniUnit = self:FindUnit( Event.IniDCSUnitName )
Event.IniGroup = self:FindGroup( Event.IniDCSGroupName ) Event.IniGroup = self:FindGroup( Event.IniDCSGroupName )
local PlayerName = Event.IniUnit:GetPlayerName() local PlayerName = Event.IniUnit:GetPlayerName()
self:E( { "PlayerName:", PlayerName } )
if PlayerName then if PlayerName then
self:E( { "Player Joined:", PlayerName } ) self:I( { "Player Joined:", PlayerName } )
if not self.PLAYERS[PlayerName] then if not self.PLAYERS[PlayerName] then
self:AddPlayer( Event.IniUnitName, PlayerName ) self:AddPlayer( Event.IniUnitName, PlayerName )
end end
@ -937,7 +942,7 @@ function DATABASE:_EventOnPlayerLeaveUnit( Event )
if Event.IniObjectCategory == 1 then if Event.IniObjectCategory == 1 then
local PlayerName = Event.IniUnit:GetPlayerName() local PlayerName = Event.IniUnit:GetPlayerName()
if PlayerName and self.PLAYERS[PlayerName] then if PlayerName and self.PLAYERS[PlayerName] then
self:E( { "Player Left:", PlayerName } ) self:I( { "Player Left:", PlayerName } )
local Settings = SETTINGS:Set( PlayerName ) local Settings = SETTINGS:Set( PlayerName )
Settings:RemovePlayerMenu( Event.IniUnit ) Settings:RemovePlayerMenu( Event.IniUnit )
self:DeletePlayer( Event.IniUnit, PlayerName ) self:DeletePlayer( Event.IniUnit, PlayerName )

View File

@ -719,7 +719,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:F( { Cargo } ) self:I( { Cargo } )
local Event = { local Event = {
id = EVENTS.NewCargo, id = EVENTS.NewCargo,

View File

@ -121,12 +121,15 @@ GROUPTEMPLATE.Takeoff = {
-- @return #GROUP self -- @return #GROUP self
function GROUP:NewTemplate( GroupTemplate, CoalitionSide, CategoryID, CountryID ) function GROUP:NewTemplate( GroupTemplate, CoalitionSide, CategoryID, CountryID )
local GroupName = GroupTemplate.name local GroupName = GroupTemplate.name
_DATABASE:_RegisterGroupTemplate( GroupTemplate, CoalitionSide, CategoryID, CountryID, GroupName ) _DATABASE:_RegisterGroupTemplate( GroupTemplate, CoalitionSide, CategoryID, CountryID, GroupName )
self = BASE:Inherit( self, CONTROLLABLE:New( GroupName ) )
self:F2( GroupName ) local self = BASE:Inherit( self, CONTROLLABLE:New( GroupName ) )
self.GroupName = GroupName self.GroupName = GroupName
_DATABASE:AddGroup( GroupName ) if not _DATABASE.GROUPS[GroupName] then
_DATABASE.GROUPS[GroupName] = self
end
self:SetEventPriority( 4 ) self:SetEventPriority( 4 )
return self return self
@ -140,7 +143,6 @@ end
-- @return #GROUP self -- @return #GROUP self
function GROUP:Register( GroupName ) function GROUP:Register( GroupName )
local self = BASE:Inherit( self, CONTROLLABLE:New( GroupName ) ) -- #GROUP local self = BASE:Inherit( self, CONTROLLABLE:New( GroupName ) ) -- #GROUP
self:F( GroupName )
self.GroupName = GroupName self.GroupName = GroupName
self:SetEventPriority( 4 ) self:SetEventPriority( 4 )