1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //--------------------------------------------------------------------------
24 // CAIEntityId creation from string methods
25 //--------------------------------------------------------------------------
27 CAIEntityId CAIEntityId::entityId(const std::string &name)
31 eid = CAIEntityId::mgrId(name);
35 eid = CAIEntityId::grpId(name);
39 eid = CAIEntityId::botId(name);
46 CAIEntityId CAIEntityId::botId(const std::string &name)
50 // see if we have a CAIEntityId.toString()
52 if (id.isBot() && id.exists())
55 // see if we have a NLMISC::CEntityId.toStirng()
58 id=CAIEntityId(NLMISC::CEntityId(name.c_str()));
59 if (id.isBot() && id.exists())
63 // see if we have a bot number, group number and manager number
64 uint mgridx, grpidx, botidx;
67 sscanf(name.c_str(),"%i:%i:%i",&mgridx,&grpidx,&botidx);
68 sprintf(s,"%i:%i:%i",mgridx,grpidx,botidx);
69 if (name==std::string(s))
70 return CAIEntityId::botId(mgridx,grpidx,botidx);
72 sscanf(name.c_str(),"%i,%i,%i",&mgridx,&grpidx,&botidx);
73 sprintf(s,"%i,%i,%i",mgridx,grpidx,botidx);
74 if (name==std::string(s))
75 return CAIEntityId::botId(mgridx,grpidx,botidx);
77 sscanf(name.c_str(),"%i.%i.%i",&mgridx,&grpidx,&botidx);
78 sprintf(s,"%i.%i.%i",mgridx,grpidx,botidx);
79 if (name==std::string(s))
80 return CAIEntityId::botId(mgridx,grpidx,botidx);
82 // we're out of options so give up
88 CAIEntityId CAIEntityId::grpId(const std::string &name)
92 // see if we have a CAIEntityId.toStirng()
94 if (id.isGrp() && id.exists())
97 // see if we have a NLMISC::CEntityId.toStirng()
100 id=CAIEntityId(NLMISC::CEntityId(name.c_str()));
101 if (id.isGrp() && id.exists())
105 // see if name corresponds to the name of one of the groups
106 for (id=CAIEntityId::firstMgr().firstGrp();!id.isInvalid();id=id.nextGrp())
108 if (id.grpPtr()->getName()==name ||
109 id.grpPtr()->getName()+"."+id.grpPtr()->getName()==name ||
110 id.grpPtr()->getName()+":"+id.grpPtr()->getName()==name )
113 // see if we have a group number and manager number
117 sscanf(name.c_str(),"%i:%i",&mgridx,&grpidx);
118 sprintf(s,"%i:%i",mgridx,grpidx);
119 if (name==std::string(s))
120 return CAIEntityId::grpId(mgridx,grpidx);
122 sscanf(name.c_str(),"%i,%i",&mgridx,&grpidx);
123 sprintf(s,"%i,%i",mgridx,grpidx);
124 if (name==std::string(s))
125 return CAIEntityId::grpId(mgridx,grpidx);
127 sscanf(name.c_str(),"%i.%i",&mgridx,&grpidx);
128 sprintf(s,"%i.%i",mgridx,grpidx);
129 if (name==std::string(s))
130 return CAIEntityId::grpId(mgridx,grpidx);
132 // we're out of options so give up
133 return CAIEntityId();
138 CAIEntityId CAIEntityId::mgrId(const std::string &name)
142 // see if we have a CAIEntityId.toString()
143 id=CAIEntityId(name);
144 if (id.isMgr() && id.exists())
147 // see if we have a NLMISC::CEntityId.toString()
150 id=CAIEntityId(NLMISC::CEntityId(name.c_str()));
151 if (id.isMgr() && id.exists())
155 // see if name corresponds to the name of one of the manager
156 for (id=CAIEntityId::firstMgr();!id.isInvalid();id=id.nextMgr())
158 if (id.mgrPtr()->getName()==name)
161 // see if we have a manager number
164 sscanf(name.c_str(),"%i",&idx);
166 if (name==std::string(s))
167 return CAIS::getMgr(idx)->id();
169 // toString no more accepts to compile and not have the time to look at, so its remplaced by the upper piece of code ..
170 // uint idx=atoi(name.c_str());
171 // if (toString(idx)==name)
172 // return CAIS::getMgr(idx)->id();
174 // we're out of options so give up
175 return CAIEntityId();