2008-11-25 20:51:44 +02:00
|
|
|
#include "CGeniusAI.h"
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2008-11-25 20:51:44 +02:00
|
|
|
#include <iostream>
|
2009-10-23 01:04:42 +03:00
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
|
2010-12-25 21:23:30 +02:00
|
|
|
#include "../../lib/BattleState.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "../../lib/CBuildingHandler.h"
|
|
|
|
#include "../../lib/CHeroHandler.h"
|
2009-08-05 12:46:55 +03:00
|
|
|
#include "../../lib/VCMI_Lib.h"
|
2009-08-06 12:52:07 +03:00
|
|
|
#include "../../lib/NetPacks.h"
|
2009-10-23 01:04:42 +03:00
|
|
|
#include "AIPriorities.h"
|
2009-08-18 10:37:45 +03:00
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
using std::endl;
|
|
|
|
using geniusai::CGeniusAI;
|
2010-11-28 18:39:13 +02:00
|
|
|
class LibClasses;
|
2008-11-25 20:51:44 +02:00
|
|
|
|
2009-02-08 18:36:53 +02:00
|
|
|
#if defined (_MSC_VER) && (_MSC_VER >= 1020) || (__MINGW32__)
|
2009-10-28 18:28:52 +02:00
|
|
|
// Excludes rarely used stuff from windows headers - delete this line if
|
|
|
|
// something is missing.
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2008-11-25 20:51:44 +02:00
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
void DbgBox(const char* msg, bool messageBox)
|
2008-11-25 20:51:44 +02:00
|
|
|
{
|
2009-08-04 01:15:13 +03:00
|
|
|
#if defined PRINT_DEBUG
|
2008-11-25 20:51:44 +02:00
|
|
|
#if defined _DEBUG
|
2009-10-28 18:28:52 +02:00
|
|
|
//# if 0
|
2008-11-25 20:51:44 +02:00
|
|
|
# if defined (_MSC_VER) && (_MSC_VER >= 1020)
|
|
|
|
if (messageBox)
|
|
|
|
{
|
|
|
|
MessageBoxA(NULL, msg, "Debug message", MB_OK | MB_ICONASTERISK);
|
|
|
|
}
|
|
|
|
# endif
|
2010-11-28 18:39:13 +02:00
|
|
|
tlog6 << msg << std::endl;
|
2008-11-25 20:51:44 +02:00
|
|
|
#endif
|
2009-08-04 01:15:13 +03:00
|
|
|
#endif
|
2008-11-25 20:51:44 +02:00
|
|
|
}
|
|
|
|
|
2009-11-01 22:13:12 +02:00
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
// TODO: Rewrite those i-s, o-s to something meaningful.
|
2010-11-28 18:39:13 +02:00
|
|
|
bool CGeniusAI::AIObjectContainer::operator<(const AIObjectContainer& b) const
|
2009-08-06 12:52:07 +03:00
|
|
|
{
|
2009-10-23 01:04:42 +03:00
|
|
|
if (o->pos != b.o->pos)
|
|
|
|
return o->pos < b.o->pos;
|
|
|
|
else
|
|
|
|
return o->id < b.o->id;
|
2009-08-06 12:52:07 +03:00
|
|
|
}
|
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
CGeniusAI::HypotheticalGameState::HeroModel::HeroModel(
|
|
|
|
const CGHeroInstance* h)
|
|
|
|
: h(h), finished(false)
|
2009-08-06 12:52:07 +03:00
|
|
|
{
|
2009-10-23 01:04:42 +03:00
|
|
|
pos = h->getPosition(false);
|
|
|
|
remainingMovement = h->movement;
|
2009-08-06 12:52:07 +03:00
|
|
|
}
|
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
CGeniusAI::HypotheticalGameState::TownModel::TownModel(
|
2009-11-01 22:13:12 +02:00
|
|
|
const CGTownInstance* t)
|
2009-10-23 01:04:42 +03:00
|
|
|
: t(t)
|
2009-08-06 12:52:07 +03:00
|
|
|
{
|
2009-11-01 22:13:12 +02:00
|
|
|
hasBuilt = static_cast<bool>(t->builded);
|
2009-08-06 12:52:07 +03:00
|
|
|
creaturesToRecruit = t->creatures;
|
2010-12-10 01:10:28 +02:00
|
|
|
//creaturesInGarrison = t->getArmy();
|
2009-08-06 12:52:07 +03:00
|
|
|
}
|
|
|
|
|
2009-11-01 22:13:12 +02:00
|
|
|
CGeniusAI::HypotheticalGameState::HypotheticalGameState(CGeniusAI& ai)
|
|
|
|
: knownVisitableObjects(ai.knownVisitableObjects)
|
2009-08-06 12:52:07 +03:00
|
|
|
{
|
2009-08-18 10:37:45 +03:00
|
|
|
AI = &ai;
|
2009-10-23 01:04:42 +03:00
|
|
|
std::vector<const CGHeroInstance*> heroes = ai.m_cb->getHeroesInfo();
|
2009-10-28 18:28:52 +02:00
|
|
|
for (std::vector<const CGHeroInstance*>::iterator i = heroes.begin();
|
2009-10-23 01:04:42 +03:00
|
|
|
i != heroes.end();
|
|
|
|
i++)
|
2009-08-06 12:52:07 +03:00
|
|
|
heroModels.push_back(HeroModel(*i));
|
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
std::vector<const CGTownInstance*> towns = ai.m_cb->getTownsInfo();
|
2009-10-28 18:28:52 +02:00
|
|
|
for (std::vector <const CGTownInstance*>::iterator i = towns.begin();
|
2009-10-23 01:04:42 +03:00
|
|
|
i != towns.end();
|
|
|
|
i++) {
|
|
|
|
if ( (*i)->tempOwner == ai.m_cb->getMyColor() )
|
|
|
|
townModels.push_back(TownModel(*i));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ai.m_cb->howManyTowns() != 0) {
|
|
|
|
AvailableHeroesToBuy =
|
|
|
|
ai.m_cb->getAvailableHeroes(ai.m_cb->getTownInfo(0,0));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
resourceAmounts.push_back(ai.m_cb->getResourceAmount(i));
|
2009-08-06 12:52:07 +03:00
|
|
|
}
|
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
|
|
|
|
void CGeniusAI::HypotheticalGameState::update(CGeniusAI& ai)
|
2009-08-06 12:52:07 +03:00
|
|
|
{
|
2009-08-18 10:37:45 +03:00
|
|
|
AI = &ai;
|
2009-08-21 21:18:52 +03:00
|
|
|
knownVisitableObjects = ai.knownVisitableObjects;
|
2009-08-06 12:52:07 +03:00
|
|
|
std::vector<HeroModel> oldModels = heroModels;
|
|
|
|
heroModels.clear();
|
2009-10-23 01:04:42 +03:00
|
|
|
|
|
|
|
std::vector<const CGHeroInstance*> heroes = ai.m_cb->getHeroesInfo();
|
2010-11-28 18:39:13 +02:00
|
|
|
for (std::vector<const CGHeroInstance*>::iterator i = heroes.begin(); i != heroes.end(); i++)
|
2009-08-06 12:52:07 +03:00
|
|
|
heroModels.push_back(HeroModel(*i));
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
int j;
|
|
|
|
for (int i = 0; i < oldModels.size(); ++i)
|
|
|
|
{
|
|
|
|
for (j = 0; j < heroModels.size(); ++j)
|
|
|
|
{
|
|
|
|
if (oldModels[i].h->subID == heroModels[j].h->subID)
|
|
|
|
{
|
2009-10-23 01:04:42 +03:00
|
|
|
heroModels[j].finished = oldModels[i].finished;
|
|
|
|
heroModels[j].previouslyVisited_pos = oldModels[i].previouslyVisited_pos;
|
2009-08-19 13:18:14 +03:00
|
|
|
}
|
2009-10-23 01:04:42 +03:00
|
|
|
}
|
|
|
|
}
|
2009-08-06 12:52:07 +03:00
|
|
|
|
|
|
|
townModels.clear();
|
2009-10-23 01:04:42 +03:00
|
|
|
std::vector<const CGTownInstance*> towns = ai.m_cb->getTownsInfo();
|
2010-11-28 18:39:13 +02:00
|
|
|
for (std::vector<const CGTownInstance*>::iterator i = towns.begin(); i != towns.end(); i++)
|
|
|
|
{
|
2009-10-23 01:04:42 +03:00
|
|
|
if ( (*i)->tempOwner == ai.m_cb->getMyColor() )
|
2009-08-06 12:52:07 +03:00
|
|
|
townModels.push_back(TownModel(*i));
|
2010-11-28 18:39:13 +02:00
|
|
|
}
|
2009-08-06 12:52:07 +03:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
if (ai.m_cb->howManyTowns())
|
|
|
|
{
|
|
|
|
AvailableHeroesToBuy = ai.m_cb->getAvailableHeroes(ai.m_cb->getTownInfo(0,0));
|
2009-10-23 01:04:42 +03:00
|
|
|
}
|
2009-08-06 12:52:07 +03:00
|
|
|
|
|
|
|
resourceAmounts.clear();
|
2009-10-23 01:04:42 +03:00
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
resourceAmounts.push_back(ai.m_cb->getResourceAmount(i));
|
2009-08-06 12:52:07 +03:00
|
|
|
}
|
|
|
|
|
2009-11-01 22:13:12 +02:00
|
|
|
CGeniusAI::HeroObjective::HeroObjective(const HypotheticalGameState &hgs,
|
|
|
|
Type t,
|
|
|
|
const CGObjectInstance* object,
|
|
|
|
HypotheticalGameState::HeroModel* h,
|
|
|
|
CGeniusAI* ai)
|
|
|
|
: object(object), hgs(hgs)
|
2009-08-06 12:52:07 +03:00
|
|
|
{
|
2009-08-07 11:41:40 +03:00
|
|
|
AI = ai;
|
2009-08-06 12:52:07 +03:00
|
|
|
pos = object->pos;
|
|
|
|
type = t;
|
|
|
|
whoCanAchieve.push_back(h);
|
2009-08-07 11:41:40 +03:00
|
|
|
_value = -1;
|
2009-08-06 12:52:07 +03:00
|
|
|
}
|
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2009-08-07 11:41:40 +03:00
|
|
|
float CGeniusAI::HeroObjective::getValue() const
|
|
|
|
{
|
2009-10-23 01:04:42 +03:00
|
|
|
if (_value >= 0)
|
|
|
|
return _value - _cost;
|
2009-08-07 11:41:40 +03:00
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
// TODO: each object should have an associated cost to visit IE
|
|
|
|
// (tree of knowledge 1000 gold/10 gems)
|
|
|
|
vector<int> resourceCosts;
|
|
|
|
for (int i = 0; i < 8; i++)
|
2009-08-07 11:41:40 +03:00
|
|
|
resourceCosts.push_back(0);
|
2009-10-23 01:04:42 +03:00
|
|
|
|
|
|
|
if (object->ID == 47) // School of magic
|
|
|
|
resourceCosts[6] += 1000;
|
2009-08-07 11:41:40 +03:00
|
|
|
|
2009-11-01 22:13:12 +02:00
|
|
|
// TODO: Add some meaningful (and not exploitable) number here.
|
|
|
|
float bestCost = 9e9f;
|
2009-10-23 01:04:42 +03:00
|
|
|
HypotheticalGameState::HeroModel* bestHero = NULL;
|
|
|
|
if (type != AIObjective::finishTurn)
|
2009-08-18 10:37:45 +03:00
|
|
|
{
|
2009-10-23 01:04:42 +03:00
|
|
|
for (int i = 0; i < whoCanAchieve.size(); i++)
|
2009-08-07 11:41:40 +03:00
|
|
|
{
|
|
|
|
int distOutOfTheWay = 0;
|
2009-08-21 21:18:52 +03:00
|
|
|
CPath path3;
|
2009-08-07 11:41:40 +03:00
|
|
|
//from hero to object
|
2009-10-23 01:04:42 +03:00
|
|
|
if (AI->m_cb->getPath(whoCanAchieve[i]->pos,
|
|
|
|
pos,
|
|
|
|
whoCanAchieve[i]->h,
|
|
|
|
path3)) {
|
2009-08-21 21:18:52 +03:00
|
|
|
distOutOfTheWay+=path3.nodes[0].dist;
|
2009-10-23 01:04:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// from object to goal
|
|
|
|
if (AI->m_cb->getPath(pos,
|
|
|
|
whoCanAchieve[i]->interestingPos,
|
|
|
|
whoCanAchieve[i]->h,
|
|
|
|
path3)) {
|
|
|
|
distOutOfTheWay += path3.nodes[0].dist;
|
|
|
|
// from hero directly to goal
|
|
|
|
if (AI->m_cb->getPath(whoCanAchieve[i]->pos,
|
|
|
|
whoCanAchieve[i]->interestingPos,
|
|
|
|
whoCanAchieve[i]->h,
|
|
|
|
path3))
|
2009-08-21 21:18:52 +03:00
|
|
|
distOutOfTheWay-=path3.nodes[0].dist;
|
2009-08-07 11:41:40 +03:00
|
|
|
}
|
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
float cost = AI->m_priorities->getCost(resourceCosts,
|
|
|
|
whoCanAchieve[i]->h,
|
|
|
|
distOutOfTheWay);
|
2010-11-28 18:39:13 +02:00
|
|
|
if (cost < bestCost)
|
|
|
|
{
|
2009-08-07 11:41:40 +03:00
|
|
|
bestCost = cost;
|
2009-08-21 21:18:52 +03:00
|
|
|
bestHero = whoCanAchieve[i];
|
|
|
|
}
|
2010-11-28 18:39:13 +02:00
|
|
|
} // for (int i = 0; i < whoCanAchieve.size(); i++)
|
|
|
|
}
|
|
|
|
else // if (type != AIObjective::finishTurn)
|
|
|
|
bestCost = 0;
|
2009-08-07 11:41:40 +03:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
if (bestHero)
|
|
|
|
{
|
2009-08-21 21:18:52 +03:00
|
|
|
whoCanAchieve.clear();
|
|
|
|
whoCanAchieve.push_back(bestHero);
|
|
|
|
}
|
|
|
|
|
2009-08-18 10:37:45 +03:00
|
|
|
_value = AI->m_priorities->getValue(*this);
|
2009-10-23 01:04:42 +03:00
|
|
|
_cost = bestCost;
|
|
|
|
return _value - _cost;
|
2009-08-07 11:41:40 +03:00
|
|
|
}
|
2009-10-23 01:04:42 +03:00
|
|
|
|
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
bool CGeniusAI::HeroObjective::operator<(const HeroObjective& other) const
|
2009-08-06 12:52:07 +03:00
|
|
|
{
|
2009-10-23 01:04:42 +03:00
|
|
|
if (type != other.type)
|
|
|
|
return type < other.type;
|
2010-11-28 18:39:13 +02:00
|
|
|
else if (pos != other.pos)
|
2009-08-06 12:52:07 +03:00
|
|
|
return pos < other.pos;
|
2009-10-23 01:04:42 +03:00
|
|
|
else if (object->id != other.object->id)
|
2009-08-06 12:52:07 +03:00
|
|
|
return object->id < other.object->id;
|
2010-11-28 18:39:13 +02:00
|
|
|
else if ((dynamic_cast<const CGVisitableOPH*>(object) != NULL) &&
|
2009-11-01 22:13:12 +02:00
|
|
|
(whoCanAchieve.front()->h->id != other.whoCanAchieve.front()->h->id))
|
|
|
|
return whoCanAchieve.front()->h->id < other.whoCanAchieve.front()->h->id;
|
2010-11-28 18:39:13 +02:00
|
|
|
else
|
|
|
|
return false;
|
2009-08-06 12:52:07 +03:00
|
|
|
}
|
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2009-08-07 11:41:40 +03:00
|
|
|
void CGeniusAI::HeroObjective::print() const
|
|
|
|
{
|
2010-11-28 18:39:13 +02:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case visit:
|
|
|
|
tlog6 << "visit " << object->hoverName
|
|
|
|
<< " at (" <<object->pos.x << ","<< object->pos.y << ")" ;
|
|
|
|
break;
|
|
|
|
case attack:
|
|
|
|
tlog6 << "attack " << object->hoverName;
|
|
|
|
break;
|
|
|
|
case finishTurn:
|
|
|
|
tlog6 << "finish turn";
|
|
|
|
// TODO: Add a default, just in case.
|
2009-08-07 11:41:40 +03:00
|
|
|
}
|
2009-10-23 01:04:42 +03:00
|
|
|
if (whoCanAchieve.size() == 1)
|
2010-11-28 18:39:13 +02:00
|
|
|
tlog6 << " with " << whoCanAchieve.front()->h->hoverName;
|
2009-08-07 11:41:40 +03:00
|
|
|
}
|
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
|
|
|
|
CGeniusAI::TownObjective::TownObjective(
|
|
|
|
const HypotheticalGameState& hgs,
|
|
|
|
Type t,
|
|
|
|
HypotheticalGameState::TownModel* tn,
|
|
|
|
int Which,
|
|
|
|
CGeniusAI * ai)
|
|
|
|
: whichTown(tn), which(Which), hgs(hgs)
|
2009-08-06 12:52:07 +03:00
|
|
|
{
|
2009-10-23 01:04:42 +03:00
|
|
|
AI = ai;
|
2009-08-06 12:52:07 +03:00
|
|
|
type = t;
|
2009-08-07 11:41:40 +03:00
|
|
|
_value = -1;
|
2009-08-06 12:52:07 +03:00
|
|
|
}
|
|
|
|
|
2009-08-07 11:41:40 +03:00
|
|
|
float CGeniusAI::TownObjective::getValue() const
|
|
|
|
{
|
2009-10-23 01:04:42 +03:00
|
|
|
if (_value >= 0)
|
|
|
|
return _value - _cost;
|
2009-08-07 11:41:40 +03:00
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
// TODO: Include a constant stating the meaning of 8 (number of resources).
|
2009-08-18 10:37:45 +03:00
|
|
|
vector<int> resourceCosts(8,0);
|
2009-11-01 22:13:12 +02:00
|
|
|
CBuilding* b = NULL;
|
|
|
|
CCreature* creature = NULL;
|
2010-11-28 18:39:13 +02:00
|
|
|
float cost = 0; // TODO: Needed?
|
2009-11-01 22:13:12 +02:00
|
|
|
int ID = 0;
|
2010-11-28 18:39:13 +02:00
|
|
|
int newID = 0;
|
|
|
|
int howMany = 0;
|
|
|
|
ui32 creatures_max = 0;
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
switch (type)
|
|
|
|
{
|
2009-08-18 10:37:45 +03:00
|
|
|
case recruitHero:
|
2009-10-23 01:04:42 +03:00
|
|
|
resourceCosts[6] = 2500; // TODO: Define somehow the meaning of gold etc.
|
2009-08-18 10:37:45 +03:00
|
|
|
break;
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2009-08-18 10:37:45 +03:00
|
|
|
case buildBuilding:
|
|
|
|
b = VLC->buildh->buildings[whichTown->t->subID][which];
|
2010-11-28 18:39:13 +02:00
|
|
|
for (int i = 0; b && ( i < b->resources.size() ); ++i)
|
2009-10-23 01:04:42 +03:00
|
|
|
resourceCosts[i] = b->resources[i];
|
2009-08-18 10:37:45 +03:00
|
|
|
break;
|
2009-08-07 11:41:40 +03:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
case recruitCreatures:
|
2009-10-23 01:04:42 +03:00
|
|
|
// Buy upgraded if possible.
|
2010-11-28 18:39:13 +02:00
|
|
|
ID = whichTown->creaturesToRecruit[which].second.back();
|
|
|
|
creature = VLC->creh->creatures[ID];
|
|
|
|
howMany = whichTown->creaturesToRecruit[which].first;
|
|
|
|
creatures_max = 0; // Max creatures you can recruit of this type.
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
for (int i = 0; i < creature->cost.size(); i++)
|
|
|
|
{
|
|
|
|
if (creature->cost[i] != 0)
|
|
|
|
creatures_max = hgs.resourceAmounts[i]/creature->cost[i];
|
|
|
|
else
|
|
|
|
creatures_max = INT_MAX; // TODO: Will have to rewrite it.
|
|
|
|
// TODO: Buy the best units (the least I can buy)?
|
|
|
|
amin(howMany, creatures_max);
|
|
|
|
}
|
|
|
|
// The cost of recruiting the stack of creatures.
|
|
|
|
for (int i = 0; creature && (i < creature->cost.size() ); ++i)
|
|
|
|
resourceCosts[i] = creature->cost[i]*howMany;
|
|
|
|
break;
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2010-12-06 01:26:56 +02:00
|
|
|
case upgradeCreatures:
|
|
|
|
UpgradeInfo ui = AI->m_cb->getUpgradeInfo(whichTown->t,which);
|
2010-12-10 01:10:28 +02:00
|
|
|
ID = whichTown->t->getCreature(which)->idNumber;
|
|
|
|
howMany = whichTown->t->getStackCount(which);
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
newID = ui.newID.back();
|
|
|
|
int upgrade_serial = ui.newID.size() - 1;
|
|
|
|
for (std::set< std::pair<int,int> >::iterator j = ui.cost[upgrade_serial].begin(); j != ui.cost[upgrade_serial].end(); j++)
|
|
|
|
resourceCosts[j->first] = j->second*howMany;
|
2009-08-18 10:37:45 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
_cost = AI->m_priorities->getCost(resourceCosts, NULL, 0);
|
2009-08-18 10:37:45 +03:00
|
|
|
_value = AI->m_priorities->getValue(*this);
|
2009-10-23 01:04:42 +03:00
|
|
|
return _value - _cost;
|
2009-08-07 11:41:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
bool CGeniusAI::TownObjective::operator<(const TownObjective &other) const
|
2009-08-06 12:52:07 +03:00
|
|
|
{
|
2009-10-23 01:04:42 +03:00
|
|
|
if (type != other.type)
|
|
|
|
return type < other.type;
|
|
|
|
else if (which != other.which)
|
|
|
|
return which < other.which;
|
|
|
|
else if (whichTown->t->id != other.whichTown->t->id)
|
2009-08-06 12:52:07 +03:00
|
|
|
return whichTown->t->id < other.whichTown->t->id;
|
2009-10-28 18:28:52 +02:00
|
|
|
else
|
|
|
|
return false;
|
2009-08-06 12:52:07 +03:00
|
|
|
}
|
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2009-08-07 11:41:40 +03:00
|
|
|
void CGeniusAI::TownObjective::print() const
|
|
|
|
{
|
2010-11-28 18:39:13 +02:00
|
|
|
HypotheticalGameState::HeroModel hm;
|
2009-10-28 18:28:52 +02:00
|
|
|
CBuilding* b = NULL;
|
|
|
|
const CCreature* creature = NULL;
|
|
|
|
int ID = 0;
|
2010-11-28 18:39:13 +02:00
|
|
|
int howMany = 0;
|
|
|
|
int newID = 0; // TODO: Needed?
|
|
|
|
int hSlot = 0; // TODO: Needed?
|
|
|
|
ui32 creatures_max;
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
switch (type)
|
|
|
|
{
|
2009-11-01 22:13:12 +02:00
|
|
|
case recruitHero:
|
2010-11-28 18:39:13 +02:00
|
|
|
tlog6 << "recruit hero.";
|
2009-11-01 22:13:12 +02:00
|
|
|
break;
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2009-11-01 22:13:12 +02:00
|
|
|
case buildBuilding:
|
|
|
|
b = VLC->buildh->buildings[whichTown->t->subID][which];
|
2010-11-28 18:39:13 +02:00
|
|
|
tlog6 << "build " << b->Name() << " cost = ";
|
|
|
|
if (b->resources.size())
|
|
|
|
{
|
|
|
|
if (b->resources[0])
|
|
|
|
tlog6 << b->resources[0] << " wood. ";
|
|
|
|
if (b->resources[1])
|
|
|
|
tlog6 << b->resources[1] << " mercury. ";
|
|
|
|
if (b->resources[2])
|
|
|
|
tlog6 << b->resources[2] << " ore. ";
|
|
|
|
if (b->resources[3])
|
|
|
|
tlog6 << b->resources[3] << " sulfur. ";
|
|
|
|
if (b->resources[4])
|
|
|
|
tlog6 << b->resources[4] << " crystal. ";
|
|
|
|
if (b->resources[5])
|
|
|
|
tlog6 << b->resources[5] << " gems. ";
|
|
|
|
if (b->resources[6])
|
|
|
|
tlog6 << b->resources[6] << " gold. ";
|
2009-11-01 22:13:12 +02:00
|
|
|
}
|
|
|
|
break;
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
case recruitCreatures:
|
2009-11-01 22:13:12 +02:00
|
|
|
// Buy upgraded if possible.
|
|
|
|
ID = whichTown->creaturesToRecruit[which].second.back();
|
2010-05-02 21:20:26 +03:00
|
|
|
creature = VLC->creh->creatures[ID];
|
2009-11-01 22:13:12 +02:00
|
|
|
howMany = whichTown->creaturesToRecruit[which].first;
|
2010-11-28 18:39:13 +02:00
|
|
|
creatures_max = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < creature->cost.size(); i++)
|
|
|
|
{
|
|
|
|
if (creature->cost[i])
|
|
|
|
creatures_max = hgs.resourceAmounts[i]/creature->cost[i];
|
|
|
|
else
|
|
|
|
creatures_max = INT_MAX;
|
|
|
|
amin(howMany, creatures_max);
|
|
|
|
}
|
|
|
|
tlog6 << "recruit " << howMany << " " << creature->namePl
|
|
|
|
<< " (Total AI Strength " << creature->AIValue*howMany
|
|
|
|
<< "). cost = ";
|
2009-11-01 22:13:12 +02:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
if (creature->cost.size())
|
2009-11-01 22:13:12 +02:00
|
|
|
{
|
2010-11-28 18:39:13 +02:00
|
|
|
if (creature->cost[0])
|
|
|
|
tlog6 << creature->cost[0]*howMany << " wood. ";
|
|
|
|
if (creature->cost[1])
|
|
|
|
tlog6 << creature->cost[1]*howMany << " mercury. ";
|
|
|
|
if (creature->cost[2])
|
|
|
|
tlog6 << creature->cost[2]*howMany << " ore. ";
|
|
|
|
if (creature->cost[3])
|
|
|
|
tlog6 << creature->cost[3]*howMany << " sulfur. ";
|
|
|
|
if (creature->cost[4])
|
|
|
|
tlog6 << creature->cost[4]*howMany << " cristal. ";
|
|
|
|
if (creature->cost[5])
|
|
|
|
tlog6 << creature->cost[5]*howMany << " gems. ";
|
|
|
|
if (creature->cost[6])
|
|
|
|
tlog6 << creature->cost[6]*howMany << " gold. ";
|
2009-11-01 22:13:12 +02:00
|
|
|
}
|
|
|
|
break; // case recruitCreatures.
|
|
|
|
|
|
|
|
case upgradeCreatures:
|
2010-11-28 18:39:13 +02:00
|
|
|
UpgradeInfo ui = AI->m_cb->getUpgradeInfo (whichTown->t, which);
|
2010-12-10 01:10:28 +02:00
|
|
|
ID = whichTown->t->getCreature(which)->idNumber;
|
2010-11-28 18:39:13 +02:00
|
|
|
tlog6 << "upgrade " << VLC->creh->creatures[ID]->namePl;
|
2009-11-01 22:13:12 +02:00
|
|
|
//ui.cost
|
|
|
|
break;
|
|
|
|
} // switch(type)
|
2009-08-07 11:41:40 +03:00
|
|
|
}
|
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
|
|
|
|
CGeniusAI::CGeniusAI() : m_generalAI(), m_state(NO_BATTLE)
|
2009-05-10 11:15:30 +03:00
|
|
|
{
|
2009-08-18 10:37:45 +03:00
|
|
|
m_priorities = new Priorities("AI/GeniusAI.brain");
|
2009-05-10 11:15:30 +03:00
|
|
|
}
|
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2009-05-10 11:15:30 +03:00
|
|
|
CGeniusAI::~CGeniusAI()
|
|
|
|
{
|
2009-08-18 10:37:45 +03:00
|
|
|
delete m_priorities;
|
2009-05-10 11:15:30 +03:00
|
|
|
}
|
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2008-11-25 20:51:44 +02:00
|
|
|
void CGeniusAI::init(ICallback *CB)
|
|
|
|
{
|
|
|
|
m_cb = CB;
|
2009-05-10 11:15:30 +03:00
|
|
|
m_generalAI.init(CB);
|
|
|
|
|
2008-11-25 20:51:44 +02:00
|
|
|
human = false;
|
|
|
|
playerID = m_cb->getMyColor();
|
2009-10-23 01:04:42 +03:00
|
|
|
std::string info = std::string("GeniusAI initialized for player ")
|
|
|
|
+ boost::lexical_cast<std::string>(playerID);
|
2008-11-25 20:51:44 +02:00
|
|
|
m_battleLogic = NULL;
|
2009-08-04 01:15:13 +03:00
|
|
|
DbgBox(info.c_str());
|
2008-11-25 20:51:44 +02:00
|
|
|
}
|
|
|
|
|
2009-08-01 05:57:50 +03:00
|
|
|
|
2009-08-04 01:15:13 +03:00
|
|
|
void CGeniusAI::reportResources()
|
|
|
|
{
|
2010-11-28 18:39:13 +02:00
|
|
|
tlog6 << "Day " << m_cb->getDate() << ": ";
|
|
|
|
tlog6 << "AI Player " <<m_cb->getMyColor()<< " with "
|
|
|
|
<< m_cb->howManyHeroes(true) << " heroes. " << endl;
|
|
|
|
tlog6 << m_cb->getResourceAmount(0) << " wood. ";
|
|
|
|
tlog6 << m_cb->getResourceAmount(1) << " mercury. ";
|
|
|
|
tlog6 << m_cb->getResourceAmount(2) << " ore. ";
|
|
|
|
tlog6 << m_cb->getResourceAmount(3) << " sulfur. ";
|
|
|
|
tlog6 << m_cb->getResourceAmount(4) << " crystal. ";
|
|
|
|
tlog6 << m_cb->getResourceAmount(5) << " gems. ";
|
|
|
|
tlog6 << m_cb->getResourceAmount(6) << " gold.";
|
|
|
|
tlog6 << endl;
|
2009-08-04 01:15:13 +03:00
|
|
|
}
|
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
void CGeniusAI::addHeroObjectives(CGeniusAI::HypotheticalGameState::HeroModel& h,
|
2009-10-23 01:04:42 +03:00
|
|
|
CGeniusAI::HypotheticalGameState& hgs)
|
2009-08-04 01:15:13 +03:00
|
|
|
{
|
2009-10-23 01:04:42 +03:00
|
|
|
int3 hpos = h.pos;
|
2010-11-28 18:39:13 +02:00
|
|
|
int3 destination;
|
|
|
|
int3 interestingPos;
|
|
|
|
CPath path;
|
2009-08-04 01:15:13 +03:00
|
|
|
int movement = h.remainingMovement;
|
2009-10-23 01:04:42 +03:00
|
|
|
int maxInteresting = 0;
|
2009-08-06 12:52:07 +03:00
|
|
|
AIObjective::Type tp = AIObjective::visit;
|
2009-10-23 01:04:42 +03:00
|
|
|
|
|
|
|
if (h.finished)
|
2010-11-28 18:39:13 +02:00
|
|
|
return;
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
for (std::set<AIObjectContainer>::const_iterator i = hgs.knownVisitableObjects.begin(); i != hgs.knownVisitableObjects.end(); i++)
|
|
|
|
{
|
2009-08-21 21:18:52 +03:00
|
|
|
tp = AIObjective::visit;
|
2010-11-28 18:39:13 +02:00
|
|
|
if (h.previouslyVisited_pos == i->o->getSightCenter())
|
2009-08-19 13:18:14 +03:00
|
|
|
continue;
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2009-08-06 12:52:07 +03:00
|
|
|
//TODO: what would the hero actually visit if he went to that spot
|
2009-10-23 01:04:42 +03:00
|
|
|
// maybe the hero wants to visit a seemingly unguarded enemy town,
|
|
|
|
// but there is a hero on top of it.
|
|
|
|
// if(i->o->)
|
2010-11-28 18:39:13 +02:00
|
|
|
if (i->o->ID != HEROI_TYPE)
|
|
|
|
{// Unless you are trying to visit a hero.
|
|
|
|
bool heroThere = false;
|
|
|
|
for(int j = 0; j < hgs.heroModels.size(); j++)
|
|
|
|
{
|
|
|
|
if (hgs.heroModels[j].pos == i->o->getSightCenter())
|
|
|
|
heroThere = true;
|
|
|
|
}
|
2009-10-23 01:04:42 +03:00
|
|
|
if (heroThere) // It won't work if there is already someone visiting that spot.
|
2009-08-06 12:52:07 +03:00
|
|
|
continue;
|
2010-11-28 18:39:13 +02:00
|
|
|
}
|
|
|
|
if (i->o->ID == HEROI_TYPE && // Visiting friendly heroes not yet supported.
|
|
|
|
i->o->getOwner() == m_cb->getMyColor())
|
2009-08-21 21:18:52 +03:00
|
|
|
continue;
|
2010-11-28 18:39:13 +02:00
|
|
|
if (i->o->id == h.h->id) // Don't visit yourself (should be caught by above).
|
2009-08-19 13:18:14 +03:00
|
|
|
continue;
|
2009-10-23 01:04:42 +03:00
|
|
|
// Don't visit a mine if you own, there's almost no
|
|
|
|
// point(maybe to leave guards or because the hero's trapped).
|
2010-11-28 18:39:13 +02:00
|
|
|
if (i->o->ID == 53 && i->o->getOwner() == m_cb->getMyColor())
|
2009-08-21 21:18:52 +03:00
|
|
|
continue;
|
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
if (i->o->getOwner() != m_cb->getMyColor())
|
|
|
|
{
|
2009-10-23 01:04:42 +03:00
|
|
|
// TODO: I feel like the AI shouldn't have access to this information.
|
|
|
|
// We must get an approximation based on few, many, ... zounds etc.
|
|
|
|
int enemyStrength = 0;
|
|
|
|
|
|
|
|
// TODO: should be virtual maybe, army strength should be
|
|
|
|
// comparable across objects.
|
|
|
|
// TODO: Rewrite all those damn i->o. For someone reading it the first
|
|
|
|
// time it's completely inconprehensible.
|
2009-11-01 22:13:12 +02:00
|
|
|
// TODO: NO MAGIC NUMBERS !!!
|
|
|
|
if (dynamic_cast<const CArmedInstance*> (i->o))
|
2010-11-28 18:39:13 +02:00
|
|
|
enemyStrength = (dynamic_cast<const CArmedInstance*> (i->o))->getArmyStrength();
|
|
|
|
if (dynamic_cast<const CGHeroInstance*> (i->o)) enemyStrength = (dynamic_cast<const CGHeroInstance*> (i->o))->getTotalStrength();
|
2009-10-23 01:04:42 +03:00
|
|
|
// TODO: Make constants of those 1.2 & 2.5.
|
2009-11-01 22:13:12 +02:00
|
|
|
if (dynamic_cast<const CGTownInstance*> (i->o))
|
2010-11-28 18:39:13 +02:00
|
|
|
enemyStrength = static_cast<int>((dynamic_cast<const CGTownInstance*> (i->o))->getArmyStrength() * 1.2);
|
2009-08-21 21:18:52 +03:00
|
|
|
float heroStrength = h.h->getTotalStrength();
|
2009-10-23 01:04:42 +03:00
|
|
|
// TODO: ballence these numbers using objective cost formula.
|
|
|
|
// TODO: it would be nice to do a battle simulation.
|
2009-11-01 22:13:12 +02:00
|
|
|
if (enemyStrength * 2.5 > heroStrength)
|
2009-10-23 01:04:42 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (enemyStrength > 0)
|
2010-11-28 18:39:13 +02:00
|
|
|
tp = AIObjective::attack;
|
2009-08-06 12:52:07 +03:00
|
|
|
}
|
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
//don't visit things that have already been visited this week.
|
2010-11-28 18:39:13 +02:00
|
|
|
if ((dynamic_cast<const CGVisitableOPW*> (i->o)) &&
|
|
|
|
(dynamic_cast<const CGVisitableOPW*> (i->o)->visited))
|
2009-08-07 11:41:40 +03:00
|
|
|
continue;
|
2009-08-19 13:18:14 +03:00
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
//don't visit things that you have already visited OPH
|
2010-11-28 18:39:13 +02:00
|
|
|
if ((dynamic_cast<const CGVisitableOPH*> (i->o)) &&
|
|
|
|
vstd::contains(dynamic_cast<const CGVisitableOPH*> (i->o)->visitors,
|
2009-11-01 22:13:12 +02:00
|
|
|
h.h->id))
|
2009-10-23 01:04:42 +03:00
|
|
|
continue;
|
2009-08-19 13:18:14 +03:00
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
// TODO: Some descriptions of those included so someone can undestand them.
|
2010-11-28 18:39:13 +02:00
|
|
|
if (i->o->ID == 88 || i->o->ID == 89 || i->o->ID == 90)
|
|
|
|
{
|
2009-08-18 10:37:45 +03:00
|
|
|
//TODO: if no spell book continue
|
|
|
|
//TODO: if the shrine's spell is identified, and the hero already has it, continue
|
|
|
|
}
|
|
|
|
|
2009-08-04 01:15:13 +03:00
|
|
|
destination = i->o->getSightCenter();
|
2009-08-05 12:46:55 +03:00
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
// Don't try to take a path from the underworld to the top or vice versa.
|
|
|
|
// TODO: Will have to make some calculations so that the AI can enter the
|
|
|
|
// underground.
|
2010-11-28 18:39:13 +02:00
|
|
|
if (hpos.z == destination.z)
|
|
|
|
{
|
2010-08-04 06:33:10 +03:00
|
|
|
//TODO: fix get path so that it doesn't return a path unless z's are
|
2009-10-23 01:04:42 +03:00
|
|
|
// the same, or path goes through sub gate.
|
2010-11-28 18:39:13 +02:00
|
|
|
if (m_cb->getPath(hpos, destination, h.h, path))
|
|
|
|
{
|
2009-08-05 12:46:55 +03:00
|
|
|
path.convert(0);
|
2010-11-28 18:39:13 +02:00
|
|
|
if (path.nodes[0].dist < movement)
|
|
|
|
{
|
|
|
|
// TODO: So easy to understand...
|
2009-10-23 01:04:42 +03:00
|
|
|
HeroObjective ho(hgs, tp, i->o, &h, this);
|
2009-08-05 12:46:55 +03:00
|
|
|
std::set<HeroObjective>::iterator found = currentHeroObjectives.find(ho);
|
2009-10-23 01:04:42 +03:00
|
|
|
if (found == currentHeroObjectives.end())
|
2009-08-05 12:46:55 +03:00
|
|
|
currentHeroObjectives.insert(ho);
|
2010-11-28 18:39:13 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// TODO: Try to rewrite if possible...
|
|
|
|
// A cast to a pointer, from a reference, to a pointer
|
|
|
|
// of an iterator.
|
2009-11-01 22:13:12 +02:00
|
|
|
HeroObjective* objective = (HeroObjective*)&(*found);
|
2009-08-12 05:08:59 +03:00
|
|
|
objective->whoCanAchieve.push_back(&h);
|
|
|
|
}
|
2009-08-05 12:46:55 +03:00
|
|
|
}
|
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
// Find the most interesting object that is eventually reachable,
|
|
|
|
// and set that position to the ultimate goal position.
|
|
|
|
// TODO: replace random numbers with some sort of ranking system.
|
|
|
|
int hi = rand();
|
2010-11-28 18:39:13 +02:00
|
|
|
if (hi > maxInteresting)
|
|
|
|
{
|
2009-08-05 12:46:55 +03:00
|
|
|
maxInteresting = hi;
|
|
|
|
interestingPos = destination;
|
|
|
|
}
|
2009-10-23 01:04:42 +03:00
|
|
|
} // if (m_cb->getPath(hpos, destination, h.h, path))
|
|
|
|
} // if (hpos.z == destination.z)
|
2009-10-28 18:28:52 +02:00
|
|
|
} // for (std::set<AIObjectContainer>::const_iterator
|
|
|
|
// i = knownVisitableObjects.begin();
|
2009-08-05 12:46:55 +03:00
|
|
|
|
2009-08-06 12:52:07 +03:00
|
|
|
h.interestingPos = interestingPos;
|
2009-10-23 01:04:42 +03:00
|
|
|
// there ought to be a path
|
|
|
|
// if(h.remainingMovement>0&&m_cb->getPath(hpos,interestingPos,h.h,path))
|
|
|
|
currentHeroObjectives.insert(HeroObjective(hgs,
|
|
|
|
HeroObjective::finishTurn,
|
|
|
|
h.h,
|
|
|
|
&h,
|
|
|
|
this));
|
2009-08-05 12:46:55 +03:00
|
|
|
}
|
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
void CGeniusAI::HeroObjective::fulfill(CGeniusAI& cg, HypotheticalGameState& hgs)
|
2009-08-05 12:46:55 +03:00
|
|
|
{
|
2009-08-06 12:52:07 +03:00
|
|
|
cg.m_cb->waitTillRealize = true;
|
2009-10-28 18:28:52 +02:00
|
|
|
HypotheticalGameState::HeroModel* h = NULL;
|
|
|
|
int3 hpos;
|
2010-11-28 18:39:13 +02:00
|
|
|
int3 destination;
|
|
|
|
int3 bestPos;
|
|
|
|
int3 currentPos;
|
|
|
|
int3 checkPos;
|
2009-08-05 12:46:55 +03:00
|
|
|
CPath path;
|
|
|
|
CPath path2;
|
2009-10-28 18:28:52 +02:00
|
|
|
int howGood = 0;
|
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case finishTurn:
|
|
|
|
h = whoCanAchieve.front();
|
|
|
|
h->finished=true;
|
|
|
|
hpos = h->pos;
|
|
|
|
destination = h->interestingPos;
|
2009-10-28 18:28:52 +02:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
if (!cg.m_cb->getPath(hpos, destination, h->h, path))
|
|
|
|
{
|
|
|
|
tlog6 << "AI error: invalid destination" << endl;
|
|
|
|
return;
|
|
|
|
}
|
2009-08-05 12:46:55 +03:00
|
|
|
destination = h->pos;
|
2010-11-28 18:39:13 +02:00
|
|
|
// Find closest coord that we can get to.
|
|
|
|
for (int i = path.nodes.size() - 2; i >= 0; i--)
|
|
|
|
{
|
|
|
|
// TODO: getPath what??
|
|
|
|
if ((cg.m_cb->getPath(hpos, path.nodes[i].coord, h->h, path2)) && (path2.nodes[0].dist <= h->remainingMovement))
|
2009-08-05 12:46:55 +03:00
|
|
|
destination = path.nodes[i].coord;
|
2010-11-28 18:39:13 +02:00
|
|
|
}
|
2009-08-05 12:46:55 +03:00
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
if (destination == h->interestingPos)
|
2010-11-28 18:39:13 +02:00
|
|
|
break;
|
2009-08-06 12:52:07 +03:00
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
// ! START ! //
|
|
|
|
// Find close pos with the most neighboring empty squares. We don't want to
|
|
|
|
// get in the way.
|
2009-08-06 12:52:07 +03:00
|
|
|
bestPos = destination;
|
2009-10-28 18:28:52 +02:00
|
|
|
howGood = 0;
|
|
|
|
// TODO: Add a meaning to 3.
|
2010-11-28 18:39:13 +02:00
|
|
|
for (int x = -3; x <= 3; x++)
|
|
|
|
{
|
|
|
|
for (int y = -3; y <= 3; y++)
|
|
|
|
{
|
|
|
|
currentPos = destination + int3(x,y,0);
|
|
|
|
// There better not be anything there.
|
|
|
|
if (cg.m_cb->getVisitableObjs(currentPos).size() != 0)
|
|
|
|
continue;
|
|
|
|
if ((cg.m_cb->getPath(hpos, currentPos, h->h, path) == false) ||
|
|
|
|
// It better be reachable from the hero
|
|
|
|
// TODO: remainingMovement > 0...
|
|
|
|
(path.nodes[0].dist>h->remainingMovement))
|
|
|
|
continue;
|
2009-08-06 12:52:07 +03:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
int count = 0;
|
|
|
|
int yy;
|
|
|
|
for (int xx = -1; xx <= 1; ++xx)
|
|
|
|
{
|
|
|
|
for (yy = -1; yy <= 1; ++yy)
|
|
|
|
{
|
|
|
|
checkPos = currentPos + int3(xx, yy, 0);
|
|
|
|
if (cg.m_cb->getPath(currentPos, checkPos, h->h, path) != false)
|
|
|
|
++count;
|
2009-08-06 12:52:07 +03:00
|
|
|
}
|
2010-11-28 18:39:13 +02:00
|
|
|
}
|
|
|
|
if (count > howGood)
|
|
|
|
{
|
|
|
|
howGood = count;
|
|
|
|
bestPos = currentPos;
|
|
|
|
}
|
|
|
|
}
|
2009-10-28 18:28:52 +02:00
|
|
|
}
|
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
destination = bestPos;
|
|
|
|
// ! END ! //
|
|
|
|
cg.m_cb->getPath(hpos, destination, h->h, path);
|
|
|
|
path.convert(0);
|
|
|
|
break;
|
2009-08-07 11:41:40 +03:00
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
case visit:
|
2010-11-28 18:39:13 +02:00
|
|
|
case attack:
|
2009-08-21 21:18:52 +03:00
|
|
|
h = whoCanAchieve.front(); //lowest cost hero
|
2009-10-28 18:28:52 +02:00
|
|
|
h->previouslyVisited_pos = object->getSightCenter();
|
2009-08-05 12:46:55 +03:00
|
|
|
hpos = h->pos;
|
|
|
|
destination = object->getSightCenter();
|
|
|
|
break;
|
2009-10-28 18:28:52 +02:00
|
|
|
} // switch(type)
|
2009-08-05 12:46:55 +03:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
if ((type == visit || type == finishTurn || type == attack) && (cg.m_cb->getPath (hpos, destination, h->h, path)))
|
|
|
|
path.convert(0);
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
if (cg.m_state.get() != NO_BATTLE)
|
2010-11-28 18:39:13 +02:00
|
|
|
cg.m_state.waitUntil (NO_BATTLE); // Wait for battle end
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
// Wait over, battle over too. hero might be killed. check.
|
2010-11-28 18:39:13 +02:00
|
|
|
for (int i = path.nodes.size() - 2; (i >= 0) && (cg.m_cb->getHeroSerial(h->h) >= 0); --i)
|
|
|
|
{
|
|
|
|
if (!cg.m_cb->moveHero(h->h,path.nodes[i].coord));
|
|
|
|
{
|
|
|
|
tlog3 << "cannot move hero to " << path.nodes[i].coord << endl;
|
|
|
|
break;
|
|
|
|
}
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
if (cg.m_state.get() != NO_BATTLE)
|
|
|
|
cg.m_state.waitUntil(NO_BATTLE); // Wait for battle end
|
2010-11-28 18:39:13 +02:00
|
|
|
}
|
2009-08-06 12:52:07 +03:00
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
h->remainingMovement -= path.nodes[0].dist;
|
|
|
|
if (object->blockVisit)
|
|
|
|
h->pos = path.nodes[1].coord;
|
|
|
|
else
|
2009-11-01 22:13:12 +02:00
|
|
|
h->pos = destination;
|
2009-10-28 18:28:52 +02:00
|
|
|
|
2009-11-01 22:13:12 +02:00
|
|
|
std::set<AIObjectContainer>::iterator
|
|
|
|
i = hgs.knownVisitableObjects.find(AIObjectContainer(object));
|
2009-10-28 18:28:52 +02:00
|
|
|
if (i != hgs.knownVisitableObjects.end())
|
|
|
|
hgs.knownVisitableObjects.erase(i);
|
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
const CGTownInstance* town = dynamic_cast<const CGTownInstance*> (object);
|
|
|
|
if (town && object->getOwner() == cg.m_cb->getMyColor())
|
|
|
|
{
|
2009-10-28 18:28:52 +02:00
|
|
|
//upgrade hero's units
|
2010-11-28 18:39:13 +02:00
|
|
|
tlog6 << "visiting town" << endl;
|
2010-12-10 01:10:28 +02:00
|
|
|
for (TSlots::const_iterator i = h->h->Slots().begin(); i != h->h->Slots().end(); i++)
|
2010-11-28 18:39:13 +02:00
|
|
|
{ // For each hero slot.
|
|
|
|
UpgradeInfo ui = cg.m_cb->getUpgradeInfo(h->h,i->first);
|
|
|
|
|
|
|
|
bool canUpgrade = false;
|
|
|
|
if (ui.newID.size() != 0)
|
|
|
|
{ // Does this stack need upgrading?
|
|
|
|
canUpgrade = true;
|
|
|
|
std::set<std::pair<int,int> >::iterator j;
|
|
|
|
for (int ii = 0; ii < ui.cost.size(); ii++) // Can afford the upgrade?
|
|
|
|
{
|
|
|
|
for (j = ui.cost[ii].begin(); j != ui.cost[ii].end(); j++)
|
2010-12-06 01:26:56 +02:00
|
|
|
if (hgs.resourceAmounts[j->first] < j->second * i->second->count)
|
2010-11-28 18:39:13 +02:00
|
|
|
canUpgrade = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (canUpgrade)
|
|
|
|
{
|
|
|
|
cg.m_cb->upgradeCreature(h->h, i->first, ui.newID.back());
|
|
|
|
tlog6 << "upgrading hero's "
|
2010-12-06 01:26:56 +02:00
|
|
|
<< i->second->type->namePl
|
2010-11-28 18:39:13 +02:00
|
|
|
<< endl;
|
|
|
|
}
|
2009-10-28 18:28:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Give town's units to hero.
|
|
|
|
int weakestCreatureStack;
|
2010-11-28 18:39:13 +02:00
|
|
|
int weakestCreatureAIValue = 99999; // we will lower it in the process
|
|
|
|
|
2010-12-10 01:10:28 +02:00
|
|
|
for (TSlots::const_iterator i = town->Slots().begin(); i != town->Slots().end(); i++)
|
2010-11-28 18:39:13 +02:00
|
|
|
{
|
2010-12-06 01:26:56 +02:00
|
|
|
if (i->second->type->AIValue < weakestCreatureAIValue)
|
2010-11-28 18:39:13 +02:00
|
|
|
{
|
2010-11-22 02:34:46 +02:00
|
|
|
weakestCreatureAIValue = i->second->type->AIValue;
|
2009-11-01 22:13:12 +02:00
|
|
|
weakestCreatureStack = i->first;
|
2009-10-28 18:28:52 +02:00
|
|
|
}
|
2010-11-28 18:39:13 +02:00
|
|
|
}
|
2010-12-10 01:10:28 +02:00
|
|
|
for (TSlots::const_iterator i = town->Slots().begin(); i != town->Slots().end(); i++)\
|
2010-11-28 18:39:13 +02:00
|
|
|
{ // For each town slot.
|
2010-12-10 01:10:28 +02:00
|
|
|
int hSlot = h->h->getSlotFor(i->second->type->idNumber);
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
if (hSlot == -1)
|
2010-11-28 18:39:13 +02:00
|
|
|
continue;
|
2010-12-06 01:26:56 +02:00
|
|
|
tlog6 << "giving hero " << i->second->type->namePl << endl;
|
2010-12-10 01:10:28 +02:00
|
|
|
if (!h->h->slotEmpty(hSlot))
|
2010-11-28 18:39:13 +02:00
|
|
|
{
|
2009-10-28 18:28:52 +02:00
|
|
|
// Can't take garrisonHero's last unit.
|
2010-11-28 18:39:13 +02:00
|
|
|
if ( (i->first == weakestCreatureStack) && (town->garrisonHero != NULL) )
|
2010-11-22 02:34:46 +02:00
|
|
|
cg.m_cb->splitStack(town, h->h, i->first, hSlot, i->second->count - 1);
|
2009-10-28 18:28:52 +02:00
|
|
|
else
|
|
|
|
// TODO: the comment says that this code is not safe for the AI.
|
|
|
|
cg.m_cb->mergeStacks(town, h->h, i->first, hSlot);
|
2010-11-28 18:39:13 +02:00
|
|
|
}
|
|
|
|
else
|
2009-10-28 18:28:52 +02:00
|
|
|
cg.m_cb->swapCreatures(town, h->h, i->first, hSlot);
|
2010-11-28 18:39:13 +02:00
|
|
|
} // for (std::map< si32, std::pair<ui32, si32> >::const_iterator ...
|
|
|
|
} // if (town && object->getOwner == cg.m_cb->getMyColor())
|
2009-08-04 01:15:13 +03:00
|
|
|
}
|
2009-08-05 12:46:55 +03:00
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
void CGeniusAI::addTownObjectives (HypotheticalGameState::TownModel& t, HypotheticalGameState& hgs)
|
2009-08-04 01:15:13 +03:00
|
|
|
{
|
|
|
|
//recruitHero
|
2009-08-05 12:46:55 +03:00
|
|
|
//buildBuilding
|
2009-08-04 01:15:13 +03:00
|
|
|
//recruitCreatures
|
|
|
|
//upgradeCreatures
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
// Recruit hero.
|
2010-11-28 18:39:13 +02:00
|
|
|
if ( (hgs.heroModels.size() < 3) && (hgs.resourceAmounts[6] >= 2500) )
|
|
|
|
{
|
2009-08-05 12:46:55 +03:00
|
|
|
bool heroAtTown = false;
|
2010-11-28 18:39:13 +02:00
|
|
|
for (int i = 0; i < hgs.heroModels.size(); i++)
|
|
|
|
{
|
2009-10-28 18:28:52 +02:00
|
|
|
if (hgs.heroModels[i].pos == t.t->getSightCenter())
|
2009-08-05 12:46:55 +03:00
|
|
|
heroAtTown = true;
|
2010-11-28 18:39:13 +02:00
|
|
|
}
|
2009-10-28 18:28:52 +02:00
|
|
|
// No visiting hero and built tavern.
|
2010-11-28 18:39:13 +02:00
|
|
|
if (!heroAtTown && vstd::contains(t.t->builtBuildings, 5))
|
|
|
|
{
|
|
|
|
for (int i = 0; i < hgs.AvailableHeroesToBuy.size(); i++)
|
|
|
|
{
|
|
|
|
if ( (hgs.AvailableHeroesToBuy[i] != NULL) && (t.t->subID == hgs.AvailableHeroesToBuy[i]->type->heroType / 2) )
|
|
|
|
{
|
|
|
|
TownObjective to(hgs,AIObjective::recruitHero, &t, 0, this);
|
2009-08-04 01:15:13 +03:00
|
|
|
currentTownObjectives.insert(to);
|
|
|
|
}
|
2010-11-28 18:39:13 +02:00
|
|
|
}
|
|
|
|
}
|
2009-10-28 18:28:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Build a building.
|
2010-11-28 18:39:13 +02:00
|
|
|
if (!t.hasBuilt)
|
|
|
|
{
|
2009-10-28 18:28:52 +02:00
|
|
|
// m_cb->getCBuildingsByID(t.t);
|
2010-12-20 23:22:53 +02:00
|
|
|
bmap<int, ConstTransitivePtr<CBuilding> > thisTownsBuildings = VLC->buildh->buildings[t.t->subID];
|
|
|
|
for (bmap<int, ConstTransitivePtr<CBuilding> >::iterator i = thisTownsBuildings.begin(); i != thisTownsBuildings.end(); i++)
|
2010-11-28 18:39:13 +02:00
|
|
|
{
|
|
|
|
if (m_cb->canBuildStructure(t.t, i->first) == 7)
|
|
|
|
{
|
2009-10-28 18:28:52 +02:00
|
|
|
TownObjective to(hgs, AIObjective::buildBuilding, &t, i->first ,this);
|
2009-08-05 12:46:55 +03:00
|
|
|
currentTownObjectives.insert(to);
|
|
|
|
}
|
2009-08-01 05:57:50 +03:00
|
|
|
}
|
2009-08-04 01:15:13 +03:00
|
|
|
}
|
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
// Recruit creatures.
|
2010-11-28 18:39:13 +02:00
|
|
|
for (int i = 0; i < t.creaturesToRecruit.size(); i++)
|
|
|
|
{
|
|
|
|
if (t.creaturesToRecruit[i].first == 0 || t.creaturesToRecruit[i].second.empty())
|
|
|
|
continue;
|
2009-08-05 12:46:55 +03:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
int ID = t.creaturesToRecruit[i].second.back();
|
2009-10-28 18:28:52 +02:00
|
|
|
// m_cb->getCCreatureByID(ID);
|
2010-05-02 21:20:26 +03:00
|
|
|
const CCreature *creature = VLC->creh->creatures[ID];
|
2009-08-05 12:46:55 +03:00
|
|
|
bool canAfford = true;
|
2009-10-28 18:28:52 +02:00
|
|
|
for (int ii = 0; ii < creature->cost.size(); ii++)
|
2010-11-28 18:39:13 +02:00
|
|
|
{
|
2009-10-28 18:28:52 +02:00
|
|
|
if (creature->cost[ii] > hgs.resourceAmounts[ii])
|
|
|
|
canAfford = false; // Can we afford at least one creature?
|
2010-11-28 18:39:13 +02:00
|
|
|
}
|
|
|
|
if (!canAfford)
|
|
|
|
continue;
|
2009-08-05 12:46:55 +03:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
//tlog6 << "town has " << t.t->creatures[i]->first << " "<< creature->namePl << " (AI Strength " << creature->AIValue << ")." << endl;
|
2009-10-28 18:28:52 +02:00
|
|
|
TownObjective to(hgs, AIObjective::recruitCreatures, &t, i, this);
|
2009-08-05 12:46:55 +03:00
|
|
|
currentTownObjectives.insert(to);
|
|
|
|
}
|
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
// Upgrade creatures.
|
2010-12-10 01:10:28 +02:00
|
|
|
for (TSlots::const_iterator i = t.t->Slots().begin(); i != t.t->Slots().end(); i++)
|
2010-11-28 18:39:13 +02:00
|
|
|
{
|
2009-10-28 18:28:52 +02:00
|
|
|
UpgradeInfo ui = m_cb->getUpgradeInfo(t.t, i->first);
|
2010-11-28 18:39:13 +02:00
|
|
|
if (ui.newID.size())
|
|
|
|
{
|
2009-08-06 12:52:07 +03:00
|
|
|
bool canAfford = true;
|
2009-08-21 21:18:52 +03:00
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
int upgrade_serial = ui.newID.size() - 1;
|
2010-11-28 18:39:13 +02:00
|
|
|
for (std::set< std::pair<int, int> >::iterator j = ui.cost[upgrade_serial].begin(); j != ui.cost[upgrade_serial].end(); j++)
|
|
|
|
{
|
2010-11-22 02:34:46 +02:00
|
|
|
if (hgs.resourceAmounts[j->first] < j->second * i->second->count)
|
2009-08-21 21:18:52 +03:00
|
|
|
canAfford = false;
|
2010-11-28 18:39:13 +02:00
|
|
|
}
|
|
|
|
if (canAfford)
|
|
|
|
{
|
2009-08-18 10:37:45 +03:00
|
|
|
TownObjective to(hgs,AIObjective::upgradeCreatures,&t,i->first,this);
|
2009-08-06 12:52:07 +03:00
|
|
|
currentTownObjectives.insert(to);
|
|
|
|
}
|
2010-11-28 18:39:13 +02:00
|
|
|
} // if (ui.netID.size() != 0)
|
|
|
|
} // for (std::map< si32, std::pair ...
|
2009-08-04 01:15:13 +03:00
|
|
|
}
|
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
void CGeniusAI::TownObjective::fulfill(CGeniusAI& cg,
|
|
|
|
HypotheticalGameState& hgs)
|
2009-08-04 01:15:13 +03:00
|
|
|
{
|
2009-08-06 12:52:07 +03:00
|
|
|
cg.m_cb->waitTillRealize = true;
|
2009-08-05 12:46:55 +03:00
|
|
|
CBuilding * b;
|
|
|
|
const CCreature *creature;
|
|
|
|
HypotheticalGameState::HeroModel hm;
|
2009-08-06 12:52:07 +03:00
|
|
|
int ID, howMany, newID, hSlot;
|
2009-10-28 18:28:52 +02:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case recruitHero:
|
|
|
|
cg.m_cb->recruitHero(whichTown->t, hgs.AvailableHeroesToBuy[which]);
|
|
|
|
hm = HypotheticalGameState::HeroModel(hgs.AvailableHeroesToBuy[which]);
|
|
|
|
hm.pos = whichTown->t->getSightCenter();
|
|
|
|
hm.remainingMovement = hm.h->maxMovePoints(true);
|
|
|
|
hgs.heroModels.push_back(hm);
|
|
|
|
hgs.resourceAmounts[6] -= 2500;
|
|
|
|
break;
|
2009-10-28 18:28:52 +02:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
case buildBuilding:
|
|
|
|
b = VLC->buildh->buildings[whichTown->t->subID][which];
|
|
|
|
if (cg.m_cb->canBuildStructure(whichTown->t,which) == 7)
|
|
|
|
{
|
|
|
|
tlog6 << "built " << b->Name() << "." << endl;
|
|
|
|
if (!cg.m_cb->buildBuilding(whichTown->t, which))
|
|
|
|
tlog6 << "really tried to build unbuildable building" << endl;
|
|
|
|
|
|
|
|
for (int i = 0; b && i < b->resources.size(); i++) // use only when certain building was found
|
|
|
|
hgs.resourceAmounts[i] -= b->resources[i];
|
|
|
|
} else
|
|
|
|
tlog6 << "trying to build a structure we cannot build" << endl;
|
|
|
|
whichTown->hasBuilt=true;
|
|
|
|
break;
|
2009-08-06 12:59:33 +03:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
case recruitCreatures:
|
|
|
|
// Buy upgraded if possible.
|
|
|
|
ID = whichTown->creaturesToRecruit[which].second.back();
|
|
|
|
creature = VLC->creh->creatures[ID];
|
|
|
|
howMany = whichTown->creaturesToRecruit[which].first;
|
|
|
|
for (int i = 0; i < creature->cost.size(); i++)
|
|
|
|
amin(howMany, creature->cost[i] ? hgs.resourceAmounts[i]/creature->cost[i] : INT_MAX);
|
|
|
|
if (howMany == 0)
|
|
|
|
{
|
|
|
|
tlog6 << "tried to recruit without enough money.";
|
|
|
|
tlog6 << "recruiting " << howMany << " "
|
|
|
|
<< creature->namePl << " (Total AI Strength "
|
|
|
|
<< creature->AIValue*howMany << ")." << endl;
|
|
|
|
cg.m_cb->recruitCreatures(whichTown->t, ID, howMany);
|
|
|
|
}
|
|
|
|
break;
|
2009-10-28 18:28:52 +02:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
case upgradeCreatures:
|
|
|
|
UpgradeInfo ui = cg.m_cb->getUpgradeInfo(whichTown->t, which);
|
2010-12-10 01:10:28 +02:00
|
|
|
ID = whichTown->t->getCreature(which)->idNumber;
|
2010-11-28 18:39:13 +02:00
|
|
|
newID = ui.newID.back();
|
|
|
|
// TODO: reduce resources in hgs
|
|
|
|
cg.m_cb->upgradeCreature(whichTown->t, which, newID);
|
|
|
|
tlog6 << "upgrading " << VLC->creh->creatures[ID]->namePl << endl;
|
|
|
|
break;
|
2009-08-04 01:15:13 +03:00
|
|
|
}
|
2009-08-01 05:57:50 +03:00
|
|
|
}
|
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
|
2009-08-04 11:56:38 +03:00
|
|
|
void CGeniusAI::fillObjectiveQueue(HypotheticalGameState & hgs)
|
|
|
|
{
|
|
|
|
objectiveQueue.clear();
|
|
|
|
currentHeroObjectives.clear();
|
|
|
|
currentTownObjectives.clear();
|
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
for (std::vector <CGeniusAI::HypotheticalGameState::HeroModel>::iterator i = hgs.heroModels.begin(); i != hgs.heroModels.end(); i++)
|
2009-10-28 18:28:52 +02:00
|
|
|
addHeroObjectives(*i, hgs);
|
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
for (std::vector <CGeniusAI::HypotheticalGameState::TownModel>::iterator i = hgs.townModels.begin(); i != hgs.townModels.end(); i++)
|
2009-10-28 18:28:52 +02:00
|
|
|
addTownObjectives(*i, hgs);
|
2009-08-18 10:37:45 +03:00
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
for (std::set<CGeniusAI::HeroObjective>::iterator i = currentHeroObjectives.begin(); i != currentHeroObjectives.end(); i++)
|
2009-10-28 18:28:52 +02:00
|
|
|
// TODO: Recheck and try to write simpler expression.
|
|
|
|
objectiveQueue.push_back(AIObjectivePtrCont((CGeniusAI::HeroObjective*)&(*i)));
|
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
for (std::set<CGeniusAI::TownObjective>::iterator i = currentTownObjectives.begin(); i != currentTownObjectives.end(); i++)
|
2009-10-28 18:28:52 +02:00
|
|
|
objectiveQueue.push_back(AIObjectivePtrCont((CGeniusAI::TownObjective*)&(*i)));
|
2009-08-04 11:56:38 +03:00
|
|
|
}
|
2009-08-18 10:37:45 +03:00
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
|
2009-08-04 11:56:38 +03:00
|
|
|
CGeniusAI::AIObjective * CGeniusAI::getBestObjective()
|
|
|
|
{
|
2009-10-28 18:28:52 +02:00
|
|
|
trueGameState.update(*this);
|
2009-08-04 11:56:38 +03:00
|
|
|
fillObjectiveQueue(trueGameState);
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
// TODO: Write this part.
|
2010-11-28 18:39:13 +02:00
|
|
|
// if(objectiveQueue.size())
|
2009-08-07 11:41:40 +03:00
|
|
|
// return max_element(objectiveQueue.begin(),objectiveQueue.end())->obj;
|
2009-08-18 10:37:45 +03:00
|
|
|
m_priorities->fillFeatures(trueGameState);
|
2009-10-28 18:28:52 +02:00
|
|
|
if (objectiveQueue.empty())
|
2010-11-28 18:39:13 +02:00
|
|
|
return NULL;
|
2009-08-19 13:18:14 +03:00
|
|
|
// sort(objectiveQueue.begin(),objectiveQueue.end());
|
|
|
|
// reverse(objectiveQueue.begin(),objectiveQueue.end());
|
2009-10-28 18:28:52 +02:00
|
|
|
int num = 1;
|
2009-08-18 10:37:45 +03:00
|
|
|
// for(std::vector<AIObjectivePtrCont> ::iterator i = objectiveQueue.begin(); i < objectiveQueue.end();i++)
|
|
|
|
// {
|
2010-11-28 18:39:13 +02:00
|
|
|
// if(!dynamic_cast<HeroObjective*>(i->obj))
|
|
|
|
// continue;
|
|
|
|
// tlog6 << num++ << ": ";
|
2009-08-18 10:37:45 +03:00
|
|
|
// i->obj->print();
|
2010-11-28 18:39:13 +02:00
|
|
|
// tlog6 << " value: " << i->obj->getValue();
|
|
|
|
// tlog6 << endl;
|
2009-08-18 10:37:45 +03:00
|
|
|
// }
|
|
|
|
// int choice = 0;
|
2010-11-28 18:39:13 +02:00
|
|
|
// tlog6 << "which would you do? (enter 0 for none): ";
|
2009-08-18 10:37:45 +03:00
|
|
|
// cin >> choice;
|
2010-11-28 18:39:13 +02:00
|
|
|
tlog6 << "doing best of " << objectiveQueue.size() << ": ";
|
|
|
|
CGeniusAI::AIObjective* best = max_element(objectiveQueue.begin(), objectiveQueue.end())->obj;
|
2009-08-19 13:18:14 +03:00
|
|
|
best->print();
|
2010-11-28 18:39:13 +02:00
|
|
|
tlog6 << " value = " << best->getValue() << endl;
|
|
|
|
|
|
|
|
if (objectiveQueue.size())
|
2009-08-19 13:18:14 +03:00
|
|
|
return best;
|
2009-08-07 11:41:40 +03:00
|
|
|
return objectiveQueue.front().obj;
|
2009-08-04 11:56:38 +03:00
|
|
|
}
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
|
2008-11-25 20:51:44 +02:00
|
|
|
void CGeniusAI::yourTurn()
|
|
|
|
{
|
2009-08-06 12:52:07 +03:00
|
|
|
static boost::mutex mutex;
|
|
|
|
boost::mutex::scoped_lock lock(mutex);
|
2009-12-29 03:07:17 +02:00
|
|
|
m_cb->waitTillRealize = false;
|
2009-08-04 01:15:13 +03:00
|
|
|
static int seed = rand();
|
|
|
|
srand(seed);
|
2010-11-28 18:39:13 +02:00
|
|
|
|
|
|
|
if (VLC->IS_AI_ENABLED)
|
|
|
|
{
|
|
|
|
m_cb->waitTillRealize = true;
|
|
|
|
// if (m_cb->getDate() == 1)
|
|
|
|
//{
|
|
|
|
// startFirstTurn();
|
|
|
|
//
|
|
|
|
// m_cb->endTurn();
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
//////////////TODO: replace with updates. Also add suspected objects list./////////
|
|
|
|
knownVisitableObjects.clear();
|
|
|
|
int3 pos = m_cb->getMapSize();
|
|
|
|
int y, z; //don't reallocate them unnecessarily
|
|
|
|
for (int x = 0; x < pos.x; ++x)
|
|
|
|
{
|
|
|
|
for (y = 0; y < pos.y; ++y)
|
|
|
|
{
|
|
|
|
for (z = 0; z < pos.z; ++z)
|
|
|
|
tileRevealed(int3(x,y,z));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
reportResources();
|
|
|
|
|
|
|
|
trueGameState = HypotheticalGameState(*this);
|
|
|
|
AIObjective * objective = getBestObjective();
|
|
|
|
if (objective) //single so far, TODO: restore while
|
|
|
|
objective->fulfill(*this,trueGameState);
|
|
|
|
seed = rand();
|
|
|
|
}
|
2009-09-20 16:22:47 +03:00
|
|
|
m_cb->endTurn();
|
2009-08-05 12:46:55 +03:00
|
|
|
m_cb->waitTillRealize = false;
|
2008-11-25 20:51:44 +02:00
|
|
|
}
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
|
2009-08-06 12:52:07 +03:00
|
|
|
void CGeniusAI::startFirstTurn()
|
|
|
|
{
|
|
|
|
HypotheticalGameState hgs(*this);
|
|
|
|
|
|
|
|
const CGTownInstance * town = m_cb->getTownInfo(0,0);
|
|
|
|
const CGHeroInstance * heroInst = m_cb->getHeroInfo(0,0);
|
|
|
|
|
2010-11-28 18:39:13 +02:00
|
|
|
TownObjective(hgs, AIObjective::recruitHero, &hgs.townModels.front(), 0, this).fulfill(*this, hgs);
|
2009-08-06 12:52:07 +03:00
|
|
|
|
|
|
|
m_cb->swapGarrisonHero(town);
|
|
|
|
hgs.update(*this);
|
2010-11-28 18:39:13 +02:00
|
|
|
for (ui32 i = 0; i < hgs.townModels.front().creaturesToRecruit.size(); ++i)
|
|
|
|
{
|
2009-10-28 18:28:52 +02:00
|
|
|
if (hgs.townModels.front().creaturesToRecruit[i].first == 0)
|
2010-11-28 18:39:13 +02:00
|
|
|
continue;
|
2009-08-06 12:52:07 +03:00
|
|
|
int ID = hgs.townModels.front().creaturesToRecruit[i].second.back();
|
2010-05-02 21:20:26 +03:00
|
|
|
const CCreature *creature = VLC->creh->creatures[ID];
|
2010-11-28 18:39:13 +02:00
|
|
|
|
2009-08-06 12:52:07 +03:00
|
|
|
bool canAfford = true;
|
2010-11-28 18:39:13 +02:00
|
|
|
for (ui32 ii = 0; ii < creature->cost.size(); ii++)
|
|
|
|
{
|
2009-10-28 18:28:52 +02:00
|
|
|
if (creature->cost[ii] > hgs.resourceAmounts[ii])
|
2009-11-01 22:13:12 +02:00
|
|
|
canAfford = false; // Can we afford at least one creature?
|
2010-11-28 18:39:13 +02:00
|
|
|
}
|
2009-10-28 18:28:52 +02:00
|
|
|
if (!canAfford)
|
2010-11-28 18:39:13 +02:00
|
|
|
continue;
|
|
|
|
|
2009-08-18 10:37:45 +03:00
|
|
|
TownObjective(hgs,AIObjective::recruitCreatures,&hgs.townModels.front(),i,this).fulfill(*this,hgs);
|
2010-11-28 18:39:13 +02:00
|
|
|
}
|
2009-08-06 12:52:07 +03:00
|
|
|
hgs.update(*this);
|
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
HypotheticalGameState::HeroModel* hero;
|
2010-11-28 18:39:13 +02:00
|
|
|
for (int i = 0; i < hgs.heroModels.size(); i++)
|
|
|
|
{
|
2009-10-28 18:28:52 +02:00
|
|
|
if (hgs.heroModels[i].h->id == heroInst->id)
|
2010-11-28 18:39:13 +02:00
|
|
|
HeroObjective(hgs, AIObjective::visit, town, hero = &hgs.heroModels[i], this).fulfill(*this,hgs);
|
|
|
|
}
|
2009-10-28 18:28:52 +02:00
|
|
|
hgs.update(*this);
|
2009-11-01 22:13:12 +02:00
|
|
|
// m_cb->swapGarrisonHero(town);
|
2009-08-06 12:52:07 +03:00
|
|
|
//TODO: choose the strongest hero.
|
|
|
|
}
|
|
|
|
|
2009-08-01 05:57:50 +03:00
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
void CGeniusAI::heroKilled(const CGHeroInstance* hero)
|
|
|
|
{
|
2008-11-25 20:51:44 +02:00
|
|
|
}
|
|
|
|
|
2009-08-01 05:57:50 +03:00
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
void CGeniusAI::heroCreated(const CGHeroInstance* hero)
|
|
|
|
{
|
2008-11-25 20:51:44 +02:00
|
|
|
}
|
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
|
2009-08-04 01:15:13 +03:00
|
|
|
void CGeniusAI::tileRevealed(int3 pos)
|
2008-11-25 20:51:44 +02:00
|
|
|
{
|
2009-10-28 18:28:52 +02:00
|
|
|
std::vector<const CGObjectInstance*> objects = m_cb->getVisitableObjs(pos);
|
2010-11-28 18:39:13 +02:00
|
|
|
for (std::vector <const CGObjectInstance*>::iterator o = objects.begin(); o != objects.end(); o++)
|
|
|
|
{
|
2009-10-28 18:28:52 +02:00
|
|
|
if ((*o)->id != -1)
|
2009-08-07 11:41:40 +03:00
|
|
|
knownVisitableObjects.insert(*o);
|
2010-11-28 18:39:13 +02:00
|
|
|
}
|
2009-08-04 01:15:13 +03:00
|
|
|
objects = m_cb->getFlaggableObjects(pos);
|
2010-11-28 18:39:13 +02:00
|
|
|
for (std::vector<const CGObjectInstance*>::iterator o = objects.begin(); o != objects.end(); o++)
|
2009-10-28 18:28:52 +02:00
|
|
|
if ((*o)->id != -1)
|
2009-08-07 11:41:40 +03:00
|
|
|
knownVisitableObjects.insert(*o);
|
2009-08-04 01:15:13 +03:00
|
|
|
}
|
2009-08-01 05:57:50 +03:00
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
// eg. ship built in shipyard
|
|
|
|
void CGeniusAI::newObject(const CGObjectInstance* obj)
|
2009-08-04 01:15:13 +03:00
|
|
|
{
|
2009-10-28 18:28:52 +02:00
|
|
|
knownVisitableObjects.insert(obj);
|
2009-08-04 11:56:38 +03:00
|
|
|
}
|
2009-08-01 05:57:50 +03:00
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
|
2009-08-04 11:56:38 +03:00
|
|
|
void CGeniusAI::objectRemoved(const CGObjectInstance *obj) //eg. collected resource, picked artifact, beaten hero
|
|
|
|
{
|
2009-10-28 18:28:52 +02:00
|
|
|
std::set<AIObjectContainer>::iterator o = knownVisitableObjects.find(obj);
|
|
|
|
if (o != knownVisitableObjects.end())
|
2009-08-04 11:56:38 +03:00
|
|
|
knownVisitableObjects.erase(o);
|
|
|
|
}
|
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
|
2009-08-04 11:56:38 +03:00
|
|
|
void CGeniusAI::tileHidden(int3 pos)
|
|
|
|
{
|
2008-11-25 20:51:44 +02:00
|
|
|
}
|
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
|
2009-11-01 22:13:12 +02:00
|
|
|
void CGeniusAI::heroMoved(const TryMoveHero& TMH)
|
2009-08-04 01:15:13 +03:00
|
|
|
{
|
2009-11-01 22:13:12 +02:00
|
|
|
// DbgBox("** CGeniusAI::heroMoved **");
|
2009-08-04 01:15:13 +03:00
|
|
|
}
|
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
void CGeniusAI::heroGotLevel(const CGHeroInstance *hero,
|
|
|
|
int pskill,
|
|
|
|
std::vector<ui16>& skills,
|
2009-11-01 22:13:12 +02:00
|
|
|
boost::function<void(ui32)>& callback)
|
2008-11-25 20:51:44 +02:00
|
|
|
{
|
|
|
|
callback(rand() % skills.size());
|
|
|
|
}
|
2009-04-11 04:32:50 +03:00
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
|
2009-11-01 22:13:12 +02:00
|
|
|
void geniusai::CGeniusAI::showGarrisonDialog(const CArmedInstance* up,
|
|
|
|
const CGHeroInstance* down,
|
2009-10-28 18:28:52 +02:00
|
|
|
bool removableUnits,
|
|
|
|
boost::function<void()>& onEnd)
|
2009-04-12 03:58:41 +03:00
|
|
|
{
|
|
|
|
onEnd();
|
|
|
|
}
|
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
|
2009-11-01 22:13:12 +02:00
|
|
|
void geniusai::CGeniusAI::playerBlocked(int reason)
|
2009-08-04 02:53:18 +03:00
|
|
|
{
|
2009-10-28 18:28:52 +02:00
|
|
|
if (reason == 0) // Battle is coming...
|
2009-08-04 02:53:18 +03:00
|
|
|
m_state.setn(UPCOMING_BATTLE);
|
|
|
|
}
|
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
|
2009-10-23 01:04:42 +03:00
|
|
|
void geniusai::CGeniusAI::battleResultsApplied()
|
2009-08-04 02:53:18 +03:00
|
|
|
{
|
|
|
|
assert(m_state.get() == ENDING_BATTLE);
|
|
|
|
m_state.setn(NO_BATTLE);
|
|
|
|
}
|
|
|
|
|
2009-11-01 22:13:12 +02:00
|
|
|
// TODO: Shouldn't the parameters be made const (apart from cancel)?
|
2009-10-28 18:28:52 +02:00
|
|
|
void CGeniusAI::showBlockingDialog(const std::string& text,
|
|
|
|
const std::vector<Component> &components,
|
|
|
|
ui32 askID,
|
|
|
|
const int soundID,
|
|
|
|
bool selection,
|
|
|
|
bool cancel)
|
2009-04-11 04:32:50 +03:00
|
|
|
{
|
2009-11-01 22:13:12 +02:00
|
|
|
m_cb->selectionMade(cancel ? false : true, askID);
|
2009-04-11 04:32:50 +03:00
|
|
|
}
|
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
|
2008-11-25 20:51:44 +02:00
|
|
|
/**
|
|
|
|
* occurs AFTER every action taken by any stack or by the hero
|
|
|
|
*/
|
2009-10-28 18:28:52 +02:00
|
|
|
void CGeniusAI::actionFinished(const BattleAction* action)
|
2008-11-25 20:51:44 +02:00
|
|
|
{
|
|
|
|
std::string message("\t\tCGeniusAI::actionFinished - type(");
|
|
|
|
message += boost::lexical_cast<std::string>((unsigned)action->actionType);
|
|
|
|
message += "), side(";
|
|
|
|
message += boost::lexical_cast<std::string>((unsigned)action->side);
|
|
|
|
message += ")";
|
2009-08-04 01:15:13 +03:00
|
|
|
DbgBox(message.c_str());
|
2008-11-25 20:51:44 +02:00
|
|
|
}
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
|
2008-11-25 20:51:44 +02:00
|
|
|
/**
|
|
|
|
* occurs BEFORE every action taken by any stack or by the hero
|
|
|
|
*/
|
|
|
|
void CGeniusAI::actionStarted(const BattleAction *action)
|
|
|
|
{
|
|
|
|
std::string message("\t\tCGeniusAI::actionStarted - type(");
|
|
|
|
message += boost::lexical_cast<std::string>((unsigned)action->actionType);
|
|
|
|
message += "), side(";
|
|
|
|
message += boost::lexical_cast<std::string>((unsigned)action->side);
|
|
|
|
message += ")";
|
2009-08-04 01:15:13 +03:00
|
|
|
DbgBox(message.c_str());
|
2008-11-25 20:51:44 +02:00
|
|
|
}
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
|
2008-11-25 20:51:44 +02:00
|
|
|
/**
|
|
|
|
* called when stack is performing attack
|
|
|
|
*/
|
2010-12-04 21:44:23 +02:00
|
|
|
void CGeniusAI::battleAttack(const BattleAttack* ba)
|
2008-11-25 20:51:44 +02:00
|
|
|
{
|
2009-08-04 01:15:13 +03:00
|
|
|
DbgBox("\t\t\tCGeniusAI::battleAttack");
|
2008-11-25 20:51:44 +02:00
|
|
|
}
|
2009-11-01 22:13:12 +02:00
|
|
|
|
|
|
|
|
2008-11-25 20:51:44 +02:00
|
|
|
/**
|
|
|
|
* called when stack receives damage (after battleAttack())
|
|
|
|
*/
|
2010-12-04 21:44:23 +02:00
|
|
|
void CGeniusAI::battleStacksAttacked(const std::set<BattleStackAttacked>& bsa)
|
2008-11-25 20:51:44 +02:00
|
|
|
{
|
2009-08-04 01:15:13 +03:00
|
|
|
DbgBox("\t\t\tCGeniusAI::battleStacksAttacked");
|
2008-11-25 20:51:44 +02:00
|
|
|
}
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
|
2008-11-25 20:51:44 +02:00
|
|
|
/**
|
|
|
|
* called by engine when battle starts; side=0 - left, side=1 - right
|
|
|
|
*/
|
2010-12-04 21:15:20 +02:00
|
|
|
void CGeniusAI::battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side)
|
2008-11-25 20:51:44 +02:00
|
|
|
{
|
2009-10-28 18:28:52 +02:00
|
|
|
// TODO: Battle logic what...
|
2009-08-04 02:53:18 +03:00
|
|
|
assert(!m_battleLogic);
|
2009-10-28 18:28:52 +02:00
|
|
|
// We have been informed that battle will start (or we are neutral AI)
|
|
|
|
assert( (playerID > PLAYER_LIMIT) || (m_state.get() == UPCOMING_BATTLE) );
|
2009-08-04 02:53:18 +03:00
|
|
|
|
|
|
|
m_state.setn(ONGOING_BATTLE);
|
2009-10-28 18:28:52 +02:00
|
|
|
m_battleLogic = new BattleAI::CBattleLogic(m_cb, army1, army2, tile, hero1,
|
|
|
|
hero2, side);
|
2008-11-25 20:51:44 +02:00
|
|
|
|
2009-08-04 01:15:13 +03:00
|
|
|
DbgBox("** CGeniusAI::battleStart **");
|
2008-11-25 20:51:44 +02:00
|
|
|
}
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
|
2008-11-25 20:51:44 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2010-12-04 21:44:23 +02:00
|
|
|
void CGeniusAI::battleEnd(const BattleResult* br)
|
2008-11-25 20:51:44 +02:00
|
|
|
{
|
2010-11-28 18:39:13 +02:00
|
|
|
switch (br->winner)
|
|
|
|
{
|
|
|
|
case 0: tlog6 << "The winner is the attacker." << std::endl; break;
|
|
|
|
case 1: tlog6 << "The winner is the defender." << std::endl; break;
|
|
|
|
case 2: tlog6 << "It's a draw." << std::endl; break;
|
2009-08-06 12:52:07 +03:00
|
|
|
};
|
2010-11-28 18:39:13 +02:00
|
|
|
tlog6 << "lost ";
|
2010-12-04 21:44:23 +02:00
|
|
|
for (std::map<ui32,si32>::const_iterator i = br->casualties[0].begin(); i != br->casualties[0].end(); i++)
|
2010-11-28 18:39:13 +02:00
|
|
|
tlog6 << i->second << " " << VLC->creh->creatures[i->first]->namePl << endl;
|
2009-08-21 21:18:52 +03:00
|
|
|
|
2008-11-25 20:51:44 +02:00
|
|
|
delete m_battleLogic;
|
|
|
|
m_battleLogic = NULL;
|
|
|
|
|
2009-08-04 02:53:18 +03:00
|
|
|
assert(m_state.get() == ONGOING_BATTLE);
|
|
|
|
m_state.setn(ENDING_BATTLE);
|
|
|
|
|
2009-08-04 01:15:13 +03:00
|
|
|
DbgBox("** CGeniusAI::battleEnd **");
|
2008-11-25 20:51:44 +02:00
|
|
|
}
|
2009-10-28 18:28:52 +02:00
|
|
|
|
2009-11-01 22:13:12 +02:00
|
|
|
/*
|
|
|
|
* Called at the beggining of each turn, round = -1 is the tactic phase,
|
|
|
|
* round = 0 is the first "normal" turn.
|
2008-11-25 20:51:44 +02:00
|
|
|
*/
|
|
|
|
void CGeniusAI::battleNewRound(int round)
|
|
|
|
{
|
|
|
|
std::string message("\tCGeniusAI::battleNewRound - ");
|
|
|
|
message += boost::lexical_cast<std::string>(round);
|
2009-08-04 01:15:13 +03:00
|
|
|
DbgBox(message.c_str());
|
2008-11-25 20:51:44 +02:00
|
|
|
|
|
|
|
m_battleLogic->SetCurrentTurn(round);
|
|
|
|
}
|
2009-10-28 18:28:52 +02:00
|
|
|
|
2008-11-25 20:51:44 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2010-12-23 22:18:10 +02:00
|
|
|
void CGeniusAI::battleStackMoved(int ID, THex dest, int distance, bool end)
|
2008-11-25 20:51:44 +02:00
|
|
|
{
|
|
|
|
std::string message("\t\t\tCGeniusAI::battleStackMoved ID(");
|
|
|
|
message += boost::lexical_cast<std::string>(ID);
|
|
|
|
message += "), dest(";
|
|
|
|
message += boost::lexical_cast<std::string>(dest);
|
|
|
|
message += ")";
|
2009-08-04 01:15:13 +03:00
|
|
|
DbgBox(message.c_str());
|
2008-11-25 20:51:44 +02:00
|
|
|
}
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
|
2008-11-25 20:51:44 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2010-12-04 21:44:23 +02:00
|
|
|
void CGeniusAI::battleSpellCast(const BattleSpellCast *sc)
|
2008-11-25 20:51:44 +02:00
|
|
|
{
|
2009-08-04 01:15:13 +03:00
|
|
|
DbgBox("\t\t\tCGeniusAI::battleSpellCast");
|
2008-11-25 20:51:44 +02:00
|
|
|
}
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
|
2008-11-25 20:51:44 +02:00
|
|
|
/**
|
|
|
|
* called when battlefield is prepared, prior the battle beginning
|
|
|
|
*/
|
2010-12-04 21:15:20 +02:00
|
|
|
// void CGeniusAI::battlefieldPrepared(int battlefieldType,
|
|
|
|
// std::vector<CObstacle*> obstacles)
|
|
|
|
// {
|
|
|
|
// DbgBox("CGeniusAI::battlefieldPrepared");
|
|
|
|
// }
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
|
2008-11-25 20:51:44 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2010-12-23 22:18:10 +02:00
|
|
|
// void CGeniusAI::battleStackMoved(int ID,
|
|
|
|
// THex dest,
|
|
|
|
// bool startMoving,
|
|
|
|
// bool endMoving)
|
|
|
|
// {
|
|
|
|
// DbgBox("\t\t\tCGeniusAI::battleStackMoved");
|
|
|
|
// }
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
|
2008-11-25 20:51:44 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void CGeniusAI::battleStackAttacking(int ID, int dest)
|
|
|
|
{
|
2009-08-04 01:15:13 +03:00
|
|
|
DbgBox("\t\t\tCGeniusAI::battleStackAttacking");
|
2008-11-25 20:51:44 +02:00
|
|
|
}
|
2009-10-28 18:28:52 +02:00
|
|
|
|
|
|
|
|
2008-11-25 20:51:44 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2009-11-01 22:13:12 +02:00
|
|
|
void CGeniusAI::battleStackIsAttacked(int ID,
|
|
|
|
int dmg,
|
|
|
|
int killed,
|
|
|
|
int IDby,
|
|
|
|
bool byShooting)
|
2008-11-25 20:51:44 +02:00
|
|
|
{
|
2009-08-04 01:15:13 +03:00
|
|
|
DbgBox("\t\t\tCGeniusAI::battleStackIsAttacked");
|
2008-11-25 20:51:44 +02:00
|
|
|
}
|
|
|
|
|
2009-10-28 18:28:52 +02:00
|
|
|
|
2008-11-25 20:51:44 +02:00
|
|
|
/**
|
|
|
|
* called when it's turn of that stack
|
|
|
|
*/
|
2010-12-23 22:18:10 +02:00
|
|
|
BattleAction CGeniusAI::activeStack(const CStack * stack)
|
2008-11-25 20:51:44 +02:00
|
|
|
{
|
|
|
|
std::string message("\t\t\tCGeniusAI::activeStack stackID(");
|
2009-02-08 17:39:26 +02:00
|
|
|
|
2010-12-23 22:18:10 +02:00
|
|
|
message += boost::lexical_cast<std::string>(stack->ID);
|
2008-11-25 20:51:44 +02:00
|
|
|
message += ")";
|
2009-08-04 01:15:13 +03:00
|
|
|
DbgBox(message.c_str());
|
2008-11-25 20:51:44 +02:00
|
|
|
|
2010-12-23 22:18:10 +02:00
|
|
|
BattleAction bact = m_battleLogic->MakeDecision(stack->ID);
|
2009-09-07 05:29:44 +03:00
|
|
|
assert(m_cb->battleGetStackByID(bact.stackNumber));
|
|
|
|
return bact;
|
2010-12-23 22:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//WTF?!? why is this needed?!?!?!
|
|
|
|
BattleAction CGlobalAI::activeStack( const CStack * stack )
|
|
|
|
{
|
|
|
|
BattleAction ba; ba.actionType = BattleAction::DEFEND;
|
|
|
|
ba.stackNumber = stack->ID;
|
|
|
|
return ba;
|
|
|
|
}
|
|
|
|
|