📄 3dgamemap-back.cpp
字号:
int Dir=GetDirection(x0,y0,x1,y1);
x0+=_DELTA_X[Dir];
y0+=_DELTA_Y[Dir];
}
long Value=(x0-x1)*(x0-x1)+(y0-y1)*(y0-y1);
long i=1;
while(1)
{
if(Value<(i*i))
break;
i++;
}
long a=(i-1)*(i-1);
if((i*i-a) > (Value-a)*2)
return int(i-1);
else
return int(i);
}
//--------------------------------------------------------------
void CGameMap::SetCamera(CMyPos posView)
{
int iWorldX = posView.x;
int iWorldY = posView.y;
UINT uBgWidth, uBgHeight;
CMySize infoSize;
this->GetBgSize(infoSize);
uBgWidth = infoSize.iWidth;
uBgHeight = infoSize.iHeight;
UINT uBgWorldX, uBgWorldY;
this->GetBgWorldPos(uBgWorldX, uBgWorldY);
/* if(iWorldX < (int)uBgWorldX)
iWorldX =uBgWorldX;
else if(iWorldX+m_nRealScreenWidth > uBgWorldX+uBgWidth)
iWorldX =uBgWorldX+uBgWidth-m_nRealScreenWidth;
if(iWorldY < (int)uBgWorldY)
iWorldY =uBgWorldY;
else if(iWorldY+m_nRealScreenHeight > uBgWorldY+uBgHeight)
iWorldY =uBgWorldY+uBgHeight-m_nRealScreenHeight;
*/
CMyPos posCamera;
posCamera.x = iWorldX-uBgWorldX;
posCamera.y = iWorldY-uBgWorldY;
float fX, fZ;
fX = (float)_SCR_WIDTH/2 + (float)posCamera.x;
fZ = (float)_SCR_HEIGHT/2 + (float)posCamera.y;
CMyBitmap::GameCameraSet(fX, fZ);
}
//--------------------------------------------------------------
void CGameMap::ApplyObjShow(CMapObj* pMapObj)
{
if(!pMapObj)
return;
CInteractiveLayer* pLayer = this->GetInteractiveLayer();
if(!pLayer)
return;
pLayer->ApplyShow(pMapObj);
}
//--------------------------------------------------------------
void CGameMap::AddInteractiveObj(CMapObj* pMapObj)
{
if(!pMapObj)
return;
CInteractiveLayer* pLayer = this->GetInteractiveLayer();
if(!pLayer)
return;
pLayer->AddMapObj(pMapObj);
}
//--------------------------------------------------------------
void CGameMap::DelInteractiveObj(CMapObj* pMapObj)
{
if(!pMapObj)
return;
CInteractiveLayer* pLayer = this->GetInteractiveLayer();
if(!pLayer)
return;
pLayer->DelObj(pMapObj);
}
//--------------------------------------------------------------
int CGameMap::GetAltitude(CMyPos posCell)
{
CellInfo* pCellInfo = this->GetCell(posCell.x, posCell.y);
if(!pCellInfo)
return 0;
LayerInfo* pInfo = g_objGameMap.GetLastLayerInfo(pCellInfo);
if(!pInfo)
return 0;
return pInfo->sAltitude;
}
//--------------------------------------------------------------
int CGameMap::GetBaseAltitude(CMyPos posCell)
{
CellInfo* pCellInfo = this->GetCell(posCell.x, posCell.y);
if(!pCellInfo)
return 0;
return pCellInfo->m_infoLayer.sAltitude;
}
//--------------------------------------------------------------
void CGameMap::Sampling(DEQUE_CELL& setCell, CMyPos& posHighest, CMyPos posStart, CMyPos posEnd, int nHits)
{
setCell.clear();
vector<POINT> setPoint;
this->DDALine(posStart.x, posStart.y, posEnd.x, posEnd.y, setPoint);
int nHighestAltitude = -65535;
int nAmount = setPoint.size();
for(int i = 0; i < nAmount; i ++)
{
CellInfo* pCellInfo = this->GetCell(setPoint[i].x, setPoint[i].y);
if(!pCellInfo)
continue;
setCell.push_back(pCellInfo);
if(this->GetGroundAltitude(pCellInfo) > nHighestAltitude)
{
posHighest.x = setPoint[i].x;
posHighest.y = setPoint[i].y;
nHighestAltitude = this->GetGroundAltitude(pCellInfo);
}
}
setPoint.clear();
/* CMyPos posStartWorld, posEndWorld;
this->Cell2World(posStart.x, posStart.y, posStartWorld.x, posStartWorld.y);
this->Cell2World(posEnd.x, posEnd.y, posEndWorld.x, posEndWorld.y);
double dbChangeX = 1.0*(posEndWorld.x - posStartWorld.x) /nHits;
double dbChangeY = 1.0*(posEndWorld.y - posStartWorld.y) /nHits;
CellInfo* pPreCell = NULL;
int nHighestAltitude = -65535;
posHighest = posStart;
for(int i = 0; i < nHits; i++)
{
CMyPos posCurrentWorld;
posCurrentWorld.x = (int)(i*dbChangeX + posStartWorld.x);
posCurrentWorld.y = (int)(i*dbChangeY + posStartWorld.y);
CMyPos posCurrentCell;
this->World2Cell(posCurrentWorld.x, posCurrentWorld.y,
posCurrentCell.x, posCurrentCell.y);
CellInfo* pCellInfo = this->GetCell(posCurrentCell.x, posCurrentCell.y);
if(!pCellInfo)
continue;
if(pCellInfo != pPreCell)
{
setCell.push_back(pCellInfo);
if(this->GetGroundAltitude(pCellInfo) > nHighestAltitude)
{
posHighest = posCurrentCell;
nHighestAltitude = this->GetGroundAltitude(pCellInfo);
}
pPreCell = pCellInfo;
}
} setCell.clear();
CMyPos posStartWorld, posEndWorld;
this->Cell2World(posStart.x, posStart.y, posStartWorld.x, posStartWorld.y);
this->Cell2World(posEnd.x, posEnd.y, posEndWorld.x, posEndWorld.y);
double dbChangeX = 1.0*(posEndWorld.x - posStartWorld.x) /nHits;
double dbChangeY = 1.0*(posEndWorld.y - posStartWorld.y) /nHits;
CellInfo* pPreCell = NULL;
int nHighestAltitude = -65535;
posHighest = posStart;
for(int i = 0; i < nHits; i++)
{
CMyPos posCurrentWorld;
posCurrentWorld.x = (int)(i*dbChangeX + posStartWorld.x);
posCurrentWorld.y = (int)(i*dbChangeY + posStartWorld.y);
CMyPos posCurrentCell;
this->World2Cell(posCurrentWorld.x, posCurrentWorld.y,
posCurrentCell.x, posCurrentCell.y);
CellInfo* pCellInfo = this->GetCell(posCurrentCell.x, posCurrentCell.y);
if(!pCellInfo)
continue;
if(pCellInfo != pPreCell)
{
setCell.push_back(pCellInfo);
if(this->GetGroundAltitude(pCellInfo) > nHighestAltitude)
{
posHighest = posCurrentCell;
nHighestAltitude = this->GetGroundAltitude(pCellInfo);
}
pPreCell = pCellInfo;
}
}*/
}
//--------------------------------------------------------------
void CGameMap::Mouse2Cell(int nMouseX, int nMouseY, int &nCellX, int &nCellY)
{
/* CMyPos posReference = {_SCR_WIDTH/2, _SCR_HEIGHT/2};
nX = (nMouseX - posReference.x)
nMouseX = posReference.x + (nX - posReference.x) * this->GetScale()/_NORMAL_SCALE;
nMouseY = posReference.y + (nY - posReference.y) * this->GetScale()/_NORMAL_SCALE;
*/
CMyPos posMouse;
posMouse.x = nMouseX;
posMouse.y = nMouseY;
int nDistX = (posMouse.x - _SCR_WIDTH/2) * _NORMAL_SCALE / this->GetScale();
int nDistY = (posMouse.y - _SCR_HEIGHT/2) * _NORMAL_SCALE / this->GetScale();
posMouse.x = _SCR_WIDTH/2 + nDistX;
posMouse.y = _SCR_HEIGHT/2 + nDistY;
CInteractiveLayer* pLayer = this->GetInteractiveLayer();
if(pLayer)
{
C2DMapTerrainObjPart* pObj = pLayer->Get2DFocusMapTerrainObjPart();
// 调试代码
if(pObj)
{
int nOffset;
if(pObj->GetMouseOffset(posMouse, nOffset))
posMouse.y += nOffset;
}
}
this->Screen2Cell(posMouse.x, posMouse.y, nCellX, nCellY);
}
//--------------------------------------------------------------
void CGameMap::DestroyCell()
{
if(!m_pCellInfo)
return;
DWORD dwAmount = m_sizeMap.iWidth*m_sizeMap.iHeight;
CellInfo* pMyCellInfo = m_pCellInfo;
for(DWORD i = 0; i < dwAmount; i ++)
{
if(pMyCellInfo->m_infoLayer.pLayer)
{
this->DelLayerInfo(pMyCellInfo->m_infoLayer.pLayer);
}
pMyCellInfo ++;
}
delete[] m_pCellInfo;
m_pCellInfo = NULL;
}
//--------------------------------------------------------------
void CGameMap::DelLayerInfo(LayerInfo* pLayerInfo)
{
if(!pLayerInfo)
return;
while (true)
{
LayerInfo* pMyLayerInfo = pLayerInfo;
if(!pMyLayerInfo->pLayer)
{
SAFE_DELETE(pMyLayerInfo);
break;
}
else
{
// 找到最后一个 CellInfo 删除
LayerInfo* pMyLastLayerInfo = pLayerInfo;
while(true)
{
if(pMyLastLayerInfo->pLayer->pLayer)
{
pMyLastLayerInfo = pMyLastLayerInfo->pLayer;
}
else
{
SAFE_DELETE(pMyLastLayerInfo->pLayer);
break;
}
}
}
}
pLayerInfo = NULL;
}
//--------------------------------------------------------------
void CGameMap::CreateCell()
{
DWORD dwAmount = m_sizeMap.iWidth*m_sizeMap.iHeight;
m_pCellInfo = new CellInfo[dwAmount];
CellInfo* pMyCellInfo = m_pCellInfo;
for(DWORD i = 0; i < dwAmount; i ++)
{
pMyCellInfo->m_infoLayer.pLayer = NULL;
pMyCellInfo->m_infoLayer.usTerrain = 0;
pMyCellInfo->m_infoLayer.usMask = 0;
pMyCellInfo->m_infoLayer.sAltitude = 0;
pMyCellInfo->m_bSearched = false;
pMyCellInfo ++;
}
}
//--------------------------------------------------------------
LayerInfo* CGameMap::GetLastLayerInfo(CellInfo* pCellInfo)
{
if(!pCellInfo)
return NULL;
if(!pCellInfo->m_infoLayer.pLayer)
return &pCellInfo->m_infoLayer;
LayerInfo* pLayerInfo = pCellInfo->m_infoLayer.pLayer;
while (true)
{
if(!pLayerInfo->pLayer)
return pLayerInfo;
else pLayerInfo = pLayerInfo->pLayer;
}
return NULL;
}
//--------------------------------------------------------------
void CGameMap::AddLayer(CellInfo* pCellInfo, LayerInfo* pLayerInfo)
{
if(!pCellInfo || !pLayerInfo)
return;
LayerInfo* infoLastLayer = this->GetLastLayerInfo(pCellInfo);
if(infoLastLayer)
infoLastLayer->pLayer = pLayerInfo;
}
//--------------------------------------------------------------
void CGameMap::DelLastLayer(CellInfo* pCellInfo)
{
if(!pCellInfo || !pCellInfo->m_infoLayer.pLayer)
return;
LayerInfo* pLayerInfo = &pCellInfo->m_infoLayer;
while (true)
{
if(!pLayerInfo->pLayer->pLayer)
{
SAFE_DELETE(pLayerInfo->pLayer);
break;
}
else
{
pLayerInfo = pLayerInfo->pLayer;
}
}
return;
}
//--------------------------------------------------------------
int CGameMap::GetGroundAltitude(CellInfo* pCellInfo)
{
if(!pCellInfo)
return 0;
LayerInfo* pLayerInfo = this->GetLastLayerInfo(pCellInfo);
if(!pLayerInfo)
return 0;
return pLayerInfo->sAltitude;
}
//--------------------------------------------------------------
DWORD CGameMap::GetGroundMask(CellInfo* pCellInfo)
{
if(!pCellInfo)
return 1;
LayerInfo* pLayerInfo = this->GetLastLayerInfo(pCellInfo);
if(!pLayerInfo)
return 1;
return pLayerInfo->usMask;
}
//--------------------------------------------------------------
void CGameMap::SetGroundMask(CellInfo* pCellInfo, DWORD dwMask)
{
if(!pCellInfo)
return;
LayerInfo* pLayerInfo = this->GetLastLayerInfo(pCellInfo);
if(!pLayerInfo)
return;
pLayerInfo->usMask = (unsigned short)dwMask;
}
//--------------------------------------------------------------
int CGameMap::GetMask(LayerInfo* pInfo)
{
if(!pInfo)
return 1;
}
//--------------------------------------------------------------
int CGameMap::GetTerrain(CellInfo* pCellInfo)
{
if(!pCellInfo)
return 0;
LayerInfo* pLayerInfo = CGameMap::GetLastLayerInfo(pCellInfo);
if(!pLayerInfo)
return 0;
return pLayerInfo->usTerrain;
}
//--------------------------------------------------------------
int CGameMap::GetAltitude(LayerInfo* pInfo)
{
if(!pInfo)
return 1;
}
//--------------------------------------------------------------
void CGameMap::SetMask(int nMask, LayerInfo* pInfo)
{
if(!pInfo)
return;
}
//--------------------------------------------------------------
void CGameMap::SetTerrain(int nTerrain, LayerInfo* pInfo)
{
if(!pInfo)
return;
}
//--------------------------------------------------------------
void CGameMap::SetAltitude(int nAltitude, LayerInfo* pInfo)
{
if(!pInfo)
return;
}
//--------------------------------------------------------------
int CGameMap::GetTerrain(CMyPos posCell)
{
return this->GetTerrain(posCell.x, posCell.y);
}
//--------------------------------------------------------------
int CGameMap::GetTerrain(int nPosX, int nPosY)
{
CellInfo* pInfo = this->GetCell(nPosX, nPosY);
return CGameMap::GetTerrain(pInfo);
}
//--------------------------------------------------------------
void CGameMap::AddMagicEffect(CMagicEffect* pEffect)
{
if(pEffect)
m_objMagicEffectManager.AddMagicEffect(pEffect);
}
//--------------------------------------------------------------
void CGameMap::Add3DMapMagicItem(OBJID idType, OBJID id, CMyPos posCell)
{
CInteractiveLayer* pLayer = this->GetInteractiveLayer();
if(pLayer)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -