From 4a52422fe14ab1a7297191cf62f184f61465c1d5 Mon Sep 17 00:00:00 2001 From: svenvandevelde Date: Wed, 17 Feb 2016 14:58:27 +0100 Subject: [PATCH] Added GROUP, ZONE classes to handle Tasks and Zones GROUP will be a class abstraction for the DCS Group class, incorporating the Controller for tasks. ZONE will be a class abstraction for a trigger zone. Each of these classes will have properties to further emulate tasks, and execute all kind of actions on the object. --- Moose/Group.lua | 85 ++++++++++++++++++++++++++++++++++++++++++++ Moose/PickupTask.lua | 1 + Moose/Spawn.lua | 33 ++++++++++++----- Moose/Zone.lua | 57 +++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+), 8 deletions(-) create mode 100644 Moose/Group.lua create mode 100644 Moose/Zone.lua diff --git a/Moose/Group.lua b/Moose/Group.lua new file mode 100644 index 000000000..bc4cef98e --- /dev/null +++ b/Moose/Group.lua @@ -0,0 +1,85 @@ +--- GROUP Classes +-- @classmod GROUP + +Include.File( "Routines" ) +Include.File( "Base" ) +Include.File( "Message" ) + +GROUPS = {} + + +GROUP = { + ClassName="GROUP", + } + +function GROUP:New( _Group ) +trace.f( self.ClassName, _Group:getName() ) + + local self = BASE:Inherit( self, BASE:New() ) + + self._Group = _Group + self.GroupName = _Group:getName() + self.GroupID = _Group:getID() + + return self +end + +function GROUP:Land( Point, Duration ) +trace.f( self.ClassName, { self.GroupName, Point, Duration } ) + + local Controller = self:_GetController() + + if Duration and Duration > 0 then + Controller:pushTask( { id = 'Land', params = { point = Point, durationFlag = true, duration = Duration } } ) + else + Controller:pushTask( { id = 'Land', params = { point = Point, durationFlag = false } } ) + end + + return self +end + +function GROUP:Embarking( Point, Duration, EmbarkingGroup ) +trace.f( self.ClassName, { self.GroupName, Point, Duration, EmbarkingGroup._Group } ) + + local Controller = self:_GetController() + + trace.i( self.ClassName, EmbarkingGroup.GroupID ) + trace.i( self.ClassName, EmbarkingGroup._Group:getID() ) + trace.i( self.ClassName, EmbarkingGroup._Group.id ) + + Controller:pushTask( { id = 'Embarking', + params = { x = Point.x, + y = Point.y, + duration = Duration, + groupsForEmbarking = { EmbarkingGroup.GroupID }, + durationFlag = true, + distributionFlag = false, + distribution = {}, + } + } + ) + + return self +end + +function GROUP:EmbarkToTransport( Point, Radius ) +trace.f( self.ClassName, { self.GroupName, Point, Radius } ) + + local Controller = self:_GetController() + + Controller:pushTask( { id = 'EmbarkToTransport', + params = { x = Point.x, + y = Point.y, + zoneRadius = Radius, + } + } + ) + + return self +end + +function GROUP:_GetController() + + return self._Group:getController() + +end diff --git a/Moose/PickupTask.lua b/Moose/PickupTask.lua index 2b4e1b3ee..ac7ce188a 100644 --- a/Moose/PickupTask.lua +++ b/Moose/PickupTask.lua @@ -3,6 +3,7 @@ -- @parent TASK Include.File("Task") +Include.File("Cargo") PICKUPTASK = { ClassName = "PICKUPTASK", diff --git a/Moose/Spawn.lua b/Moose/Spawn.lua index e6d06bd53..48df6e921 100644 --- a/Moose/Spawn.lua +++ b/Moose/Spawn.lua @@ -5,6 +5,8 @@ Include.File( "Routines" ) Include.File( "Base" ) Include.File( "Database" ) +Include.File( "Group" ) + SPAWN = { ClassName = "SPAWN", @@ -375,14 +377,14 @@ end --- Will return the SpawnGroupName either with with a specific count number or without any count. --- @tparam number SpawnNumber is the number of the Group that is to be SPAWNed. +-- @tparam number SpawnIndex is the number of the Group that is to be SPAWNed. -- @treturn string SpawnGroupName -function SPAWN:SpawnGroupName( SpawnNumber ) -trace.f("Spawn", SpawnNumber ) +function SPAWN:SpawnGroupName( SpawnIndex ) +trace.f("Spawn", SpawnIndex ) - if SpawnNumber then - trace.i( self.ClassName, string.format( '%s#%03d', self.SpawnPrefix, SpawnNumber ) ) - return string.format( '%s#%03d', self.SpawnPrefix, SpawnNumber ) + if SpawnIndex then + trace.i( self.ClassName, string.format( '%s#%03d', self.SpawnPrefix, SpawnIndex ) ) + return string.format( '%s#%03d', self.SpawnPrefix, SpawnIndex ) else trace.i( self.ClassName, self.SpawnPrefix ) return self.SpawnPrefix @@ -390,6 +392,21 @@ trace.f("Spawn", SpawnNumber ) end +function SPAWN:GetLastIndex() + + return self.SpawnCount +end + + +function SPAWN:GetLastGroup() +trace.f( self.ClassName ) + + local LastGroupName = self:SpawnGroupName( self:GetLastIndex() ) + + return GROUP:New( Group.getByName( LastGroupName ) ) +end + + --- Will SPAWN a Group within a given ZoneName. -- @tparam string ZonePrefix is the name of the zone where the Group is to be SPAWNed. -- @treturn SpawnTemplate @@ -528,8 +545,8 @@ trace.f( self.ClassName ) for u = 1, SpawnUnits do SpawnTemplate.units[u].name = string.format( SpawnTemplate.name .. '-%02d', u ) SpawnTemplate.units[u].unitId = nil - SpawnTemplate.units[u].x = SpawnTemplate.route.points[1].x - SpawnTemplate.units[u].y = SpawnTemplate.route.points[1].y + SpawnTemplate.units[u].x = SpawnTemplate.route.points[1].x + math.random( -50, 50 ) + SpawnTemplate.units[u].y = SpawnTemplate.route.points[1].y + math.random( -50, 50 ) end trace.r( self.ClassName, "", SpawnTemplate.name ) diff --git a/Moose/Zone.lua b/Moose/Zone.lua new file mode 100644 index 000000000..a4f5fe113 --- /dev/null +++ b/Moose/Zone.lua @@ -0,0 +1,57 @@ +--- ZONE Classes +-- @classmod ZONE + +Include.File( "Routines" ) +Include.File( "Base" ) +Include.File( "Message" ) + +ZONES = {} + + +ZONE = { + ClassName="ZONE", + } + +function ZONE:New( ZoneName ) +trace.f( self.ClassName, ZoneName ) + + local self = BASE:Inherit( self, BASE:New() ) + + local Zone = trigger.misc.getZone( ZoneName ) + + if not Zone then + error( "Zone " .. ZoneName .. " does not exist." ) + return nil + end + + self.Zone = Zone + self.ZoneName = ZoneName + + return self +end + +function ZONE:GetRandomPoint() +trace.f( self.ClassName, self.ZoneName ) + + local Point = {} + + local Zone = trigger.misc.getZone( self.ZoneName ) + + Point.x = Zone.point.x + math.random( Zone.radius * -1, Zone.radius ) + Point.y = Zone.point.z + math.random( Zone.radius * -1, Zone.radius ) + + trace.i( self.ClassName, { Zone } ) + trace.i( self.ClassName, { Point } ) + + return Point +end + +function ZONE:GetRadius() +trace.f( self.ClassName, self.ZoneName ) + + local Zone = trigger.misc.getZone( self.ZoneName ) + + trace.i( self.ClassName, { Zone } ) + + return Zone.radius +end