Add infos into target window
[ryzomcore.git] / ryzom / server / src / ai_share / ai_event.cpp
blob1d509397a86bd9fbb6ff217075f80e253ae59dc2
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 #include "stdpch.h"
20 #include "ai_event.h"
22 using namespace std;
23 using namespace NLMISC;
25 NL_INSTANCE_COUNTER_IMPL(IAIEvent);
26 NL_INSTANCE_COUNTER_IMPL(CAIStunEvent);
27 NL_INSTANCE_COUNTER_IMPL(CAIStunEndEvent);
29 //------------------------------IMPORTANT----------------------------------
30 // The EventType isn't read in the serial as it is used in the read process
31 // to get the right event type (in the AI service)
32 //-------------------------------------------------------------------------
36 //--------------------------------------------------------------
37 // CAIStunEvent::serial()
38 //--------------------------------------------------------------
39 void CAIStunEvent::serial(NLMISC::IStream &f)
41 if (f.isReading() )
43 // CAIEventType type;
44 uint16 size;
45 // f.serial(type);
46 f.serial(size);
48 if (/*type != CAIEventType("STUN") || */size != sizeof(CAIStunEvent))
50 CreatureId = NLMISC::CEntityId();
51 try
53 // seek takes a param in bytes (8 bits)
54 f.seek( size, NLMISC::IStream::current);
56 catch(const ESeekNotSupported &)
58 uint8 tmp;
59 for (uint i = 0 ; i < size ; ++i)
60 f.serial(tmp);
63 else
65 f.serial(CreatureId);
68 else
70 CAIEventType type("STUN");
71 uint16 size = sizeof(CAIStunEvent);
73 f.serial(type);
74 f.serial(size);
75 f.serial(CreatureId);
77 } // CAIStunEvent::serial //
81 //--------------------------------------------------------------
82 // CAIAggroEvent::serial()
83 //--------------------------------------------------------------
84 void CAIAggroEvent::serial(NLMISC::IStream &f)
86 if (f.isReading() )
88 // CAIEventType type;
89 uint16 size;
90 // f.serial(type);
91 f.serial(size);
93 if (/*type != CAIEventType("AGGRO") || */size != sizeof(CAIAggroEvent))
95 CreatureId = NLMISC::CEntityId();
96 EntityId = NLMISC::CEntityId();
97 AggroModifier = 0;
98 try
100 // seek takes a param in bytes (8 bits)
101 f.seek( size, NLMISC::IStream::current);
103 catch(const ESeekNotSupported &)
105 uint8 tmp;
106 for (uint i = 0 ; i < size ; ++i)
107 f.serial(tmp);
110 else
112 f.serial(CreatureId);
113 f.serial(EntityId);
114 f.serial(AggroModifier);
117 else
119 CAIEventType type("AGGRO");
120 uint16 size = sizeof(CAIAggroEvent);
122 f.serial(type);
123 f.serial(size);
124 f.serial(CreatureId);
125 f.serial(EntityId);
126 f.serial(AggroModifier);
128 } // CAIAggroEvent::serial //
133 //--------------------------------------------------------------
134 // CAIStunEndEvent::serial()
135 //--------------------------------------------------------------
136 void CAIStunEndEvent::serial(NLMISC::IStream &f)
138 if (f.isReading() )
140 // CAIEventType type;
141 uint16 size;
142 // f.serial(type);
143 f.serial(size);
145 if (/*type != CAIEventType("STUN_END") ||*/ size != sizeof(CAIStunEndEvent))
147 CreatureId = NLMISC::CEntityId();
150 // seek takes a param in bytes (8 bits)
151 f.seek( size, NLMISC::IStream::current);
153 catch(const ESeekNotSupported &)
155 uint8 tmp;
156 for (uint i = 0 ; i < size ; ++i)
157 f.serial(tmp);
160 else
162 f.serial(CreatureId);
165 else
167 CAIEventType type("STUN_END");
168 uint16 size = sizeof(CAIStunEndEvent);
170 f.serial(type);
171 f.serial(size);
172 f.serial(CreatureId);
174 } // CAIStunEndEvent::serial //
179 //--------------------------------------------------------------
180 // CAISurvivalInstinctEvent::serial()
181 //--------------------------------------------------------------
182 void CAISurvivalInstinctEvent::serial(NLMISC::IStream &f)
184 if (f.isReading() )
186 // CAIEventType type;
187 uint16 size;
188 // f.serial(type);
189 f.serial(size);
191 if (/*type != CAIEventType("SURVIE") ||*/ size != sizeof(CAISurvivalInstinctEvent))
193 CreatureId = NLMISC::CEntityId();
194 EntityId = NLMISC::CEntityId();
195 Modifier = 0;
198 // seek takes a param in bytes (8 bits)
199 f.seek( size, NLMISC::IStream::current);
201 catch(const ESeekNotSupported &)
203 uint8 tmp;
204 for (uint i = 0 ; i < size ; ++i)
205 f.serial(tmp);
208 else
210 f.serial(CreatureId);
211 f.serial(EntityId);
212 f.serial(Modifier);
215 else
217 CAIEventType type("SURVIE");
218 uint16 size = sizeof(CAISurvivalInstinctEvent);
220 f.serial(type);
221 f.serial(size);
222 f.serial(CreatureId);
223 f.serial(EntityId);
224 f.serial(Modifier);
227 } // CAISurvivalInstinctEvent::serial //
231 //--------------------------------------------------------------
232 // CAIFearEvent::serial()
233 //--------------------------------------------------------------
234 void CAIFearEvent::serial(NLMISC::IStream &f)
236 if (f.isReading() )
238 // CAIEventType type;
239 uint16 size;
240 // f.serial(type);
241 f.serial(size);
243 if (/*type != CAIEventType("FEAR") ||*/ size != sizeof(CAIFearEvent))
245 CreatureId = NLMISC::CEntityId();
246 EntityId = NLMISC::CEntityId();
249 // seek takes a param in bytes (8 bits)
250 f.seek( size, NLMISC::IStream::current);
252 catch(const ESeekNotSupported &)
254 uint8 tmp;
255 for (uint i = 0 ; i < size ; ++i)
256 f.serial(tmp);
259 else
261 f.serial(CreatureId);
262 f.serial(EntityId);
265 else
267 CAIEventType type("FEAR");
268 uint16 size = sizeof(CAIFearEvent);
270 f.serial(type);
271 f.serial(size);
272 f.serial(CreatureId);
273 f.serial(EntityId);
275 } // CAIFearEvent::serial //
278 //--------------------------------------------------------------
279 // CAIFearEndEvent::serial()
280 //--------------------------------------------------------------
281 void CAIFearEndEvent::serial(NLMISC::IStream &f)
283 if (f.isReading() )
285 //CAIEventType type;
286 uint16 size;
287 //f.serial(type);
288 f.serial(size);
290 if (/*type != CAIEventType("FEAR_END") ||*/ size != sizeof(CAIFearEndEvent))
292 CreatureId = NLMISC::CEntityId();
293 EntityId = NLMISC::CEntityId();
296 // seek takes a param in bytes (8 bits)
297 f.seek( size, NLMISC::IStream::current);
299 catch(const ESeekNotSupported &)
301 uint8 tmp;
302 for (uint i = 0 ; i < size ; ++i)
303 f.serial(tmp);
306 else
308 f.serial(CreatureId);
309 f.serial(EntityId);
312 else
314 CAIEventType type("FEAR_END");
315 uint16 size = sizeof(CAIFearEndEvent);
317 f.serial(type);
318 f.serial(size);
319 f.serial(CreatureId);
320 f.serial(EntityId);
322 } // CAIFearEndEvent::serial //
326 //--------------------------------------------------------------
327 // CAIHungerEvent::serial()
328 //--------------------------------------------------------------
329 void CAIHungerEvent::serial(NLMISC::IStream &f)
331 if (f.isReading() )
333 //CAIEventType type;
334 uint16 size;
335 //f.serial(type);
336 f.serial(size);
338 if (/*type != CAIEventType("HUNGER") ||*/ size != sizeof(CAIHungerEvent))
340 CreatureId = NLMISC::CEntityId();
341 Modifier = 0;
344 // seek takes a param in bytes (8 bits)
345 f.seek( size, NLMISC::IStream::current);
347 catch(const ESeekNotSupported &)
349 uint8 tmp;
350 for (uint i = 0 ; i < size ; ++i)
351 f.serial(tmp);
354 else
356 f.serial(CreatureId);
357 f.serial(Modifier);
360 else
362 CAIEventType type("HUNGER");
363 uint16 size = sizeof(CAIHungerEvent);
365 f.serial(type);
366 f.serial(size);
367 f.serial(CreatureId);
368 f.serial(Modifier);
370 } // CAIHungerEvent::serial //