Got Task_SEAD template working with all the variations and complexity!

This commit is contained in:
FlightControl 2017-03-04 08:51:31 +01:00
parent 5ddeb8d396
commit b46d61d865
13 changed files with 68834 additions and 90 deletions

View File

@ -231,7 +231,6 @@ do -- ACT_ACCOUNT_DEADS
if self.TargetSetUnit:FindUnit( EventData.IniUnitName ) then
local TaskGroup = ProcessUnit:GetGroup()
self.TargetSetUnit:RemoveUnitsByName( EventData.IniUnitName )
self:Message( "You hit a target. Your group with assigned " .. self.TaskName .. " task has " .. self.TargetSetUnit:Count() .. " targets ( " .. self.TargetSetUnit:GetUnitTypesText() .. " ) left to be destroyed." )
end
end
@ -244,7 +243,7 @@ do -- ACT_ACCOUNT_DEADS
-- @param #string To
function ACT_ACCOUNT_DEADS:onafterEvent( ProcessUnit, From, Event, To, EventData )
if self.TargetSetUnit:Count() > 0 then
if self.TargetSetUnit:Count() > 1 then
self:__More( 1 )
else
self:__NoMore( 1 )
@ -259,7 +258,7 @@ do -- ACT_ACCOUNT_DEADS
self:T( { "EventDead", EventData } )
if EventData.IniDCSUnit then
self:__Event( 1, EventData )
self:Event( EventData )
end
end

View File

@ -223,6 +223,7 @@ do -- ACT_ROUTE_POINT
-- @param #ACT_ROUTE_POINT self
-- @param Core.Point#POINT_VEC2 PointVec2 The PointVec2 to route to.
function ACT_ROUTE_POINT:SetPointVec2( PointVec2 )
self:F2( { PointVec2 } )
self.PointVec2 = PointVec2
end
@ -230,6 +231,7 @@ do -- ACT_ROUTE_POINT
-- @param #ACT_ROUTE_POINT self
-- @return Core.Point#POINT_VEC2 PointVec2 The PointVec2 to route to.
function ACT_ROUTE_POINT:GetPointVec2()
self:F2( { self.PointVec2 } )
return self.PointVec2
end
@ -237,6 +239,7 @@ do -- ACT_ROUTE_POINT
-- @param #ACT_ROUTE_POINT self
-- @param #number Range The Range to consider the arrival. Default is 10000 meters.
function ACT_ROUTE_POINT:SetRange( Range )
self:F2( { self.Range } )
self.Range = Range or 10000
end

View File

