Planeshift
spawnmanager.h
Go to the documentation of this file.
1 /*
2  * spawnmanager.h by Keith Fulton <keith@paqrat.com>
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 __SPAWNMANAGER_H__
20 #define __SPAWNMANAGER_H__
21 
22 class gemObject;
23 class psCharacter;
24 class psDatabase;
25 class psScheduledItem;
26 class psSectorInfo;
27 
28 #include <csgeom/vector3.h>
29 #include <csutil/hash.h>
30 #include "util/gameevent.h"
31 #include "msgmanager.h"
32 #include "lootrandomizer.h"
33 
34 
44 {
45 protected:
46  csRandomGen* randomgen;
47 
49  int id;
50 
51  char type;
52 
55 
57  csString spawnsector;
58 
59 private:
61  float x1;
62  float y1;
63  float z1;
64  float x2;
65  float y2;
66  float z2;
67  float radius;
68 
70  float area;
71 
72  csVector3 PickWithRadius(csVector3 pos, float radius);
73 
74 public:
76  SpawnRange();
77 
79  void Initialize(int idval,
80  int spawnruleid,
81  const char* type_code,
82  float rx1, float ry1, float rz1,
83  float rx2, float ry2, float rz2,
84  float radius,
85  const char* sectorname);
86 
87  void SetID(int idval)
88  {
89  id = idval;
90  };
91  int GetID()
92  {
93  return id;
94  }
95 
97  float GetArea()
98  {
99  return area;
100  };
101 
103  const csString &GetSector()
104  {
105  return spawnsector;
106  }
107 
109  const csVector3 PickPos();
110 };
111 
112 class LootEntrySet;
113 
119 {
120 protected:
121 
122  csRandomGen* randomgen;
123 
125  int id;
126 
129 
132 
135 
138 
140  float fixedspawnx;
141  float fixedspawny;
142  float fixedspawnz;
147 
149  csHash<SpawnRange*> ranges;
150 
153 
155 
156 public:
157 
159  SpawnRule();
160  ~SpawnRule();
161 
163  void Initialize(int idval,
164  int minspawn,
165  int maxspawn,
166  float substodds,
167  int substplayer,
168  float x,float y,float z,float angle,
169  const char* sector,
170  LootEntrySet* loot_id,
171  int dead_time,
172  float minSpacing,
173  InstanceID instance);
174 
175  int GetID()
176  {
177  return id;
178  };
179  void SetID(int idval)
180  {
181  id = idval;
182  };
183 
185  int GetRespawnDelay();
186 
188  PID CheckSubstitution(PID originalplayer);
189 
195  bool DetermineSpawnLoc(psCharacter* ch, csVector3 &pos, float &angle, csString &sectorname, InstanceID &instance);
196 
198  void AddRange(SpawnRange* range);
199 
202  {
203  return loot;
204  }
205 
207  {
208  return dead_remain_time;
209  }
210 
212  {
213  return minSpawnSpacingDistance;
214  }
215 
216 };
217 
218 class psItemStats;
219 class psCharacter;
220 
225 struct LootEntry
226 {
228  int min_item;
229  int max_item;
230  float probability;
233  bool randomize;
235 };
236 
242 {
243 protected:
244  int id;
245  csArray<LootEntry*> entries;
246  float total_prob;
248 
249  void CreateSingleLoot(psCharacter* chr);
250  void CreateMultipleLoot(psCharacter* chr, size_t numModifiers = 0);
251 
252 public:
254  {
255  id=idx;
256  total_prob=0;
257  lootRandomizer=lr;
258  }
259  ~LootEntrySet();
260 
262  void AddLootEntry(LootEntry* entry);
263 
272  void CreateLoot(psCharacter* character, size_t numModifiers = 0);
273 };
274 
277 class PendingLootPrompt;
278 
283 class SpawnManager : public MessageManager<SpawnManager>
284 {
285 protected:
287  csHash<SpawnRule*> rules;
288  csHash<LootEntrySet*> looting;
293 
294  void HandleLootItem(MsgEntry* me,Client* client);
295  void HandleDeathEvent(MsgEntry* me,Client* notused);
296 
297 public:
298 
299  SpawnManager(psDatabase* db, CacheManager* cachemanager, EntityManager* entitymanager, GEMSupervisor* gemsupervisor);
300  virtual ~SpawnManager();
301 
308  {
309  return lootRandomizer;
310  }
311 
315  void PreloadDatabase();
316 
320  void PreloadLootRules();
321 
322 #if 0
323 
326  LoadWaypointsAsSpawnRanges(iDocumentNode* topNode);
327 #endif
328 
332  void LoadSpawnRanges(SpawnRule* rule);
333 
339  void LoadHuntLocations(psSectorInfo* sectorinfo = 0);
340 
347  void SpawnHuntLocations(Result &result, psSectorInfo* sectorinfo);
348 
358  void RepopulateLive(psSectorInfo* sectorinfo = 0);
359 
364  void Respawn(PID playerID, SpawnRule* spawnRule);
365 
369  void Respawn(psCharacter* chardata, InstanceID instance, csVector3 &where, float rot, const char* sector);
370 
379  void RepopulateItems(psSectorInfo* sectorinfo = 0);
380 
385  void KillNPC(gemActor* npc, gemActor* killer);
386 
391  void RemoveNPC(gemObject* obj);
392 };
393 
394 
401 {
402 protected:
404  PID playerID;
406 
407 public:
412  int delayticks,
413  PID playerID,
414  SpawnRule* spawnRule);
415 
416  virtual void Trigger(); // Abstract event processing function
417 };
418 
425 {
426 protected:
429  EID entity;
430 
431 public:
433  GEMSupervisor* gemSupervisor,
434  int delayticks,
435  gemObject* obj);
436 
437  virtual void Trigger(); // Abstract event processing function
438 };
439 
441 {
442 public:
444  virtual ~psItemSpawnEvent();
445 
446  void Trigger(); // Abstract event processing function
447 
448 protected:
450 };
451 
462 void handleGroupLootItem(psItem* item, gemActor* obj, Client* client, CacheManager* cacheManager, GEMSupervisor* gem, uint8_t lootAction = 0);
463 
466 #endif
This class stores an array of LootModifiers and randomizes loot stats.
float fixedspawnz
Definition: spawnmanager.h:142
uint32 InstanceID
Definition: psconst.h:64
int npcspawnruleid
A = Area (rect), L = Line Segment, C = Circle.
Definition: spawnmanager.h:54
PID substituteplayer
Player id to respawn if substitution spawn odds are met.
Definition: spawnmanager.h:137
Manages CEL entities on the server.
Definition: entitymanager.h:77
csRandomGen * randomgen
Definition: spawnmanager.h:122
LootRandomizer * GetLootRandomizer()
Returns the loot randomizer.
Definition: spawnmanager.h:307
float fixedspawny
Definition: spawnmanager.h:141
int dead_remain_time
Definition: spawnmanager.h:154
float GetArea()
Get range&#39;s XZ area.
Definition: spawnmanager.h:97
float minSpawnSpacingDistance
What should the free space be around before spawn position is accepted.
Definition: spawnmanager.h:146
int id
Unique Id used for ident and tree sorting.
Definition: spawnmanager.h:125
GEMSupervisor * gem
Definition: spawnmanager.h:428
bool randomize
Definition: spawnmanager.h:233
The structure of 1 queue entry (pointer to a message)
Definition: message.h:143
void SetID(int idval)
Definition: spawnmanager.h:87
psScheduledItem * schedule
Definition: spawnmanager.h:449
csString fixedspawnsector
Definition: spawnmanager.h:144
This class holds one loot possibility for a killed npc.
Definition: spawnmanager.h:225
void SetID(int idval)
Definition: spawnmanager.h:179
SpawnManager * spawnmanager
Definition: spawnmanager.h:427
csString spawnsector
Spawn sector name.
Definition: spawnmanager.h:57
csHash< LootEntrySet * > looting
Definition: spawnmanager.h:288
csArray< LootEntry * > entries
Definition: spawnmanager.h:245
int GetID()
Definition: spawnmanager.h:91
int GetID()
Definition: spawnmanager.h:175
int max_item
The maximum amount of these items.
Definition: spawnmanager.h:229
Any semi-autonomous object, either a player or an NPC.
Definition: gem.h:1170
void Initialize(int idval, int spawnruleid, const char *type_code, float rx1, float ry1, float rz1, float rx2, float ry2, float rz2, float radius, const char *sectorname)
Setup variables and compute area.
LootRandomizer * lootRandomizer
Definition: spawnmanager.h:289
iDataConnection * db
Global connection to the Database. Set from the psDatabase class.
int min_item
The minimal amount of these items.
Definition: spawnmanager.h:228
float substitutespawnodds
Odds of substitute spawn triggering instead of respawn of same entity.
Definition: spawnmanager.h:134
InstanceID fixedinstance
Definition: spawnmanager.h:145
LootEntrySet * GetLootRules()
Get the Loot Rule set to generate loot.
Definition: spawnmanager.h:201
EntityManager * entityManager
Definition: spawnmanager.h:291
This class stores an array of LootEntry and calculates required loot on a newly dead mob...
Definition: spawnmanager.h:241
const csString & GetSector()
Get spawn sector name.
Definition: spawnmanager.h:103
When an NPC or mob is killed in the spawn manager, its respawn event is immediately created and added...
Definition: spawnmanager.h:424
When an NPC or mob is killed in the spawn manager, its respawn event is immediately created and added...
Definition: spawnmanager.h:400
float total_prob
Definition: spawnmanager.h:246
int id
Unique ID used for ident.
Definition: spawnmanager.h:49
This is a wrapper class for result sets which makes syntax for getting at the data easier and also us...
Definition: psdatabase.h:132
LootRandomizer * lootRandomizer
Definition: spawnmanager.h:247
void handleGroupLootItem(psItem *item, gemActor *obj, Client *client, CacheManager *cacheManager, GEMSupervisor *gem, uint8_t lootAction=0)
Handles looting of an item, whether there is a group or not.
This class collects data of a netclient.
Definition: client.h:95
SpawnRange()
Ctor clears all to zero.
int minspawntime
Minimum respawn delay in ticks (msec)
Definition: spawnmanager.h:128
CacheManager * cacheManager
Definition: spawnmanager.h:290
csHash< SpawnRule * > rules
Definition: spawnmanager.h:287
GEMSupervisor * gem
Definition: spawnmanager.h:292
csRandomGen * randomgen
Definition: spawnmanager.h:46
float fixedspawnx
If ranges are populated, these are ignored.
Definition: spawnmanager.h:140
SpawnManager * spawnmanager
Definition: spawnmanager.h:403
PID playerID
The PID of the entity to respawn.
Definition: spawnmanager.h:404
This huge class stores all the properties of any object a player can have in the game.
Definition: psitemstats.h:463
const csVector3 PickPos()
Randomly pick a position within the range.
This class manages the caching of data that is unchanging during server operation.
Definition: cachemanager.h:234
int GetDeadRemainTime()
Definition: spawnmanager.h:206
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
int maxspawntime
Maximum respawn delay in ticks.
Definition: spawnmanager.h:131
float fixedspawnrot
Definition: spawnmanager.h:143
LootEntrySet * loot
Rules for generating loot when this npc is killed.
Definition: spawnmanager.h:152
SpawnRule * spawnRule
The rule to use for determine where.
Definition: spawnmanager.h:405
Contains information about sectors from the server perspective.
Definition: pssectorinfo.h:46
float probability
Definition: spawnmanager.h:230
psDatabase * database
Definition: spawnmanager.h:286
This class is used to store respawn rules for NPCs.
Definition: spawnmanager.h:118
All scheduled events must inherit from this class.
Definition: gameevent.h:36
LootEntrySet(int idx, LootRandomizer *lr)
Definition: spawnmanager.h:253
int GetMinSpawnSpacingDistance()
Definition: spawnmanager.h:211
psItemStats * item
Definition: spawnmanager.h:227
This class is used to store respawn ranges for NPCs.
Definition: spawnmanager.h:43
This class is periodically called by the engine to ensure that monsters (and other NPCs) are respawne...
Definition: spawnmanager.h:283
float randomizeProbability
The probability that if this item was picked it will be randomized.
Definition: spawnmanager.h:234
csHash< SpawnRange * > ranges
Spawn ranges for the current rule.
Definition: spawnmanager.h:149
This class embodies item instances in the game.
Definition: psitem.h:238
Provides a manager to facilitate subscriptions.
Definition: msgmanager.h:106