示例#1
0
 //-----------------------------------------------------------------------------------------------
 public void ClearPlan()
 {
     m_activeStrategyPlan.ClearPlan();
     StopSync();
 }
示例#2
0
    //-----------------------------------------------------------------------------------------------
    public Plan HandleAgentPlanRequest(AgentPlanRequest request)
    {
        int currentIndex = request.m_nextTaskIndex;

        // plan finished
        if (IsPlanFinished(currentIndex))
        {
            return(null);
        }

        // Can't get a new plan if syncing
        if (m_isSyncing && (currentIndex > m_syncIndex))
        {
            return(null);
        }

        Plan agentPlan     = new Plan();
        bool canGetNewTask = true;

        while (canGetNewTask)
        {
            PrimitiveTask taskToGet = m_activeStrategyPlan.TaskList[currentIndex];
            if (taskToGet.IsClaimed)
            {
                ++currentIndex;
                continue;
            }

            // Handle modifiers on task
            uint taskMods = taskToGet.ModifierMask;

            // Blocking tasks mean we can't get more tasks until we're done
            if ((taskMods & (byte)Task.eModifier.BLOCKING_MODIFIER) != 0)
            {
                canGetNewTask = false;
            }

            // Sync tasks require everyone to reach the task before continuing
            if ((taskMods & (byte)Task.eModifier.SYNC_MODIFIER) != 0)
            {
                m_isSyncing = true;
                m_syncIndex = currentIndex;
                ++m_syncCount;

                // extra check to see if done syncing
                if (m_syncCount == m_numActiveAgents)
                {
                    StopSync();
                    ++currentIndex;
                    agentPlan.ClearPlan();
                    continue;
                }
                else
                {
                    canGetNewTask = false;
                }
            }

            // Reservable tasks can be claimed and ran only once
            if ((taskMods & (byte)Task.eModifier.RESERVABLE_MODIFIER) != 0)
            {
                taskToGet.Claim();
            }

            // Add task to plan and increment index
            PrimitiveTask taskClone = taskToGet.Clone() as PrimitiveTask;
            taskClone.Op.AssignVariables(request.m_agent);

            agentPlan.AddTask(taskClone);
            ++currentIndex;

            if (m_activeStrategyPlan.IsIndexOutOfPlan(currentIndex))
            {
                canGetNewTask = false;
            }
        }

        request.m_agent.CurrentPlanIndex = currentIndex;
        return(agentPlan);
    }