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