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

📄 field.cpp

📁 奇迹世界 部分源代码奇迹世界 部分源代码奇迹世界 部分源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:

	// 泅犁 Zone 鸥涝阑 掘绢辑 付阑牢瘤 眉农茄促.
	SERVER_ENV * pServerEnv = g_pGameServer->GetFileParser()->GetServerEnv();
	BOOL bVillage = FALSE;
	if( pServerEnv->bVillageRenderInfo )
	{
		const sMAPINFO *pMapInfo = m_pMap->GetMapInfo()->GetMapInfo();
		bVillage = pMapInfo->byMKind == eZONETYPE_VILLAGE;
	}

	// 脚痹肺 殿厘窍绰 冀磐 贸府
	for( it = m_setEnterSector.begin() ; it != m_setEnterSector.end() ; ++it )
	{
		index = *it;

		if( m_pFieldInfo->GetViewPort() )
		{
			// 货肺款 某腐磐啊 殿厘沁澜阑 冀磐俊 舅妨霖促.
			m_vecTotalSector[index]->SendAddObject( pObject, bVillage );

			// 冀磐狼 沥焊甫 殿厘 某腐磐俊霸 舅妨霖促.
			m_vecTotalSector[index]->SendAddSectorInfo( pObject, bVillage );
		}

		// 冀磐狼 曼炼 敲饭捞绢 荐甫 刘啊矫挪促.
		IncreasePlayerReferenceCount( index, pObject );
	}
}

BOOL Field::WarpObject( Object* pObject, WzVector* pVec)				// Object狼 鞘靛郴 况橇
{
	// 泅犁 谅钎啊 蜡瓤茄瘤 眉农
	if( !_finite(pVec->x) || !_finite(pVec->y) || !_finite(pVec->z) )
	{
		SUNLOG( eCRITICAL_LOG,  "[Field::WarpObject] CurPos is Invalid! x[%f] y[%f] z[%f]", pVec->x, pVec->y, pVec->z );
		return FALSE;
	}

	Character* pCharacter = static_cast<Character*>(pObject);

	// 况橇且 荐 乐绰 困摹牢瘤 八荤 鞘夸!!!

	pCharacter->SetPos(pVec);
	return TRUE;
}

VOID Field::TeleportObject( Object * pObject, WzVector * pVec )
{
	// 泅犁 谅钎啊 蜡瓤茄瘤 眉农
	if( !_finite(pVec->x) || !_finite(pVec->y) || !_finite(pVec->z) )
	{
		SUNLOG( eCRITICAL_LOG,  "[Field::TeleportObject] CurPos is Invalid! x[%f] y[%f] z[%f]", pVec->x, pVec->y, pVec->z );
		return;
	}

	pObject->SetPos( pVec );

	MSG_CG_MAP_TELEPORT_BRD msg;
	msg.m_byCategory = CG_MAP;
	msg.m_byProtocol = CG_MAP_TELEPORT_BRD;
	msg.m_dwObjectKey = pObject->GetObjectKey();
	msg.vPos = *pVec;

	// 林函 坷宏璃飘俊 焊郴淋
	SendPacketAround( pObject->GetSectorIndex(), &msg, sizeof(msg) );

	// 捞悼 傈 冀磐 牢郸胶
	DWORD dwPrevSectorIndex = pObject->GetSectorIndex();

	// 捞悼 饶 冀磐 牢郸胶
	DWORD dwAfterSectorIndex = GetSectorIndex( pVec );

	// Sector啊 函版登菌阑 版快
	if( dwPrevSectorIndex != dwAfterSectorIndex )
	{
		pObject->SetOldSectorIndex( dwPrevSectorIndex );
		pObject->SetSectorIndex( dwAfterSectorIndex );
		ChangeSector( pObject );
	}
}

DWORD Field::GetSectorIndex(WzVector* pwzVec)
{
	ASSERT( m_pFieldInfo );
	if( !m_pFieldInfo )	return 0;

	return m_pFieldInfo->GetSectorIndexFor( pwzVec );
}

BOOL Field::IsMovableCoordinates( WzVector* pwzVec )
{
	if( !m_pFieldInfo )	return FALSE;

	if( !m_pFieldInfo->IsValidCoordinates(pwzVec) ) 
	{
		SUNLOG( eCRITICAL_LOG, "[IsMovableCoordinates] InValid Coordinates" );
		return FALSE;
	}

	DWORD dwXIndex = 0;
	DWORD dwYIndex = 0;
	m_pFieldInfo->GetSectorIndexFor( pwzVec, dwXIndex, dwYIndex );

	// X,Y谅钎惑俊辑 弥措蔼焊促 奴 蔼阑 努扼捞攫飘俊辑 焊辰 版快
	if( ( m_dwSectorXNum < dwXIndex ) || ( m_dwSectorYNum < dwYIndex ) )
	{
		SUNLOG( eCRITICAL_LOG, "[IsMovableCoordinates] InValid SectorXIndex[%d/%d] SectorYIndex[%d/%d]", dwXIndex, m_dwSectorXNum, dwYIndex, m_dwSectorYNum );
		return FALSE;
	}

	SetActiveRoom();

	// 甘惑俊辑 捞悼 啊瓷茄 谅钎牢瘤 八荤
	if( GetWorldBase()->x_pPathFinder->GetTileToStand( *pwzVec, NULL, -1.0f, 100.0f ) == -1 )
	{
		SUNLOG( eCRITICAL_LOG, "GetTileToStand -1 Error!!");
		return FALSE;
	}

	return TRUE;
}


Sector * Field::GetSector( DWORD dwSectorIndex )
{
	if( dwSectorIndex >= m_vecTotalSector.size() )
	{
		ASSERT( ! "[Field::GetSector] Invalid SectorIndex!" );
		SUNLOG( eCRITICAL_LOG, "[Field::GetSector] Invalid SectorIndex[%d/%d]", dwSectorIndex, m_vecTotalSector.size() );
		return NULL;
	}

	return m_vecTotalSector[dwSectorIndex];
}

#include "PublicMath.h"

BOOL Field::FindPath( Character *pChar, WzVector *pwvDest )
{
	if( NULL == pChar )		return FALSE;
	if( NULL == pwvDest )	return FALSE;

	// 某腐磐啊 捞悼啊瓷茄 惑怕牢瘤 眉农
	if( !pChar->CanMove() )	return FALSE;

	// 捞悼啊瓷茄 谅钎牢瘤 眉农
	if( !m_pFieldInfo->IsValidCoordinates(pwvDest) ) return FALSE;

	// 唱吝俊 TestExplorer绰 瘤匡 荐 乐档废 浚柳阑 官层霖促绊 沁澜 -_-;
	CPathExplorer*	pPathExplorer = pChar->GetPathExplorer();

	SetActiveRoom();
	int iTileIndex = GetWorldBase()->x_pPathFinder->GetTileToStand( *pwvDest, NULL, -1.0f, 100.0f );
	if( iTileIndex == -1 )	
	{
		SUNLOG( eCRITICAL_LOG,  "[Field::FindPath] GetTileToStand -1 惯积!! " );
		return FALSE;
	}
		
	// 格利瘤 鸥老俊 痢橇 加己捞芭唱 哎 荐 绝绰 镑捞搁 弊成 府畔茄促.
	WORD wTileAttr = GetWorldBase()->x_pPathFinder->GetAttribute( iTileIndex );
	if( wTileAttr & (PTA_ONLY_JUMP |  PTA_NO_WALK) )
	{
//		SUNLOG( eFULL_LOG, "Field => FindPath => GetAttribute return!! " );
		return FALSE;
	}

	// 叼弃飘 捞悼 力距 鸥老
	WORD wAttr = PTA_ONLY_JUMP | PTA_NO_WALK;

	// 痢橇且 荐 乐绰 NPC扼搁 FindPath矫 捞悼 力距 加己俊辑 痢橇 鸥老阑 哗霖促.
	if( ( pChar->GetObjectType() & NPC_OBJECT ) == NPC_OBJECT )
	{		
		NPC *pNPC = static_cast<NPC*>( pChar );
		if( pNPC->GetBaseInfo()->m_bJump )
		{
			wAttr &= (~PTA_ONLY_JUMP);
		}
	}

	// 烙矫... 穿备扼档 痢橇 鸥老 困甫 吧阑 荐 乐促.
	wAttr &= (~PTA_ONLY_JUMP);

/*	LARGE_INTEGER freq;
	QueryPerformanceFrequency(&freq);
	LARGE_INTEGER firstcounter,nextcounter;

	QueryPerformanceCounter(&firstcounter);

	WzVector CurPos = GetWorldBase()->GetRandomPosInTile( 156 );
	pChar->SetPos( &CurPos );
	*pwvDest = GetWorldBase()->GetRandomPosInTile( 708 );
	iTileIndex = 708;*/

	if( !GetWorldBase()->PathExp_FindPath( pPathExplorer, *pwvDest, iTileIndex, wAttr ) )
	{
/*		QueryPerformanceCounter(&nextcounter);

		__int64  elapsedclock = nextcounter.QuadPart - firstcounter.QuadPart;
		__int64  elapsedmillsecond = elapsedclock * 1000000 / freq.QuadPart;

		if( elapsedmillsecond >= 1 )
		{
			char szLog[256];
			WzVector vCurPos;	pChar->GetPos( &vCurPos );

			int iRoute[MAX_PATH_ROUTE];
			int iRouteLength = pPathExplorer->GetTileRoute(iRoute);
			
			float fDistance = Math_VectorLength( vCurPos, *pwvDest );
			sprintf( szLog, "[PathExp_FindPath Fail] CurTile[%d] DestTile[%d] Distance[%f] Tick[%I64d] RouteLength[%d]", 
				pPathExplorer->GetTile(), iTileIndex, fDistance, elapsedmillsecond, iRouteLength);

			LogToFile( "FindPath_Release.txt", szLog );
		}*/

		return FALSE;
	}

/*	QueryPerformanceCounter(&nextcounter);

	__int64  elapsedclock = nextcounter.QuadPart - firstcounter.QuadPart;
	__int64  elapsedmillsecond = elapsedclock * 1000000 / freq.QuadPart;

	if( elapsedmillsecond >= 1 )
	{
		char szLog[256];
		WzVector vCurPos;	pChar->GetPos( &vCurPos );
		float fDistance = Math_VectorLength( vCurPos, *pwvDest );
		int iRoute[MAX_PATH_ROUTE];
		int iRouteLength = pPathExplorer->GetTileRoute(iRoute);

		sprintf( szLog, "[PathExp_FindPath Success] CurTile[%d] DestTile[%d] Distance[%f] Tick[%I64d] RouteLength[%d]", 
			pPathExplorer->GetTile(), iTileIndex, fDistance, elapsedmillsecond, iRouteLength );

		LogToFile( "FindPath_Release.txt", szLog );
	}*/
	//numTiles = pPathExplorer->GetTileRoute( piTileRoute );

	return TRUE;
}

