00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "nel/ai/script/compilateur.h"
00025 #include "nel/ai/script/constraint.h"
00026 #include "nel/ai/script/type_def.h"
00027
00028 namespace NLAISCRIPT
00029 {
00030 IOpType::~IOpType()
00031 {
00032 }
00033
00034 double IOpType::evalParam(IOpType *e)
00035 {
00036 double d;
00037 if(e->getConstraintTypeOf() != NULL)
00038 {
00039 const NLAIC::CIdentType &idG = *getConstraintTypeOf();
00040 const NLAIC::CIdentType &idD = *e->getConstraintTypeOf();
00041 if(!(idG == idD))
00042 {
00043 if(((const NLAIC::CTypeOfObject &)idD) & NLAIC::CTypeOfObject::tInterpret )
00044 {
00045 IClassInterpret *o = (IClassInterpret *)((CClassInterpretFactory *)idD.getFactory())->getClass();
00046 bool type = false;
00047 d = 0.0;
00048 while(o != NULL)
00049 {
00050 if( o->getType() == idG)
00051 {
00052 d += 1.0;
00053 type = true;
00054 break;
00055 }
00056 o = (IClassInterpret *)o->getComputeBaseClass();
00057 }
00058 if(!type) return -1.0;
00059 else return d;
00060 }
00061 else
00062 {
00063
00064 if(((const NLAIC::CTypeOfObject &)idD) & ((const NLAIC::CTypeOfObject &)idG))
00065 {
00066 return 0.0;
00067 }
00068 else return -1.0;
00069 }
00070 }
00071 else return 0.0;
00072 }
00073 else return -1.0;
00074 }
00075
00076 double IOpType::eval(IOpType *e)
00077 {
00078 if(getConstraintTypeOf() != NULL && e->getConstraintTypeOf() != NULL)
00079 {
00080 if(e->getTypeOfClass() == operandSimpleListOr)
00081 {
00082 COperandSimpleListOr *l = (COperandSimpleListOr *)e;
00083 std::list<NLAIC::CIdentType *>::const_iterator i = l->getList().begin();
00084 while(i != l->getList().end() )
00085 {
00086 COperandSimple *x =new COperandSimple (new NLAIC::CIdentType(*(*i++)));
00087 double d = evalParam(x);
00088 delete x;
00089 if(d >= 0.0) return d;
00090 }
00091
00092 }
00093 else return evalParam(e);
00094 }
00095 return -1.0;
00096 }
00097
00098 bool COperationTypeGD::satisfied()
00099 {
00100 if(_OpG->satisfied() && _OpD->satisfied())
00101 {
00102 if(_Op == NLAIC::CTypeOfOperator::opAff)
00103 {
00104 if(*_OpG->getConstraintTypeOf() == *_OpD->getConstraintTypeOf()) return true;
00105 else
00106 {
00107 if(((const NLAIC::CTypeOfObject &)*_OpD->getConstraintTypeOf()) & NLAIC::CTypeOfObject::tInterpret)
00108 {
00109 const IClassInterpret *o = (const IClassInterpret *)((CClassInterpretFactory *)_OpD->getConstraintTypeOf()->getFactory())->getClass();
00110 for(sint32 i = o->sizeVTable() - 1; i >= 1; i--)
00111 {
00112 if( o->getInheritance(i)->getType() == *(_OpG->getConstraintTypeOf())) return true;
00113 }
00114 }
00115 else return false;
00116 }
00117 }
00118 else
00119 {
00120 const NLAIC::CIdentType *id = _OpG->getConstraintTypeOf();
00121 if( (( uint32)(((const NLAIC::CTypeOfOperator &)*id) & _Op)) != (uint32)_Op) return false;
00122 id = _OpD->getConstraintTypeOf();
00123 if( ((uint32)(((const NLAIC::CTypeOfOperator &)*id) & _Op)) != (uint32)_Op) return false;
00124 }
00125 return true;
00126 }
00127 return false;
00128 }
00129
00130
00131 COperandSimpleListOr::COperandSimpleListOr(int count, ...)
00132 {
00133 va_list marker;
00134
00135 va_start( marker, count );
00136 while(count --)
00137 {
00138 NLAIC::CIdentType *o = va_arg( marker, NLAIC::CIdentType *);
00139 _TypeListe.push_back(o);
00140 }
00141 std::string text;
00142 text = NLAIC::stringGetBuild("constraint<COperandSimpleListOr> for ...");
00143 _TxtInfo = new char [strlen(text.c_str()) + 1];
00144 strcpy(_TxtInfo,text.c_str());
00145 }
00146
00147 double COperandSimpleListOr::eval (IOpType *e)
00148 {
00149 std::list<NLAIC::CIdentType *>::const_iterator i = getList().begin();
00150 while(i != getList().end() )
00151 {
00152
00153 COperandSimple x(*i);
00154 (*i)->incRef();
00155 double d = x.eval(e);
00156 i ++;
00157 if(d >= 0.0) return d;
00158 }
00159 return -1.0;
00160 }
00161 }