CGeniusAI.cpp 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. #include "CGeniusAI.h"
  2. #include "AIPriorities.h"
  3. #include <iostream>
  4. #include "../../hch/CBuildingHandler.h"
  5. #include "../../hch/CHeroHandler.h"
  6. #include "../../lib/VCMI_Lib.h"
  7. #include "../../lib/NetPacks.h"
  8. using namespace std;
  9. using namespace GeniusAI;
  10. #if defined (_MSC_VER) && (_MSC_VER >= 1020) || (__MINGW32__)
  11. #define WIN32_LEAN_AND_MEAN //excludes rarely used stuff from windows headers - delete this line if something is missing
  12. #include <windows.h>
  13. #endif
  14. void DbgBox(const char *msg, bool messageBox)
  15. {
  16. #if defined PRINT_DEBUG
  17. #if defined _DEBUG
  18. //#if 0
  19. # if defined (_MSC_VER) && (_MSC_VER >= 1020)
  20. if (messageBox)
  21. {
  22. MessageBoxA(NULL, msg, "Debug message", MB_OK | MB_ICONASTERISK);
  23. }
  24. # endif
  25. std::cout << msg << std::endl;
  26. #endif
  27. #endif
  28. }
  29. bool CGeniusAI::AIObjectContainer::operator<(const AIObjectContainer& b)const
  30. {
  31. if (o->pos!=b.o->pos)
  32. return o->pos<b.o->pos;
  33. return o->id<b.o->id;
  34. }
  35. CGeniusAI::HypotheticalGameState::HeroModel::HeroModel(const CGHeroInstance * h)
  36. :h(h),finished(false)
  37. {
  38. pos = h->getPosition(false);remainingMovement = h->movement;
  39. }
  40. CGeniusAI::HypotheticalGameState::TownModel::TownModel(const CGTownInstance *t):t(t)
  41. {
  42. hasBuilt = t->builded;
  43. creaturesToRecruit = t->creatures;
  44. creaturesInGarrison = t->army;
  45. }
  46. CGeniusAI::HypotheticalGameState::HypotheticalGameState(CGeniusAI & ai)
  47. :knownVisitableObjects(ai.knownVisitableObjects)
  48. {
  49. AI = &ai;
  50. std::vector < const CGHeroInstance *> heroes = ai.m_cb->getHeroesInfo();
  51. for(std::vector < const CGHeroInstance *>::iterator i = heroes.begin(); i != heroes.end(); i++)
  52. heroModels.push_back(HeroModel(*i));
  53. std::vector < const CGTownInstance *> towns = ai.m_cb->getTownsInfo();
  54. for(std::vector < const CGTownInstance *>::iterator i = towns.begin(); i != towns.end(); i++)
  55. if((*i)->tempOwner==ai.m_cb->getMyColor())
  56. townModels.push_back(TownModel(*i));
  57. if(ai.m_cb->howManyTowns()!=0)
  58. AvailableHeroesToBuy = ai.m_cb->getAvailableHeroes(ai.m_cb->getTownInfo(0,0));
  59. for(int i = 0; i < 8;i++)resourceAmounts.push_back(ai.m_cb->getResourceAmount(i));
  60. }
  61. void CGeniusAI::HypotheticalGameState::update(CGeniusAI & ai)
  62. {
  63. AI = &ai;
  64. knownVisitableObjects = ai.knownVisitableObjects;
  65. std::vector<HeroModel> oldModels = heroModels;
  66. heroModels.clear();
  67. std::vector < const CGHeroInstance *> heroes = ai.m_cb->getHeroesInfo();
  68. for(std::vector < const CGHeroInstance *>::iterator i = heroes.begin(); i != heroes.end(); i++)
  69. heroModels.push_back(HeroModel(*i));
  70. for(int i = 0; i < oldModels.size();i++)
  71. for(int ii = 0; ii < heroModels.size();ii++)
  72. if(oldModels[i].h->subID==heroModels[ii].h->subID)
  73. {
  74. heroModels[ii].finished = oldModels[i].finished;
  75. heroModels[ii].previouslyVisited_pos=oldModels[i].previouslyVisited_pos;
  76. }
  77. townModels.clear();
  78. std::vector < const CGTownInstance *> towns = ai.m_cb->getTownsInfo();
  79. for(std::vector < const CGTownInstance *>::iterator i = towns.begin(); i != towns.end(); i++)
  80. if((*i)->tempOwner==ai.m_cb->getMyColor())
  81. townModels.push_back(TownModel(*i));
  82. if(ai.m_cb->howManyTowns()!=0)
  83. AvailableHeroesToBuy = ai.m_cb->getAvailableHeroes(ai.m_cb->getTownInfo(0,0));
  84. resourceAmounts.clear();
  85. for(int i = 0; i < 8;i++)resourceAmounts.push_back(ai.m_cb->getResourceAmount(i));
  86. }
  87. CGeniusAI::HeroObjective::HeroObjective(const HypotheticalGameState &hgs,Type t,const CGObjectInstance * object,HypotheticalGameState::HeroModel *h,CGeniusAI * ai):object(object),hgs(hgs)
  88. {
  89. AI = ai;
  90. pos = object->pos;
  91. type = t;
  92. whoCanAchieve.push_back(h);
  93. _value = -1;
  94. }
  95. float CGeniusAI::HeroObjective::getValue() const
  96. {
  97. if(_value>=0)
  98. return _value-_cost;
  99. vector<int> resourceCosts; //TODO: each object should have an associated cost to visit IE (tree of knowledge 1000 gold/10 gems)
  100. for(int i = 0; i < 8;i++)
  101. resourceCosts.push_back(0);
  102. if(object->ID==47) //school of magic
  103. resourceCosts[6]+=1000;
  104. float bestCost = 9e9;
  105. HypotheticalGameState::HeroModel * bestHero = NULL;
  106. if(type !=AIObjective::finishTurn)
  107. {
  108. for(int i = 0; i < whoCanAchieve.size();i++)
  109. {
  110. int distOutOfTheWay = 0;
  111. CPath path3;
  112. //from hero to object
  113. if(AI->m_cb->getPath(whoCanAchieve[i]->pos,pos,whoCanAchieve[i]->h,path3))
  114. distOutOfTheWay+=path3.nodes[0].dist;
  115. //from object to goal
  116. if(AI->m_cb->getPath(pos,whoCanAchieve[i]->interestingPos,whoCanAchieve[i]->h,path3))
  117. {
  118. distOutOfTheWay+=path3.nodes[0].dist;
  119. //from hero directly to goal
  120. if(AI->m_cb->getPath(whoCanAchieve[i]->pos,whoCanAchieve[i]->interestingPos,whoCanAchieve[i]->h,path3))
  121. distOutOfTheWay-=path3.nodes[0].dist;
  122. }
  123. float cost = AI->m_priorities->getCost(resourceCosts,whoCanAchieve[i]->h,distOutOfTheWay);
  124. if(cost < bestCost)
  125. {
  126. bestCost = cost;
  127. bestHero = whoCanAchieve[i];
  128. }
  129. }
  130. }
  131. else bestCost = 0;
  132. if(bestHero)
  133. {
  134. whoCanAchieve.clear();
  135. whoCanAchieve.push_back(bestHero);
  136. }
  137. _value = AI->m_priorities->getValue(*this);
  138. _cost=bestCost;
  139. return _value-_cost;
  140. }
  141. bool CGeniusAI::HeroObjective::operator < (const HeroObjective &other)const
  142. {
  143. if(type != other.type)
  144. return type<other.type;
  145. if(pos!=other.pos)
  146. return pos < other.pos;
  147. if(object->id!=other.object->id)
  148. return object->id < other.object->id;
  149. if(dynamic_cast<const CGVisitableOPH *> (object))
  150. if(whoCanAchieve.front()->h->id!=other.whoCanAchieve.front()->h->id)
  151. return whoCanAchieve.front()->h->id<other.whoCanAchieve.front()->h->id;
  152. return false;
  153. }
  154. void CGeniusAI::HeroObjective::print() const
  155. {
  156. switch(type)
  157. {
  158. case visit:
  159. cout << "visit " << object->hoverName << " at (" <<object->pos.x << ","<<object->pos.y << ")" ;
  160. break;
  161. case attack:
  162. cout << "attack " << object->hoverName;
  163. break;
  164. case finishTurn:
  165. cout << "finish turn";
  166. }
  167. if(whoCanAchieve.size()==1)
  168. cout << " with " << whoCanAchieve.front()->h->hoverName;
  169. }
  170. CGeniusAI::TownObjective::TownObjective(const HypotheticalGameState &hgs,Type t,HypotheticalGameState::TownModel * tn,int Which,CGeniusAI * ai)
  171. :whichTown(tn),which(Which),hgs(hgs)
  172. {
  173. AI=ai;
  174. type = t;
  175. _value = -1;
  176. }
  177. float CGeniusAI::TownObjective::getValue() const
  178. {
  179. if(_value>=0)
  180. return _value-_cost;
  181. float cost;
  182. vector<int> resourceCosts(8,0);
  183. CBuilding * b;
  184. CCreature * creature;
  185. int ID,newID, howMany;
  186. switch(type)
  187. {
  188. case recruitHero:
  189. resourceCosts[6]=2500;
  190. break;
  191. case buildBuilding:
  192. b = VLC->buildh->buildings[whichTown->t->subID][which];
  193. for(int i = 0; b && i < b->resources.size();i++)
  194. resourceCosts[i]=b->resources[i];
  195. break;
  196. case recruitCreatures:
  197. ID = whichTown->creaturesToRecruit[which].second.back(); //buy upgraded if possible
  198. creature = &VLC->creh->creatures[ID];
  199. howMany = whichTown->creaturesToRecruit[which].first;
  200. for(int i = 0; i < creature->cost.size();i++)
  201. amin(howMany,creature->cost[i]?hgs.resourceAmounts[i]/creature->cost[i]:INT_MAX);
  202. for(int i = 0; creature && i < creature->cost.size();i++)
  203. resourceCosts[i]=creature->cost[i]*howMany;
  204. break;
  205. case upgradeCreatures:
  206. UpgradeInfo ui = AI->m_cb->getUpgradeInfo(whichTown->t,which);
  207. ID = whichTown->creaturesInGarrison.slots[which].first;
  208. howMany = whichTown->creaturesInGarrison.slots[which].second;
  209. newID = ui.newID.back();
  210. int upgrade_serial = ui.newID.size()-1;
  211. for (std::set<std::pair<int,int> >::iterator j=ui.cost[upgrade_serial].begin(); j!=ui.cost[upgrade_serial].end(); j++)
  212. resourceCosts[j->first] = j->second*howMany;
  213. break;
  214. }
  215. _cost = AI->m_priorities->getCost(resourceCosts,NULL,0);
  216. _value = AI->m_priorities->getValue(*this);
  217. return _value-_cost;
  218. }
  219. bool CGeniusAI::TownObjective::operator < (const TownObjective &other)const
  220. {
  221. if(type != other.type)
  222. return type<other.type;
  223. if(which!=other.which)
  224. return which<other.which;
  225. if(whichTown->t->id!=other.whichTown->t->id)
  226. return whichTown->t->id < other.whichTown->t->id;
  227. return false;
  228. }
  229. void CGeniusAI::TownObjective::print() const
  230. {
  231. CBuilding * b;
  232. const CCreature *creature;
  233. HypotheticalGameState::HeroModel hm;
  234. int ID, howMany, newID, hSlot;
  235. switch(type)
  236. {
  237. case recruitHero:
  238. cout << "recruit hero.";break;
  239. case buildBuilding:
  240. b = VLC->buildh->buildings[whichTown->t->subID][which];
  241. cout << "build " << b->Name() << " cost = ";
  242. if(b->resources.size()!=0)
  243. {
  244. if(b->resources[0]!=0)cout << b->resources[0] << " wood. ";
  245. if(b->resources[1]!=0)cout << b->resources[1] << " mercury. ";
  246. if(b->resources[2]!=0)cout << b->resources[2] << " ore. ";
  247. if(b->resources[3]!=0)cout << b->resources[3] << " sulfer. ";
  248. if(b->resources[4]!=0)cout << b->resources[4] << " cristal. ";
  249. if(b->resources[5]!=0)cout << b->resources[5] << " gems. ";
  250. if(b->resources[6]!=0)cout << b->resources[6] << " gold. ";
  251. }
  252. break;
  253. case recruitCreatures:
  254. ID = whichTown->creaturesToRecruit[which].second.back(); //buy upgraded if possible
  255. creature = &VLC->creh->creatures[ID];
  256. howMany = whichTown->creaturesToRecruit[which].first;
  257. for(int i = 0; i < creature->cost.size();i++)
  258. amin(howMany,creature->cost[i]?AI->m_cb->getResourceAmount(i)/creature->cost[i]:INT_MAX);
  259. cout << "recruit " << howMany << " "<< creature->namePl << " (Total AI Strength " << creature->AIValue*howMany << "). cost = ";
  260. if(creature->cost.size()!=0)
  261. {
  262. if(creature->cost[0]!=0)cout << creature->cost[0]*howMany << " wood. ";
  263. if(creature->cost[1]!=0)cout << creature->cost[1]*howMany << " mercury. ";
  264. if(creature->cost[2]!=0)cout << creature->cost[2]*howMany << " ore. ";
  265. if(creature->cost[3]!=0)cout << creature->cost[3]*howMany << " sulfer. ";
  266. if(creature->cost[4]!=0)cout << creature->cost[4]*howMany << " cristal. ";
  267. if(creature->cost[5]!=0)cout << creature->cost[5]*howMany << " gems. ";
  268. if(creature->cost[6]!=0)cout << creature->cost[6]*howMany << " gold. ";
  269. }
  270. break;
  271. case upgradeCreatures:
  272. UpgradeInfo ui = AI->m_cb->getUpgradeInfo(whichTown->t,which);
  273. ID = whichTown->creaturesInGarrison.slots[which].first;
  274. cout << "upgrade " << VLC->creh->creatures[ID].namePl;
  275. //ui.cost
  276. break;
  277. }
  278. }
  279. CGeniusAI::CGeniusAI()
  280. : m_generalAI(), m_state(NO_BATTLE)
  281. {
  282. m_priorities = new Priorities("AI/GeniusAI.brain");
  283. }
  284. CGeniusAI::~CGeniusAI()
  285. {
  286. delete m_priorities;
  287. }
  288. void CGeniusAI::init(ICallback *CB)
  289. {
  290. m_cb = CB;
  291. m_generalAI.init(CB);
  292. human = false;
  293. playerID = m_cb->getMyColor();
  294. serialID = m_cb->getMySerial();
  295. std::string info = std::string("GeniusAI initialized for player ") + boost::lexical_cast<std::string>(playerID);
  296. m_battleLogic = NULL;
  297. DbgBox(info.c_str());
  298. }
  299. void CGeniusAI::reportResources()
  300. {
  301. cout << "Day " << m_cb->getDate() << ": ";
  302. cout << "AI Player " <<m_cb->getMySerial()<< " with " << m_cb->howManyHeroes(true) << " heroes. " << endl;
  303. cout << m_cb->getResourceAmount(0) << " wood. ";
  304. cout << m_cb->getResourceAmount(1) << " mercury. ";
  305. cout << m_cb->getResourceAmount(2) << " ore. ";
  306. cout << m_cb->getResourceAmount(3) << " sulfer. ";
  307. cout << m_cb->getResourceAmount(4) << " cristal. ";
  308. cout << m_cb->getResourceAmount(5) << " gems. ";
  309. cout << m_cb->getResourceAmount(6) << " gold.";
  310. cout << endl;
  311. }
  312. void CGeniusAI::addHeroObjectives(CGeniusAI::HypotheticalGameState::HeroModel &h, CGeniusAI::HypotheticalGameState &hgs)
  313. {
  314. int3 hpos, destination;
  315. CPath path;
  316. hpos = h.pos;
  317. int movement = h.remainingMovement;
  318. int3 interestingPos;
  319. int maxInteresting=0;
  320. AIObjective::Type tp = AIObjective::visit;
  321. if(h.finished) return;
  322. for(std::set<AIObjectContainer>::const_iterator i = hgs.knownVisitableObjects.begin(); i != hgs.knownVisitableObjects.end();i++)
  323. {
  324. tp = AIObjective::visit;
  325. if( h.previouslyVisited_pos==i->o->getSightCenter())
  326. continue;
  327. //TODO: what would the hero actually visit if he went to that spot
  328. // maybe the hero wants to visit a seemingly unguarded enemy town, but there is a hero on top of it.
  329. //if(i->o->)
  330. if(i->o->ID!=HEROI_TYPE) //unless you are trying to visit a hero
  331. {
  332. bool heroThere = false;
  333. for(int ii = 0; ii < hgs.heroModels.size();ii++)
  334. if(hgs.heroModels[ii].pos==i->o->getSightCenter())
  335. heroThere = true;
  336. if(heroThere) //it won't work if there is already someone visiting that spot.
  337. continue;
  338. }
  339. if(i->o->ID==HEROI_TYPE&&i->o->getOwner()==m_cb->getMyColor())//visiting friendly heroes not yet supported
  340. continue;
  341. if(i->o->id==h.h->id) //don't visit yourself (should be caught by above)
  342. continue;
  343. if(i->o->ID==53&&i->o->getOwner()==m_cb->getMyColor())//don't visit a mine if you own, there's almost no point(maybe to leave guards or because the hero's trapped).
  344. continue;
  345. if(i->o->getOwner()!=m_cb->getMyColor())
  346. {
  347. int enemyStrength = 0; //TODO: I feel like the AI shouldn't have access to this information.
  348. // We must get an approximation based on few, many, ... zounds etc.
  349. if(dynamic_cast<const CArmedInstance *> (i->o))
  350. enemyStrength = (dynamic_cast<const CArmedInstance *> (i->o))->getArmyStrength();//TODO: should be virtual maybe, Army strength should be comparable across objects
  351. if(dynamic_cast<const CGHeroInstance *> (i->o))
  352. enemyStrength = (dynamic_cast<const CGHeroInstance *> (i->o))->getTotalStrength();
  353. if(dynamic_cast<const CGTownInstance *> (i->o))
  354. enemyStrength = (dynamic_cast<const CGTownInstance *> (i->o))->getArmyStrength()*1.2;
  355. float heroStrength = h.h->getTotalStrength();
  356. if(enemyStrength*2.5 > heroStrength) //TODO: ballence these numbers using objective cost formula.
  357. continue; // it would be nice to do a battle sim
  358. if(enemyStrength>0)tp = AIObjective::attack;
  359. }
  360. if(dynamic_cast<const CGVisitableOPW *> (i->o)&&dynamic_cast<const CGVisitableOPW *> (i->o)->visited)//don't visit things that have already been visited this week.
  361. continue;
  362. if(dynamic_cast<const CGVisitableOPH *> (i->o)&&vstd::contains(dynamic_cast<const CGVisitableOPH *> (i->o)->visitors,h.h->id))//don't visit things that you have already visited OPH
  363. continue;
  364. if(i->o->ID==88||i->o->ID==89||i->o->ID==90)
  365. {
  366. //TODO: if no spell book continue
  367. //TODO: if the shrine's spell is identified, and the hero already has it, continue
  368. }
  369. destination = i->o->getSightCenter();
  370. if(hpos.z==destination.z) //don't try to take a path from the underworld to the top or vice versa
  371. { //TODO: fix get path so that it doesn't return a path unless z's are the same, or path goes through sub gate
  372. if(m_cb->getPath(hpos,destination,h.h,path))
  373. {
  374. path.convert(0);
  375. if(path.nodes[0].dist<movement)
  376. {
  377. HeroObjective ho(hgs,tp,i->o,&h,this);
  378. std::set<HeroObjective>::iterator found = currentHeroObjectives.find(ho);
  379. if(found==currentHeroObjectives.end())
  380. currentHeroObjectives.insert(ho);
  381. else {
  382. HeroObjective *objective = (HeroObjective *)&(*found);
  383. objective->whoCanAchieve.push_back(&h);
  384. }
  385. }
  386. // find the most interesting object that is eventually reachable, and set that position to the ultimate goal position
  387. int hi = rand(); //TODO: replace random numbers with some sort of ranking system
  388. if(hi>maxInteresting)
  389. {
  390. maxInteresting = hi;
  391. interestingPos = destination;
  392. }
  393. }
  394. }
  395. }
  396. h.interestingPos = interestingPos;
  397. // if(h.remainingMovement>0&&m_cb->getPath(hpos,interestingPos,h.h,path)) // there ought to be a path
  398. currentHeroObjectives.insert(HeroObjective(hgs,HeroObjective::finishTurn,h.h,&h,this));
  399. }
  400. void CGeniusAI::HeroObjective::fulfill(CGeniusAI & cg,HypotheticalGameState & hgs)
  401. {
  402. cg.m_cb->waitTillRealize = true;
  403. HypotheticalGameState::HeroModel * h;
  404. int3 hpos, destination;
  405. CPath path;
  406. CPath path2;
  407. int3 bestPos,currentPos,checkPos;
  408. int howGood;
  409. switch(type)
  410. {
  411. case finishTurn:
  412. h = whoCanAchieve.front();
  413. h->finished=true;
  414. hpos = h->pos;
  415. destination = h->interestingPos;
  416. if(!cg.m_cb->getPath(hpos,destination,h->h,path)) {cout << "AI error: invalid destination" << endl; return;}
  417. destination = h->pos;
  418. for(int i = path.nodes.size()-2;i>=0;i--) //find closest coord that we can get to
  419. if(cg.m_cb->getPath(hpos,path.nodes[i].coord,h->h,path2)&&path2.nodes[0].dist<=h->remainingMovement)
  420. destination = path.nodes[i].coord;
  421. if(destination == h->interestingPos) break;
  422. ///////// Find close pos with the most neighboring empty squares. We don't want to get in the way. ///////////////////
  423. bestPos = destination;
  424. howGood=0;
  425. for(int x = -3;x <= 3;x++)
  426. for(int y = -3;y <= 3;y++)
  427. {
  428. currentPos=destination+int3(x,y,0);
  429. if(cg.m_cb->getVisitableObjs(currentPos).size()!=0) //there better not be anything there
  430. continue;
  431. if(!cg.m_cb->getPath(hpos,currentPos,h->h,path)||path.nodes[0].dist>h->remainingMovement) //it better be reachable from the hero
  432. continue;
  433. int count = 0;
  434. for(int xx = -1;xx <= 1;xx++)
  435. for(int yy = -1;yy <= 1;yy++)
  436. {
  437. checkPos = currentPos+int3(xx,yy,0);
  438. if(cg.m_cb->getPath(currentPos,checkPos,h->h,path))
  439. count++;
  440. }
  441. if(count > howGood)
  442. {
  443. howGood = count;
  444. bestPos = currentPos;
  445. }
  446. }
  447. destination = bestPos;
  448. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  449. cg.m_cb->getPath(hpos,destination,h->h,path);
  450. path.convert(0);
  451. break;
  452. case visit:case attack:
  453. h = whoCanAchieve.front(); //lowest cost hero
  454. h->previouslyVisited_pos=object->getSightCenter();
  455. hpos = h->pos;
  456. destination = object->getSightCenter();
  457. break;
  458. }
  459. if(type == visit||type == finishTurn||type == attack)
  460. if(cg.m_cb->getPath(hpos,destination,h->h,path))
  461. {
  462. path.convert(0);
  463. if(cg.m_state.get() != NO_BATTLE)
  464. cg.m_state.waitUntil(NO_BATTLE);//wait for battle end
  465. //wait over, battle over too. hero might be killed. check.
  466. for(int i = path.nodes.size()-2;i>=0&&(cg.m_cb->getHeroSerial(h->h) >= 0);i--)
  467. {
  468. cg.m_cb->moveHero(h->h,path.nodes[i].coord);
  469. if(cg.m_state.get() != NO_BATTLE)
  470. cg.m_state.waitUntil(NO_BATTLE);//wait for battle end
  471. }
  472. h->remainingMovement-=path.nodes[0].dist;
  473. if(object->blockVisit)
  474. h->pos = path.nodes[1].coord;
  475. else
  476. h->pos=destination;
  477. std::set<AIObjectContainer>::iterator i = hgs.knownVisitableObjects.find(AIObjectContainer(object));
  478. if(i!=hgs.knownVisitableObjects.end())
  479. hgs.knownVisitableObjects.erase(i);
  480. }
  481. const CGTownInstance * town = dynamic_cast<const CGTownInstance *> (object);
  482. if(town&&object->getOwner()==cg.m_cb->getMyColor())
  483. {
  484. //upgrade hero's units
  485. cout << "visiting town" << endl;
  486. CCreatureSet hcreatures = h->h->army;
  487. for(std::map<si32,std::pair<ui32,si32> >::const_iterator i = hcreatures.slots.begin();i!=hcreatures.slots.end();i++) // for each hero slot
  488. {
  489. UpgradeInfo ui = cg.m_cb->getUpgradeInfo(h->h,i->first);
  490. bool canUpgrade = false;
  491. if(ui.newID.size()!=0) //does this stack need upgrading?
  492. {
  493. canUpgrade = true;
  494. for(int ii=0;ii<ui.cost.size();ii++)//can afford the upgrade?
  495. for (std::set<std::pair<int,int> >::iterator j=ui.cost[ii].begin(); j!=ui.cost[ii].end(); j++)
  496. if(hgs.resourceAmounts[j->first] < j->second*i->second.second)
  497. canUpgrade = false;
  498. }
  499. if(canUpgrade)
  500. {
  501. cg.m_cb->upgradeCreature(h->h,i->first,ui.newID.back());
  502. cout << "upgrading hero's " << VLC->creh->creatures[i->second.first].namePl << endl;
  503. }
  504. }
  505. //give town's units to hero
  506. CCreatureSet tcreatures = town->army;
  507. int weakestCreatureStack;
  508. int weakestCreatureAIValue=99999;
  509. for(std::map<si32,std::pair<ui32,si32> >::const_iterator i = tcreatures.slots.begin();i!=tcreatures.slots.end();i++)
  510. if(VLC->creh->creatures[i->second.first].AIValue<weakestCreatureAIValue)
  511. {
  512. weakestCreatureAIValue = VLC->creh->creatures[i->second.first].AIValue;
  513. weakestCreatureStack = i->first;
  514. }
  515. for(std::map<si32,std::pair<ui32,si32> >::const_iterator i = tcreatures.slots.begin();i!=tcreatures.slots.end();i++) // for each town slot
  516. {
  517. hcreatures = h->h->army;
  518. int hSlot = hcreatures.getSlotFor(i->second.first);
  519. if(hSlot == -1) continue;
  520. cout << "giving hero " << VLC->creh->creatures[i->second.first].namePl << endl;
  521. if(hcreatures.slots.find(hSlot)!=hcreatures.slots.end())
  522. {
  523. if(i->first==weakestCreatureStack&&town->garrisonHero!=NULL)//can't take garrisonHero's last unit
  524. cg.m_cb->splitStack(town,h->h,i->first,hSlot,i->second.second-1);
  525. else
  526. cg.m_cb->mergeStacks(town,h->h,i->first,hSlot); //TODO: the comment says that this code is not safe for the AI.
  527. }
  528. else
  529. {
  530. cg.m_cb->swapCreatures(town,h->h,i->first,hSlot);
  531. }
  532. }
  533. }
  534. }
  535. void CGeniusAI::addTownObjectives(HypotheticalGameState::TownModel &t, HypotheticalGameState & hgs)
  536. {
  537. //recruitHero
  538. //buildBuilding
  539. //recruitCreatures
  540. //upgradeCreatures
  541. if(hgs.heroModels.size()<3&&hgs.resourceAmounts[6]>=2500) //recruitHero
  542. {
  543. bool heroAtTown = false;
  544. for(int i = 0; i < hgs.heroModels.size();i++)
  545. if(hgs.heroModels[i].pos==t.t->getSightCenter())
  546. heroAtTown = true;
  547. if(!heroAtTown && vstd::contains(t.t->builtBuildings, 5)) //no visiting hero and built tavern
  548. {
  549. for(int i =0; i < hgs.AvailableHeroesToBuy.size();i++)
  550. if(hgs.AvailableHeroesToBuy[i]!=NULL&&(t.t->subID==(hgs.AvailableHeroesToBuy[i]->type->heroType/2)))
  551. {
  552. TownObjective to(hgs,AIObjective::recruitHero,&t,0,this);
  553. currentTownObjectives.insert(to);
  554. }
  555. }
  556. }
  557. //buildBuilding
  558. if(!t.hasBuilt)
  559. {
  560. std::map<int, CBuilding *> thisTownsBuildings = VLC->buildh->buildings[t.t->subID];// m_cb->getCBuildingsByID(t.t);
  561. for(std::map<int, CBuilding *>::iterator i = thisTownsBuildings.begin(); i != thisTownsBuildings.end();i++)
  562. {
  563. if(m_cb->canBuildStructure(t.t,i->first)==7)
  564. {
  565. TownObjective to(hgs,AIObjective::buildBuilding,&t,i->first,this);
  566. currentTownObjectives.insert(to);
  567. }
  568. }
  569. }
  570. //recruitCreatures
  571. for(int i = 0; i < t.creaturesToRecruit.size() ;i++)
  572. {
  573. if(t.creaturesToRecruit[i].first==0||t.creaturesToRecruit[i].second.empty()) continue;
  574. int ID = t.creaturesToRecruit[i].second.back();
  575. const CCreature *creature = &VLC->creh->creatures[ID];//m_cb->getCCreatureByID(ID);
  576. bool canAfford = true;
  577. for(int ii = 0;ii<creature->cost.size();ii++)
  578. if(creature->cost[ii]>hgs.resourceAmounts[ii])
  579. canAfford = false; // can we afford at least one creature?
  580. if(!canAfford) continue;
  581. //cout << "town has " << t.t->creatures[i].first << " "<< creature->namePl << " (AI Strength " << creature->AIValue << ")." << endl;
  582. TownObjective to(hgs,AIObjective::recruitCreatures,&t,i,this);
  583. currentTownObjectives.insert(to);
  584. }
  585. //upgradeCreatures
  586. for(std::map<si32,std::pair<ui32,si32> >::iterator i = t.creaturesInGarrison.slots.begin();i!=t.creaturesInGarrison.slots.end();i++)
  587. {
  588. UpgradeInfo ui = m_cb->getUpgradeInfo(t.t,i->first);
  589. if(ui.newID.size()!=0)
  590. {
  591. bool canAfford = true;
  592. int upgrade_serial = ui.newID.size()-1;
  593. for (std::set<std::pair<int,int> >::iterator j=ui.cost[upgrade_serial].begin(); j!=ui.cost[upgrade_serial].end(); j++)
  594. if(hgs.resourceAmounts[j->first] < j->second*i->second.second)
  595. canAfford = false;
  596. if(canAfford)
  597. {
  598. TownObjective to(hgs,AIObjective::upgradeCreatures,&t,i->first,this);
  599. currentTownObjectives.insert(to);
  600. }
  601. }
  602. }
  603. }
  604. void CGeniusAI::TownObjective::fulfill(CGeniusAI & cg,HypotheticalGameState &hgs)
  605. {
  606. cg.m_cb->waitTillRealize = true;
  607. CBuilding * b;
  608. const CCreature *creature;
  609. HypotheticalGameState::HeroModel hm;
  610. int ID, howMany, newID, hSlot;
  611. switch(type)
  612. {
  613. case recruitHero:
  614. cg.m_cb->recruitHero(whichTown->t,hgs.AvailableHeroesToBuy[which]);
  615. hm = HypotheticalGameState::HeroModel(hgs.AvailableHeroesToBuy[which]);
  616. hm.pos = whichTown->t->getSightCenter();
  617. hm.remainingMovement = hm.h->maxMovePoints(true);
  618. hgs.heroModels.push_back(hm);
  619. hgs.resourceAmounts[6]-=2500;
  620. break;
  621. case buildBuilding:
  622. b = VLC->buildh->buildings[whichTown->t->subID][which];
  623. if(cg.m_cb->canBuildStructure(whichTown->t,which)==7)
  624. {
  625. cout << "built " << b->Name() << "." << endl;
  626. if(!cg.m_cb->buildBuilding(whichTown->t,which)) cout << "really tried to build unbuildable building" <<endl;
  627. for(int i = 0; b && i < b->resources.size();i++)
  628. hgs.resourceAmounts[i]-=b->resources[i];
  629. }
  630. else cout << "trying to build a structure we cannot build" << endl;
  631. whichTown->hasBuilt=true;
  632. break;
  633. case recruitCreatures:
  634. ID = whichTown->creaturesToRecruit[which].second.back(); //buy upgraded if possible
  635. creature = &VLC->creh->creatures[ID];
  636. howMany = whichTown->creaturesToRecruit[which].first;
  637. for(int i = 0; i < creature->cost.size();i++)
  638. amin(howMany,creature->cost[i]?hgs.resourceAmounts[i]/creature->cost[i]:INT_MAX);
  639. if(howMany == 0) cout << "tried to recruit without enough money.";
  640. cout << "recruiting " << howMany << " "<< creature->namePl << " (Total AI Strength " << creature->AIValue*howMany << ")." << endl;
  641. cg.m_cb->recruitCreatures(whichTown->t,ID,howMany);
  642. break;
  643. case upgradeCreatures:
  644. UpgradeInfo ui = cg.m_cb->getUpgradeInfo(whichTown->t,which);
  645. ID = whichTown->creaturesInGarrison.slots[which].first;
  646. newID = ui.newID.back();
  647. cg.m_cb->upgradeCreature(whichTown->t,which,newID);//TODO: reduce resources in hgs
  648. cout << "upgrading " << VLC->creh->creatures[ID].namePl << endl;
  649. break;
  650. }
  651. }
  652. void CGeniusAI::fillObjectiveQueue(HypotheticalGameState & hgs)
  653. {
  654. objectiveQueue.clear();
  655. currentHeroObjectives.clear();
  656. currentTownObjectives.clear();
  657. for(std::vector <CGeniusAI::HypotheticalGameState::HeroModel>::iterator i = hgs.heroModels.begin(); i != hgs.heroModels.end(); i++)
  658. addHeroObjectives(*i,hgs);
  659. for(std::vector <CGeniusAI::HypotheticalGameState::TownModel>::iterator i = hgs.townModels.begin(); i != hgs.townModels.end(); i++)
  660. addTownObjectives(*i,hgs);
  661. for(std::set<CGeniusAI::HeroObjective>::iterator i = currentHeroObjectives.begin(); i != currentHeroObjectives.end(); i++)
  662. objectiveQueue.push_back(AIObjectivePtrCont((CGeniusAI::HeroObjective *)&(*i)));
  663. for(std::set<CGeniusAI::TownObjective>::iterator i = currentTownObjectives.begin(); i != currentTownObjectives.end(); i++)
  664. objectiveQueue.push_back(AIObjectivePtrCont((CGeniusAI::TownObjective *)&(*i)));
  665. }
  666. CGeniusAI::AIObjective * CGeniusAI::getBestObjective()
  667. {
  668. trueGameState.update(*this);
  669. fillObjectiveQueue(trueGameState);
  670. // if(!objectiveQueue.empty())
  671. // return max_element(objectiveQueue.begin(),objectiveQueue.end())->obj;
  672. m_priorities->fillFeatures(trueGameState);
  673. if(objectiveQueue.empty()) return NULL;
  674. // sort(objectiveQueue.begin(),objectiveQueue.end());
  675. // reverse(objectiveQueue.begin(),objectiveQueue.end());
  676. int num= 1;
  677. // for(std::vector<AIObjectivePtrCont> ::iterator i = objectiveQueue.begin(); i < objectiveQueue.end();i++)
  678. // {
  679. // if(!dynamic_cast<HeroObjective*>(i->obj))continue;
  680. // cout << num++ << ": ";
  681. // i->obj->print();
  682. // cout << " value: " << i->obj->getValue();
  683. // cout << endl;
  684. // }
  685. // int choice = 0;
  686. // cout << "which would you do? (enter 0 for none): ";
  687. // cin >> choice;
  688. cout << "doing best of " << objectiveQueue.size() << " ";
  689. CGeniusAI::AIObjective* best = max_element(objectiveQueue.begin(),objectiveQueue.end())->obj;
  690. best->print();
  691. cout << " value = " << best->getValue() << endl;
  692. if(!objectiveQueue.empty())
  693. return best;
  694. return objectiveQueue.front().obj;
  695. }
  696. void CGeniusAI::yourTurn()
  697. {
  698. static boost::mutex mutex;
  699. boost::mutex::scoped_lock lock(mutex);
  700. m_cb->waitTillRealize = true;
  701. static int seed = rand();
  702. srand(seed);
  703. if(m_cb->getDate()==1)
  704. {
  705. // startFirstTurn();
  706. // m_cb->endTurn();
  707. // return;
  708. }
  709. //////////////TODO: replace with updates. Also add suspected objects list./////////
  710. knownVisitableObjects.clear();
  711. int3 pos = m_cb->getMapSize();
  712. for(int x = 0;x<pos.x;x++)
  713. for(int y = 0;y<pos.y;y++)
  714. for(int z = 0;z<pos.z;z++)
  715. tileRevealed(int3(x,y,z));
  716. ///////////////////////////////////////////////////////////////////////////////////
  717. reportResources();
  718. trueGameState = HypotheticalGameState(*this);
  719. AIObjective * objective;
  720. while((objective = getBestObjective())!=NULL)
  721. objective->fulfill(*this,trueGameState);
  722. seed = rand();
  723. m_cb->endTurn();
  724. m_cb->waitTillRealize = false;
  725. }
  726. /*
  727. void CGeniusAI::startFirstTurn()
  728. {
  729. HypotheticalGameState hgs(*this);
  730. const CGTownInstance * town = m_cb->getTownInfo(0,0);
  731. const CGHeroInstance * heroInst = m_cb->getHeroInfo(0,0);
  732. TownObjective(hgs,AIObjective::recruitHero,&hgs.townModels.front(),0,this).fulfill(*this,hgs);
  733. m_cb->swapGarrisonHero(town);
  734. hgs.update(*this);
  735. for(int i = 0; i < hgs.townModels.front().creaturesToRecruit.size() ;i++)
  736. {
  737. if(hgs.townModels.front().creaturesToRecruit[i].first==0) continue;
  738. int ID = hgs.townModels.front().creaturesToRecruit[i].second.back();
  739. const CCreature *creature = &VLC->creh->creatures[ID];
  740. bool canAfford = true;
  741. for(int ii = 0;ii<creature->cost.size();ii++)
  742. if(creature->cost[ii]>hgs.resourceAmounts[ii])
  743. canAfford = false; // can we afford at least one creature?
  744. if(!canAfford) continue;
  745. TownObjective(hgs,AIObjective::recruitCreatures,&hgs.townModels.front(),i,this).fulfill(*this,hgs);
  746. }
  747. hgs.update(*this);
  748. HypotheticalGameState::HeroModel *hero;
  749. for(int i = 0; i < hgs.heroModels.size();i++)
  750. if(hgs.heroModels[i].h->id==heroInst->id)
  751. HeroObjective(hgs,AIObjective::visit,town,hero=&hgs.heroModels[i],this).fulfill(*this,hgs);
  752. hgs.update(*this);
  753. // m_cb->swapGarrisonHero(town);
  754. //TODO: choose the strongest hero.
  755. }
  756. */
  757. void CGeniusAI::heroKilled(const CGHeroInstance * hero)
  758. {
  759. }
  760. void CGeniusAI::heroCreated(const CGHeroInstance *hero)
  761. {
  762. }
  763. void CGeniusAI::tileRevealed(int3 pos)
  764. {
  765. std::vector < const CGObjectInstance * > objects = m_cb->getVisitableObjs(pos);
  766. for(std::vector < const CGObjectInstance * >::iterator o = objects.begin();o!=objects.end();o++)
  767. if((*o)->id!=-1)
  768. knownVisitableObjects.insert(*o);
  769. objects = m_cb->getFlaggableObjects(pos);
  770. for(std::vector < const CGObjectInstance * >::iterator o = objects.begin();o!=objects.end();o++)
  771. if((*o)->id!=-1)
  772. knownVisitableObjects.insert(*o);
  773. }
  774. void CGeniusAI::newObject(const CGObjectInstance * obj) //eg. ship built in shipyard
  775. {
  776. knownVisitableObjects.insert(obj);
  777. }
  778. void CGeniusAI::objectRemoved(const CGObjectInstance *obj) //eg. collected resource, picked artifact, beaten hero
  779. {
  780. std::set <AIObjectContainer>::iterator o = knownVisitableObjects.find(obj);
  781. if(o!=knownVisitableObjects.end())
  782. knownVisitableObjects.erase(o);
  783. }
  784. void CGeniusAI::tileHidden(int3 pos)
  785. {
  786. }
  787. void CGeniusAI::heroMoved(const TryMoveHero &TMH)
  788. {
  789. //DbgBox("** CGeniusAI::heroMoved **");
  790. }
  791. void CGeniusAI::heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback)
  792. {
  793. callback(rand() % skills.size());
  794. }
  795. void GeniusAI::CGeniusAI::showGarrisonDialog( const CArmedInstance *up, const CGHeroInstance *down, boost::function<void()> &onEnd )
  796. {
  797. onEnd();
  798. }
  799. void GeniusAI::CGeniusAI::playerBlocked( int reason )
  800. {
  801. if(reason == 0) //battle is coming...
  802. {
  803. m_state.setn(UPCOMING_BATTLE);
  804. }
  805. }
  806. void GeniusAI::CGeniusAI::battleResultsApplied()
  807. {
  808. assert(m_state.get() == ENDING_BATTLE);
  809. m_state.setn(NO_BATTLE);
  810. }
  811. void CGeniusAI::showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, const int soundID, bool selection, bool cancel)
  812. {
  813. m_cb->selectionMade(cancel ? 0 : 1, askID);
  814. }
  815. /**
  816. * occurs AFTER every action taken by any stack or by the hero
  817. */
  818. void CGeniusAI::actionFinished(const BattleAction *action)
  819. {
  820. std::string message("\t\tCGeniusAI::actionFinished - type(");
  821. message += boost::lexical_cast<std::string>((unsigned)action->actionType);
  822. message += "), side(";
  823. message += boost::lexical_cast<std::string>((unsigned)action->side);
  824. message += ")";
  825. DbgBox(message.c_str());
  826. }
  827. /**
  828. * occurs BEFORE every action taken by any stack or by the hero
  829. */
  830. void CGeniusAI::actionStarted(const BattleAction *action)
  831. {
  832. std::string message("\t\tCGeniusAI::actionStarted - type(");
  833. message += boost::lexical_cast<std::string>((unsigned)action->actionType);
  834. message += "), side(";
  835. message += boost::lexical_cast<std::string>((unsigned)action->side);
  836. message += ")";
  837. DbgBox(message.c_str());
  838. }
  839. /**
  840. * called when stack is performing attack
  841. */
  842. void CGeniusAI::battleAttack(BattleAttack *ba)
  843. {
  844. DbgBox("\t\t\tCGeniusAI::battleAttack");
  845. }
  846. /**
  847. * called when stack receives damage (after battleAttack())
  848. */
  849. void CGeniusAI::battleStacksAttacked(std::set<BattleStackAttacked> & bsa)
  850. {
  851. DbgBox("\t\t\tCGeniusAI::battleStacksAttacked");
  852. }
  853. /**
  854. * called by engine when battle starts; side=0 - left, side=1 - right
  855. */
  856. void CGeniusAI::battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side)
  857. {
  858. assert(!m_battleLogic);
  859. assert(playerID > PLAYER_LIMIT || m_state.get() == UPCOMING_BATTLE); //we have been informed that battle will start (or we are neutral AI)
  860. m_state.setn(ONGOING_BATTLE);
  861. m_battleLogic = new BattleAI::CBattleLogic(m_cb, army1, army2, tile, hero1, hero2, side);
  862. DbgBox("** CGeniusAI::battleStart **");
  863. }
  864. /**
  865. *
  866. */
  867. void CGeniusAI::battleEnd(BattleResult *br)
  868. {
  869. switch(br->winner)
  870. {
  871. case 0: std::cout << "The winner is the attacker." << std::endl;break;
  872. case 1: std::cout << "The winner is the defender." << std::endl;break;
  873. case 2: std::cout << "It's a draw." << std::endl;break;
  874. };
  875. cout << "lost ";
  876. for(std::set<std::pair<ui32,si32> >::iterator i = br->casualties[0].begin(); i !=br->casualties[0].end();i++)
  877. cout << i->second << " " << VLC->creh->creatures[i->first].namePl << endl;
  878. delete m_battleLogic;
  879. m_battleLogic = NULL;
  880. assert(m_state.get() == ONGOING_BATTLE);
  881. m_state.setn(ENDING_BATTLE);
  882. DbgBox("** CGeniusAI::battleEnd **");
  883. }
  884. /**
  885. * called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
  886. */
  887. void CGeniusAI::battleNewRound(int round)
  888. {
  889. std::string message("\tCGeniusAI::battleNewRound - ");
  890. message += boost::lexical_cast<std::string>(round);
  891. DbgBox(message.c_str());
  892. m_battleLogic->SetCurrentTurn(round);
  893. }
  894. /**
  895. *
  896. */
  897. void CGeniusAI::battleStackMoved(int ID, int dest, int distance, bool end)
  898. {
  899. std::string message("\t\t\tCGeniusAI::battleStackMoved ID(");
  900. message += boost::lexical_cast<std::string>(ID);
  901. message += "), dest(";
  902. message += boost::lexical_cast<std::string>(dest);
  903. message += ")";
  904. DbgBox(message.c_str());
  905. }
  906. /**
  907. *
  908. */
  909. void CGeniusAI::battleSpellCast(SpellCast *sc)
  910. {
  911. DbgBox("\t\t\tCGeniusAI::battleSpellCast");
  912. }
  913. /**
  914. * called when battlefield is prepared, prior the battle beginning
  915. */
  916. void CGeniusAI::battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles)
  917. {
  918. DbgBox("CGeniusAI::battlefieldPrepared");
  919. }
  920. /**
  921. *
  922. */
  923. void CGeniusAI::battleStackMoved(int ID, int dest, bool startMoving, bool endMoving)
  924. {
  925. DbgBox("\t\t\tCGeniusAI::battleStackMoved");
  926. }
  927. /**
  928. *
  929. */
  930. void CGeniusAI::battleStackAttacking(int ID, int dest)
  931. {
  932. DbgBox("\t\t\tCGeniusAI::battleStackAttacking");
  933. }
  934. /**
  935. *
  936. */
  937. void CGeniusAI::battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting)
  938. {
  939. DbgBox("\t\t\tCGeniusAI::battleStackIsAttacked");
  940. }
  941. /**
  942. * called when it's turn of that stack
  943. */
  944. BattleAction CGeniusAI::activeStack(int stackID)
  945. {
  946. std::string message("\t\t\tCGeniusAI::activeStack stackID(");
  947. message += boost::lexical_cast<std::string>(stackID);
  948. message += ")";
  949. DbgBox(message.c_str());
  950. return m_battleLogic->MakeDecision(stackID);
  951. };