This commit is contained in:
FlightControl
2017-02-18 19:51:20 +01:00
parent 5c090b108c
commit f9708de598
16 changed files with 318 additions and 137 deletions

View File

@@ -869,6 +869,27 @@ do -- FSM_PROCESS
function FSM_PROCESS:Init( FsmProcess )
self:T( "No Initialisation" )
end
function FSM_PROCESS:_call_handler( handler, params, EventName )
local ErrorHandler = function( errmsg )
env.info( "Error in FSM_PROCESS call handler:" .. errmsg )
if debug ~= nil then
env.info( debug.traceback() )
end
return errmsg
end
if self[handler] then
self:F3( "Calling " .. handler )
self._EventSchedules[EventName] = nil
local Result, Value = xpcall( function() return self[handler]( self, self.Controllable, self.Task, unpack( params ) ) end, ErrorHandler )
return Value
--return self[handler]( self, self.Controllable, unpack( params ) )
end
end
--- Creates a new FSM_PROCESS object based on this FSM_PROCESS.
-- @param #FSM_PROCESS self
@@ -893,7 +914,7 @@ do -- FSM_PROCESS
-- Copy Processes
for ProcessID, Process in pairs( self:GetProcesses() ) do
self:T( { Process} )
self:E( { Process} )
local FsmProcess = NewFsm:AddProcess( Process.From, Process.Event, Process.fsm:Copy( Controllable, Task ), Process.ReturnEvents )
end

View File

@@ -240,6 +240,7 @@ SET_BASE = {
Filter = {},
Set = {},
List = {},
Index = {},
}
--- Creates a new SET_BASE object, building a set of units belonging to a coalitions, categories, countries, types or with defined prefix names.
@@ -258,10 +259,14 @@ function SET_BASE:New( Database )
self.YieldInterval = 10
self.TimeInterval = 0.001
self.Set = {}
self.List = {}
self.List.__index = self.List
self.List = setmetatable( { Count = 0 }, self.List )
self.Index = {}
self.CallScheduler = SCHEDULER:New( self )
self:SetEventPriority( 2 )
@@ -313,6 +318,8 @@ function SET_BASE:Add( ObjectName, Object )
self.Set[ObjectName] = t._
table.insert( self.Index, ObjectName )
end
--- Adds a @{Base#BASE} object in the @{Set#SET_BASE}, using the Object Name as the index.
@@ -364,7 +371,15 @@ function SET_BASE:Remove( ObjectName )
t._prev = nil
self.List.Count = self.List.Count - 1
for Index, Key in ipairs( self.Index ) do
if Key == ObjectName then
table.remove( self.Index, Index )
break
end
end
self.Set[ObjectName] = nil
end
end
@@ -406,13 +421,26 @@ function SET_BASE:GetLast()
return t
end
--- Gets a random object from the @{Set#SET_BASE} and derived classes.
-- @param #SET_BASE self
-- @return Core.Base#BASE
function SET_BASE:GetRandom()
self:F()
local RandomItem = self.Set[self.Index[math.random(#self.Index)]]
self:T3( { RandomItem } )
return RandomItem
end
--- Retrieves the amount of objects in the @{Set#SET_BASE} and derived classes.
-- @param #SET_BASE self
-- @return #number Count
function SET_BASE:Count()
return self.List.Count
return #self.Index
end