Merge pull request #8 from svenvandevelde/SPAWN_Create_Visible_Array

Spawn create visible array
This commit is contained in:
Sven Van de Velde 2016-03-11 12:26:21 +01:00
commit e396353cc7
21 changed files with 11541 additions and 723 deletions

View File

@ -0,0 +1,31 @@
rem Generate Moose_Embedded.lua
copy Trace.lua ^
+ Routines.lua ^
+ Base.lua ^
+ Menu.lua ^
+ Group.lua ^
+ Unit.lua ^
+ Zone.lua ^
+ Database.lua ^
+ Cargo.lua ^
+ Client.lua ^
+ Message.lua ^
+ Stage.lua ^
+ Task.lua ^
+ GoHomeTask.lua ^
+ DestroyBaseTask.lua ^
+ DestroyGroupsTask.lua ^
+ DestroyRadarsTask.lua ^
+ DestroyUnitTypesTask.lua ^
+ PickupTask.lua ^
+ DeployTask.lua ^
+ NoTask.lua ^
+ RouteTask.lua ^
+ Mission.lua ^
+ CleanUp.lua ^
+ Spawn.lua ^
+ Movement.lua ^
+ Sead.lua ^
Moose_Embedded.lua

View File

@ -1,159 +0,0 @@
local base = _G
local MOOSE_Version = "0.1.1.1"
env.info("Loading MOOSE " .. base.timer.getAbsTime() )
function script_path()
local str = debug.getinfo(2, "S").source
return str:match("(.*/)"):sub(1,-2):gsub("\\","/")
end
Include = {}
Include.ProgramPath = "Scripts/Moose/Moose/"
Include.MissionPath = script_path()
env.info( "Include.ProgramPath = " .. Include.ProgramPath)
env.info( "Include.MissionPath = " .. Include.MissionPath)
Include.Files = {}
Include.FileIn = function(fileName, table)
-- env.info( fileName )
local chunk, errMsg = base.loadfile(fileName)
if chunk ~= nil then
env.info( "chunk assigned " )
env.info( Include.oneLineSerialize( chunk ) )
base.setfenv(chunk, table)
chunk()
if table.MOOSE_Version then
env.info( table.MOOSE_Version )
end
return chunk
else
return nil, errMsg
end
end
Include.MisFiles = {}
Include.FileName = function( num )
local hexstr = '0123456789ABCDEF'
local s = ''
while num > 0 do
local mod = math.fmod(num, 16)
s = string.sub(hexstr, mod+1, mod+1) .. s
num = math.floor(num / 16)
end
if s == '' then s = '0' end
-- env.info( string.format( "~mis" .. "%8s", "00000000" .. s ) )
return string.format( "~mis" .. "%s", string.sub( "00000000" .. s, -8 ) )
end
Include.ScanFiles = function()
local i = 0
while i <= 32767 do
local FileName = Include.FileName( i )
local FileChunk = {}
local FileChunk = Include.FileIn( Include.MissionPath .. FileName, FileChunk )
if FileChunk then
end
i = i + 1
end
end
Include.File = function( IncludeFile )
if not Include.Files[ IncludeFile ] then
Include.Files[IncludeFile] = IncludeFile
env.info( "Include:" .. IncludeFile .. " from " .. Include.ProgramPath )
local f = base.loadfile( Include.ProgramPath .. IncludeFile .. ".lua" )
if f == nil then
env.info( "Include:" .. IncludeFile .. " from " .. Include.MissionPath )
local f = base.loadfile( Include.MissionPath .. IncludeFile .. ".lua" )
if f == nil then
error ("Could not load MOOSE file " .. IncludeFile .. ".lua" )
else
env.info( "Include:" .. IncludeFile .. " loaded from " .. Include.MissionPath )
return f()
end
else
env.info( "Include:" .. IncludeFile .. " loaded from " .. Include.ProgramPath )
return f()
end
end
end
--porting in Slmod's "safestring" basic serialize
Include.basicSerialize = function(s)
if s == nil then
return "\"\""
else
if ((type(s) == 'number') or (type(s) == 'boolean') or (type(s) == 'function') or (type(s) == 'table') or (type(s) == 'userdata') ) then
return tostring(s)
elseif type(s) == 'string' then
s = string.format('%q', s)
return s
end
end
end
-- porting in Slmod's serialize_slmod2
Include.oneLineSerialize = function(tbl) -- serialization of a table all on a single line, no comments, made to replace old get_table_string function
if type(tbl) == 'table' then --function only works for tables!
local tbl_str = {}
tbl_str[#tbl_str + 1] = '{'
for ind,val in pairs(tbl) do -- serialize its fields
if type(ind) == "number" then
tbl_str[#tbl_str + 1] = '['
tbl_str[#tbl_str + 1] = tostring(ind)
tbl_str[#tbl_str + 1] = ']='
else --must be a string
tbl_str[#tbl_str + 1] = '['
tbl_str[#tbl_str + 1] = Include.basicSerialize(ind)
tbl_str[#tbl_str + 1] = ']='
end
if ((type(val) == 'number') or (type(val) == 'boolean')) then
tbl_str[#tbl_str + 1] = tostring(val)
tbl_str[#tbl_str + 1] = ','
elseif type(val) == 'string' then
tbl_str[#tbl_str + 1] = Include.basicSerialize(val)
tbl_str[#tbl_str + 1] = ','
elseif type(val) == 'nil' then -- won't ever happen, right?
tbl_str[#tbl_str + 1] = 'nil,'
elseif type(val) == 'table' then
if ind == "__index" then
tbl_str[#tbl_str + 1] = "__index"
tbl_str[#tbl_str + 1] = ',' --I think this is right, I just added it
else
tbl_str[#tbl_str + 1] = Include.oneLineSerialize(val)
tbl_str[#tbl_str + 1] = ',' --I think this is right, I just added it
end
elseif type(val) == 'function' then
tbl_str[#tbl_str + 1] = "function " .. tostring(ind)
tbl_str[#tbl_str + 1] = ',' --I think this is right, I just added it
else
env.info('unable to serialize value type ' .. Include.basicSerialize(type(val)) .. ' at index ' .. tostring(ind))
env.info( debug.traceback() )
end
end
tbl_str[#tbl_str + 1] = '}'
return table.concat(tbl_str)
else
return tostring(tbl)
end
end
Include.ScanFiles( )
Include.File( "Database" )
env.info("Loaded MOOSE Include Engine")

View File

@ -6,13 +6,21 @@ Include.File( "Routines" )
_TraceOn = true
_TraceClass = {
DATABASE = true,
--DATABASE = true,
--SEAD = true,
--DESTROYBASETASK = true,
--MOVEMENT = true,
--SPAWN = true,
--GROUP = true,
--UNIT = true,
SPAWN = true,
STAGE = true,
ZONE = true,
GROUP = true,
UNIT = true,
--CLIENT = true,
--CARGO = true,
CARGO_GROUP = true,
--CARGO_PACKAGE = true,
--CARGO_SLINGLOAD = true,
CARGO_ZONE = true,
}
BASE = {

View File

@ -40,7 +40,6 @@ self:T( { CargoZoneName, CargoHostName } )
if CargoHostName then
self.CargoHostName = CargoHostName
self.CargoHostSpawn = SPAWN:New( CargoHostName )
end
self:T( self.CargoZone )
@ -49,33 +48,35 @@ self:T( { CargoZoneName, CargoHostName } )
end
function CARGO_ZONE:Spawn()
self:T( CargoHostSpawn )
self:T( self.CargoHostName )
if self.CargoHostSpawn then
local CargoHostGroup = Group.getByName( self.CargoHostSpawn:SpawnGroupName() )
if CargoHostGroup then
if not CargoHostGroup:isExist() then
self.CargoHostSpawn:ReSpawn()
local CargoHostGroup = self.CargoHostSpawn:GetGroupFromIndex()
if CargoHostGroup and CargoHostGroup:IsAlive() then
else
self.CargoHostSpawn:ReSpawn( 1 )
end
else
self.CargoHostSpawn:ReSpawn()
end
self:T( "Initialize CargoHostSpawn" )
self.CargoHostSpawn = SPAWN:New( self.CargoHostName )
self.CargoHostSpawn:ReSpawn( 1 )
end
return self
end
function CARGO_ZONE:GetHostUnit()
self:T( self )
if self.CargoHostName then
-- A Host has been given, signal the host
local CargoHostGroup = Group.getByName( self.CargoHostSpawn:SpawnGroupName() )
local CargoHostGroup = self.CargoHostSpawn:GetGroupFromIndex()
local CargoHostUnit
if CargoHostGroup == nil then
CargoHostUnit = StaticObject.getByName( self.CargoHostName )
if CargoHostGroup and CargoHostGroup:IsAlive() then
CargoHostUnit = CargoHostGroup:GetUnit(1)
else
CargoHostUnit = CargoHostGroup:getUnits()[1]
CargoHostUnit = StaticObject.getByName( self.CargoHostName )
end
return CargoHostUnit
@ -129,7 +130,7 @@ self:T()
if SignalUnit then
self:T( 'Signalling Unit' )
local SignalVehiclePos = SignalUnit:getPosition().p
local SignalVehiclePos = SignalUnit:GetPositionVec3()
SignalVehiclePos.y = SignalVehiclePos.y + 2
if self.SignalType.ID == CARGO_ZONE.SIGNAL.TYPE.SMOKE.ID then
@ -251,12 +252,17 @@ end
function CARGO_ZONE:GetCargoHostUnit()
self:T()
self:T( self )
local CargoHostUnit = Group.getByName( self.CargoHostSpawn:SpawnGroupName() ):getUnit(1)
if CargoHostUnit and CargoHostUnit:isExist() then
if self.CargoHostSpawn then
local CargoHostGroup = self.CargoHostSpawn:GetGroupFromIndex(1)
if CargoHostGroup and CargoHostGroup:IsAlive() then
local CargoHostUnit = CargoHostGroup:GetUnit(1)
if CargoHostUnit and CargoHostUnit:IsAlive() then
return CargoHostUnit
end
end
end
return nil
end
@ -347,7 +353,7 @@ self:T()
local Valid = true
self.CargoClient = Client
local ClientUnit = Client:GetClientGroupUnit()
local ClientUnit = Client:GetClientGroupDCSUnit()
return Valid
end
@ -451,7 +457,7 @@ CARGO_GROUP = {
function CARGO_GROUP:New( CargoType, CargoName, CargoWeight, CargoGroupTemplate, CargoZone ) local self = BASE:Inherit( self, CARGO:New( CargoType, CargoName, CargoWeight ) )
self:T( { CargoType, CargoName, CargoWeight, CargoGroupTemplate, CargoZone } )
self.CargoSpawn = SPAWN:New( CargoGroupTemplate )
self.CargoSpawn = SPAWN:NewWithAlias( CargoGroupTemplate, CargoName )
self.CargoZone = CargoZone
CARGOS[self.CargoName] = self
@ -499,10 +505,10 @@ self:T()
if SpawnCargo then
if self.CargoZone:GetCargoHostUnit() then
--- ReSpawn the Cargo from the CargoHost
self.CargoGroupName = self.CargoSpawn:FromHost( self.CargoZone:GetCargoHostUnit(), 60, 30, self.CargoName, false ).name
self.CargoGroupName = self.CargoSpawn:SpawnFromUnit( self.CargoZone:GetCargoHostUnit(), 60, 30 ):GetName()
else
--- ReSpawn the Cargo in the CargoZone without a host ...
self.CargoGroupName = self.CargoSpawn:InZone( self.CargoZone:GetCargoZoneName(), self.CargoName ).name
self.CargoGroupName = self.CargoSpawn:SpawnInZone( self.CargoZone ):GetName()
end
self:StatusNone()
end
@ -534,7 +540,7 @@ self:T()
local Valid = true
local ClientUnit = Client:GetClientGroupUnit()
local ClientUnit = Client:GetClientGroupDCSUnit()
local CarrierPos = ClientUnit:getPoint()
local CarrierPosMove = ClientUnit:getPoint()
@ -630,7 +636,9 @@ self:T()
self:T( 'self.CargoName = ' .. self.CargoName )
self:T( 'self.CargoGroupName = ' .. self.CargoGroupName )
self.CargoSpawn:FromCarrier( Client:GetClientGroupUnit(), TargetZoneName, self.CargoGroupName )
--self.CargoSpawn:FromCarrier( Client:GetClientGroupDCSUnit(), TargetZoneName, self.CargoGroupName )
self.CargoSpawn:SpawnFromUnit( Client:GetClientGroupUnit(), self.CargoGroupName ):RouteToZone( ZONE:New( TargetZoneName ), true )
self:StatusUnLoaded()
@ -645,7 +653,7 @@ CARGO_PACKAGE = {
function CARGO_PACKAGE:New( CargoType, CargoName, CargoWeight, CargoClient ) local self = BASE:Inherit( self, CARGO:New( CargoType, CargoName, CargoWeight ) )
self:T( { CargoType, CargoName, CargoWeight, CargoClient.ClientName } )
self:T( { CargoType, CargoName, CargoWeight, CargoClient } )
self.CargoClient = CargoClient
@ -657,16 +665,16 @@ end
function CARGO_PACKAGE:Spawn()
self:T()
self:T( self )
-- this needs to be checked thoroughly
local CargoClientInitGroup = self.CargoClient:ClientGroup()
if not CargoClientInitGroup then
if not self.CargoClientInitGroupSpawn then
self.CargoClientInitGroupSpawn = SPAWN:New( self.CargoClient:GetClientGroupName() )
local CargoClientGroup = self.CargoClient:ClientGroup()
if not CargoClientGroup then
if not self.CargoClientSpawn then
self.CargoClientSpawn = SPAWN:New( self.CargoClient:GetClientGroupName() )
end
self.CargoClientInitGroupSpawn:Spawn( self.CargoClient:GetClientGroupName() )
self.CargoClientSpawn:ReSpawn( 1 )
end
local SpawnCargo = true
@ -705,7 +713,7 @@ self:T()
self:T( self.CargoClient.ClientName )
self:T( 'Client Exists.' )
if routines.IsUnitInRadius( self.CargoClient:GetClientGroupUnit(), Client:ClientPosition(), 150 ) then
if routines.IsUnitInRadius( self.CargoClient:GetClientGroupDCSUnit(), Client:ClientPosition(), 150 ) then
Near = true
end
end
@ -720,7 +728,7 @@ self:T()
local Valid = true
local ClientUnit = Client:GetClientGroupUnit()
local ClientUnit = Client:GetClientGroupDCSUnit()
local CarrierPos = ClientUnit:getPoint()
local CarrierPosMove = ClientUnit:getPoint()
@ -812,7 +820,7 @@ self:T()
local OnBoarded = false
if self.CargoClient and self.CargoClient:ClientGroup() then
if routines.IsUnitInRadius( self.CargoClient:GetClientGroupUnit(), self.CargoClient:ClientPosition(), 10 ) then
if routines.IsUnitInRadius( self.CargoClient:GetClientGroupDCSUnit(), self.CargoClient:ClientPosition(), 10 ) then
-- Switch Cargo from self.CargoClient to Client ... Each cargo can have only one client. So assigning the new client for the cargo is enough.
self:StatusLoaded( Client )

View File

@ -175,6 +175,24 @@ self:T()
local ClientGroup = self:ClientGroup()
if ClientGroup then
if ClientGroup:isExist() then
return UNIT:New( ClientGroup:getUnit(1) )
else
return UNIT:New( self.ClientGroupUnit )
end
end
return nil
end
--- Returns the DCSUnit of the @{CLIENT}.
-- @treturn DCSUnit
function CLIENT:GetClientGroupDCSUnit()
self:T()
local ClientGroup = self:ClientGroup()
if ClientGroup then
if ClientGroup:isExist() then
return ClientGroup:getUnits()[1]
@ -189,7 +207,7 @@ end
function CLIENT:GetUnit()
self:T()
return UNIT:New( self:GetClientGroupUnit() )
return UNIT:New( self:GetClientGroupDCSUnit() )
end
@ -198,7 +216,7 @@ end
function CLIENT:ClientPosition()
--self:T()
ClientGroupUnit = self:GetClientGroupUnit()
ClientGroupUnit = self:GetClientGroupDCSUnit()
if ClientGroupUnit then
if ClientGroupUnit:isExist() then
@ -294,7 +312,7 @@ self:T()
end
MESSAGE:New( Message, MessageCategory, MessageDuration, MessageId ):ToClient( self )
else
if self:GetClientGroupUnit() and not self:GetClientGroupUnit():inAir() then
if self:GetClientGroupDCSUnit() and not self:GetClientGroupDCSUnit():inAir() then
if timer.getTime() - self.Messages[MessageId].MessageTime >= self.Messages[MessageId].MessageDuration + 10 then
MESSAGE:New( Message, MessageCategory, MessageDuration, MessageId ):ToClient( self )
self.Messages[MessageId].MessageTime = timer.getTime()

View File

@ -5,6 +5,7 @@
Include.File( "Routines" )
Include.File( "Base" )
Include.File( "Menu" )
Include.File( "Group" )
DATABASE = {
ClassName = "DATABASE",
@ -138,6 +139,9 @@ function DATABASE:Spawn( SpawnTemplate )
self:_RegisterGroup( SpawnTemplate )
coalition.addGroup( SpawnCountryID, SpawnCategoryID, SpawnTemplate )
local SpawnGroup = GROUP:New( Group.getByName( SpawnTemplate.name ) )
return SpawnGroup
end
@ -206,7 +210,7 @@ end
--- Track DCSRTE DEAD or CRASH events for the internal scoring.
function DATABASE:OnDeadOrCrash( event )
self:T( { event } )
--self:T( { event } )
local TargetUnit = nil
local TargetGroup = nil
@ -241,7 +245,7 @@ function DATABASE:OnDeadOrCrash( event )
TargetUnitCategory = DATABASECategory[TargetCategory]
TargetUnitType = TargetType
self:T( { TargetUnitName, TargetGroupName, TargetPlayerName, TargetCoalition, TargetCategory, TargetType } )
--self:T( { TargetUnitName, TargetGroupName, TargetPlayerName, TargetCoalition, TargetCategory, TargetType } )
end
for PlayerName, PlayerData in pairs( self.Players ) do

View File

@ -13,13 +13,14 @@ GROUP = {
ClassName="GROUP",
}
function GROUP:New( _Group )
function GROUP:New( DCSGroup )
local self = BASE:Inherit( self, BASE:New() )
self:T( _Group:getName() )
self:T( DCSGroup:getName() )
self._Group = _Group
self.GroupName = _Group:getName()
self.GroupID = _Group:getID()
self.DCSGroup = DCSGroup
self.GroupName = DCSGroup:getName()
self.GroupID = DCSGroup:getID()
self.Controller = DCSGroup:getController()
return self
end
@ -29,13 +30,32 @@ function GROUP:NewFromName( GroupName )
local self = BASE:Inherit( self, BASE:New() )
self:T( GroupName )
self._Group = Group.getByName( GroupName )
self.GroupName = self._Group:getName()
self.GroupID = self._Group:getID()
self.DCSGroup = Group.getByName( GroupName )
if self.DCSGroup then
self.GroupName = self.DCSGroup:getName()
self.GroupID = self.DCSGroup:getID()
end
return self
end
function GROUP:GetDCSGroup()
self:T( { self.GroupName } )
self.DCSGroup = Group.getByName( self.GroupName )
return self.DCSGroup
end
function GROUP:GetDCSUnit( UnitNumber )
self:T( { self.GroupName, UnitNumber } )
return self.DCSGroup:getUnit( UnitNumber )
end
function GROUP:Activate()
self:T( { self.GroupName } )
trigger.action.activateGroup( self:GetDCSGroup() )
return self:GetDCSGroup()
end
function GROUP:GetName()
self:T( self.GroupName )
@ -43,40 +63,59 @@ function GROUP:GetName()
return self.GroupName
end
function GROUP:GetPoint()
self:T( self.GroupName )
local GroupPoint = self:GetUnit(1):GetPoint()
self:T( GroupPoint )
return GroupPoint
end
function GROUP:Destroy()
self:T( self.GroupName )
for Index, UnitData in pairs( self._Group:getUnits() ) do
for Index, UnitData in pairs( self.DCSGroup:getUnits() ) do
self:CreateEventCrash( timer.getTime(), UnitData )
end
self._Group:destroy()
self.DCSGroup:destroy()
end
function GROUP:GetUnit( UnitNumber )
self:T( self.GroupName )
return UNIT:New( self._Group:getUnit( UnitNumber ) )
self:T( { self.GroupName, UnitNumber } )
return UNIT:New( self.DCSGroup:getUnit( UnitNumber ) )
end
function GROUP:IsAir()
self:T()
local IsAirResult = self._Group:getCategory() == Group.Category.AIRPLANE or self._Group:getCategory() == Group.Category.HELICOPTER
local IsAirResult = self.DCSGroup:getCategory() == Group.Category.AIRPLANE or self.DCSGroup:getCategory() == Group.Category.HELICOPTER
self:T( IsAirResult )
return IsAirResult
end
function GROUP:IsAlive()
self:T()
local IsAliveResult = self.DCSGroup and self.DCSGroup:isExist()
self:T( IsAliveResult )
return IsAliveResult
end
function GROUP:AllOnGround()
self:T()
local AllOnGroundResult = true
for Index, UnitData in pairs( self._Group:getUnits() ) do
for Index, UnitData in pairs( self.DCSGroup:getUnits() ) do
if UnitData:inAir() then
AllOnGroundResult = false
end
@ -92,7 +131,7 @@ self:T()
local MaxVelocity = 0
for Index, UnitData in pairs( self._Group:getUnits() ) do
for Index, UnitData in pairs( self.DCSGroup:getUnits() ) do
local Velocity = UnitData:getVelocity()
local VelocityTotal = math.abs( Velocity.x ) + math.abs( Velocity.y ) + math.abs( Velocity.z )
@ -129,13 +168,13 @@ end
function GROUP:Embarking( Point, Duration, EmbarkingGroup )
trace.f( self.ClassName, { self.GroupName, Point, Duration, EmbarkingGroup._Group } )
trace.f( self.ClassName, { self.GroupName, Point, Duration, EmbarkingGroup.DCSGroup } )
local Controller = self:_GetController()
trace.i( self.ClassName, EmbarkingGroup.GroupID )
trace.i( self.ClassName, EmbarkingGroup._Group:getID() )
trace.i( self.ClassName, EmbarkingGroup._Group.id )
trace.i( self.ClassName, EmbarkingGroup.DCSGroup:getID() )
trace.i( self.ClassName, EmbarkingGroup.DCSGroup.id )
Controller:pushTask( { id = 'Embarking',
params = { x = Point.x,
@ -169,9 +208,112 @@ trace.f( self.ClassName, { self.GroupName, Point, Radius } )
return self
end
function GROUP:Route( GoPoints )
self:T( GoPoints )
local Points = routines.utils.deepCopy( GoPoints )
local MissionTask = { id = 'Mission', params = { route = { points = Points, }, }, }
--self.Controller.setTask( self.Controller, MissionTask )
routines.scheduleFunction( self.Controller.setTask, { self.Controller, MissionTask}, timer.getTime() + 1 )
return self
end
function GROUP:RouteToZone( Zone, Randomize, Speed, Formation )
self:T( Zone )
local GroupPoint = self:GetPoint()
local PointFrom = {}
PointFrom.x = GroupPoint.x
PointFrom.y = GroupPoint.y
PointFrom.type = "Turning Point"
PointFrom.action = "Cone"
PointFrom.speed = 20 / 1.6
local PointTo = {}
local ZonePoint
if Randomize then
ZonePoint = Zone:GetRandomPoint()
else
ZonePoint = Zone:GetPoint()
end
PointTo.x = ZonePoint.x
PointTo.y = ZonePoint.y
PointTo.type = "Turning Point"
if Formation then
PointTo.action = Formation
else
PointTo.action = "Cone"
end
if Speed then
PointTo.speed = Speed
else
PointTo.speed = 20 / 1.6
end
local Points = { PointFrom, PointTo }
self:T( Points )
self:Route( Points )
return self
end
function GROUP:CopyRoute( Begin, End, Randomize, Radius )
self:T( { Begin, End } )
local Points = {}
-- Could be a Spawned Group
local GroupName = string.match( self:GetName(), ".*#" )
if GroupName then
GroupName = GroupName:sub( 1, -2 )
else
GroupName = self:GetName()
end
self:T( { GroupName } )
local Template = _Database.Groups[GroupName].Template
if Template then
if not Begin then
Begin = 0
end
if not End then
End = 0
end
for TPointID = Begin + 1, #Template.route.points - End do
if Template.route.points[TPointID] then
Points[#Points+1] = routines.utils.deepCopy( Template.route.points[TPointID] )
if Randomize then
if not Radius then
Radius = 500
end
Points[#Points].x = Points[#Points].x + math.random( Radius * -1, Radius )
Points[#Points].y = Points[#Points].y + math.random( Radius * -1, Radius )
end
end
end
return Points
end
return nil
end
function GROUP:_GetController()
return self._Group:getController()
return self.DCSGroup:getController()
end

View File

@ -174,12 +174,12 @@ function MISSION:ReportToAll()
local AlivePlayers = ''
for ClientID, Client in pairs( self._Clients ) do
if Client:ClientGroup() then
if Client:GetClientGroupUnit() then
if Client:GetClientGroupUnit():getLife() > 0.0 then
if Client:GetClientGroupDCSUnit() then
if Client:GetClientGroupDCSUnit():getLife() > 0.0 then
if AlivePlayers == '' then
AlivePlayers = ' Players: ' .. Client:GetClientGroupUnit():getPlayerName()
AlivePlayers = ' Players: ' .. Client:GetClientGroupDCSUnit():getPlayerName()
else
AlivePlayers = AlivePlayers .. ' / ' .. Client:GetClientGroupUnit():getPlayerName()
AlivePlayers = AlivePlayers .. ' / ' .. Client:GetClientGroupDCSUnit():getPlayerName()
end
end
end
@ -486,7 +486,7 @@ trace.scheduled("MISSIONSCHEDULER","Scheduler")
if Mission.GoalFunction ~= nil then
Mission.GoalFunction( Mission, Client )
end
_Database:_AddMissionTaskScore( Client:GetClientGroupUnit(), Mission.Name, 25 )
_Database:_AddMissionTaskScore( Client:GetClientGroupDCSUnit(), Mission.Name, 25 )
-- if not Mission:IsCompleted() then
-- end

View File

@ -0,0 +1,31 @@
rem Generate Moose_Embedded.lua
copy Trace.lua ^
+ Routines.lua ^
+ Base.lua ^
+ Menu.lua ^
+ Group.lua ^
+ Unit.lua ^
+ Zone.lua ^
+ Database.lua ^
+ Cargo.lua ^
+ Client.lua ^
+ Message.lua ^
+ Stage.lua ^
+ Task.lua ^
+ GoHomeTask.lua ^
+ DestroyBaseTask.lua ^
+ DestroyGroupsTask.lua ^
+ DestroyRadarsTask.lua ^
+ DestroyUnitTypesTask.lua ^
+ PickupTask.lua ^
+ DeployTask.lua ^
+ NoTask.lua ^
+ RouteTask.lua ^
+ Mission.lua ^
+ CleanUp.lua ^
+ Spawn.lua ^
+ Movement.lua ^
+ Sead.lua ^
Moose_Embedded.lua

10379
Moose/Moose_Embedded.lua Normal file

File diff suppressed because it is too large Load Diff

View File

@ -66,39 +66,49 @@ routines.utils.oneLineSerialize = function(tbl) -- serialization of a table all
tbl_str[#tbl_str + 1] = '{'
for ind,val in pairs(tbl) do -- serialize its fields
local ind_str = {}
if type(ind) == "number" then
tbl_str[#tbl_str + 1] = '['
tbl_str[#tbl_str + 1] = tostring(ind)
tbl_str[#tbl_str + 1] = ']='
ind_str[#ind_str + 1] = '['
ind_str[#ind_str + 1] = tostring(ind)
ind_str[#ind_str + 1] = ']='
else --must be a string
tbl_str[#tbl_str + 1] = '['
tbl_str[#tbl_str + 1] = routines.utils.basicSerialize(ind)
tbl_str[#tbl_str + 1] = ']='
ind_str[#ind_str + 1] = '['
ind_str[#ind_str + 1] = routines.utils.basicSerialize(ind)
ind_str[#ind_str + 1] = ']='
end
local val_str = {}
if ((type(val) == 'number') or (type(val) == 'boolean')) then
tbl_str[#tbl_str + 1] = tostring(val)
tbl_str[#tbl_str + 1] = ','
val_str[#val_str + 1] = tostring(val)
val_str[#val_str + 1] = ','
tbl_str[#tbl_str + 1] = table.concat(ind_str)
tbl_str[#tbl_str + 1] = table.concat(val_str)
elseif type(val) == 'string' then
tbl_str[#tbl_str + 1] = routines.utils.basicSerialize(val)
tbl_str[#tbl_str + 1] = ','
val_str[#val_str + 1] = routines.utils.basicSerialize(val)
val_str[#val_str + 1] = ','
tbl_str[#tbl_str + 1] = table.concat(ind_str)
tbl_str[#tbl_str + 1] = table.concat(val_str)
elseif type(val) == 'nil' then -- won't ever happen, right?
tbl_str[#tbl_str + 1] = 'nil,'
val_str[#val_str + 1] = 'nil,'
tbl_str[#tbl_str + 1] = table.concat(ind_str)
tbl_str[#tbl_str + 1] = table.concat(val_str)
elseif type(val) == 'table' then
if ind == "__index" then
tbl_str[#tbl_str + 1] = "__index"
tbl_str[#tbl_str + 1] = ',' --I think this is right, I just added it
-- tbl_str[#tbl_str + 1] = "__index"
-- tbl_str[#tbl_str + 1] = ',' --I think this is right, I just added it
else
tbl_str[#tbl_str + 1] = _Serialize(val)
tbl_str[#tbl_str + 1] = ',' --I think this is right, I just added it
val_str[#val_str + 1] = _Serialize(val)
val_str[#val_str + 1] = ',' --I think this is right, I just added it
tbl_str[#tbl_str + 1] = table.concat(ind_str)
tbl_str[#tbl_str + 1] = table.concat(val_str)
end
elseif type(val) == 'function' then
tbl_str[#tbl_str + 1] = "function " .. tostring(ind)
tbl_str[#tbl_str + 1] = ',' --I think this is right, I just added it
-- tbl_str[#tbl_str + 1] = "function " .. tostring(ind)
-- tbl_str[#tbl_str + 1] = ',' --I think this is right, I just added it
else
env.info('unable to serialize value type ' .. routines.utils.basicSerialize(type(val)) .. ' at index ' .. tostring(ind))
env.info( debug.traceback() )
-- env.info('unable to serialize value type ' .. routines.utils.basicSerialize(type(val)) .. ' at index ' .. tostring(ind))
-- env.info( debug.traceback() )
end
end

View File

@ -132,5 +132,3 @@ self:T( { event } )
end
end
end

File diff suppressed because it is too large Load Diff

View File

@ -226,7 +226,7 @@ self:T()
local RouteMessage = "Fly to "
self:T( Task.LandingZones )
for LandingZoneID, LandingZoneName in pairs( Task.LandingZones.LandingZoneNames ) do
RouteMessage = RouteMessage .. LandingZoneName .. ' at ' .. routines.getBRStringZone( { zone = LandingZoneName, ref = Client:GetClientGroupUnit():getPoint(), true, true } ) .. ' km. '
RouteMessage = RouteMessage .. LandingZoneName .. ' at ' .. routines.getBRStringZone( { zone = LandingZoneName, ref = Client:GetClientGroupDCSUnit():getPoint(), true, true } ) .. ' km. '
end
Client:Message( RouteMessage, self.MSG.TIME, Mission.Name .. "/StageRoute", "Co-Pilot: Route", 20 )
@ -243,7 +243,7 @@ self:T()
-- check if the Client is in the landing zone
self:T( Task.LandingZones.LandingZoneNames )
Task.CurrentLandingZoneName = routines.IsUnitInZones( Client:GetClientGroupUnit(), Task.LandingZones.LandingZoneNames )
Task.CurrentLandingZoneName = routines.IsUnitInZones( Client:GetClientGroupDCSUnit(), Task.LandingZones.LandingZoneNames )
if Task.CurrentLandingZoneName then
@ -285,10 +285,12 @@ self:T()
Task.HostUnit = Task.CurrentCargoZone:GetHostUnit()
self:T( { Task.HostUnit } )
if Task.HostUnit then
Task.HostUnitName = Task.HostUnit:getName()
Task.HostUnitTypeName = Task.HostUnit:getTypeName()
Task.HostUnitName = Task.HostUnit:GetPrefix()
Task.HostUnitTypeName = Task.HostUnit:GetTypeName()
local HostMessage = ""
Task.CargoNames = ""
@ -331,7 +333,7 @@ end
function STAGELANDING:Validate( Mission, Client, Task )
self:T()
Task.CurrentLandingZoneName = routines.IsUnitInZones( Client:GetClientGroupUnit(), Task.LandingZones.LandingZoneNames )
Task.CurrentLandingZoneName = routines.IsUnitInZones( Client:GetClientGroupDCSUnit(), Task.LandingZones.LandingZoneNames )
if Task.CurrentLandingZoneName then
-- Client is in de landing zone.
@ -357,7 +359,7 @@ self:T()
return -1
end
if Task.IsLandingRequired and Client:GetClientGroupUnit():inAir() then
if Task.IsLandingRequired and Client:GetClientGroupDCSUnit():inAir() then
return 0
end
@ -397,14 +399,14 @@ end
function STAGELANDED:Validate( Mission, Client, Task )
self:T()
if not routines.IsUnitInZones( Client:GetClientGroupUnit(), Task.CurrentLandingZoneName ) then
if not routines.IsUnitInZones( Client:GetClientGroupDCSUnit(), Task.CurrentLandingZoneName ) then
self:T( "Client is not anymore in the landing zone, go back to stage Route, and remove cargo menus." )
Task.Signalled = false
Task:RemoveCargoMenus( Client )
return -2
end
if Task.IsLandingRequired and Client:GetClientGroupUnit():inAir() then
if Task.IsLandingRequired and Client:GetClientGroupDCSUnit():inAir() then
self:T( "Client went back in the air. Go back to stage Landing." )
Task.Signalled = false
return -1
@ -464,7 +466,7 @@ function STAGEUNLOAD:Validate( Mission, Client, Task )
self:T()
env.info( 'STAGEUNLOAD:Validate()' )
if routines.IsUnitInZones( Client:GetClientGroupUnit(), Task.CurrentLandingZoneName ) then
if routines.IsUnitInZones( Client:GetClientGroupDCSUnit(), Task.CurrentLandingZoneName ) then
else
Task.ExecuteStage = _TransportExecuteStage.FAILED
Task:RemoveCargoMenus( Client )
@ -473,7 +475,7 @@ self:T()
return 1
end
if not Client:GetClientGroupUnit():inAir() then
if not Client:GetClientGroupDCSUnit():inAir() then
else
Task.ExecuteStage = _TransportExecuteStage.FAILED
Task:RemoveCargoMenus( Client )
@ -578,7 +580,7 @@ self:T()
self:T( "Task.CurrentLandingZoneName = " .. Task.CurrentLandingZoneName )
if not Task.IsSlingLoad then
if not routines.IsUnitInZones( Client:GetClientGroupUnit(), Task.CurrentLandingZoneName ) then
if not routines.IsUnitInZones( Client:GetClientGroupDCSUnit(), Task.CurrentLandingZoneName ) then
Task:RemoveCargoMenus( Client )
Task.ExecuteStage = _TransportExecuteStage.FAILED
Task.CargoName = nil
@ -587,7 +589,7 @@ self:T()
return -1
end
if not Client:GetClientGroupUnit():inAir() then
if not Client:GetClientGroupDCSUnit():inAir() then
else
-- The carrier is back in the air, undo the loading process.
Task:RemoveCargoMenus( Client )
@ -673,7 +675,7 @@ self:T()
function STAGEARRIVE:Validate( Mission, Client, Task )
self:T()
Task.CurrentLandingZoneID = routines.IsUnitInZones( Client:GetClientGroupUnit(), Task.LandingZones )
Task.CurrentLandingZoneID = routines.IsUnitInZones( Client:GetClientGroupDCSUnit(), Task.LandingZones )
if ( Task.CurrentLandingZoneID ) then
else
return -1

View File

@ -12,27 +12,71 @@ UNIT = {
ClassName="UNIT",
}
function UNIT:New( _Unit )
function UNIT:New( DCSUnit )
local self = BASE:Inherit( self, BASE:New() )
self:T( _Unit:getName() )
self:T( DCSUnit:getName() )
self._Unit = _Unit
self.UnitName = _Unit:getName()
self.UnitID = _Unit:getID()
self.DCSUnit = DCSUnit
self.UnitName = DCSUnit:getName()
self.UnitID = DCSUnit:getID()
return self
end
function UNIT:IsAlive()
self:T( self.UnitName )
return ( self.DCSUnit and self.DCSUnit:isExist() )
end
function UNIT:GetName()
self:T( self.UnitName )
return self.UnitName
end
function UNIT:GetTypeName()
self:T( self.UnitName )
return self.DCSUnit:getTypeName()
end
function UNIT:GetPrefix()
self:T( self.UnitName )
local UnitPrefix = string.match( self.UnitName, ".*#" ):sub( 1, -2 )
self:T( UnitPrefix )
return UnitPrefix
end
function UNIT:GetCallSign()
self:T( self.UnitName )
return self._Unit:getCallsign()
return self.DCSUnit:getCallsign()
end
function UNIT:GetPoint()
self:T( self.UnitName )
local UnitPos = self.DCSUnit:getPosition().p
local UnitPoint = {}
UnitPoint.x = UnitPos.x
UnitPoint.y = UnitPos.z
self:T( UnitPoint )
return UnitPoint
end
function UNIT:GetPositionVec3()
self:T( self.UnitName )
local UnitPos = self._Unit:getPosition().p
local UnitPos = self.DCSUnit:getPosition().p
self:T( UnitPos )
return UnitPos

View File

@ -30,6 +30,17 @@ trace.f( self.ClassName, ZoneName )
return self
end
function ZONE:GetPoint()
self:T( self.ZoneName )
local Zone = trigger.misc.getZone( self.ZoneName )
local Point = { x = Zone.point.x, y = Zone.point.z }
self:T( { Zone, Point } )
return Point
end
function ZONE:GetRandomPoint()
trace.f( self.ClassName, self.ZoneName )
@ -55,3 +66,4 @@ trace.f( self.ClassName, self.ZoneName )
return Zone.radius
end

View File

@ -62,14 +62,13 @@ end
do
local Mission = MISSION:New( 'Deliver secret letter', 'Operational', 'Pickup letter to the commander.', 'NATO' )
Mission:AddClient( CLIENT:New( 'BE Package Test 1' ):Transport() )
Mission:AddClient( CLIENT:New( 'BE Package Test 2' ):Transport() )
Mission:AddClient( CLIENT:New( 'DE Pickup Test 1' ):Transport() )
Mission:AddClient( CLIENT:New( 'DE Pickup Test 2' ):Transport() )
Client_Package_1 = CLIENT:New( 'BE Package Test 1' ):Transport()
Mission:AddClient( Client_Package_1 )
Package_Pickup_Zone = CARGO_ZONE:New( 'Package Pickup Zone', 'DE Guard' ):GreenSmoke()
Cargo_Package = CARGO_PACKAGE:New( 'Letter', 'Letter to Command', 0.1, 'DE Guard' )
Cargo_Package = CARGO_PACKAGE:New( 'Letter', 'Letter to Command', 0.1, Client_Package_1 )
--Cargo_Goods = CARGO_STATIC:New( 'Goods', 20, 'Goods', 'Pickup Zone Goods', 'DE Collection Point' )
--Cargo_SlingLoad = CARGO_SLING:New( 'Basket', 40, 'Basket', 'Pickup Zone Sling Load', 'DE Cargo Guard' )

Binary file not shown.

View File

@ -1,15 +1,81 @@
Include.File( "Spawn" )
SpawnTest = SPAWN:New( 'TEST' ):Schedule( 1, 1, 15, 0.4 ):Repeat()
SpawnTestPlane = SPAWN:New( 'TESTPLANE' ):Schedule( 1, 1, 15, 0.4 ):RepeatOnLanding()
-- Tests Batumi
---------------
Spawn_Plane_Scheduled = SPAWN:New( "Spawn Plane Scheduled" ):SpawnScheduled( 30, 0.4 )
Spawn_Helicopter_Scheduledd = SPAWN:New( "Spawn Helicopter Scheduled" ):SpawnScheduled( 30, 1 )
Spawn_Ship_Scheduled = SPAWN:New( "Spawn Ship Scheduled" ):SpawnScheduled( 30, 0.5 )
Spawn_Vehicle_Scheduled = SPAWN:New( "Spawn Vehicle Scheduled" ):SpawnScheduled( 30, 0.5 )
SpawnTestShipPlane = SPAWN:New( 'SHIPPLANE' ):Schedule( 1, 1, 15, 0.4 ):RepeatOnLanding()
SpawnTestShipHeli = SPAWN:New( 'SHIPHELI' ):Schedule( 1, 1, 15, 0.4 ):RepeatOnLanding()
SpawnCH53E = SPAWN:New( 'VEHICLE' )
-- Tests Tbilisi
----------------
Spawn_Plane_Limited_Repeat = SPAWN:New( "Spawn Plane Limited Repeat" ):Limit( 1, 1 ):Repeat():Spawn()
Spawn_Plane_Limited_RepeatOnLanding = SPAWN:New( "Spawn Plane Limited RepeatOnLanding" ):Limit( 1, 1 ):Repeat():Spawn()
Spawn_Plane_Limited_RepeatOnEngineShutDown = SPAWN:New( "Spawn Plane Limited RepeatOnEngineShutDown" ):Limit( 1, 1 ):Repeat():Spawn()
Spawn_Helicopter_Limited_Repeat = SPAWN:New( "Spawn Helicopter Limited Repeat" ):Limit( 1, 1 ):Repeat():Spawn()
Spawn_Helicopter_Limited_RepeatOnLanding = SPAWN:New( "Spawn Helicopter Limited RepeatOnLanding" ):Limit( 1, 1 ):Repeat():Spawn()
Spawn_Helicopter_Limited_RepeatOnEngineShutDown = SPAWN:New( "Spawn Helicopter Limited RepeatOnEngineShutDown" ):Limit( 1, 1 ):Repeat():Spawn()
-- Tests Soganlug
Spawn_Plane_Limited_Scheduled = SPAWN:New( "Spawn Plane Limited Scheduled" ):Limit( 2, 10 ):SpawnScheduled( 30, 0 )
Spawn_Helicopter_Limited_Scheduled = SPAWN:New( "Spawn Helicopter Limited Scheduled" ):Limit( 2, 10 ):SpawnScheduled( 30, 0 )
Spawn_Ground_Limited_Scheduled = SPAWN:New( "Spawn Vehicle Limited Scheduled" ):Limit( 1, 20 ):SpawnScheduled( 90, 0 )
-- Tests Sukhumi
Spawn_Plane_Limited_Scheduled_RandomizeRoute = SPAWN:New( "Spawn Plane Limited Scheduled RandomizeRoute" ):Limit( 2, 10 ):RandomizeRoute( 1, 1, 4000 ):SpawnScheduled( 30, 0 )
Spawn_Helicopter_Limited_Scheduled_RandomizeRoute = SPAWN:New( "Spawn Helicopter Limited Scheduled RandomizeRoute" ):Limit( 2, 10 ):RandomizeRoute( 1, 1, 4000 ):SpawnScheduled( 30, 0 )
Spawn_Vehicle_Limited_Scheduled_RandomizeRoute = SPAWN:New( "Spawn Vehicle Limited Scheduled RandomizeRoute" ):Limit( 10, 10 ):RandomizeRoute( 1, 1, 1000 ):SpawnScheduled( 1, 0 )
-- Tests Kutaisi
----------------
-- Spawn Helicopters and Ground attack.
-- Observe when helicopters land but are not dead and are out of the danger zone, that they get removed after a while (+/- 180 seconds) and ReSpawn.
Spawn_Helicopter_Scheduled_CleanUp = SPAWN:New( "Spawn Helicopter Scheduled CleanUp" ):Limit( 3, 100 ):RandomizeRoute( 1, 1, 1000 ):CleanUp( 180 ):SpawnScheduled( 10, 0 )
Spawn_Vehicle_Scheduled_CleanUp = SPAWN:New( "Spawn Vehicle Scheduled CleanUp" ):Limit( 3, 100 ):RandomizeRoute( 1, 1, 1000 ):SpawnScheduled( 10, 0 )
-- Test Matrix Visible Setup
SpawnTestVisible = SPAWN:New( "Spawn Vehicle Visible Scheduled" ):Limit( 200, 200 ):SpawnArray( 59, 20, 20, 10 ):SpawnScheduled( 10, 0.2 )
Spawn_Templates_1 = { "Spawn Vehicle Visible Template A",
"Spawn Vehicle Visible Template B",
"Spawn Vehicle Visible Template C",
"Spawn Vehicle Visible Template D",
"Spawn Vehicle Visible Template E",
"Spawn Vehicle Visible Template F",
"Spawn Vehicle Visible Template G",
"Spawn Vehicle Visible Template H",
"Spawn Vehicle Visible Template I",
"Spawn Vehicle Visible Template J"
}
Spawn_Vehicle_Visible_RandomizeTemplate_Scheduled_1 = SPAWN:New( "Spawn Vehicle Visible RandomizeTemplate Scheduled" )
:Limit( 40, 40 )
:RandomizeTemplate( Spawn_Templates_1 )
:SpawnArray( 49, 20, 8, 8 )
:SpawnScheduled( 10, 0.2 )
-- Tests Maykop
Spawn_Infantry = SPAWN:New( "Spawn Infantry" )
:Limit( 10, 10 )
Spawn_Vehicle_Host = SPAWN:New( "Spawn Vehicle Host" )
:Limit( 10, 10 )
:SpawnArray( 0, 5, 8, 8 )
:SpawnScheduled( 10, 0.2 )
Spawn_Vehicle_SpawnToZone = SPAWN:New( "Spawn Vehicle SpawnToZone" )
:Limit( 10, 10 )
Spawn_Helicopter_SpawnToZone = SPAWN:New( "Spawn Helicopter SpawnToZone" )
:Limit( 10, 10 )
:SpawnScheduled( 60, 0.2 )
SpawnTestHelicopterCleanUp = SPAWN:New( "TEST_HELI_CLEANUP" ):Limit( 3, 100 ):Schedule( 10, 0 ):RandomizeRoute( 1, 1, 1000 ):CleanUp( 180 )
SpawnTestVehiclesCleanUp = SPAWN:New( "TEST_AAA_CLEANUP" ):Limit( 3, 100 ):Schedule( 10, 0 ):RandomizeRoute( 1, 1, 1000 )

Binary file not shown.