📄 maphandler.cpp
字号:
[老磊][荐沥磊] : 荐沥郴侩
*******************************************************************************************************************/
VOID CMapHandler::DrawBaseTile(INT nX, INT nY)
{
INT nFileIdx;
INT nImgIdx;
if ( nX >= m_stMapFileHeader.shWidth || nY >= m_stMapFileHeader.shHeight || nX < 0 || nY < 0 )
return;
if( !( nX % 2 ) && !( nY % 2 ) && nY < m_shStartViewTileY+_VIEW_CELL_Y_COUNT )
{
nFileIdx= m_pstTileInfo[(nY/2) + (nX/2)*m_stMapFileHeader.shHeight/2].bFileIdx;
nImgIdx = m_pstTileInfo[(nY/2) + (nX/2)*m_stMapFileHeader.shHeight/2].wTileIdx;
if( nFileIdx != 255 && nImgIdx != 65535 )
{
m_pxTileImg[nFileIdx]->NewSetIndex(nImgIdx);
g_xMainWnd.DrawWithImageForCompMemToMem(
(nX-m_shStartViewTileX)*_CELL_WIDTH ,
(nY-m_shStartViewTileY)*_CELL_HEIGHT,
m_pxTileImg[nFileIdx]->m_lpstNewCurrWilImageInfo->shWidth,
m_pxTileImg[nFileIdx]->m_lpstNewCurrWilImageInfo->shHeight,
(WORD*)m_pxTileImg[nFileIdx]->m_pbCurrImage,
_VIEW_CELL_X_COUNT*_CELL_WIDTH, _VIEW_CELL_Y_COUNT*_CELL_HEIGHT, m_wSavedMapBuffer);
}
}
}
/******************************************************************************************************************
窃荐疙 : CMapHandler::DrawOpenDoor()
累己磊 :
累己老 :
格利 :
涝仿 : INT nX
INT nY
免仿 : VOID
[老磊][荐沥磊] : 荐沥郴侩
*******************************************************************************************************************/
/*VOID CMapHandler::DrawOpenDoor(INT nX, INT nY)
{
if ( GetDoorState(nX, nY) )
{
BYTE bDoorIndex = m_pbCellIDoorIdx[nX + nY*m_stMapFileHeader.shWidth];
for ( INT nCnt = 0; nCnt < m_bDoorCount; nCnt++ )
{
if ( m_pstDoorInfo[nCnt].bDoorIdx == bDoorIndex )
{
for ( INT nLoop = 0; nLoop < m_pstDoorInfo[nCnt].bDoorImgCnt; nLoop++ )
{
WORD wPosX = m_pstDoorInfo[nCnt].pstDoorImgInfo[nLoop].wPosX;
WORD wPosY = m_pstDoorInfo[nCnt].pstDoorImgInfo[nLoop].wPosY;
if ( nX == wPosX && nY == wPosY )
{
WORD wImgIndex = m_pstDoorInfo[nCnt].pstDoorImgInfo[nLoop].wImageNum;
// 弊覆阑 弊赴促.
// ".\\Data\\housesc.wil"
m_pxTileImg[4].NewSetIndex(wImgIndex);
g_xMainWnd.DrawWithImageForCompClipRgn(
(nX-m_shStartViewTileX)*_CELL_WIDTH +_VIEW_CELL_X_START-m_shViewOffsetX,
(nY-m_shStartViewTileY)*_CELL_HEIGHT+_VIEW_CELL_Y_START-m_pxTileImg[4].m_lpstNewCurrWilImageInfo->shHeight+_CELL_HEIGHT-m_shViewOffsetY,
m_pxTileImg[4].m_lpstNewCurrWilImageInfo->shWidth,
m_pxTileImg[4].m_lpstNewCurrWilImageInfo->shHeight,
(WORD*)m_pxTileImg[4].m_pbCurrImage,
_CLIP_WIDTH, _CLIP_HEIGHT);
break;
}
}
}
}
}
}
VOID CMapHandler::SetDoorIndex()
{
for ( INT nCnt = 0; nCnt < m_bDoorCount; nCnt++ )
{
for ( INT nLoop = 0; nLoop < m_pstDoorInfo[nCnt].bDoorImgCnt; nLoop++ )
{
WORD wPosX = m_pstDoorInfo[nCnt].pstDoorImgInfo[nLoop].wPosX;
WORD wPosY = m_pstDoorInfo[nCnt].pstDoorImgInfo[nLoop].wPosY;
m_pbCellIDoorIdx[wPosX + wPosY*m_stMapFileHeader.shWidth] = m_pstDoorInfo[nCnt].bDoorIdx;
}
}
}
BOOL CMapHandler::GetDoorState(INT nX, INT nY)
{
if ( (nX == 432 || nX == 433) && (nY == 70 || nY == 71 ||nY == 72 ) )
int a = 0;
if ( (m_pstCellInfo[nX + nY*m_stMapFileHeader.shWidth].wLigntNEvent == 65535) ||
!(m_pstCellInfo[nX + nY*m_stMapFileHeader.shWidth].wLigntNEvent & 0X08) )
return FALSE;
// 巩捞凯妨乐促.
return TRUE;
}
VOID CMapHandler::SetDoorState(BYTE bIndex, BOOL bDoorOpen)
{
for ( INT nCnt = 0; nCnt < m_bDoorCount; nCnt++ )
{
if ( m_pstDoorInfo[nCnt].bDoorIdx == bIndex )
{
for ( INT nLoop = 0; nLoop < m_pstDoorInfo[nCnt].bDoorImgCnt; nLoop++ )
{
WORD wPosX = m_pstDoorInfo[nCnt].pstDoorImgInfo[nLoop].wPosX;
WORD wPosY = m_pstDoorInfo[nCnt].pstDoorImgInfo[nLoop].wPosY;
if ( bDoorOpen )
m_pstCellInfo[wPosX + wPosY*m_stMapFileHeader.shWidth].wLigntNEvent = m_pstCellInfo[wPosX + wPosY*m_stMapFileHeader.shWidth].wLigntNEvent | 0X08;
else
m_pstCellInfo[wPosX + wPosY*m_stMapFileHeader.shWidth].wLigntNEvent = m_pstCellInfo[wPosX + wPosY*m_stMapFileHeader.shWidth].wLigntNEvent & 0XFFF7;
}
}
}
}
*/
INT CMapHandler::GetDoor(INT nX, INT nY)
{
INT nResult = 0;
if ( (m_pstCellInfo[nY + nX*m_stMapFileHeader.shWidth].bDoorIdx & 0X80) > 0 )
{
nResult = m_pstCellInfo[nY + nX*m_stMapFileHeader.shWidth].bDoorIdx & 0X7F;
}
return nResult;
}
BOOL CMapHandler::IsDoorOpen(INT nX, INT nY)
{
if ( (m_pstCellInfo[nY + nX*m_stMapFileHeader.shWidth].bDoorIdx & 0X80) > 0 )
{
if ( (m_pstCellInfo[nY + nX*m_stMapFileHeader.shWidth].bDoorOffset & 0X80) == 0 )
{
return FALSE;
}
}
return TRUE;
}
VOID CMapHandler::OpenDoor(INT nX, INT nY, INT nIdx)
{
for ( INT nCntY = nY-8; nCntY < nY+10; nCntY++ )
{
for ( INT nCntX = nX-8; nCntX < nX+10; nCntX++ )
{
if ( nCntX >= 0 && nCntY >= 0 && nCntX < m_stMapFileHeader.shWidth && nCntY < m_stMapFileHeader.shHeight )
{
if ( (m_pstCellInfo[nCntY + nCntX*m_stMapFileHeader.shWidth].bDoorIdx & 0X7F) == nIdx )
{
m_pstCellInfo[nCntY + nCntX*m_stMapFileHeader.shWidth].bDoorOffset |= 0X80;
}
}
}
}
}
VOID CMapHandler::CloseDoor(INT nX, INT nY, INT nIdx)
{
for ( INT nCntY = nY-8; nCntY < nY+10; nCntY++ )
{
for ( INT nCntX = nX-8; nCntX < nX+10; nCntX++ )
{
if ( nCntX >= 0 && nCntY >= 0 && nCntX < m_stMapFileHeader.shWidth && nCntY < m_stMapFileHeader.shHeight )
{
if ( (m_pstCellInfo[nCntY + nCntX*m_stMapFileHeader.shWidth].bDoorIdx & 0X7F) == nIdx )
{
m_pstCellInfo[nCntY + nCntX*m_stMapFileHeader.shWidth].bDoorOffset &= 0X7F;
}
}
}
}
}
INT CMapHandler::GetDoorImgIdx(INT nX, INT nY)
{
INT nDoorIdx = 0;
if ( (m_pstCellInfo[nY + nX*m_stMapFileHeader.shWidth].bDoorOffset & 0X80) > 0 )
{
if ( (m_pstCellInfo[nY + nX*m_stMapFileHeader.shWidth].bDoorIdx & 0X7F) > 0 )
nDoorIdx += m_pstCellInfo[nY + nX*m_stMapFileHeader.shWidth].bDoorOffset & 0X7F;
}
return nDoorIdx;
}
/******************************************************************************************************************
窃荐疙 : CMapHandler::SetMovedTileBuffer()
累己磊 :
累己老 :
格利 :
涝仿 : SHORT shMovedTileX
SHORT shMovedTileY
免仿 : VOID
[老磊][荐沥磊] : 荐沥郴侩
*******************************************************************************************************************/
VOID CMapHandler::SetMovedTileBuffer(SHORT shMovedTileX, SHORT shMovedTileY)
{
m_shStartViewTileX += shMovedTileX;
m_shStartViewTileY += shMovedTileY;
m_shViewOffsetX = 0;
m_shViewOffsetY = 0;
INT nX, nY;
// 泅犁 鸥老滚欺俊 乐绰 皋葛府甫 舅嘎霸 捞悼矫虐绊 眠啊登绰弊覆阑 弊赴促.
// 伎窜困啊 酒囱 鸥老窜困肺 诀单捞飘茄促.
// 泅犁 Y鸥老捞芭唱, 酒贰肺 哎锭.
if ( shMovedTileY >= 0 )
{
if ( shMovedTileX >= 0 )
{
// 坷弗率栏肺 哎锭.
for ( INT nYCnt = 0; nYCnt < _VIEW_CELL_Y_COUNT*_CELL_HEIGHT-_CELL_HEIGHT*shMovedTileY; nYCnt++ )
{
memmove(&m_wSavedMapBuffer[(nYCnt*_VIEW_CELL_X_COUNT*_CELL_WIDTH)],
&m_wSavedMapBuffer[((nYCnt+_CELL_HEIGHT*shMovedTileY)*_VIEW_CELL_X_COUNT*_CELL_WIDTH)+_CELL_WIDTH*shMovedTileX],
sizeof(WORD)*_CELL_WIDTH*(_VIEW_CELL_X_COUNT-shMovedTileX));
}
// 弊覆惑栏肺 坷弗率苞 酒贰何盒狼 鸥老阑 盎脚秦拎具茄促.
// 扁夯鸥老篮 2伎肺 捞凤廉乐绊 (坷弗率苞 酒贰绰 1伎父狼 咯蜡)甫 啊瘤扁 锭巩俊 1伎究阑 歹 佬绢拎辑 盎脚阑 矫挪促.
// 酒贰客 鞍篮 屈怕捞促. '1'篮 memmove肺 颗败柳 单捞鸥捞绊 'o'啊 货肺 盎脚矫懦 鸥老弊覆单捞鸥捞促. '0'篮 歹佬绢临 单捞鸥捞促.
// 11111111111111...0o
// 11111111111111...0o
// 11111111111111...0o
// .................0o
// .................0o
// 00000000000000...0o
// oooooooooooooo...oo
// 扁夯鸥老 盎脚.
for ( nX = m_shStartViewTileX+_VIEW_CELL_X_COUNT-shMovedTileX-1; nX < m_shStartViewTileX+_VIEW_CELL_X_COUNT; nX++ )
for ( nY = m_shStartViewTileY; nY < m_shStartViewTileY+_VIEW_CELL_Y_COUNT; nY++ )
{
DrawBaseTile(nX, nY);
}
for ( nX = m_shStartViewTileX; nX < m_shStartViewTileX+_VIEW_CELL_X_COUNT; nX++ )
for ( nY = m_shStartViewTileY+_VIEW_CELL_Y_COUNT-shMovedTileY-1; nY < m_shStartViewTileY+_VIEW_CELL_Y_COUNT; nY++ )
{
DrawBaseTile(nX, nY);
}
}
else
{
// 哭率栏肺 哎锭.
// 哭率苞 酒贰何盒狼 鸥老阑 盎脚.
// o11111111111111...1
// o11111111111111...1
// o11111111111111...1
// o1................1
// o1................1
// o00000000000000...0
// ooooooooooooooo...o
// 扁夯鸥老 盎脚.
// 谅螟篮 2鸥老狼 咯蜡甫 啊瘤骨肺 1伎究父 佬绊, 酒贰肺绰 茄鸥老父狼 咯蜡甫 啊瘤骨肺 酒贰肺绰 1伎究阑 歹 佬绢霖促.
for ( INT nYCnt = 0; nYCnt < _VIEW_CELL_Y_COUNT*_CELL_HEIGHT-_CELL_HEIGHT*shMovedTileY; nYCnt++ )
{
memmove(&m_wSavedMapBuffer[(nYCnt*_VIEW_CELL_X_COUNT*_CELL_WIDTH)+_CELL_WIDTH*(-shMovedTileX)],
&m_wSavedMapBuffer[((nYCnt+_CELL_HEIGHT*shMovedTileY)*_VIEW_CELL_X_COUNT*_CELL_WIDTH)], sizeof(WORD)*_CELL_WIDTH*(_VIEW_CELL_X_COUNT-(-shMovedTileX)));
}
for ( nX = m_shStartViewTileX; nX < m_shStartViewTileX+(-shMovedTileX); nX++ )
for ( nY = m_shStartViewTileY; nY < m_shStartViewTileY+_VIEW_CELL_Y_COUNT; nY++ )
{
DrawBaseTile(nX, nY);
}
for ( nX = m_shStartViewTileX; nX < m_shStartViewTileX+_VIEW_CELL_X_COUNT; nX++ )
for ( nY = m_shStartViewTileY+_VIEW_CELL_Y_COUNT-shMovedTileY-1; nY < m_shStartViewTileY+_VIEW_CELL_Y_COUNT; nY++ )
{
DrawBaseTile(nX, nY);
}
}
}
// 困肺 哎锭.
else
{
if ( shMovedTileX >= 0 )
{
// 坷弗率栏肺 哎锭.
// ooooooooooooo...0o
// 1111111111111...0o
// ................0o
// ................0o
// 1111111111111...0o
// 1111111111111...0o
// 1111111111111...0o
for ( INT nYCnt = (_VIEW_CELL_Y_COUNT*_CELL_HEIGHT)+(_CELL_HEIGHT*shMovedTileY)-1; nYCnt >= 0 ; nYCnt-- )
{
memmove(&m_wSavedMapBuffer[((nYCnt+_CELL_HEIGHT*(-shMovedTileY))*_VIEW_CELL_X_COUNT*_CELL_WIDTH)],
&m_wSavedMapBuffer[(nYCnt*_VIEW_CELL_X_COUNT*_CELL_WIDTH)+_CELL_WIDTH*shMovedTileX], sizeof(WORD)*_CELL_WIDTH*(_VIEW_CELL_X_COUNT-shMovedTileX));
}
for ( nX = m_shStartViewTileX+_VIEW_CELL_X_COUNT-shMovedTileX-1; nX < m_shStartViewTileX+_VIEW_CELL_X_COUNT; nX++ )
for ( nY = m_shStartViewTileY; nY < m_shStartViewTileY+_VIEW_CELL_Y_COUNT; nY++ )
{
DrawBaseTile(nX, nY);
}
for ( nX = m_shStartViewTileX; nX < m_shStartViewTileX+_VIEW_CELL_X_COUNT; nX++ )
for ( nY = m_shStartViewTileY; nY < m_shStartViewTileY+(-shMovedTileY); nY++ )
{
DrawBaseTile(nX, nY);
}
}
else
{
for ( INT nYCnt = (_VIEW_CELL_Y_COUNT*_CELL_HEIGHT)+(_CELL_HEIGHT*shMovedTileY)-1; nYCnt >= 0 ; nYCnt-- )
{
// 哭率栏肺 哎锭.
memmove(&m_wSavedMapBuffer[((nYCnt+_CELL_HEIGHT*(-shMovedTileY))*_VIEW_CELL_X_COUNT*_CELL_WIDTH)+_CELL_WIDTH*(-shMovedTileX)],
&m_wSavedMapBuffer[(nYCnt*_VIEW_CELL_X_COUNT*_CELL_WIDTH)], sizeof(WORD)*_CELL_WIDTH*(_VIEW_CELL_X_COUNT-(-shMovedTileX)));
}
// oooooooooooooo...o
// o1111111111111...1
// o1...............1
// o1...............1
// o1111111111111...1
// o1111111111111...1
// o1111111111111...1
for ( nX = m_shStartViewTileX; nX < m_shStartViewTileX+(-shMovedTileX); nX++ )
for ( nY = m_shStartViewTileY; nY < m_shStartViewTileY+_VIEW_CELL_Y_COUNT; nY++ )
{
DrawBaseTile(nX, nY);
}
for ( nX = m_shStartViewTileX; nX < m_shStartViewTileX+_VIEW_CELL_X_COUNT; nX++ )
for ( nY = m_shStartViewTileY; nY < m_shStartViewTileY+(-shMovedTileY); nY++ )
{
DrawBaseTile(nX, nY);
}
}
}
}
VOID CMapHandler::SetStartViewTile(INT nX, INT nY)
{
m_shStartViewTileX = nX;
m_shStartViewTileY = nY;
m_shViewOffsetX = 0;
m_shViewOffsetY = 0;
}
BYTE CMapHandler::GetTileAttribute(INT nX, INT nY)
{
if ( m_pstCellInfo )
{
BYTE bAttr = _CAN_WALK;
if ( m_pstCellInfo[nY + nX*m_stMapFileHeader.shHeight].bFlag & 0X01 )
return bAttr;
}
return _CAN_NOTWALK;
}
LIGHTINFO CMapHandler::GetTileLightInfo(INT nX, INT nY)
{
LIGHTINFO stLight = {FALSE, -1, -1};
if ( (m_pstCellInfo[nY + nX*m_stMapFileHeader.shHeight].wLigntNEvent == 0) &&
((m_pstCellInfo[nY + nX*m_stMapFileHeader.shHeight].wLigntNEvent & 0X07) != 1) )
return stLight;
stLight.bIsLight = TRUE;
stLight.cLightSizeType = ((m_pstCellInfo[nY + nX*m_stMapFileHeader.shHeight].wLigntNEvent & 0XC000) >> 14);
stLight.cLightColorType = ((m_pstCellInfo[nY + nX*m_stMapFileHeader.shHeight].wLigntNEvent & 0X3FF0) >> 4);
return stLight;
}
BYTE CMapHandler::GetEventNum(INT nX, INT nY)
{
BYTE bEventNum = -1;
if ( (m_pstCellInfo[nY + nX*m_stMapFileHeader.shHeight].wLigntNEvent == -1) &&
((m_pstCellInfo[nY + nX*m_stMapFileHeader.shHeight].wLigntNEvent & 0X07) != 3) )
return bEventNum;
bEventNum = ((m_pstCellInfo[nY + nX*m_stMapFileHeader.shHeight].wLigntNEvent & 0XF0) >> 4);
return bEventNum;
}
BOOL CMapHandler::GetNextTileCanMove(INT nXPos, INT nYPos, BYTE bDir, INT nGap, POINT* lpptTarget)
{
INT nXGapPos, nYGapPos;
BYTE bCanMove = _CAN_WALK;
nXGapPos = nYGapPos = 0;
switch ( bDir )
{
case _DIRECTION_LIST_1:
{
nXGapPos = nXPos;
nYGapPos = nYPos-nGap;
bCanMove = GetTileAttribute(nXGapPos, nYGapPos);
}
break;
case _DIRECTION_LIST_2:
{
nXGapPos = nXPos+nGap;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -