mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-24 03:47:18 +02:00
5222be8d94
* new folder structure
49 lines
1.6 KiB
C++
49 lines
1.6 KiB
C++
#include "stdafx.h"
|
|
#include "CCallback.h"
|
|
#include "CPathfinder.h"
|
|
#include "hch\CHeroHandler.h"
|
|
#include "CGameInfo.h"
|
|
#include "hch\CAmbarCendamo.h"
|
|
#include "mapHandler.h"
|
|
#include "CGameState.h"
|
|
#include "CGameInterface.h"
|
|
|
|
bool CCallback::moveHero(int ID, int3 destPoint)
|
|
{
|
|
if(ID<0 || ID>CGI->heroh->heroInstances.size())
|
|
return false;
|
|
if(destPoint.x<0 || destPoint.x>CGI->ac->map.width)
|
|
return false;
|
|
if(destPoint.y<0 || destPoint.y>CGI->ac->map.height)
|
|
return false;
|
|
if(destPoint.z<0 || destPoint.z>CGI->mh->ttiles[0][0].size()-1)
|
|
return false;
|
|
CPath * ourPath = CGI->pathf->getPath(CGI->heroh->heroInstances[ID]->pos, destPoint, CGI->heroh->heroInstances[ID]);
|
|
if(!ourPath)
|
|
return false;
|
|
for(int i=0; i<ourPath->nodes.size()-1; ++i)
|
|
{
|
|
int3 stpos, endpos;
|
|
stpos = int3(ourPath->nodes[i].x, ourPath->nodes[i].y, CGI->heroh->heroInstances[ID]->pos.z);
|
|
endpos = int3(ourPath->nodes[i+1].x, ourPath->nodes[i+1].y, CGI->heroh->heroInstances[ID]->pos.z);
|
|
HeroMoveDetails curd;
|
|
curd.src = stpos;
|
|
curd.dst = endpos;
|
|
curd.heroID = ID;
|
|
curd.owner = CGI->heroh->heroInstances[ID]->owner;
|
|
if(CGI->heroh->heroInstances[ID]->movement>=CGI->mh->getCost(stpos, endpos, CGI->heroh->heroInstances[ID]))
|
|
{ //performing move
|
|
for(int j=0; j<CGI->state->players.size(); ++j)
|
|
{
|
|
if(CGI->state->players[j].fogOfWarMap[stpos.x][stpos.y][stpos.z] || CGI->state->players[j].fogOfWarMap[endpos.x][endpos.y][endpos.z])
|
|
{ //player should be notified
|
|
CGI->playerint[j]->heroMoved(curd);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
return true; //move ended - no more movement points
|
|
}
|
|
return true;
|
|
}
|