Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / admin.h
blobed677eb196fe494159189fdf89c179a9e50e6a4c
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/>.
19 #ifndef RYAI_ADMIN_H
20 #define RYAI_ADMIN_H
22 #include "nel/misc/types_nl.h"
23 #include "ai_share/ai_types.h"
26 void selectEntities (const string &entityName, vector <uint32> &entities)
28 if (entityName.empty ())
29 return;
33 valid name formats:
34 ALL MGRS:
35 - *
37 MGR:
38 - <mgr id> =
39 - <mgr idx>
40 - <mgr name>
41 - <8 digit hex mgr CAIEntityId>
43 ALL GRPS IN MGR:
44 - <mgr id>*
46 GRP:
47 - <grp id> =
48 - <grp name>
49 - <8 digit hex grp CAIEntityId>
50 - <mgr id>:<grp index>
52 ALL BOTS IN GRP:
53 - <grp id>*
55 INDIVIDUAL:
56 - <bot id> =
57 - <bot name>
58 - <8 digit hex bot CAIEntityId>
59 - <grp id>:<bot index>
61 RANGE OF INDIVIDUALS:
62 - <bot id>-<bot id>
66 uint32 entity = atoi (entityName.c_str());
68 if (entityName == "*")
70 // we want all entities
71 for (uint i = 0; i < Entities.size(); i++)
72 entities.push_back (i);
74 else if (entityName.find ("-") != string::npos)
76 // it's a range
77 uint ent2;
78 NLMISC::fromString(entityName.substr(entityName.find("-")+1), ent2);
79 for (uint i = entity; i <= ent2; i++)
80 entities.push_back (i);
82 else
84 // we want a specific entity
85 entities.push_back (entity);
91 #define ENTITY_VARIABLE(__name,__help) \
92 struct __name##Class : public NLMISC::ICommand \
93 { \
94 __name##Class () : NLMISC::ICommand(#__name, __help, "<entity>
95 [<value>]") { Type = Variable; } \
96 virtual bool execute(const std::vector<std::string> &args,
97 NLMISC::CLog &log) \
98 { \
99 if (args.size () != 1 && args.size () != 2) \
100 return false; \
102 vector <uint32> entities; \
103 selectEntities (args[0], entities); \
105 for (uint i = 0; i < entities.size(); i++) \
107 string value; \
108 if (args.size()==2) \
109 value = args[1]; \
110 else \
111 value = "???"; \
112 pointer (entities[i], (args.size()==1), value); \
113 log.displayNL ("Entity %d Variable %s = %s", entities[i], _CommandName.c_str(), value.c_str()); \
115 return true; \
117 void pointer(uint32 entity, bool get, std::string &value); \
118 }; \
119 __name##Class __name##Instance; \
120 void __name##Class::pointer(uint32 entity, bool get, std::string &value)
122 ENTITY_VARIABLE(test, "test")
124 if (get)
126 // get the value if available
127 if(entity < Entities.size())
128 value = toString(Entities[entity].first);
130 else
132 // set the variable with the new value
133 if(entity >= Entities.size())
134 Entities.resize(entity+1);
136 NLMISC::fromString(value, Entities[entity].first);
140 ENTITY_VARIABLE(test2, "test2")
142 if (get)
144 // get the value if available
145 if(entity < Entities.size())
146 value = toString(Entities[entity].second);
148 else
150 // set the variable with the new value
151 if(entity >= Entities.size())
152 Entities.resize(entity+1);
154 NLMISC::fromString(value, Entities[entity].second);
158 #endif