Add infos into target window
[ryzomcore.git] / ryzom / server / src / ai_share / ai_event.h
blobbe567b8f225e6c7daf5f89c70aa7c755477130b4
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 RY_AI_EVENT_H
21 #define RY_AI_EVENT_H
23 #include <string>
25 #include "nel/misc/stream.h"
26 #include "nel/misc/entity_id.h"
28 //------------------------------MESSAGES DESCRIPTION---------------------------------
29 // STUN
30 // CEntityId CreatureId
31 // STUN_END
32 // CEntityId CreatureId
33 // AGGRO
34 // CEntityId CreatureId
35 // CEntityId EntityId
36 // sint32 Modifier
37 // SURVIE
38 // CEntityId CreatureId
39 // CEntityId EntityId
40 // sint32 Modifier
41 // FEAR
42 // CEntityId CreatureId
43 // CEntityId EntityId
44 // FEAR_END
45 // CEntityId CreatureId
46 // CEntityId EntityId
47 //-----------------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------------
51 // class CAIEventType
52 //-----------------------------------------------------------------------------------
53 // this class encapsulates the class id for classes derived from IAIEvent
54 // for now class names are limitted to 8 characters - if need be this can be
55 // extended at a later date but will require services to synchronise event id
56 // tables at startup
58 class CAIEventType
60 public:
61 CAIEventType()
62 { _val = (uint64)0;}
64 CAIEventType(const CAIEventType &other)
66 *this=other;
69 CAIEventType(const char *typeName)
71 // copy text from input string to _val variable
72 uint i;
73 for (i=0;i<8 && typeName[i];++i)
74 ((char *)&_val)[i]=typeName[i];
76 // if type name is longer than 8 characters it won't fit in an int64!
77 nlassert(typeName[i]==0);
79 // pad out _val variable with 0s
80 while(i<8)
81 ((char *)&_val)[i++]=0;
83 CAIEventType(const std::string &typeName)
85 *this=CAIEventType(typeName.c_str());
88 const CAIEventType &operator=(const CAIEventType &other)
90 _val=other._val;
91 return *this;
93 bool operator==(const CAIEventType &other) const
95 return _val==other._val;
97 bool operator!=(const CAIEventType &other) const
99 return _val!=other._val;
101 bool operator<=(const CAIEventType &other) const
103 return _val<=other._val;
105 bool operator>=(const CAIEventType &other) const
107 return _val>=other._val;
109 bool operator<(const CAIEventType &other) const
111 return _val<other._val;
113 bool operator>(const CAIEventType &other) const
115 return _val>other._val;
118 void serial(NLMISC::IStream &f)
120 f.serial(_val);
123 std::string toString() const
125 return NLMISC::toString("%8.8s",&_val);
128 private:
129 uint64 _val;
133 //-----------------------------------------------------------------------------------
134 // base class IAIEvent
135 //-----------------------------------------------------------------------------------
136 // This is the base class for classes of event sent from the game dev services to
137 // the AI. Note that the serial has a special syntax to allow for skipping of
138 // unrecognised events.
140 class IAIEvent
142 NL_INSTANCE_COUNTER_DECL(IAIEvent);
143 public:
145 virtual ~IAIEvent() {}
147 // this is the name of the class
148 // for now it is limited to 8 letters - wil be extended at a later date if need be
149 virtual const CAIEventType &type() const = 0;
151 // serial()
152 // note serial should serialise: <Type> <uint16 sizeof(EventClass)> <event_parameters>
153 // the 'read' version of the serial should test the <sizeof> to ensure version robustness
154 virtual void serial(NLMISC::IStream &f) = 0;
159 * CAIStunEvent : event STUN
160 * \author Fleury David
161 * \author Nevrax France
162 * \date 2003
164 class CAIStunEvent: public IAIEvent
166 NL_INSTANCE_COUNTER_DECL(CAIStunEvent);
167 public:
169 // this is the name of the class
170 // for now it is limited to 8 letters - will be extended at a later date if need be
171 virtual const CAIEventType &type() const { static CAIEventType type("STUN"); return type; }
173 // serial()
174 // note serial should serialise: <Type> <uint16 sizeof(EventClass)> <event_parameters>
175 // the 'read' version of the serial should test the <sizeof> to ensure version robustness
176 virtual void serial(NLMISC::IStream &f);
178 public:
179 /// the stunned creature id
180 NLMISC::CEntityId CreatureId;
185 * CAIStunEndEvent : event STUN_END
186 * \author Fleury David
187 * \author Nevrax France
188 * \date 2003
190 class CAIStunEndEvent: public IAIEvent
192 NL_INSTANCE_COUNTER_DECL(CAIStunEndEvent);
193 public:
195 // this is the name of the class
196 // for now it is limited to 8 letters - will be extended at a later date if need be
197 virtual const CAIEventType &type() const { static CAIEventType type("STUN_END"); return type; }
199 // serial()
200 // note serial should serialise: <Type> <uint16 sizeof(EventClass)> <event_parameters>
201 // the 'read' version of the serial should test the <sizeof> to ensure version robustness
202 virtual void serial(NLMISC::IStream &f);
204 public:
205 /// the waked creature id
206 NLMISC::CEntityId CreatureId;
212 * CAIAggroEvent : event AGGRO
213 * \author Fleury David
214 * \author Nevrax France
215 * \date 2003
217 class CAIAggroEvent: public IAIEvent
219 public:
220 CAIAggroEvent() : AggroModifier(0)
223 // this is the name of the class
224 // for now it is limited to 8 letters - will be extended at a later date if need be
225 virtual const CAIEventType &type() const { static CAIEventType type("AGGRO"); return type; }
227 // serial()
228 // note serial should serialise: <Type> <uint16 sizeof(EventClass)> <event_parameters>
229 // the 'read' version of the serial should test the <sizeof> to ensure version robustness
230 virtual void serial(NLMISC::IStream &f);
232 public:
233 /// the creature Id
234 NLMISC::CEntityId CreatureId;
236 /// the entity Id affected by the aggro
237 NLMISC::CEntityId EntityId;
239 /// aggro modifier
240 sint32 AggroModifier;
247 * CAISurvivalInstinctEvent : event SURVIE
248 * \author Fleury David
249 * \author Nevrax France
250 * \date 2003
252 class CAISurvivalInstinctEvent: public IAIEvent
254 public:
255 // this is the name of the class
256 // for now it is limited to 8 letters - will be extended at a later date if need be
257 virtual const CAIEventType &type() const { static CAIEventType type("SURVIE"); return type; }
259 // serial()
260 // note serial should serialise: <Type> <uint16 sizeof(EventClass)> <event_parameters>
261 // the 'read' version of the serial should test the <sizeof> to ensure version robustness
262 virtual void serial(NLMISC::IStream &f);
264 public:
265 /// the affected creature id
266 NLMISC::CEntityId CreatureId;
268 /// the entity for which the creature survival instinct is modified
269 NLMISC::CEntityId EntityId;
271 /// the modifier
272 sint32 Modifier;
279 * CAIFearEvent : event FEAR
280 * \author Fleury David
281 * \author Nevrax France
282 * \date 2003
284 class CAIFearEvent: public IAIEvent
286 public:
287 // this is the name of the class
288 // for now it is limited to 8 letters - will be extended at a later date if need be
289 virtual const CAIEventType &type() const { static CAIEventType type("FEAR"); return type; }
291 // serial()
292 // note serial should serialise: <Type> <uint16 sizeof(EventClass)> <event_parameters>
293 // the 'read' version of the serial should test the <sizeof> to ensure version robustness
294 virtual void serial(NLMISC::IStream &f);
296 public:
297 /// the creature id
298 NLMISC::CEntityId CreatureId;
299 /// the entity feared by the creature
300 NLMISC::CEntityId EntityId;
305 * CAIFearEndEvent : event FEAR_END
306 * \author Fleury David
307 * \author Nevrax France
308 * \date 2003
310 class CAIFearEndEvent: public IAIEvent
312 public:
313 // this is the name of the class
314 // for now it is limited to 8 letters - will be extended at a later date if need be
315 virtual const CAIEventType &type() const { static CAIEventType type("FEAR_END"); return type; }
317 // serial()
318 // note serial should serialise: <Type> <uint16 sizeof(EventClass)> <event_parameters>
319 // the 'read' version of the serial should test the <sizeof> to ensure version robustness
320 virtual void serial(NLMISC::IStream &f);
322 public:
323 /// the creature id
324 NLMISC::CEntityId CreatureId;
325 /// the entity no longer feared by the creature
326 NLMISC::CEntityId EntityId;
330 * CAIHungerEvent : event HUNGER
331 * \author Fleury David
332 * \author Nevrax France
333 * \date 2003
335 class CAIHungerEvent: public IAIEvent
337 public:
338 // this is the name of the class
339 // for now it is limited to 8 letters - will be extended at a later date if need be
340 virtual const CAIEventType &type() const { static CAIEventType type("HUNGER"); return type; }
342 // serial()
343 // note serial should serialise: <Type> <uint16 sizeof(EventClass)> <event_parameters>
344 // the 'read' version of the serial should test the <sizeof> to ensure version robustness
345 virtual void serial(NLMISC::IStream &f);
347 public:
348 /// the affected creature id
349 NLMISC::CEntityId CreatureId;
351 /// the modifier
352 sint32 Modifier;
357 #endif