00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <time.h>
00025 #include "nel/ai/script/compilateur.h"
00026 #include "nel/ai/script/interpret_object_message.h"
00027 #include "nel/ai/script/interpret_object_manager.h"
00028 #include "nel/ai/script/interpret_actor.h"
00029 #include "nel/ai/script/test_method.h"
00030 #include "nel/ai/script/type_def.h"
00031 #include "nel/ai/script/object_unknown.h"
00032 #include "nel/ai/agent/agent_digital.h"
00033
00034
00035 namespace NLAISCRIPT
00036 {
00037 CLibTest test;
00038 const NLAIC::CIdentType CLibTest::IdLibTest = NLAIC::CIdentType("External",
00039 NLAIC::CSelfClassFactory(test),
00040 NLAIC::CTypeOfObject(NLAIC::CTypeOfObject::tObject),NLAIC::CTypeOfOperator(0));
00041
00042
00043 CLibTest::CMethodCall **CLibTest::StaticMethod = NULL;
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 void CLibTest::initClass()
00081 {
00082 CLibTest::StaticMethod = new CLibTest::CMethodCall *[CLibTest::TLastM];
00083
00084 CLibTest::StaticMethod[CLibTest::TConst] = new CLibTest::CMethodCall( _CONSTRUCTOR_,
00085 CLibTest::TConst, NULL,
00086 CLibTest::CheckCount,
00087 0,
00088 new CObjectUnknown(new NLAISCRIPT::COperandVoid));
00089
00090 CLibTest::StaticMethod[CLibTest::TIsNULL] = new CLibTest::CMethodCall(
00091 "IsNotNull",
00092 CLibTest::TIsNULL, NULL,
00093 CLibTest::CheckCount,
00094 1,
00095 new CObjectUnknown(new COperandSimple(new NLAIC::CIdentType(NLAIAGENT::DigitalType::IdDigitalType))));
00096
00097 CLibTest::StaticMethod[CLibTest::TRand1] = new CLibTest::CMethodCall(
00098 "Rand",
00099 CLibTest::TRand1,
00100 new NLAISCRIPT::CParam(1,new NLAISCRIPT::COperandSimpleListOr(2,
00101 new NLAIC::CIdentType(NLAIAGENT::DDigitalType::IdDDigitalType),
00102 new NLAIC::CIdentType(NLAIAGENT::DigitalType::IdDigitalType))),
00103 CLibTest::CheckAll,
00104 1,
00105 new CObjectUnknown(new COperandSimple(new NLAIC::CIdentType(NLAIAGENT::DDigitalType::IdDDigitalType))));
00106
00107 CLibTest::StaticMethod[CLibTest::TRand2] = new CLibTest::CMethodCall(
00108 "Rand",
00109 CLibTest::TRand2,
00110 new NLAISCRIPT::CParam(2,new NLAISCRIPT::COperandSimpleListOr(2,
00111 new NLAIC::CIdentType(NLAIAGENT::DDigitalType::IdDDigitalType),
00112 new NLAIC::CIdentType(NLAIAGENT::DigitalType::IdDigitalType)),
00113 new NLAISCRIPT::COperandSimpleListOr(2,
00114 new NLAIC::CIdentType(NLAIAGENT::DDigitalType::IdDDigitalType),
00115 new NLAIC::CIdentType(NLAIAGENT::DigitalType::IdDigitalType))),
00116 CLibTest::CheckAll,
00117 2,
00118 new CObjectUnknown(new COperandSimple(new NLAIC::CIdentType(NLAIAGENT::DDigitalType::IdDDigitalType))));
00119
00120 CLibTest::StaticMethod[CLibTest::TDiscretRand] = new CLibTest::CMethodCall(
00121 "DRand",
00122 CLibTest::TDiscretRand,
00123 new NLAISCRIPT::CParam(2,new NLAISCRIPT::COperandSimpleListOr(2,
00124 new NLAIC::CIdentType(NLAIAGENT::DDigitalType::IdDDigitalType),
00125 new NLAIC::CIdentType(NLAIAGENT::DigitalType::IdDigitalType)),
00126 new NLAISCRIPT::COperandSimpleListOr(2,
00127 new NLAIC::CIdentType(NLAIAGENT::DDigitalType::IdDDigitalType),
00128 new NLAIC::CIdentType(NLAIAGENT::DigitalType::IdDigitalType))),
00129 CLibTest::CheckAll,
00130 2,
00131 new CObjectUnknown(new COperandSimple(new NLAIC::CIdentType(NLAIAGENT::DDigitalType::IdDDigitalType))));
00132
00133 }
00134
00135 void CLibTest::releaseClass()
00136 {
00137 int i;
00138 for(i = 0; i < CLibTest::TLastM; i++)
00139 {
00140 delete CLibTest::StaticMethod[i];
00141 }
00142 delete CLibTest::StaticMethod;
00143 }
00144
00145
00146 CLibTest::CLibTest()
00147 {
00148
00149
00150
00151 }
00152 sint32 CLibTest::isClassInheritedFrom(const NLAIAGENT::IVarName &className) const
00153 {
00154 NLAIAGENT::CStringVarName check((const char *)IdLibTest);
00155
00156 if(className == check)
00157 {
00158 return 0;
00159 }
00160 else return -1;
00161 }
00162
00163 NLAIAGENT::tQueue CLibTest::isMember(const NLAIAGENT::IVarName *className,const NLAIAGENT::IVarName *methodName,const NLAIAGENT::IObjectIA ¶m) const
00164 {
00165 NLAIAGENT::tQueue r;
00166 NLAIAGENT::CStringVarName check((const char *)IdLibTest);
00167
00168 if(className == NULL || *className == check)
00169 {
00170 sint i;
00171 CLibTest::TMethodNumDef index;
00172 for(i = 0; i < CLibTest::TLastM; i ++)
00173 {
00174 if(CLibTest::StaticMethod[i]->MethodName == *methodName)
00175 {
00176 index = (CLibTest::TMethodNumDef)CLibTest::StaticMethod[i]->Index;
00177 switch(CLibTest::StaticMethod[i]->CheckArgType)
00178 {
00179 case CLibTest::CheckAll:
00180 {
00181 double d = ((NLAISCRIPT::CParam &)*CLibTest::StaticMethod[i]->ArgType).eval((NLAISCRIPT::CParam &)param);
00182 if(d >= 0.0)
00183 {
00184 CLibTest::StaticMethod[i]->ReturnValue->incRef();
00185 r.push(NLAIAGENT::CIdMethod((CLibTest::getMethodIndexSize() + CLibTest::StaticMethod[i]->Index),
00186 0.0,
00187 NULL,
00188 CLibTest::StaticMethod[i]->ReturnValue));
00189 return r;
00190 }
00191 }
00192 break;
00193 case CLibTest::CheckCount:
00194 {
00195 if(((NLAISCRIPT::CParam &)param).size() == CLibTest::StaticMethod[i]->ArgCount)
00196 {
00197 CLibTest::StaticMethod[i]->ReturnValue->incRef();
00198 r.push(NLAIAGENT::CIdMethod((CLibTest::getMethodIndexSize() + CLibTest::StaticMethod[i]->Index),
00199 0.0,
00200 NULL,
00201 CLibTest::StaticMethod[i]->ReturnValue ));
00202 return r;
00203 }
00204 }
00205 break;
00206
00207 case CLibTest::DoNotCheck:
00208 {
00209 CLibTest::StaticMethod[i]->ReturnValue->incRef();
00210 r.push(NLAIAGENT::CIdMethod((CLibTest::getMethodIndexSize() + CLibTest::StaticMethod[i]->Index),
00211 0.0,
00212 NULL,
00213 CLibTest::StaticMethod[i]->ReturnValue));
00214 return r;
00215 }
00216 break;
00217 }
00218 }
00219
00220 }
00221 }
00222 return r;
00223 }
00224
00225 NLAIAGENT::IObjectIA::CProcessResult CLibTest::runMethodeMember(sint32 heritance, sint32 index, NLAIAGENT::IObjectIA *)
00226 {
00227 return NLAIAGENT::IObjectIA::ProcessRun;
00228 }
00229
00230 NLAIAGENT::IObjectIA::CProcessResult CLibTest::runMethodeMember(sint32 index,NLAIAGENT::IObjectIA *p)
00231 {
00232 NLAIAGENT::IObjectIA::CProcessResult r;
00233
00234 switch(index)
00235 {
00236 case CLibTest::TIsNULL:
00237 {
00238 NLAIAGENT::IObjectIA *param = (NLAIAGENT::IObjectIA *)((NLAIAGENT::IBaseGroupType *)p)->get();
00239 if( ((const NLAIC::CTypeOfObject &)param->getType()) & NLAIC::CTypeOfObject::tNombre)
00240 {
00241 param->incRef();
00242 r.Result = param;
00243 return r;
00244 }
00245 else
00246 {
00247 r.Result = new NLAIAGENT::DigitalType(1.0);
00248 return r;
00249 }
00250 }
00251 break;
00252 case CLibTest::TRand1:
00253 {
00254 NLAIAGENT::DDigitalType *param = (NLAIAGENT::DDigitalType *)((NLAIAGENT::IBaseGroupType *)p)->get();
00255 r.Result = new NLAIAGENT::DDigitalType(rand(0.0,param->getNumber()));
00256 return r;
00257 }
00258
00259 case CLibTest::TRand2:
00260 {
00261 NLAIAGENT::CIteratorContener iter = ((NLAIAGENT::IBaseGroupType *)p)->getIterator();
00262 NLAIAGENT::DDigitalType *p1 = (NLAIAGENT::DDigitalType *)(iter ++);
00263 NLAIAGENT::DDigitalType *p2 = (NLAIAGENT::DDigitalType *)(iter ++);
00264 r.Result = new NLAIAGENT::DDigitalType(rand(p1->getNumber(),p2->getNumber()));
00265 return r;
00266 }
00267
00268 case CLibTest::TDiscretRand:
00269 {
00270 NLAIAGENT::CIteratorContener iter = ((NLAIAGENT::IBaseGroupType *)p)->getIterator();
00271 NLAIAGENT::DDigitalType *p1 = (NLAIAGENT::DDigitalType *)(iter ++);
00272 NLAIAGENT::DDigitalType *p2 = (NLAIAGENT::DDigitalType *)(iter ++);
00273 r.Result = new NLAIAGENT::DDigitalType((double)dRand((sint)p1->getNumber(), (sint)p2->getNumber()));
00274 return r;
00275 }
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 }
00320 return r;
00321 }
00322
00323 double CLibTest::rand(double d1, double d2) const
00324 {
00325 double r = ((double)::rand() - (((double)RAND_MAX)/2));
00326
00327 r /= ((double)RAND_MAX);
00328
00329 return d1 + r*(d2 - d1);
00330
00331 }
00332
00333 sint CLibTest::dRand(sint d1, sint d2) const
00334 {
00335
00336 sint ra = ::rand();
00337 sint d = (d2 - d1);
00338 if(d < 0) d = -d;
00339 if(!d) d = 1;
00340 sint r = d1 + (ra%d);
00341
00342 return r;
00343
00344 }
00345
00346 }
00347