Planeshift

perceptions.h

Go to the documentation of this file.
00001 /*
00002 * perceptions.h
00003 *
00004 * Copyright (C) 2003 Atomic Blue ([email protected], http://www.atomicblue.org)
00005 *
00006 *
00007 * This program is free software; you can redistribute it and/or
00008 * modify it under the terms of the GNU General Public License
00009 * as published by the Free Software Foundation (version 2 of the License)
00010 * This program is distributed in the hope that it will be useful,
00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 * GNU General Public License for more details.
00014 * You should have received a copy of the GNU General Public License
00015 * along with this program; if not, write to the Free Software
00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 *
00018 */
00019 
00020 /* This file holds definitions for ALL global variables in the planeshift
00021 * server, normally you should move global variables into the psServer class
00022 */
00023 #ifndef __PERCEPTIONS_H__
00024 #define __PERCEPTIONS_H__
00025 
00026 //=============================================================================
00027 // Crystal Space Includes
00028 //=============================================================================
00029 #include <csutil/weakref.h>
00030 #include <csutil/array.h>
00031 
00032 //=============================================================================
00033 // Library Includes
00034 //=============================================================================
00035 #include "util/psconst.h"
00036 #include "net/npcmessages.h"
00037 #include "gem.h"
00038 
00043 class Reaction;
00044 class NPC;
00045 class Location;
00046 struct iSector;
00047 
00048 //-----------------------------------------------------------------------------
00049 
00058 class Perception
00059 {
00060 protected:
00061     csString name;       
00062 
00063     csString type;       
00064 
00065 public:
00071     Perception(const char* name):name(name) {}
00072 
00079     Perception(const char* name, const char* type):name(name),type(type) {}
00080 
00084     virtual ~Perception() {}
00085 
00094     virtual bool ShouldReact(Reaction* reaction,NPC* npc);
00095 
00101     virtual Perception* MakeCopy();
00102 
00109     virtual void ExecutePerception(NPC* npc,float weight);
00110 
00118     virtual gemNPCObject* GetTarget()
00119     {
00120         return NULL;
00121     }
00122 
00131     virtual const csString &GetName() const;
00132 
00138     const csString &GetType() const;
00139 
00145     void SetType(const char* type);
00146 
00158     virtual bool GetLocation(csVector3 &pos, iSector* &sector);
00159 
00163     virtual float GetRadius() const
00164     {
00165         return 0.0;
00166     }
00167 
00171     virtual csString ToString(NPC* npc);
00172 };
00173 
00174 //-----------------------------------------------------------------------------
00175 
00183 class TimePerception : public Perception
00184 {
00185 protected:
00186     int gameHour,gameMinute,gameYear,gameMonth,gameDay;
00187 
00188 public:
00189     TimePerception(int hour, int minute, int year, int month, int day)
00190         : Perception("time"), gameHour(hour),gameMinute(minute),gameYear(year),gameMonth(month),gameDay(day)  {    }
00191     virtual ~TimePerception() {}
00192 
00193     virtual bool ShouldReact(Reaction* reaction,NPC* npc);
00194     virtual Perception* MakeCopy();
00195     virtual csString ToString(NPC* npc);
00196 
00201     static void NormalizeReaction(Reaction* reaction);
00202 };
00203 
00204 //-----------------------------------------------------------------------------
00205 
00211 class FactionPerception : public Perception
00212 {
00213 protected:
00214     int factionDelta;
00215     csWeakRef<gemNPCActor> player;
00216 
00217 public:
00218     FactionPerception(const char* n,int d,gemNPCObject* p)
00219         : Perception(n), factionDelta(d), player((gemNPCActor*)p)  {    }
00220     virtual ~FactionPerception() {}
00221 
00222     virtual bool ShouldReact(Reaction* reaction,NPC* npc);
00223     virtual Perception* MakeCopy();
00224     virtual gemNPCObject* GetTarget()
00225     {
00226         return player;
00227     }
00228     virtual void ExecutePerception(NPC* npc,float weight);
00229 };
00230 
00231 //-----------------------------------------------------------------------------
00232 
00237 class ItemPerception : public Perception
00238 {
00239 protected:
00240     csWeakRef<gemNPCObject> item;
00241 
00242 public:
00243     ItemPerception(const char* n,gemNPCObject* i)
00244         : Perception(n), item(i)  {    }
00245     virtual ~ItemPerception() {}
00246 
00247     virtual Perception* MakeCopy();
00248     virtual gemNPCObject* GetTarget()
00249     {
00250         return item;
00251     }
00252 };
00253 
00254 //-----------------------------------------------------------------------------
00255 
00260 class LocationPerception : public Perception
00261 {
00262 protected:
00263     Location* location;
00264 
00265 public:
00266     LocationPerception(const char* n, const char* type, Location* location, iEngine* engine)
00267         : Perception(n,type), location(location), engine(engine)  {}
00268     virtual ~LocationPerception() {}
00269 
00270     virtual Perception* MakeCopy();
00271     virtual bool GetLocation(csVector3 &pos, iSector* &sector);
00272     virtual float GetRadius() const;
00273 
00274 private:
00275     iEngine* engine;
00276 };
00277 
00281 class PositionPerception : public Perception
00282 {
00283 protected:
00284     InstanceID instance;
00285     iSector* sector;
00286     csVector3 pos;
00287     float yrot;
00288 
00289     float radius;
00290 
00291 public:
00292     PositionPerception(const char* n, const char* type,InstanceID &instance, iSector* sector, csVector3 &pos, float yrot, float radius)
00293         : Perception(n,type), instance(instance), sector(sector), pos(pos), yrot(yrot), radius(radius)  {}
00294     virtual ~PositionPerception() {}
00295 
00296     virtual Perception* MakeCopy();
00297     virtual bool GetLocation(csVector3 &pos, iSector* &sector);
00298     virtual float GetRadius() const;
00299 };
00300 
00301 //-----------------------------------------------------------------------------
00302 
00311 class AttackPerception : public Perception
00312 {
00313 protected:
00314     csWeakRef<gemNPCActor> attacker;
00315 
00316 public:
00317     AttackPerception(const char* n,gemNPCObject* attack)
00318         : Perception(n), attacker((gemNPCActor*) attack) { }
00319 
00320     virtual Perception* MakeCopy();
00321     virtual void ExecutePerception(NPC* npc,float weight);
00322     virtual gemNPCObject* GetTarget()
00323     {
00324         return attacker;
00325     }
00326 };
00327 
00328 //-----------------------------------------------------------------------------
00329 
00338 class GroupAttackPerception : public Perception
00339 {
00340 protected:
00341     csWeakRef<gemNPCObject> attacker;
00342     csArray<gemNPCObject*> attacker_ents;
00343     csArray<int> bestSkillSlots;
00344 
00345 public:
00346     GroupAttackPerception(const char* n,csArray<gemNPCObject*> &ents, csArray<int> &slots)
00347         : Perception(n), attacker_ents(ents), bestSkillSlots(slots) { }
00348 
00349     virtual Perception* MakeCopy();
00350     virtual void ExecutePerception(NPC* npc,float weight);
00351 };
00352 
00353 //-----------------------------------------------------------------------------
00354 
00361 class DamagePerception : public Perception
00362 {
00363 protected:
00364     csWeakRef<gemNPCActor> attacker;
00365     float damage;
00366 
00367 public:
00368     DamagePerception(const char* n,gemNPCObject* attack,float dmg)
00369         : Perception(n), attacker((gemNPCActor*)attack), damage(dmg) { }
00370 
00371     virtual Perception* MakeCopy();
00372     virtual void ExecutePerception(NPC* npc,float weight);
00373     virtual gemNPCObject* GetTarget()
00374     {
00375         return attacker;
00376     }
00377 };
00378 
00379 //-----------------------------------------------------------------------------
00380 
00391 class SpellPerception : public Perception
00392 {
00393 protected:
00394     csWeakRef<gemNPCActor> caster;
00395     csWeakRef<gemNPCActor> target;
00396     float       spell_severity;
00397 
00398 public:
00399     SpellPerception(const char* name,gemNPCObject* caster,gemNPCObject* target, const char* spell_type, float severity);
00400 
00401     virtual bool ShouldReact(Reaction* reaction,NPC* npc);
00402     virtual Perception* MakeCopy();
00403     virtual gemNPCObject* GetTarget()
00404     {
00405         return caster;
00406     }
00407     virtual void ExecutePerception(NPC* npc,float weight);
00408 };
00409 
00410 //-----------------------------------------------------------------------------
00411 
00420 class DeathPerception : public Perception
00421 {
00422 protected:
00423     EID who;
00424 
00425 public:
00426     DeathPerception(EID ent_id)
00427         : Perception("death"), who(ent_id) { }
00428 
00429     virtual Perception* MakeCopy();
00430     virtual void ExecutePerception(NPC* npc,float weight);
00431 };
00432 
00433 //-----------------------------------------------------------------------------
00434 
00438 class InventoryPerception : public Perception
00439 {
00440 protected:
00441     csVector3 pos;
00442     iSector* sector;
00443     float     radius;
00444     int       count;
00445 
00446 public:
00447     InventoryPerception(const char* n,const char* t,const int c, const csVector3 &p, iSector* s, float r)
00448         : Perception(n), pos(p), radius(r), count(c)
00449     {
00450         type = t;
00451         sector = s;
00452     }
00453 
00454     virtual Perception* MakeCopy();
00455     virtual bool GetLocation(csVector3 &pos, iSector* &sector)
00456     {
00457         pos = this->pos;
00458         sector = this->sector;
00459         return true;
00460     }
00461 
00462     virtual float GetRadius() const
00463     {
00464         return radius;
00465     }
00466     virtual int GetCount() const
00467     {
00468         return count;
00469     }
00470 
00471 };
00472 
00475 //-----------------------------------------------------------------------------
00476 
00487 class OwnerCmdPerception : public Perception
00488 {
00489 protected:
00490     psPETCommandMessage::PetCommand_t command;
00491     csWeakRef<gemNPCObject> owner;
00492     csWeakRef<gemNPCObject> pet;
00493     csWeakRef<gemNPCActor> target;
00494 
00495 public:
00496     OwnerCmdPerception(const char* n, psPETCommandMessage::PetCommand_t command, gemNPCObject* owner, gemNPCObject* pet, gemNPCObject* target);
00497 
00498     virtual bool ShouldReact(Reaction* reaction, NPC* pet);
00499     virtual Perception* MakeCopy();
00500     virtual void ExecutePerception(NPC* pet, float weight);
00501     virtual gemNPCObject* GetTarget()
00502     {
00503         return target;
00504     }
00505     static csString BuildName(psPETCommandMessage::PetCommand_t command);
00506 };
00507 
00508 //-----------------------------------------------------------------------------
00509 
00516 class OwnerActionPerception : public Perception
00517 {
00518 protected:
00519     int action;
00520     csWeakRef<gemNPCObject> owner;
00521     csWeakRef<gemNPCObject> pet;
00522 
00523 public:
00524     OwnerActionPerception(const char* n, int action, gemNPCObject* owner, gemNPCObject* pet);
00525 
00526     virtual bool ShouldReact(Reaction* reaction, NPC* pet);
00527     virtual Perception* MakeCopy();
00528     virtual void ExecutePerception(NPC* pet, float weight);
00529 };
00530 
00531 //-----------------------------------------------------------------------------
00532 
00539 class NPCCmdPerception : public Perception
00540 {
00541 protected:
00542     NPC* self;
00543 
00544 public:
00545     NPCCmdPerception(const char* command, NPC* self);
00546 
00547     virtual bool ShouldReact(Reaction* reaction, NPC* npc);
00548     virtual Perception* MakeCopy();
00549 };
00550 
00553 #endif
00554