mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-28 23:06:24 +02:00
NKAI: mutex for internal AI state
This commit is contained in:
parent
cc7fc4a2c6
commit
36bc9ddcec
@ -588,6 +588,8 @@ void AIGateway::heroGotLevel(const CGHeroInstance * hero, PrimarySkill pskill, s
|
||||
{
|
||||
if(hPtr.validAndSet())
|
||||
{
|
||||
std::unique_lock<std::mutex> lockGuard(nullkiller->aiStateMutex);
|
||||
|
||||
nullkiller->heroManager->update();
|
||||
answerQuery(queryID, nullkiller->heroManager->selectBestSkill(hPtr, skills));
|
||||
}
|
||||
@ -661,14 +663,18 @@ void AIGateway::showBlockingDialog(const std::string & text, const std::vector<C
|
||||
if(selection) //select from multiple components -> take the last one (they're indexed [1-size])
|
||||
sel = components.size();
|
||||
|
||||
// TODO: Find better way to understand it is Chest of Treasures
|
||||
if(hero.validAndSet()
|
||||
&& components.size() == 2
|
||||
&& components.front().type == ComponentType::RESOURCE
|
||||
&& (nullkiller->heroManager->getHeroRole(hero) != HeroRole::MAIN
|
||||
|| nullkiller->buildAnalyzer->getGoldPreasure() > MAX_GOLD_PEASURE))
|
||||
{
|
||||
sel = 1; // for now lets pick gold from a chest.
|
||||
std::unique_lock<std::mutex>(nullkiller->aiStateMutex);
|
||||
|
||||
// TODO: Find better way to understand it is Chest of Treasures
|
||||
if(hero.validAndSet()
|
||||
&& components.size() == 2
|
||||
&& components.front().type == ComponentType::RESOURCE
|
||||
&& (nullkiller->heroManager->getHeroRole(hero) != HeroRole::MAIN
|
||||
|| nullkiller->buildAnalyzer->getGoldPreasure() > MAX_GOLD_PEASURE))
|
||||
{
|
||||
sel = 1; // for now lets pick gold from a chest.
|
||||
}
|
||||
}
|
||||
|
||||
answerQuery(askID, sel);
|
||||
@ -859,6 +865,8 @@ void AIGateway::performObjectInteraction(const CGObjectInstance * obj, HeroPtr h
|
||||
{
|
||||
makePossibleUpgrades(h.get());
|
||||
|
||||
std::unique_lock<std::mutex> lockGuard(nullkiller->aiStateMutex);
|
||||
|
||||
if(!h->visitedTown->garrisonHero || !nullkiller->isHeroLocked(h->visitedTown->garrisonHero))
|
||||
moveCreaturesToHero(h->visitedTown);
|
||||
|
||||
|
@ -115,6 +115,8 @@ Goals::TTask Nullkiller::choseBestTask(Goals::TSubgoal behavior, int decompositi
|
||||
|
||||
void Nullkiller::resetAiState()
|
||||
{
|
||||
std::unique_lock<std::mutex> lockGuard(aiStateMutex);
|
||||
|
||||
lockedResources = TResources();
|
||||
scanDepth = ScanDepth::MAIN_FULL;
|
||||
playerID = ai->playerID;
|
||||
@ -127,6 +129,8 @@ void Nullkiller::updateAiState(int pass, bool fast)
|
||||
{
|
||||
boost::this_thread::interruption_point();
|
||||
|
||||
std::unique_lock<std::mutex> lockGuard(aiStateMutex);
|
||||
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
activeHero = nullptr;
|
||||
|
@ -73,6 +73,7 @@ public:
|
||||
std::unique_ptr<ArmyFormation> armyFormation;
|
||||
PlayerColor playerID;
|
||||
std::shared_ptr<CCallback> cb;
|
||||
std::mutex aiStateMutex;
|
||||
|
||||
Nullkiller();
|
||||
void init(std::shared_ptr<CCallback> cb, PlayerColor playerID);
|
||||
|
Loading…
Reference in New Issue
Block a user