1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-15 20:03:15 +02:00

Updated C::B projects, fixed a few warnings

This commit is contained in:
AlexVinS
2018-10-10 16:07:28 +03:00
parent cbaa834589
commit be45c8cb43
7 changed files with 35 additions and 27 deletions

View File

@@ -407,7 +407,7 @@ int3 whereToExplore(HeroPtr h)
TimeCheck tc("where to explore"); TimeCheck tc("where to explore");
int radius = h->getSightRadius(); int radius = h->getSightRadius();
int3 hpos = h->visitablePos(); int3 hpos = h->visitablePos();
//look for nearby objs -> visit them if they're close enouh //look for nearby objs -> visit them if they're close enouh
const int DIST_LIMIT = 3; const int DIST_LIMIT = 3;
const int MP_LIMIT = DIST_LIMIT * 150; // aproximate cost of diagonal movement const int MP_LIMIT = DIST_LIMIT * 150; // aproximate cost of diagonal movement
@@ -535,11 +535,13 @@ ui64 howManyReinforcementsCanBuy(HeroPtr h, const CGDwelling * t)
{ {
//can be merged with another stack? //can be merged with another stack?
SlotID dst = h->getSlotFor(ci.creID); SlotID dst = h->getSlotFor(ci.creID);
if (!h->hasStackAtSlot(dst)) //need another new slot for this stack if(!h->hasStackAtSlot(dst)) //need another new slot for this stack
if (!freeHeroSlots) //no more place for stacks {
if(!freeHeroSlots) //no more place for stacks
continue; continue;
else else
freeHeroSlots--; //new slot will be occupied freeHeroSlots--; //new slot will be occupied
}
//we found matching occupied or free slot //we found matching occupied or free slot
aivalue += ci.count * ci.cre->AIValue; aivalue += ci.count * ci.cre->AIValue;
@@ -607,9 +609,9 @@ uint32_t distanceToTile(const CGHeroInstance * hero, int3 pos)
{ {
auto pathInfo = cb->getPathsInfo(hero)->getPathInfo(pos); auto pathInfo = cb->getPathsInfo(hero)->getPathInfo(pos);
uint32_t totalMovementPoints = pathInfo->turns * hero->maxMovePoints(true) + hero->movement; uint32_t totalMovementPoints = pathInfo->turns * hero->maxMovePoints(true) + hero->movement;
if(totalMovementPoints < pathInfo->moveRemains) // should not be but who knows if(totalMovementPoints < pathInfo->moveRemains) // should not be but who knows
return 0; return 0;
return totalMovementPoints - pathInfo->moveRemains; return totalMovementPoints - pathInfo->moveRemains;
} }

View File

@@ -35,7 +35,7 @@ void AINodeStorage::updateAINode(CGPathNode * node, std::function<void(AIPathNod
bool AINodeStorage::isBattleNode(const CGPathNode * node) const bool AINodeStorage::isBattleNode(const CGPathNode * node) const
{ {
return getAINode(node)->chainMask & BATTLE_CHAIN > 0; return (getAINode(node)->chainMask & BATTLE_CHAIN) > 0;
} }
AIPathNode * AINodeStorage::getNode(const int3 & coord, const EPathfindingLayer layer, int chainNumber) AIPathNode * AINodeStorage::getNode(const int3 & coord, const EPathfindingLayer layer, int chainNumber)
@@ -75,7 +75,7 @@ void AINodeStorage::commit(CDestinationNodeInfo & destination, const PathNodeInf
dstNode->turns = destination.turn; dstNode->turns = destination.turn;
dstNode->danger = srcNode->danger; dstNode->danger = srcNode->danger;
dstNode->action = destination.action; dstNode->action = destination.action;
dstNode->theNodeBefore = srcNode->theNodeBefore; dstNode->theNodeBefore = srcNode->theNodeBefore;
}); });
} }
@@ -140,12 +140,12 @@ bool AINodeStorage::hasBetterChain(const PathNodeInfo & source, CDestinationNode
if(node.danger <= destinationNode->danger && destinationNode->chainMask == 1 && node.chainMask == 0) if(node.danger <= destinationNode->danger && destinationNode->chainMask == 1 && node.chainMask == 0)
{ {
if(node.turns < destinationNode->turns if(node.turns < destinationNode->turns
|| node.turns == destinationNode->turns && node.moveRemains >= destinationNode->moveRemains) || (node.turns == destinationNode->turns && node.moveRemains >= destinationNode->moveRemains))
{ {
logAi->trace( logAi->trace(
"Block ineficient move %s:->%s, mask=%i, mp diff: %i", "Block ineficient move %s:->%s, mask=%i, mp diff: %i",
source.coord.toString(), source.coord.toString(),
destination.coord.toString(), destination.coord.toString(),
destinationNode->chainMask, destinationNode->chainMask,
node.moveRemains - destinationNode->moveRemains); node.moveRemains - destinationNode->moveRemains);
@@ -234,4 +234,4 @@ uint64_t AIPath::getTotalDanger(HeroPtr hero) const
uint64_t danger = pathDanger > objDanger ? pathDanger : objDanger; uint64_t danger = pathDanger > objDanger ? pathDanger : objDanger;
return danger; return danger;
} }

View File

@@ -12,7 +12,7 @@
#include "../../../lib/CPathfinder.h" #include "../../../lib/CPathfinder.h"
#include "../../../lib/mapObjects/CGHeroInstance.h" #include "../../../lib/mapObjects/CGHeroInstance.h"
#include "AIUtility.h" #include "../AIUtility.h"
class IVirtualObject class IVirtualObject
{ {

View File

@@ -10,7 +10,7 @@
#pragma once #pragma once
#include "AIUtility.h" #include "../AIUtility.h"
#include "AINodeStorage.h" #include "AINodeStorage.h"
class AIPathfinder class AIPathfinder
@@ -25,4 +25,4 @@ public:
AIPathfinder(CPlayerSpecificInfoCallback * cb); AIPathfinder(CPlayerSpecificInfoCallback * cb);
std::vector<AIPath> getPathInfo(HeroPtr hero, int3 tile); std::vector<AIPath> getPathInfo(HeroPtr hero, int3 tile);
void clear(); void clear();
}; };

View File

@@ -41,13 +41,11 @@ public:
if(blocker == BlockingReason::NONE) if(blocker == BlockingReason::NONE)
return; return;
auto srcNode = nodeStorage->getAINode(source.node);
if(blocker == BlockingReason::DESTINATION_BLOCKVIS && destination.nodeObject) if(blocker == BlockingReason::DESTINATION_BLOCKVIS && destination.nodeObject)
{ {
auto objID = destination.nodeObject->ID; auto objID = destination.nodeObject->ID;
if(objID == Obj::HERO && destination.objectRelations != PlayerRelations::ENEMIES if((objID == Obj::HERO && destination.objectRelations != PlayerRelations::ENEMIES)
|| objID == Obj::SUBTERRANEAN_GATE || objID == Obj::MONOLITH_TWO_WAY || objID == Obj::SUBTERRANEAN_GATE || objID == Obj::MONOLITH_TWO_WAY
|| objID == Obj::MONOLITH_ONE_WAY_ENTRANCE || objID == Obj::MONOLITH_ONE_WAY_EXIT || objID == Obj::MONOLITH_ONE_WAY_ENTRANCE || objID == Obj::MONOLITH_ONE_WAY_EXIT
|| objID == Obj::WHIRLPOOL) || objID == Obj::WHIRLPOOL)
{ {
@@ -202,7 +200,8 @@ public:
const PathfinderConfig * pathfinderConfig, const PathfinderConfig * pathfinderConfig,
CPathfinderHelper * pathfinderHelper) const override CPathfinderHelper * pathfinderHelper) const override
{ {
auto blocker = getBlockingReason(source, destination, pathfinderConfig, pathfinderHelper); //FIXME: unused
// auto blocker = getBlockingReason(source, destination, pathfinderConfig, pathfinderHelper);
if(source.guarded) if(source.guarded)
{ {
@@ -234,7 +233,7 @@ public:
}; };
std::vector<std::shared_ptr<IPathfindingRule>> makeRuleset( std::vector<std::shared_ptr<IPathfindingRule>> makeRuleset(
CPlayerSpecificInfoCallback * cb, CPlayerSpecificInfoCallback * cb,
std::shared_ptr<AINodeStorage> nodeStorage) std::shared_ptr<AINodeStorage> nodeStorage)
{ {
std::vector<std::shared_ptr<IPathfindingRule>> rules = { std::vector<std::shared_ptr<IPathfindingRule>> rules = {
@@ -250,8 +249,8 @@ std::vector<std::shared_ptr<IPathfindingRule>> makeRuleset(
} }
AIPathfinderConfig::AIPathfinderConfig( AIPathfinderConfig::AIPathfinderConfig(
CPlayerSpecificInfoCallback * cb, CPlayerSpecificInfoCallback * cb,
std::shared_ptr<AINodeStorage> nodeStorage) std::shared_ptr<AINodeStorage> nodeStorage)
:PathfinderConfig(nodeStorage, makeRuleset(cb, nodeStorage)) :PathfinderConfig(nodeStorage, makeRuleset(cb, nodeStorage))
{ {
} }

View File

@@ -95,6 +95,14 @@
<Unit filename="Goals.h" /> <Unit filename="Goals.h" />
<Unit filename="MapObjectsEvaluator.cpp" /> <Unit filename="MapObjectsEvaluator.cpp" />
<Unit filename="MapObjectsEvaluator.h" /> <Unit filename="MapObjectsEvaluator.h" />
<Unit filename="Pathfinding/AINodeStorage.cpp" />
<Unit filename="Pathfinding/AINodeStorage.h" />
<Unit filename="Pathfinding/AIPathfinder.cpp" />
<Unit filename="Pathfinding/AIPathfinder.h" />
<Unit filename="Pathfinding/AIPathfinderConfig.cpp" />
<Unit filename="Pathfinding/AIPathfinderConfig.h" />
<Unit filename="Pathfinding/PathfindingManager.cpp" />
<Unit filename="Pathfinding/PathfindingManager.h" />
<Unit filename="ResourceManager.cpp" /> <Unit filename="ResourceManager.cpp" />
<Unit filename="ResourceManager.h" /> <Unit filename="ResourceManager.h" />
<Unit filename="SectorMap.cpp" /> <Unit filename="SectorMap.cpp" />

View File

@@ -985,7 +985,7 @@ void VCAI::mainLoop()
completeGoal(goalToRealize); completeGoal(goalToRealize);
// remove abstract visit tile if we completed the elementar one // remove abstract visit tile if we completed the elementar one
vstd::erase_if_present(goalsToAdd, goalToRealize); vstd::erase_if_present(goalsToAdd, goalToRealize);
} }
catch (std::exception & e) catch (std::exception & e)
{ {
@@ -1326,9 +1326,9 @@ bool VCAI::isGoodForVisit(const CGObjectInstance * obj, HeroPtr h, const AIPath
return false; return false;
if (vstd::contains(reservedObjs, obj)) if (vstd::contains(reservedObjs, obj))
return false; return false;
// TODO: looks extra if we already have AIPath // TODO: looks extra if we already have AIPath
//if (!isAccessibleForHero(targetPos, h)) //if (!isAccessibleForHero(targetPos, h))
// return false; // return false;
const CGObjectInstance * topObj = cb->getVisitableObjs(obj->visitablePos()).back(); //it may be hero visiting this obj const CGObjectInstance * topObj = cb->getVisitableObjs(obj->visitablePos()).back(); //it may be hero visiting this obj
@@ -1345,7 +1345,7 @@ bool VCAI::isTileNotReserved(const CGHeroInstance * h, int3 t) const
if(t.valid()) if(t.valid())
{ {
auto obj = cb->getTopObj(t); auto obj = cb->getTopObj(t);
if(obj && vstd::contains(ai->reservedObjs, obj) if(obj && vstd::contains(ai->reservedObjs, obj)
&& vstd::contains(reservedHeroesMap, h) && vstd::contains(reservedHeroesMap, h)
&& !vstd::contains(reservedHeroesMap.at(h), obj)) && !vstd::contains(reservedHeroesMap.at(h), obj))
return false; //do not capture object reserved by another hero return false; //do not capture object reserved by another hero
@@ -1402,7 +1402,7 @@ void VCAI::wander(HeroPtr h)
{ {
validateVisitableObjs(); validateVisitableObjs();
std::vector<ObjectIdRef> dests; std::vector<ObjectIdRef> dests;
//also visit our reserved objects - but they are not prioritized to avoid running back and forth //also visit our reserved objects - but they are not prioritized to avoid running back and forth
vstd::copy_if(reservedHeroesMap[h], std::back_inserter(dests), [&](ObjectIdRef obj) -> bool vstd::copy_if(reservedHeroesMap[h], std::back_inserter(dests), [&](ObjectIdRef obj) -> bool
{ {
@@ -2389,7 +2389,6 @@ Goals::TSubgoal VCAI::decomposeGoal(Goals::TSubgoal ultimateGoal)
} }
const int searchDepth = 30; const int searchDepth = 30;
const int searchDepth2 = searchDepth - 2;
Goals::TSubgoal abstractGoal = sptr(Goals::Invalid()); Goals::TSubgoal abstractGoal = sptr(Goals::Invalid());
Goals::TSubgoal goal = ultimateGoal; Goals::TSubgoal goal = ultimateGoal;