mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-21 12:06:49 +02:00
Nullkiller: temporary hacks to allow army buying
This commit is contained in:
parent
286d084445
commit
04bf6f536d
73
AI/Nullkiller/Behaviors/BuyArmyBehavior.cpp
Normal file
73
AI/Nullkiller/Behaviors/BuyArmyBehavior.cpp
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Goals.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 "BuyArmyBehavior.h"
|
||||||
|
#include "../VCAI.h"
|
||||||
|
#include "../AIhelper.h"
|
||||||
|
#include "../AIUtility.h"
|
||||||
|
#include "../Goals/BuyArmy.h"
|
||||||
|
#include "../Goals/VisitTile.h"
|
||||||
|
#include "lib/mapping/CMap.h" //for victory conditions
|
||||||
|
#include "lib/CPathfinder.h"
|
||||||
|
|
||||||
|
extern boost::thread_specific_ptr<CCallback> cb;
|
||||||
|
extern boost::thread_specific_ptr<VCAI> ai;
|
||||||
|
extern FuzzyHelper * fh;
|
||||||
|
|
||||||
|
using namespace Goals;
|
||||||
|
|
||||||
|
std::string BuyArmyBehavior::toString() const
|
||||||
|
{
|
||||||
|
return "Buy army";
|
||||||
|
}
|
||||||
|
|
||||||
|
Goals::TGoalVec BuyArmyBehavior::getTasks()
|
||||||
|
{
|
||||||
|
Goals::TGoalVec tasks;
|
||||||
|
|
||||||
|
if(cb->getDate(Date::DAY) == 1)
|
||||||
|
return tasks;
|
||||||
|
|
||||||
|
auto heroes = cb->getHeroesInfo();
|
||||||
|
|
||||||
|
if(heroes.size())
|
||||||
|
{
|
||||||
|
auto mainHero = vstd::maxElementByFun(heroes, [](const CGHeroInstance * hero) -> uint64_t
|
||||||
|
{
|
||||||
|
return hero->getFightingStrength();
|
||||||
|
});
|
||||||
|
|
||||||
|
for(auto town : cb->getTownsInfo())
|
||||||
|
{
|
||||||
|
const CGHeroInstance * targetHero = *mainHero;
|
||||||
|
|
||||||
|
/*if(town->visitingHero)
|
||||||
|
{
|
||||||
|
targetHero = town->visitingHero.get();
|
||||||
|
|
||||||
|
if(ai->ah->howManyReinforcementsCanGet(targetHero, town->getUpperArmy()))
|
||||||
|
{
|
||||||
|
tasks.push_back(sptr(VisitTile(town->visitablePos()).sethero(targetHero).setpriority(5)));
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
auto reinforcement = ai->ah->howManyReinforcementsCanBuy(targetHero, town);
|
||||||
|
|
||||||
|
if(reinforcement)
|
||||||
|
{
|
||||||
|
tasks.push_back(Goals::sptr(Goals::BuyArmy(town, reinforcement).setpriority(5)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tasks;
|
||||||
|
}
|
26
AI/Nullkiller/Behaviors/BuyArmyBehavior.h
Normal file
26
AI/Nullkiller/Behaviors/BuyArmyBehavior.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Goals.h, 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "lib/VCMI_Lib.h"
|
||||||
|
#include "Behavior.h"
|
||||||
|
#include "../AIUtility.h"
|
||||||
|
|
||||||
|
class BuyArmyBehavior : public Behavior
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BuyArmyBehavior()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual Goals::TGoalVec getTasks() override;
|
||||||
|
virtual std::string toString() const override;
|
||||||
|
};
|
||||||
|
|
@ -58,6 +58,7 @@ set(VCAI_SRCS
|
|||||||
Behaviors/Behavior.cpp
|
Behaviors/Behavior.cpp
|
||||||
Behaviors/CaptureObjectsBehavior.cpp
|
Behaviors/CaptureObjectsBehavior.cpp
|
||||||
Behaviors/RecruitHeroBehavior.cpp
|
Behaviors/RecruitHeroBehavior.cpp
|
||||||
|
Behaviors/BuyArmyBehavior.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
VCAI.cpp
|
VCAI.cpp
|
||||||
)
|
)
|
||||||
@ -119,6 +120,7 @@ set(VCAI_HEADERS
|
|||||||
Behaviors/Behavior.h
|
Behaviors/Behavior.h
|
||||||
Behaviors/CaptureObjectsBehavior.h
|
Behaviors/CaptureObjectsBehavior.h
|
||||||
Behaviors/RecruitHeroBehavior.h
|
Behaviors/RecruitHeroBehavior.h
|
||||||
|
Behaviors/BuyArmyBehavior.h
|
||||||
VCAI.h
|
VCAI.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "../AIHelper.h"
|
#include "../AIHelper.h"
|
||||||
#include "../Behaviors/CaptureObjectsBehavior.h"
|
#include "../Behaviors/CaptureObjectsBehavior.h"
|
||||||
#include "../Behaviors/RecruitHeroBehavior.h"
|
#include "../Behaviors/RecruitHeroBehavior.h"
|
||||||
|
#include "../Behaviors/BuyArmyBehavior.h"
|
||||||
#include "../Goals/Invalid.h"
|
#include "../Goals/Invalid.h"
|
||||||
|
|
||||||
extern boost::thread_specific_ptr<CCallback> cb;
|
extern boost::thread_specific_ptr<CCallback> cb;
|
||||||
@ -74,6 +75,7 @@ void Nullkiller::makeTurn()
|
|||||||
updateAiState();
|
updateAiState();
|
||||||
|
|
||||||
Goals::TGoalVec bestTasks = {
|
Goals::TGoalVec bestTasks = {
|
||||||
|
choseBestTask(BuyArmyBehavior()),
|
||||||
choseBestTask(CaptureObjectsBehavior()),
|
choseBestTask(CaptureObjectsBehavior()),
|
||||||
choseBestTask(RecruitHeroBehavior())
|
choseBestTask(RecruitHeroBehavior())
|
||||||
};
|
};
|
||||||
|
@ -2177,7 +2177,7 @@ void VCAI::tryRealize(Goals::BuyArmy & g)
|
|||||||
auto res = ah->allResources();
|
auto res = ah->allResources();
|
||||||
std::vector<creInfo> creaturesInDwellings;
|
std::vector<creInfo> creaturesInDwellings;
|
||||||
|
|
||||||
for (int i = 0; i < t->creatures.size(); i++)
|
for (int i = t->creatures.size() - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
auto ci = infoFromDC(t->creatures[i]);
|
auto ci = infoFromDC(t->creatures[i]);
|
||||||
|
|
||||||
@ -2214,6 +2214,11 @@ void VCAI::tryRealize(Goals::BuyArmy & g)
|
|||||||
valueBought += ci.count * ci.cre->AIValue;
|
valueBought += ci.count * ci.cre->AIValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(t->visitingHero)
|
||||||
|
{
|
||||||
|
moveHeroToTile(t->visitablePos(), t->visitingHero.get());
|
||||||
|
}
|
||||||
|
|
||||||
throw goalFulfilledException(sptr(g)); //we bought as many creatures as we wanted
|
throw goalFulfilledException(sptr(g)); //we bought as many creatures as we wanted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user