Planeshift

gem.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * Copyright (C) 2003 Atomic Blue ([email protected], http://www.atomicblue.org)
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation (version 2 of the License)
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program; if not, write to the Free Software
00015  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00016  *
00017  */
00018 #ifndef PS_GEM_HEADER
00019 #define PS_GEM_HEADER
00020 
00021 //=============================================================================
00022 // Crystal Space Includes
00023 //=============================================================================
00024 #include <iengine/mesh.h>
00025 #include <csutil/csobject.h>
00026 
00027 //=============================================================================
00028 // Project Library Includes
00029 //=============================================================================
00030 #include "net/messages.h"
00031 
00032 //=============================================================================
00033 // Local Includes
00034 //=============================================================================
00035 #include "npcclient.h"
00036 #include "stat.h"
00037 
00042 class gemNPCActor;
00043 class gemNPCObject;
00044 class npcMesh;
00045 
00046 
00047 //-----------------------------------------------------------------------------
00048 
00051 class psNpcMeshAttach : public scfImplementationExt1<psNpcMeshAttach,
00052     csObject,
00053     scfFakeInterface<psNpcMeshAttach> >
00054 {
00055 public:
00056     SCF_INTERFACE(psNpcMeshAttach, 0, 0, 1);
00057 
00061     psNpcMeshAttach(gemNPCObject* object);
00062 
00065     gemNPCObject* GetObject()
00066     {
00067         return object;
00068     }
00069 
00070 private:
00071     gemNPCObject* object;          
00072 };
00073 
00074 //-----------------------------------------------------------------------------
00075 
00076 
00077 
00078 class gemNPCObject : public CS::Utility::WeakReferenced
00079 {
00080 public:
00081     gemNPCObject(psNPCClient* npcclient, EID id);
00082     virtual ~gemNPCObject();
00083 
00084     bool InitMesh(const char* factname,const char* filename,
00085                   const csVector3 &pos,const float rotangle, const char* sector);
00086     static void FiniMesh();
00087 
00088     iMeshWrapper* GetMeshWrapper();
00089     void Move(const csVector3 &pos, float rotangle, const char* room);
00090     void Move(const csVector3 &pos, float rotangle, const char* room, InstanceID instance);
00091 
00092     EID GetEID()
00093     {
00094         return eid;
00095     }
00096 
00097     int GetType()
00098     {
00099         return type;
00100     }
00101 
00102     const char* GetName()
00103     {
00104         return name.GetDataSafe();
00105     }
00106     virtual PID GetPID()
00107     {
00108         return PID(0);
00109     }
00110 
00111     virtual const char* GetObjectType()
00112     {
00113         return "Object";
00114     }
00115     virtual gemNPCActor* GetActorPtr()
00116     {
00117         return NULL;
00118     }
00119 
00120     virtual bool IsPickable()
00121     {
00122         return false;
00123     }
00124     virtual bool IsVisible()
00125     {
00126         return visible;
00127     }
00128     virtual bool IsInvisible()
00129     {
00130         return !visible;
00131     }
00132     virtual void SetVisible(bool vis)
00133     {
00134         visible = vis;
00135     }
00136     virtual void SetInvisible(bool invis)
00137     {
00138         SetVisible(!invis);
00139     }
00140 
00141     virtual bool IsInvincible()
00142     {
00143         return invincible;
00144     }
00145     virtual void SetInvincible(bool inv)
00146     {
00147         invincible = inv;
00148     }
00149 
00150     virtual bool IsAlive()
00151     {
00152         return isAlive;
00153     }
00154     virtual void SetAlive(bool alive);
00155 
00156     virtual NPC* GetNPC()
00157     {
00158         return NULL;
00159     }
00160 
00161     virtual void SetPosition(csVector3 &pos, iSector* sector = NULL, InstanceID* instance = NULL);
00162     virtual void SetInstance(InstanceID instance)
00163     {
00164         this->instance = instance;
00165     }
00166     virtual InstanceID GetInstance()
00167     {
00168         return instance;
00169     };
00170 
00171     npcMesh* pcmesh;
00172 
00173 protected:
00174     static csRef<iMeshFactoryWrapper> nullfact;
00175 
00176     csString name;
00177     EID  eid;
00178     int  type;
00179     bool visible;
00180     bool invincible;
00181     bool isAlive;
00182     float scale;
00183     float baseScale;
00184 
00185     InstanceID  instance;
00186 
00187     csRef<iThreadReturn> factory;
00188 };
00189 
00190 
00191 class gemNPCActor : public gemNPCObject, public iScriptableVar
00192 {
00193 public:
00194 
00195     gemNPCActor(psNPCClient* npcclient, psPersistActor &mesg);
00196     virtual ~gemNPCActor();
00197 
00198     psLinearMovement* pcmove;
00199 
00200     virtual PID GetPID()
00201     {
00202         return playerID;
00203     }
00204     virtual EID GetOwnerEID()
00205     {
00206         return ownerEID;
00207     }
00208 
00209     csString &GetRace()
00210     {
00211         return race;
00212     };
00213 
00214     virtual const char* GetObjectType()
00215     {
00216         return "Actor";
00217     }
00218     virtual gemNPCActor* GetActorPtr()
00219     {
00220         return this;
00221     }
00222 
00223     virtual void AttachNPC(NPC* newNPC);
00224     virtual NPC* GetNPC()
00225     {
00226         return npc;
00227     }
00228 
00229 
00233     void SetHP(float hp);
00234 
00238     float GetHP();
00239 
00243     void SetMaxHP(float maxHP);
00244 
00248     float GetMaxHP() const;
00249 
00253     void SetHPRate(float hpRate);
00254 
00258     float GetHPRate() const;
00259 
00263     void SetMana(float mana);
00264 
00268     float GetMana();
00269 
00273     void SetMaxMana(float maxMana);
00274 
00278     float GetMaxMana() const;
00279 
00283     void SetManaRate(float manaRate);
00284 
00288     float GetManaRate() const;
00289 
00293     void SetPysStamina(float pysStamina);
00294 
00298     float GetPysStamina();
00299 
00303     void SetMaxPysStamina(float maxPysStamina);
00304 
00308     float GetMaxPysStamina() const;
00309 
00313     void SetPysStaminaRate(float pysStaminaRate);
00314 
00318     float GetPysStaminaRate() const;
00319 
00323     void SetMenStamina(float menStamina);
00324 
00328     float GetMenStamina();
00329 
00333     void SetMaxMenStamina(float maxMenStamina);
00334 
00338     float GetMaxMenStamina() const;
00339 
00343     void SetMenStaminaRate(float menStaminaRate);
00344 
00348     float GetMenStaminaRate() const;
00349 
00353     virtual bool SetWithinTribe(Tribe* tribe,Tribe** oldTribe = NULL);
00354 
00355 private:
00359 
00360     virtual double GetProperty(MathEnvironment* env, const char* ptr);
00361     virtual double CalcFunction(MathEnvironment* env, const char* functionName, const double* params);
00362     virtual const char* ToString();
00364 
00365 protected:
00366 
00367     bool InitLinMove(const csVector3 &pos,float angle, const char* sector,
00368                      csVector3 top, csVector3 bottom, csVector3 offset);
00369 
00370     bool InitCharData(const char* textures, const char* equipment);
00371 
00372     PID playerID;
00373     EID ownerEID;
00374     csString race;
00375 
00376     NPC* npc;
00377 
00378     Tribe* withinTribe; 
00379 
00380     // Stats
00381     Stat               hp;
00382     Stat               mana;
00383     Stat               pysStamina;
00384     Stat               menStamina;
00385 };
00386 
00387 
00388 class gemNPCItem : public gemNPCObject
00389 {
00390 public:
00391     enum Flags
00392     {
00393         NONE           = 0,
00394         NOPICKUP       = 1 << 0
00395     };
00396 
00397     gemNPCItem(psNPCClient* npcclient, psPersistItem &mesg);
00398     virtual ~gemNPCItem();
00399 
00400     virtual const char* GetObjectType()
00401     {
00402         return "Item";
00403     }
00404 
00405     virtual bool IsPickable();
00406 
00407     uint32_t GetUID() const;
00408     uint32_t GetTribeID() const;
00409 
00410 protected:
00411     uint32_t uid;
00412     uint32_t tribeID;
00413     int flags;
00414 };
00415 
00418 #endif