mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
parent
2018fc09a4
commit
b54489ecb7
@ -280,7 +280,7 @@ ui64 evaluateDanger(crint3 tile)
|
||||
ui64 objectDanger = 0, guardDanger = 0;
|
||||
|
||||
if(t->visitable)
|
||||
objectDanger = evaluateDanger(t->visitableObjects.front());
|
||||
objectDanger = evaluateDanger(t->visitableObjects.back());
|
||||
|
||||
int3 guardPos = cb->guardingCreaturePosition(tile);
|
||||
if(guardPos.x >= 0 && guardPos != tile)
|
||||
|
@ -339,6 +339,10 @@ CCallback::CCallback( CGameState * GS, int Player, CClient *C )
|
||||
|
||||
const CGPathNode * CCallback::getPathInfo( int3 tile )
|
||||
{
|
||||
if (!gs->map->isInTheMap(tile))
|
||||
return nullptr;
|
||||
|
||||
validatePaths();
|
||||
return &cl->pathInfo->nodes[tile.x][tile.y][tile.z];
|
||||
}
|
||||
|
||||
@ -347,12 +351,8 @@ bool CCallback::getPath2( int3 dest, CGPath &ret )
|
||||
if (!gs->map->isInTheMap(dest))
|
||||
return false;
|
||||
|
||||
const CGHeroInstance *h = cl->IGameCallback::getSelectedHero(player);
|
||||
assert(cl->pathInfo->hero == h);
|
||||
if(cl->pathInfo->hpos != h->getPosition(false) || !cl->pathInfo->isValid) //hero position changed, must update paths
|
||||
{
|
||||
recalculatePaths();
|
||||
}
|
||||
validatePaths();
|
||||
|
||||
boost::unique_lock<boost::mutex> pathLock(cl->pathMx);
|
||||
return cl->pathInfo->getPath(dest, ret);
|
||||
}
|
||||
@ -391,6 +391,17 @@ void CCallback::unregisterMyInterface()
|
||||
//TODO? should callback be disabled as well?
|
||||
}
|
||||
|
||||
void CCallback::validatePaths()
|
||||
{
|
||||
const CGHeroInstance *h = cl->IGameCallback::getSelectedHero(player);
|
||||
if(cl->pathInfo->hero != h //wrong hero
|
||||
|| cl->pathInfo->hpos != h->getPosition(false) //wrong hero positoin
|
||||
|| !cl->pathInfo->isValid) //paths invalidated by game event
|
||||
{
|
||||
recalculatePaths();
|
||||
}
|
||||
}
|
||||
|
||||
CBattleCallback::CBattleCallback(CGameState *GS, int Player, CClient *C )
|
||||
{
|
||||
gs = GS;
|
||||
|
@ -101,11 +101,15 @@ class CCallback : public CPlayerSpecificInfoCallback, public IGameActionCallback
|
||||
{
|
||||
private:
|
||||
CCallback(CGameState * GS, int Player, CClient *C);
|
||||
|
||||
void validatePaths(); //recalcualte paths if necessary
|
||||
|
||||
public:
|
||||
//client-specific functionalities (pathfinding)
|
||||
virtual bool getPath(int3 src, int3 dest, const CGHeroInstance * hero, CPath &ret); //DEPRACATED!!!
|
||||
virtual const CGPathNode *getPathInfo(int3 tile); //uses main, client pathfinder info
|
||||
virtual bool getPath2(int3 dest, CGPath &ret); //uses main, client pathfinder info
|
||||
|
||||
virtual void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out, int3 src = int3(-1,-1,-1), int movement = -1);
|
||||
virtual void recalculatePaths(); //updates main, client pathfinder info (should be called when moving hero is over)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user