mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Fixed the respawn problem and reworked the test mission directory structure
This commit is contained in:
@@ -80,14 +80,18 @@ Include.File( "Zone" )
|
||||
-- @type SPAWN
|
||||
-- @extends Base#BASE
|
||||
-- @field ClassName
|
||||
-- @field #string SpawnTemplatePrefix
|
||||
-- @field #string SpawnAliasPrefix
|
||||
SPAWN = {
|
||||
ClassName = "SPAWN",
|
||||
SpawnTemplatePrefix = nil,
|
||||
SpawnAliasPrefix = nil,
|
||||
}
|
||||
|
||||
|
||||
|
||||
--- Creates the main object to spawn a GROUP defined in the DCS ME.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @param #string SpawnTemplatePrefix is the name of the Group in the ME that defines the Template. Each new group will have the name starting with SpawnTemplatePrefix.
|
||||
-- @return #SPAWN
|
||||
-- @usage
|
||||
@@ -128,7 +132,7 @@ function SPAWN:New( SpawnTemplatePrefix )
|
||||
end
|
||||
|
||||
--- Creates a new SPAWN instance to create new groups based on the defined template and using a new alias for each new group.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @param #string SpawnTemplatePrefix is the name of the Group in the ME that defines the Template.
|
||||
-- @param #string SpawnAliasPrefix is the name that will be given to the Group at runtime.
|
||||
-- @return #SPAWN
|
||||
@@ -175,7 +179,7 @@ end
|
||||
-- Note that this method is exceptionally important to balance the performance of the mission. Depending on the machine etc, a mission can only process a maximum amount of units.
|
||||
-- If the time interval must be short, but there should not be more Units or Groups alive than a maximum amount of units, then this function should be used...
|
||||
-- When a @{#SPAWN.New} is executed and the limit of the amount of units alive is reached, then no new spawn will happen of the group, until some of these units of the spawn object will be destroyed.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @param #number SpawnMaxUnitsAlive The maximum amount of units that can be alive at runtime.
|
||||
-- @param #number SpawnMaxGroups The maximum amount of groups that can be spawned. When the limit is reached, then no more actual spawns will happen of the group.
|
||||
-- This parameter is useful to define a maximum amount of airplanes, ground troops, helicopters, ships etc within a supply area.
|
||||
@@ -201,7 +205,7 @@ end
|
||||
|
||||
|
||||
--- Randomizes the defined route of the SpawnTemplatePrefix group in the ME. This is very useful to define extra variation of the behaviour of groups.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @param #number SpawnStartPoint is the waypoint where the randomization begins.
|
||||
-- Note that the StartPoint = 0 equaling the point where the group is spawned.
|
||||
-- @param #number SpawnEndPoint is the waypoint where the randomization ends counting backwards.
|
||||
@@ -234,7 +238,7 @@ end
|
||||
-- This function becomes useful when you need to spawn groups with random templates of groups defined within the mission editor,
|
||||
-- but they will all follow the same Template route and have the same prefix name.
|
||||
-- In other words, this method randomizes between a defined set of groups the template to be used for each new spawn of a group.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @param #string SpawnTemplatePrefixTable A table with the names of the groups defined within the mission editor, from which one will be choosen when a new group will be spawned.
|
||||
-- @return #SPAWN
|
||||
-- @usage
|
||||
@@ -271,7 +275,7 @@ end
|
||||
-- This will enable a spawned group to be re-spawned after it lands, until it is destroyed...
|
||||
-- Note: When the group is respawned, it will re-spawn from the original airbase where it took off.
|
||||
-- So ensure that the routes for groups that respawn, always return to the original airbase, or players may get confused ...
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @return #SPAWN self
|
||||
-- @usage
|
||||
-- -- RU Su-34 - AI Ship Attack
|
||||
@@ -321,7 +325,7 @@ end
|
||||
|
||||
--- CleanUp groups when they are still alive, but inactive.
|
||||
-- When groups are still alive and have become inactive due to damage and are unable to contribute anything, then this group will be removed at defined intervals in seconds.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @param #string SpawnCleanUpInterval The interval to check for inactive groups within seconds.
|
||||
-- @return #SPAWN self
|
||||
-- @usage Spawn_Helicopter:CleanUp( 20 ) -- CleanUp the spawning of the helicopters every 20 seconds when they become inactive.
|
||||
@@ -339,7 +343,7 @@ end
|
||||
|
||||
--- Makes the groups visible before start (like a batallion).
|
||||
-- The method will take the position of the group as the first position in the array.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @param #number SpawnAngle The angle in degrees how the groups and each unit of the group will be positioned.
|
||||
-- @param #number SpawnWidth The amount of Groups that will be positioned on the X axis.
|
||||
-- @param #number SpawnDeltaX The space between each Group on the X-axis.
|
||||
@@ -394,7 +398,7 @@ end
|
||||
|
||||
--- Will spawn a group based on the internal index.
|
||||
-- Note: Uses @{DATABASE} module defined in MOOSE.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @return Group#GROUP The group that was spawned. You can use this group for further actions.
|
||||
function SPAWN:Spawn()
|
||||
self:F( { self.SpawnTemplatePrefix, self.SpawnIndex } )
|
||||
@@ -404,7 +408,7 @@ end
|
||||
|
||||
--- Will re-spawn a group based on a given index.
|
||||
-- Note: Uses @{DATABASE} module defined in MOOSE.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @param #string SpawnIndex The index of the group to be spawned.
|
||||
-- @return Group#GROUP The group that was spawned. You can use this group for further actions.
|
||||
function SPAWN:ReSpawn( SpawnIndex )
|
||||
@@ -414,10 +418,11 @@ function SPAWN:ReSpawn( SpawnIndex )
|
||||
SpawnIndex = 1
|
||||
end
|
||||
|
||||
--local SpawnGroup = self:GetGroupFromIndex( SpawnIndex ):GetDCSGroup()
|
||||
--if SpawnGroup then
|
||||
--DCSGroup:destroy()
|
||||
--end
|
||||
local SpawnGroup = self:GetGroupFromIndex( SpawnIndex )
|
||||
local SpawnDCSGroup = SpawnGroup:GetDCSGroup()
|
||||
if SpawnDCSGroup then
|
||||
SpawnGroup:Destroy()
|
||||
end
|
||||
|
||||
return self:SpawnWithIndex( SpawnIndex )
|
||||
end
|
||||
@@ -452,7 +457,7 @@ end
|
||||
|
||||
--- Spawns new groups at varying time intervals.
|
||||
-- This is useful if you want to have continuity within your missions of certain (AI) groups to be present (alive) within your missions.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @param #number SpawnTime The time interval defined in seconds between each new spawn of new groups.
|
||||
-- @param #number SpawnTimeVariation The variation to be applied on the defined time interval between each new spawn.
|
||||
-- The variation is a number between 0 and 1, representing the %-tage of variation to be applied on the time interval.
|
||||
@@ -516,7 +521,7 @@ end
|
||||
--- Will spawn a group from a hosting unit. This function is mostly advisable to be used if you want to simulate spawning from air units, like helicopters, which are dropping infantry into a defined Landing Zone.
|
||||
-- Note that each point in the route assigned to the spawning group is reset to the point of the spawn.
|
||||
-- You can use the returned group to further define the route to be followed.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @param Unit#UNIT HostUnit The air or ground unit dropping or unloading the group.
|
||||
-- @param #number OuterRadius The outer radius in meters where the new group will be spawned.
|
||||
-- @param #number InnerRadius The inner radius in meters where the new group will NOT be spawned.
|
||||
@@ -593,7 +598,7 @@ function SPAWN:SpawnFromUnit( HostUnit, OuterRadius, InnerRadius, SpawnIndex )
|
||||
end
|
||||
|
||||
--- Will spawn a Group within a given @{ZONE}.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @param #ZONE Zone The zone where the group is to be spawned.
|
||||
-- @param #number SpawnIndex (Optional) The index which group to spawn within the given zone.
|
||||
-- @return Group#GROUP that was spawned.
|
||||
@@ -667,7 +672,7 @@ end
|
||||
|
||||
|
||||
--- Will return the SpawnGroupName either with with a specific count number or without any count.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @param #number SpawnIndex Is the number of the Group that is to be spawned.
|
||||
-- @return #string SpawnGroupName
|
||||
function SPAWN:SpawnGroupName( SpawnIndex )
|
||||
@@ -690,7 +695,7 @@ function SPAWN:SpawnGroupName( SpawnIndex )
|
||||
end
|
||||
|
||||
--- Find the first alive group.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @param #number SpawnCursor A number holding the index from where to find the first group from.
|
||||
-- @return Group#GROUP, #number The group found, the new index where the group was found.
|
||||
-- @return #nil, #nil When no group is found, #nil is returned.
|
||||
@@ -710,7 +715,7 @@ end
|
||||
|
||||
|
||||
--- Find the next alive group.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @param #number SpawnCursor A number holding the last found previous index.
|
||||
-- @return Group#GROUP, #number The group found, the new index where the group was found.
|
||||
-- @return #nil, #nil When no group is found, #nil is returned.
|
||||
@@ -751,7 +756,7 @@ end
|
||||
--- Get the group from an index.
|
||||
-- Returns the group from the SpawnGroups list.
|
||||
-- If no index is given, it will return the first group in the list.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @param #number SpawnIndex The index of the group to return.
|
||||
-- @return Group#GROUP
|
||||
function SPAWN:GetGroupFromIndex( SpawnIndex )
|
||||
@@ -769,7 +774,7 @@ end
|
||||
--- Get the group index from a DCSUnit.
|
||||
-- The method will search for a #-mark, and will return the index behind the #-mark of the DCSUnit.
|
||||
-- It will return nil of no prefix was found.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @param DCSUnit The DCS unit to be searched.
|
||||
-- @return #string The prefix
|
||||
-- @return #nil Nothing found
|
||||
@@ -793,7 +798,7 @@ end
|
||||
--- Return the prefix of a DCSUnit.
|
||||
-- The method will search for a #-mark, and will return the text before the #-mark.
|
||||
-- It will return nil of no prefix was found.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @param DCSUnit The DCS unit to be searched.
|
||||
-- @return #string The prefix
|
||||
-- @return #nil Nothing found
|
||||
@@ -964,7 +969,7 @@ function SPAWN:_Prepare( SpawnTemplatePrefix, SpawnIndex )
|
||||
end
|
||||
|
||||
--- Internal function randomizing the routes.
|
||||
-- @param self
|
||||
-- @param #SPAWN self
|
||||
-- @param #number SpawnIndex The index of the group to be spawned.
|
||||
-- @return #SPAWN
|
||||
function SPAWN:_RandomizeRoute( SpawnIndex )
|
||||
@@ -1096,7 +1101,7 @@ end
|
||||
--- Obscolete
|
||||
-- @todo Need to delete this... _Database does this now ...
|
||||
function SPAWN:_OnDeadOrCrash( event )
|
||||
|
||||
self:F( self.SpawnTemplatePrefix, event )
|
||||
|
||||
if event.initiator and event.initiator:getName() then
|
||||
local EventPrefix = self:_GetPrefixFromDCSUnit( event.initiator )
|
||||
@@ -1116,6 +1121,7 @@ end
|
||||
-- This is needed to ensure that Re-SPAWNing only is done for landed AIR Groups.
|
||||
-- @todo Need to test for AIR Groups only...
|
||||
function SPAWN:_OnTakeOff( event )
|
||||
self:F( self.SpawnTemplatePrefix, event )
|
||||
|
||||
if event.initiator and event.initiator:getName() then
|
||||
local SpawnGroup = self:_GetGroupFromDCSUnit( event.initiator )
|
||||
@@ -1131,11 +1137,13 @@ end
|
||||
-- This is needed to ensure that Re-SPAWNing is only done for landed AIR Groups.
|
||||
-- @todo Need to test for AIR Groups only...
|
||||
function SPAWN:_OnLand( event )
|
||||
self:F( self.SpawnTemplatePrefix, event )
|
||||
|
||||
if event.initiator and event.initiator:getName() then
|
||||
local SpawnGroup = self:_GetGroupFromDCSUnit( event.initiator )
|
||||
local SpawnUnit = event.initiator
|
||||
if SpawnUnit and SpawnUnit:isExist() and Object.getCategory(SpawnUnit) == Object.Category.UNIT then
|
||||
local SpawnGroup = self:_GetGroupFromDCSUnit( SpawnUnit )
|
||||
if SpawnGroup then
|
||||
self:T( { "Landed event:" .. event.initiator:getName(), event } )
|
||||
self:T( { "Landed event:" .. SpawnUnit:getName(), event } )
|
||||
self.Landed = true
|
||||
self:T( "self.Landed = true" )
|
||||
if self.Landed and self.RepeatOnLanding then
|
||||
@@ -1150,15 +1158,18 @@ end
|
||||
--- Will detect AIR Units shutting down their engines ...
|
||||
-- When the event takes place, and the method @{RepeatOnEngineShutDown} was called, the spawned Group will Re-SPAWN.
|
||||
-- But only when the Unit was registered to have landed.
|
||||
-- @param #SPAWN self
|
||||
-- @see _OnTakeOff
|
||||
-- @see _OnLand
|
||||
-- @todo Need to test for AIR Groups only...
|
||||
function SPAWN:_OnLand( event )
|
||||
function SPAWN:_OnEngineShutDown( event )
|
||||
self:F( self.SpawnTemplatePrefix, event )
|
||||
|
||||
if event.initiator and event.initiator:getName() then
|
||||
local SpawnGroup = self:_GetGroupFromDCSUnit( event.initiator )
|
||||
local SpawnUnit = event.initiator
|
||||
if SpawnUnit and SpawnUnit:isExist() and Object.getCategory(SpawnUnit) == Object.Category.UNIT then
|
||||
local SpawnGroup = self:_GetGroupFromDCSUnit( SpawnUnit )
|
||||
if SpawnGroup then
|
||||
self:T( { "EngineShutDown event: " .. event.initiator:getName(), event } )
|
||||
self:T( { "EngineShutDown event: " .. SpawnUnit:getName(), event } )
|
||||
if self.Landed and self.RepeatOnEngineShutDown then
|
||||
local SpawnGroupIndex = self:GetSpawnIndexFromGroup( SpawnGroup )
|
||||
self:T( { "EngineShutDown: ", "ReSpawn:", SpawnGroup:GetName(), SpawnGroupIndex } )
|
||||
@@ -1199,8 +1210,8 @@ function SPAWN:_SpawnCleanUpScheduler()
|
||||
while SpawnGroup do
|
||||
|
||||
if SpawnGroup:AllOnGround() and SpawnGroup:GetMaxVelocity() < 1 then
|
||||
if not self.SpawnCleanUpTimeStamps[SpawnGroup:GetName()] then
|
||||
self.SpawnCleanUpTimeStamps[SpawnGroup:GetName()] = timer.getTime()
|
||||
if not self.SpanUwnCleanUpTimeStamps[SpawnGroup:GetName()] then
|
||||
self.SpawnCleapTimeStamps[SpawnGroup:GetName()] = timer.getTime()
|
||||
else
|
||||
if self.SpawnCleanUpTimeStamps[SpawnGroup:GetName()] + self.SpawnCleanUpInterval < timer.getTime() then
|
||||
self:T( { "CleanUp Scheduler:", "Cleaning:", SpawnGroup } )
|
||||
|
||||
Reference in New Issue
Block a user