mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Spawning FARPS
**SPAWNSTATIC** - Added event birth when static FARPS are spawned **EVENT** - Unknown airbases as inititiator are registered
This commit is contained in:
parent
2538d583ad
commit
6834a2e083
@ -1027,11 +1027,26 @@ function DATABASE:_RegisterAirbases()
|
||||
|
||||
for DCSAirbaseId, DCSAirbase in pairs(world.getAirbases()) do
|
||||
|
||||
self:_RegisterAirbase(DCSAirbase)
|
||||
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Register a DCS airbase.
|
||||
-- @param #DATABASE self
|
||||
-- @param DCS#Airbase airbase Airbase.
|
||||
-- @return #DATABASE self
|
||||
function DATABASE:_RegisterAirbase(airbase)
|
||||
|
||||
if airbase then
|
||||
|
||||
-- Get the airbase name.
|
||||
local DCSAirbaseName = DCSAirbase:getName()
|
||||
local DCSAirbaseName = airbase:getName()
|
||||
|
||||
-- This gave the incorrect value to be inserted into the airdromeID for DCS 2.5.6. Is fixed now.
|
||||
local airbaseID=DCSAirbase:getID()
|
||||
local airbaseID=airbase:getID()
|
||||
|
||||
-- Add and register airbase.
|
||||
local airbase=self:AddAirbase( DCSAirbaseName )
|
||||
@ -1065,20 +1080,23 @@ function DATABASE:_EventOnBirth( Event )
|
||||
|
||||
if Event.IniDCSUnit then
|
||||
|
||||
if Event.IniObjectCategory == 3 then
|
||||
if Event.IniObjectCategory == Object.Category.STATIC then
|
||||
|
||||
-- Add static object to DB.
|
||||
self:AddStatic( Event.IniDCSUnitName )
|
||||
|
||||
else
|
||||
|
||||
if Event.IniObjectCategory == 1 then
|
||||
if Event.IniObjectCategory == Object.Category.UNIT then
|
||||
|
||||
-- Add unit and group to DB.
|
||||
self:AddUnit( Event.IniDCSUnitName )
|
||||
self:AddGroup( Event.IniDCSGroupName )
|
||||
|
||||
-- Add airbase if it was spawned later in the mission.
|
||||
-- A unit can also be an airbase (e.g. ships).
|
||||
local DCSAirbase = Airbase.getByName(Event.IniDCSUnitName)
|
||||
if DCSAirbase then
|
||||
-- Add airbase if it was spawned later in the mission.
|
||||
self:I(string.format("Adding airbase %s", tostring(Event.IniDCSUnitName)))
|
||||
self:AddAirbase(Event.IniDCSUnitName)
|
||||
end
|
||||
@ -1086,7 +1104,7 @@ function DATABASE:_EventOnBirth( Event )
|
||||
end
|
||||
end
|
||||
|
||||
if Event.IniObjectCategory == 1 then
|
||||
if Event.IniObjectCategory == Object.Category.UNIT then
|
||||
|
||||
Event.IniUnit = self:FindUnit( Event.IniDCSUnitName )
|
||||
Event.IniGroup = self:FindGroup( Event.IniDCSGroupName )
|
||||
|
||||
@ -1130,7 +1130,7 @@ function EVENT:onEvent( Event )
|
||||
Event.IniUnitName = Event.IniDCSUnitName
|
||||
Event.IniDCSGroup = Event.IniDCSUnit:getGroup()
|
||||
Event.IniUnit = UNIT:FindByName( Event.IniDCSUnitName )
|
||||
|
||||
|
||||
if not Event.IniUnit then
|
||||
-- Unit can be a CLIENT. Most likely this will be the case ...
|
||||
Event.IniUnit = CLIENT:FindByName( Event.IniDCSUnitName, '', true )
|
||||
@ -1165,8 +1165,7 @@ function EVENT:onEvent( Event )
|
||||
if Event.IniObjectCategory == Object.Category.SCENERY then
|
||||
---
|
||||
-- Scenery
|
||||
---
|
||||
|
||||
---
|
||||
Event.IniDCSUnit = Event.initiator
|
||||
Event.IniDCSUnitName = Event.IniDCSUnit:getName()
|
||||
Event.IniUnitName = Event.IniDCSUnitName
|
||||
@ -1186,6 +1185,12 @@ function EVENT:onEvent( Event )
|
||||
Event.IniCoalition = Event.IniDCSUnit:getCoalition()
|
||||
Event.IniCategory = Event.IniDCSUnit:getDesc().category
|
||||
Event.IniTypeName = Event.IniDCSUnit:getTypeName()
|
||||
|
||||
-- If the airbase does not exist in the DB, we add it (e.g. when FARPS are spawned).
|
||||
if not Event.IniUnit then
|
||||
_DATABASE:_RegisterAirbase(Event.initiator)
|
||||
Event.IniUnit = AIRBASE:FindByName(Event.IniDCSUnitName)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -467,7 +467,7 @@ function SPAWNSTATIC:_SpawnStatic(Template, CountryID)
|
||||
self:T(Template)
|
||||
|
||||
-- Add static to the game.
|
||||
local Static=nil
|
||||
local Static=nil --DCS#StaticObject
|
||||
|
||||
if self.InitFarp then
|
||||
|
||||
@ -487,6 +487,17 @@ function SPAWNSTATIC:_SpawnStatic(Template, CountryID)
|
||||
|
||||
-- ED's dirty way to spawn FARPS.
|
||||
Static=coalition.addGroup(CountryID, -1, TemplateGroup)
|
||||
|
||||
-- Currently DCS 2.8 does not trigger birth events if FAPRS are spawned!
|
||||
-- We create such an event. The airbase is registered in Core.Event
|
||||
local Event = {
|
||||
id = EVENTS.Birth,
|
||||
time = timer.getTime(),
|
||||
initiator = Static
|
||||
}
|
||||
-- Create BIRTH event.
|
||||
world.onEvent(Event)
|
||||
|
||||
else
|
||||
self:T("Spawning Static")
|
||||
self:T2({Template=Template})
|
||||
|
||||
@ -341,9 +341,23 @@ do -- coalition
|
||||
-- @field RED
|
||||
-- @field BLUE
|
||||
|
||||
--- @function [parent=#coalition] getCountryCoalition
|
||||
-- @param #number countryId
|
||||
-- @return #number coalitionId
|
||||
--- Get country coalition.
|
||||
-- @function [parent=#coalition] getCountryCoalition
|
||||
-- @param #number countryId Country ID.
|
||||
-- @return #number coalitionId Coalition ID.
|
||||
|
||||
--- Dynamically spawns a group. See [hoggit](https://wiki.hoggitworld.com/view/DCS_func_addGroup)
|
||||
-- @function [parent=#coalition] addGroup
|
||||
-- @param #number countryId Id of the country.
|
||||
-- @param #number groupCategory Group category. Set -1 for spawning FARPS.
|
||||
-- @param #table groupData Group data table.
|
||||
-- @return DCS#Group The spawned Group object.
|
||||
|
||||
--- Dynamically spawns a static object. See [hoggit](https://wiki.hoggitworld.com/view/DCS_func_addGroup)
|
||||
-- @function [parent=#coalition] addStaticObject
|
||||
-- @param #number countryId Id of the country.
|
||||
-- @param #table groupData Group data table.
|
||||
-- @return DCS#Static The spawned static object.
|
||||
|
||||
coalition = {} -- #coalition
|
||||
|
||||
@ -1294,6 +1308,42 @@ do -- Group
|
||||
|
||||
end -- Group
|
||||
|
||||
do -- StaticObject
|
||||
|
||||
--- Represents a static object.
|
||||
-- @type StaticObject
|
||||
-- @extends DCS#Object
|
||||
|
||||
--- Returns the static object.
|
||||
-- @function [parent=#StaticObject] getByName
|
||||
-- @param #string name Name of the static object.
|
||||
-- @return #StaticObject
|
||||
|
||||
StaticObject = {} --#StaticObject
|
||||
|
||||
end
|
||||
|
||||
do --Event
|
||||
|
||||
--- Event structure. Note that present fields depend on type of event.
|
||||
-- @type Event
|
||||
-- @field #number id Event ID.
|
||||
-- @field #number time Mission time in seconds.
|
||||
-- @field DCS#Unit initiator Unit initiating the event.
|
||||
-- @field DCS#Unit target Target unit.
|
||||
-- @field DCS#Airbase place Airbase.
|
||||
-- @field number subPlace Subplace. Unknown and often just 0.
|
||||
-- @field #string weapon_name Weapoin name.
|
||||
-- @field #number idx Mark ID.
|
||||
-- @field #number coalition Coalition ID.
|
||||
-- @field #number groupID Group ID, *e.g.* of group that added mark point.
|
||||
-- @field #string text Text, *e.g.* of mark point.
|
||||
-- @field DCS#Vec3 pos Position vector, *e.g.* of mark point.
|
||||
-- @field #string comment Comment, *e.g.* LSO score.
|
||||
|
||||
Event={} --#Event
|
||||
|
||||
end
|
||||
|
||||
do -- AI
|
||||
|
||||
|
||||
@ -685,6 +685,9 @@ function AIRBASE:Register(AirbaseName)
|
||||
else
|
||||
self:E(string.format("ERROR: Cound not get position Vec2 of airbase %s", AirbaseName))
|
||||
end
|
||||
|
||||
-- Debug info.
|
||||
self:T2(string.format("Registered airbase %s", tostring(self.AirbaseName)))
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user