mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
Nullkiller: fix crash, refactor
This commit is contained in:
parent
fb3cda666f
commit
0265de77fa
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -93,11 +93,11 @@ HeroActor::HeroActor(const CGHeroInstance * hero, HeroRole heroRole, uint64_t ch
|
||||
}
|
||||
|
||||
HeroActor::HeroActor(
|
||||
const ChainActor * carrier,
|
||||
const ChainActor * other,
|
||||
const HeroExchangeArmy * army,
|
||||
const ChainActor * carrier,
|
||||
const ChainActor * other,
|
||||
const HeroExchangeArmy * army,
|
||||
const Nullkiller * ai)
|
||||
:ChainActor(carrier, other, army)
|
||||
:ChainActor(carrier, other, army)
|
||||
{
|
||||
exchangeMap.reset(new HeroExchangeMap(this, ai));
|
||||
armyCost += army->armyCost;
|
||||
@ -124,7 +124,7 @@ void ChainActor::setBaseActor(HeroActor * base)
|
||||
|
||||
void HeroActor::setupSpecialActors()
|
||||
{
|
||||
auto allActors = std::vector<ChainActor *>{ this };
|
||||
auto allActors = std::vector<ChainActor *>{this};
|
||||
|
||||
for(ChainActor & specialActor : specialActors)
|
||||
{
|
||||
@ -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;
|
||||
|
||||
@ -367,10 +370,10 @@ HillFortActor::HillFortActor(const CGObjectInstance * hillFort, uint64_t chainMa
|
||||
}
|
||||
|
||||
DwellingActor::DwellingActor(const CGDwelling * dwelling, uint64_t chainMask, bool waitForGrowth, int dayOfWeek)
|
||||
:ObjectActor(
|
||||
dwelling,
|
||||
getDwellingCreatures(dwelling, waitForGrowth),
|
||||
chainMask,
|
||||
: ObjectActor(
|
||||
dwelling,
|
||||
getDwellingCreatures(dwelling, waitForGrowth),
|
||||
chainMask,
|
||||
getInitialTurn(waitForGrowth, dayOfWeek)),
|
||||
dwelling(dwelling)
|
||||
{
|
||||
@ -409,7 +412,7 @@ CCreatureSet * DwellingActor::getDwellingCreatures(const CGDwelling * dwelling,
|
||||
|
||||
auto creature = creatureInfo.second.back().toCreature();
|
||||
auto count = creatureInfo.first;
|
||||
|
||||
|
||||
if(waitForGrowth)
|
||||
{
|
||||
const CGTownInstance * town = dynamic_cast<const CGTownInstance *>(dwelling);
|
||||
|
@ -15,6 +15,8 @@
|
||||
#include "../AIUtility.h"
|
||||
#include "Actions/SpecialAction.h"
|
||||
|
||||
extern const uint64_t MIN_ARMY_STRENGTH_FOR_CHAIN;
|
||||
|
||||
class HeroActor;
|
||||
class Nullkiller;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user