mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-11 11:31:52 +02:00
Updated C::B projects, fixed a few warnings
This commit is contained in:
parent
cbaa834589
commit
be45c8cb43
@ -407,7 +407,7 @@ int3 whereToExplore(HeroPtr h)
|
||||
TimeCheck tc("where to explore");
|
||||
int radius = h->getSightRadius();
|
||||
int3 hpos = h->visitablePos();
|
||||
|
||||
|
||||
//look for nearby objs -> visit them if they're close enouh
|
||||
const int DIST_LIMIT = 3;
|
||||
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?
|
||||
SlotID dst = h->getSlotFor(ci.creID);
|
||||
if (!h->hasStackAtSlot(dst)) //need another new slot for this stack
|
||||
if (!freeHeroSlots) //no more place for stacks
|
||||
if(!h->hasStackAtSlot(dst)) //need another new slot for this stack
|
||||
{
|
||||
if(!freeHeroSlots) //no more place for stacks
|
||||
continue;
|
||||
else
|
||||
freeHeroSlots--; //new slot will be occupied
|
||||
}
|
||||
|
||||
//we found matching occupied or free slot
|
||||
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);
|
||||
uint32_t totalMovementPoints = pathInfo->turns * hero->maxMovePoints(true) + hero->movement;
|
||||
|
||||
|
||||
if(totalMovementPoints < pathInfo->moveRemains) // should not be but who knows
|
||||
return 0;
|
||||
|
||||
return totalMovementPoints - pathInfo->moveRemains;
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ void AINodeStorage::updateAINode(CGPathNode * node, std::function<void(AIPathNod
|
||||
|
||||
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)
|
||||
@ -75,7 +75,7 @@ void AINodeStorage::commit(CDestinationNodeInfo & destination, const PathNodeInf
|
||||
dstNode->turns = destination.turn;
|
||||
dstNode->danger = srcNode->danger;
|
||||
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.turns < destinationNode->turns
|
||||
|| node.turns == destinationNode->turns && node.moveRemains >= destinationNode->moveRemains)
|
||||
|| (node.turns == destinationNode->turns && node.moveRemains >= destinationNode->moveRemains))
|
||||
{
|
||||
logAi->trace(
|
||||
"Block ineficient move %s:->%s, mask=%i, mp diff: %i",
|
||||
source.coord.toString(),
|
||||
destination.coord.toString(),
|
||||
destination.coord.toString(),
|
||||
destinationNode->chainMask,
|
||||
node.moveRemains - destinationNode->moveRemains);
|
||||
|
||||
@ -234,4 +234,4 @@ uint64_t AIPath::getTotalDanger(HeroPtr hero) const
|
||||
uint64_t danger = pathDanger > objDanger ? pathDanger : objDanger;
|
||||
|
||||
return danger;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
#include "../../../lib/CPathfinder.h"
|
||||
#include "../../../lib/mapObjects/CGHeroInstance.h"
|
||||
#include "AIUtility.h"
|
||||
#include "../AIUtility.h"
|
||||
|
||||
class IVirtualObject
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AIUtility.h"
|
||||
#include "../AIUtility.h"
|
||||
#include "AINodeStorage.h"
|
||||
|
||||
class AIPathfinder
|
||||
@ -25,4 +25,4 @@ public:
|
||||
AIPathfinder(CPlayerSpecificInfoCallback * cb);
|
||||
std::vector<AIPath> getPathInfo(HeroPtr hero, int3 tile);
|
||||
void clear();
|
||||
};
|
||||
};
|
||||
|
@ -41,13 +41,11 @@ public:
|
||||
if(blocker == BlockingReason::NONE)
|
||||
return;
|
||||
|
||||
auto srcNode = nodeStorage->getAINode(source.node);
|
||||
|
||||
if(blocker == BlockingReason::DESTINATION_BLOCKVIS && destination.nodeObject)
|
||||
{
|
||||
auto objID = destination.nodeObject->ID;
|
||||
if(objID == Obj::HERO && destination.objectRelations != PlayerRelations::ENEMIES
|
||||
|| objID == Obj::SUBTERRANEAN_GATE || objID == Obj::MONOLITH_TWO_WAY
|
||||
if((objID == Obj::HERO && destination.objectRelations != PlayerRelations::ENEMIES)
|
||||
|| objID == Obj::SUBTERRANEAN_GATE || objID == Obj::MONOLITH_TWO_WAY
|
||||
|| objID == Obj::MONOLITH_ONE_WAY_ENTRANCE || objID == Obj::MONOLITH_ONE_WAY_EXIT
|
||||
|| objID == Obj::WHIRLPOOL)
|
||||
{
|
||||
@ -202,7 +200,8 @@ public:
|
||||
const PathfinderConfig * pathfinderConfig,
|
||||
CPathfinderHelper * pathfinderHelper) const override
|
||||
{
|
||||
auto blocker = getBlockingReason(source, destination, pathfinderConfig, pathfinderHelper);
|
||||
//FIXME: unused
|
||||
// auto blocker = getBlockingReason(source, destination, pathfinderConfig, pathfinderHelper);
|
||||
|
||||
if(source.guarded)
|
||||
{
|
||||
@ -234,7 +233,7 @@ public:
|
||||
};
|
||||
|
||||
std::vector<std::shared_ptr<IPathfindingRule>> makeRuleset(
|
||||
CPlayerSpecificInfoCallback * cb,
|
||||
CPlayerSpecificInfoCallback * cb,
|
||||
std::shared_ptr<AINodeStorage> nodeStorage)
|
||||
{
|
||||
std::vector<std::shared_ptr<IPathfindingRule>> rules = {
|
||||
@ -250,8 +249,8 @@ std::vector<std::shared_ptr<IPathfindingRule>> makeRuleset(
|
||||
}
|
||||
|
||||
AIPathfinderConfig::AIPathfinderConfig(
|
||||
CPlayerSpecificInfoCallback * cb,
|
||||
CPlayerSpecificInfoCallback * cb,
|
||||
std::shared_ptr<AINodeStorage> nodeStorage)
|
||||
:PathfinderConfig(nodeStorage, makeRuleset(cb, nodeStorage))
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -95,6 +95,14 @@
|
||||
<Unit filename="Goals.h" />
|
||||
<Unit filename="MapObjectsEvaluator.cpp" />
|
||||
<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.h" />
|
||||
<Unit filename="SectorMap.cpp" />
|
||||
|
@ -985,7 +985,7 @@ void VCAI::mainLoop()
|
||||
completeGoal(goalToRealize);
|
||||
|
||||
// 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)
|
||||
{
|
||||
@ -1326,9 +1326,9 @@ bool VCAI::isGoodForVisit(const CGObjectInstance * obj, HeroPtr h, const AIPath
|
||||
return false;
|
||||
if (vstd::contains(reservedObjs, obj))
|
||||
return false;
|
||||
|
||||
|
||||
// TODO: looks extra if we already have AIPath
|
||||
//if (!isAccessibleForHero(targetPos, h))
|
||||
//if (!isAccessibleForHero(targetPos, h))
|
||||
// return false;
|
||||
|
||||
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())
|
||||
{
|
||||
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.at(h), obj))
|
||||
return false; //do not capture object reserved by another hero
|
||||
@ -1402,7 +1402,7 @@ void VCAI::wander(HeroPtr h)
|
||||
{
|
||||
validateVisitableObjs();
|
||||
std::vector<ObjectIdRef> dests;
|
||||
|
||||
|
||||
//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
|
||||
{
|
||||
@ -2389,7 +2389,6 @@ Goals::TSubgoal VCAI::decomposeGoal(Goals::TSubgoal ultimateGoal)
|
||||
}
|
||||
|
||||
const int searchDepth = 30;
|
||||
const int searchDepth2 = searchDepth - 2;
|
||||
Goals::TSubgoal abstractGoal = sptr(Goals::Invalid());
|
||||
|
||||
Goals::TSubgoal goal = ultimateGoal;
|
||||
|
Loading…
x
Reference in New Issue
Block a user