This commit is contained in:
FlightControl_Master
2017-10-03 19:19:09 +02:00
parent 78f4f532f7
commit 1f5030fcbc
96 changed files with 7501 additions and 99 deletions

View File

@@ -269,6 +269,19 @@ function BASE:Inherit( Child, Parent )
return Child
end
local function getParent( Child )
local Parent = nil
if rawget( Child, "__" ) then
Parent = getmetatable( Child.__ ).__index
else
Parent = getmetatable( Child ).__index
end
return Parent
end
--- This is the worker method to retrieve the Parent class.
-- Note that the Parent class must be passed to call the parent class method.
--
@@ -278,17 +291,27 @@ end
-- @param #BASE self
-- @param #BASE Child is the Child class from which the Parent class needs to be retrieved.
-- @return #BASE
function BASE:GetParent( Child )
function BASE:GetParent( Child, FromClass )
local Parent
-- BASE class has no parent
if Child.ClassName == 'BASE' then
Parent = nil
elseif rawget( Child, "__" ) then
Parent = getmetatable( Child.__ ).__index
else
Parent = getmetatable( Child ).__index
end
return Parent
else
self:E({FromClass = FromClass})
self:E({Child = Child.ClassName})
if FromClass then
while( Child.ClassName ~= FromClass.ClassName ) do
Child = getParent( Child )
self:E({Child.ClassName})
end
end
Parent = getParent( Child )
end
self:E({Parent.ClassName})
return Parent
end
--- This is the worker method to check if an object is an (sub)instance of a class.
@@ -334,7 +357,7 @@ function BASE:IsInstanceOf( ClassName )
return true
end
local Parent = self:GetParent(self)
local Parent = getParent(self)
while Parent do
@@ -342,7 +365,7 @@ function BASE:IsInstanceOf( ClassName )
return true
end
Parent = Parent:GetParent(Parent)
Parent = getParent(Parent)
end

View File

