?? map.cpp
字號:
////////////////////////////////////////////////////////////////////////////////////////
// Map.cpp : implementation file
//
//
// - Memory Pool籃 ServerMem Class肺 包訪 內(nèi)靛甫 撈傈矯糯
////////////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Map.h"
#include "CFightZone.h"
#ifdef DEF_AZIT
#include "AzitManager.h"
#endif
#include "../MapLoad/ArchiveMap.h" // Map Data
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////////////////////////////////////////////////////////////////////////////
// Global Values or Functions
////////////////////////////////////////////////////////////////////////////////////////
extern _LPCFIGHTZONEMANAGER g_lpFightzoneManager ;
////////////////////////////////////////////////////////////////////////////////////////
// Construction/Destruction
////////////////////////////////////////////////////////////////////////////////////////
Map::Map()
{
for(int i =0 ; i < _Module.m_iMaxMapLayer ; ++i )
{
_MAP[i] = new _GAME_MAP_ * [MAX_MAPTILE_SIZE] ;
for(int j =0 ; j < MAX_MAPTILE_SIZE ; ++j )
{
_MAP[i][j] = new _GAME_MAP_ [MAX_MAPTILE_SIZE] ;
}
}
for( i =0 ; i < _Module.m_iMaxMapLayer ; ++i )
{
for(int j =0 ; j < MAX_MAPTILE_SIZE ; ++j )
{
memset(_MAP[i][j] ,0x00, sizeof( _GAME_MAP_ ) * MAX_MAPTILE_SIZE ) ;
}
}
// memset(_MONSTER_MAP_, 0x00, sizeof(__MONSTER_MAP__)*MAX_MAPLAYER );
memset(MapConfig, 0x00, sizeof(_MapConfig_)*MAX_MAPLAYER );
memset(&_LOBBY_, 0x00, sizeof(_LOBBY_) );
memset(&_HIDDENLOBBY_, 0x00, sizeof(_HIDDENLOBBY_) );
// --------------------------------------------------------------------------------
// Inistialize Handle
// --------------------------------------------------------------------------------
m_nTempHandle = 0;
m_nMaxLayer = 0;
m_bHaveFightzone = false ;
// --------------------------------------------------------------------------------
// Initialize Critical Section
// --------------------------------------------------------------------------------
::InitializeCriticalSectionAndSpinCount( &m_MapLock , 2000 );
::InitializeCriticalSectionAndSpinCount( &m_DBLock , 2000 );
}
Map::~Map()
{
// --------------------------------------------------------------------------------
// Socket 瀝焊甫 Memory俊輯 昏力 矯糯
//
// - SOCKET秦力矯 肋給等 Handle藹 秦力竅綽 版快 坷幅 貿(mào)府
// --------------------------------------------------------------------------------
LIST_VOIDPTR::iterator itEnd = m_PoolSocket.End() ;
for (LIST_VOIDPTR::iterator it = m_PoolSocket.Begin(); it != itEnd; ++it)
{
_SOCKET_FD *pSocket = (_SOCKET_FD *)*it;
if( pSocket )
{
if( pSocket->dwMagicNum == MAGIC_NUM )
{
::DeleteCriticalSection( &pSocket->SendCS );
// DUKE KIM 酒貳 扼牢俊輯 輛豐 矯 Memory 坷幅 慣積
SAFE_DELETE<PlayerInfo> (&pSocket->pPlayer) ;
SAFE_DELETE<_SOCKET_FD> (&pSocket) ;
}
}
}
m_PoolSocket.Clear();
#ifdef DEF_SERVERDOWNDELAYTRACE
ErrorMsg("m_PoolParty stop Start") ;
#endif
// --------------------------------------------------------------------------------
// Party 瀝焊甫 Memory俊輯 昏力 矯糯
// --------------------------------------------------------------------------------
MAP_VOIDPTR::iterator it_mapEnd = m_MapParty.End() ;
for (MAP_VOIDPTR::iterator it_map = m_MapParty.Begin(); it_map != it_mapEnd ; ++it_map)
{
CParty * lpParty = (CParty *) it_map->second;
SAFE_DELETE<CParty> (&lpParty) ;
}
m_MapParty.Clear() ;
itEnd = m_PoolParty.End() ;
for (it = m_PoolParty.Begin(); it != itEnd ; ++it)
{
CParty *pParty = (CParty *)*it;
SAFE_DELETE<CParty> (&pParty) ;
}
m_PoolParty.Clear() ;
#ifdef DEF_SERVERDOWNDELAYTRACE
ErrorMsg("m_PoolGuild stop Start") ;
#endif
it_mapEnd = m_MapGuild.End() ;
for (it_map = m_MapGuild.Begin(); it_map != it_mapEnd ; ++it_map)
{
_LPGUILD pGuild = (_LPGUILD) it_map->second;
SAFE_DELETE<_CGUILD> (&pGuild) ;
}
m_MapGuild.Clear() ;
// --------------------------------------------------------------------------------
// NOTENOTE: 辨靛 瀝焊甫 Memory俊輯 昏力竊
// --------------------------------------------------------------------------------
itEnd = m_PoolGuild.End() ;
for (it = m_PoolGuild.Begin(); it != itEnd ; ++it)
{
_LPGUILD pGuild = (_LPGUILD) *it;
SAFE_DELETE<_CGUILD> (&pGuild) ;
}
m_PoolGuild.Clear() ;
#ifdef DEF_SERVERDOWNDELAYTRACE
ErrorMsg("m_MapItem stop Start") ;
#endif
// --------------------------------------------------------------------------------
// Delete Item
// --------------------------------------------------------------------------------
for (it_map = m_MapItem.Begin(); it_map != m_MapItem.End(); it_map++)
{
CItem *pItem = (CItem *)it_map->second;
SAFE_DELETE<CItem> (&pItem) ;
}
m_MapItem.Clear();
#ifdef DEF_SERVERDOWNDELAYTRACE
ErrorMsg("m_MapItem stop end") ;
#endif
#ifdef DEF_SERVERDOWNDELAYTRACE
ErrorMsg("m_PoolItem stop Start") ;
#endif
// --------------------------------------------------------------------------------
// Item 瀝焊甫 Memory俊輯 昏力 矯糯
// --------------------------------------------------------------------------------
itEnd = m_PoolItem.End() ;
for (it = m_PoolItem.Begin(); it != itEnd; ++it)
{
CItem *pItem = (CItem *)*it;
SAFE_DELETE<CItem> (&pItem) ;
}
m_PoolItem.Clear();
#ifdef DEF_SERVERDOWNDELAYTRACE
ErrorMsg("m_MapNPC stop Start") ;
#endif
for(int i = 0 ; i < m_nMaxLayer; ++i )
{
// --------------------------------------------------------------------------------
// Delete Map NPC
// --------------------------------------------------------------------------------
MAP_VOIDPTR::iterator it_mapEnd = m_MapNPC[i]->End() ;
for (MAP_VOIDPTR::iterator it_map = m_MapNPC[i]->Begin(); it_map != it_mapEnd; ++it_map)
{
NPC *lpNpc = (NPC *)it_map->second;
if(!lpNpc->IsDead() )
lpNpc->EnchantAllStop() ;
SAFE_DELETE<NPC> (&lpNpc) ;
}
m_MapNPC[i]->Clear();
SAFE_DELETE<SafeMap> (&m_MapNPC[i]) ;
}
// --------------------------------------------------------------------------------
// NPC Setting瀝焊甫 昏力 矯糯
// --------------------------------------------------------------------------------
#ifdef DEF_SERVERDOWNDELAYTRACE
ErrorMsg("m_LocationNPC stop Start") ;
#endif
itEnd = m_LocationNPC.End() ;
for ( it = m_LocationNPC.Begin(); it != itEnd; ++it)
{
_NPC_ *pNPC = (_NPC_ *)*it; // 殿廢等 檬扁 NPC瀝焊甫 掘瀾
SAFE_DELETE< _NPC_> (&pNPC) ;
}
m_LocationNPC.Clear() ;
#ifdef DEF_SERVERDOWNDELAYTRACE
ErrorMsg("m_PoolSocket stop Start") ;
#endif
#ifdef DEF_SERVERDOWNDELAYTRACE
ErrorMsg("m_PoolSkill stop Start") ;
#endif
// --------------------------------------------------------------------------------
// Skill 瀝焊甫 Memory俊輯 昏力 矯糯
// --------------------------------------------------------------------------------
itEnd = m_PoolSkill.End() ;
for (it = m_PoolSkill.Begin(); it != itEnd; ++it)
{
CEnchant *pEnchant = (CEnchant *)*it;
SAFE_DELETE<CEnchant> (&pEnchant) ;
}
m_PoolSkill.Clear();
// --------------------------------------------------------------------------------
// Delete Critical Section
// --------------------------------------------------------------------------------
#ifdef DEF_SERVERDOWNDELAYTRACE
ErrorMsg("DeleteCriticalSection start ") ;
#endif
::DeleteCriticalSection( &m_MapLock );
::DeleteCriticalSection( &m_DBLock );
#ifdef DEF_SERVERDOWNDELAYTRACE
ErrorMsg("DeleteCriticalSection end") ;
#endif
m_MapAccountID.Clear();
m_MapPlayerID.Clear();
m_MapPlayerHandle.Clear();
//#ifdef DEF_LOGOUT_TO_WORLD
// m_MapTempPlayerID.Clear(); // 烙矯 歷厘儈 AccountID
//#endif
for( i =0 ; i < _Module.m_iMaxMapLayer ; ++i )
{
for(int j =0 ; j < MAX_MAPTILE_SIZE ; ++j )
{
SAFE_DELETE<_GAME_MAP_ >(&_MAP[i][j]) ;
}
}
for(i =0 ; i < _Module.m_iMaxMapLayer ; ++i )
{
SAFE_DELETE<_GAME_MAP_ *>(&_MAP[i]) ;
}
#ifdef DEF_SERVERDOWNDELAYTRACE
ErrorMsg("MapClear end") ;
#endif
}
////////////////////////////////////////////////////////////////////////////////////////
// AOI Array俊 秦寸 困摹肺 撈悼 矯糯
//
// NPC(Monster)貿(mào)府 風(fēng)憑闌 眠啊 矯糯
// PC/NCP Handle貿(mào)府俊 包茄 絆刮
////////////////////////////////////////////////////////////////////////////////////////
int Map::AOI_PlayerMove( _LPSOCKET_FD pSocketFD, _POINT &pPoint )
{
if( pSocketFD == NULL ) return -1;
if( pSocketFD->dwMagicNum != MAGIC_NUM ) return -1;
if( !pSocketFD->pPlayer ) return -1;
if( pSocketFD->PlayerStatus == CONNECT_CLOSE) return -1;
// --------------------------------------------------------------------------------
// 秦寸 甘狼 瀝焊甫 掘瀾
// --------------------------------------------------------------------------------
BYTE nMapLayer = pSocketFD->pPlayer->m_nMapLayer;
if( nMapLayer >= m_nMaxLayer ) return -1;
int nMaxX = MapConfig[nMapLayer].nMaxX;
int nMaxY = MapConfig[nMapLayer].nMaxY;
// --------------------------------------------------------------------------------
// 撈悼且 困摹甫 崔曝?fù)?葛膽肺 秦寸 困摹俊 瀝焊甫 扁廢 矯糯
// --------------------------------------------------------------------------------
int nLevel = 0, i, j;
int nXFrom = 0, nXTo = 0;
int nYFrom = 0, nYTo = 0;
_POINT Point;
Point.x = (WORD)(pPoint.x/100);
Point.y = (WORD)(pPoint.y/100);
// --------------------------------------------------------------------------------
// NOTENOTE: 彌利拳 累訣闌 竊
// --------------------------------------------------------------------------------
while( 1 )
{
nXFrom = Point.x - nLevel;
nXTo = Point.x + nLevel;
nYFrom = Point.y - nLevel;
nYTo = Point.y + nLevel;
nXFrom = MAX( nXFrom , 0 );
nXTo = MIN( nXTo , nMaxX );
nYFrom = MAX( nYFrom , 0 );
nYTo = MIN( nYTo , nMaxY );
for( i = nXFrom; i <= nXTo; i ++ )
{
for( j = nYFrom; j <= nYTo; j ++ )
{
if( !(_MAP[nMapLayer][i][j].nCheckBit & CHK_MOVE) ) continue; // 撈悼 閡啊 瘤開牢 版快
if( _MAP[nMapLayer][i][j].dwHandle ) continue; // PC/NPC啊 秦寸 Cell俊 糧犁 竅瘤 臼綽 版快
EnterCriticalSection( &m_MapLock );
AOI_PlayerFastDelete( pSocketFD->pPlayer);
_MAP[nMapLayer][i][j].dwHandle = pSocketFD->pPlayer->m_dwHandle;
_MAP[nMapLayer][i][j].pObject = pSocketFD;
_MAP[nMapLayer][i][j].nType = (BYTE)MAP_PC; // PC
LeaveCriticalSection( &m_MapLock );
// --------------------------------------------------------------------
// 秦寸 AOI藹闌 歷厘 矯糯
// --------------------------------------------------------------------
pSocketFD->pPlayer->m_Tile.x = i;
pSocketFD->pPlayer->m_Tile.y = j;
// --------------------------------------------------------------------
// 秦寸 AOI俊 諜 NPC/PC啊 糧犁竅綽 版快
// 困摹 焊瀝 累訣籃 Title狼 吝埃俊 困摹 竅促廢 父惦
// -> 拋膠飄 饒 困摹 釬矯啊 撈惑茄 版快 薦瀝 累訣
// --------------------------------------------------------------------
if( nLevel > 0 )
{
pSocketFD->pPlayer->_PLAYERINFO.wX = pSocketFD->pPlayer->m_Tile.x * 100 + 50;
pSocketFD->pPlayer->_PLAYERINFO.wY = pSocketFD->pPlayer->m_Tile.y * 100 + 50;
}
else
{
// 泅 困摹俊 糧犁 竅綽 版快
pSocketFD->pPlayer->_PLAYERINFO.wX = pPoint.x;
pSocketFD->pPlayer->_PLAYERINFO.wY = pPoint.y;
}
return nLevel; // LOOP狐廉 唱坷扁
}
}
nLevel ++;
// 漂瀝 Level鱉瘤 貿(mào)府 竅瘤 給茄 版快
if( nLevel > 10 ) return -1;
}
return nLevel;
}
////////////////////////////////////////////////////////////////////////////////////////
// 框流老薦 絕綽瘤 咯何 魄傈
//
// - 框流 老薦 樂綽瘤 咯何 魄瀝 (Tile 犬牢)
// - 框流老薦 樂綽 困摹咯何 犬牢 (救傈 瘤開撈 酒囪 版快)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -