# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

operator_script.cpp

Go to the documentation of this file.
00001 #include "nel/ai/logic/operator_script.h"
00002 #include "nel/ai/agent/agent_script.h"
00003 #include "nel/ai/agent/object_type.h"
00004 #include "nel/ai/script/codage.h"
00005 #include "nel/ai/logic/interpret_object_operator.h"
00006 #include "nel/ai/agent/comp_handle.h"
00007 #include "nel/ai/fuzzy/fuzzyset.h"
00008 #include "nel/ai/logic/valueset.h"
00009 #include "nel/ai/logic/factbase.h"
00010 #include "nel/ai/agent/agent_proxy_mailer.h"
00011 #include "nel/ai/agent/msg_goal.h"
00012 #include "nel/ai/script/interpret_object_message.h"
00013 
00014 namespace NLAIAGENT
00015 {
00016         static CGroupType listBidon;
00017 
00018         COperatorScript::COperatorScript(const COperatorScript &a) : CActorScript(a)
00019         {
00020                 _CurrentGoal = a._CurrentGoal;          
00021                 _CyclesBeforeUpdate = a._CyclesBeforeUpdate;
00022                 _IsActivable = a._IsActivable;
00023                 _Maintain = a._Maintain;
00024                 _Priority = 0;
00025                 _Exclusive = a._Exclusive;
00026                 _BasePriority = a._BasePriority;
00027         }
00028 
00029         COperatorScript::COperatorScript(IAgentManager *manager, 
00030                                                            IBasicAgent *father,
00031                                                            std::list<IObjectIA *> &components,  
00032                                                            NLAISCRIPT::COperatorClass *actor_class )
00033         : CActorScript(manager, father, components, actor_class )
00034         {       
00035                 _CurrentGoal = NULL;
00036                 _CyclesBeforeUpdate = 0;
00037                 _IsActivable = false;
00038                 _Maintain = false;
00039                 _Priority = 0;
00040                 _Exclusive = true;
00041         }       
00042 
00043         COperatorScript::COperatorScript(IAgentManager *manager, bool stay_alive) : CActorScript( manager )
00044         {
00045                 _CurrentGoal = NULL;
00046                 _CyclesBeforeUpdate = 0;
00047                 _IsActivable = false;
00048                 _Maintain = false;
00049                 _Priority = 0;
00050                 _Exclusive = true;
00051         }
00052 
00053         COperatorScript::~COperatorScript()
00054         {
00055 #ifdef NL_DEBUG
00056                 //const char *className = (const char *)getType();
00057 #endif
00058                 std::vector<NLAIAGENT::IObjectIA *>::iterator it_val = _VarValues.begin();
00059                 while ( it_val != _VarValues.end() )
00060                 {
00061                         (*it_val)->release();
00062                         it_val++;
00063                 }
00064         }
00065 
00066         void COperatorScript::onKill(IConnectIA *a)
00067         {
00068                 CActorScript::onKill(a);
00069         }
00070 
00071         const NLAIC::IBasicType *COperatorScript::clone() const
00072         {               
00073                 COperatorScript *m = new COperatorScript(*this);
00074                 return m; 
00075         }               
00076 
00077         const NLAIC::IBasicType *COperatorScript::newInstance() const
00078         {       
00079                 COperatorScript *instance;
00080                 if ( _AgentClass )
00081                 {
00082                         instance = (COperatorScript *) _AgentClass->buildNewInstance();
00083                 }
00084                 else 
00085                 {                       
00086                         instance = new COperatorScript(NULL);
00087                 }
00088                 return instance;
00089         }
00090         
00091         void COperatorScript::getDebugString(std::string &t) const
00092         {
00093                 if ( _AgentClass )
00094                         _AgentClass->getDebugString(t);
00095                 else
00096                         t += "<COperatorScript>";
00097                 t += "<";
00098 
00099                 if ( _IsActivated )
00100                         t += "activated>";
00101                 else
00102                         t += "idle>";
00103                 t += " <P ";
00104                 std::string text;
00105                 text = NLAIC::stringGetBuild("%f", priority() );
00106                 t += text;
00107                 t += "\n\t";
00108 
00109                 if( _AgentManager != NULL)
00110                 {
00111                         const NLAISCRIPT::CParam p;
00112                         static CStringVarName debugStringF("GetDebugString");
00113 
00114                         tQueue r = isMember(NULL,&debugStringF,p);
00115                         if(r.size())
00116                         {
00117                                 NLAISCRIPT::CCodeContext *c = (NLAISCRIPT::CCodeContext *)_AgentManager->getAgentContext()->clone();
00118                                 NLAIAGENT::CIdMethod m = r.top();
00119                                 //msg->setMethodIndex(0,m.Index);       
00120                                 c->Self = this;
00121 
00122                                 IBaseGroupType *param = new CGroupType();                                                               
00123                                 (*c).Stack ++;
00124                                 (*c).Stack[(int)(*c).Stack] = param;
00125                                 NLAISCRIPT::IMethodContext *methodContex = new NLAISCRIPT::CMethodContext();
00126                                 NLAISCRIPT::CCallMethod opCall(methodContex,0,m.Index);
00127                                 opCall.runOpCode(*c);                                                                                           
00128                                 const NLAIAGENT::CStringType *returnMsg = (const NLAIAGENT::CStringType *)c->Stack[(int)(*c).Stack];                            
00129                                 t += returnMsg->getStr().getString();
00130                                 (*c).Stack--;
00131                                 c->release();                           
00132                         }
00133                 }
00134         }
00135 
00136         bool COperatorScript::isEqual(const IBasicObjectIA &a) const
00137         {
00138                 return true;
00139         }
00140 
00141         const NLAIC::CIdentType &COperatorScript::getType() const
00142         {               
00143                 if ( getFactoryClass() != NULL ) 
00144                         return getFactoryClass()->getType();
00145                 else
00146                         return IdOperatorScript;
00147         }
00148 
00149         void COperatorScript::save(NLMISC::IStream &os)
00150         {
00151                 CAgentScript::save(os);
00152                 // TODO
00153         }
00154 
00155         void COperatorScript::load(NLMISC::IStream &is)
00156         {
00157                 CAgentScript::load(is);
00158                 // TODO
00159         }
00160 
00161         // This is where the activation of the operator and its children is controled...
00162         const IObjectIA::CProcessResult &COperatorScript::run()
00163         {
00164 
00165 #ifdef NL_DEBUG
00166                 const char *dbg_class_name = (const char *) getType();
00167                 std::string dbg_goal;           
00168 #endif
00169 
00170                 // Checks the goal and preconditions after a certain number of cycles (defined in the script using the UdpateEvery keyword)
00171                 if ( _CyclesBeforeUpdate == 0 )
00172                 {
00173                         _IsActivable = checkActivation();
00174                         _CyclesBeforeUpdate = ( (NLAISCRIPT::COperatorClass *) _AgentClass )->getUpdateEvery();
00175                         calcPriority();
00176                 }
00177                 else
00178                         _CyclesBeforeUpdate--;
00179 
00180                 if ( _IsActivable ) // If the goal exists and the preconditions are validated
00181                 {
00182                         if ( ! _IsActivated )           // If the operator wasn't activated before, initialises the current goal and runs the OnActivate() function
00183                         {
00184                                 // Registers to the goal and gets the args
00185                                 if ( _CurrentGoal == NULL && ( (NLAISCRIPT::COperatorClass *) _AgentClass )->getGoal() != NULL )
00186                                 {
00187                                         _CurrentGoal = selectGoal();                                                    // Select a goal among possible ones
00188 #ifdef NL_DEBUG
00189         {
00190 //              static sint untrucMerdic = 0;
00191 //              nlinfo("_CurrentGoal = 0x%4x, at untrucMerdic = %d",_CurrentGoal, untrucMerdic ++);
00192         }
00193 #endif
00194                                         _CurrentGoal->addSuccessor( (IBasicAgent *) this );             // Adds the operator to the list of operators launched for this goal
00195                                         linkGoalArgs( _CurrentGoal );                                                   // Instanciates the goal's args values into the operator's components
00196                                 }
00197 
00198                                 if ( ( _CurrentGoal != NULL && _CurrentGoal->isSelected() ) || ( (NLAISCRIPT::COperatorClass *) _AgentClass )->getGoal() == NULL)
00199                                 {
00200                                         activate();
00201                                         execOnActivate();       // Execs onActivate() function in the script if defined, otherwise the C++ one inherited from CActorScript.
00202                                 }
00203                         }
00204                         else
00205                                 checkPause();                   // Check if the agent must be paused / restarted
00206 
00207                         // If the operator is activated and not paused, runs it (including its children), 
00208                         // otherwise just process messages
00209                         if ( _IsActivated )
00210                         {
00211                                 if( !_IsPaused ) 
00212                                         return CAgentScript::run();
00213                                 else
00214                                 {
00215                                         CActorScript::processMessages();
00216                                         return IObjectIA::ProcessRun;
00217                                 }
00218                         }
00219                         else
00220                                 CActorScript::processMessages();
00221                 }
00222                 else
00223                 {
00224                         if ( _IsActivated == true )             // If the operator is curently activated, unactivates it
00225                         {
00226                                 unActivate();
00227                                 _CurrentGoal = NULL;                            
00228                         }
00229                         CActorScript::processMessages();
00230                         return IObjectIA::ProcessRun;
00231                 }
00232                 return IObjectIA::ProcessRun;
00233         }
00234 
00235 
00236         void COperatorScript::execOnActivate()
00237         {
00238 #ifdef NL_DEBUG
00239                 const char *dbg_class_name = (const char *) getType();
00240 #endif
00241                 if ( _OnActivateIndex != -1 )                                   // if found, runs the script's OnActivate() function declared in the operator class
00242                 {
00243                         if ( getAgentManager() != NULL )
00244                         {
00245                                 NLAISCRIPT::CCodeContext *context = (NLAISCRIPT::CCodeContext *) getAgentManager()->getAgentContext();
00246 #ifdef NL_DEBUG
00247                                 sint sp = context->Stack.CIndexStackPointer::operator int ();
00248 #endif
00249                                 context->Self = this;
00250                                 IObjectIA::CProcessResult r = runMethodeMember( _OnActivateIndex , context);
00251                                 if(r.Result != NULL)
00252                                 {
00253                                         throw;
00254                                 }
00255 
00256 #ifdef NL_DEBUG
00257                                 if ( sp != context->Stack.CIndexStackPointer::operator int () )
00258                                 {
00259                                         throw;
00260                                 }
00261 #endif
00262                                 _OnActivateIndex = -1;
00263                         }
00264                 }
00265                 else
00266                         onActivate();                                                           // Otherwise runs the C++ virtual one (inherited from CActorScript)
00267         }
00268 
00269         void COperatorScript::checkPause()
00270         {
00271 #ifdef NL_DEBUG
00272                 const char *dbg_class_name = (const char *) getType();
00273 #endif
00274                 if ( (_CurrentGoal != NULL) )
00275                 {
00276                         if ( !_IsPaused && !_CurrentGoal->isSelected() )
00277                                 pause();
00278                         if ( _IsPaused && _CurrentGoal->isSelected() )
00279                                 restart();
00280                 }
00281         }
00282 
00283         // This function selects a goals among the ones the operator can process
00284         // Actualy returns the first of the list (can be overriden to implement more complex mechanisms)
00285         NLAILOGIC::CGoal *COperatorScript::selectGoal()
00286         {
00287                 if ( !_ActivatedGoals.empty() )
00288                 {
00289                         // TODO: instantiate each goal's variables and compute priority.
00290                         // then select the highest priority goal.
00291                         return _ActivatedGoals.front();
00292                 }
00293 
00294                 else
00295                         return NULL;
00296         }
00297 
00298         // Check if the owner of the operator has a goal the operator could process and if the preconditions are validated
00299         bool COperatorScript::checkActivation()
00300         {
00301 #ifdef NL_DEBUG
00302                 const char *dbg_class_name = (const char *) getType();
00303 #endif
00304 
00305                 // If not in maintain mode and the operator has already been activated, keeps it activated.
00306                 if ( _IsActivated && _CurrentGoal != NULL && !_Maintain)
00307                         return true;
00308 
00309                 if ( ( (NLAISCRIPT::COperatorClass *) _AgentClass )->getGoal() != NULL)
00310                 {
00311 //                      if ( _CurrentGoal != NULL )
00312                                 lookForGoals();
00313 
00314                         // If no goal is posted corresponding to this operator's one, returns false
00315                         if ( _ActivatedGoals.empty() )
00316                                 return false;   
00317 
00318                         std::list<NLAILOGIC::CGoal *>::iterator it_goal = _ActivatedGoals.begin();
00319                         while ( it_goal != _ActivatedGoals.end() )
00320                         {
00321                                 linkGoalArgs( *it_goal );
00322                                 if ( checkPreconditions() == true )
00323                                 {
00324                                         NLAILOGIC::CGoal *goal = *it_goal;
00325                                         _ActivatedGoals.clear();
00326                                         _ActivatedGoals.push_back( goal );
00327                                         return true;
00328                                 }
00329                                 it_goal++;
00330                         }
00331                         return false;
00332                 }
00333                 else
00334                         return checkPreconditions();
00335         }
00336 
00337         // Looks for the goals the operator could process in the father's goal stack
00338         void COperatorScript::lookForGoals()
00339         {
00340 #ifdef NL_DEBUG
00341                 const char *dbg_class_name = (const char *) getType();
00342 #endif
00343                 _ActivatedGoals.clear();
00344                 CAgentScript *father = (CAgentScript *) getParent();
00345                 const std::vector<NLAILOGIC::CGoal *> *goals = father->getGoalStack();
00346 
00347                 int i;
00348                 for ( i = 0; i < (int) goals->size(); i++ )
00349                 {
00350                         if ( (*( (*goals)[i])) == *( (NLAISCRIPT::COperatorClass *) _AgentClass )->getGoal() )
00351                                 _ActivatedGoals.push_back( (*goals)[i] );
00352                 }
00353         }
00354 
00355         // Checks the boolean scripted funcs conditions
00356         bool COperatorScript::checkPreconditions()
00357         {
00358 #ifdef NL_DEBUG
00359                 const char *dbg_class_name = (const char *) getType();
00360 #endif
00361                 // Checks for message triggers
00362                 if ( ( (NLAISCRIPT::COperatorClass *) _AgentClass )->NbMsgTrigger() != 0 && !checkTrigMsg() )
00363                         return false;
00364 
00365                 NLAISCRIPT::CCodeContext *context = (NLAISCRIPT::CCodeContext *) getAgentManager()->getAgentContext();
00366                 context->Self = this;
00367                 return ((NLAISCRIPT::COperatorClass *)_AgentClass)->isValidFonc( context );
00368         }
00369 
00370         // Called by the goal when canceled: removes all childs and unactivates the operator.
00371         void COperatorScript::cancel()
00372         {
00373                 _CurrentGoal = NULL;
00374                 CActorScript::cancel();
00375                 _CurrentGoal = NULL;
00376         }
00377 
00378         // The priority of an operator is calculated as follow:
00379         //              
00380         //              - If the operator is not activable (no corresponding goal and / or preconditions are not validated), return 0
00381         //              - If fuzzy conds exist,  returns their truth value multiplied by the operator's class priority (defined in the script using the Priority keyword)
00382         //              - If no fuzzy conds, return 1 * the operator's class priority (defined in the script using the Priority keyword)
00383         void COperatorScript::calcPriority()
00384         {
00385                 int i;
00386                 double pri = 1.0;
00387                 for ( i = 0; i < (int) ( (NLAISCRIPT::COperatorClass *) _AgentClass)->getFuzzyVars().size(); i++)
00388                 {
00389                         CComponentHandle var_handle( *(const IVarName *)( ( (NLAISCRIPT::COperatorClass *) _AgentClass )->getFuzzySets() )[i],(IAgent *)getParent(), true );
00390                         CComponentHandle set_handle( *(const IVarName *)( ( (NLAISCRIPT::COperatorClass *) _AgentClass )->getFuzzyVars() )[i],(IAgent *)getParent(), true );
00391                         CComponentHandle this_var_handle( *(const IVarName *)( ( (NLAISCRIPT::COperatorClass *) _AgentClass )->getFuzzySets() )[i], this, true );
00392 
00393                         NLAIFUZZY::IFuzzySet *set = (NLAIFUZZY::IFuzzySet *) set_handle.getValue();
00394                         DigitalType *var = (DigitalType *) var_handle.getValue();
00395 
00396                         if ( var == NULL )
00397                                 var = (DigitalType *) this_var_handle.getValue();
00398 
00399                         // Min
00400                         if ( set != NULL && var != NULL )
00401                         {
00402                                 double value = var->getNumber();
00403                                 double membership = set->membership( value );
00404                                 if ( membership < pri )
00405                                         pri = membership;
00406                         }
00407                 }
00408 
00409 #ifdef NL_DEBUG
00410                 const char *dbg_class = (const char *) getType();
00411 #endif
00412 
00413 //              float class_pri = ( (NLAISCRIPT::COperatorClass *) _AgentClass)->getPriority();
00414 
00415                 if (! _IsActivable )
00416                         _Priority = 0.0;
00417                 else
00418 //                      _Priority = (float)pri * class_pri;
00419                         _Priority = (float)pri * _BasePriority;
00420         }
00421 
00422         float COperatorScript::priority() const
00423         {
00424                 return _Priority;
00425         }
00426 
00427         NLAILOGIC::CFact *COperatorScript::buildFromVars(NLAILOGIC::IBaseAssert *assert, std::vector<sint32> &pl, NLAILOGIC::CValueSet *vars)
00428         {
00429                 NLAILOGIC::CFact *result = new NLAILOGIC::CFact( assert);       // TODO:: pas besoin du nombre dans ce constructeur puisqu'on a l'assert
00430                 for (sint32 i = 0; i < (sint32) pl.size() ; i++ )
00431                 {
00432                         result->setValue( i, (*vars)[ pl[i] ] );
00433                 }
00434                 return result;
00435         }
00436 
00437         // Tries to unify a new first order logic fact with current instanciations of the operator's vars
00438         std::list<NLAILOGIC::CValueSet *> *COperatorScript::propagate(std::list<NLAILOGIC::CValueSet *> &liaisons, NLAILOGIC::CValueSet *fact, std::vector<sint32> &pos_vals) 
00439         {
00440                 std::list<NLAILOGIC::CValueSet *> *conflits = new std::list<NLAILOGIC::CValueSet *>;
00441                 std::list<NLAILOGIC::CValueSet *> buf_liaisons;
00442                 // Pour chaque liaison...
00443                 std::list< NLAILOGIC::CValueSet *>::iterator it_l = liaisons.begin();
00444                 
00445                 while ( it_l != liaisons.end() )
00446                 {
00447                         NLAILOGIC::CValueSet *l = *it_l;
00448 
00449                         NLAILOGIC::CValueSet *result = unifyLiaison( l, fact, pos_vals );
00450                         if ( result )
00451                         {
00452                                 if ( result->undefined() == 0 )
00453                                 {
00454                                         conflits->push_back( result );
00455                                 }
00456                                 else 
00457                                         buf_liaisons.push_back( result );
00458                         }
00459                         it_l++;
00460                 }
00461 
00462                 while ( buf_liaisons.size() )
00463                 {
00464                         liaisons.push_back( buf_liaisons.front() );
00465                         buf_liaisons.pop_front();
00466                 }
00467 
00468                 return conflits;
00469         }
00470 
00471 
00472         // Tries to unify a list of new first order logic facts with current instanciations of the operator's vars
00473         std::list<NLAILOGIC::CFact *> *COperatorScript::propagate(std::list<NLAILOGIC::CFact *> &facts)
00474         {
00475                 std::list<NLAILOGIC::CFact *> *conflicts = new std::list<NLAILOGIC::CFact *>;
00476                 std::list< NLAILOGIC::CValueSet *>      liaisons;
00477                 NLAILOGIC::CValueSet *empty = new NLAILOGIC::CValueSet( ( (NLAISCRIPT::COperatorClass *)_AgentClass)->getVars().size() );
00478                 liaisons.push_back( empty );
00479                 
00480                 NLAISCRIPT::COperatorClass *op_class = (NLAISCRIPT::COperatorClass *) _AgentClass;
00481 
00482                 std::list<NLAILOGIC::CFact *>::iterator it_f = facts.begin();
00483                 while ( it_f != facts.end() )
00484                 {
00485                         std::vector<sint32> pos_asserts;
00486                         op_class->getAssertPos( (*it_f)->getAssert() , op_class->getConds(), pos_asserts);
00487                         for (sint32 i = 0; i < (sint32) pos_asserts.size(); i++ )
00488                         {
00489                                 std::list<NLAILOGIC::CValueSet *> *links = propagate( liaisons, *it_f, op_class->getPosVarsConds()[ pos_asserts[i] ] );
00490                                 if ( links )
00491                                 {
00492                                         while ( links->size() )
00493                                         {
00494                                                 for (sint32 i = 0; i < (sint32) op_class->getConcs().size(); i++ )
00495                                                 {
00496                                                         NLAILOGIC::CFact *r = buildFromVars( op_class->getConcs()[i], op_class->getPosVarsConcs()[i], links->front() );
00497                                                         std::string buf;
00498                                                         r->getDebugString( buf );
00499                                                         // Tests if the fact is already in the conflicts list
00500                                                         bool found = false;
00501                                                         std::list<NLAILOGIC::CFact *>::iterator it_c = conflicts->begin();
00502                                                         while ( ! found && it_c != conflicts->end() )
00503                                                         {
00504                                                                 found = (**it_c) == *r;
00505                                                                 it_c++;
00506                                                         }
00507                                                         if ( !found )
00508                                                         {
00509                                                                 std::string buf;
00510                                                                 r->getDebugString( buf );
00511                                                                 conflicts->push_back( r );
00512                                                         }
00513                                                 }
00514                                                 links->front()->release();
00515                                                 links->pop_front();
00516                                         }
00517                                         delete links;
00518                                 }
00519                         }
00520                         it_f++;
00521                 }
00522 
00523                 while ( liaisons.size() )
00524                 {
00525                         liaisons.front()->release();
00526                         liaisons.pop_front();
00527                 }
00528                 return conflicts;
00529         }
00530 
00531 
00532         // Simple unifcation between two first order logic patterns
00533         NLAILOGIC::CValueSet *COperatorScript::unifyLiaison( const NLAILOGIC::CValueSet *fp, NLAILOGIC::CValueSet *vals, std::vector<sint32> &pos_vals)
00534         {
00535                 NLAILOGIC::CValueSet *result;
00536 
00537                 if ( (result = fp->unify( vals, pos_vals )) )
00538                         return result;
00539                 else
00540                 {
00541                         return NULL;
00542                 }
00543         }
00544 
00545         // Instanciates a goals's args as static components of the operator
00546         void COperatorScript::linkGoalArgs(NLAILOGIC::CGoal *g)
00547         {
00548                 std::vector<NLAIAGENT::IObjectIA *>::const_iterator it_arg = g->getArgs().begin();
00549                 std::vector<sint32>::iterator it_pos = ( (NLAISCRIPT::COperatorClass *) _AgentClass )->getGoalVarPos().begin();
00550                 while ( it_arg != g->getArgs().end() )
00551                 {
00552                         if(!setStaticMember( *it_pos, *it_arg ))
00553                                                                                 (*it_arg)->incRef();
00554                         it_arg++;
00555                         it_pos++;
00556                 }
00557         }
00558 
00559         // Function called when a launched actor succeded
00560         void COperatorScript::onSuccess( IObjectIA *msg)
00561         {
00562 #ifdef NL_DEBUG
00563                 const char *dbg_class = (const char *) getType();
00564 #endif
00565                 if(_CurrentGoal == NULL) 
00566                         return;
00567                 _CurrentGoal->operatorSuccess( this );
00568                 _CurrentGoal = NULL;
00569                 unActivate();
00570         }
00571         
00572         // Function called when a lauched actor failed
00573         void COperatorScript::onFailure( IObjectIA *)
00574         {
00575 
00576 #ifdef NL_DEBUG
00577                 const char *dbg_class = (const char *) getType();
00578 #endif
00579 
00580                 if(_CurrentGoal == NULL) 
00581                         return;
00582                 // Tells the goal the operator failed
00583                 _CurrentGoal->operatorFailure( this );
00584                 _CurrentGoal = NULL;
00585                 unActivate();
00586         }
00587 
00588         IObjectIA::CProcessResult COperatorScript::runMethodBase(int index,int heritance, IObjectIA *params)
00589         {               
00590                 IObjectIA::CProcessResult r;
00591 
00592                 switch ( index )
00593                 {
00594                         case fid_modeachieve:
00595                                 _Maintain = false;
00596                                 r.ResultState =  NLAIAGENT::processIdle;
00597                                 r.Result = NULL;
00598                                 return r;
00599 
00600                         case fid_modemaintain:
00601                                 _Maintain = true;
00602                                 r.ResultState =  NLAIAGENT::processIdle;
00603                                 r.Result = NULL;
00604                                 return r;
00605 
00606                         case fid_isActivable:
00607                                 r.ResultState =  NLAIAGENT::processIdle;
00608                                 r.Result = new NLAILOGIC::CBoolType( _IsActivable );
00609                                 return r;
00610 
00611                         case fid_isPaused:
00612                                 r.ResultState =  NLAIAGENT::processIdle;
00613                                 r.Result = new NLAILOGIC::CBoolType( _IsPaused );
00614                                 return r;
00615 
00616                         case fid_getPriority:
00617                                 r.ResultState =  NLAIAGENT::processIdle;
00618                                 r.Result = new NLAIAGENT::DigitalType( priority() );
00619                                 return r;
00620 
00621                         case fid_setPriority:
00622                                 {
00623                                         setPriority(((NLAIAGENT::DigitalType *)((NLAIAGENT::IBaseGroupType *) params)->get())->getValue());
00624                                         r.ResultState =  NLAIAGENT::processIdle;
00625                                         r.Result = NULL;
00626                                         return r;
00627                                 }
00628 
00629                         case fid_background:
00630                                 _Exclusive = false;
00631                                 r.ResultState =  NLAIAGENT::processIdle;
00632                                 r.Result = NULL;
00633                                 return r;
00634 
00635                         case fid_exclusive:
00636                                 _Exclusive = true;
00637                                 r.ResultState =  NLAIAGENT::processIdle;
00638                                 r.Result = NULL;
00639                                 return r;
00640 
00641                         case fid_achieve:
00642                                 r.ResultState =  NLAIAGENT::processIdle;
00643                                 r.Result = NULL;
00644                                 return r;
00645 
00646                         case fid_order:
00647                                 {
00648                                         NLAIAGENT::IBaseGroupType *receivers = (NLAIAGENT::IBaseGroupType *) ((NLAIAGENT::IBaseGroupType *)params)->getFront();
00649                                         ((NLAIAGENT::IBaseGroupType *)params)->popFront();
00650                                         NLAILOGIC::IGoal *goal = (NLAILOGIC::IGoal *) ((NLAIAGENT::IBaseGroupType *)params)->getFront();
00651                                         ((NLAIAGENT::IBaseGroupType *)params)->popFront();
00652                                         order( receivers, goal );
00653                                         return r;
00654                                 }
00655                 }
00656                 return r;
00657         }
00658 
00659         IObjectIA::CProcessResult COperatorScript::runMethodBase(int index,IObjectIA *params)
00660         {       
00661                 int i = index - CActorScript::getMethodIndexSize();
00662 
00663 
00664                 IObjectIA::CProcessResult r;
00665                 std::vector<CStringType *> handles;
00666 
00667 
00668                 switch( i )
00669                 {
00670                         case fid_modemaintain:
00671                                 _Maintain = true;
00672                                 r.ResultState =  NLAIAGENT::processIdle;
00673                                 r.Result = NULL;
00674                                 return r;
00675 
00676                         case fid_modeachieve:
00677                                 _Maintain = false;
00678                                 r.ResultState =  NLAIAGENT::processIdle;
00679                                 r.Result = NULL;
00680                                 return r;
00681 
00682                         case fid_isActivable:
00683                                 r.ResultState =  NLAIAGENT::processIdle;
00684                                 r.Result = new NLAILOGIC::CBoolType( _IsActivable );
00685                                 return r;
00686 
00687                         case fid_isPaused:
00688                                 r.ResultState =  NLAIAGENT::processIdle;
00689                                 r.Result = new NLAILOGIC::CBoolType( _IsPaused );
00690                                 return r;
00691 
00692                         case fid_getPriority:
00693                                 r.ResultState =  NLAIAGENT::processIdle;
00694                                 r.Result = new NLAIAGENT::DigitalType( priority() );
00695                                 return r;
00696 
00697                         case fid_setPriority:
00698                                 _Priority  = ((NLAIAGENT::DigitalType *)((NLAIAGENT::IBaseGroupType *) params)->get())->getValue();
00699                                 r.ResultState =  NLAIAGENT::processIdle;
00700                                 r.Result = NULL;
00701                                 return r;
00702 
00703                         case fid_background:
00704                                 _Exclusive = false;
00705                                 r.ResultState =  NLAIAGENT::processIdle;
00706                                 r.Result = NULL;
00707                                 return r;
00708 
00709                         case fid_exclusive:
00710                                 _Exclusive = true;
00711                                 r.ResultState =  NLAIAGENT::processIdle;
00712                                 r.Result = NULL;
00713                                 return r;
00714 
00715                         case fid_order:
00716                                 {
00717                                         NLAIAGENT::IBaseGroupType *receivers = (NLAIAGENT::IBaseGroupType *) ((NLAIAGENT::IBaseGroupType *)params)->getFront();
00718                                         ((NLAIAGENT::IBaseGroupType *)params)->popFront();
00719                                         NLAILOGIC::IGoal *goal = (NLAILOGIC::IGoal *) ((NLAIAGENT::IBaseGroupType *)params)->getFront();
00720                                         ((NLAIAGENT::IBaseGroupType *)params)->popFront();
00721                                         order( receivers, goal );
00722                                         return r;
00723                                 }
00724 
00725                 }
00726                 return CActorScript::runMethodBase(index, params);
00727         }
00728 
00729         int COperatorScript::getBaseMethodCount() const
00730         {
00731                 return CActorScript::getBaseMethodCount() + fid_last;
00732         }
00733 
00734         tQueue COperatorScript::getPrivateMember(const IVarName *className,const IVarName *name,const IObjectIA &param) const
00735         {               
00736 
00737 #ifdef NL_DEBUG
00738                 const char *dbg_func_name = name->getString();          
00739 #endif
00740 
00741                 tQueue result; 
00742 
00743                 static NLAIAGENT::CStringVarName modeachieve_name("SetModeAchieve");
00744                 static NLAIAGENT::CStringVarName modemaintain_name("SetModeMaintain");
00745                 static NLAIAGENT::CStringVarName ispaused_name("IsPaused");
00746                 static NLAIAGENT::CStringVarName isactivable_name("IsActivable");
00747                 static NLAIAGENT::CStringVarName priority_name("GetPriority");
00748                 static NLAIAGENT::CStringVarName set_priority_name("SetPriority");
00749                 static NLAIAGENT::CStringVarName exclusive_name("SetExclusive");
00750                 static NLAIAGENT::CStringVarName background_name("SetBackground");
00751                 static NLAIAGENT::CStringVarName order_name("Order");
00752 
00753 
00754                 if ( *name == modeachieve_name )
00755                 {
00756                         NLAIAGENT::CObjectType *r_type = new NLAIAGENT::CObjectType( new NLAIC::CIdentType( NLAIC::CIdentType::VoidType ) );
00757                         result.push( NLAIAGENT::CIdMethod(  CActorScript::getMethodIndexSize() + fid_modeachieve, 0.0,NULL, r_type ) );
00758                 }
00759 
00760                 if ( *name == modemaintain_name )
00761                 {
00762                         NLAIAGENT::CObjectType *r_type = new NLAIAGENT::CObjectType( new NLAIC::CIdentType( NLAIC::CIdentType::VoidType ) );
00763                         result.push( NLAIAGENT::CIdMethod( CActorScript::getMethodIndexSize() + fid_modemaintain , 0.0,NULL, r_type ) );
00764                 }
00765 
00766                 if ( *name == ispaused_name )
00767                 {
00768                         NLAIAGENT::CObjectType *r_type = new NLAIAGENT::CObjectType( new NLAIC::CIdentType( NLAIC::CIdentType::VoidType ) );
00769                         result.push( NLAIAGENT::CIdMethod( CActorScript::getMethodIndexSize() + fid_isPaused , 0.0,NULL, r_type ) );
00770                 }
00771 
00772 
00773                 if ( *name == isactivable_name )
00774                 {
00775                         NLAIAGENT::CObjectType *r_type = new NLAIAGENT::CObjectType( new NLAIC::CIdentType( NLAIC::CIdentType::VoidType ) );
00776                         result.push( NLAIAGENT::CIdMethod( CActorScript::getMethodIndexSize() + fid_isActivable , 0.0,NULL, r_type ) );
00777                 }
00778 
00779                 if ( *name == priority_name )
00780                 {
00781                         NLAIAGENT::CObjectType *r_type = new NLAIAGENT::CObjectType( new NLAIC::CIdentType( NLAIC::CIdentType::VoidType ) );
00782                         result.push( NLAIAGENT::CIdMethod( CActorScript::getMethodIndexSize() + fid_getPriority , 0.0,NULL, r_type ) );
00783                 }
00784 
00785                 if ( *name == set_priority_name )
00786                 {
00787                         NLAIAGENT::CObjectType *r_type = new NLAIAGENT::CObjectType( new NLAIC::CIdentType( NLAIAGENT::DigitalType::IdDigitalType ) );
00788                         result.push( NLAIAGENT::CIdMethod( CActorScript::getMethodIndexSize() + fid_setPriority , 0.0,NULL, r_type ) );
00789                 }
00790 
00791                 if ( *name == exclusive_name )
00792                 {
00793                         NLAIAGENT::CObjectType *r_type = new NLAIAGENT::CObjectType( new NLAIC::CIdentType( NLAIC::CIdentType::VoidType ) );
00794                         result.push( NLAIAGENT::CIdMethod( CActorScript::getMethodIndexSize() + fid_exclusive , 0.0,NULL, r_type ) );
00795                 }
00796 
00797                 if ( *name == background_name )
00798                 {
00799                         NLAIAGENT::CObjectType *r_type = new NLAIAGENT::CObjectType( new NLAIC::CIdentType( NLAIC::CIdentType::VoidType ) );
00800                         result.push( NLAIAGENT::CIdMethod( CActorScript::getMethodIndexSize() + fid_background , 0.0,NULL, r_type ) );
00801                 }
00802 
00803                 if ( *name == order_name )
00804                 {
00805                         NLAIAGENT::CObjectType *r_type = new NLAIAGENT::CObjectType( new NLAIC::CIdentType( NLAIC::CIdentType::VoidType ) );
00806                         result.push( NLAIAGENT::CIdMethod( CActorScript::getMethodIndexSize() + fid_order , 0.0,NULL, r_type ) );
00807                 }
00808 
00809                 if ( result.empty() )
00810                         return CActorScript::getPrivateMember(className, name, param);
00811                 else
00812                         return result;
00813         }
00814 
00815         sint32 COperatorScript::getMethodIndexSize() const
00816         {
00817                 return CActorScript::getMethodIndexSize() + fid_last;
00818         }
00819 
00820         bool COperatorScript::isExclusive()
00821         {
00822 #ifdef NL_DEBUG
00823                 const char *dbg_exclusive = (const char *) getType();
00824 #endif
00825                 return _Exclusive;
00826         }
00827 
00828         bool COperatorScript::checkTrigMsg()
00829         {
00830                 IBasicAgent *father = (IBasicAgent *) getParent();
00831                 if ( father != NULL )
00832                 {
00833                         IMailBox *mailbox = father->getMail();
00834                         if ( mailbox != NULL )
00835                         {
00836                                 std::list<const IMessageBase *>::const_iterator it_msg;
00837                                 const std::list<const IMessageBase *> &msg_list = mailbox->getMesseageListe();
00838 
00839                                 it_msg = msg_list.begin();
00840                                 while ( it_msg != msg_list.end() )
00841                                 {
00842                                         IMessageBase *msg = (NLAIAGENT::IMessageBase *)*it_msg;
00843 #ifdef NL_DEBUG
00844                                         const char *id = (const char *) msg->getType();                                 
00845 #endif
00846 
00847                                         sint32 msg_comp_pos = ( (NLAISCRIPT::COperatorClass *) _AgentClass )->checkTriggerMsg( msg );
00848                                         if ( msg_comp_pos == -1)
00849                                                 return false;
00850                                         else
00851                                         {
00852                                                 if(!setStaticMember( msg_comp_pos, (NLAIAGENT::IObjectIA *) msg ))
00853                                                         msg->incRef();          
00854                                                 return true;
00855                                         }
00856                                         it_msg++;
00857                                 }       
00858                         }
00859                 }
00860                 return false;
00861         }
00862 
00863         void COperatorScript::order( NLAIAGENT::IBaseGroupType *receivers, NLAILOGIC::IGoal *order)
00864         {
00865                 _NbAnswers = receivers->size();
00866                 while ( receivers->size() )
00867                 {
00868                         NLAIAGENT::CGoalMsg *msg = new NLAIAGENT::CGoalMsg();
00869                         NLAILOGIC::IGoal *goal = (NLAILOGIC::IGoal *) order->clone();
00870                         msg->set( 0, (NLAILOGIC::IGoal *) goal );
00871                         goal->setSender( this );
00872                         msg->setSender( this );
00873                         msg->setPerformatif( NLAIAGENT::IMessageBase::PAchieve );
00874                         NLAIAGENT::CProxyAgentMail *member = (NLAIAGENT::CProxyAgentMail *) receivers->getFront()->clone();
00875                         member->sendMessage( (NLAIAGENT::IObjectIA *) msg );
00876                         receivers->popFront();
00877                 }
00878         }
00879 
00880         void COperatorScript::processMessages(NLAIAGENT::IMessageBase *msg,NLAIAGENT::IObjectIA *o)
00881         {
00882 #ifdef NL_DEBUG
00883         const char *txt = (const char *)msg->getType();
00884 #endif
00885                 CAgentScript::processMessages(msg,o);
00886         }
00887 
00888         void COperatorScript::setPriority(float prio)
00889         {
00890                 _BasePriority = prio;
00891         }
00892 }