1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-14 02:33:51 +02:00

Nullkiller: fix crash when buy army through pathfinder

This commit is contained in:
Andrii Danylchenko 2021-05-16 14:59:35 +03:00 committed by Andrii Danylchenko
parent 45942cfbbe
commit 3dc76cfe35
4 changed files with 25 additions and 4 deletions

View File

@ -188,9 +188,17 @@ std::vector<SlotInfo> ArmyManager::getBestArmy(const IBonusBearer * armyCarrier,
} }
ui64 ArmyManager::howManyReinforcementsCanBuy(const CCreatureSet * h, const CGDwelling * t) const ui64 ArmyManager::howManyReinforcementsCanBuy(const CCreatureSet * h, const CGDwelling * t) const
{
return howManyReinforcementsCanBuy(h, t, cb->getResourceAmount());
}
ui64 ArmyManager::howManyReinforcementsCanBuy(
const CCreatureSet * h,
const CGDwelling * t,
const TResources & availableResources) const
{ {
ui64 aivalue = 0; ui64 aivalue = 0;
auto army = getArmyAvailableToBuy(h, t); auto army = getArmyAvailableToBuy(h, t, availableResources);
for(const creInfo & ci : army) for(const creInfo & ci : army)
{ {

View File

@ -43,6 +43,10 @@ class DLL_EXPORT IArmyManager //: public: IAbstractManager
public: public:
virtual void update() = 0; virtual void update() = 0;
virtual ui64 howManyReinforcementsCanBuy(const CCreatureSet * target, const CGDwelling * source) const = 0; virtual ui64 howManyReinforcementsCanBuy(const CCreatureSet * target, const CGDwelling * source) const = 0;
virtual ui64 howManyReinforcementsCanBuy(
const CCreatureSet * h,
const CGDwelling * t,
const TResources & availableResources) const = 0;
virtual ui64 howManyReinforcementsCanGet(const CGHeroInstance * hero, const CCreatureSet * source) const = 0; virtual ui64 howManyReinforcementsCanGet(const CGHeroInstance * hero, const CCreatureSet * source) const = 0;
virtual ui64 howManyReinforcementsCanGet(const IBonusBearer * armyCarrier, const CCreatureSet * target, const CCreatureSet * source) const = 0; virtual ui64 howManyReinforcementsCanGet(const IBonusBearer * armyCarrier, const CCreatureSet * target, const CCreatureSet * source) const = 0;
virtual std::vector<SlotInfo> getBestArmy(const IBonusBearer * armyCarrier, const CCreatureSet * target, const CCreatureSet * source) const = 0; virtual std::vector<SlotInfo> getBestArmy(const IBonusBearer * armyCarrier, const CCreatureSet * target, const CCreatureSet * source) const = 0;
@ -71,6 +75,10 @@ public:
ArmyManager(CPlayerSpecificInfoCallback * CB, const Nullkiller * ai): cb(CB), ai(ai) {} ArmyManager(CPlayerSpecificInfoCallback * CB, const Nullkiller * ai): cb(CB), ai(ai) {}
void update() override; void update() override;
ui64 howManyReinforcementsCanBuy(const CCreatureSet * target, const CGDwelling * source) const override; ui64 howManyReinforcementsCanBuy(const CCreatureSet * target, const CGDwelling * source) const override;
ui64 howManyReinforcementsCanBuy(
const CCreatureSet * h,
const CGDwelling * t,
const TResources & availableResources) const override;
ui64 howManyReinforcementsCanGet(const CGHeroInstance * hero, const CCreatureSet * source) const override; ui64 howManyReinforcementsCanGet(const CGHeroInstance * hero, const CCreatureSet * source) const override;
ui64 howManyReinforcementsCanGet(const IBonusBearer * armyCarrier, const CCreatureSet * target, const CCreatureSet * source) const override; ui64 howManyReinforcementsCanGet(const IBonusBearer * armyCarrier, const CCreatureSet * target, const CCreatureSet * source) const override;
std::vector<SlotInfo> getBestArmy(const IBonusBearer * armyCarrier, const CCreatureSet * target, const CCreatureSet * source) const override; std::vector<SlotInfo> getBestArmy(const IBonusBearer * armyCarrier, const CCreatureSet * target, const CCreatureSet * source) const override;

View File

@ -11,7 +11,7 @@
#pragma once #pragma once
#define PATHFINDER_TRACE_LEVEL 0 #define PATHFINDER_TRACE_LEVEL 0
#define AI_TRACE_LEVEL 0 #define AI_TRACE_LEVEL 1
#define SCOUT_TURN_DISTANCE_LIMIT 3 #define SCOUT_TURN_DISTANCE_LIMIT 3
#include "../../../lib/CPathfinder.h" #include "../../../lib/CPathfinder.h"

View File

@ -198,10 +198,12 @@ bool HeroExchangeMap::canExchange(const ChainActor * other)
return; return;
} }
TResources availableResources = resources - actor->armyCost - other->armyCost;
auto upgradeInfo = ai->armyManager->calculateCreateresUpgrade( auto upgradeInfo = ai->armyManager->calculateCreateresUpgrade(
actor->creatureSet, actor->creatureSet,
other->getActorObject(), other->getActorObject(),
resources - actor->armyCost - other->armyCost); availableResources);
uint64_t reinforcment = upgradeInfo.upgradeValue; uint64_t reinforcment = upgradeInfo.upgradeValue;
@ -211,7 +213,10 @@ bool HeroExchangeMap::canExchange(const ChainActor * other)
auto obj = other->getActorObject(); auto obj = other->getActorObject();
if(obj && obj->ID == Obj::TOWN) if(obj && obj->ID == Obj::TOWN)
{ {
reinforcment += ai->armyManager->howManyReinforcementsCanBuy(actor->creatureSet, ai->cb->getTown(obj->id)); reinforcment += ai->armyManager->howManyReinforcementsCanBuy(
actor->creatureSet,
ai->cb->getTown(obj->id),
availableResources - upgradeInfo.upgradeCost);
} }
#if PATHFINDER_TRACE_LEVEL >= 2 #if PATHFINDER_TRACE_LEVEL >= 2