Planeshift

npcmanager.h

Go to the documentation of this file.
00001 /*
00002 * npcmanager.h by Keith Fulton <[email protected]>
00003 *
00004 * Copyright (C) 2003 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 
00020 #ifndef __NPCMANAGER_H_
00021 #define __NPCMANAGER_H_
00022 //=============================================================================
00023 // Crystal Space Includes
00024 //=============================================================================
00025 #include <csutil/ref.h>
00026 
00027 //=============================================================================
00028 // Project Includes
00029 //=============================================================================
00030 #include "net/netbase.h"                // PublishVector class
00031 #include "net/npcmessages.h"
00032 
00033 #include "bulkobjects/psskills.h"
00034 #include "cachemanager.h"
00035 
00036 //=============================================================================
00037 // Local Includes
00038 //=============================================================================
00039 #include "msgmanager.h"   // Subscriber class
00040 
00041 #define OWNER_ALL 0xFFFFFFFF
00042 
00043 
00044 class Client;
00045 class psDatabase;
00046 class psNPCCommandsMessage;
00047 class ClientConnectionSet;
00048 class EntityManager;
00049 class EventManager;
00050 class gemObject;
00051 class gemActor;
00052 class gemNPC;
00053 class PetOwnerSession;
00054 class psPathPoint;
00055 class Waypoint;
00056 class psPath;
00057 class Location;
00058 class LocationType;
00059 
00060 class NPCManager : public MessageManager<NPCManager>
00061 {
00062 public:
00063     NPCManager(ClientConnectionSet* pCCS,
00064                psDatabase* db,
00065                EventManager* evtmgr,
00066                GEMSupervisor* gemsupervisor,
00067                CacheManager* cachemanager,
00068                EntityManager* entitymanager);
00069 
00070     virtual ~NPCManager();
00071 
00073     bool Initialize();
00074 
00076     void SendNPCList(Client* client);
00077 
00079     void SendAllNPCStats(Client* client);
00080 
00082     void Disconnect(Client* client);
00083 
00085     void AddEntity(gemObject* obj);
00086 
00088     void RemoveEntity(MsgEntry* me);
00089 
00091     void UpdateWorldPositions();
00092 
00094     void QueueAssessPerception(EID entityEID, EID targetEID, const csString &physicalAssessmentPerception,
00095                                const csString &physicalAssessmentDifferencePerception,
00096                                const csString &magicalAssessmentPerception,
00097                                const csString &magicalAssessmentDifferencePerception,
00098                                const csString &overallAssessmentPerception,
00099                                const csString &overallAssessmentDifferencePerception);
00100 
00101 
00103     void QueueTalkPerception(gemActor* speaker, gemNPC* target);
00104 
00106     void QueueAttackPerception(gemActor* attacker,gemNPC* target);
00107 
00109     void QueueDamagePerception(gemActor* attacker,gemNPC* target,float dmg);
00110 
00112     void QueueDeathPerception(gemObject* who);
00113 
00115     void QueueSpellPerception(gemActor* caster, gemObject* target,const char* spell_cat, uint32_t spell_category, float severity);
00116 
00118     void QueueStatDR(gemActor* actor, unsigned int statsDirtyFlags);
00119 
00121     void QueueEnemyPerception(psNPCCommandsMessage::PerceptionType type, gemActor* npc, gemActor* player, float relative_faction);
00122 
00124     void QueueOwnerCmdPerception(gemActor* owner, gemNPC* pet, psPETCommandMessage::PetCommand_t command);
00125 
00127     void QueueInventoryPerception(gemActor* owner, psItem* itemdata, bool inserted);
00128 
00130     void QueueFlagPerception(gemActor* owner);
00131 
00133     void QueueNPCCmdPerception(gemActor* owner, const csString &cmd);
00134 
00136     void QueueTransferPerception(gemActor* owner, psItem* itemdata, csString target);
00137 
00139     void QueueSpawnedPerception(gemNPC* spawned, gemNPC* spawner, const csString &tribeMemberType);
00140 
00142     void QueueTeleportPerception(gemNPC* npc, csVector3 &pos, float yrot, iSector* sector, InstanceID instance);
00143 
00145     void QueueInfoRequestPerception(gemNPC* npc, Client* client, const char* infoRequestSubCmd);
00146 
00148     void QueueFailedToAttackPerception(gemNPC* attacker, gemObject* target);
00149 
00151     void QueuePerceptPerception(gemNPC* npc, csString perception, csString type);
00152 
00154     void QueueSpokenToPerception(gemNPC* npc, bool spokenTo);
00155 
00157     void QueueChangeOwnerPerception(gemNPC* npc, EID owner);
00158 
00165     void ChangeNPCBrain(gemNPC* npc, Client* client, const char* brainName);
00166 
00173     void DebugNPC(gemNPC* npc, Client* client, uint8_t debugLevel);
00174 
00181     void DebugTribe(gemNPC* npc, Client* client, uint8_t debugLevel);
00182 
00184     void SendAllCommands(bool createNewTick);
00185 
00187     csArray<PublishDestination> &GetSuperClients()
00188     {
00189         return superclients;
00190     }
00191 
00193     void WorkDoneNotify(EID npcEID, csString reward, csString nick);
00194 
00196     void NewNPCNotify(PID player_id, PID master_id, PID owner_id);
00197 
00199     void DeletedNPCNotify(PID player_id);
00200 
00202     void ControlNPC(gemNPC* npc);
00203 
00208     void CheckWorkLocation(gemNPC* npc, Location* location);
00209 
00211     PetOwnerSession* CreatePetOwnerSession(gemActor*, psCharacter*);
00212 
00214     void DismissPet(gemNPC* pet, Client* owner);
00215 
00217     void RemovePetOwnerSession(PetOwnerSession* session);
00218 
00220     void UpdatePetTime();
00221 
00227     PSSKILL GetPetSkill()
00228     {
00229         return (PSSKILL)petSkill->getValueAsInt();
00230     }
00231 
00237     void LocationAdjusted(Location* location);
00238 
00244     void LocationCreated(Location* location);
00245 
00251     void LocationInserted(Location* location);
00252 
00256     void LocationRadius(Location* location);
00257 
00261     void LocationTypeAdd(LocationType* locationType);
00262 
00266     void LocationTypeRemove(const csString &locationTypeName);
00267 
00271     void WaypointAdjusted(Waypoint* wp);
00272 
00276     void PathPointAdjusted(psPathPoint* point);
00277 
00282     void WaypointAddAlias(const Waypoint* wp, const WaypointAlias* alias);
00283 
00288     void WaypointAliasRotation(const Waypoint* wp, const WaypointAlias* alias);
00289 
00294     void WaypointRemoveAlias(const Waypoint* wp, const csString &alias);
00295 
00301     void WaypointSetFlag(const Waypoint* wp, const csString &flag, bool enable);
00302 
00308     void PathSetFlag(const psPath* path, const csString &flag, bool enable);
00309 
00313     void WaypointRadius(const Waypoint* waypoint);
00314 
00318     void WaypointRename(const Waypoint* waypoint);
00319 
00323     void PathRename(const psPath* path);
00324 
00328     void WaypointCreate(const Waypoint* waypoint);
00329 
00333     void PathCreate(const psPath* path);
00334 
00339     void AddPoint(const psPath* path, const psPathPoint* point);
00340 
00345     void RemovePoint(const psPath* path, int pointId);
00346 
00347     MathScript* GetPetDepletedLockoutTime() { return petDepletedLockoutTime; }
00348     MathScript* GetPetDismissLockoutTime() { return petDismissLockoutTime; }
00349     MathScript* GetMaxPetTime() { return maxPetTime; }
00350     MathScript* GetPetDeathLockoutTime() { return petDeathLockoutTime; }
00351     MathScript* GetPetTrainingLockoutTime() { return petTrainingLockoutTime; }
00352 
00353 protected:
00354 
00356     void HandleAuthentRequest(MsgEntry* me,Client* client);
00357 
00359     void HandleCommandList(MsgEntry* me,Client* client);
00360 
00362     void HandleDamageEvent(MsgEntry* me,Client* client);
00363 
00365     void HandleDeathEvent(MsgEntry* me,Client* client);
00366 
00367     void HandleNPCReady(MsgEntry* me,Client* client);
00368 
00370     void HandleSimpleRenderMesh(MsgEntry* me, Client* client);
00371 
00373     void SendMapList(Client* client);
00374 
00376     void SendRaces(Client* client);
00377 
00379     bool CanPetHearYou(int clientnum, Client* owner, gemNPC* pet, const char* type);
00380 
00382     bool WillPetReact(int clientnum, Client* owner, gemNPC* pet, const char* type, int level);
00383 
00385     void HandlePetCommand(MsgEntry* me, Client* client);
00386 
00388     void HandlePetSkill(MsgEntry* me, Client* client);
00389     void SendPetSkillList(Client* client, bool forceOpen = true, PSSKILL focus = PSSKILL_NONE);
00390 
00391 public:
00395     void PetHasBeenKilled(gemNPC*  pet);
00396 
00400     void PetInfo(Client* client, psCharacter* pet);
00401 
00402 protected:
00404     void HandleConsoleCommand(MsgEntry* me,Client* client);
00405 
00407     void PrepareMessage();
00408 
00416     void CheckSendPerceptionQueue(size_t expectedAddSize);
00417 
00419     csArray<PublishDestination> superclients;
00420 
00421     psDatabase*  database;
00422     EventManager* eventmanager;
00423     GEMSupervisor* gemSupervisor;
00424     CacheManager* cacheManager;
00425     EntityManager* entityManager;
00426     ClientConnectionSet* clients;
00427     psNPCCommandsMessage* outbound;
00428     int cmd_count;
00429     optionEntry* petSkill;
00430 
00431     csHash<PetOwnerSession*, PID> OwnerPetList;
00432 
00434     MathScript* petRangeScript;
00435 
00437     MathScript* petReactScript;
00438 
00439     MathScript* petDepletedLockoutTime;
00440     MathScript* petDismissLockoutTime;
00441     MathScript* maxPetTime;
00442     MathScript* petDeathLockoutTime;
00443     MathScript* petTrainingLockoutTime;
00444 };
00445 
00446 #endif