2021-05-15 18:22:44 +02:00
|
|
|
/*
|
|
|
|
* AIUtility.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "AIUtility.h"
|
2021-05-16 14:39:38 +02:00
|
|
|
#include "AIGateway.h"
|
2021-05-15 18:22:44 +02:00
|
|
|
#include "Goals/Goals.h"
|
|
|
|
|
|
|
|
#include "../../lib/UnlockGuard.h"
|
|
|
|
#include "../../lib/CConfigHandler.h"
|
2020-05-04 17:58:43 +02:00
|
|
|
#include "../../lib/mapObjects/MapObjects.h"
|
2021-05-15 18:22:44 +02:00
|
|
|
#include "../../lib/mapping/CMapDefines.h"
|
2023-06-23 17:02:48 +02:00
|
|
|
#include "../../lib/gameState/QuestInfo.h"
|
2024-08-31 13:00:36 +02:00
|
|
|
#include "../../lib/IGameSettings.h"
|
2021-05-16 13:56:27 +02:00
|
|
|
|
2023-04-05 02:26:29 +02:00
|
|
|
#include <vcmi/CreatureService.h>
|
|
|
|
|
2022-09-26 20:01:07 +02:00
|
|
|
namespace NKAI
|
|
|
|
{
|
|
|
|
|
2021-05-15 18:22:44 +02:00
|
|
|
const CGObjectInstance * ObjectIdRef::operator->() const
|
|
|
|
{
|
|
|
|
return cb->getObj(id, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectIdRef::operator const CGObjectInstance *() const
|
|
|
|
{
|
|
|
|
return cb->getObj(id, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectIdRef::operator bool() const
|
|
|
|
{
|
|
|
|
return cb->getObj(id, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectIdRef::ObjectIdRef(ObjectInstanceID _id)
|
|
|
|
: id(_id)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectIdRef::ObjectIdRef(const CGObjectInstance * obj)
|
|
|
|
: id(obj->id)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ObjectIdRef::operator<(const ObjectIdRef & rhs) const
|
|
|
|
{
|
|
|
|
return id < rhs.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeroPtr::HeroPtr(const CGHeroInstance * H)
|
|
|
|
{
|
|
|
|
if(!H)
|
|
|
|
{
|
|
|
|
//init from nullptr should equal to default init
|
|
|
|
*this = HeroPtr();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
h = H;
|
|
|
|
hid = H->id;
|
|
|
|
// infosCount[ai->playerID][hid]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeroPtr::HeroPtr()
|
|
|
|
{
|
|
|
|
h = nullptr;
|
|
|
|
hid = ObjectInstanceID();
|
|
|
|
}
|
|
|
|
|
|
|
|
HeroPtr::~HeroPtr()
|
|
|
|
{
|
|
|
|
// if(hid >= 0)
|
|
|
|
// infosCount[ai->playerID][hid]--;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HeroPtr::operator<(const HeroPtr & rhs) const
|
|
|
|
{
|
|
|
|
return hid < rhs.hid;
|
|
|
|
}
|
|
|
|
|
2024-07-03 19:01:38 +02:00
|
|
|
std::string HeroPtr::name() const
|
|
|
|
{
|
|
|
|
if (h)
|
|
|
|
return h->getNameTextID();
|
|
|
|
else
|
|
|
|
return "<NO HERO>";
|
|
|
|
}
|
|
|
|
|
2021-05-15 18:22:44 +02:00
|
|
|
const CGHeroInstance * HeroPtr::get(bool doWeExpectNull) const
|
|
|
|
{
|
2024-04-20 09:33:37 +02:00
|
|
|
return get(cb, doWeExpectNull);
|
2021-05-15 18:22:44 +02:00
|
|
|
}
|
|
|
|
|
2024-04-14 14:23:44 +02:00
|
|
|
const CGHeroInstance * HeroPtr::get(const CPlayerSpecificInfoCallback * cb, bool doWeExpectNull) const
|
2021-05-16 14:08:56 +02:00
|
|
|
{
|
|
|
|
//TODO? check if these all assertions every time we get info about hero affect efficiency
|
|
|
|
//
|
|
|
|
//behave terribly when attempting unauthorized access to hero that is not ours (or was lost)
|
|
|
|
assert(doWeExpectNull || h);
|
|
|
|
|
|
|
|
if(h)
|
|
|
|
{
|
|
|
|
auto obj = cb->getObj(hid);
|
|
|
|
//const bool owned = obj && obj->tempOwner == ai->playerID;
|
|
|
|
|
|
|
|
if(doWeExpectNull && !obj)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assert(obj);
|
|
|
|
//assert(owned);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2021-05-15 18:22:44 +02:00
|
|
|
const CGHeroInstance * HeroPtr::operator->() const
|
|
|
|
{
|
|
|
|
return get();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HeroPtr::validAndSet() const
|
|
|
|
{
|
|
|
|
return get(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
const CGHeroInstance * HeroPtr::operator*() const
|
|
|
|
{
|
|
|
|
return get();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HeroPtr::operator==(const HeroPtr & rhs) const
|
|
|
|
{
|
|
|
|
return h == rhs.get(true);
|
|
|
|
}
|
|
|
|
|
2024-03-29 20:39:03 +02:00
|
|
|
bool isSafeToVisit(const CGHeroInstance * h, const CCreatureSet * heroArmy, uint64_t dangerStrength)
|
2021-05-15 18:22:44 +02:00
|
|
|
{
|
2019-03-17 23:27:09 +02:00
|
|
|
const ui64 heroStrength = h->getFightingStrength() * heroArmy->getArmyStrength();
|
2021-05-15 18:22:44 +02:00
|
|
|
|
|
|
|
if(dangerStrength)
|
|
|
|
{
|
2019-04-07 06:31:47 +02:00
|
|
|
return heroStrength / SAFE_ATTACK_CONSTANT > dangerStrength;
|
2021-05-15 18:22:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true; //there's no danger
|
|
|
|
}
|
|
|
|
|
2024-03-29 20:39:03 +02:00
|
|
|
bool isSafeToVisit(const CGHeroInstance * h, uint64_t dangerStrength)
|
2021-05-15 20:01:48 +02:00
|
|
|
{
|
2024-03-29 20:39:03 +02:00
|
|
|
return isSafeToVisit(h, h, dangerStrength);
|
2021-05-15 20:01:48 +02:00
|
|
|
}
|
|
|
|
|
2021-05-15 18:22:44 +02:00
|
|
|
bool isObjectRemovable(const CGObjectInstance * obj)
|
|
|
|
{
|
|
|
|
//FIXME: move logic to object property!
|
|
|
|
switch (obj->ID)
|
|
|
|
{
|
|
|
|
case Obj::MONSTER:
|
|
|
|
case Obj::RESOURCE:
|
|
|
|
case Obj::CAMPFIRE:
|
|
|
|
case Obj::TREASURE_CHEST:
|
|
|
|
case Obj::ARTIFACT:
|
|
|
|
case Obj::BORDERGUARD:
|
|
|
|
case Obj::FLOTSAM:
|
|
|
|
case Obj::PANDORAS_BOX:
|
|
|
|
case Obj::OCEAN_BOTTLE:
|
|
|
|
case Obj::SEA_CHEST:
|
|
|
|
case Obj::SHIPWRECK_SURVIVOR:
|
|
|
|
case Obj::SPELL_SCROLL:
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool canBeEmbarkmentPoint(const TerrainTile * t, bool fromWater)
|
|
|
|
{
|
|
|
|
// TODO: Such information should be provided by pathfinder
|
|
|
|
// Tile must be free or with unoccupied boat
|
|
|
|
if(!t->blocked)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if(!fromWater) // do not try to board when in water sector
|
|
|
|
{
|
|
|
|
if(t->visitableObjects.size() == 1 && t->topVisitableId() == Obj::BOAT)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-16 14:08:56 +02:00
|
|
|
bool isObjectPassable(const Nullkiller * ai, const CGObjectInstance * obj)
|
|
|
|
{
|
|
|
|
return isObjectPassable(obj, ai->playerID, ai->cb->getPlayerRelations(obj->tempOwner, ai->playerID));
|
|
|
|
}
|
|
|
|
|
2021-05-16 13:45:30 +02:00
|
|
|
// Pathfinder internal helper
|
2023-08-19 20:43:50 +02:00
|
|
|
bool isObjectPassable(const CGObjectInstance * obj, PlayerColor playerColor, PlayerRelations objectRelations)
|
2021-05-16 13:45:30 +02:00
|
|
|
{
|
|
|
|
if((obj->ID == Obj::GARRISON || obj->ID == Obj::GARRISON2)
|
|
|
|
&& objectRelations != PlayerRelations::ENEMIES)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if(obj->ID == Obj::BORDER_GATE)
|
|
|
|
{
|
|
|
|
auto quest = dynamic_cast<const CGKeys *>(obj);
|
|
|
|
|
2022-12-26 20:17:39 +02:00
|
|
|
if(quest->wasMyColorVisited(playerColor))
|
2021-05-16 13:45:30 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-15 18:22:44 +02:00
|
|
|
bool isBlockVisitObj(const int3 & pos)
|
|
|
|
{
|
|
|
|
if(auto obj = cb->getTopObj(pos))
|
|
|
|
{
|
2023-06-21 15:49:44 +02:00
|
|
|
if(obj->isBlockedVisitable()) //we can't stand on that object
|
2021-05-15 18:22:44 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
creInfo infoFromDC(const dwellingContent & dc)
|
|
|
|
{
|
|
|
|
creInfo ci;
|
|
|
|
ci.count = dc.first;
|
|
|
|
ci.creID = dc.second.size() ? dc.second.back() : CreatureID(-1); //should never be accessed
|
2023-08-19 19:48:28 +02:00
|
|
|
if (ci.creID != CreatureID::NONE)
|
2021-05-15 18:22:44 +02:00
|
|
|
{
|
2023-12-31 23:43:35 +02:00
|
|
|
ci.level = ci.creID.toCreature()->getLevel(); //this is creature tier, while tryRealize expects dwelling level. Ignore.
|
2021-05-15 18:22:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ci.level = 0;
|
|
|
|
}
|
|
|
|
return ci;
|
|
|
|
}
|
|
|
|
|
2024-03-29 20:39:03 +02:00
|
|
|
bool compareHeroStrength(const CGHeroInstance * h1, const CGHeroInstance * h2)
|
2021-05-15 18:22:44 +02:00
|
|
|
{
|
|
|
|
return h1->getTotalStrength() < h2->getTotalStrength();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool compareArmyStrength(const CArmedInstance * a1, const CArmedInstance * a2)
|
|
|
|
{
|
|
|
|
return a1->getArmyStrength() < a2->getArmyStrength();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool compareArtifacts(const CArtifactInstance * a1, const CArtifactInstance * a2)
|
|
|
|
{
|
|
|
|
auto art1 = a1->artType;
|
|
|
|
auto art2 = a2->artType;
|
|
|
|
|
2023-07-03 22:11:56 +02:00
|
|
|
if(art1->getPrice() == art2->getPrice())
|
2023-05-01 00:20:01 +02:00
|
|
|
return art1->valOfBonuses(BonusType::PRIMARY_SKILL) > art2->valOfBonuses(BonusType::PRIMARY_SKILL);
|
2021-05-15 18:22:44 +02:00
|
|
|
else
|
2023-07-03 22:11:56 +02:00
|
|
|
return art1->getPrice() > art2->getPrice();
|
2021-05-15 18:22:44 +02:00
|
|
|
}
|
2020-05-04 17:58:43 +02:00
|
|
|
|
2024-03-31 17:39:00 +02:00
|
|
|
bool isWeeklyRevisitable(const Nullkiller * ai, const CGObjectInstance * obj)
|
2020-05-04 17:58:43 +02:00
|
|
|
{
|
2022-09-24 16:29:29 +02:00
|
|
|
if(!obj)
|
|
|
|
return false;
|
|
|
|
|
2020-05-04 17:58:43 +02:00
|
|
|
//TODO: allow polling of remaining creatures in dwelling
|
2023-01-23 15:27:01 +02:00
|
|
|
if(const auto * rewardable = dynamic_cast<const CRewardableObject *>(obj))
|
2023-04-30 15:13:07 +02:00
|
|
|
return rewardable->configuration.getResetDuration() == 7;
|
2023-01-23 15:27:01 +02:00
|
|
|
|
2020-05-04 17:58:43 +02:00
|
|
|
if(dynamic_cast<const CGDwelling *>(obj))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
switch(obj->ID)
|
|
|
|
{
|
|
|
|
case Obj::HILL_FORT:
|
|
|
|
return true;
|
|
|
|
case Obj::BORDER_GATE:
|
|
|
|
case Obj::BORDERGUARD:
|
|
|
|
return (dynamic_cast<const CGKeys *>(obj))->wasMyColorVisited(ai->playerID); //FIXME: they could be revisited sooner than in a week
|
|
|
|
}
|
|
|
|
return false;
|
2021-05-16 13:56:13 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 10:56:06 +02:00
|
|
|
uint64_t timeElapsed(std::chrono::time_point<std::chrono::high_resolution_clock> start)
|
2021-05-16 13:56:13 +02:00
|
|
|
{
|
2021-11-23 08:41:03 +02:00
|
|
|
auto end = std::chrono::high_resolution_clock::now();
|
2021-05-16 13:56:13 +02:00
|
|
|
|
2021-11-23 08:41:03 +02:00
|
|
|
return std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
|
2021-05-16 13:56:27 +02:00
|
|
|
}
|
|
|
|
|
2024-04-20 09:33:37 +02:00
|
|
|
int getDuplicatingSlots(const CArmedInstance * army)
|
|
|
|
{
|
|
|
|
int duplicatingSlots = 0;
|
|
|
|
|
|
|
|
for(auto stack : army->Slots())
|
|
|
|
{
|
|
|
|
if(stack.second->type && army->getSlotFor(stack.second->type) != stack.first)
|
|
|
|
duplicatingSlots++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return duplicatingSlots;
|
|
|
|
}
|
|
|
|
|
2021-05-16 13:56:27 +02:00
|
|
|
// todo: move to obj manager
|
2021-05-16 14:08:56 +02:00
|
|
|
bool shouldVisit(const Nullkiller * ai, const CGHeroInstance * h, const CGObjectInstance * obj)
|
2021-05-16 13:56:27 +02:00
|
|
|
{
|
2022-11-13 11:01:32 +02:00
|
|
|
auto relations = ai->cb->getPlayerRelations(obj->tempOwner, h->tempOwner);
|
|
|
|
|
2021-05-16 13:56:27 +02:00
|
|
|
switch(obj->ID)
|
|
|
|
{
|
|
|
|
case Obj::TOWN:
|
|
|
|
case Obj::HERO: //never visit our heroes at random
|
2022-11-13 11:01:32 +02:00
|
|
|
return relations == PlayerRelations::ENEMIES; //do not visit our towns at random
|
|
|
|
|
2021-05-16 13:56:27 +02:00
|
|
|
case Obj::BORDER_GATE:
|
|
|
|
{
|
2021-05-16 14:08:56 +02:00
|
|
|
for(auto q : ai->cb->getMyQuests())
|
2021-05-16 13:56:27 +02:00
|
|
|
{
|
|
|
|
if(q.obj == obj)
|
|
|
|
{
|
|
|
|
return false; // do not visit guards or gates when wandering
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true; //we don't have this quest yet
|
|
|
|
}
|
|
|
|
case Obj::BORDERGUARD: //open borderguard if possible
|
|
|
|
return (dynamic_cast<const CGKeys *>(obj))->wasMyColorVisited(ai->playerID);
|
|
|
|
case Obj::SEER_HUT:
|
|
|
|
{
|
2021-05-16 14:08:56 +02:00
|
|
|
for(auto q : ai->cb->getMyQuests())
|
2021-05-16 13:56:27 +02:00
|
|
|
{
|
|
|
|
if(q.obj == obj)
|
|
|
|
{
|
|
|
|
if(q.quest->checkQuest(h))
|
|
|
|
return true; //we completed the quest
|
|
|
|
else
|
|
|
|
return false; //we can't complete this quest
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true; //we don't have this quest yet
|
|
|
|
}
|
|
|
|
case Obj::CREATURE_GENERATOR1:
|
|
|
|
{
|
2022-11-13 11:01:32 +02:00
|
|
|
if(relations == PlayerRelations::ENEMIES)
|
2021-05-16 13:56:27 +02:00
|
|
|
return true; //flag just in case
|
|
|
|
|
2022-11-13 11:01:32 +02:00
|
|
|
if(relations == PlayerRelations::ALLIES)
|
|
|
|
return false;
|
|
|
|
|
2021-05-16 13:56:27 +02:00
|
|
|
const CGDwelling * d = dynamic_cast<const CGDwelling *>(obj);
|
2024-04-20 09:33:37 +02:00
|
|
|
auto duplicatingSlotsCount = getDuplicatingSlots(h);
|
2021-05-16 13:56:27 +02:00
|
|
|
|
|
|
|
for(auto level : d->creatures)
|
|
|
|
{
|
|
|
|
for(auto c : level.second)
|
|
|
|
{
|
|
|
|
if(level.first
|
2024-04-20 09:33:37 +02:00
|
|
|
&& (h->getSlotFor(CreatureID(c)) != SlotID() || duplicatingSlotsCount > 0)
|
2023-04-05 02:26:29 +02:00
|
|
|
&& ai->cb->getResourceAmount().canAfford(c.toCreature()->getFullRecruitCost()))
|
2021-05-16 13:56:27 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case Obj::HILL_FORT:
|
|
|
|
{
|
|
|
|
for(auto slot : h->Slots())
|
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
if(slot.second->type->hasUpgrades())
|
2021-05-16 13:56:27 +02:00
|
|
|
return true; //TODO: check price?
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case Obj::MONOLITH_ONE_WAY_ENTRANCE:
|
|
|
|
case Obj::MONOLITH_ONE_WAY_EXIT:
|
|
|
|
case Obj::MONOLITH_TWO_WAY:
|
|
|
|
case Obj::WHIRLPOOL:
|
|
|
|
return false;
|
|
|
|
case Obj::SCHOOL_OF_MAGIC:
|
|
|
|
case Obj::SCHOOL_OF_WAR:
|
|
|
|
{
|
2021-05-16 14:39:38 +02:00
|
|
|
if(ai->getFreeGold() < 1000)
|
2021-05-16 13:56:27 +02:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Obj::LIBRARY_OF_ENLIGHTENMENT:
|
2022-11-13 11:01:32 +02:00
|
|
|
if(h->level < 10)
|
2021-05-16 13:56:27 +02:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case Obj::TREE_OF_KNOWLEDGE:
|
|
|
|
{
|
2021-05-16 14:08:56 +02:00
|
|
|
if(ai->heroManager->getHeroRole(h) == HeroRole::SCOUT)
|
2021-05-16 13:56:27 +02:00
|
|
|
return false;
|
|
|
|
|
2021-05-16 14:39:38 +02:00
|
|
|
TResources myRes = ai->getFreeResources();
|
2023-04-05 02:26:29 +02:00
|
|
|
if(myRes[EGameResID::GOLD] < 2000 || myRes[EGameResID::GEMS] < 10)
|
2021-05-16 13:56:27 +02:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Obj::MAGIC_WELL:
|
|
|
|
return h->mana < h->manaLimit();
|
|
|
|
case Obj::PRISON:
|
2024-02-25 12:39:19 +02:00
|
|
|
return !ai->heroManager->heroCapReached();
|
2021-05-16 13:56:27 +02:00
|
|
|
case Obj::TAVERN:
|
2021-05-16 14:39:38 +02:00
|
|
|
case Obj::EYE_OF_MAGI:
|
2021-05-16 13:56:27 +02:00
|
|
|
case Obj::BOAT:
|
2021-05-16 14:39:38 +02:00
|
|
|
case Obj::SIGN:
|
2021-05-16 13:56:27 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-04-20 14:28:42 +02:00
|
|
|
if(obj->wasVisited(h))
|
2021-05-16 13:56:27 +02:00
|
|
|
return false;
|
|
|
|
|
2024-04-20 14:28:42 +02:00
|
|
|
auto rewardable = dynamic_cast<const Rewardable::Interface *>(obj);
|
|
|
|
|
|
|
|
if(rewardable && rewardable->getAvailableRewards(h, Rewardable::EEventType::EVENT_FIRST_VISIT).empty())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-16 13:56:27 +02:00
|
|
|
return true;
|
2021-11-23 08:41:03 +02:00
|
|
|
}
|
2022-09-26 20:01:07 +02:00
|
|
|
|
2022-10-15 14:05:20 +02:00
|
|
|
bool townHasFreeTavern(const CGTownInstance * town)
|
|
|
|
{
|
|
|
|
if(!town->hasBuilt(BuildingID::TAVERN)) return false;
|
|
|
|
if(!town->visitingHero) return true;
|
|
|
|
|
2024-06-24 03:23:26 +02:00
|
|
|
bool canMoveVisitingHeroToGarrison = !town->getUpperArmy()->stacksCount();
|
2022-10-15 14:05:20 +02:00
|
|
|
|
2024-06-24 03:23:26 +02:00
|
|
|
return canMoveVisitingHeroToGarrison;
|
2022-10-15 14:05:20 +02:00
|
|
|
}
|
|
|
|
|
2024-04-26 22:18:20 +02:00
|
|
|
uint64_t getHeroArmyStrengthWithCommander(const CGHeroInstance * hero, const CCreatureSet * heroArmy)
|
|
|
|
{
|
|
|
|
auto armyStrength = heroArmy->getArmyStrength();
|
|
|
|
|
|
|
|
if(hero && hero->commander && hero->commander->alive)
|
|
|
|
{
|
|
|
|
armyStrength += 100 * hero->commander->level;
|
|
|
|
}
|
|
|
|
|
|
|
|
return armyStrength;
|
|
|
|
}
|
|
|
|
|
2022-09-26 20:01:07 +02:00
|
|
|
}
|