Add infos into target window
[ryzomcore.git] / ryzom / server / src / ai_share / ai_event_description.h
blob871ea078b1d7d4d599a73c3b6b2e69b87c88c389
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 #ifndef RYAI_AI_EVENT_ACTION_NODE_H
21 #define RYAI_AI_EVENT_ACTION_NODE_H
23 #include "nel/misc/types_nl.h"
24 #include "nel/misc/entity_id.h"
25 #include "nel/misc/smart_ptr.h"
26 #include "nel/net/message.h"
28 #include "ai_types.h"
30 #include <string>
31 #include <vector>
33 #include "ai_vector.h"
35 class CTmpPropertyZone : public NLMISC::CRefCount
37 public:
38 enum TTarget { All, Fauna, Npc };
39 CTmpPropertyZone()
40 :verticalPos(AITYPES::vp_auto),
41 Target(All)
43 typedef NLMISC::CSmartPtr<CTmpPropertyZone> TSmartPtr;
45 AITYPES::TVerticalPos verticalPos;
46 std::vector <CAIVector> points;
47 AITYPES::CPropertySet properties;
48 TTarget Target;
51 class CAIEventActionNode : public NLMISC::CRefCount
53 public:
54 typedef NLMISC::CSmartPtr<CAIEventActionNode> TSmartPtr;
56 std::string Action;
57 std::vector<std::string> Args;
58 std::vector<CTmpPropertyZone::TSmartPtr> _PropertyZones;
59 std::vector<TSmartPtr> Children;
60 uint32 Weight;
61 uint32 Alias;
63 void pushToPdr(CPersistentDataRecord& pdr) const
65 pdr.push(pdr.addString("type"),Action);
67 if (Weight!=1) pdr.push(pdr.addString("weight"),Weight);
68 if (Alias!=0) pdr.push(pdr.addString("alias"),Alias);
70 for (uint32 i=0;i<Args.size();++i)
71 pdr.push(pdr.addString("arg"), Args[i]);
73 // Note I haven't implemented property zones for now so make sure that we don't need them!
74 nlassert(_PropertyZones.empty());
76 for (uint32 i=0;i<Children.size();++i)
78 pdr.pushStructBegin(pdr.addString("child"));
79 Children[i]->pushToPdr(pdr);
80 pdr.pushStructEnd(pdr.addString("child"));
83 static CAIEventActionNode* popFromPdr(CPersistentDataRecord& pdr)
85 CAIEventActionNode* result= new CAIEventActionNode;
86 result->Weight= 1;
87 result->Alias= 0;
89 while (!pdr.isEndOfStruct())
91 uint16 token= pdr.peekNextToken();
92 const std::string& tokenName= pdr.peekNextTokenName();
93 if (tokenName=="type") { result->Action= pdr.popNextArg(token).asString(); continue; }
94 if (tokenName=="weight") { result->Weight= (uint32) pdr.popNextArg(token).asUint(); continue; }
95 if (tokenName=="alias") { result->Alias= (uint32) pdr.popNextArg(token).asUint(); continue; }
96 if (tokenName=="arg") { result->Args.push_back( pdr.popNextArg(token).asString() ); continue; }
97 if (tokenName=="child")
99 pdr.popStructBegin(token);
100 vectAppend(result->Children)= CAIEventActionNode::popFromPdr(pdr);
101 pdr.popStructEnd(token);
102 continue;
104 WARN("Unrecognised content found in pdr: "+tokenName);
105 if (pdr.isStartOfStruct())
106 pdr.skipStruct();
107 else
108 pdr.skipData();
111 return result;
116 class CAIEventDescription : public NLMISC::CRefCount
118 public:
119 typedef NLMISC::CSmartPtr<CAIEventDescription> TSmartPtr;
121 std::string EventType;
122 std::vector<std::string> StateKeywords;
123 std::vector<std::string> NamedStates;
124 std::vector<std::string> GroupKeywords;
125 std::vector<std::string> NamedGroups;
127 CAIEventActionNode::TSmartPtr Action;
129 void pushToPdr(CPersistentDataRecord& pdr) const
131 pdr.push(pdr.addString("type"),EventType);
133 for (uint32 i=0;i<StateKeywords.size();++i)
134 pdr.push(pdr.addString("stateKeyword"), StateKeywords[i]);
136 for (uint32 i=0;i<NamedStates.size();++i)
137 pdr.push(pdr.addString("state"), NamedStates[i]);
139 for (uint32 i=0;i<GroupKeywords.size();++i)
140 pdr.push(pdr.addString("groupKeyword"), GroupKeywords[i]);
142 for (uint32 i=0;i<NamedGroups.size();++i)
143 pdr.push(pdr.addString("group"), NamedGroups[i]);
145 if (Action!=NULL)
147 pdr.pushStructBegin(pdr.addString("action"));
148 Action->pushToPdr(pdr);
149 pdr.pushStructEnd(pdr.addString("action"));
153 static CAIEventDescription* popFromPdr(CPersistentDataRecord& pdr)
155 CAIEventDescription* result= new CAIEventDescription;
157 while (!pdr.isEndOfStruct())
159 uint16 token= pdr.peekNextToken();
160 const std::string& tokenName= pdr.peekNextTokenName();
161 if (tokenName=="type") { result->EventType= pdr.popNextArg(token).asString(); continue; }
162 if (tokenName=="stateKeyword") { result->StateKeywords.push_back( pdr.popNextArg(token).asString() ); continue; }
163 if (tokenName=="state") { result->NamedStates.push_back( pdr.popNextArg(token).asString() ); continue; }
164 if (tokenName=="groupKeyword") { result->GroupKeywords.push_back( pdr.popNextArg(token).asString() ); continue; }
165 if (tokenName=="group") { result->NamedGroups.push_back( pdr.popNextArg(token).asString() ); continue; }
167 if (tokenName=="action")
169 pdr.popStructBegin(token);
170 result->Action= CAIEventActionNode::popFromPdr(pdr);
171 pdr.popStructEnd(token);
172 continue;
174 WARN("Unrecognised content found in pdr: "+tokenName);
175 if (pdr.isStartOfStruct())
176 pdr.skipStruct();
177 else
178 pdr.skipData();
180 return result;
186 #endif