Added ai command setEquipment
[ryzomcore.git] / ryzom / server / src / ai_service / ais_actions_global.cpp
blob44352fbf2407c7475f368c4d70b0bf6df9d0a0b8
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/>.
20 //----------------------------------------------------------------------------
22 #include "stdpch.h"
23 #include "ais_actions.h"
24 #include "script_compiler.h"
26 using namespace NLMISC;
27 using namespace NLNET;
28 using namespace std;
29 using namespace CAISActionEnums;
30 using namespace AITYPES;
32 extern CAIInstance *currentInstance;
34 //----------------------------------------------------------------------------
35 // Handy local variables and sub routines for GLOBAL context
36 //----------------------------------------------------------------------------
38 static void DoMgrAction(const std::vector <CAIActions::CArg> &args,
39 enum TMgrType type,
40 TContext context,
41 uint32 aIInstanceNumber=0)
43 // if (!CAIS::initialised())
44 // CAIS::initAI();
46 /* CAIInstance *aiInstance=NULL;
48 if (aIInstanceNumber<CAIS::instance().AIList().size())
50 aiInstance=CAIS::instance().AIList()[aIInstanceNumber];
53 if (!aiInstance)
55 aiInstance=CAIS::instance().AIList().addChild(new CAIInstance(*((CAIS*)NULL)), aIInstanceNumber); // Arggghhh !!!
56 if (!aiInstance)
58 return;
63 nlassertex(currentInstance != NULL, ("No AIInstance created !"));
64 CAIInstance *aiInstance=currentInstance ;
65 CWorkPtr::aiInstance(aiInstance); // set the current AIInstance.
67 // get hold of the manager's slot id - note that managers are identified by slot and not by alias!
68 uint32 alias; //,firstSlot,lastSlot;
69 std::string name,mapName, filename;
70 if (!getArgs(args,"MANAGER",alias,name,mapName, filename))
71 return;
73 // see whether the manager is already loaded
74 CManager* mgr = aiInstance->managers().getChildByAlias(alias);
76 // not found so look for a free slot
77 if (!mgr)
78 aiInstance->newMgr(type, alias, name, mapName, filename);
79 else
80 mgr->registerForFile(filename);
82 mgr=aiInstance->managers().getChildByAlias(alias);
84 // clear the delete flag (if present)
85 // mgr->clearDeleteFlag();
88 // setup the working manager pointer and exit
89 CWorkPtr::mgr(mgr);
90 if (mgr)
91 CWorkPtr::eventReactionContainer(mgr->getStateMachine());
92 else
93 CWorkPtr::eventReactionContainer(NULL);
95 // push the manager context onto the context stack
96 CContextStack::setContext(context);
100 //----------------------------------------------------------------------------
101 // The GLOBAL context
102 //----------------------------------------------------------------------------
104 DEFINE_ACTION(ContextGlobal,MGRFAUNA)
106 DoMgrAction(args,MgrTypeFauna,ContextFaunaMgr);
109 DEFINE_ACTION(ContextGlobal,MGRNPC)
111 DoMgrAction(args,MgrTypeNpc,ContextNpcMgr);
114 //DEFINE_ACTION(ContextGlobal,MGRKAMI)
116 // DoMgrAction(args,MgrTypeKami,ContextNpcMgrKami);
119 //DEFINE_ACTION(ContextGlobal,MGRTRIBE)
121 // DoMgrAction(args,MgrTypeTribe,ContextNpcMgrTribe);
124 DEFINE_ACTION(ContextGlobal,MGRKARAV)
126 DoMgrAction(args,MgrTypeKaravan,ContextNpcMgrKaravan);
129 DEFINE_ACTION(ContextGlobal,SCRIPT)
131 // get hold of the parameters and check their validity
132 string name;
133 std::string code;
134 if (!getArgs(args,"",name,code))
135 return;
137 AIVM::CLibrary::getInstance().addLib(name, code);
140 //----------------------------------------------------------------------------
141 // The base context for MGR contexts
142 //----------------------------------------------------------------------------
144 DEFINE_ACTION(BaseContextMgr,IDTREE)
146 // set the id tree for the manager (results in creation or update of manager's object tree)
147 // args: aliasTree
149 if (!CWorkPtr::mgr())
150 return;
152 // read the alias tree from the argument list
153 CAIAliasDescriptionNode *aliasTree;
154 if (!getArgs(args,name(),aliasTree))
155 return;
157 // have the manager update it's structure from the id tree
158 nlinfo("ACTION IDTREE: Applying new tree to manager[%u]: '%s'%s",
159 CWorkPtr::mgr()->getChildIndex(),
160 CWorkPtr::mgr()->getAliasTreeOwner()->getName().c_str(),
161 CWorkPtr::mgr()->getAliasTreeOwner()->getAliasString().c_str());
163 if (aliasTree)
164 CWorkPtr::mgr()->updateAliasTree(*aliasTree);
167 DEFINE_ACTION(BaseContextMgr,BOUNDS)
169 // set the bounding patat for a manager
170 // args: [x0, y0 [, x1, y1 [, x2,y2 [,...]]]]
172 if (CWorkPtr::mgr()==NULL) return;
174 // make sure argument count is even
175 if (args.size()&1)
177 nlwarning("BOUNDS failed due to invalid arguments");
178 return;
181 // build a vector of CAIVectot to hold points
182 std::vector<CAIVector> points;
183 for (uint i=0;i<args.size();i+=2)
185 double x,y;
186 if (!(args[i].get(x)&&args[i+1].get(y)))
188 nlwarning("BOUNDS failed due to invalid arguments");
189 return;
191 points.push_back(CAIVector(x,y));
194 // pass vector of points to the currently active manger
195 // CWorkPtr::mgr()->setBounds(points);
198 //DEFINE_ACTION(BaseContextMgr,NOGO)
200 // // add a no-go zone to the manager's bounding patat
201 // // args: [x0, y0 [, x1, y1 [, x2,y2 [,...]]]]
203 // if (CWorkPtr::mgr()==NULL) return;
205 // // make sure argument count is even (plus alias)
206 // uint32 alias;
207 // if (args.size()<3 || !args[0].get(alias) || (args.size()&1)==0)
208 // {
209 // nlwarning("NOGO failed due to invalid arguments");
210 // return;
211 // }
213 // // build a vector of CAIVectot to hold points
214 // std::vector<CAIVector> points;
215 // for (uint i=0;i<args.size();i+=2)
216 // {
217 // double x,y;
218 // if (!(args[i].get(x)&&args[i+1].get(y)))
219 // {
220 // nlwarning("BOUNDS failed due to invalid arguments");
221 // return;
222 // }
223 // points.push_back(CAIVector(x,y));
224 // }
226 // // pass vector of points to the currently active manger
227 // // CWorkPtr::mgr()->addNogo(alias,points);