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/>.
21 #include "nel/net/service.h"
22 #include "nel/misc/command.h"
25 #include "game_share/macro_manager.h"
29 #include "ai_manager.h"
30 #include "ai_service.h"
32 using namespace NLMISC
;
33 using namespace NLNET
;
37 //-------------------------------------------------------------------------
40 static void argsToManagerVector(const vector
<string
> &args
, vector
<CAIManager
*> &theManagers
)
44 for (uint i
=0;i
<CAIManager::numManagers();++i
)
45 theManagers
.push_back(CAIManager::getManagerByIdx(i
));
49 for (uint i
=0;i
<args
.size();++i
)
51 int id
=CAIManager::nameToId(args
[i
]);
53 nlwarning("Can't find a manger record for: %s",args
[i
].c_str());
55 theManagers
.push_back(CAIManager::getManagerById(id
));
60 //-------------------------------------------------------------------------
61 // scanning the hard disk for interesting files, compiling
62 // where nessessary and allerting ai_service(s) of data file changes
64 NLMISC_COMMAND(aiRescanDirectories
,"Rescan disk file directories","")
66 if(args
.size()!=0) return false;
67 COMMAND_MACRO_RECORD_TEST
74 NLMISC_COMMAND(aiMake
,"scan the hard disk for interesting files, recompile as necessary and allert services","")
76 COMMAND_MACRO_RECORD_TEST
78 // rescan the source and object directories for files
81 // build the list of ai managers to act on
82 vector
<CAIManager
*> theManagers
;
83 argsToManagerVector(args
,theManagers
);
86 for (uint i
=0;i
<theManagers
.size();++i
)
88 if (theManagers
[i
]->needCompile())
90 //nlinfo("Compiling manager: %04d: %s",theManagers[i]->id(),theManagers[i]->name());
91 theManagers
[i
]->compile();
94 nlinfo("Manager is up to date: %04d: %s",theManagers
[i
]->id(),theManagers
[i
]->name().c_str());
100 NLMISC_COMMAND(aiClean
,"delete all generated files on the hard disk (next 'make' will rebuild everything)","")
102 COMMAND_MACRO_RECORD_TEST
104 // rescan the source and object directories for files
107 // build the list of ai managers to act on
108 vector
<CAIManager
*> theManagers
;
109 argsToManagerVector(args
,theManagers
);
112 for (uint i
=0;i
<theManagers
.size();++i
)
114 nlinfo("Cleaning: %04d: %s",theManagers
[i
]->id(),theManagers
[i
]->name().c_str());
115 theManagers
[i
]->clean();
121 //-------------------------------------------------------------------------
123 NLMISC_COMMAND(aiDisplayServices
,"list the ai services, their parameters and their lists of running managers","[<service id>[...]]")
125 if(args
.size()!=0) return false;
126 COMMAND_MACRO_RECORD_TEST
131 NLMISC_COMMAND(aiDisplayManagers
,"Display the known ai manager list","[<manager name|id>[...]]")
133 COMMAND_MACRO_RECORD_TEST
135 // build the list of ai managers to act on
136 vector
<CAIManager
*> theManagers
;
137 argsToManagerVector(args
,theManagers
);
140 for (uint i
=0;i
<theManagers
.size();++i
)
141 theManagers
[i
]->display();
146 //-------------------------------------------------------------------------
147 NLMISC_COMMAND(aiOpenAllManagers
,"Open all managers and automatically assign to ai services","")
149 if(args
.size()!=0) return false;
150 COMMAND_MACRO_RECORD_TEST
152 for (uint i
=0;i
<CAIManager::numManagers();++i
)
153 if (!CAIManager::getManagerByIdx(i
)->isOpen())
154 CAIManager::getManagerByIdx(i
)->open();
159 NLMISC_COMMAND(aiOpenManagers
,"Open managers and automatically assign to ai services","<manager name|id>[...]")
161 if(args
.size()<1) return false;
162 COMMAND_MACRO_RECORD_TEST
164 for (uint i
=0;i
<args
.size();++i
)
166 int id
=CAIManager::nameToId(args
[i
]);
168 nlwarning("Can't find a manger record for: %s",args
[i
].c_str());
170 CAIManager::getManagerById(id
)->open();
176 NLMISC_COMMAND(aiAssignManagers
,"Open managers and assign to specified ai service","<service><manager name|id>[...]")
178 if(args
.size()<2) return false;
179 COMMAND_MACRO_RECORD_TEST
181 // convert args[0] to service id and verify existance in services list
182 NLNET::TServiceId
service(atoi(args
[0].c_str()));
183 if (service
.get()==0 && args
[0]!="0")
185 nlwarning("Invalid service id: %s",args
[0].c_str());
189 // iterate through args assigning managers to service
190 for (uint i
=1;i
<args
.size();++i
)
192 int id
=CAIManager::nameToId(args
[i
]);
194 nlwarning("Can't find a manger record for: %s",args
[i
].c_str());
196 CAIManager::getManagerById(id
)->assign(service
);
202 NLMISC_COMMAND(aiReassignManagers
,"Save & close managers on existing services and open on specified ai service","<service><manager name|id>[...]")
204 if(args
.size()<2) return false;
205 COMMAND_MACRO_RECORD_TEST
207 // convert args[0] to service id and verify existance in services list
208 NLNET::TServiceId
service(atoi(args
[0].c_str()));
209 if (service
.get()==0 && args
[0]!="0")
211 nlwarning("Invalid service id: %s",args
[0].c_str());
215 // iterate through args reassigning managers to service
216 for (uint i
=1;i
<args
.size();++i
)
218 int id
=CAIManager::nameToId(args
[i
]);
220 nlwarning("Can't find a manger record for: %s",args
[i
].c_str());
222 CAIManager::getManagerById(id
)->reassign(service
);
228 //-------------------------------------------------------------------------
229 NLMISC_COMMAND(aiCloseAllManagers
,"Close all managers across all ai services on the shard","")
231 if(args
.size()!=0) return false;
232 COMMAND_MACRO_RECORD_TEST
234 for (uint i
=0;i
<CAIManager::numManagers();++i
)
235 if (CAIManager::getManagerByIdx(i
)->isOpen())
236 CAIManager::getManagerByIdx(i
)->close();
241 NLMISC_COMMAND(aiCloseManagers
,"Close listed managers","<manager name|id>[...]")
243 if(args
.size()<1) return false;
244 COMMAND_MACRO_RECORD_TEST
246 for (uint i
=0;i
<args
.size();++i
)
248 int id
=CAIManager::nameToId(args
[i
]);
250 nlwarning("Can't find a manger record for: %s",args
[i
].c_str());
252 CAIManager::getManagerById(id
)->close();
258 //-------------------------------------------------------------------------