⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 map.cpp

📁 韩国英雄王座倒闭后流出来部分源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
////////////////////////////////////////////////////////////////////////////////////////
//	Map.cpp : implementation file
//
//
//	-	Memory Pool篮 ServerMem Class肺 包访 内靛甫 捞傈矫糯
////////////////////////////////////////////////////////////////////////////////////////

#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蔼 秦力窍绰 版快 坷幅 贸府 
	//	--------------------------------------------------------------------------------


	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)贸府 风凭阑 眠啊 矫糯	  
//	PC/NCP Handle贸府俊 包茄 绊刮 
////////////////////////////////////////////////////////////////////////////////////////
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;

	//	--------------------------------------------------------------------------------
	//	捞悼且 困摹甫 崔曝捞 葛胆肺 秦寸 困摹俊 沥焊甫 扁废 矫糯	
	//	--------------------------------------------------------------------------------
	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鳖瘤 贸府 窍瘤 给茄 版快
		if( nLevel > 10 ) return -1;
	}

	return	nLevel;
}



////////////////////////////////////////////////////////////////////////////////////////
//	框流老荐 绝绰瘤 咯何 魄傈
//
//	- 框流 老荐 乐绰瘤 咯何 魄沥 (Tile 犬牢)
//	- 框流老荐 乐绰 困摹咯何 犬牢 (救傈 瘤开捞 酒囱 版快)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -