Planeshift
entitymanager.h
Go to the documentation of this file.
1 /*
2  * entitymanager.h
3  *
4  * Copyright (C) 2002 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 #ifndef __EntityManager_H__
20 #define __EntityManager_H__
21 //=============================================================================
22 // Crystal Space Includes
23 //=============================================================================
24 #include <csgeom/vector3.h>
25 
26 //=============================================================================
27 // Project Includes
28 //=============================================================================
29 #include "util/gameevent.h"
30 #include "util/psconst.h"
31 #include "util/singleton.h"
32 
33 //=============================================================================
34 // Local Includes
35 //=============================================================================
36 #include "msgmanager.h"
37 
38 struct iSector;
39 struct iEngine;
40 
42 class psServerDR;
43 class psDatabase;
44 class psWorld;
45 class psItem;
46 class GEMSupervisor;
47 class UserManager;
48 class gemItem;
49 class gemNPC;
50 class gemActor;
51 class psActionLocation;
52 class psCharacter;
53 class psSectorInfo;
55 
56 
58 {
59 public:
60  csString Attribute;
61  csString Category;
62 };
63 
65 {
66 public:
67  PID Id;
68  csString Name;
69  csString Type;
70  csString Lifecycle;
71  csString AttackTool;
72  csString AttackType;
73  csString MagicalAffinity;
74 };
75 
77 class EntityManager : public MessageManager<EntityManager>, public Singleton<EntityManager>
78 {
79 public:
80  EntityManager();
81  virtual ~EntityManager();
82 
83  bool Initialize(iObjectRegistry* object_reg,
84  ClientConnectionSet* clients,
85  UserManager* usermanager,
86  GEMSupervisor* gemsupervisor,
87  psServerDR* psserverdr,
88  CacheManager* cachemanager);
89 
90  void HandleUserAction(MsgEntry* me, Client* client);
91  void HandleWorld(MsgEntry* me, Client* client);
92  void HandleActor(MsgEntry* me, Client* client);
93  void HandleAllRequest(MsgEntry* me, Client* client);
94  void SendMovementInfo(MsgEntry* me, Client* client);
95 
96  bool LoadMap(const char* mapname);
97 
98  iSector* FindSector(const char* name);
99 
100  bool CreatePlayer(Client* client);
101  bool DeletePlayer(Client* client);
102 
103  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);
104  EID CreateNPC(PID npcID, bool updateProxList = true, bool alwaysWatching = false);
105  EID CreateNPC(psCharacter* chardata, bool updateProxList = true, bool alwaysWatching = false);
106  EID CreateNPC(psCharacter* chardata, InstanceID instance, csVector3 pos, iSector* sector, float yrot, bool updateProxList = true, bool alwaysWatching = false);
107 
110  gemNPC* CreateFamiliar(gemActor* owner, PID masterPID);
111 
114  gemNPC* CreateHiredNPC(gemActor* owner, PID masterPID, const csString& name);
115 
119  gemNPC* CloneNPC(psCharacter* chardata);
120 
121  bool CreateActionLocation(psActionLocation* instance, bool transient);
122 
123  gemItem* CreateItem(psItem* iteminstance, bool transient, int tribeID = 0);
124  gemItem* MoveItemToWorld(psItem* keyItem,
125  InstanceID instance,
126  psSectorInfo* sectorinfo,
127  float loc_x,
128  float loc_y,
129  float loc_z,
130  float loc_xrot,
131  float loc_yrot,
132  float loc_zrot,
133  psCharacter* owner,
134  bool transient);
135 
136  bool RemoveActor(gemObject* actor);
137 
144  bool DeleteActor(gemObject* actor);
145 
146  bool AddRideRelation(gemActor* rider, gemActor* mount);
147  void RemoveRideRelation(gemActor* rider);
148 
149  void SetReady(bool flag);
150  bool IsReady()
151  {
152  return ready;
153  }
155  {
156  return hasBeenReady;
157  }
159  {
160  return gem;
161  }
162  iEngine* GetEngine()
163  {
164  return engine;
165  }
166 
168  {
169  return clients;
170  };
172  {
173  return gameWorld;
174  }
175 
176 protected:
177  csHash<psAffinityAttribute*> affinityAttributeList;
178  csHash<psFamiliarType*, PID> familiarTypeList;
179 
180  bool SendActorList(Client* client);
181 
182 
183  void CreateMovementInfoMsg();
184  void LoadFamiliarTypes();
185  void LoadFamiliarAffinityAttributes();
186  PID GetMasterFamiliarID(psCharacter* charData);
187  int CalculateFamiliarAffinity(psCharacter* chardata, size_t type, size_t lifecycle, size_t attacktool, size_t attacktype);
188 
189 
190  bool ready;
198  iEngine* engine;
200 
202 };
203 
205 {
206 public:
208  {
209  DESTROY = 0
210  };
211 
212  psEntityEvent(EntityManager* entitymanager, EventType type, gemObject* object) :
213  psGameEvent(0, 0, "psEntityEvent"), type(type), object(object)
214  {
215  this->entitymanager = entitymanager;
216  }
217 
218  virtual void Trigger()
219  {
220  switch(type)
221  {
222  case DESTROY:
223  {
224  entitymanager->RemoveActor(object);
225  break;
226  }
227  }
228  }
229 
230 private:
231  EventType type;
232  gemObject* object;
233  EntityManager* entitymanager;
234 };
235 
236 #endif
237 
psWorld is in charge of managing all regions (zone map files) and loading/unloading them as needed...
Definition: psworld.h:47
uint32 InstanceID
Definition: psconst.h:64
CacheManager * cacheManager
Manages CEL entities on the server.
Definition: entitymanager.h:77
virtual void Trigger()
Abstract event processing function.
csString MagicalAffinity
Definition: entitymanager.h:73
Used to manage incoming user commands from a client.
Definition: usermanager.h:53
The structure of 1 queue entry (pointer to a message)
Definition: message.h:143
psDatabase * database
ClientConnectionSet * clients
psMovementInfoMessage * moveinfomsg
Any semi-autonomous object, either a player or an NPC.
Definition: gem.h:1170
GEMSupervisor * gem
iEngine * GetEngine()
psEntityEvent(EntityManager *entitymanager, EventType type, gemObject *object)
GEMSupervisor * GetGEM()
csString AttackTool
Definition: entitymanager.h:71
csHash< psFamiliarType *, PID > familiarTypeList
This class collects data of a netclient.
Definition: client.h:95
bool HasBeenReady()
void void Initialize(iObjectRegistry *object_reg)
csString AttackType
Definition: entitymanager.h:72
Definition: gem.h:1910
UserManager * usermanager
csHash< psAffinityAttribute * > affinityAttributeList
psWorld * gameWorld
This class manages the caching of data that is unchanging during server operation.
Definition: cachemanager.h:234
psWorld * GetWorld()
A gemObject is any solid, graphical object visible in PS with normal physics and normal collision det...
Definition: gem.h:314
This class holds the refs to the core factories, etc in CEL.
Definition: gem.h:126
This class stores all the properties of an action location Entrance, return location, name, response type, trigger.
psServerDR * serverdr
This class is a list of several CLient objects, it&#39;s designed for finding clients very fast based on ...
Definition: clients.h:58
Contains information about sectors from the server perspective.
Definition: pssectorinfo.h:46
csString Lifecycle
Definition: entitymanager.h:70
All scheduled events must inherit from this class.
Definition: gameevent.h:36
ClientConnectionSet * GetClients()
iEngine * engine
Definition: gem.h:768
This class embodies item instances in the game.
Definition: psitem.h:238
Provides a manager to facilitate subscriptions.
Definition: msgmanager.h:106