1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +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; return;
} }
std::string taskDescr = bestTask->toString();
boost::this_thread::interruption_point(); 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 try
{ {
@ -256,7 +258,7 @@ void Nullkiller::makeTurn()
} }
catch(std::exception & e) 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()); logAi->debug("The error message was: %s", e.what());
return; return;

View File

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

View File

@ -124,7 +124,7 @@ void ChainActor::setBaseActor(HeroActor * base)
void HeroActor::setupSpecialActors() void HeroActor::setupSpecialActors()
{ {
auto allActors = std::vector<ChainActor *>{ this }; auto allActors = std::vector<ChainActor *>{this};
for(ChainActor & specialActor : specialActors) for(ChainActor & specialActor : specialActors)
{ {
@ -240,6 +240,9 @@ HeroActor * HeroExchangeMap::tryExchange(const ChainActor * other)
return nullptr; 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; TResources availableResources = resources - actor->armyCost - other->armyCost;
HeroExchangeArmy * upgradedInitialArmy = tryUpgrade(actor->creatureSet, other->getActorObject(), availableResources); HeroExchangeArmy * upgradedInitialArmy = tryUpgrade(actor->creatureSet, other->getActorObject(), availableResources);
HeroExchangeArmy * newArmy; HeroExchangeArmy * newArmy;
@ -277,7 +280,7 @@ HeroActor * HeroExchangeMap::tryExchange(const ChainActor * other)
100.0f * reinforcement / actor->armyValue); 100.0f * reinforcement / actor->armyValue);
#endif #endif
if(reinforcement <= actor->armyValue / 10 && reinforcement < 1000) if(reinforcement <= actor->armyValue / 10 && reinforcement < MIN_ARMY_STRENGTH_FOR_CHAIN)
{ {
delete newArmy; delete newArmy;
@ -367,7 +370,7 @@ HillFortActor::HillFortActor(const CGObjectInstance * hillFort, uint64_t chainMa
} }
DwellingActor::DwellingActor(const CGDwelling * dwelling, uint64_t chainMask, bool waitForGrowth, int dayOfWeek) DwellingActor::DwellingActor(const CGDwelling * dwelling, uint64_t chainMask, bool waitForGrowth, int dayOfWeek)
:ObjectActor( : ObjectActor(
dwelling, dwelling,
getDwellingCreatures(dwelling, waitForGrowth), getDwellingCreatures(dwelling, waitForGrowth),
chainMask, chainMask,

View File

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