00001 #include "nel/ai/logic/fsm_script.h"
00002 #include "nel/ai/agent/msg_action.h"
00003 #include "nel/ai/agent/agent.h"
00004 #include "nel/ai/agent/agent_script.h"
00005 #include "nel/ai/agent/object_type.h"
00006 #include "nel/ai/script/codage.h"
00007
00008 #include "nel/ai/script/interpret_message_action.h"
00009
00010 namespace NLAIAGENT
00011 {
00012 static CGroupType listBidon;
00013
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00041
00042
00043 CFsmScript::CFsmScript(const CFsmScript &a) : CActorScript(a)
00044 {
00045
00046
00047
00048
00049
00050
00051
00052 }
00053
00054 CFsmScript::CFsmScript(IAgentManager *manager,
00055 IBasicAgent *father,
00056 std::list<IObjectIA *> &components,
00057 NLAISCRIPT::CFsmClass *actor_class )
00058 : CActorScript(manager, father, components, actor_class )
00059 {
00060 }
00061
00062 CFsmScript::CFsmScript(IAgentManager *manager, bool stay_alive) : CActorScript( manager, stay_alive )
00063 {
00064 }
00065
00066 CFsmScript::~CFsmScript()
00067 {
00068
00069
00070
00071
00072
00073 }
00074
00075 const NLAIC::IBasicType *CFsmScript::clone() const
00076 {
00077 CFsmScript *m = new CFsmScript(*this);
00078 return m;
00079 }
00080
00081 const NLAIC::IBasicType *CFsmScript::newInstance() const
00082 {
00083 CFsmScript *instance;
00084 if ( _AgentClass )
00085 {
00086 instance = (CFsmScript *) _AgentClass->buildNewInstance();
00087 }
00088 else
00089 {
00090 instance = new CFsmScript(NULL);
00091 }
00092 return instance;
00093 }
00094
00095 void CFsmScript::getDebugString(std::string &t) const
00096 {
00097 if ( _AgentClass )
00098 {
00099 std::string buf;
00100 _AgentClass->getDebugString(buf);
00101 t += buf;
00102 }
00103 else
00104 t += "<CFsmScript>";
00105 }
00106
00107 bool CFsmScript::isEqual(const IBasicObjectIA &a) const
00108 {
00109 return true;
00110 }
00111
00112 const NLAIC::CIdentType &CFsmScript::getType() const
00113 {
00114 return IdFsmScript;
00115 }
00116
00117 void CFsmScript::save(NLMISC::IStream &os)
00118 {
00119 CAgentScript::save(os);
00120
00121 }
00122
00123 void CFsmScript::load(NLMISC::IStream &is)
00124 {
00125 CAgentScript::load(is);
00126
00127 }
00128
00129 sint32 CFsmScript::getMethodIndexSize() const
00130 {
00131 return CAgentScript::getBaseMethodCount();
00132 }
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 IObjectIA::CProcessResult CFsmScript::runMethodBase(int index,IObjectIA *params)
00152 {
00153
00154
00155 int i = index - IAgent::getMethodIndexSize();
00156
00157 if ( i < getBaseMethodCount() )
00158 return CAgentScript::runMethodBase(index, params);
00159
00160 switch ( i )
00161 {
00162 case 1:
00163 onSuccess(params);
00164 break;
00165 case 2:
00166 onFailure(params);
00167 break;
00168 }
00169
00170 IObjectIA::CProcessResult r;
00171
00172 #ifdef NL_DEBUG
00173 std::string buf;
00174 getDebugString(buf);
00175 #endif
00176
00177 return r;
00178 }
00179
00180 int CFsmScript::getBaseMethodCount() const
00181 {
00182 return CAgentScript::getBaseMethodCount();
00183 }
00184
00185
00186 tQueue CFsmScript::isMember(const IVarName *className,const IVarName *name,const IObjectIA ¶m) const
00187 {
00188 #ifdef NL_DEBUG
00189 const char *dbg_func_name = name->getString();
00190 #endif
00191
00192 tQueue result = CAgentScript::isMember( className, name, param);
00193
00194 static NLAIAGENT::CStringVarName run_tell("RunTell");
00195 static NLAIAGENT::CStringVarName get_active("getActive");
00196
00197 if ( result.size() )
00198 return result;
00199
00200
00201 if ( *name == run_tell)
00202 {
00203 double d;
00204 d = ((NLAISCRIPT::CParam &)*ParamSuccessMsg).eval((NLAISCRIPT::CParam &)param);
00205 if ( d >= 0.0 )
00206 {
00207 NLAIAGENT::CObjectType *r_type = new NLAIAGENT::CObjectType( new NLAIC::CIdentType( NLAIC::CIdentType::VoidType ) );
00208 result.push( NLAIAGENT::CIdMethod( IAgent::getMethodIndexSize() + 1, 0.0,NULL, r_type ) );
00209 }
00210
00211 d = ((NLAISCRIPT::CParam &)*ParamFailureMsg).eval((NLAISCRIPT::CParam &)param);
00212 if ( d >= 0.0 )
00213 {
00214 NLAIAGENT::CObjectType *r_type = new NLAIAGENT::CObjectType( new NLAIC::CIdentType( NLAIC::CIdentType::VoidType ) );
00215 result.push( NLAIAGENT::CIdMethod( IAgent::getMethodIndexSize() + 2, 0.0,NULL, r_type ) );
00216 }
00217 }
00218
00219
00220 if ( *name == get_active )
00221 {
00222
00223 }
00224
00225 return result;
00226 }
00227
00228 const IObjectIA::CProcessResult &CFsmScript::run()
00229 {
00230 return CAgentScript::run();
00231 }
00232
00233 void CFsmScript::activate(IBasicAgent *child)
00234 {
00235
00236 }
00237
00238 void CFsmScript::unactivate(IBasicAgent *child)
00239 {
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 }
00252
00253 void CFsmScript::runChildren()
00254 {
00255 #ifdef NL_DEBUG
00256 const char *classBase = (const char *)getType();
00257 #endif
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 CAgentScript::runChildren();
00269 }
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 void CFsmScript::setTopLevel(NLAIAGENT::CAgentScript *tl)
00284 {
00285 _TopLevel = tl;
00286
00287 for (int i = 0; i < _NbComponents; i++ )
00288 {
00289 if ( _Components[i]->isClassInheritedFrom( NLAIAGENT::CStringVarName("Actor") ) != -1 )
00290 {
00291 if ( _TopLevel )
00292 ( (CActorScript *)_Components[i] )->setTopLevel( _TopLevel );
00293 else
00294 ( (CActorScript *)_Components[i] )->setTopLevel( this );
00295 }
00296 }
00297 }
00298 }