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/>.
25 #include "nel/misc/stream.h"
26 #include "nel/misc/entity_id.h"
28 //------------------------------MESSAGES DESCRIPTION---------------------------------
30 // CEntityId CreatureId
32 // CEntityId CreatureId
34 // CEntityId CreatureId
38 // CEntityId CreatureId
42 // CEntityId CreatureId
45 // CEntityId CreatureId
47 //-----------------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------------
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
64 CAIEventType(const CAIEventType
&other
)
69 CAIEventType(const char *typeName
)
71 // copy text from input string to _val variable
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
81 ((char *)&_val
)[i
++]=0;
83 CAIEventType(const std::string
&typeName
)
85 *this=CAIEventType(typeName
.c_str());
88 const CAIEventType
&operator=(const CAIEventType
&other
)
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
)
123 std::string
toString() const
125 return NLMISC::toString("%8.8s",&_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.
142 NL_INSTANCE_COUNTER_DECL(IAIEvent
);
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;
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
164 class CAIStunEvent
: public IAIEvent
166 NL_INSTANCE_COUNTER_DECL(CAIStunEvent
);
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
; }
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
);
179 /// the stunned creature id
180 NLMISC::CEntityId CreatureId
;
185 * CAIStunEndEvent : event STUN_END
186 * \author Fleury David
187 * \author Nevrax France
190 class CAIStunEndEvent
: public IAIEvent
192 NL_INSTANCE_COUNTER_DECL(CAIStunEndEvent
);
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
; }
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
);
205 /// the waked creature id
206 NLMISC::CEntityId CreatureId
;
212 * CAIAggroEvent : event AGGRO
213 * \author Fleury David
214 * \author Nevrax France
217 class CAIAggroEvent
: public IAIEvent
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
; }
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
);
234 NLMISC::CEntityId CreatureId
;
236 /// the entity Id affected by the aggro
237 NLMISC::CEntityId EntityId
;
240 sint32 AggroModifier
;
247 * CAISurvivalInstinctEvent : event SURVIE
248 * \author Fleury David
249 * \author Nevrax France
252 class CAISurvivalInstinctEvent
: public IAIEvent
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
; }
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
);
265 /// the affected creature id
266 NLMISC::CEntityId CreatureId
;
268 /// the entity for which the creature survival instinct is modified
269 NLMISC::CEntityId EntityId
;
279 * CAIFearEvent : event FEAR
280 * \author Fleury David
281 * \author Nevrax France
284 class CAIFearEvent
: public IAIEvent
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
; }
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
);
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
310 class CAIFearEndEvent
: public IAIEvent
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
; }
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
);
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
335 class CAIHungerEvent
: public IAIEvent
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
; }
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
);
348 /// the affected creature id
349 NLMISC::CEntityId CreatureId
;