Planeshift
|
00001 /* 00002 * spawnmanager.h by Keith Fulton <[email protected]> 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 __SPAWNMANAGER_H__ 00020 #define __SPAWNMANAGER_H__ 00021 00022 class gemObject; 00023 class psCharacter; 00024 class psDatabase; 00025 class psScheduledItem; 00026 class psSectorInfo; 00027 00028 #include <csgeom/vector3.h> 00029 #include <csutil/hash.h> 00030 #include "util/gameevent.h" 00031 #include "msgmanager.h" 00032 #include "lootrandomizer.h" 00033 00034 00043 class SpawnRange 00044 { 00045 protected: 00046 csRandomGen* randomgen; 00047 00049 int id; 00050 00051 char type; 00052 00054 int npcspawnruleid; 00055 00057 csString spawnsector; 00058 00059 private: 00061 float x1; 00062 float y1; 00063 float z1; 00064 float x2; 00065 float y2; 00066 float z2; 00067 float radius; 00068 00070 float area; 00071 00072 csVector3 PickWithRadius(csVector3 pos, float radius); 00073 00074 public: 00076 SpawnRange(); 00077 00079 void Initialize(int idval, 00080 int spawnruleid, 00081 const char* type_code, 00082 float rx1, float ry1, float rz1, 00083 float rx2, float ry2, float rz2, 00084 float radius, 00085 const char* sectorname); 00086 00087 void SetID(int idval) 00088 { 00089 id = idval; 00090 }; 00091 int GetID() 00092 { 00093 return id; 00094 } 00095 00097 float GetArea() 00098 { 00099 return area; 00100 }; 00101 00103 const csString &GetSector() 00104 { 00105 return spawnsector; 00106 } 00107 00109 const csVector3 PickPos(); 00110 }; 00111 00112 class LootEntrySet; 00113 00118 class SpawnRule 00119 { 00120 protected: 00121 00122 csRandomGen* randomgen; 00123 00125 int id; 00126 00128 int minspawntime; 00129 00131 int maxspawntime; 00132 00134 float substitutespawnodds; 00135 00137 PID substituteplayer; 00138 00140 float fixedspawnx; 00141 float fixedspawny; 00142 float fixedspawnz; 00143 float fixedspawnrot; 00144 csString fixedspawnsector; 00145 InstanceID fixedinstance; 00146 float minSpawnSpacingDistance; 00147 00149 csHash<SpawnRange*> ranges; 00150 00152 LootEntrySet* loot; 00153 00154 int dead_remain_time; 00155 00156 public: 00157 00159 SpawnRule(); 00160 ~SpawnRule(); 00161 00163 void Initialize(int idval, 00164 int minspawn, 00165 int maxspawn, 00166 float substodds, 00167 int substplayer, 00168 float x,float y,float z,float angle, 00169 const char* sector, 00170 LootEntrySet* loot_id, 00171 int dead_time, 00172 float minSpacing, 00173 InstanceID instance); 00174 00175 int GetID() 00176 { 00177 return id; 00178 }; 00179 void SetID(int idval) 00180 { 00181 id = idval; 00182 }; 00183 00185 int GetRespawnDelay(); 00186 00188 PID CheckSubstitution(PID originalplayer); 00189 00195 bool DetermineSpawnLoc(psCharacter* ch, csVector3 &pos, float &angle, csString §orname, InstanceID &instance); 00196 00198 void AddRange(SpawnRange* range); 00199 00201 LootEntrySet* GetLootRules() 00202 { 00203 return loot; 00204 } 00205 00206 int GetDeadRemainTime() 00207 { 00208 return dead_remain_time; 00209 } 00210 00211 int GetMinSpawnSpacingDistance() 00212 { 00213 return minSpawnSpacingDistance; 00214 } 00215 00216 }; 00217 00218 class psItemStats; 00219 class psCharacter; 00220 00225 struct LootEntry 00226 { 00227 psItemStats* item; 00228 int min_item; 00229 int max_item; 00230 float probability; 00231 int min_money; 00232 int max_money; 00233 bool randomize; 00234 float randomizeProbability; 00235 }; 00236 00241 class LootEntrySet 00242 { 00243 protected: 00244 int id; 00245 csArray<LootEntry*> entries; 00246 float total_prob; 00247 LootRandomizer* lootRandomizer; 00248 00249 void CreateSingleLoot(psCharacter* chr); 00250 void CreateMultipleLoot(psCharacter* chr, size_t numModifiers = 0); 00251 00252 public: 00253 LootEntrySet(int idx, LootRandomizer* lr) 00254 { 00255 id=idx; 00256 total_prob=0; 00257 lootRandomizer=lr; 00258 } 00259 ~LootEntrySet(); 00260 00262 void AddLootEntry(LootEntry* entry); 00263 00272 void CreateLoot(psCharacter* character, size_t numModifiers = 0); 00273 }; 00274 00277 class PendingLootPrompt; 00278 00283 class SpawnManager : public MessageManager<SpawnManager> 00284 { 00285 protected: 00286 psDatabase* database; 00287 csHash<SpawnRule*> rules; 00288 csHash<LootEntrySet*> looting; 00289 LootRandomizer* lootRandomizer; 00290 CacheManager* cacheManager; 00291 EntityManager* entityManager; 00292 GEMSupervisor* gem; 00293 00294 void HandleLootItem(MsgEntry* me,Client* client); 00295 void HandleDeathEvent(MsgEntry* me,Client* notused); 00296 00297 public: 00298 00299 SpawnManager(psDatabase* db, CacheManager* cachemanager, EntityManager* entitymanager, GEMSupervisor* gemsupervisor); 00300 virtual ~SpawnManager(); 00301 00307 LootRandomizer* GetLootRandomizer() 00308 { 00309 return lootRandomizer; 00310 } 00311 00315 void PreloadDatabase(); 00316 00320 void PreloadLootRules(); 00321 00322 #if 0 00323 00326 LoadWaypointsAsSpawnRanges(iDocumentNode* topNode); 00327 #endif 00328 00332 void LoadSpawnRanges(SpawnRule* rule); 00333 00339 void LoadHuntLocations(psSectorInfo* sectorinfo = 0); 00340 00347 void SpawnHuntLocations(Result &result, psSectorInfo* sectorinfo); 00348 00358 void RepopulateLive(psSectorInfo* sectorinfo = 0); 00359 00364 void Respawn(PID playerID, SpawnRule* spawnRule); 00365 00369 void Respawn(psCharacter* chardata, InstanceID instance, csVector3 &where, float rot, const char* sector); 00370 00379 void RepopulateItems(psSectorInfo* sectorinfo = 0); 00380 00385 void KillNPC(gemActor* npc, gemActor* killer); 00386 00391 void RemoveNPC(gemObject* obj); 00392 }; 00393 00394 00400 class psRespawnGameEvent : public psGameEvent 00401 { 00402 protected: 00403 SpawnManager* spawnmanager; 00404 PID playerID; 00405 SpawnRule* spawnRule; 00406 00407 public: 00411 psRespawnGameEvent(SpawnManager* mgr, 00412 int delayticks, 00413 PID playerID, 00414 SpawnRule* spawnRule); 00415 00416 virtual void Trigger(); // Abstract event processing function 00417 }; 00418 00424 class psDespawnGameEvent : public psGameEvent 00425 { 00426 protected: 00427 SpawnManager* spawnmanager; 00428 GEMSupervisor* gem; 00429 EID entity; 00430 00431 public: 00432 psDespawnGameEvent(SpawnManager* mgr, 00433 GEMSupervisor* gemSupervisor, 00434 int delayticks, 00435 gemObject* obj); 00436 00437 virtual void Trigger(); // Abstract event processing function 00438 }; 00439 00440 class psItemSpawnEvent : public psGameEvent 00441 { 00442 public: 00443 psItemSpawnEvent(psScheduledItem* item); 00444 virtual ~psItemSpawnEvent(); 00445 00446 void Trigger(); // Abstract event processing function 00447 00448 protected: 00449 psScheduledItem* schedule; 00450 }; 00451 00462 void handleGroupLootItem(psItem* item, gemActor* obj, Client* client, CacheManager* cacheManager, GEMSupervisor* gem, uint8_t lootAction = 0); 00463 00466 #endif