@@ -77,8 +77,6 @@ do -- Goal
-- @param #string Event
-- @param #string To
GOAL.States.On = "On"
end
do
@@ -101,13 +99,10 @@ do -- Goal
-- @param #string Event
-- @param #string To
GOAL.States.Off = "Off"
end
--- Achieved State for GOAL
-- @field GOAL.Achieved
GOAL.States.Achieved = "Achieved"
--- Achieved State Handler OnLeave for GOAL
-- @function [parent=#GOAL] OnLeaveAchieved
@@ -125,8 +120,8 @@ do -- Goal
-- @param #string To
self:SetStartState( GOAL.States.Off )
self:AddTransition( GOAL.States.Off, "Start", GOAL.States.On )
self:SetStartState( "Idle" )
self:AddTransition( "Idle", "Start", "On" )
--- Start Handler OnBefore for GOAL
-- @function [parent=#GOAL] OnBeforeStart
@@ -152,7 +147,7 @@ do -- Goal
-- @param #GOAL self
-- @param #number Delay
self:AddTransition( GOAL.States.On, "Stop", GOAL.States.Off )
self:AddTransition( "On", "Stop", "Idle" )
--- Stop Handler OnBefore for GOAL
-- @function [parent=#GOAL] OnBeforeStop
@@ -179,7 +174,7 @@ do -- Goal
-- @param #number Delay
self:AddTransition( GOAL.States.On, "IsAchieved", GOAL.States.On )
self:AddTransition( "On", "IsAchieved", "On" )
--- IsAchieved Handler OnBefore for GOAL
-- @function [parent=#GOAL] OnBeforeIsAchieved
@@ -205,7 +200,7 @@ do -- Goal
-- @param #GOAL self
-- @param #number Delay
self:AddTransition( GOAL.States.On, "Achieved", GOAL.States.Achieved )
self:AddTransition( "On", "Achieved", "Achieved" )
--- Achieved Handler OnBefore for GOAL
-- @function [parent=#GOAL] OnBeforeAchieved

View File

@@ -10,15 +10,15 @@
--
-- ====
--
-- @module Zone
-- @module ZoneGoal
do -- Zone
--- @type ZONE_GOAL
-- @extends Core.Goal#GOAL
-- @extends Core.Fsm#FSM
--- # ZONE_GOAL class, extends @{Goal#GOAL}
--- # ZONE_GOAL class, extends @{Fsm#FSM}
--
-- ZONE_GOAL models processes that have an objective with a defined achievement involving a Zone. Derived classes implement the ways how the achievements can be realized.
--
@@ -56,7 +56,8 @@ do -- Zone
self:F( { Zone = Zone } )
self.Zone = Zone -- Core.Zone#ZONE_BASE
self.Goal = GOAL:New():Start()
self.Goal = GOAL:New()
self.Goal:Start()
do
@@ -75,8 +76,6 @@ do -- Zone
-- @param #string Event
-- @param #string To
ZONE_GOAL.States.Guarded = "Guarded"
end
@@ -97,12 +96,10 @@ do -- Zone
-- @param #string Event
-- @param #string To
ZONE_GOAL.States.Empty = "Empty"
end
self:AddTransition( "*", "Guard", ZONE_GOAL.States.Guarded )
self:AddTransition( "*", "Guard", "Guarded" )
--- Guard Handler OnBefore for ZONE_GOAL
-- @function [parent=#ZONE_GOAL] OnBeforeGuard
@@ -128,7 +125,7 @@ do -- Zone
-- @param #ZONE_GOAL self
-- @param #number Delay
self:AddTransition( "*", "Empty", ZONE_GOAL.States.Empty )
self:AddTransition( "*", "Empty", "Empty" )
--- Empty Handler OnBefore for ZONE_GOAL
-- @function [parent=#ZONE_GOAL] OnBeforeEmpty
@@ -228,15 +225,16 @@ do -- Zone
-- @param #ZONE_GOAL self
function ZONE_GOAL:StatusZone()
local State = self:GetState()
self:E( { State = self:GetState() } )
self.Zone:Scan()
if self:IsGuarded() then
if State ~= "Guarded" and self:IsGuarded() then
self:Guard()
end
if self:IsEmpty() then
if State ~= "Empty" and self:IsEmpty() then
self:Empty()
end

View File

@@ -2,7 +2,8 @@
--
-- ====
--
-- ZONE_GOAL_COALITION models processes that have an objective with a defined achievement involving a Zone. Derived classes implement the ways how the achievements can be realized.
-- ZONE_GOAL_COALITION models processes that have a Goal with a defined achievement involving a Zone for a Coalition.
-- Derived classes implement the ways how the achievements can be realized.
--
-- ====
--
@@ -10,17 +11,18 @@
--
-- ====
--
-- @module ZoneGoal
-- @module ZoneGoalCoalition
do -- ZoneGoal
--- @type ZONE_GOAL_COALITION
-- @extends Core.Goal#ZONE_GOAL_COALITION
-- @extends Core.ZoneGoal#ZONE_GOAL
--- # ZONE_GOAL_COALITION class, extends @{Goal#GOAL}
--- # ZONE_GOAL_COALITION class, extends @{ZoneGoal#ZONE_GOAL}
--
-- ZONE_GOAL_COALITION models processes that have an objective with a defined achievement involving a Zone. Derived classes implement the ways how the achievements can be realized.
-- ZONE_GOAL_COALITION models processes that have a Goal with a defined achievement involving a Zone for a Coalition.
-- Derived classes implement the ways how the achievements can be realized.
--
-- ## 1. ZONE_GOAL_COALITION constructor
--
@@ -29,16 +31,26 @@ do -- ZoneGoal
-- ## 2. ZONE_GOAL_COALITION is a finite state machine (FSM).
--
-- ### 2.1 ZONE_GOAL_COALITION States
--
-- * **Off**: The goal is not timely measured.
-- * **On**: The goal is timely being measured.
-- * **Achieved**: The objective is achieved.
--
-- * **Captured**: The Zone has been captured by an other coalition.
-- * **Attacked**: The Zone is currently intruded by an other coalition. There are units of the owning coalition and an other coalition in the Zone.
-- * **Guarded**: The Zone is guarded by the owning coalition. There is no other unit of an other coalition in the Zone.
-- * **Empty**: The Zone is empty. There is not valid unit in the Zone.
--
-- ### 2.2 ZONE_GOAL_COALITION Events
--
-- * **@{#ZONE_GOAL_COALITION.Start}()**: Start Measuring the Goal.
-- * **@{#ZONE_GOAL_COALITION.Stop}()**: Stop Measuring the Goal.
-- * **@{#ZONE_GOAL_COALITION.IsAchieved}()**: Check if the Goal is Achieved.
-- * **Capture**: The Zone has been captured by an other coalition.
-- * **Attack**: The Zone is currently intruded by an other coalition. There are units of the owning coalition and an other coalition in the Zone.
-- * **Guard**: The Zone is guarded by the owning coalition. There is no other unit of an other coalition in the Zone.
-- * **Empty**: The Zone is empty. There is not valid unit in the Zone.
--
-- ### 2.3 ZONE_GOAL_COALITION State Machine
--
--
--
-- Hello | World
-- ------|------
-- Test|Test2
--
-- @field #ZONE_GOAL_COALITION
ZONE_GOAL_COALITION = {
@@ -77,8 +89,6 @@ do -- ZoneGoal
-- @param #string Event
-- @param #string To
ZONE_GOAL_COALITION.States.Captured = "Captured"
end
@@ -99,13 +109,13 @@ do -- ZoneGoal
-- @param #string Event
-- @param #string To
ZONE_GOAL_COALITION.States.Attacked = "Attacked"
end
self:E( { Guarded = "Guarded" } )
self:AddTransition( { ZONE_GOAL_COALITION.States.Guarded, ZONE_GOAL_COALITION.States.Empty }, "Attack", ZONE_GOAL_COALITION.States.Attacked )
self:AddTransition( { "Guarded", "Empty" }, "Attack", "Attacked" )
--- Attack Handler OnBefore for ZONE_GOAL_COALITION
-- @function [parent=#ZONE_GOAL_COALITION] OnBeforeAttack
@@ -131,7 +141,7 @@ do -- ZoneGoal
-- @param #ZONE_GOAL_COALITION self
-- @param #number Delay
self:AddTransition( { ZONE_GOAL_COALITION.States.Guarded, ZONE_GOAL_COALITION.States.Attacked, ZONE_GOAL_COALITION.States.Empty }, "Capture", ZONE_GOAL_COALITION.States.Captured )
self:AddTransition( { "Guarded", "Attacked", "Empty" }, "Capture", "Captured" )
--- Capture Handler OnBefore for ZONE_GOAL_COALITION
-- @function [parent=#ZONE_GOAL_COALITION] OnBeforeCapture
@@ -265,7 +275,7 @@ do -- ZoneGoal
--self:GetParent( self ):onenterCaptured()
local NewCoalition = self.ProtectZone:GetCoalition()
local NewCoalition = self.Zone:GetCoalition()
self:E( { NewCoalition = NewCoalition } )
self:SetCoalition( NewCoalition )
@@ -324,15 +334,16 @@ do -- ZoneGoal
-- @param #ZONE_GOAL_COALITION self
function ZONE_GOAL_COALITION:StatusZone()
local State = self:GetState()
self:E( { State = self:GetState() } )
self:GetParent( self ):StatusZone()
self:GetParent( self, ZONE_GOAL_COALITION ).StatusZone( self )
if self:IsAttacked() then
if State ~= "Attacked" and self:IsAttacked() then
self:Attack()
end
if self:IsCaptured() then
if State ~= "Captured" and self:IsCaptured() then
self:Capture()
end

View File

@@ -18,7 +18,7 @@ do -- ZoneGoal
-- @extends Core.ZoneGoalCoalition#ZONE_GOAL_COALITION
--- # ZONE_CAPTURE_COALITION class, extends @{Goal#GOAL}
--- # ZONE_CAPTURE_COALITION class, extends @{ZoneGoalCoalition#ZONE_GOAL_COALITION}
--
-- ZONE_CAPTURE_COALITION models processes that have an objective with a defined achievement involving a Zone. Derived classes implement the ways how the achievements can be realized.
--
@@ -50,7 +50,7 @@ do -- ZoneGoal
local self = BASE:Inherit( self, ZONE_GOAL_COALITION:New( Zone, Coalition ) ) -- #ZONE_CAPTURE_COALITION
self:F( { Zone = Zone, Coalition = Coalition } )
return self
end