1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-20 20:23:03 +02:00
vcmi/AI/GeniusAI/CGeniusAI.cpp

209 lines
5.1 KiB
C++
Raw Normal View History

2008-11-25 20:51:44 +02:00
#include "CGeniusAI.h"
#include <iostream>
using namespace std;
2008-11-25 20:51:44 +02:00
using namespace GeniusAI;
2009-02-08 18:36:53 +02:00
#if defined (_MSC_VER) && (_MSC_VER >= 1020) || (__MINGW32__)
2008-11-25 20:51:44 +02:00
#include <windows.h>
#endif
void MsgBox(const char *msg, bool messageBox)
2008-11-25 20:51:44 +02:00
{
#if defined _DEBUG
# if defined (_MSC_VER) && (_MSC_VER >= 1020)
if (messageBox)
{
MessageBoxA(NULL, msg, "Debug message", MB_OK | MB_ICONASTERISK);
}
# endif
std::cout << msg << std::endl;
#endif
}
CGeniusAI::CGeniusAI()
: m_generalAI()
{
}
CGeniusAI::~CGeniusAI()
{
}
2008-11-25 20:51:44 +02:00
void CGeniusAI::init(ICallback *CB)
{
m_cb = CB;
m_generalAI.init(CB);
2008-11-25 20:51:44 +02:00
human = false;
playerID = m_cb->getMyColor();
serialID = m_cb->getMySerial();
std::string info = std::string("GeniusAI initialized for player ") + boost::lexical_cast<std::string>(playerID);
m_battleLogic = NULL;
MsgBox(info.c_str());
}
void CGeniusAI::yourTurn()
{
m_cb->endTurn();
}
void CGeniusAI::heroKilled(const CGHeroInstance *)
{
}
void CGeniusAI::heroCreated(const CGHeroInstance *)
{
}
void CGeniusAI::heroMoved(const HeroMoveDetails &)
{
}
void CGeniusAI::heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback)
{
callback(rand() % skills.size());
}
void GeniusAI::CGeniusAI::showGarrisonDialog( const CArmedInstance *up, const CGHeroInstance *down, boost::function<void()> &onEnd )
{
onEnd();
}
void CGeniusAI::showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, const int soundID, bool selection, bool cancel)
{
m_cb->selectionMade(cancel ? 0 : 1, askID);
}
2008-11-25 20:51:44 +02:00
/**
* occurs AFTER every action taken by any stack or by the hero
*/
void CGeniusAI::actionFinished(const BattleAction *action)
{
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 += ")";
MsgBox(message.c_str());
}
/**
* 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 += ")";
MsgBox(message.c_str());
}
/**
* called when stack is performing attack
*/
void CGeniusAI::battleAttack(BattleAttack *ba)
{
MsgBox("\t\t\tCGeniusAI::battleAttack");
}
/**
* called when stack receives damage (after battleAttack())
*/
void CGeniusAI::battleStacksAttacked(std::set<BattleStackAttacked> & bsa)
2008-11-25 20:51:44 +02:00
{
MsgBox("\t\t\tCGeniusAI::battleStacksAttacked");
2008-11-25 20:51:44 +02:00
}
/**
* called by engine when battle starts; side=0 - left, side=1 - right
*/
void CGeniusAI::battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side)
{
assert(!m_battleLogic);
m_battleLogic = new BattleAI::CBattleLogic(m_cb, army1, army2, tile, hero1, hero2, side);
2008-11-25 20:51:44 +02:00
MsgBox("** CGeniusAI::battleStart **");
}
/**
*
*/
void CGeniusAI::battleEnd(BattleResult *br)
{
delete m_battleLogic;
m_battleLogic = NULL;
MsgBox("** CGeniusAI::battleEnd **");
}
/**
* called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
*/
void CGeniusAI::battleNewRound(int round)
{
std::string message("\tCGeniusAI::battleNewRound - ");
message += boost::lexical_cast<std::string>(round);
MsgBox(message.c_str());
m_battleLogic->SetCurrentTurn(round);
}
/**
*
*/
void CGeniusAI::battleStackMoved(int ID, int 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 += ")";
MsgBox(message.c_str());
}
/**
*
*/
2009-05-12 06:35:51 +03:00
void CGeniusAI::battleSpellCast(SpellCast *sc)
2008-11-25 20:51:44 +02:00
{
2009-05-12 06:35:51 +03:00
MsgBox("\t\t\tCGeniusAI::battleSpellCast");
2008-11-25 20:51:44 +02:00
}
/**
* called when battlefield is prepared, prior the battle beginning
*/
void CGeniusAI::battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles)
{
MsgBox("CGeniusAI::battlefieldPrepared");
}
/**
*
*/
void CGeniusAI::battleStackMoved(int ID, int dest, bool startMoving, bool endMoving)
{
MsgBox("\t\t\tCGeniusAI::battleStackMoved");
}
/**
*
*/
void CGeniusAI::battleStackAttacking(int ID, int dest)
{
MsgBox("\t\t\tCGeniusAI::battleStackAttacking");
}
/**
*
*/
void CGeniusAI::battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting)
{
MsgBox("\t\t\tCGeniusAI::battleStackIsAttacked");
}
/**
* called when it's turn of that stack
*/
BattleAction CGeniusAI::activeStack(int stackID)
2008-11-25 20:51:44 +02:00
{
std::string message("\t\t\tCGeniusAI::activeStack stackID(");
2008-11-25 20:51:44 +02:00
message += boost::lexical_cast<std::string>(stackID);
message += ")";
MsgBox(message.c_str());
return m_battleLogic->MakeDecision(stackID);
};