?? fieldinfo.cpp
字號:
#include "stdafx.h"
#include "FieldInfo.h"
#include "FieldServer.h"
#include <ProgramCommon/WzArchive.h>
#include <Macro.h>
#include <3DEngine/IncludeAll_NewWorld.h>
#include <3DEngine/3DTerrain/WorldBase.h>
#include <ProgramCommon/DiscAccess.h>
#include "TriggerGroupInfoList.h"
////////////////////////////////////////////////////////////////////////////////////
// MapInfo class
////////////////////////////////////////////////////////////////////////////////////
MapInfo::MapInfo():
m_pMapInfo ( NULL )
{
m_FieldInfoHashTable.Initialize( _MAX_FIELD_IN_MAP_NUM );
}
MapInfo::~MapInfo()
{
m_FieldInfoHashTable.RemoveAll();
}
VOID MapInfo::AddFieldInfo( FieldInfo * pFieldInfo )
{
m_FieldInfoHashTable.Add( pFieldInfo, pFieldInfo->GetFieldCode() );
}
////////////////////////////////////////////////////////////////////////////////////
// FieldInfo class
////////////////////////////////////////////////////////////////////////////////////
FieldInfo::FieldInfo():
m_pWorldBase ( NULL ),
m_dwTotalSectorNum ( 0 ),
m_ppSectorInfo( NULL ),
m_pFieldInfo ( NULL ),
m_pTriggerGroupInfoList( NULL )
{
m_pMapObjectInfoHashTable = new util::SolarHashTable<MAPOBJECT_INFO *>;
m_pMapObjectInfoHashTable->Initialize( _MAX_MAPOBJECT_INFO_NUM );
}
FieldInfo::~FieldInfo()
{
for( DWORD i = 0 ; i < m_dwTotalSectorNum ; ++i )
{
SAFE_DELETE( m_ppSectorInfo[i] );
}
SAFE_DELETE_ARRAY( m_ppSectorInfo );
Destroy();
SAFE_DELETE( m_pMapObjectInfoHashTable );
SAFE_DELETE( m_pTriggerGroupInfoList );
}
VOID FieldInfo::Create( const sFIELDINFO * pInfoIn )
{
SetFieldInfo( pInfoIn );
ASSERT( m_pTriggerGroupInfoList == NULL );
m_pTriggerGroupInfoList = new TriggerGroupInfoList;
ASSERT(!m_pWorldBase);
m_pWorldBase = (CWorldBase *)g_pGameServer->m_fnContactTerrain( CT_NEW_WORLD, 0 );
m_pWorldBase->Create();
}
INT FieldInfo::Init()
{
return m_pWorldBase->x_pRoomManager->DuplicateRoomInfo();
}
VOID FieldInfo::Release( INT Index )
{
BOOL rt = m_pWorldBase->x_pRoomManager->DestroyRoomInfo(Index);
ASSERT( rt );
}
///< FieldInfo甫 佬籃 促瀾, SectorSize俊 蝶弗 SectorInfo甫 悸潑
VOID FieldInfo::EstablishSectorInfo( WORD wSectorSize, BOOL bViewport )
{
if(wSectorSize == 0)
ASSERT( !"冀磐 牢鄲膠啊 0撈促" );
m_dwSectorSize = wSectorSize;
m_bViewport = bViewport;
BvAABB bdv = m_pWorldBase->GetTerrainSize();
// 彌措藹撈 瀾薦老薦檔 樂欄骨肺 例措藹欄肺 拌魂
DWORD XSize = 0, YSize = 0;
XSize = (DWORD)abs(bdv.m_wvMax.x - bdv.m_wvMin.x);
YSize = (DWORD)abs(bdv.m_wvMax.y - bdv.m_wvMin.y);
// 冀磐 牢鄲膠甫 拌魂竅扁 困茄 函薦
m_iShiftMinX = (int)(bdv.m_wvMin.x);
m_iShiftMinY = (int)(bdv.m_wvMin.y);
m_iShiftMaxX = (int)(bdv.m_wvMax.x);
m_iShiftMaxY = (int)(bdv.m_wvMax.y);
BYTE byMarginX = 0, byMarginY = 0;
XSize % wSectorSize == 0 ? byMarginX = 0 : byMarginX = 1;
YSize % wSectorSize == 0 ? byMarginY = 0 : byMarginY = 1;
m_dwSectorXNum = XSize / wSectorSize + byMarginX;
m_dwSectorYNum = YSize / wSectorSize + byMarginY;
m_dwTotalSectorNum = m_dwSectorXNum * m_dwSectorYNum;
m_ppSectorInfo = new SectorInfo*[ m_dwSectorXNum * m_dwSectorYNum ];
memset( m_ppSectorInfo, 0, sizeof(SectorInfo *) * m_dwSectorXNum * m_dwSectorYNum );
/// 泅犁, 葛電 Sector啊 糧犁茄促絆 啊瀝
DWORD dwSectorIndex = 0;
for( dwSectorIndex = 0 ; dwSectorIndex < m_dwTotalSectorNum ; ++dwSectorIndex )
{
m_ppSectorInfo[ dwSectorIndex ] = new SectorInfo( dwSectorIndex );
}
/// 撈眶竅綽 sector甫 楷搬
for( dwSectorIndex = 0 ; dwSectorIndex < m_dwTotalSectorNum ; ++dwSectorIndex )
{
// 秦寸 冀磐狼 青苞 凱闌 備茄促.
DWORD dwRow = dwSectorIndex / m_dwSectorXNum; // Index_Y
DWORD dwColumn = dwSectorIndex % m_dwSectorXNum; // Index_X
for( int i = -1; i <= 1; ++i )
{
int iNeighborColumn = dwColumn + i;
if( iNeighborColumn < 0 || iNeighborColumn >= (int)m_dwSectorXNum ) continue;
for( int j = -1; j <= 1; ++j )
{
int iNeighborRow = dwRow + j;
if( iNeighborRow < 0 || iNeighborRow >= (int)m_dwSectorYNum ) continue;
int index = iNeighborRow * m_dwSectorXNum + iNeighborColumn;
if( dwSectorIndex == index ) continue;
if( !m_ppSectorInfo[index] ) continue;
m_ppSectorInfo[dwSectorIndex]->AddNeighborSectorInfo( m_ppSectorInfo[index] );
}
}
}
}
BOOL FieldInfo::IsValidCoordinates( WzVector* pwzVec )
{
// X,Y諒釬惑俊輯 彌家藹焊促 累籃 藹闌 努扼撈攫飄俊輯 焊辰 版快
if( ( m_iShiftMinX > pwzVec->x ) || ( m_iShiftMinY > pwzVec->y ) )
{
return FALSE;
}
if( ( m_iShiftMaxX < pwzVec->x ) || ( m_iShiftMaxY < pwzVec->y ) )
{
return FALSE;
}
return TRUE;
}
// Client俊輯 逞絹柯 諒釬甫 啊瘤絆 秦寸竅綽 牢鄲膠甫 掘絹咳
DWORD FieldInfo::GetSectorIndexFor( WzVector * pwzVec )
{
DWORD dwXIndex = 0;
DWORD dwYIndex = 0;
if( IsValidCoordinates( pwzVec ) )
{
GetSectorIndexFor( pwzVec, dwXIndex, dwYIndex );
}
ASSERT( dwXIndex + m_dwSectorXNum * dwYIndex < m_dwTotalSectorNum );
return ( dwXIndex + m_dwSectorXNum * dwYIndex );
}
VOID FieldInfo::GetSectorIndexFor( WzVector * pwzVec, DWORD & dwXIndexOut, DWORD & dwYIndexOut )
{
dwXIndexOut = (DWORD)( pwzVec->x - m_iShiftMinX ) / GetSectorSize();
dwYIndexOut = (DWORD)( pwzVec->y - m_iShiftMinY ) / GetSectorSize();
}
VOID FieldInfo::Destroy()
{
_unloadMapObjectInfo();
if( m_pTriggerGroupInfoList )
m_pTriggerGroupInfoList->Unload();
if( m_pWorldBase )
{
m_pWorldBase->Destroy( NULL );
g_pGameServer->m_fnContactTerrain( CT_DELETE_WORLD, m_pWorldBase );
m_pWorldBase = NULL;
}
}
#include <io.h>
BOOL FieldInfo::Load()
{
CWzArchive archive;
CDiscAccess cda;
cda.Create();
//m_pWorldBase->SetDiscAccess(&cda);
ASSERT(_access(m_pFieldInfo->pszPath,0)!=-1);
if( archive.LoadFile( const_cast<char *>(m_pFieldInfo->pszPath) ) == FALSE )
{
SUNLOG( eCRITICAL_LOG, "[FieldInfo::Load] Failed LoadFile() : From Fieldxx.map[%s]\n", m_pFieldInfo->pszPath );
archive.Close();
return FALSE;
}
if( m_pWorldBase->Serialize( &archive ) == FALSE )
{
archive.Close();
return FALSE;
}
_loadMapObjectInfo( archive );
// 飄府芭 瀝焊 肺爹
m_pTriggerGroupInfoList->Load( archive );
//_loadAreaInfo( archive );
archive.Close();
SetStartingTileIndex();
// 操坷 拋膠飄儈 林籍
/*CPathExplorer *pExplorer;
pExplorer = (CPathExplorer*)g_pGameServer->m_fnContactTerrain( CT_NEW_PATH_EXPLORER, 0);
WzVector vPos;
vPos.x = 7.6181059f;
vPos.y = 23.331070f;
vPos.z = 14.0f;
m_pWorldBase->PathExp_Reset(pExplorer,&vPos);
g_pGameServer->m_fnContactTerrain( CT_DELETE_PATH_EXPLORER, pExplorer);*/
return TRUE;
}
VOID FieldInfo::_loadMapObjectInfo( CWzArchive & archive )
{
BOOL bAreaChunk = FALSE;
while( TRUE )
{
St_ChunkInfo ci = archive.ReadChunk();
if( ci.m_nID == 0x1781 )
{
bAreaChunk = TRUE;
break;
}
archive.SkipCurrentChunk(ci);
}
ASSERT( TRUE == bAreaChunk );
DWORD dwNumbers = 0;
DWORD dwDummy = 0;
// WZU扒呈訛
archive >> dwNumbers;
char pszUnitFileFullPath[0xff];
for( DWORD j = 0 ; j < dwNumbers ; ++j )
{
archive.ReadName( pszUnitFileFullPath );
archive >> dwDummy;
}
// 咆膠媚 扒呈訛
archive >> dwNumbers;
for ( j = 0; j < dwNumbers; ++j )
{
archive >> dwDummy;
archive.ReadName( pszUnitFileFullPath );
}
MAPOBJECT_INFO * pObject = NULL;
// 角力 甘坷宏璃飄
archive >> dwNumbers;
for( DWORD i = 0 ; i < dwNumbers ; ++i )
{
pObject = new MAPOBJECT_INFO;
//pObject->dwMapObjectID = MAP_OBJECT_KEY+i; //< 努扼撈攫飄客 措開闌 嘎苗拎具 茄促.
pObject->dwMapObjectID = i;
archive >> pObject->wzId
>> pObject->dwAttribute
>> pObject->wvPos
>> pObject->wzRot
>> pObject->wzScale
>> pObject->wzBV;
if(archive.GetVersion() >= 138)
{
archive >> dwDummy;
}
DWORD dwCustom[4];
if( archive.GetVersion() >= 158)
{
archive >> dwCustom[0];
archive >> dwCustom[1];
archive >> dwCustom[2];
archive >> dwCustom[3];
}
ASSERT( NULL == m_pMapObjectInfoHashTable->GetData( pObject->dwMapObjectID ) );
m_pMapObjectInfoHashTable->Add( pObject, pObject->dwMapObjectID );
}
}
/*
VOID FieldInfo::_loadAreaInfo( CWzArchive & archive )
{
//------------------------------------------------------------------------------------
//
if( archive.GetVersion() < 140 ) return;
if( archive.GetVersion() > 143 ) return;
BOOL bAreaChunk = FALSE;
while( TRUE )
{
St_ChunkInfo ci = archive.ReadChunk();
if( ci.m_nID == 0x1785 )
{
bAreaChunk = TRUE;
break;
}
archive.SkipCurrentChunk(ci);
}
if( TRUE != bAreaChunk ) return;
// 康開 俺薦
WORD wNumberOfAreas = 0;
BYTE byAreaType = 0;
WzID wzAreaID = 0;
archive >> wNumberOfAreas;
ASSERT( wNumberOfAreas < 1000 );
DEBUG_CODE( if(wNumberOfAreas >= 1000) return; );
for( DWORD idx = 0 ; idx < wNumberOfAreas ; ++idx )
{
archive >> byAreaType;
archive >> wzAreaID;
if( byAreaType == AREA_INFO::AREA_AABB )
{
AABB_AREA_INFO * pAreaInfo = new AABB_AREA_INFO;
pAreaInfo->dwKey = idx;
pAreaInfo->byAreaType = byAreaType;
pAreaInfo->wzAreaID = wzAreaID;
archive >> pAreaInfo->bvAABB;
//m_pAreaInfoHashTable->Add( pAreaInfo, pAreaInfo->wzAreaID );
m_pAreaInfoHashTable->Add( pAreaInfo, pAreaInfo->dwKey );
}
else
{
TILE_AREA_INFO * pAreaInfo = new TILE_AREA_INFO;
pAreaInfo->dwKey = idx;
pAreaInfo->byAreaType = byAreaType;
pAreaInfo->wzAreaID = wzAreaID;
archive >> pAreaInfo->wNumberOfTiles;
pAreaInfo->piTileIndex = new int[pAreaInfo->wNumberOfTiles];
memset( pAreaInfo->piTileIndex, 0, sizeof(int) * pAreaInfo->wNumberOfTiles );
WORD wTileAttr; int iTileIndex = 0; WORD wValidateTiles = 0;
for( WORD i = 0 ; i < pAreaInfo->wNumberOfTiles ; ++i )
{
if( !m_pWorldBase ) continue;
archive >> iTileIndex;
wTileAttr = m_pWorldBase->x_pPathFinder->GetAttribute( iTileIndex );
if( wTileAttr & PTA_NO_WALK )
{
continue;
}
pAreaInfo->piTileIndex[wValidateTiles] = iTileIndex;
++wValidateTiles;
}
pAreaInfo->wNumberOfTiles = wValidateTiles;
m_pAreaInfoHashTable->Add( pAreaInfo, pAreaInfo->dwKey );
}
}
}
*/
VOID FieldInfo::_unloadMapObjectInfo()
{
MAPOBJECT_INFO * pDelNode = NULL;
m_pMapObjectInfoHashTable->SetFirst();
while( (pDelNode = m_pMapObjectInfoHashTable->GetNext()) != NULL )
{
SAFE_DELETE( pDelNode );
}
m_pMapObjectInfoHashTable->RemoveAll();
}
/*
VOID FieldInfo::_unloadAreaInfo()
{
AREA_INFO * pDelNode = NULL;
m_pAreaInfoHashTable->SetFirst();
while( (pDelNode = m_pAreaInfoHashTable->GetNext()) != NULL )
{
SAFE_DELETE( pDelNode );
}
m_pAreaInfoHashTable->RemoveAll();
}
*/
VOID FieldInfo::SetStartingTileIndex()
{
m_StartTiles.clear();
for( int i = '0' ; i <= '9' ; ++i )
{
WzSpecialArea * pArea = m_pWorldBase->GetSpecialArea( CharToWzID('S','T','R',i) );
if( !pArea ) continue;
ASSERT( pArea->m_wbvRegion.m_eBvType == BVT_PATH_TILE_INDEX );
ASSERT( pArea->m_wbvRegion.m_BvPathTileIndex.m_nCount != 0 );
for( DWORD j = 0 ; j < pArea->m_wbvRegion.m_BvPathTileIndex.m_nCount ; ++j )
m_StartTiles.push_back( pArea->m_wbvRegion.m_BvPathTileIndex.m_pdwData[j] );
}
for( int i = 'A' ; i <= 'Z' ; ++i )
{
WzSpecialArea * pArea = m_pWorldBase->GetSpecialArea( CharToWzID('S','T','R', i) );
if( !pArea ) continue;
ASSERT( pArea->m_wbvRegion.m_eBvType == BVT_PATH_TILE_INDEX );
ASSERT( pArea->m_wbvRegion.m_BvPathTileIndex.m_nCount != 0 );
for( DWORD j = 0 ; j < pArea->m_wbvRegion.m_BvPathTileIndex.m_nCount ; ++j )
m_StartTiles.push_back( pArea->m_wbvRegion.m_BvPathTileIndex.m_pdwData[j] );
}
}
DWORD FieldInfo::GetRandomStartingTileIndex()
{
// 罰待 寂敲
ASSERT( m_StartTiles.size() != 0 );
random_shuffle( m_StartTiles.begin(), m_StartTiles.end() );
return *(m_StartTiles.begin());
}
TriggerGroupInfo * FieldInfo::GetTriggerGroupInfo( const TCHAR * pszGroupName )
{
return m_pTriggerGroupInfoList->GetGroupInfo( pszGroupName );
}
BOOL FieldInfo::CheckMapVersion( DWORD dwCheckSum )
{
if( m_pWorldBase->GetCheckSum() != dwCheckSum )
{
return FALSE;
}
else
{
if( 0 == dwCheckSum)
{
// 0牢 版快綽 備滾傈 甘!!
return FALSE;
}
return TRUE;
}
}
////////////////////////////////////////////////////////////////////////////////////
// SectorInfo class
////////////////////////////////////////////////////////////////////////////////////
SectorInfo::SectorInfo( DWORD index )
: m_dwSectorIndex ( index ),
m_NeighborSectorInfo ( MAX_NEIGHBOR_SECTOR_NUM )
{
}
SectorInfo::~SectorInfo()
{
}
VOID SectorInfo::AddNeighborSectorInfo( SectorInfo * pSectorInfo )
{
m_NeighborSectorInfo.AddTail( pSectorInfo );
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -