00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef NL_IDENTTYPE_H
00028 #define NL_IDENTTYPE_H
00029 #include <stdlib.h>
00030 #include "nel/misc/file.h"
00031 #include "nel/misc/entity_id.h"
00032 #include "nel/ai/e/ai_exception.h"
00033 #include "nel/ai/agent/agent_string.h"
00034
00035 namespace NLAIAGENT
00036 {
00037 #ifndef _MAX__INDEX_DEFINED
00038 const sint32 maxIndex = 2;
00039 #define _MAX__INDEX_DEFINED
00040
00041 const uint64 maxResolutionNumer = ((uint64)2 << 48) - (uint64)1;
00042 #else
00043 extern const sint32 maxIndex;
00044 extern const uint64 maxResolutionNumer;
00045 #endif
00046
00047 struct CAgentNumber: public NLMISC::CEntityId
00048 {
00051 static const uint8 AgentTypeBit;
00052
00053 CAgentNumber()
00054 {
00055 setType( CAgentNumber::AgentTypeBit );
00056 }
00057 CAgentNumber(uint64 id,uint8 creator,uint8 dyn):NLMISC::CEntityId(AgentTypeBit,id,creator,dyn)
00058 {
00059 }
00060
00061 CAgentNumber(uint64 id, uint8 t,uint8 creator,uint8 dyn):NLMISC::CEntityId(t,id,creator,dyn)
00062 {
00063 }
00064
00065 CAgentNumber(uint64 p):NLMISC::CEntityId(p)
00066 {
00067 }
00068
00069 CAgentNumber(const CAgentNumber &a):NLMISC::CEntityId(a)
00070 {
00071 }
00072
00073 CAgentNumber(NLMISC::IStream &is):NLMISC::CEntityId(is)
00074 {
00075 }
00076
00077 CAgentNumber(const char *id):NLMISC::CEntityId(id)
00078 {
00079 }
00080
00081 bool isAgentId() const
00082 {
00083 return (getType() & AgentTypeBit) != 0;
00084 }
00085
00086 virtual bool operator < (const NLMISC::CEntityId &a) const
00087 {
00088
00089 if(isAgentId())
00090 {
00091 if (getShortId() < a.getShortId())
00092 {
00093 return true;
00094 }
00095 else
00096 if (getShortId() == a.getShortId())
00097 {
00098 if(getCreatorId() < a.getCreatorId())
00099 {
00100 return true;
00101 }
00102 else
00103 if(getCreatorId() == a.getCreatorId())
00104 {
00105 return getDynamicId() < a.getDynamicId();
00106 }
00107 }
00108 return false;
00109 }
00110 else
00111 {
00112 return CEntityId::operator < (a);
00113 }
00114 }
00115
00117 void setTypeAt(uint64 t)
00118 {
00119 uint8 type = getType();
00120 type |= (t & 0x7f);
00121 setType( type );
00122 }
00123
00124 };
00125
00126
00127
00128
00129
00131
00133
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00278
00279
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00300
00301
00302
00308 struct CIdent: public CAgentNumber
00309 {
00310 std::string TypeName;
00311 CIdent()
00312 {
00313 }
00314
00315 CIdent(const std::string &typeName,uint64 id,uint8 creator = ServerId,uint8 dyn = ServerId):CAgentNumber(id,creator,dyn),TypeName(typeName)
00316 {
00317 }
00318
00319 CIdent(const std::string &typeName,const CAgentNumber &a):CAgentNumber(a),TypeName(typeName)
00320 {
00321 }
00322
00323 CIdent(const CIdent &a):CAgentNumber(a),TypeName(a.TypeName)
00324 {
00325 }
00326
00328 CIdent(NLMISC::IStream &is):CAgentNumber(is)
00329 {
00330 std::string s;
00331 is.serial(s);
00332 TypeName = s;
00333 }
00334
00335 virtual ~CIdent() {}
00336
00337 bool operator == (const CIdent &a) const
00338 {
00339 if(TypeName == a.TypeName)
00340 {
00341 return CAgentNumber::operator == (a);
00342 }
00343 return false;
00344 }
00345
00346 bool operator < (const CIdent &a) const
00347 {
00348 return TypeName < a.TypeName;
00349 }
00350
00351 bool operator > (const CIdent &a) const
00352 {
00353 return !(TypeName < a.TypeName);
00354 }
00355
00356
00357 const CIdent &operator = (const CIdent &a)
00358 {
00359 CAgentNumber::operator = (a);
00360 TypeName = a.TypeName;
00361 return *this;
00362 }
00363
00365 virtual void save(NLMISC::IStream &os)
00366 {
00367 CAgentNumber::save(os);
00368 os.serial(TypeName);
00369 }
00370
00372 virtual void load(NLMISC::IStream &is)
00373 {
00374 CAgentNumber::load(is);
00375 std::string s;
00376 is.serial(s);
00377 TypeName = s;
00378 }
00379
00380
00381
00383 virtual void getDebugString(std::string &str) const
00384 {
00385 CAgentNumber::getDebugString(str);
00386 str += NLAIC::stringGetBuild(" '%s'",TypeName.data());
00387 }
00388
00389 const std::string &getTypeName() const
00390 {
00391 return TypeName;
00392 }
00393 };
00394 }
00395 #endif