Planeshift

entitymanager.h

Go to the documentation of this file.
00001 /*
00002  * entitymanager.h
00003  *
00004  * Copyright (C) 2002 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 #ifndef __EntityManager_H__
00020 #define __EntityManager_H__
00021 //=============================================================================
00022 // Crystal Space Includes
00023 //=============================================================================
00024 #include <csgeom/vector3.h>
00025 
00026 //=============================================================================
00027 // Project Includes
00028 //=============================================================================
00029 #include "util/gameevent.h"
00030 #include "util/psconst.h"
00031 #include "util/singleton.h"
00032 
00033 //=============================================================================
00034 // Local Includes
00035 //=============================================================================
00036 #include "msgmanager.h"
00037 
00038 struct iSector;
00039 struct iEngine;
00040 
00041 class ClientConnectionSet;
00042 class psServerDR;
00043 class psDatabase;
00044 class psWorld;
00045 class psItem;
00046 class GEMSupervisor;
00047 class UserManager;
00048 class gemItem;
00049 class gemNPC;
00050 class gemActor;
00051 class psActionLocation;
00052 class psCharacter;
00053 class psSectorInfo;
00054 class psMovementInfoMessage;
00055 
00056 
00057 struct psAffinityAttribute
00058 {
00059 public:
00060     csString Attribute;
00061     csString Category;
00062 };
00063 
00064 struct psFamiliarType
00065 {
00066 public:
00067     PID Id;
00068     csString Name;
00069     csString Type;
00070     csString Lifecycle;
00071     csString AttackTool;
00072     csString AttackType;
00073     csString MagicalAffinity;
00074 };
00075 
00077 class EntityManager : public MessageManager<EntityManager>, public Singleton<EntityManager>
00078 {
00079 public:
00080     EntityManager();
00081     virtual ~EntityManager();
00082 
00083     bool Initialize(iObjectRegistry* object_reg,
00084                     ClientConnectionSet* clients,
00085                     UserManager* usermanager,
00086                     GEMSupervisor* gemsupervisor,
00087                     psServerDR* psserverdr,
00088                     CacheManager* cachemanager);
00089 
00090     void HandleUserAction(MsgEntry* me, Client* client);
00091     void HandleWorld(MsgEntry* me, Client* client);
00092     void HandleActor(MsgEntry* me, Client* client);
00093     void HandleAllRequest(MsgEntry* me, Client* client);
00094     void SendMovementInfo(MsgEntry* me, Client* client);
00095 
00096     bool LoadMap(const char* mapname);
00097 
00098     iSector* FindSector(const char* name);
00099 
00100     bool CreatePlayer(Client* client);
00101     bool DeletePlayer(Client* client);
00102 
00103     PID CopyNPCFromDatabase(PID master_id, float x, float y, float z, float angle, const csString &sector, InstanceID instance, const char* firstName = NULL, const char* lastName = NULL);
00104     EID CreateNPC(PID npcID, bool updateProxList = true, bool alwaysWatching = false);
00105     EID CreateNPC(psCharacter* chardata, bool updateProxList = true, bool alwaysWatching = false);
00106     EID CreateNPC(psCharacter* chardata, InstanceID instance, csVector3 pos, iSector* sector, float yrot, bool updateProxList = true, bool alwaysWatching = false);
00107 
00110     gemNPC* CreateFamiliar(gemActor* owner, PID masterPID);
00111     
00114     gemNPC* CreateHiredNPC(gemActor* owner, PID masterPID, const csString& name);
00115     
00119     gemNPC* CloneNPC(psCharacter* chardata);
00120 
00121     bool CreateActionLocation(psActionLocation* instance, bool transient);
00122 
00123     gemItem* CreateItem(psItem* iteminstance, bool transient, int tribeID = 0);
00124     gemItem* MoveItemToWorld(psItem*       keyItem,
00125                              InstanceID  instance,
00126                              psSectorInfo* sectorinfo,
00127                              float         loc_x,
00128                              float         loc_y,
00129                              float         loc_z,
00130                              float         loc_xrot,
00131                              float         loc_yrot,
00132                              float         loc_zrot,
00133                              psCharacter*  owner,
00134                              bool          transient);
00135 
00136     bool RemoveActor(gemObject* actor);
00137 
00144     bool DeleteActor(gemObject* actor);
00145 
00146     bool AddRideRelation(gemActor* rider, gemActor* mount);
00147     void RemoveRideRelation(gemActor* rider);
00148 
00149     void SetReady(bool flag);
00150     bool IsReady()
00151     {
00152         return ready;
00153     }
00154     bool HasBeenReady()
00155     {
00156         return hasBeenReady;
00157     }
00158     GEMSupervisor* GetGEM()
00159     {
00160         return gem;
00161     }
00162     iEngine* GetEngine()
00163     {
00164         return engine;
00165     }
00166 
00167     ClientConnectionSet* GetClients()
00168     {
00169         return clients;
00170     };
00171     psWorld* GetWorld()
00172     {
00173         return gameWorld;
00174     }
00175 
00176 protected:
00177     csHash<psAffinityAttribute*> affinityAttributeList;
00178     csHash<psFamiliarType*, PID> familiarTypeList;
00179 
00180     bool SendActorList(Client* client);
00181 
00182 
00183     void CreateMovementInfoMsg();
00184     void LoadFamiliarTypes();
00185     void LoadFamiliarAffinityAttributes();
00186     PID GetMasterFamiliarID(psCharacter* charData);
00187     int CalculateFamiliarAffinity(psCharacter* chardata, size_t type, size_t lifecycle, size_t attacktool, size_t attacktype);
00188 
00189 
00190     bool ready;
00191     bool hasBeenReady;
00192     psServerDR* serverdr;
00193     ClientConnectionSet* clients;
00194     psDatabase* database;
00195     UserManager* usermanager;
00196     CacheManager* cacheManager;
00197     GEMSupervisor* gem;
00198     iEngine* engine;
00199     psWorld* gameWorld;
00200 
00201     psMovementInfoMessage* moveinfomsg;
00202 };
00203 
00204 class psEntityEvent : public psGameEvent
00205 {
00206 public:
00207     enum EventType
00208     {
00209         DESTROY = 0
00210     };
00211 
00212     psEntityEvent(EntityManager* entitymanager, EventType type, gemObject* object) :
00213         psGameEvent(0, 0, "psEntityEvent"), type(type), object(object)
00214     {
00215         this->entitymanager = entitymanager;
00216     }
00217 
00218     virtual void Trigger()
00219     {
00220         switch(type)
00221         {
00222             case DESTROY:
00223             {
00224                 entitymanager->RemoveActor(object);
00225                 break;
00226             }
00227         }
00228     }
00229 
00230 private:
00231     EventType type;
00232     gemObject* object;
00233     EntityManager* entitymanager;
00234 };
00235 
00236 #endif
00237