// Ryzom - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . #ifndef RYAI_ADMIN_H #define RYAI_ADMIN_H #include "nel/misc/types_nl.h" #include "ai_share/ai_types.h" void selectEntities (const string &entityName, vector &entities) { if (entityName.empty ()) return; /* valid name formats: ALL MGRS: - * MGR: - = - - - <8 digit hex mgr CAIEntityId> ALL GRPS IN MGR: - * GRP: - = - - <8 digit hex grp CAIEntityId> - : ALL BOTS IN GRP: - * INDIVIDUAL: - = - - <8 digit hex bot CAIEntityId> - : RANGE OF INDIVIDUALS: - - */ uint32 entity = atoi (entityName.c_str()); if (entityName == "*") { // we want all entities for (uint i = 0; i < Entities.size(); i++) entities.push_back (i); } else if (entityName.find ("-") != string::npos) { // it's a range uint ent2 = atoi(entityName.substr(entityName.find("-")+1).c_str()); for (uint i = entity; i <= ent2; i++) entities.push_back (i); } else { // we want a specific entity entities.push_back (entity); } } #define ENTITY_VARIABLE(__name,__help) \ struct __name##Class : public NLMISC::ICommand \ { \ __name##Class () : NLMISC::ICommand(#__name, __help, " []") { Type = Variable; } \ virtual bool execute(const std::vector &args, NLMISC::CLog &log) \ { \ if (args.size () != 1 && args.size () != 2) \ return false; \ \ vector entities; \ selectEntities (args[0], entities); \ \ for (uint i = 0; i < entities.size(); i++) \ { \ string value; \ if (args.size()==2) \ value = args[1]; \ else \ value = "???"; \ pointer (entities[i], (args.size()==1), value); \ log.displayNL ("Entity %d Variable %s = %s", entities[i], _CommandName.c_str(), value.c_str()); \ } \ return true; \ } \ void pointer(uint32 entity, bool get, std::string &value); \ }; \ __name##Class __name##Instance; \ void __name##Class::pointer(uint32 entity, bool get, std::string &value) ENTITY_VARIABLE(test, "test") { if (get) { // get the value if available if(entity < Entities.size()) value = toString(Entities[entity].first); } else { // set the variable with the new value if(entity >= Entities.size()) Entities.resize(entity+1); Entities[entity].first = atoi(value.c_str()); } } ENTITY_VARIABLE(test2, "test2") { if (get) { // get the value if available if(entity < Entities.size()) value = toString(Entities[entity].second); } else { // set the variable with the new value if(entity >= Entities.size()) Entities.resize(entity+1); Entities[entity].second = atoi(value.c_str()); } } #endif