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/>.
20 //----------------------------------------------------------------------------
23 #include "ais_actions.h"
24 #include "script_compiler.h"
26 using namespace NLMISC
;
27 using namespace NLNET
;
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
,
41 uint32 aIInstanceNumber
=0)
43 // if (!CAIS::initialised())
46 /* CAIInstance *aiInstance=NULL;
48 if (aIInstanceNumber<CAIS::instance().AIList().size())
50 aiInstance=CAIS::instance().AIList()[aIInstanceNumber];
55 aiInstance=CAIS::instance().AIList().addChild(new CAIInstance(*((CAIS*)NULL)), aIInstanceNumber); // Arggghhh !!!
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
))
73 // see whether the manager is already loaded
74 CManager
* mgr
= aiInstance
->managers().getChildByAlias(alias
);
76 // not found so look for a free slot
78 aiInstance
->newMgr(type
, alias
, name
, mapName
, filename
);
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
91 CWorkPtr::eventReactionContainer(mgr
->getStateMachine());
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
134 if (!getArgs(args
,"",name
,code
))
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)
149 if (!CWorkPtr::mgr())
152 // read the alias tree from the argument list
153 CAIAliasDescriptionNode
*aliasTree
;
154 if (!getArgs(args
,name(),aliasTree
))
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());
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
177 nlwarning("BOUNDS failed due to invalid arguments");
181 // build a vector of CAIVectot to hold points
182 std::vector
<CAIVector
> points
;
183 for (uint i
=0;i
<args
.size();i
+=2)
186 if (!(args
[i
].get(x
)&&args
[i
+1].get(y
)))
188 nlwarning("BOUNDS failed due to invalid arguments");
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)
207 // if (args.size()<3 || !args[0].get(alias) || (args.size()&1)==0)
209 // nlwarning("NOGO failed due to invalid arguments");
213 // // build a vector of CAIVectot to hold points
214 // std::vector<CAIVector> points;
215 // for (uint i=0;i<args.size();i+=2)
218 // if (!(args[i].get(x)&&args[i+1].get(y)))
220 // nlwarning("BOUNDS failed due to invalid arguments");
223 // points.push_back(CAIVector(x,y));
226 // // pass vector of points to the currently active manger
227 // // CWorkPtr::mgr()->addNogo(alias,points);