Planeshift
perceptions.h
Go to the documentation of this file.
1 /*
2 * perceptions.h
3 *
4 * Copyright (C) 2003 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5 *
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation (version 2 of the License)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 */
19 
20 #ifndef __PERCEPTIONS_H__
21 #define __PERCEPTIONS_H__
22 
23 //=============================================================================
24 // Crystal Space Includes
25 //=============================================================================
26 #include <csutil/weakref.h>
27 #include <csutil/array.h>
28 
29 //=============================================================================
30 // Library Includes
31 //=============================================================================
32 #include "util/psconst.h"
33 #include "net/npcmessages.h"
34 #include "gem.h"
35 
40 class Reaction;
41 class NPC;
42 class Location;
43 struct iSector;
44 
45 //-----------------------------------------------------------------------------
46 
56 {
57 protected:
58  csString name;
59 
60  csString type;
61 
62 public:
68  Perception(const char* name):name(name) {}
69 
76  Perception(const char* name, const char* type):name(name),type(type) {}
77 
81  virtual ~Perception() {}
82 
91  virtual bool ShouldReact(Reaction* reaction,NPC* npc);
92 
98  virtual Perception* MakeCopy();
99 
106  virtual void ExecutePerception(NPC* npc,float weight);
107 
116  {
117  return NULL;
118  }
119 
128  virtual const csString &GetName() const;
129 
135  const csString &GetType() const;
136 
142  void SetType(const char* type);
143 
155  virtual bool GetLocation(csVector3 &pos, iSector* &sector);
156 
160  virtual float GetRadius() const
161  {
162  return 0.0;
163  }
164 
168  virtual csString ToString(NPC* npc);
169 };
170 
171 //-----------------------------------------------------------------------------
172 
181 {
182 protected:
183  int gameHour,gameMinute,gameYear,gameMonth,gameDay;
184 
185 public:
186  TimePerception(int hour, int minute, int year, int month, int day)
187  : Perception("time"), gameHour(hour),gameMinute(minute),gameYear(year),gameMonth(month),gameDay(day) { }
188  virtual ~TimePerception() {}
189 
190  virtual bool ShouldReact(Reaction* reaction,NPC* npc);
191  virtual Perception* MakeCopy();
192  virtual csString ToString(NPC* npc);
193 
198  static void NormalizeReaction(Reaction* reaction);
199 };
200 
201 //-----------------------------------------------------------------------------
202 
209 {
210 protected:
212  csWeakRef<gemNPCActor> player;
213 
214 public:
215  FactionPerception(const char* n,int d,gemNPCObject* p)
216  : Perception(n), factionDelta(d), player((gemNPCActor*)p) { }
217  virtual ~FactionPerception() {}
218 
219  virtual bool ShouldReact(Reaction* reaction,NPC* npc);
220  virtual Perception* MakeCopy();
222  {
223  return player;
224  }
225  virtual void ExecutePerception(NPC* npc,float weight);
226 };
227 
228 //-----------------------------------------------------------------------------
229 
235 {
236 protected:
237  csWeakRef<gemNPCObject> item;
238 
239 public:
240  ItemPerception(const char* n,gemNPCObject* i)
241  : Perception(n), item(i) { }
242  virtual ~ItemPerception() {}
243 
244  virtual Perception* MakeCopy();
246  {
247  return item;
248  }
249 };
250 
251 //-----------------------------------------------------------------------------
252 
258 {
259 protected:
261 
262 public:
263  LocationPerception(const char* n, const char* type, Location* location, iEngine* engine)
264  : Perception(n,type), location(location), engine(engine) {}
265  virtual ~LocationPerception() {}
266 
267  virtual Perception* MakeCopy();
268  virtual bool GetLocation(csVector3 &pos, iSector* &sector);
269  virtual float GetRadius() const;
270 
271 private:
272  iEngine* engine;
273 };
274 
279 {
280 protected:
282  iSector* sector;
283  csVector3 pos;
284  float yrot;
285 
286  float radius;
287 
288 public:
289  PositionPerception(const char* n, const char* type,InstanceID &instance, iSector* sector, csVector3 &pos, float yrot, float radius)
290  : Perception(n,type), instance(instance), sector(sector), pos(pos), yrot(yrot), radius(radius) {}
291  virtual ~PositionPerception() {}
292 
293  virtual Perception* MakeCopy();
294  virtual bool GetLocation(csVector3 &pos, iSector* &sector);
295  virtual float GetRadius() const;
296 };
297 
298 //-----------------------------------------------------------------------------
299 
309 {
310 protected:
311  csWeakRef<gemNPCActor> attacker;
312 
313 public:
314  AttackPerception(const char* n,gemNPCObject* attack)
315  : Perception(n), attacker((gemNPCActor*) attack) { }
316 
317  virtual Perception* MakeCopy();
318  virtual void ExecutePerception(NPC* npc,float weight);
320  {
321  return attacker;
322  }
323 };
324 
325 //-----------------------------------------------------------------------------
326 
336 {
337 protected:
338  csWeakRef<gemNPCObject> attacker;
339  csArray<gemNPCObject*> attacker_ents;
340  csArray<int> bestSkillSlots;
341 
342 public:
343  GroupAttackPerception(const char* n,csArray<gemNPCObject*> &ents, csArray<int> &slots)
344  : Perception(n), attacker_ents(ents), bestSkillSlots(slots) { }
345 
346  virtual Perception* MakeCopy();
347  virtual void ExecutePerception(NPC* npc,float weight);
348 };
349 
350 //-----------------------------------------------------------------------------
351 
359 {
360 protected:
361  csWeakRef<gemNPCActor> attacker;
362  float damage;
363 
364 public:
365  DamagePerception(const char* n,gemNPCObject* attack,float dmg)
366  : Perception(n), attacker((gemNPCActor*)attack), damage(dmg) { }
367 
368  virtual Perception* MakeCopy();
369  virtual void ExecutePerception(NPC* npc,float weight);
371  {
372  return attacker;
373  }
374 };
375 
376 //-----------------------------------------------------------------------------
377 
389 {
390 protected:
391  csWeakRef<gemNPCActor> caster;
392  csWeakRef<gemNPCActor> target;
394 
395 public:
396  SpellPerception(const char* name,gemNPCObject* caster,gemNPCObject* target, const char* spell_type, float severity);
397 
398  virtual bool ShouldReact(Reaction* reaction,NPC* npc);
399  virtual Perception* MakeCopy();
401  {
402  return caster;
403  }
404  virtual void ExecutePerception(NPC* npc,float weight);
405 };
406 
407 //-----------------------------------------------------------------------------
408 
418 {
419 protected:
420  EID who;
421 
422 public:
423  DeathPerception(EID ent_id)
424  : Perception("death"), who(ent_id) { }
425 
426  virtual Perception* MakeCopy();
427  virtual void ExecutePerception(NPC* npc,float weight);
428 };
429 
430 //-----------------------------------------------------------------------------
431 
436 {
437 protected:
438  csVector3 pos;
439  iSector* sector;
440  float radius;
441  int count;
442 
443 public:
444  InventoryPerception(const char* n,const char* t,const int c, const csVector3 &p, iSector* s, float r)
445  : Perception(n), pos(p), radius(r), count(c)
446  {
447  type = t;
448  sector = s;
449  }
450 
451  virtual Perception* MakeCopy();
452  virtual bool GetLocation(csVector3 &pos, iSector* &sector)
453  {
454  pos = this->pos;
455  sector = this->sector;
456  return true;
457  }
458 
459  virtual float GetRadius() const
460  {
461  return radius;
462  }
463  virtual int GetCount() const
464  {
465  return count;
466  }
467 
468 };
469 
472 //-----------------------------------------------------------------------------
473 
485 {
486 protected:
488  csWeakRef<gemNPCObject> owner;
489  csWeakRef<gemNPCObject> pet;
490  csWeakRef<gemNPCActor> target;
491 
492 public:
493  OwnerCmdPerception(const char* n, psPETCommandMessage::PetCommand_t command, gemNPCObject* owner, gemNPCObject* pet, gemNPCObject* target);
494 
495  virtual bool ShouldReact(Reaction* reaction, NPC* pet);
496  virtual Perception* MakeCopy();
497  virtual void ExecutePerception(NPC* pet, float weight);
499  {
500  return target;
501  }
502  static csString BuildName(psPETCommandMessage::PetCommand_t command);
503 };
504 
505 //-----------------------------------------------------------------------------
506 
514 {
515 protected:
516  int action;
517  csWeakRef<gemNPCObject> owner;
518  csWeakRef<gemNPCObject> pet;
519 
520 public:
521  OwnerActionPerception(const char* n, int action, gemNPCObject* owner, gemNPCObject* pet);
522 
523  virtual bool ShouldReact(Reaction* reaction, NPC* pet);
524  virtual Perception* MakeCopy();
525  virtual void ExecutePerception(NPC* pet, float weight);
526 };
527 
528 //-----------------------------------------------------------------------------
529 
537 {
538 protected:
539  NPC* self;
540 
541 public:
542  NPCCmdPerception(const char* command, NPC* self);
543 
544  virtual bool ShouldReact(Reaction* reaction, NPC* npc);
545  virtual Perception* MakeCopy();
546 };
547 
550 #endif
551 
csString type
Type used by perceptions. Usally they correspond to the same value in a reaction. ...
Definition: perceptions.h:60
Whenever an NPC is close to an item, this perception is passed to the npc.
Definition: perceptions.h:234
uint32 InstanceID
Definition: psconst.h:64
This embodies any perception an NPC might have, or any game event of interest.
Definition: perceptions.h:55
csWeakRef< gemNPCObject > pet
Definition: perceptions.h:518
InventoryPerception(const char *n, const char *t, const int c, const csVector3 &p, iSector *s, float r)
Definition: perceptions.h:444
virtual ~ItemPerception()
Definition: perceptions.h:242
csString name
The name of this perception.
Definition: perceptions.h:58
virtual float GetRadius() const
Get the radius of the perception.
Definition: perceptions.h:160
virtual gemNPCObject * GetTarget()
Some perception has a target/source.
Definition: perceptions.h:221
csWeakRef< gemNPCActor > player
Definition: perceptions.h:212
csArray< gemNPCObject * > attacker_ents
Definition: perceptions.h:339
csWeakRef< gemNPCActor > caster
Definition: perceptions.h:391
Given to the NPC upon ever tick of game minute.
Definition: perceptions.h:180
Whenever an NPC is attacked by a grouop, this perception is passed to the attacked npc...
Definition: perceptions.h:335
PositionPerception(const char *n, const char *type, InstanceID &instance, iSector *sector, csVector3 &pos, float yrot, float radius)
Definition: perceptions.h:289
InstanceID instance
Definition: perceptions.h:281
float spell_severity
Definition: perceptions.h:393
csWeakRef< gemNPCActor > target
Definition: perceptions.h:392
The network layer is notified of any deaths from players or NPCs on the server.
Definition: perceptions.h:417
DamagePerception(const char *n, gemNPCObject *attack, float dmg)
Definition: perceptions.h:365
This perception is used when a item is added or removed from inventory.
Definition: perceptions.h:435
virtual gemNPCObject * GetTarget()
Some perception has a target/source.
Definition: perceptions.h:245
AttackPerception(const char *n, gemNPCObject *attack)
Definition: perceptions.h:314
GroupAttackPerception(const char *n, csArray< gemNPCObject * > &ents, csArray< int > &slots)
Definition: perceptions.h:343
virtual gemNPCObject * GetTarget()
Some perception has a target/source.
Definition: perceptions.h:319
virtual ~TimePerception()
Definition: perceptions.h:188
Whenever an NPCPet is told by it&#39;s owner to stay, this perception is passed to the NPCPet...
Definition: perceptions.h:484
FactionPerception(const char *n, int d, gemNPCObject *p)
Definition: perceptions.h:215
virtual ~Perception()
Destructor.
Definition: perceptions.h:81
virtual ~PositionPerception()
Definition: perceptions.h:291
csWeakRef< gemNPCObject > item
Definition: perceptions.h:237
Perception(const char *name)
Constructor.
Definition: perceptions.h:68
Whenever an NPC is close to an location, this perception is passed to the npc.
Definition: perceptions.h:257
Deliver a faction based perception.
Definition: perceptions.h:208
csWeakRef< gemNPCObject > owner
Definition: perceptions.h:488
csWeakRef< gemNPCObject > owner
Definition: perceptions.h:517
virtual ~FactionPerception()
Definition: perceptions.h:217
virtual int GetCount() const
Definition: perceptions.h:463
Whenever an NPC is attacked by a player, this perception is passed to the attacked npc...
Definition: perceptions.h:308
virtual csString ToString(NPC *npc)
Get a text description of the perception.
csWeakRef< gemNPCActor > attacker
Definition: perceptions.h:311
const csString & GetType() const
Get the type of the perception.
virtual gemNPCObject * GetTarget()
Some perception has a target/source.
Definition: perceptions.h:370
A reaction embodies the change in desire which occurs in an NPC when he perceives something...
Definition: reaction.h:51
virtual bool GetLocation(csVector3 &pos, iSector *&sector)
Get a location assosiated with the perception.
This object represents each NPC managed by this superclient.
Definition: npc.h:126
LocationPerception(const char *n, const char *type, Location *location, iEngine *engine)
Definition: perceptions.h:263
Whenever a player casts a spell on himself, another player, or any npc, this perception is passed to ...
Definition: perceptions.h:388
void SetType(const char *type)
Set the type of the perception.
virtual ~LocationPerception()
Definition: perceptions.h:265
virtual gemNPCObject * GetTarget()
Some perception has a target/source.
Definition: perceptions.h:400
virtual float GetRadius() const
Get the radius of the perception.
Definition: perceptions.h:459
TimePerception(int hour, int minute, int year, int month, int day)
Definition: perceptions.h:186
virtual void ExecutePerception(NPC *npc, float weight)
All preconditions has been checked, now excecute the perception.
csWeakRef< gemNPCObject > pet
Definition: perceptions.h:489
virtual bool GetLocation(csVector3 &pos, iSector *&sector)
Get a location assosiated with the perception.
Definition: perceptions.h:452
ItemPerception(const char *n, gemNPCObject *i)
Definition: perceptions.h:240
virtual gemNPCObject * GetTarget()
Some perception has a target/source.
Definition: perceptions.h:115
csWeakRef< gemNPCObject > attacker
Definition: perceptions.h:338
csWeakRef< gemNPCActor > attacker
Definition: perceptions.h:361
Perception(const char *name, const char *type)
Constructor.
Definition: perceptions.h:76
Percept a position.
Definition: perceptions.h:278
Whenever an NPC Cmd is received this perception is fired.
Definition: perceptions.h:536
virtual Perception * MakeCopy()
Make a copy of this perception.
DeathPerception(EID ent_id)
Definition: perceptions.h:423
Whenever an NPC is hit for damage by a melee hit or a spell, this perception is passed to the damaged...
Definition: perceptions.h:358
A Location is a named place on the map, located dynamically by NPCs as scripted.
Definition: location.h:48
csArray< int > bestSkillSlots
Definition: perceptions.h:340
psPETCommandMessage::PetCommand_t command
Definition: perceptions.h:487
virtual const csString & GetName() const
Get the name of the perception.
csWeakRef< gemNPCActor > target
Definition: perceptions.h:490
virtual gemNPCObject * GetTarget()
Some perception has a target/source.
Definition: perceptions.h:498
Whenever an NPCPet is told by it&#39;s owner to stay, this perception is passed to the NPCPet...
Definition: perceptions.h:513
virtual bool ShouldReact(Reaction *reaction, NPC *npc)
Check if this perception should react to a reaction.
Location * location
Definition: perceptions.h:260