@ -405,9 +405,10 @@ end
function SET_BASE:GetFirst()
self:F()
local t = self.List.first._
self:T3( { t } )
return t
local ObjectName = self.Index[1]
local FirstObject = self.Set[ObjectName]
self:T3( { FirstObject } )
return FirstObject
end
--- Gets the last object from the @{Set#SET_BASE} and derived classes.
@ -416,9 +417,10 @@ end
function SET_BASE:GetLast()
self:F()
local t = self.List.last._
self:T3( { t } )
return t
local ObjectName = self.Index[#self.Index]
local LastObject = self.Set[ObjectName]
self:T3( { LastObject } )
return LastObject
end
--- Gets a random object from the @{Set#SET_BASE} and derived classes.

View File

@ -990,11 +990,11 @@ function SCORING:_EventOnDeadOrCrash( Event )
TargetDestroy.ScoreDestroy = TargetDestroy.ScoreDestroy or 0
TargetDestroy.Penalty = TargetDestroy.Penalty or 0
TargetDestroy.PenaltyDestroy = TargetDestroy.PenaltyDestroy or 0
TargetDestroy.UNIT = TargetDestroy.UNIT or Player.Hit[TargetCategory][TargetUnitName].UNIT
local TargetUNIT = Player.Hit[TargetCategory][TargetUnitName].UNIT
if TargetCoalition then
if InitCoalition == TargetCoalition then
local ThreatLevelTarget, ThreatTypeTarget = TargetDestroy.UNIT:GetThreatLevel()
local ThreatLevelTarget, ThreatTypeTarget = TargetUNIT:GetThreatLevel()
local ThreatLevelPlayer = Player.UNIT:GetThreatLevel() / 10 + 1
local ThreatPenalty = math.ceil( ( ThreatLevelTarget / ThreatLevelPlayer ) * self.ScaleDestroyPenalty / 10 )
self:E( { ThreatLevel = ThreatPenalty, ThreatLevelTarget = ThreatLevelTarget, ThreatTypeTarget = ThreatTypeTarget, ThreatLevelPlayer = ThreatLevelPlayer } )
@ -1025,7 +1025,7 @@ function SCORING:_EventOnDeadOrCrash( Event )
self:ScoreCSV( PlayerName, "DESTROY_PENALTY", 1, ThreatPenalty, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType )
else
local ThreatLevelTarget, ThreatTypeTarget = TargetDestroy.UNIT:GetThreatLevel()
local ThreatLevelTarget, ThreatTypeTarget = TargetUNIT:GetThreatLevel()
local ThreatLevelPlayer = Player.UNIT:GetThreatLevel() / 10 + 1
local ThreatScore = math.ceil( ( ThreatLevelTarget / ThreatLevelPlayer ) * self.ScaleDestroyScore / 10 )
@ -1055,7 +1055,7 @@ function SCORING:_EventOnDeadOrCrash( Event )
end
self:ScoreCSV( PlayerName, "DESTROY_SCORE", 1, ThreatScore, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType )
local UnitName = TargetDestroy.UNIT:GetName()
local UnitName = TargetUNIT:GetName()
local Score = self.ScoringObjects[UnitName]
if Score then
Player.Score = Player.Score + Score
@ -1075,7 +1075,7 @@ function SCORING:_EventOnDeadOrCrash( Event )
self:E( { ScoringZone = ScoreZoneData } )
local ScoreZone = ScoreZoneData.ScoreZone -- Core.Zone#ZONE_BASE
local Score = ScoreZoneData.Score
if ScoreZone:IsVec2InZone( TargetDestroy.UNIT:GetVec2() ) then
if ScoreZone:IsVec2InZone( TargetUNIT:GetVec2() ) then
Player.Score = Player.Score + Score
TargetDestroy.Score = TargetDestroy.Score + Score
MESSAGE
@ -1096,7 +1096,7 @@ function SCORING:_EventOnDeadOrCrash( Event )
self:E( { ScoringZone = ScoreZoneData } )
local ScoreZone = ScoreZoneData.ScoreZone -- Core.Zone#ZONE_BASE
local Score = ScoreZoneData.Score
if ScoreZone:IsVec2InZone( TargetDestroy.UNIT:GetVec2() ) then
if ScoreZone:IsVec2InZone( TargetUNIT:GetVec2() ) then
Player.Score = Player.Score + Score
TargetDestroy.Score = TargetDestroy.Score + Score
MESSAGE

View File

@ -192,9 +192,13 @@ end
--- Get the Task FSM Process Template
-- @param #TASK self
-- @return Core.Fsm#FSM_PROCESS
function TASK:GetUnitProcess()
function TASK:GetUnitProcess( TaskUnit )
if TaskUnit then
return self:GetStateMachine( TaskUnit )
else
return self.FsmTemplate
end
end
--- Sets the Task FSM Process Template
@ -661,15 +665,26 @@ end
--- Add a FiniteStateMachine to @{Task} with key Task@{Unit}
-- @param #TASK self
-- @param Wrapper.Unit#UNIT TaskUnit
-- @param Core.Fsm#FSM_PROCESS Fsm
-- @return #TASK self
function TASK:SetStateMachine( TaskUnit, Fsm )
self:F( { TaskUnit, self.Fsm[TaskUnit] ~= nil } )
self:F2( { TaskUnit, self.Fsm[TaskUnit] ~= nil, Fsm:GetClassNameAndID() } )
self.Fsm[TaskUnit] = Fsm
return Fsm
end
--- Gets the FiniteStateMachine of @{Task} with key Task@{Unit}
-- @param #TASK self
-- @param Wrapper.Unit#UNIT TaskUnit
-- @return Core.Fsm#FSM_PROCESS
function TASK:GetStateMachine( TaskUnit )
self:F2( { TaskUnit, self.Fsm[TaskUnit] ~= nil } )
return self.Fsm[TaskUnit]
end
--- Remove FiniteStateMachines from @{Task} with key Task@{Unit}
-- @param #TASK self
-- @param Wrapper.Unit#UNIT TaskUnit

View File

@ -70,6 +70,7 @@ do -- TASK_SEAD
Fsm:AddTransition( "Engaging", "RouteToTargets", "Engaging" )
Fsm:AddTransition( "Accounted", "DestroyedAll", "Accounted" )
Fsm:AddTransition( "Accounted", "Success", "Success" )
Fsm:AddTransition( "Rejected", "Reject", "Aborted" )
Fsm:AddTransition( "Failed", "Fail", "Failed" )
@ -82,10 +83,10 @@ do -- TASK_SEAD
self:E( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } )
-- Determine the first Unit from the self.RendezVousSetUnit
if Task:GetRendezVousZone() then
if Task:GetRendezVousZone( TaskUnit ) then
self:__RouteToRendezVousZone( 0.1 )
else
if Task:GetRendezVousPointVec2() then
if Task:GetRendezVousPointVec2( TaskUnit ) then
self:__RouteToRendezVousPoint( 0.1 )
else
self:__ArriveAtRendezVous( 0.1 )
@ -123,18 +124,18 @@ do -- TASK_SEAD
self:E( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } )
-- Determine the first Unit from the self.TargetSetUnit
if Task:GetTargetZone() then
if Task:GetTargetZone( TaskUnit ) then
self:__RouteToTargetZone( 0.1 )
else
if Task:GetTargetPointVec2() then
local TargetUnit = Task.TargetSetUnit:GetFirst() -- Wrapper.Unit#UNIT
if TargetUnit then
Task:SetTargetPointVec2( TargetUnit:GetPointVec2() )
local PointVec2 = TargetUnit:GetPointVec2()
self:T( { TargetPointVec2 = PointVec2, PointVec2:GetX(), PointVec2:GetAlt(), PointVec2:GetZ() } )
Task:SetTargetPointVec2( TargetUnit:GetPointVec2(), TaskUnit )
end
self:__RouteToTargetPoint( 0.1 )
end
end
end
--- Test
-- @param #FSM_PROCESS self
@ -144,8 +145,9 @@ do -- TASK_SEAD
self:E( { TaskUnit = TaskUnit, Task = Task and Task:GetClassNameAndID() } )
local TargetUnit = Task.TargetSetUnit:GetFirst() -- Wrapper.Unit#UNIT
if TargetUnit then
Task:SetTargetPointVec2( TargetUnit:GetPointVec2() )
Task:SetTargetPointVec2( TargetUnit:GetPointVec2(), TaskUnit )
end
self:__RouteToTargets( -10 )
end
return self
@ -160,9 +162,10 @@ do -- TASK_SEAD
--- @param #TASK_SEAD self
-- @param Core.Point#POINT_VEC2 RendezVousPointVec2 The PointVec2 object referencing to the 2D point where the RendezVous point is located on the map.
-- @param #number RendezVousRange The RendezVousRange that defines when the player is considered to have arrived at the RendezVous point.
function TASK_SEAD:SetRendezVousPointVec2( RendezVousPointVec2, RendezVousRange )
-- @param Wrapper.Unit#UNIT TaskUnit
function TASK_SEAD:SetRendezVousPointVec2( RendezVousPointVec2, RendezVousRange, TaskUnit )
local ProcessUnit = self:GetUnitProcess()
local ProcessUnit = self:GetUnitProcess( TaskUnit )
local ActRouteRendezVous = ProcessUnit:GetProcess( "RoutingToRendezVous", "RouteToRendezVousPoint" ) -- Actions.Act_Route#ACT_ROUTE_POINT
ActRouteRendezVous:SetPointVec2( RendezVousPointVec2 )
@ -170,11 +173,12 @@ do -- TASK_SEAD
end
--- @param #TASK_SEAD self
-- @param Wrapper.Unit#UNIT TaskUnit
-- @return Core.Point#POINT_VEC2 The PointVec2 object referencing to the 2D point where the RendezVous point is located on the map.
-- @return #number The RendezVousRange that defines when the player is considered to have arrived at the RendezVous point.
function TASK_SEAD:GetRendezVousPointVec2()
function TASK_SEAD:GetRendezVousPointVec2( TaskUnit )
local ProcessUnit = self:GetUnitProcess()
local ProcessUnit = self:GetUnitProcess( TaskUnit )
local ActRouteRendezVous = ProcessUnit:GetProcess( "RoutingToRendezVous", "RouteToRendezVousPoint" ) -- Actions.Act_Route#ACT_ROUTE_POINT
return ActRouteRendezVous:GetPointVec2(), ActRouteRendezVous:GetRange()
@ -184,19 +188,21 @@ do -- TASK_SEAD
--- @param #TASK_SEAD self
-- @param Core.Zone#ZONE_BASE RendezVousZone The Zone object where the RendezVous is located on the map.
function TASK_SEAD:SetRendezVousZone( RendezVousZone )
-- @param Wrapper.Unit#UNIT TaskUnit
function TASK_SEAD:SetRendezVousZone( RendezVousZone, TaskUnit )
local ProcessUnit = self:GetUnitProcess()
local ProcessUnit = self:GetUnitProcess( TaskUnit )
local ActRouteRendezVous = ProcessUnit:GetProcess( "RoutingToRendezVous", "RouteToRendezVousZone" ) -- Actions.Act_Route#ACT_ROUTE_ZONE
ActRouteRendezVous:SetZone( RendezVousZone )
end
--- @param #TASK_SEAD self
-- @param Wrapper.Unit#UNIT TaskUnit
-- @return Core.Zone#ZONE_BASE The Zone object where the RendezVous is located on the map.
function TASK_SEAD:GetRendezVousZone()
function TASK_SEAD:GetRendezVousZone( TaskUnit )
local ProcessUnit = self:GetUnitProcess()
local ProcessUnit = self:GetUnitProcess( TaskUnit )
local ActRouteRendezVous = ProcessUnit:GetProcess( "RoutingToRendezVous", "RouteToRendezVousZone" ) -- Actions.Act_Route#ACT_ROUTE_ZONE
return ActRouteRendezVous:GetZone()
@ -204,9 +210,10 @@ do -- TASK_SEAD
--- @param #TASK_SEAD self
-- @param Core.Point#POINT_VEC2 TargetPointVec2 The PointVec2 object where the Target is located on the map.
function TASK_SEAD:SetTargetPointVec2( TargetPointVec2 )
-- @param Wrapper.Unit#UNIT TaskUnit
function TASK_SEAD:SetTargetPointVec2( TargetPointVec2, TaskUnit )
local ProcessUnit = self:GetUnitProcess()
local ProcessUnit = self:GetUnitProcess( TaskUnit )
local ActRouteTarget = ProcessUnit:GetProcess( "Engaging", "RouteToTargetPoint" ) -- Actions.Act_Route#ACT_ROUTE_POINT
ActRouteTarget:SetPointVec2( TargetPointVec2 )
@ -214,10 +221,11 @@ do -- TASK_SEAD
--- @param #TASK_SEAD self
-- @param Wrapper.Unit#UNIT TaskUnit
-- @return Core.Point#POINT_VEC2 The PointVec2 object where the Target is located on the map.
function TASK_SEAD:GetTargetPointVec2()
function TASK_SEAD:GetTargetPointVec2( TaskUnit )
local ProcessUnit = self:GetUnitProcess()
local ProcessUnit = self:GetUnitProcess( TaskUnit )
local ActRouteTarget = ProcessUnit:GetProcess( "Engaging", "RouteToTargetPoint" ) -- Actions.Act_Route#ACT_ROUTE_POINT
return ActRouteTarget:GetPointVec2()
@ -226,9 +234,10 @@ do -- TASK_SEAD
--- @param #TASK_SEAD self
-- @param Core.Zone#ZONE_BASE TargetZone The Zone object where the Target is located on the map.
function TASK_SEAD:SetTargetZone( TargetZone )
-- @param Wrapper.Unit#UNIT TaskUnit
function TASK_SEAD:SetTargetZone( TargetZone, TaskUnit )
local ProcessUnit = self:GetUnitProcess()
local ProcessUnit = self:GetUnitProcess( TaskUnit )
local ActRouteTarget = ProcessUnit:GetProcess( "Engaging", "RouteToTargetZone" ) -- Actions.Act_Route#ACT_ROUTE_ZONE
ActRouteTarget:SetZone( TargetZone )
@ -236,9 +245,11 @@ do -- TASK_SEAD
--- @param #TASK_SEAD self
-- @param Wrapper.Unit#UNIT TaskUnit
-- @return Core.Zone#ZONE_BASE The Zone object where the Target is located on the map.
function TASK_SEAD:GetTargetZone()
local ProcessUnit = self:GetUnitProcess()
function TASK_SEAD:GetTargetZone( TaskUnit )
local ProcessUnit = self:GetUnitProcess( TaskUnit )
local ActRouteTarget = ProcessUnit:GetProcess( "Engaging", "RouteToTargetZone" ) -- Actions.Act_Route#ACT_ROUTE_ZONE
return ActRouteTarget:GetZone()

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -88,7 +88,7 @@ SEADSet:Flush()
-- Define the set of units that are the targets.
-- Note that I use FilterOnce, which means that the set will be defined only once,
-- and will not be continuously updated!
local TargetSet = SET_UNIT:New():FilterPrefixes( "US Hawk SR" ):FilterOnce()
local TargetSet = SET_UNIT:New():FilterPrefixes( "US Hawk SR" ):FilterStart()
-- Define the RendezVous Zone where the pilot needs to RendezVous with other players before engaging.
local RendezVousZone = ZONE:New( "RendezVous Zone" )