BOOL Field::FindPathThrust( Character *pChar, WzVector *pwvMoveDistance, BOOL bForcedMove )
{
	// 某腐磐啊 捞悼啊瓷茄 惑怕牢瘤 眉农
	if( !bForcedMove && !pChar->CanMove() )			return FALSE;

	// 捞悼啊瓷茄 谅钎牢瘤 眉农
	WzVector vCurPos, vDestPos;
	pChar->GetPos( &vCurPos );
	vDestPos = vCurPos + *pwvMoveDistance;
	if( !m_pFieldInfo->IsValidCoordinates(&vDestPos) ) return FALSE;

	int iTileIndex = pChar->GetPathExplorer()->GetTile();
	if( -1 == iTileIndex)
	{
		return FALSE;
	}

	// 叼弃飘 捞悼 力距 鸥老
	WORD wAttr = PTA_ONLY_JUMP | PTA_NO_WALK;

	// 痢橇且 荐 乐绰 NPC扼搁 FindPath矫 捞悼 力距 加己俊辑 痢橇 鸥老阑 哗霖促.
	if( ( pChar->GetObjectType() & NPC_OBJECT ) == NPC_OBJECT )
	{		
		NPC *pNPC = static_cast<NPC*>( pChar );
		if( pNPC->GetBaseInfo()->m_bJump )
		{
			wAttr &= (~PTA_ONLY_JUMP);
		}
	}

	// 烙矫... 穿备扼档 痢橇 鸥老 困甫 吧阑 荐 乐促.
	wAttr &= (~PTA_ONLY_JUMP);

	SetActiveRoom();

	if( EFR_FAILURE == GetWorldBase()->PathExp_Thrust( pChar->GetPathExplorer(), pwvMoveDistance, wAttr ))
	{
		return FALSE;
	}

	return TRUE;
}

Character*	Field::FindCharacter( DWORD dwObjectKey )
{
	NPC* pNPC = FindNPC(dwObjectKey);
	if (pNPC != NULL)
	{
		return pNPC;
	}

	// 敲饭捞绢 府胶飘吝俊辑 矫具郴俊 甸绢坷绰 利捞 乐绰瘤 八荤
	Sector *pSector;	SectorGroup *pSectorGroup;
	for( SECTORGROUP_ITERATOR it = m_pSectorGroupList->Begin(); it != m_pSectorGroupList->End(); ++it )
	{
		pSectorGroup = *it;
		if( !pSectorGroup->GetReferenceCount() )	continue;

		for( SECTOR_ITERATOR itr = pSectorGroup->Begin(); itr != pSectorGroup->End(); ++itr )
		{
			pSector = *itr;
			Object* pObject = pSector->FindObject( PLAYER_OBJECT, dwObjectKey );
			if ( pObject )
			{
				return dynamic_cast<Character*>(pObject);
			}
		}
	}

	return NULL;
}


