Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / ais_spawn_ctrl.cpp
blob6dc2728ccc7a6be98103dc6e2c217b7ae574f2fa
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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/>.
19 //-------------------------------------------------------------------------
20 // Includes & namespaces
22 #include "stdpch.h"
23 #include "ai_share/ai_spawn_commands.h"
24 #include "ai_grp.h"
26 using namespace NLMISC;
27 using namespace std;
30 //-------------------------------------------------------------------------
31 // The CAISpawnCtrl sub-class
33 //class CAISSpawnCtrl: public CAISpawnCtrl
34 //{
35 //protected:
36 // virtual bool _spawn (int aiInstance, const std::string &name);
37 // virtual bool _spawnMap (int aiInstance, const std::string &name);
38 // virtual bool _spawnMgr (int aiInstance, const std::string &name);
39 // virtual bool _spawnGrp (int aiInstance, const std::string &name);
40 // virtual bool _spawnAll (int aiInstance);
42 // virtual bool _despawn (int aiInstance, const std::string &name);
43 // virtual bool _despawnMap (int aiInstance, const std::string &name);
44 // virtual bool _despawnMgr (int aiInstance, const std::string &name);
45 // virtual bool _despawnGrp (int aiInstance, const std::string &name);
46 // virtual bool _despawnAll (int aiInstance);
48 //} AIServiceSpawnCtrl;
51 //-------------------------------------------------------------------------
52 // The CAISpawnCtrl singleton data
53 //CAISpawnCtrl *CAISpawnCtrl::_instance=&AIServiceSpawnCtrl;
56 //-------------------------------------------------------------------------
57 // SPAWNING
59 //bool CAISSpawnCtrl::_spawn(int aiInstance, const std::string &name)
60 //{
61 // if (_spawnMap(aiInstance, name)) return true;
62 // if (_spawnMgr(aiInstance, name)) return true;
63 // if (_spawnGrp(aiInstance, name)) return true;
64 // return false;
65 //}
67 //bool CAISSpawnCtrl::_spawnGrp(int aiInstance, const std::string &name)
68 //{
69 // bool returnVal=false;
71 // if (aiInstance==-1) // all aiInstance are concerned.
72 // {
73 // CCont<CAIInstance>::iterator instanceIt=CAIS::instance().AIList().begin(), instanceItEnd=CAIS::instance().AIList().end();
74 // while (instanceIt!=instanceItEnd)
75 // {
76 // CGroup* grpPtr=(*instanceIt)->tryToGetGroup(name.c_str());
77 // if (grpPtr)
78 // {
79 // grpPtr->spawn (); // check error only if not a npc group.
80 // returnVal=true;
81 // }
82 // ++instanceIt;
83 // }
84 //
85 // }
86 // else
87 // {
88 // if (CAIS::instance().AIList()[aiInstance])
89 // {
90 // CGroup* grpPtr=CAIS::instance().AIList()[aiInstance]->tryToGetGroup(name.c_str());
91 // if (grpPtr)
92 // {
93 // grpPtr->spawn (); // check error only if not a npc group.
94 // returnVal=true;
95 // }
96 //
97 // }
98 //
99 // }
101 // if (!returnVal)
102 // {
103 // nlinfo("Failed to identify groupe from id: %s",name.c_str());
104 // }
105 // return returnVal;
108 //bool CAISSpawnCtrl::_spawnMgr(int aiInstance, const std::string &name)
110 // bool returnVal=false;
112 // if (aiInstance==-1) // all aiInstance are concerned.
113 // {
114 // CCont<CAIInstance>::iterator instanceIt=CAIS::instance().AIList().begin(), instanceItEnd=CAIS::instance().AIList().end();
115 // while (instanceIt!=instanceItEnd)
116 // {
117 // CManager* mgrPtr=(*instanceIt)->tryToGetManager(name.c_str());
118 // if (mgrPtr)
119 // {
120 // mgrPtr->spawn (); // check error only if not a npc group.
121 // returnVal=true;
122 // }
123 // ++instanceIt;
124 // }
126 // }
127 // else
128 // {
129 // if (CAIS::instance().AIList()[aiInstance])
130 // {
131 // CManager* mgrPtr=CAIS::instance().AIList()[aiInstance]->tryToGetManager(name.c_str());
132 // if (mgrPtr)
133 // {
134 // mgrPtr->spawn (); // check error only if not a npc group.
135 // returnVal=true;
136 // }
138 // }
140 // }
142 // if (!returnVal)
143 // {
144 // nlinfo("Failed to identify mgr from id: %s",name.c_str());
145 // }
146 // return returnVal;
149 //bool CAISSpawnCtrl::_spawnMap(int aiInstance, const std::string &name)
151 //#ifdef NL_DEBUG
152 // nlassert(false);
153 //#endif
154 //// // for each manager if map's name found in the command arguments then spawn()
155 //// for (CAIEntityId it=CAIEntityId::firstMgr();!it.isInvalid();it=it.nextMgr())
156 //// if (it.mgrPtr()->getMap()->Name==name)
157 //// it.mgrPtr()->spawn();
158 // return true;
161 //bool CAISSpawnCtrl::_spawnAll (int aiInstance)
163 // if (aiInstance==-1) // all aiInstance are concerned.
164 // {
165 // CCont<CAIInstance>::iterator instanceIt=CAIS::instance().AIList().begin(), instanceItEnd=CAIS::instance().AIList().end();
166 // while (instanceIt!=instanceItEnd)
167 // {
168 // (*instanceIt)->spawnAll();
169 // ++instanceIt;
170 // }
172 // }
173 // else
174 // {
175 // if (CAIS::instance().AIList()[aiInstance])
176 // {
177 // CAIS::instance().AIList()[aiInstance]->spawnAll();
178 // }
180 // }
181 // return true;
185 ////-------------------------------------------------------------------------
186 //// DESPAWNING
188 //bool CAISSpawnCtrl::_despawn(int aiInstance, const std::string &name)
190 // if (_despawnMap(aiInstance, name)) return true;
191 // if (_despawnMgr(aiInstance, name)) return true;
192 // if (_despawnGrp(aiInstance, name)) return true;
193 // return false;
196 //bool CAISSpawnCtrl::_despawnGrp(int aiInstance, const std::string &name)
199 // bool returnVal=false;
201 // if (aiInstance==-1) // all aiInstance are concerned.
202 // {
203 // CCont<CAIInstance>::iterator instanceIt=CAIS::instance().AIList().begin(), instanceItEnd=CAIS::instance().AIList().end();
204 // while (instanceIt!=instanceItEnd)
205 // {
206 // CGroup* grpPtr=(*instanceIt)->tryToGetGroup(name.c_str());
207 // if (grpPtr)
208 // {
209 // grpPtr->despawnGrp (); // check error only if not a npc group.
210 // returnVal=true;
211 // }
212 // ++instanceIt;
213 // }
215 // }
216 // else
217 // {
218 // if (CAIS::instance().AIList()[aiInstance])
219 // {
220 // CGroup* grpPtr=CAIS::instance().AIList()[aiInstance]->tryToGetGroup(name.c_str());
221 // if (grpPtr)
222 // {
223 // grpPtr->despawnGrp (); // check error only if not a npc group.
224 // returnVal=true;
225 // }
227 // }
229 // }
231 // if (!returnVal)
232 // {
233 // nlinfo("Failed to identify groupe from id: %s",name.c_str());
234 // }
235 // return returnVal;
238 //bool CAISSpawnCtrl::_despawnMgr(int aiInstance, const std::string &name)
240 // bool returnVal=false;
242 // if (aiInstance==-1) // all aiInstance are concerned.
243 // {
244 // CCont<CAIInstance>::iterator instanceIt=CAIS::instance().AIList().begin(), instanceItEnd=CAIS::instance().AIList().end();
245 // while (instanceIt!=instanceItEnd)
246 // {
247 // CManager* mgrPtr=(*instanceIt)->tryToGetManager(name.c_str());
248 // if (mgrPtr)
249 // {
250 // mgrPtr->despawnMgr(); // check error only if not a npc group.
251 // returnVal=true;
252 // }
253 // ++instanceIt;
254 // }
256 // }
257 // else
258 // {
259 // if (CAIS::instance().AIList()[aiInstance])
260 // {
261 // CManager* mgrPtr=CAIS::instance().AIList()[aiInstance]->tryToGetManager(name.c_str());
262 // if (mgrPtr)
263 // {
264 // mgrPtr->despawnMgr(); // check error only if not a npc group.
265 // returnVal=true;
266 // }
268 // }
270 // }
272 // if (!returnVal)
273 // {
274 // nlinfo("Failed to identify mgr from id: %s",name.c_str());
275 // }
276 // return returnVal;
279 //bool CAISSpawnCtrl::_despawnMap(int aiInstance, const std::string &name)
281 //#ifdef NL_DEBUG
282 // nlwarning("Not Implemented");
283 //#endif
285 //// // for each manager if map's name found in the command arguments then spawn()
286 //// for (CAIEntityId it=CAIEntityId::firstMgr();!it.isInvalid();it=it.nextMgr())
287 //// if (it.mgrPtr()->getMap()->Name==name)
288 //// it.mgrPtr()->despawn();
290 // return true;
293 //bool CAISSpawnCtrl::_despawnAll(int aiInstance)
295 // if (aiInstance==-1) // all aiInstance are concerned.
296 // {
297 // CCont<CAIInstance>::iterator instanceIt=CAIS::instance().AIList().begin(), instanceItEnd=CAIS::instance().AIList().end();
298 // while (instanceIt!=instanceItEnd)
299 // {
300 //// NLMEMORY::CheckHeap(true);
301 // (*instanceIt)->despawnAll();
302 // ++instanceIt;
303 // }
305 // }
306 // else
307 // {
308 // if (CAIS::instance().AIList()[aiInstance])
309 // {
310 // CAIS::instance().AIList()[aiInstance]->despawnAll();
311 // }
313 // }
314 // return true;