mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
Remove a few more usages of thread shared ai and cb
This commit is contained in:
parent
6165954e40
commit
f76c6c2300
@ -194,12 +194,6 @@ bool CDistanceSorter::operator()(const CGObjectInstance * lhs, const CGObjectIns
|
|||||||
return ln->cost < rn->cost;
|
return ln->cost < rn->cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool compareDanger(const CGObjectInstance * lhs, const CGObjectInstance * rhs)
|
|
||||||
{
|
|
||||||
return fh->evaluateDanger(lhs) < fh->evaluateDanger(rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isSafeToVisit(HeroPtr h, crint3 tile)
|
bool isSafeToVisit(HeroPtr h, crint3 tile)
|
||||||
{
|
{
|
||||||
return isSafeToVisit(h, fh->evaluateDanger(tile, h.get()));
|
return isSafeToVisit(h, fh->evaluateDanger(tile, h.get()));
|
||||||
|
@ -207,11 +207,12 @@ void FuzzyHelper::setPriority(Goals::TSubgoal & g) //calls evaluate - Visitor pa
|
|||||||
|
|
||||||
ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor)
|
ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor)
|
||||||
{
|
{
|
||||||
return evaluateDanger(tile, visitor, cb.get());
|
return evaluateDanger(tile, visitor, ai.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor, const CPlayerSpecificInfoCallback * cb)
|
ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor, const VCAI * ai)
|
||||||
{
|
{
|
||||||
|
auto cb = ai->myCb;
|
||||||
const TerrainTile * t = cb->getTile(tile, false);
|
const TerrainTile * t = cb->getTile(tile, false);
|
||||||
if(!t) //we can know about guard but can't check its tile (the edge of fow)
|
if(!t) //we can know about guard but can't check its tile (the edge of fow)
|
||||||
return 190000000; //MUCH
|
return 190000000; //MUCH
|
||||||
@ -231,7 +232,7 @@ ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor, co
|
|||||||
|
|
||||||
if(const CGObjectInstance * dangerousObject = vstd::backOrNull(visitableObjects))
|
if(const CGObjectInstance * dangerousObject = vstd::backOrNull(visitableObjects))
|
||||||
{
|
{
|
||||||
objectDanger = evaluateDanger(dangerousObject); //unguarded objects can also be dangerous or unhandled
|
objectDanger = evaluateDanger(dangerousObject, ai); //unguarded objects can also be dangerous or unhandled
|
||||||
if(objectDanger)
|
if(objectDanger)
|
||||||
{
|
{
|
||||||
//TODO: don't downcast objects AI shouldn't know about!
|
//TODO: don't downcast objects AI shouldn't know about!
|
||||||
@ -251,7 +252,9 @@ ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor, co
|
|||||||
auto guards = cb->getGuardingCreatures(it->second->visitablePos());
|
auto guards = cb->getGuardingCreatures(it->second->visitablePos());
|
||||||
for(auto cre : guards)
|
for(auto cre : guards)
|
||||||
{
|
{
|
||||||
vstd::amax(guardDanger, evaluateDanger(cre) * tacticalAdvantageEngine.getTacticalAdvantage(visitor, dynamic_cast<const CArmedInstance *>(cre)));
|
float tacticalAdvantage = tacticalAdvantageEngine.getTacticalAdvantage(visitor, dynamic_cast<const CArmedInstance *>(cre));
|
||||||
|
|
||||||
|
vstd::amax(guardDanger, evaluateDanger(cre, ai) * tacticalAdvantage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -260,15 +263,19 @@ ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor, co
|
|||||||
auto guards = cb->getGuardingCreatures(tile);
|
auto guards = cb->getGuardingCreatures(tile);
|
||||||
for(auto cre : guards)
|
for(auto cre : guards)
|
||||||
{
|
{
|
||||||
vstd::amax(guardDanger, evaluateDanger(cre) * tacticalAdvantageEngine.getTacticalAdvantage(visitor, dynamic_cast<const CArmedInstance *>(cre))); //we are interested in strongest monster around
|
float tacticalAdvantage = tacticalAdvantageEngine.getTacticalAdvantage(visitor, dynamic_cast<const CArmedInstance *>(cre));
|
||||||
|
|
||||||
|
vstd::amax(guardDanger, evaluateDanger(cre, ai) * tacticalAdvantage); //we are interested in strongest monster around
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO mozna odwiedzic blockvis nie ruszajac straznika
|
//TODO mozna odwiedzic blockvis nie ruszajac straznika
|
||||||
return std::max(objectDanger, guardDanger);
|
return std::max(objectDanger, guardDanger);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui64 FuzzyHelper::evaluateDanger(const CGObjectInstance * obj)
|
ui64 FuzzyHelper::evaluateDanger(const CGObjectInstance * obj, const VCAI * ai)
|
||||||
{
|
{
|
||||||
|
auto cb = ai->myCb;
|
||||||
|
|
||||||
if(obj->tempOwner < PlayerColor::PLAYER_LIMIT && cb->getPlayerRelations(obj->tempOwner, ai->playerID) != PlayerRelations::ENEMIES) //owned or allied objects don't pose any threat
|
if(obj->tempOwner < PlayerColor::PLAYER_LIMIT && cb->getPlayerRelations(obj->tempOwner, ai->playerID) != PlayerRelations::ENEMIES) //owned or allied objects don't pose any threat
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ public:
|
|||||||
Goals::TSubgoal chooseSolution(Goals::TGoalVec vec);
|
Goals::TSubgoal chooseSolution(Goals::TGoalVec vec);
|
||||||
//std::shared_ptr<AbstractGoal> chooseSolution (std::vector<std::shared_ptr<AbstractGoal>> & vec);
|
//std::shared_ptr<AbstractGoal> chooseSolution (std::vector<std::shared_ptr<AbstractGoal>> & vec);
|
||||||
|
|
||||||
ui64 evaluateDanger(const CGObjectInstance * obj);
|
ui64 evaluateDanger(const CGObjectInstance * obj, const VCAI * ai);
|
||||||
ui64 evaluateDanger(crint3 tile, const CGHeroInstance * visitor, const CPlayerSpecificInfoCallback * cb);
|
ui64 evaluateDanger(crint3 tile, const CGHeroInstance * visitor, const VCAI * ai);
|
||||||
ui64 evaluateDanger(crint3 tile, const CGHeroInstance * visitor);
|
ui64 evaluateDanger(crint3 tile, const CGHeroInstance * visitor);
|
||||||
};
|
};
|
||||||
|
@ -45,7 +45,7 @@ TSubgoal VisitHero::whatToDoToAchieve()
|
|||||||
|
|
||||||
if(hero && ai->isAccessibleForHero(pos, hero, true) && isSafeToVisit(hero, pos)) //enemy heroes can get reinforcements
|
if(hero && ai->isAccessibleForHero(pos, hero, true) && isSafeToVisit(hero, pos)) //enemy heroes can get reinforcements
|
||||||
{
|
{
|
||||||
if(hero->pos == pos)
|
if(hero->visitablePos() == pos)
|
||||||
logAi->error("Hero %s tries to visit himself.", hero.name);
|
logAi->error("Hero %s tries to visit himself.", hero.name);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -185,10 +185,11 @@ std::vector<CGPathNode *> AINodeStorage::calculateNeighbours(
|
|||||||
return neighbours;
|
return neighbours;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AINodeStorage::setHero(HeroPtr heroPtr, const CPlayerSpecificInfoCallback * _cb)
|
void AINodeStorage::setHero(HeroPtr heroPtr, const VCAI * _ai)
|
||||||
{
|
{
|
||||||
hero = heroPtr.get();
|
hero = heroPtr.get();
|
||||||
cb = _cb;
|
cb = _ai->myCb.get();
|
||||||
|
ai = _ai;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CGPathNode *> AINodeStorage::calculateTeleportations(
|
std::vector<CGPathNode *> AINodeStorage::calculateTeleportations(
|
||||||
|
@ -62,6 +62,7 @@ private:
|
|||||||
/// 1-3 - position on map, 4 - layer (air, water, land), 5 - chain (normal, battle, spellcast and combinations)
|
/// 1-3 - position on map, 4 - layer (air, water, land), 5 - chain (normal, battle, spellcast and combinations)
|
||||||
boost::multi_array<AIPathNode, 5> nodes;
|
boost::multi_array<AIPathNode, 5> nodes;
|
||||||
const CPlayerSpecificInfoCallback * cb;
|
const CPlayerSpecificInfoCallback * cb;
|
||||||
|
const VCAI * ai;
|
||||||
const CGHeroInstance * hero;
|
const CGHeroInstance * hero;
|
||||||
std::unique_ptr<FuzzyHelper> dangerEvaluator;
|
std::unique_ptr<FuzzyHelper> dangerEvaluator;
|
||||||
|
|
||||||
@ -106,7 +107,7 @@ public:
|
|||||||
std::vector<AIPath> getChainInfo(const int3 & pos, bool isOnLand) const;
|
std::vector<AIPath> getChainInfo(const int3 & pos, bool isOnLand) const;
|
||||||
bool isTileAccessible(const int3 & pos, const EPathfindingLayer layer) const;
|
bool isTileAccessible(const int3 & pos, const EPathfindingLayer layer) const;
|
||||||
|
|
||||||
void setHero(HeroPtr heroPtr, const CPlayerSpecificInfoCallback * cb);
|
void setHero(HeroPtr heroPtr, const VCAI * ai);
|
||||||
|
|
||||||
const CGHeroInstance * getHero() const
|
const CGHeroInstance * getHero() const
|
||||||
{
|
{
|
||||||
@ -115,7 +116,7 @@ public:
|
|||||||
|
|
||||||
uint64_t evaluateDanger(const int3 & tile) const
|
uint64_t evaluateDanger(const int3 & tile) const
|
||||||
{
|
{
|
||||||
return dangerEvaluator->evaluateDanger(tile, hero, cb);
|
return dangerEvaluator->evaluateDanger(tile, hero, ai);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -62,7 +62,6 @@ void AIPathfinder::updatePaths(std::vector<HeroPtr> heroes)
|
|||||||
|
|
||||||
std::vector<Task> calculationTasks;
|
std::vector<Task> calculationTasks;
|
||||||
|
|
||||||
// TODO: go parallel?
|
|
||||||
for(HeroPtr hero : heroes)
|
for(HeroPtr hero : heroes)
|
||||||
{
|
{
|
||||||
std::shared_ptr<AINodeStorage> nodeStorage;
|
std::shared_ptr<AINodeStorage> nodeStorage;
|
||||||
@ -78,7 +77,7 @@ void AIPathfinder::updatePaths(std::vector<HeroPtr> heroes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
storageMap[hero] = nodeStorage;
|
storageMap[hero] = nodeStorage;
|
||||||
nodeStorage->setHero(hero, cb);
|
nodeStorage->setHero(hero, ai);
|
||||||
|
|
||||||
auto config = std::make_shared<AIPathfinding::AIPathfinderConfig>(cb, ai, nodeStorage);
|
auto config = std::make_shared<AIPathfinding::AIPathfinderConfig>(cb, ai, nodeStorage);
|
||||||
|
|
||||||
@ -121,7 +120,7 @@ void AIPathfinder::updatePaths(const HeroPtr & hero)
|
|||||||
}
|
}
|
||||||
|
|
||||||
storageMap[hero] = nodeStorage;
|
storageMap[hero] = nodeStorage;
|
||||||
nodeStorage->setHero(hero, cb);
|
nodeStorage->setHero(hero, ai);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user