diff --git a/CPathfinder.cpp b/CPathfinder.cpp index 75b90e34d..7339a08fc 100644 --- a/CPathfinder.cpp +++ b/CPathfinder.cpp @@ -180,8 +180,8 @@ void CPathfinder::convertPath(CPath * path, unsigned int mode) //mode=0 -> from void CPathfinder::processNode(CPathNode & dp, const CGHeroInstance * hero, std::queue & mq, const CPathNode & cp, const int3 & src, bool diagonal) { const TerrainTile * tinfo = CGI->mh->ttiles[dp.coord.x][dp.coord.y][src.z].tileInfo; - int cost = hero->getTileCost(tinfo->tertype, tinfo->malle, tinfo->nuine); - if(diagonal) + int cost = hero->getTileCost(tinfo->tertype, tinfo->malle, tinfo->nuine, hero->movement - cp.dist); + if(diagonal && (hero->movement - cp.dist) > 145) //second condition - workaround for strange behaviour manifested by Heroes III cost *= std::sqrt(2.0); if((dp.dist==-1 || (dp.dist > cp.dist + cost)) && dp.accesible && checkForVisitableDir(cp.coord, dp.coord) && checkForVisitableDir(dp.coord, cp.coord)) { diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 56fdc8636..6713d63f8 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -2506,7 +2506,17 @@ void CHeroList::select(int which) selected = which; LOCPLINT->adventureInt->centerOn(items[which].first->pos); LOCPLINT->adventureInt->selection = items[which].first; - LOCPLINT->adventureInt->terrain.currentPath = items[which].second; + //recalculationg path in case of something has changed on map + if(items[which].second) + { + CPath * newPath = CGI->pathf->getPath(items[which].second->startPos(), items[which].second->endPos(), items[which].first); + LOCPLINT->adventureInt->terrain.currentPath = items[which].second = newPath; + } + else + { + LOCPLINT->adventureInt->terrain.currentPath = NULL; + } + //recalculated and assigned draw(); LOCPLINT->adventureInt->townList.draw(); LOCPLINT->adventureInt->infoBar.draw(NULL); diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 3a50c2341..7316ebecd 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -195,8 +195,9 @@ int lowestSpeed(const CGHeroInstance * chi) return ret; } -unsigned int CGHeroInstance::getTileCost(const EterrainType & ttype, const Eroad & rdtype, const Eriver & rvtype) const +unsigned int CGHeroInstance::getTileCost(const EterrainType & ttype, const Eroad & rdtype, const Eriver & rvtype, const int & remaingMP) const { + if(remaingMP <= 100) return 100; //workaround for strange behaviour manifested by Heroes III unsigned int ret = type->heroClass->terrCosts[ttype]; //applying pathfinding skill switch(getSecSkillLevel(0)) diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 2ca5365e7..e69cb03c0 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -207,7 +207,7 @@ public: const HeroBonus *getBonus(int from, int id) const; const std::string &getBiography() const; bool needsLastStack()const; - unsigned int getTileCost(const EterrainType & ttype, const Eroad & rdtype, const Eriver & rvtype) const; + unsigned int getTileCost(const EterrainType & ttype, const Eroad & rdtype, const Eriver & rvtype, const int & remaingMP) const; unsigned int getLowestCreatureSpeed() const; unsigned int getAdditiveMoveBonus() const; float getMultiplicativeMoveBonus() const; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 40568d965..4cb11cfff 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -495,7 +495,9 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) int3 hmpos = end + int3(-1,0,0); TerrainTile t = gs->map->terrain[hmpos.x][hmpos.y][hmpos.z]; CGHeroInstance *h = static_cast(gs->map->objects[id]); - int cost = (int)((double)h->getTileCost(t.tertype,t.malle,t.nuine) * distance(start,end)); + double dist = distance(start,end); + if(h->movement <= 145) dist = 1.0f; //workaround for strange behaviour manifested by Heroes III + int cost = (int)((double)h->getTileCost(t.tertype,t.malle,t.nuine, h->movement) * dist); TryMoveHero tmh; tmh.id = id;