1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Nullkiller: fix crash, refactor

This commit is contained in:
Andrii Danylchenko 2021-05-16 15:08:39 +03:00 committed by Andrii Danylchenko
parent fb3cda666f
commit 0265de77fa
4 changed files with 24 additions and 14 deletions

View File

@ -243,8 +243,10 @@ void Nullkiller::makeTurn()
return;
}
std::string taskDescr = bestTask->toString();
boost::this_thread::interruption_point();
logAi->debug("Trying to realize %s (value %2.3f)", bestTask->toString(), bestTask->priority);
logAi->debug("Trying to realize %s (value %2.3f)", taskDescr, bestTask->priority);
try
{
@ -256,7 +258,7 @@ void Nullkiller::makeTurn()
}
catch(std::exception & e)
{
logAi->debug("Failed to realize subgoal of type %s, I will stop.", bestTask->toString());
logAi->debug("Failed to realize subgoal of type %s, I will stop.", taskDescr);
logAi->debug("The error message was: %s", e.what());
return;

View File

@ -30,6 +30,9 @@ const uint64_t FirstActorMask = 1;
const int BUCKET_COUNT = 11;
const int BUCKET_SIZE = GameConstants::MAX_HEROES_PER_PLAYER;
const int NUM_CHAINS = BUCKET_COUNT * BUCKET_SIZE;
const uint64_t MIN_ARMY_STRENGTH_FOR_CHAIN = 5000;
const uint64_t MIN_ARMY_STRENGTH_FOR_NEXT_ACTOR = 1000;
AISharedStorage::AISharedStorage(int3 sizes)
{
@ -535,7 +538,7 @@ bool AINodeStorage::selectNextActor()
if(nextActor != actors.end())
{
if(nextActor->get()->armyValue < 1000)
if(nextActor->get()->armyValue < MIN_ARMY_STRENGTH_FOR_NEXT_ACTOR)
return false;
chainMask = nextActor->get()->chainMask;

View File

@ -240,6 +240,9 @@ HeroActor * HeroExchangeMap::tryExchange(const ChainActor * other)
return nullptr;
}
if(other->isMovable && other->armyValue <= actor->armyValue / 10 && other->armyValue < MIN_ARMY_STRENGTH_FOR_CHAIN)
return nullptr;
TResources availableResources = resources - actor->armyCost - other->armyCost;
HeroExchangeArmy * upgradedInitialArmy = tryUpgrade(actor->creatureSet, other->getActorObject(), availableResources);
HeroExchangeArmy * newArmy;
@ -277,7 +280,7 @@ HeroActor * HeroExchangeMap::tryExchange(const ChainActor * other)
100.0f * reinforcement / actor->armyValue);
#endif
if(reinforcement <= actor->armyValue / 10 && reinforcement < 1000)
if(reinforcement <= actor->armyValue / 10 && reinforcement < MIN_ARMY_STRENGTH_FOR_CHAIN)
{
delete newArmy;

View File

@ -15,6 +15,8 @@
#include "../AIUtility.h"
#include "Actions/SpecialAction.h"
extern const uint64_t MIN_ARMY_STRENGTH_FOR_CHAIN;
class HeroActor;
class Nullkiller;