Add infos into target window
[ryzomcore.git] / ryzom / server / src / ai_share / ai_action_commands.cpp
blob73539f23766071b81c5ceed49ee286fd6f66e53a
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/>.
18 #include "stdpch.h"
20 #include "ai_actions.h"
22 using namespace NLMISC;
23 //using namespace NLNET;
24 using namespace std;
27 namespace AI_SHARE
30 //-------------------------------------------------------------------------
31 // GENERATING BOT MANAGERS & GROUPS
33 NLMISC_COMMAND(setMap,"set the active map","<name>")
35 if (args.size() !=1) return false;
37 CAIActions::exec("SET_MAP",args[0]);
39 return true;
42 NLMISC_COMMAND(setMgr,"set the active manager within a map","<name>|<slot>")
44 if (args.size() !=1) return false;
46 // see if we have a number or a name
47 uint slot;
48 NLMISC::fromString(args[0], slot);
50 if (toString(slot)!=args[0])
51 CAIActions::exec("SET_MGR",slot);
52 else
53 CAIActions::exec("SET_MGR",-1,args[0]);
55 return true;
58 NLMISC_COMMAND(setGrp,"set the active group within a manager","<name>|<slot>")
60 if (args.size() !=1) return false;
62 // see if we have a number or a name
63 uint slot;
64 NLMISC::fromString(args[0], slot);
66 if (toString(slot)!=args[0])
67 CAIActions::exec("SET_GRP",slot);
68 else
69 CAIActions::exec("SET_GRP",-1,args[0]);
71 return true;
75 NLMISC_COMMAND(newFaunaManager,"create the fauna manager for a region","<name> [<slot>]")
77 uint slot;
78 switch (args.size())
80 case 1: // <name>
82 slot=~0;
83 break;
86 case 2: // <name> <slot>
88 // the slot id is explicit so make sure its a number
89 NLMISC::fromString(args[1], slot);
90 if (toString(slot)!=args[1])
91 return false;
92 break;
95 default:
96 return false;
99 CAIActions::exec("SET_MGR",slot,args[0],"FAUNA");
101 return true;
104 NLMISC_COMMAND(newPlaceXYR,"","<place name> <x> <y> <r> <verticalPos>")
106 if(args.size() !=5)
107 return false;
109 sint x, y;
110 NLMISC::fromString(args[1], x);
111 NLMISC::fromString(args[2], y);
112 sint r=10; // default value.
113 uint32 vp = AITYPES::vp_auto;
114 if (!args[3].empty())
116 NLMISC::fromString(args[3], r);
118 vp = AITYPES::verticalPosFromString(args[4]);
120 if (toString(x)+toString(y)+toString(r)!=args[1]+args[2]+args[3])
122 nlinfo("Cumulated numeric parameter test failed: '%s' != '%s'",(toString(x)+toString(y)+toString(r)).c_str(),(args[1]+args[2]+args[3]).c_str());
123 return false;
126 CAIActions::exec("PLACEXYR",args[0],x*1000,y*1000,r*1000, vp);
128 return true;
131 NLMISC_COMMAND(newHerbivoreGroup,"","<group name> ")
133 if(args.size() !=4) return false;
135 CAIActions::exec("SET_GRP",-1,args[0],"HERBIVORE");
137 return true;
140 NLMISC_COMMAND(newPredatorGroup,"","<group name> <spawn point> <eat point> <rest point>")
142 if(args.size() !=4) return false;
144 CAIActions::exec("SET_GRP",-1,args[0],"PREDATOR");
146 return true;
149 NLMISC_COMMAND(newPlantGroup,"","<group name> <spawn point> <eat point> <rest point>")
151 if(args.size() !=4) return false;
153 CAIActions::exec("SET_GRP",-1,args[0],"PLANT");
155 return true;
158 NLMISC_COMMAND(newAnimatGroup,"","<group name> <spawn point> <eat point> <rest point>")
160 if(args.size() !=4) return false;
162 CAIActions::exec("SET_GRP",-1,args[0],"ANIMAT");
164 return true;
167 NLMISC_COMMAND(newScavengerGroup,"","<group name> <spawn point> <eat point> <rest point>")
169 if(args.size() !=4) return false;
171 CAIActions::exec("SET_GRP",-1,args[0],"SCAVENGER");
173 return true;
176 NLMISC_COMMAND(addHerbivorePopulation,"add a population version to the current group","<creature type> <qty> [<type> <qty>] [...] [...]")
178 if ( (args.size()&1) || args.size()>8)
179 return false;
181 std::vector <CAIActions::CArg> executeArgs;
183 // push the weight
184 executeArgs.push_back(100);
186 // check that every second argument is a number
187 for (uint i=0;i<args.size();i+=2)
189 uint32 count;
190 NLMISC::fromString(args[i+1], count);
191 if (toString(count)!=args[i+1])
192 return false;
193 executeArgs.push_back(CAIActions::CArg(args[i]));
194 executeArgs.push_back(count);
196 CAIActions::execute("POP_ADD",executeArgs);
198 return true;
203 NLMISC_COMMAND(newUrbanManager,"create the urban npc manager for a sttlement","<name> [<slot>]")
205 uint slot;
206 switch (args.size())
208 case 1: // <name>
210 slot=~0;
211 break;
214 case 2: // <name> <slot>
216 // the slot id is explicit so make sure its a number
217 NLMISC::fromString(args[1], slot);
218 if (toString(slot)!=args[1])
219 return false;
220 break;
223 default:
224 return false;
227 CAIActions::exec("SET_MGR",slot,args[0],"URBAN");
229 return true;
232 NLMISC_COMMAND(newStationaryGroup,"","<group name>")
234 if(args.size() !=1) return false;
236 CAIActions::exec("SET_GRP",-1,args[0],"STATIONARY");
238 return true;
241 NLMISC_COMMAND(npcAddGrpPatrol,"add a group to the manager","<name>")
243 if(args.size() !=1) return false;
245 CAIActions::exec("SET_GRP",-1,args[0],"PATROL");
247 return true;
250 NLMISC_COMMAND(npcAddGrpGuard,"add a group to the manager","<name>")
252 if(args.size() !=1) return false;
254 CAIActions::exec("SET_GRP",-1,args[0],"GUARD");
256 return true;
259 NLMISC_COMMAND(npcAddGrpWandering,"add a group to the manager","<name>")
261 if(args.size() !=1) return false;
263 CAIActions::exec("SET_GRP",-1,args[0],"WANDER");
265 return true;
268 NLMISC_COMMAND(npcGrpSetRoute,"setup a patrol route","<route name>")
270 if ( args.size()!=1)
271 return false;
273 CAIActions::exec("SETROUTE",args[0]);
275 return true;
278 NLMISC_COMMAND(npcMgrDefaults,"setup the manager dummy bot","")
280 if ( args.size()!=0)
281 return false;
283 CAIActions::exec("SET_BOT");
285 return true;
288 NLMISC_COMMAND(npcGrpDefaults,"setup the manager dummy bot","")
290 if ( args.size()!=0)
291 return false;
293 CAIActions::exec("SET_BOT");
295 return true;
298 NLMISC_COMMAND(addNpc,"create a new npc ","<x> <y> <theta>")
300 if ( args.size()!=3)
301 return false;
303 uint x=(uint)(1000.0*atof(args[0].c_str()));
304 uint y=(uint)(1000.0*atof(args[1].c_str()));
305 float theta=(float)atof(args[2].c_str());
307 CAIActions::exec("SET_BOT",-1,"npc",x,y,theta);
309 return true;
312 NLMISC_COMMAND(npcSetColours,"set the npc clothing colour scheme","<colour scheme>")
314 if ( args.size()!=1)
315 return false;
317 CAIActions::exec("COLOURS");
319 return true;
322 NLMISC_COMMAND(npcSetName,"set npc name","<name>")
324 if ( args.size()!=1)
325 return false;
327 // concatenate the names on the command line into a single string
328 std::string s=args[0];
329 for (uint i=1;i<args.size();++i)
330 s=s+' '+args[i];
332 CAIActions::exec("NAME",s);
334 return true;
337 NLMISC_COMMAND(npcSetGameForm,"set the .CREATURE sheet to use for game stats","<sheet name>")
339 if ( args.size()!=1)
340 return false;
342 CAIActions::exec("GAMEFORM",args[0]);
344 return true;
347 NLMISC_COMMAND(npcSetLookForm,"set the .CREATURE sheet to use for look on client","<sheet name>")
349 if ( args.size()!=1)
350 return false;
352 CAIActions::exec("LOOKFORM",args[0]);
354 return true;
357 NLMISC_COMMAND(npcSetLookType,"set the possible look types","<keyword>")
359 if ( args.size()!=1)
360 return false;
362 CAIActions::exec("LOOKTYPE",args[0]);
364 return true;
367 NLMISC_COMMAND(npcSetChat,"set the npc chat parameters","<keyword>[...]")
369 if ( args.size()<1)
370 return false;
372 // prepare the arguments from the command line for the 'execute' command
373 std::vector <CAIActions::CArg> executeArgs;
374 for (uint i=0;i<args.size();++i)
375 executeArgs.push_back(CAIActions::CArg(args[i]));
377 CAIActions::execute("CHATTYPE",executeArgs);
379 return true;
383 // THIS LINE EXISTS TO MAKE SURE THE LINKER DOESN'T THROW OUT THIS MODULE AT LINK TIME!!!
384 bool LinkWithAiActionCommands=false;
386 } // end of namespace