MSpawnManager.h
00001 #ifndef MSPAWNMANAGER_H 00002 #define MSPAWNMANAGER_H 00003 00004 00005 #include "RTypes.h" 00006 using namespace std; 00007 #include <map> 00008 00009 00010 #define RESPAWN_TICK_INTERVAL 1000 00011 00012 00013 class MSpawnData { 00014 int m_nSpawnID; 00015 char m_szSpawnName[24]; 00016 00017 int m_nObjID; 00018 00019 int m_nMapID; 00020 int m_nCellID; 00021 rvector m_Pos; 00022 00023 int m_nMaxCount; 00024 int m_nCurrentCount; 00025 00026 unsigned long m_nRespawnTime; 00027 unsigned long m_nLastSpawnTick; 00028 00029 public: 00030 MSpawnData(int nSpawnID, char* pszSpawnName) { 00031 m_nObjID=0; m_nMapID=0; m_nCellID=0; m_Pos=rvector(.0,.0,.0); m_nMaxCount=0; m_nCurrentCount=0; m_nRespawnTime=0; m_nLastSpawnTick=0; 00032 00033 m_nSpawnID = nSpawnID; 00034 strcpy(m_szSpawnName, pszSpawnName); 00035 } 00036 int GetSpawnID() { return m_nSpawnID; } 00037 char* GetSpawnName() { return m_szSpawnName; } 00038 int GetObjID() { return m_nObjID; } 00039 void SetObjID(int nObjID) { m_nObjID = nObjID; } 00040 int GetMapID() { return m_nMapID; } 00041 void SetMapID(int nMapID) { m_nMapID = nMapID; } 00042 int GetCellID() { return m_nCellID; } 00043 void SetCellID(int nCellID) { m_nCellID = nCellID; } 00044 rvector& GetPos() { return m_Pos; } 00045 void SetPos(const rvector& Pos) { m_Pos = Pos; } 00046 int GetMaxCount() { return m_nMaxCount; } 00047 void SetMaxCount(int nMaxCount) { m_nMaxCount = nMaxCount; } 00048 int GetCurrentCount() { return m_nCurrentCount; } 00049 void SetCurrentCount(int nCount) { m_nCurrentCount = nCount; } 00050 unsigned long GetRespawnTime() { return m_nRespawnTime; } 00051 void SetRespawnTime(unsigned long nSeconds) { m_nRespawnTime = nSeconds; } 00052 unsigned long GetLastSpawnTime() { return m_nLastSpawnTick; } 00053 void SetLastSpawnTime(unsigned long nTick) { m_nLastSpawnTick = nTick; } 00054 }; 00055 00056 00057 class MSpawnList : public map<int, MSpawnData*> {}; 00058 class MZoneServer; 00059 00060 00061 class MSpawnManager { 00062 int m_nNextSpawnID; 00063 MSpawnList m_SpawnList; 00064 unsigned long m_nLastTickTime; 00065 00066 MZoneServer* m_pZoneServer; 00067 00068 public: 00069 MSpawnManager(); 00070 virtual ~MSpawnManager(); 00071 00072 void SetZoneServer(MZoneServer* pServer) { m_pZoneServer = pServer; } 00073 00074 MSpawnData* FindSpawnByName(char* pszSpawnName); 00075 MSpawnData* FindSpawnByID(int nSpawnID) { 00076 MSpawnList::iterator i = m_SpawnList.find(nSpawnID); 00077 if(i!=m_SpawnList.end()) return (MSpawnData*)(*i).second; 00078 else return NULL; 00079 } 00080 00081 int CreateSpawnID() { return m_nNextSpawnID++; } 00082 MSpawnData* AddSpawnData(char* szSpawnName, const rvector& Pos); 00083 00084 bool ReadSpawnPosition(char* pszMapFile); 00085 bool ReadSpawnData(char* pszSpawnFile); 00086 00087 void Spawn(MSpawnData* pSpawn, unsigned long nTime); 00088 void DeSpawn(int nSpawnID); 00089 00090 bool IsNewTick(unsigned long int nTime) { 00091 if (nTime-m_nLastTickTime >= RESPAWN_TICK_INTERVAL) return true; 00092 else return false; 00093 } 00094 void UpdateTick(unsigned long int nTime) { m_nLastTickTime = nTime; } 00095 void Tick(unsigned long int nTime); 00096 00097 void LOG(const char *pFormat,...); 00098 }; 00099 00100 00101 #endif
MAIET entertainment