Exemple #1
0
        public override void action()
        {
            Agent agt = (Agent)(this.Host);

            if (ispause)
            {
                return;
            }
            // StreamWriter file = MascaretApplication.Instance.logfile;
            //file.WriteLine("NB PRocs : " + runningProcedures.Count); file.Flush();

            if (runningProcedures.Count > 0)
            {
                for (int iP = 0; iP < runningProcedures.Count; iP++)
                {
                    // file.WriteLine("ProceduralBehavior in procedure " + runningProcedures[iP].procedure.name); file.Flush();
                    ProcedureExecution procInfo    = runningProcedures[iP];
                    List <ActionNode>  actionNodes = new List <ActionNode>();

                    //remove those which are not agreed upon

                    /*if (agt.ControlledByHuman)
                     * {
                     *   MascaretApplication.Instance.VRComponentFactory.Log("[ProceduralBehavior Info] Agent controlled ... ");
                     *   actionNodes = procInfo.getActionToExecute();
                     *   for (int atd = 0; atd < actionNodes.Count; ++atd)
                     *     MascaretApplication.Instance.VRComponentFactory.Log("ProceduralBehavior Info] -- Human has to do : " + actionNodes[atd].name);
                     *   actionNodes.Clear();
                     *
                     *   for (int atd = 0; atd < actionsToDo.Count; ++atd)
                     *   {
                     *       actionNodes.Add(actionsToDo[atd]);
                     *   }
                     *   actionsToDo.Clear();
                     * }
                     * else*/
                    {
                        actionNodes = procInfo.getActionToExecute();
                    }
                    if (actionNodes.Count > 0)
                    {
                        for (int i = 0; i < actionNodes.Count; i++)
                        {
                            //Dictionary<string, InstanceSpecification> affectations = procInfo.getAffectations();
                            //actionNodes[i].procInfo.procedure.Activity.Context
                            bool isCallBehavior = false;
                            if (actionNodes[i].Action.Kind == "CallBehavior")
                            {
                                isCallBehavior = true;
                            }
                            if (!agt.ControlledByHuman)
                            {
                                actionNodes[i].start(agt, procInfo.getAffectations(), false); //TODO ///////////////////////////////////////// if not flag start, else start
                                sendActionRealisationMessage(actionNodes[i], procInfo);       // TODO
                                procInfo.informActionRunning(agt.Aid, actionNodes[i]);

                                if (actionNodes[i].CurrentExecution != null)
                                {
                                    behaviorToNode.Add(actionNodes[i].CurrentExecution, actionNodes[i]);
                                    actionNodes[i].CurrentExecution.addCallbackOnBehaviorStop(onBehaviorStop);
                                }
                                else
                                {
                                    procInfo.informActionDone(agt.Aid, actionNodes[i]); //TODO
                                    sendActionDoneMessage(actionNodes[i], procInfo);
                                }
                            }
                            else
                            {
                                if (isCallBehavior)
                                {
                                    actionNodes[i].start(agt, procInfo.getAffectations(), false); //TODO ///////////////////////////////////////// if not flag start, else start
                                    sendActionRealisationMessage(actionNodes[i], procInfo);       // TODO
                                    procInfo.informActionRunning(agt.Aid, actionNodes[i]);

                                    if (actionNodes[i].CurrentExecution != null)
                                    {
                                        behaviorToNode.Add(actionNodes[i].CurrentExecution, actionNodes[i]);
                                        actionNodes[i].CurrentExecution.addCallbackOnBehaviorStop(onBehaviorStop);
                                    }
                                    else
                                    {
                                        procInfo.informActionDone(agt.Aid, actionNodes[i]); //TODO
                                        sendActionDoneMessage(actionNodes[i], procInfo);
                                    }
                                }
                                else
                                {
                                    actionsToDo.Add(actionNodes[i]);
                                    MascaretApplication.Instance.VRComponentFactory.Log("ProceduralBehavior Info] -- Human has to do : " + actionNodes[i].name);
                                }
                            }
                        }
                    }
                    else if (agt.getMessageQueue().Count == 0)
                    {
                        //pause();
                        //ispause = true;
                    }

                    if (procInfo.isFinished())
                    {
                        //file.WriteLine("ProceduralBehavior Procedure : " + runningProcedures[iP].procedure.name + " finie "); file.Flush();
                        //inform all agents that this agent's role in this procedure has ended (used to unblock tokens in ProcedureExecution)
                        sendProcedureDoneMessage(procInfo);

                        runningProcedures[iP] = runningProcedures[runningProcedures.Count - 1];
                        runningProcedures.RemoveAt(runningProcedures.Count - 1);
                        //cerr << getHost()->getName()<<" : suppression de la procedure"<< endl;
                    }
                    else
                    {
                        iP++;
                    }
                }
            }
            else
            {
                ispause = true;
            }
        }