mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-27 21:49:10 +02:00
nullkiller&herochain stabilisation
This commit is contained in:
parent
62e5366a08
commit
87f1079c60
@ -148,9 +148,9 @@ std::vector<AIPath> AIhelper::getPathsToTile(const HeroPtr & hero, const int3 &
|
|||||||
return pathfindingManager->getPathsToTile(hero, tile);
|
return pathfindingManager->getPathsToTile(hero, tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AIhelper::updatePaths(std::vector<HeroPtr> heroes)
|
void AIhelper::updatePaths(std::vector<HeroPtr> heroes, bool useHeroChain)
|
||||||
{
|
{
|
||||||
pathfindingManager->updatePaths(heroes);
|
pathfindingManager->updatePaths(heroes, useHeroChain);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AIhelper::updatePaths(const HeroPtr & hero)
|
void AIhelper::updatePaths(const HeroPtr & hero)
|
||||||
|
@ -60,7 +60,7 @@ public:
|
|||||||
Goals::TGoalVec howToVisitTile(const int3 & tile, bool allowGatherArmy = true) const override;
|
Goals::TGoalVec howToVisitTile(const int3 & tile, bool allowGatherArmy = true) const override;
|
||||||
Goals::TGoalVec howToVisitObj(ObjectIdRef obj, bool allowGatherArmy = true) const override;
|
Goals::TGoalVec howToVisitObj(ObjectIdRef obj, bool allowGatherArmy = true) const override;
|
||||||
std::vector<AIPath> getPathsToTile(const HeroPtr & hero, const int3 & tile) const override;
|
std::vector<AIPath> getPathsToTile(const HeroPtr & hero, const int3 & tile) const override;
|
||||||
void updatePaths(std::vector<HeroPtr> heroes) override;
|
void updatePaths(std::vector<HeroPtr> heroes, bool useHeroChain = false) override;
|
||||||
void updatePaths(const HeroPtr & hero) override;
|
void updatePaths(const HeroPtr & hero) override;
|
||||||
|
|
||||||
STRONG_INLINE
|
STRONG_INLINE
|
||||||
|
@ -26,6 +26,8 @@ Goals::TSubgoal Nullkiller::choseBestTask(Goals::TGoalVec tasks)
|
|||||||
|
|
||||||
Goals::TSubgoal Nullkiller::choseBestTask(Behavior & behavior)
|
Goals::TSubgoal Nullkiller::choseBestTask(Behavior & behavior)
|
||||||
{
|
{
|
||||||
|
logAi->debug("Checking behavior %s", behavior.toString());
|
||||||
|
|
||||||
auto tasks = behavior.getTasks();
|
auto tasks = behavior.getTasks();
|
||||||
|
|
||||||
if(tasks.empty())
|
if(tasks.empty())
|
||||||
@ -51,7 +53,7 @@ void Nullkiller::makeTurn()
|
|||||||
{
|
{
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
ai->ah->updatePaths(ai->getMyHeroes());
|
ai->ah->updatePaths(ai->getMyHeroes(), true);
|
||||||
|
|
||||||
Goals::TGoalVec bestTasks = {
|
Goals::TGoalVec bestTasks = {
|
||||||
choseBestTask(CaptureObjectsBehavior()),
|
choseBestTask(CaptureObjectsBehavior()),
|
||||||
@ -71,6 +73,8 @@ void Nullkiller::makeTurn()
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
activeHero = bestTask->hero;
|
||||||
|
|
||||||
bestTask->accept(ai.get());
|
bestTask->accept(ai.get());
|
||||||
}
|
}
|
||||||
catch(goalFulfilledException &)
|
catch(goalFulfilledException &)
|
||||||
|
@ -8,10 +8,12 @@ class Nullkiller
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<PriorityEvaluator> priorityEvaluator;
|
std::unique_ptr<PriorityEvaluator> priorityEvaluator;
|
||||||
|
HeroPtr activeHero;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Nullkiller();
|
Nullkiller();
|
||||||
void makeTurn();
|
void makeTurn();
|
||||||
|
bool isActive(const CGHeroInstance * hero) const { return activeHero.h == hero; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Goals::TSubgoal choseBestTask(Behavior & behavior);
|
Goals::TSubgoal choseBestTask(Behavior & behavior);
|
||||||
|
@ -323,6 +323,13 @@ void VCAI::heroExchangeStarted(ObjectInstanceID hero1, ObjectInstanceID hero2, Q
|
|||||||
{
|
{
|
||||||
logAi->debug("Heroes owned by different players. Do not exchange army or artifacts.");
|
logAi->debug("Heroes owned by different players. Do not exchange army or artifacts.");
|
||||||
}
|
}
|
||||||
|
else if(nullkiller)
|
||||||
|
{
|
||||||
|
if(nullkiller->isActive(firstHero))
|
||||||
|
transferFrom2to1(secondHero, firstHero);
|
||||||
|
else
|
||||||
|
transferFrom2to1(firstHero, secondHero);
|
||||||
|
}
|
||||||
else if(goalpriority1 > goalpriority2)
|
else if(goalpriority1 > goalpriority2)
|
||||||
{
|
{
|
||||||
transferFrom2to1(firstHero, secondHero);
|
transferFrom2to1(firstHero, secondHero);
|
||||||
@ -1172,7 +1179,8 @@ void VCAI::pickBestCreatures(const CArmedInstance * destinationArmy, const CArme
|
|||||||
{
|
{
|
||||||
if(armyPtr->getCreature(SlotID(j)) == bestArmy[i] && (i != j || armyPtr != destinationArmy)) //it's a searched creature not in dst SLOT
|
if(armyPtr->getCreature(SlotID(j)) == bestArmy[i] && (i != j || armyPtr != destinationArmy)) //it's a searched creature not in dst SLOT
|
||||||
{
|
{
|
||||||
if(!(armyPtr->needsLastStack() && armyPtr->stacksCount() == 1)) //can't take away last creature without split
|
if(!armyPtr->needsLastStack() || armyPtr->stacksCount() != 1
|
||||||
|
|| armyPtr == destinationArmy || 0 < destinationArmy->getStackCount(SlotID(i))) //can't take away last creature without split
|
||||||
{
|
{
|
||||||
cb->mergeOrSwapStacks(armyPtr, destinationArmy, SlotID(j), SlotID(i));
|
cb->mergeOrSwapStacks(armyPtr, destinationArmy, SlotID(j), SlotID(i));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user