NPC* Field::FindNPC( DWORD dwObjectKey )
{
	return (NPC*)m_pNPCList->Find( dwObjectKey );
}

BOOL Field::AddNPC( NPC* pNPC )
{
	SASSERT( pNPC != NULL, "[Field::AddNPC] pSector == pNPC" );
	return m_pNPCList->Add( pNPC );
}

BOOL Field::RemoveNPC( NPC* pNPC )
{
	SASSERT( pNPC != NULL, "[Field::RemoveNPC] pSector == pNPC" );
	return m_pNPCList->Remove( pNPC ) != NULL;
}

BOOL Field::CreateNPC( eOBJECT_TYPE eObjectType, DWORD dwCode, DWORD dwNumberOfNPC, WzVector* pvPos, DWORD dwAreaID, DWORD dwGroupID )
{
	BASE_NPCINFO* pBaseNPCInfo = NPCInfoParser::Instance()->GetMonsterInfo( dwCode );
	if( NULL == pBaseNPCInfo )
	{
		SUNLOG( eFULL_LOG,  "[Field::CreateNPC] 积己窍绊磊 窍绰 阁胶磐 内靛啊 胶农赋飘俊 绝嚼聪促.(%d)", dwCode );
		return FALSE;
	}

	// 秦寸窍绰 弊缝阑 茫芭唱 绝栏搁 货肺 弊缝阑 且寸
	ObjectGroup *pObjectGroup = NULL;
	if( dwAreaID && dwGroupID )
	{
		pObjectGroup = AllocGroup( dwAreaID, dwGroupID );
	}

	// 阁胶磐 积己
	for( DWORD i = 0; i < dwNumberOfNPC; ++i )
	{
		NPC *pNPC = (NPC*)ObjectFactory::Instance()->AllocObject( eObjectType );
		ASSERT(pNPC);

		pNPC->SetBaseInfo( pBaseNPCInfo );
//		pNPC->SetObjectKey( g_pGameServer->AllocMonsterObjectKey() );

		EnterField( pNPC, pvPos );

		// 积己等 NPC甫 Group俊 殿废茄促.
		if( pObjectGroup )
		{
			pObjectGroup->AddObject( eObjectType, pNPC, dwCode );
			pNPC->JoinGroup( pObjectGroup );
		}
	}
	return TRUE;
}

// 规氢 爱绰 阁胶磐 积己
BOOL Field::CreateNPC_Dir( eOBJECT_TYPE eObjectType, DWORD dwCode, DWORD dwNumberOfNPC, WzVector* pvPos, DWORD dwAreaID, DWORD dwGroupID, WORD wAngle )
{
	BASE_NPCINFO* pBaseNPCInfo = NPCInfoParser::Instance()->GetMonsterInfo( dwCode );
	if( NULL == pBaseNPCInfo )
	{
		SUNLOG( eFULL_LOG,  "[Field::CreateNPC] 积己窍绊磊 窍绰 阁胶磐 内靛啊 胶农赋飘俊 绝嚼聪促.(%d)", dwCode );
		return FALSE;
	}

	// 秦寸窍绰 弊缝阑 茫芭唱 绝栏搁 货肺 弊缝阑 且寸
	ObjectGroup *pObjectGroup = NULL;
	if( dwAreaID && dwGroupID )
	{
		pObjectGroup = AllocGroup( dwAreaID, dwGroupID );
	}

	// 阁胶磐 积己
	for( DWORD i = 0; i < dwNumberOfNPC; ++i )
	{
		NPC *pNPC = (NPC*)ObjectFactory::Instance()->AllocObject( eObjectType );
		ASSERT(pNPC);

		pNPC->SetBaseInfo( pBaseNPCInfo );
//		pNPC->SetObjectKey( g_pGameServer->AllocMonsterObjectKey() );

		EnterField_Dir( pNPC, pvPos, wAngle );

		// 积己等 NPC甫 Group俊 殿废茄促.
		if( pObjectGroup )
		{
			pObjectGroup->AddObject( eObjectType, pNPC, dwCode );
			pNPC->JoinGroup( pObjectGroup );
		}
	}
	return TRUE;
}

VOID Field::DestroyAllNPC()
{
/*	VEC_SECTOR_ITR it;

	for( it = m_vecTotalSector.begin(); it != m_vecTotalSector.end(); ++it )
	{

⌨️ 快捷键说明

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