CBattleInterface.cpp 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198
  1. #include "CBattleInterface.h"
  2. #include "CGameInfo.h"
  3. #include "hch/CLodHandler.h"
  4. #include "SDL_Extensions.h"
  5. #include "CAdvmapInterface.h"
  6. #include "AdventureMapButton.h"
  7. #include "hch/CObjectHandler.h"
  8. #include "hch/CHeroHandler.h"
  9. #include "hch/CDefHandler.h"
  10. #include "CCursorHandler.h"
  11. #include "CCallback.h"
  12. #include "CGameState.h"
  13. #include "hch/CGeneralTextHandler.h"
  14. #include "hch/CPreGameTextHandler.h"
  15. #include "client/CCreatureAnimation.h"
  16. #include "client/Graphics.h"
  17. #include "client/CSpellWindow.h"
  18. #include <queue>
  19. #include <sstream>
  20. #include "lib/CondSh.h"
  21. #include "lib/NetPacks.h"
  22. #include <boost/assign/list_of.hpp>
  23. #ifndef __GNUC__
  24. const double M_PI = 3.14159265358979323846;
  25. #else
  26. #define _USE_MATH_DEFINES
  27. #include <cmath>
  28. #endif
  29. extern SDL_Surface * screen;
  30. extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16;
  31. extern SDL_Color zwykly;
  32. class CMP_stack2
  33. {
  34. public:
  35. bool operator ()(const CStack& a, const CStack& b)
  36. {
  37. return (a.creature->speed)>(b.creature->speed);
  38. }
  39. } cmpst2 ;
  40. CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2)
  41. : printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL), attackingInfo(NULL), myTurn(false), resWindow(NULL), showStackQueue(false), animSpeed(2), printStackRange(true), printMouseShadow(true), spellDestSelectMode(false), spellToCast(NULL)
  42. {
  43. strongInterest = true;
  44. givenCommand = new CondSh<BattleAction *>(NULL);
  45. //initializing armies
  46. this->army1 = army1;
  47. this->army2 = army2;
  48. std::map<int, CStack> stacks = LOCPLINT->cb->battleGetStacks();
  49. for(std::map<int, CStack>::iterator b=stacks.begin(); b!=stacks.end(); ++b)
  50. {
  51. std::pair <int, int> coords = CBattleHex::getXYUnitAnim(b->second.position, b->second.owner == attackingHeroInstance->tempOwner, b->second.creature);
  52. creAnims[b->second.ID] = (new CCreatureAnimation(b->second.creature->animDefName));
  53. creAnims[b->second.ID]->setType(2);
  54. creAnims[b->second.ID]->pos = genRect(creAnims[b->second.ID]->fullHeight, creAnims[b->second.ID]->fullWidth, coords.first, coords.second);
  55. creDir[b->second.ID] = b->second.owner==attackingHeroInstance->tempOwner;
  56. }
  57. //preparing menu background and terrain
  58. std::vector< std::string > & backref = graphics->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ];
  59. background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()] );
  60. menu = BitmapHandler::loadBitmap("CBAR.BMP");
  61. graphics->blueToPlayersAdv(menu, hero1->tempOwner);
  62. //preparing graphics for displaying amounts of creatures
  63. amountBasic = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
  64. amountNormal = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
  65. CSDL_Ext::alphaTransform(amountNormal);
  66. for(int g=0; g<amountNormal->format->palette->ncolors; ++g)
  67. {
  68. if((amountNormal->format->palette->colors+g)->b != 132 &&
  69. (amountNormal->format->palette->colors+g)->g != 231 &&
  70. (amountNormal->format->palette->colors+g)->r != 255) //it's not yellow border
  71. {
  72. (amountNormal->format->palette->colors+g)->r = (float)((amountNormal->format->palette->colors+g)->r) * 0.54f;
  73. (amountNormal->format->palette->colors+g)->g = (float)((amountNormal->format->palette->colors+g)->g) * 0.19f;
  74. (amountNormal->format->palette->colors+g)->b = (float)((amountNormal->format->palette->colors+g)->b) * 0.93f;
  75. }
  76. }
  77. ////blitting menu background and terrain
  78. blitAt(background, 0, 0);
  79. blitAt(menu, 0, 556);
  80. CSDL_Ext::update();
  81. //preparing buttons and console
  82. bOptions = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bOptionsf,this), 3, 561, "icm003.def", SDLK_o);
  83. bSurrender = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSurrenderf,this), 54, 561, "icm001.def", SDLK_s);
  84. bFlee = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bFleef,this), 105, 561, "icm002.def", SDLK_r);
  85. bAutofight = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bAutofightf,this), 157, 561, "icm004.def", SDLK_a);
  86. bSpell = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSpellf,this), 645, 561, "icm005.def", SDLK_c);
  87. bWait = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bWaitf,this), 696, 561, "icm006.def", SDLK_w);
  88. bDefence = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bDefencef,this), 747, 561, "icm007.def", SDLK_d);
  89. bDefence->assignedKeys.insert(SDLK_SPACE);
  90. bConsoleUp = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleUpf,this), 624, 561, "ComSlide.def", SDLK_UP);
  91. bConsoleDown = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleDownf,this), 624, 580, "ComSlide.def", SDLK_DOWN);
  92. bConsoleDown->bitmapOffset = 2;
  93. console = new CBattleConsole();
  94. console->pos.x = 211;
  95. console->pos.y = 560;
  96. console->pos.w = 406;
  97. console->pos.h = 38;
  98. //loading hero animations
  99. if(hero1) // attacking hero
  100. {
  101. attackingHero = new CBattleHero(graphics->battleHeroes[hero1->type->heroType], 0, 0, false, hero1->tempOwner, hero1->tempOwner == LOCPLINT->playerID ? hero1 : NULL, this);
  102. attackingHero->pos = genRect(attackingHero->dh->ourImages[0].bitmap->h, attackingHero->dh->ourImages[0].bitmap->w, -40, 0);
  103. }
  104. else
  105. {
  106. attackingHero = NULL;
  107. }
  108. if(hero2) // defending hero
  109. {
  110. defendingHero = new CBattleHero(graphics->battleHeroes[hero2->type->heroType], 0, 0, true, hero2->tempOwner, hero2->tempOwner == LOCPLINT->playerID ? hero2 : NULL, this);
  111. defendingHero->pos = genRect(defendingHero->dh->ourImages[0].bitmap->h, defendingHero->dh->ourImages[0].bitmap->w, 690, 0);
  112. }
  113. else
  114. {
  115. defendingHero = NULL;
  116. }
  117. //preparing cells and hexes
  118. cellBorder = BitmapHandler::loadBitmap("CCELLGRD.BMP");
  119. CSDL_Ext::alphaTransform(cellBorder);
  120. cellShade = BitmapHandler::loadBitmap("CCELLSHD.BMP");
  121. CSDL_Ext::alphaTransform(cellShade);
  122. for(int h=0; h<187; ++h)
  123. {
  124. bfield[h].myNumber = h;
  125. int x = 14 + ((h/17)%2==0 ? 22 : 0) + 44*(h%17);
  126. int y = 86 + 42 * (h/17);
  127. bfield[h].pos = genRect(cellShade->h, cellShade->w, x, y);
  128. bfield[h].accesible = true;
  129. bfield[h].myInterface = this;
  130. }
  131. //locking occupied positions on batlefield
  132. for(std::map<int, CStack>::iterator it = stacks.begin(); it!=stacks.end(); ++it) //stacks gained at top of this function
  133. {
  134. bfield[it->second.position].accesible = false;
  135. }
  136. //loading projectiles for units
  137. for(std::map<int, CStack>::iterator g = stacks.begin(); g != stacks.end(); ++g)
  138. {
  139. if(g->second.creature->isShooting() && CGI->creh->idToProjectile[g->second.creature->idNumber] != std::string())
  140. {
  141. idToProjectile[g->second.creature->idNumber] = CDefHandler::giveDef(CGI->creh->idToProjectile[g->second.creature->idNumber]);
  142. if(idToProjectile[g->second.creature->idNumber]->ourImages.size() > 2) //add symmetric images
  143. {
  144. for(int k = idToProjectile[g->second.creature->idNumber]->ourImages.size()-2; k > 1; --k)
  145. {
  146. Cimage ci;
  147. ci.bitmap = CSDL_Ext::rotate01(idToProjectile[g->second.creature->idNumber]->ourImages[k].bitmap);
  148. ci.groupNumber = 0;
  149. ci.imName = std::string();
  150. idToProjectile[g->second.creature->idNumber]->ourImages.push_back(ci);
  151. }
  152. }
  153. for(int s=0; s<idToProjectile[g->second.creature->idNumber]->ourImages.size(); ++s) //alpha transforming
  154. {
  155. CSDL_Ext::alphaTransform(idToProjectile[g->second.creature->idNumber]->ourImages[s].bitmap);
  156. }
  157. }
  158. }
  159. //prepairing graphic with cell borders
  160. cellBorders = CSDL_Ext::newSurface(background->w, background->h, cellBorder);
  161. //copying palette
  162. for(int g=0; g<cellBorder->format->palette->ncolors; ++g) //we assume that cellBorders->format->palette->ncolors == 256
  163. {
  164. cellBorders->format->palette->colors[g] = cellBorder->format->palette->colors[g];
  165. }
  166. //palette copied
  167. for(int i=0; i<11; ++i) //rows
  168. {
  169. for(int j=0; j<15; ++j) //columns
  170. {
  171. int x = 58 + (i%2==0 ? 22 : 0) + 44*j;
  172. int y = 86 + 42 * i;
  173. for(int cellX = 0; cellX < cellBorder->w; ++cellX)
  174. {
  175. for(int cellY = 0; cellY < cellBorder->h; ++cellY)
  176. {
  177. if(y+cellY < cellBorders->h && x+cellX < cellBorders->w)
  178. * ((Uint8*)cellBorders->pixels + (y+cellY) * cellBorders->pitch + (x+cellX)) |= * ((Uint8*)cellBorder->pixels + cellY * cellBorder->pitch + cellX);
  179. }
  180. }
  181. }
  182. }
  183. backgroundWithHexes = CSDL_Ext::newSurface(background->w, background->h, screen);
  184. }
  185. CBattleInterface::~CBattleInterface()
  186. {
  187. SDL_FreeSurface(background);
  188. SDL_FreeSurface(menu);
  189. SDL_FreeSurface(amountBasic);
  190. SDL_FreeSurface(amountNormal);
  191. SDL_FreeSurface(cellBorders);
  192. SDL_FreeSurface(backgroundWithHexes);
  193. delete bOptions;
  194. delete bSurrender;
  195. delete bFlee;
  196. delete bAutofight;
  197. delete bSpell;
  198. delete bWait;
  199. delete bDefence;
  200. delete bConsoleUp;
  201. delete bConsoleDown;
  202. delete console;
  203. delete resWindow;
  204. delete givenCommand;
  205. delete attackingHero;
  206. delete defendingHero;
  207. SDL_FreeSurface(cellBorder);
  208. SDL_FreeSurface(cellShade);
  209. for(std::map< int, CCreatureAnimation * >::iterator g=creAnims.begin(); g!=creAnims.end(); ++g)
  210. delete g->second;
  211. for(std::map< int, CDefHandler * >::iterator g=idToProjectile.begin(); g!=idToProjectile.end(); ++g)
  212. delete g->second;
  213. }
  214. void CBattleInterface::setPrintCellBorders(bool set)
  215. {
  216. printCellBorders = set;
  217. redrawBackgroundWithHexes(activeStack);
  218. }
  219. void CBattleInterface::setPrintStackRange(bool set)
  220. {
  221. printStackRange = set;
  222. redrawBackgroundWithHexes(activeStack);
  223. }
  224. void CBattleInterface::setPrintMouseShadow(bool set)
  225. {
  226. printMouseShadow = set;
  227. }
  228. void CBattleInterface::activate()
  229. {
  230. KeyInterested::activate();
  231. MotionInterested::activate();
  232. subInt = NULL;
  233. bOptions->activate();
  234. bSurrender->activate();
  235. bFlee->activate();
  236. bAutofight->activate();
  237. bSpell->activate();
  238. bWait->activate();
  239. bDefence->activate();
  240. bConsoleUp->activate();
  241. bConsoleDown->activate();
  242. for(int b=0; b<187; ++b)
  243. {
  244. bfield[b].activate();
  245. }
  246. if(attackingHero)
  247. attackingHero->activate();
  248. if(defendingHero)
  249. defendingHero->activate();
  250. }
  251. void CBattleInterface::deactivate()
  252. {
  253. KeyInterested::deactivate();
  254. MotionInterested::deactivate();
  255. bOptions->deactivate();
  256. bSurrender->deactivate();
  257. bFlee->deactivate();
  258. bAutofight->deactivate();
  259. bSpell->deactivate();
  260. bWait->deactivate();
  261. bDefence->deactivate();
  262. bConsoleUp->deactivate();
  263. bConsoleDown->deactivate();
  264. for(int b=0; b<187; ++b)
  265. {
  266. bfield[b].deactivate();
  267. }
  268. if(attackingHero)
  269. attackingHero->deactivate();
  270. if(defendingHero)
  271. defendingHero->deactivate();
  272. }
  273. void CBattleInterface::show(SDL_Surface * to)
  274. {
  275. std::map<int, CStack> stacks = LOCPLINT->cb->battleGetStacks(); //used in a few places
  276. ++animCount;
  277. if(!to) //"evaluating" to
  278. to = screen;
  279. //printing background and hexes
  280. if(activeStack != -1 && creAnims[activeStack]->getType() != 0) //show everything with range
  281. {
  282. blitAt(backgroundWithHexes, 0, 0, to);
  283. }
  284. else
  285. {
  286. //showing background
  287. blitAt(background, 0, 0, to);
  288. if(printCellBorders)
  289. {
  290. CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, to, NULL);
  291. }
  292. }
  293. //printing hovered cell
  294. if(printMouseShadow)
  295. {
  296. for(int b=0; b<187; ++b)
  297. {
  298. if(bfield[b].strictHovered && bfield[b].hovered)
  299. {
  300. int x = 14 + ((b/17)%2==0 ? 22 : 0) + 44*(b%17);
  301. int y = 86 + 42 * (b/17);
  302. CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, NULL, to, &genRect(cellShade->h, cellShade->w, x, y));
  303. }
  304. }
  305. }
  306. //showing menu background and console
  307. blitAt(menu, 0, 556, to);
  308. console->show(to);
  309. //showing buttons
  310. bOptions->show(to);
  311. bSurrender->show(to);
  312. bFlee->show(to);
  313. bAutofight->show(to);
  314. bSpell->show(to);
  315. bWait->show(to);
  316. bDefence->show(to);
  317. bConsoleUp->show(to);
  318. bConsoleDown->show(to);
  319. //showing hero animations
  320. if(attackingHero)
  321. attackingHero->show(to);
  322. if(defendingHero)
  323. defendingHero->show(to);
  324. ////showing units //a lot of work...
  325. std::vector<int> stackAliveByHex[187];
  326. //double loop because dead stacks should be printed first
  327. for(std::map<int, CStack>::iterator j=stacks.begin(); j!=stacks.end(); ++j)
  328. {
  329. if(j->second.alive())
  330. stackAliveByHex[j->second.position].push_back(j->second.ID);
  331. }
  332. std::vector<int> stackDeadByHex[187];
  333. for(std::map<int, CStack>::iterator j=stacks.begin(); j!=stacks.end(); ++j)
  334. {
  335. if(!j->second.alive())
  336. stackDeadByHex[j->second.position].push_back(j->second.ID);
  337. }
  338. attackingShowHelper(); // handle attack animation
  339. for(int b=0; b<187; ++b) //showing dead stacks
  340. {
  341. for(int v=0; v<stackDeadByHex[b].size(); ++v)
  342. {
  343. creAnims[stackDeadByHex[b][v]]->nextFrame(to, creAnims[stackDeadByHex[b][v]]->pos.x, creAnims[stackDeadByHex[b][v]]->pos.y, creDir[stackDeadByHex[b][v]], (animCount%(4/animSpeed)==0) && creAnims[stackDeadByHex[b][v]]->getType()!=5, stackDeadByHex[b][v]==activeStack); //increment always when moving, never if stack died
  344. //printing amount
  345. if(stacks[stackDeadByHex[b][v]].amount > 0) //don't print if stack is not alive
  346. {
  347. int xAdd = stacks[stackDeadByHex[b][v]].attackerOwned ? 220 : 202;
  348. CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackDeadByHex[b][v]]->pos.x + xAdd, creAnims[stackDeadByHex[b][v]]->pos.y + 260));
  349. std::stringstream ss;
  350. ss<<stacks[stackDeadByHex[b][v]].amount;
  351. CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackDeadByHex[b][v]]->pos.x + xAdd + 14, creAnims[stackDeadByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
  352. }
  353. }
  354. }
  355. for(int b=0; b<187; ++b) //showing alive stacks
  356. {
  357. for(int v=0; v<stackAliveByHex[b].size(); ++v)
  358. {
  359. creAnims[stackAliveByHex[b][v]]->nextFrame(to, creAnims[stackAliveByHex[b][v]]->pos.x, creAnims[stackAliveByHex[b][v]]->pos.y, creDir[stackAliveByHex[b][v]], (animCount%(4/animSpeed)==0) && creAnims[stackAliveByHex[b][v]]->getType()!=0 && creAnims[stackAliveByHex[b][v]]->getType()!=5 && creAnims[stackAliveByHex[b][v]]->getType()!=20 && creAnims[stackAliveByHex[b][v]]->getType()!=21, stackAliveByHex[b][v]==activeStack); //increment always when moving, never if stack died
  360. //printing amount
  361. if(stacks[stackAliveByHex[b][v]].amount > 0) //don't print if stack is not alive
  362. {
  363. int xAdd = stacks[stackAliveByHex[b][v]].attackerOwned ? 220 : 202;
  364. CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackAliveByHex[b][v]]->pos.x + xAdd, creAnims[stackAliveByHex[b][v]]->pos.y + 260));
  365. std::stringstream ss;
  366. ss<<stacks[stackAliveByHex[b][v]].amount;
  367. CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackAliveByHex[b][v]]->pos.x + xAdd + 14, creAnims[stackAliveByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
  368. }
  369. }
  370. }
  371. //units shown
  372. projectileShowHelper(to);//showing projectiles
  373. //showing spell effects
  374. std::vector< std::list<SBattleEffect>::iterator > toErase;
  375. for(std::list<SBattleEffect>::iterator it = battleEffects.begin(); it!=battleEffects.end(); ++it)
  376. {
  377. blitAt(it->anim->ourImages[it->frame].bitmap, it->x, it->y, to);
  378. ++(it->frame);
  379. if(it->frame == it->maxFrame)
  380. toErase.push_back(it);
  381. }
  382. for(int b=0; b<toErase.size(); ++b)
  383. {
  384. delete toErase[b]->anim;
  385. battleEffects.erase(toErase[b]);
  386. }
  387. //showing queue of stacks
  388. if(showStackQueue)
  389. {
  390. int xPos = screen->w/2 - ( stacks.size() * 37 )/2;
  391. int yPos = 10;
  392. std::vector<CStack> stacksSorted;
  393. for(int v=0; v<stacks.size(); ++v)
  394. {
  395. if(stacks[v].alive()) //we don't want dead stacks to be there
  396. stacksSorted.push_back(stacks[v]);
  397. }
  398. std::stable_sort(stacksSorted.begin(), stacksSorted.end(), cmpst2);
  399. int startFrom = -1;
  400. for(int n=0; n<stacksSorted.size(); ++n)
  401. {
  402. if(stacksSorted[n].ID == activeStack)
  403. {
  404. startFrom = n;
  405. break;
  406. }
  407. }
  408. if(startFrom != -1)
  409. {
  410. for(int b=startFrom; b<stacksSorted.size()+startFrom; ++b)
  411. {
  412. SDL_BlitSurface(graphics->smallImgs[-2], NULL, to, &genRect(32, 32, xPos, yPos));
  413. //printing colored border
  414. for(int xFrom = xPos-1; xFrom<xPos+33; ++xFrom)
  415. {
  416. for(int yFrom = yPos-1; yFrom<yPos+33; ++yFrom)
  417. {
  418. if(xFrom == xPos-1 || xFrom == xPos+32 || yFrom == yPos-1 || yFrom == yPos+32)
  419. {
  420. SDL_Color pc;
  421. if(stacksSorted[b % stacksSorted.size()].owner != 255)
  422. {
  423. pc = graphics->playerColors[stacksSorted[b % stacksSorted.size()].owner];
  424. }
  425. else
  426. {
  427. pc = *graphics->neutralColor;
  428. }
  429. CSDL_Ext::SDL_PutPixel(to, xFrom, yFrom, pc.r, pc.g, pc.b);
  430. }
  431. }
  432. }
  433. //colored border printed
  434. SDL_BlitSurface(graphics->smallImgs[stacksSorted[b % stacksSorted.size()].creature->idNumber], NULL, to, &genRect(32, 32, xPos, yPos));
  435. xPos += 37;
  436. }
  437. }
  438. }
  439. //showing window with result of battle
  440. if(resWindow)
  441. {
  442. resWindow->show(to);
  443. }
  444. }
  445. void CBattleInterface::keyPressed(const SDL_KeyboardEvent & key)
  446. {
  447. if(key.keysym.sym == SDLK_q)
  448. showStackQueue = key.state==SDL_PRESSED;
  449. }
  450. void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
  451. {
  452. if(activeStack>=0 && !spellDestSelectMode)
  453. {
  454. int myNumber = -1; //number of hovered tile
  455. for(int g=0; g<187; ++g)
  456. {
  457. if(bfield[g].hovered && bfield[g].strictHovered)
  458. {
  459. myNumber = g;
  460. break;
  461. }
  462. }
  463. if(myNumber == -1)
  464. {
  465. CGI->curh->changeGraphic(1, 6);
  466. }
  467. else
  468. {
  469. if(std::find(shadedHexes.begin(),shadedHexes.end(),myNumber) == shadedHexes.end())
  470. {
  471. CStack *shere = LOCPLINT->cb->battleGetStackByPos(myNumber);
  472. if(shere)
  473. {
  474. if(shere->owner == LOCPLINT->playerID) //our stack
  475. CGI->curh->changeGraphic(1,5);
  476. else if(LOCPLINT->cb->battleCanShoot(activeStack,myNumber)) //we can shoot enemy
  477. CGI->curh->changeGraphic(1,3);
  478. else if(isTileAttackable(myNumber)) //available enemy (melee attackable)
  479. {
  480. int fromHex = -1;
  481. for(int b=0; b<187; ++b)
  482. if(bfield[b].hovered && !bfield[b].strictHovered)
  483. {
  484. fromHex = b;
  485. break;
  486. }
  487. if(fromHex!=-1 && fromHex%17!=0 && fromHex%17!=16 && vstd::contains(shadedHexes, fromHex))
  488. {
  489. switch(BattleInfo::mutualPosition(fromHex, myNumber))
  490. {
  491. case 0:
  492. CGI->curh->changeGraphic(1,12);
  493. break;
  494. case 1:
  495. CGI->curh->changeGraphic(1,7);
  496. break;
  497. case 2:
  498. CGI->curh->changeGraphic(1,8);
  499. break;
  500. case 3:
  501. CGI->curh->changeGraphic(1,9);
  502. break;
  503. case 4:
  504. CGI->curh->changeGraphic(1,10);
  505. break;
  506. case 5:
  507. CGI->curh->changeGraphic(1,11);
  508. break;
  509. }
  510. }
  511. }
  512. else //unavailable enemy
  513. CGI->curh->changeGraphic(1,0);
  514. }
  515. else //empty unavailable tile
  516. CGI->curh->changeGraphic(1,0);
  517. }
  518. else //available tile
  519. {
  520. if(LOCPLINT->cb->battleGetStackByID(activeStack)->creature->isFlying())
  521. CGI->curh->changeGraphic(1,2);
  522. else
  523. CGI->curh->changeGraphic(1,1);
  524. }
  525. }
  526. }
  527. }
  528. bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick)
  529. {
  530. if(creAnims[number]==NULL)
  531. return false; //there is no such creature
  532. creAnims[number]->setType(8);
  533. int firstFrame = creAnims[number]->getFrame();
  534. for(int g=0; creAnims[number]->getFrame() != creAnims[number]->framesInGroup(8) + firstFrame - 1; ++g)
  535. {
  536. show();
  537. CSDL_Ext::update();
  538. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  539. }
  540. creDir[number] = !creDir[number];
  541. CStack curs = *LOCPLINT->cb->battleGetStackByID(number);
  542. std::pair <int, int> coords = CBattleHex::getXYUnitAnim(hex, creDir[number], curs.creature);
  543. creAnims[number]->pos.x = coords.first;
  544. //creAnims[number]->pos.y = coords.second;
  545. if(wideTrick && curs.creature->isDoubleWide())
  546. {
  547. if(!creDir[number])
  548. creAnims[number]->pos.x -= 44;
  549. }
  550. creAnims[number]->setType(7);
  551. firstFrame = creAnims[number]->getFrame();
  552. for(int g=0; creAnims[number]->getFrame() != creAnims[number]->framesInGroup(7) + firstFrame - 1; ++g)
  553. {
  554. show();
  555. CSDL_Ext::update();
  556. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  557. }
  558. creAnims[number]->setType(2);
  559. return true;
  560. }
  561. void CBattleInterface::bOptionsf()
  562. {
  563. CGI->curh->changeGraphic(0,0);
  564. deactivate();
  565. SDL_Rect temp_rect = genRect(431, 481, 160, 84);
  566. CBattleOptionsWindow * optionsWin = new CBattleOptionsWindow(temp_rect, this);
  567. optionsWin->activate();
  568. LOCPLINT->objsToBlit.push_back(optionsWin);
  569. }
  570. void CBattleInterface::bSurrenderf()
  571. {
  572. }
  573. void CBattleInterface::bFleef()
  574. {
  575. CFunctionList<void()> ony = boost::bind(&CBattleInterface::activate,this);
  576. ony += boost::bind(&CBattleInterface::reallyFlee,this);
  577. LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[28],std::vector<SComponent*>(), ony, boost::bind(&CBattleInterface::activate,this), true, false);
  578. }
  579. void CBattleInterface::reallyFlee()
  580. {
  581. giveCommand(4,0,0);
  582. CGI->curh->changeGraphic(0, 0);
  583. }
  584. void CBattleInterface::bAutofightf()
  585. {
  586. }
  587. void CBattleInterface::bSpellf()
  588. {
  589. CGI->curh->changeGraphic(0,0);
  590. deactivate();
  591. const CGHeroInstance * chi = NULL;
  592. if(attackingHeroInstance->tempOwner == LOCPLINT->playerID)
  593. chi = attackingHeroInstance;
  594. else
  595. chi = defendingHeroInstance;
  596. CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, 90, 2), chi);
  597. spellWindow->activate();
  598. LOCPLINT->objsToBlit.push_back(spellWindow);
  599. }
  600. void CBattleInterface::bWaitf()
  601. {
  602. }
  603. void CBattleInterface::bDefencef()
  604. {
  605. giveCommand(3,0,activeStack);
  606. }
  607. void CBattleInterface::bConsoleUpf()
  608. {
  609. console->scrollUp();
  610. }
  611. void CBattleInterface::bConsoleDownf()
  612. {
  613. console->scrollDown();
  614. }
  615. void CBattleInterface::newStack(CStack stack)
  616. {
  617. creAnims[stack.ID] = new CCreatureAnimation(stack.creature->animDefName);
  618. creAnims[stack.ID]->setType(2);
  619. creDir[stack.ID] = stack.owner==attackingHeroInstance->tempOwner;
  620. }
  621. void CBattleInterface::stackRemoved(CStack stack)
  622. {
  623. delete creAnims[stack.ID];
  624. creAnims.erase(stack.ID);
  625. }
  626. void CBattleInterface::stackKilled(int ID, int dmg, int killed, int IDby, bool byShooting)
  627. {
  628. if(creAnims[ID]->getType() != 2)
  629. {
  630. return; //something went wrong
  631. }
  632. if(byShooting) //delay hit animation
  633. {
  634. CStack attacker = *LOCPLINT->cb->battleGetStackByID(IDby);
  635. while(true)
  636. {
  637. bool found = false;
  638. for(std::list<SProjectileInfo>::const_iterator it = projectiles.begin(); it!=projectiles.end(); ++it)
  639. {
  640. if(it->creID == attacker.creature->idNumber)
  641. {
  642. found = true;
  643. break;
  644. }
  645. }
  646. if(!found)
  647. break;
  648. else
  649. {
  650. show();
  651. CSDL_Ext::update();
  652. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  653. }
  654. }
  655. }
  656. creAnims[ID]->setType(5); //death
  657. //int firstFrame = creAnims[ID]->getFrame();
  658. int increments = 0;
  659. while(increments < creAnims[ID]->framesInGroup(5)-1)
  660. {
  661. if((animCount%(4/animSpeed))==0)
  662. {
  663. creAnims[ID]->incrementFrame();
  664. ++increments;
  665. }
  666. show();
  667. CSDL_Ext::update();
  668. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  669. }
  670. if(IDby!=-1)
  671. printConsoleAttacked(ID, dmg, killed, IDby);
  672. }
  673. void CBattleInterface::stackActivated(int number)
  674. {
  675. //givenCommand = NULL;
  676. activeStack = number;
  677. myTurn = true;
  678. redrawBackgroundWithHexes(number);
  679. }
  680. void CBattleInterface::stackMoved(int number, int destHex, bool endMoving)
  681. {
  682. bool startMoving = creAnims[number]->type==20;
  683. //a few useful variables
  684. int curStackPos = LOCPLINT->cb->battleGetPos(number);
  685. int steps = creAnims[number]->framesInGroup(0)*getAnimSpeedMultiplier()-1;
  686. int hexWbase = 44, hexHbase = 42;
  687. bool twoTiles = LOCPLINT->cb->battleGetCreature(number).isDoubleWide();
  688. if(startMoving) //animation of starting move; some units don't have this animation (ie. halberdier)
  689. {
  690. CGI->curh->hide();
  691. for(int i=0; i<creAnims[number]->framesInGroup(20)*getAnimSpeedMultiplier()-1; ++i)
  692. {
  693. show();
  694. CSDL_Ext::update();
  695. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  696. if((animCount+1)%(4/animSpeed)==0)
  697. creAnims[number]->incrementFrame();
  698. }
  699. }
  700. int mutPos = BattleInfo::mutualPosition(curStackPos, destHex);
  701. {
  702. switch(mutPos) //reverse unit if necessary
  703. {
  704. case 0: case 4: case 5:
  705. if(creDir[number] == true)
  706. reverseCreature(number, curStackPos, twoTiles);
  707. break;
  708. case 1: case 2: case 3:
  709. if(creDir[number] == false)
  710. reverseCreature(number, curStackPos, twoTiles);
  711. break;
  712. }
  713. //moving instructions
  714. creAnims[number]->setType(0);
  715. float posX = creAnims[number]->pos.x, posY = creAnims[number]->pos.y; // for precise calculations ;]
  716. for(int i=0; i<steps; ++i)
  717. {
  718. switch(mutPos)
  719. {
  720. case 0:
  721. posX -= ((float)hexWbase)/(2.0f*steps);
  722. creAnims[number]->pos.x = posX;
  723. posY -= ((float)hexHbase)/((float)steps);
  724. creAnims[number]->pos.y = posY;
  725. break;
  726. case 1:
  727. posX += ((float)hexWbase)/(2.0f*steps);
  728. creAnims[number]->pos.x = posX;
  729. posY -= ((float)hexHbase)/((float)steps);
  730. creAnims[number]->pos.y = posY;
  731. break;
  732. case 2:
  733. posX += ((float)hexWbase)/((float)steps);
  734. creAnims[number]->pos.x = posX;
  735. break;
  736. case 3:
  737. posX += ((float)hexWbase)/(2.0f*steps);
  738. creAnims[number]->pos.x = posX;
  739. posY += ((float)hexHbase)/((float)steps);
  740. creAnims[number]->pos.y = posY;
  741. break;
  742. case 4:
  743. posX -= ((float)hexWbase)/(2.0f*steps);
  744. creAnims[number]->pos.x = posX;
  745. posY += ((float)hexHbase)/((float)steps);
  746. creAnims[number]->pos.y = posY;
  747. break;
  748. case 5:
  749. posX -= ((float)hexWbase)/((float)steps);
  750. creAnims[number]->pos.x = posX;
  751. break;
  752. }
  753. show();
  754. CSDL_Ext::update();
  755. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  756. if((animCount+1)%(4/animSpeed)==0)
  757. creAnims[number]->incrementFrame();
  758. }
  759. }
  760. if(endMoving) //animation of ending move
  761. {
  762. if(creAnims[number]->framesInGroup(21)!=0) // some units don't have this animation (ie. halberdier)
  763. {
  764. creAnims[number]->setType(21);
  765. for(int i=0; i<creAnims[number]->framesInGroup(21)*getAnimSpeedMultiplier()-1; ++i)
  766. {
  767. show();
  768. CSDL_Ext::update();
  769. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  770. if((animCount+1)%(4/animSpeed)==0)
  771. creAnims[number]->incrementFrame();
  772. }
  773. }
  774. creAnims[number]->setType(2); //resetting to default
  775. CGI->curh->show();
  776. }
  777. CStack curs = *LOCPLINT->cb->battleGetStackByID(number);
  778. if(endMoving) //resetting to default
  779. {
  780. if(creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))
  781. reverseCreature(number, destHex, twoTiles);
  782. }
  783. std::pair <int, int> coords = CBattleHex::getXYUnitAnim(destHex, creDir[number], curs.creature);
  784. creAnims[number]->pos.x = coords.first;
  785. if(!endMoving && twoTiles && (creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))) //big creature is reversed
  786. creAnims[number]->pos.x -= 44;
  787. creAnims[number]->pos.y = coords.second;
  788. }
  789. void CBattleInterface::stackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting)
  790. {
  791. while(creAnims[ID]->getType() != 2 || (attackingInfo && attackingInfo->IDby == IDby))
  792. {
  793. show();
  794. CSDL_Ext::update();
  795. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  796. }
  797. if(byShooting) //delay hit animation
  798. {
  799. CStack attacker = *LOCPLINT->cb->battleGetStackByID(IDby);
  800. while(true)
  801. {
  802. bool found = false;
  803. for(std::list<SProjectileInfo>::const_iterator it = projectiles.begin(); it!=projectiles.end(); ++it)
  804. {
  805. if(it->creID == attacker.creature->idNumber)
  806. {
  807. found = true;
  808. break;
  809. }
  810. }
  811. if(!found)
  812. break;
  813. else
  814. {
  815. show();
  816. CSDL_Ext::update();
  817. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  818. }
  819. }
  820. }
  821. creAnims[ID]->setType(3); //getting hit
  822. int firstFrame = creAnims[ID]->getFrame();
  823. for(int i=0; creAnims[ID]->getFrame() != creAnims[ID]->framesInGroup(3) + firstFrame - 1; ++i)
  824. {
  825. show();
  826. CSDL_Ext::update();
  827. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  828. /*if((animCount+1)%(4/animSpeed)==0)
  829. creAnims[ID]->incrementFrame();*/
  830. }
  831. creAnims[ID]->setType(2);
  832. if(IDby!=-1)
  833. printConsoleAttacked(ID, dmg, killed, IDby);
  834. }
  835. void CBattleInterface::stackAttacking(int ID, int dest)
  836. {
  837. while(attackingInfo != NULL || creAnims[ID]->getType()!=2)
  838. {
  839. show();
  840. CSDL_Ext::update();
  841. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  842. }
  843. CStack aStack = *LOCPLINT->cb->battleGetStackByID(ID); //attacking stack
  844. if(aStack.attackerOwned)
  845. {
  846. if(aStack.creature->isDoubleWide())
  847. {
  848. switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction
  849. {
  850. case 0:
  851. //reverseCreature(ID, aStack.position, true);
  852. break;
  853. case 1:
  854. break;
  855. case 2:
  856. break;
  857. case 3:
  858. break;
  859. case 4:
  860. //reverseCreature(ID, aStack.position, true);
  861. break;
  862. case 5:
  863. reverseCreature(ID, aStack.position, true);
  864. break;
  865. }
  866. }
  867. else //else for if(aStack.creature->isDoubleWide())
  868. {
  869. switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction
  870. {
  871. case 0:
  872. reverseCreature(ID, aStack.position, true);
  873. break;
  874. case 1:
  875. break;
  876. case 2:
  877. break;
  878. case 3:
  879. break;
  880. case 4:
  881. reverseCreature(ID, aStack.position, true);
  882. break;
  883. case 5:
  884. reverseCreature(ID, aStack.position, true);
  885. break;
  886. }
  887. }
  888. }
  889. else //if(aStack.attackerOwned)
  890. {
  891. if(aStack.creature->isDoubleWide())
  892. {
  893. switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction
  894. {
  895. case 0:
  896. //reverseCreature(ID, aStack.position, true);
  897. break;
  898. case 1:
  899. break;
  900. case 2:
  901. reverseCreature(ID, aStack.position, true);
  902. break;
  903. case 3:
  904. break;
  905. case 4:
  906. //reverseCreature(ID, aStack.position, true);
  907. break;
  908. case 5:
  909. //reverseCreature(ID, aStack.position, true);
  910. break;
  911. }
  912. }
  913. else //else for if(aStack.creature->isDoubleWide())
  914. {
  915. switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction
  916. {
  917. case 0:
  918. //reverseCreature(ID, aStack.position, true);
  919. break;
  920. case 1:
  921. reverseCreature(ID, aStack.position, true);
  922. break;
  923. case 2:
  924. reverseCreature(ID, aStack.position, true);
  925. break;
  926. case 3:
  927. reverseCreature(ID, aStack.position, true);
  928. break;
  929. case 4:
  930. //reverseCreature(ID, aStack.position, true);
  931. break;
  932. case 5:
  933. //reverseCreature(ID, aStack.position, true);
  934. break;
  935. }
  936. }
  937. }
  938. attackingInfo = new CAttHelper;
  939. attackingInfo->dest = dest;
  940. attackingInfo->frame = 0;
  941. attackingInfo->hitCount = 0;
  942. attackingInfo->ID = ID;
  943. attackingInfo->IDby = LOCPLINT->cb->battleGetStackByPos(dest)->ID;
  944. attackingInfo->reversing = false;
  945. attackingInfo->shooting = false;
  946. switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction
  947. {
  948. case 0:
  949. attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
  950. break;
  951. case 1:
  952. attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
  953. break;
  954. case 2:
  955. attackingInfo->maxframe = creAnims[ID]->framesInGroup(12);
  956. break;
  957. case 3:
  958. attackingInfo->maxframe = creAnims[ID]->framesInGroup(13);
  959. break;
  960. case 4:
  961. attackingInfo->maxframe = creAnims[ID]->framesInGroup(13);
  962. break;
  963. case 5:
  964. attackingInfo->maxframe = creAnims[ID]->framesInGroup(12);
  965. break;
  966. default:
  967. tlog1<<"Critical Error! Wrong dest in stackAttacking!"<<std::endl;
  968. }
  969. }
  970. void CBattleInterface::newRound(int number)
  971. {
  972. console->addText(CGI->generaltexth->allTexts[412]);
  973. }
  974. void CBattleInterface::giveCommand(ui8 action, ui16 tile, ui32 stack, si32 additional)
  975. {
  976. BattleAction * ba = new BattleAction(); //is deleted in CPlayerInterface::activeStack()
  977. ba->actionType = action;
  978. ba->destinationTile = tile;
  979. ba->stackNumber = stack;
  980. ba->additionalInfo = additional;
  981. givenCommand->setn(ba);
  982. myTurn = false;
  983. activeStack = -1;
  984. }
  985. bool CBattleInterface::isTileAttackable(int number)
  986. {
  987. for(int b=0; b<shadedHexes.size(); ++b)
  988. {
  989. if(BattleInfo::mutualPosition(shadedHexes[b], number) != -1 || shadedHexes[b] == number)
  990. return true;
  991. }
  992. return false;
  993. }
  994. void CBattleInterface::hexLclicked(int whichOne)
  995. {
  996. if((whichOne%17)!=0 && (whichOne%17)!=16) //if player is trying to attack enemey unit or move creature stack
  997. {
  998. if(!myTurn)
  999. return; //we are not permit to do anything
  1000. if(spellDestSelectMode)
  1001. {
  1002. spellToCast->destinationTile = whichOne;
  1003. LOCPLINT->cb->battleMakeAction(spellToCast);
  1004. delete spellToCast;
  1005. spellToCast = NULL;
  1006. spellDestSelectMode = false;
  1007. CGI->curh->changeGraphic(1, 6);
  1008. }
  1009. else
  1010. {
  1011. CStack* dest = LOCPLINT->cb->battleGetStackByPos(whichOne); //creature at destination tile; -1 if there is no one
  1012. if(!dest || !dest->alive()) //no creature at that tile
  1013. {
  1014. if(std::find(shadedHexes.begin(),shadedHexes.end(),whichOne)!=shadedHexes.end())// and it's in our range
  1015. giveCommand(2,whichOne,activeStack);
  1016. }
  1017. else if(dest->owner != attackingHeroInstance->tempOwner
  1018. && LOCPLINT->cb->battleCanShoot(activeStack, whichOne)
  1019. && BattleInfo::mutualPosition(LOCPLINT->cb->battleGetPos(activeStack),whichOne) < 0 ) //shooting
  1020. {
  1021. giveCommand(7,whichOne,activeStack);
  1022. }
  1023. else if(dest->owner != attackingHeroInstance->tempOwner) //attacking
  1024. {
  1025. //std::vector<int> n = BattleInfo::neighbouringTiles(whichOne);
  1026. //for(int i=0;i<n.size();i++)
  1027. //{
  1028. // //TODO: now we are using first available tile, but in the future we should add possibility of choosing from which tile we want to attack
  1029. // if(vstd::contains(shadedHexes,n[i]))
  1030. // {
  1031. // giveCommand(6,n[i],activeStack,whichOne);
  1032. // return;
  1033. // }
  1034. //}
  1035. switch(CGI->curh->number)
  1036. {
  1037. case 12:
  1038. giveCommand(6,whichOne + ( (whichOne/17)%2 ? 17 : 18 ),activeStack,whichOne);
  1039. break;
  1040. case 7:
  1041. giveCommand(6,whichOne + ( (whichOne/17)%2 ? 16 : 17 ),activeStack,whichOne);
  1042. break;
  1043. case 8:
  1044. giveCommand(6,whichOne - 1,activeStack,whichOne);
  1045. break;
  1046. case 9:
  1047. giveCommand(6,whichOne - ( (whichOne/17)%2 ? 18 : 17 ),activeStack,whichOne);
  1048. break;
  1049. case 10:
  1050. giveCommand(6,whichOne - ( (whichOne/17)%2 ? 17 : 16 ),activeStack,whichOne);
  1051. break;
  1052. case 11:
  1053. giveCommand(6,whichOne + 1,activeStack,whichOne);
  1054. break;
  1055. }
  1056. }
  1057. }
  1058. }
  1059. }
  1060. void CBattleInterface::stackIsShooting(int ID, int dest)
  1061. {
  1062. if(attackingInfo != NULL)
  1063. {
  1064. return; //something went wrong
  1065. }
  1066. //projectile
  1067. float projectileAngle; //in radians; if positive, projectiles goes up
  1068. float straightAngle = 0.2f; //maximal angle in radians between straight horizontal line and shooting line for which shot is considered to be straight (absoulte value)
  1069. int fromHex = LOCPLINT->cb->battleGetPos(ID);
  1070. projectileAngle = atan2(float(abs(dest - fromHex)/17), float(abs(dest - fromHex)%17));
  1071. if(fromHex < dest)
  1072. projectileAngle = -projectileAngle;
  1073. SProjectileInfo spi;
  1074. spi.creID = LOCPLINT->cb->battleGetStackByID(ID)->creature->idNumber;
  1075. spi.step = 0;
  1076. spi.frameNum = 0;
  1077. spi.spin = CGI->creh->idToProjectileSpin[spi.creID];
  1078. std::pair<int, int> xycoord = CBattleHex::getXYUnitAnim(LOCPLINT->cb->battleGetPos(ID), true, &LOCPLINT->cb->battleGetCreature(ID));
  1079. std::pair<int, int> destcoord = CBattleHex::getXYUnitAnim(dest, false, &LOCPLINT->cb->battleGetCreature(ID));
  1080. destcoord.first += 250; destcoord.second += 210; //TODO: find a better place to shoot
  1081. if(projectileAngle > straightAngle) //upper shot
  1082. {
  1083. spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).upperRightMissleOffsetX;
  1084. spi.y = xycoord.second + 100 - LOCPLINT->cb->battleGetCreature(ID).upperRightMissleOffsetY;
  1085. }
  1086. else if(projectileAngle < -straightAngle) //lower shot
  1087. {
  1088. spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).lowerRightMissleOffsetX;
  1089. spi.y = xycoord.second + 150 - LOCPLINT->cb->battleGetCreature(ID).lowerRightMissleOffsetY;
  1090. }
  1091. else //straight shot
  1092. {
  1093. spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).rightMissleOffsetX;
  1094. spi.y = xycoord.second + 125 - LOCPLINT->cb->battleGetCreature(ID).rightMissleOffsetY;
  1095. }
  1096. spi.lastStep = sqrt((float)((destcoord.first - spi.x)*(destcoord.first - spi.x) + (destcoord.second - spi.y) * (destcoord.second - spi.y))) / 40;
  1097. if(spi.lastStep == 0)
  1098. spi.lastStep = 1;
  1099. spi.dx = (destcoord.first - spi.x) / spi.lastStep;
  1100. spi.dy = (destcoord.second - spi.y) / spi.lastStep;
  1101. //set starting frame
  1102. if(spi.spin)
  1103. {
  1104. spi.frameNum = 0;
  1105. }
  1106. else
  1107. {
  1108. spi.frameNum = ((M_PI/2.0f - projectileAngle) / (2.0f *M_PI) + 1/((float)(2*(idToProjectile[spi.creID]->ourImages.size()-1)))) * (idToProjectile[spi.creID]->ourImages.size()-1);
  1109. }
  1110. //set delay
  1111. spi.animStartDelay = CGI->creh->creatures[spi.creID].attackClimaxFrame;
  1112. projectiles.push_back(spi);
  1113. //attack aniamtion
  1114. attackingInfo = new CAttHelper;
  1115. attackingInfo->dest = dest;
  1116. attackingInfo->frame = 0;
  1117. attackingInfo->hitCount = 0;
  1118. attackingInfo->ID = ID;
  1119. attackingInfo->reversing = false;
  1120. attackingInfo->shooting = true;
  1121. if(projectileAngle > straightAngle) //upper shot
  1122. attackingInfo->shootingGroup = 14;
  1123. else if(projectileAngle < -straightAngle) //lower shot
  1124. attackingInfo->shootingGroup = 16;
  1125. else //straight shot
  1126. attackingInfo->shootingGroup = 15;
  1127. attackingInfo->maxframe = creAnims[ID]->framesInGroup(attackingInfo->shootingGroup);
  1128. }
  1129. void CBattleInterface::battleFinished(const BattleResult& br)
  1130. {
  1131. deactivate();
  1132. CGI->curh->changeGraphic(0,0);
  1133. SDL_Rect temp_rect = genRect(561, 470, 165, 19);
  1134. resWindow = new CBattleReslutWindow(br, temp_rect, this);
  1135. resWindow->activate();
  1136. }
  1137. void CBattleInterface::spellCasted(SpellCasted * sc)
  1138. {
  1139. switch(sc->id)
  1140. {
  1141. case 15: //magic arrow
  1142. {
  1143. //initial variables
  1144. std::vector< std::string > anims;
  1145. anims.push_back("C20SPX0.DEF"); anims.push_back("C20SPX1.DEF"); anims.push_back("C20SPX2.DEF"); anims.push_back("C20SPX3.DEF"); anims.push_back("C20SPX4.DEF");
  1146. std::string animToDisplay;
  1147. std::pair<int, int> srccoord = sc->side ? std::make_pair(770, 60) : std::make_pair(30, 60);
  1148. std::pair<int, int> destcoord = CBattleHex::getXYUnitAnim(sc->tile, !sc->side, LOCPLINT->cb->battleGetStackByPos(sc->tile)->creature); //position attacked by arrow
  1149. destcoord.first += 250; destcoord.second += 240;
  1150. //animation angle
  1151. float angle = atan2(float(destcoord.first - srccoord.first), float(destcoord.second - srccoord.second));
  1152. //choosing animation by angle
  1153. if(angle > 1.50)
  1154. animToDisplay = anims[0];
  1155. else if(angle > 1.20)
  1156. animToDisplay = anims[1];
  1157. else if(angle > 0.90)
  1158. animToDisplay = anims[2];
  1159. else if(angle > 0.60)
  1160. animToDisplay = anims[3];
  1161. else
  1162. animToDisplay = anims[4];
  1163. //displaying animation
  1164. int steps = sqrt((float)((destcoord.first - srccoord.first)*(destcoord.first - srccoord.first) + (destcoord.second - srccoord.second) * (destcoord.second - srccoord.second))) / 40;
  1165. if(steps <= 0)
  1166. steps = 1;
  1167. CDefHandler * animDef = CDefHandler::giveDef(animToDisplay);
  1168. int dx = (destcoord.first - srccoord.first - animDef->ourImages[0].bitmap->w)/steps, dy = (destcoord.second - srccoord.second - animDef->ourImages[0].bitmap->h)/steps;
  1169. for(int g=0; g<steps; ++g)
  1170. {
  1171. show();
  1172. SDL_Rect & srcr = animDef->ourImages[g%animDef->ourImages.size()].bitmap->clip_rect;
  1173. SDL_Rect dstr = genRect(srcr.h, srcr.w, srccoord.first + g*dx, srccoord.second + g*dy);
  1174. SDL_BlitSurface(animDef->ourImages[g%animDef->ourImages.size()].bitmap, &srcr, screen, &dstr);
  1175. CSDL_Ext::update();
  1176. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  1177. }
  1178. int b=0;
  1179. break;
  1180. }
  1181. case 53://haste
  1182. displayEffect(31,sc->tile,LOCPLINT->cb->battleGetStackByPos(sc->tile)->owner);
  1183. break;
  1184. }
  1185. }
  1186. void CBattleInterface::castThisSpell(int spellID)
  1187. {
  1188. BattleAction * ba = new BattleAction;
  1189. ba->actionType = 1;
  1190. ba->additionalInfo = spellID; //spell number
  1191. ba->destinationTile = -1;
  1192. ba->stackNumber = (attackingHeroInstance->tempOwner == LOCPLINT->playerID) ? -1 : -2;
  1193. ba->side = defendingHeroInstance ? (LOCPLINT->playerID == defendingHeroInstance->tempOwner) : false;
  1194. spellToCast = ba;
  1195. spellDestSelectMode = true;
  1196. CGI->curh->changeGraphic(3, 0);
  1197. }
  1198. void CBattleInterface::displayEffect(ui32 effect, int destTile, bool affected)
  1199. {
  1200. if(graphics->battleACToDef[effect].size() != 0)
  1201. {
  1202. SBattleEffect be;
  1203. be.anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]);
  1204. be.frame = 0;
  1205. be.maxFrame = be.anim->ourImages.size();
  1206. std::pair<int, int> coords = CBattleHex::getXYUnitAnim(destTile, affected, NULL);
  1207. coords.first += 250; coords.second += 240;
  1208. coords.first -= be.anim->ourImages[0].bitmap->w/2;
  1209. coords.second -= be.anim->ourImages[0].bitmap->h/2;
  1210. be.x = coords.first; be.y = coords.second;
  1211. battleEffects.push_back(be);
  1212. }
  1213. //battleEffects
  1214. }
  1215. void CBattleInterface::setAnimSpeed(int set)
  1216. {
  1217. animSpeed = set;
  1218. }
  1219. int CBattleInterface::getAnimSpeed() const
  1220. {
  1221. return animSpeed;
  1222. }
  1223. float CBattleInterface::getAnimSpeedMultiplier() const
  1224. {
  1225. switch(animSpeed)
  1226. {
  1227. case 1:
  1228. return 3.5f;
  1229. case 2:
  1230. return 2.2f;
  1231. case 4:
  1232. return 1.0f;
  1233. default:
  1234. return 0.0f;
  1235. }
  1236. }
  1237. void CBattleInterface::attackingShowHelper()
  1238. {
  1239. if(attackingInfo && !attackingInfo->reversing)
  1240. {
  1241. if(attackingInfo->frame == 0)
  1242. {
  1243. CStack aStack = *LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
  1244. if(attackingInfo->shooting)
  1245. {
  1246. creAnims[attackingInfo->ID]->setType(attackingInfo->shootingGroup);
  1247. }
  1248. else
  1249. {
  1250. if(aStack.creature->isDoubleWide())
  1251. {
  1252. switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
  1253. {
  1254. case 0:
  1255. creAnims[attackingInfo->ID]->setType(11);
  1256. break;
  1257. case 1:
  1258. creAnims[attackingInfo->ID]->setType(11);
  1259. break;
  1260. case 2:
  1261. creAnims[attackingInfo->ID]->setType(12);
  1262. break;
  1263. case 3:
  1264. creAnims[attackingInfo->ID]->setType(13);
  1265. break;
  1266. case 4:
  1267. creAnims[attackingInfo->ID]->setType(13);
  1268. break;
  1269. case 5:
  1270. creAnims[attackingInfo->ID]->setType(12);
  1271. break;
  1272. }
  1273. }
  1274. else //else for if(aStack.creature->isDoubleWide())
  1275. {
  1276. switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
  1277. {
  1278. case 0:
  1279. creAnims[attackingInfo->ID]->setType(11);
  1280. break;
  1281. case 1:
  1282. creAnims[attackingInfo->ID]->setType(11);
  1283. break;
  1284. case 2:
  1285. creAnims[attackingInfo->ID]->setType(12);
  1286. break;
  1287. case 3:
  1288. creAnims[attackingInfo->ID]->setType(13);
  1289. break;
  1290. case 4:
  1291. creAnims[attackingInfo->ID]->setType(13);
  1292. break;
  1293. case 5:
  1294. creAnims[attackingInfo->ID]->setType(12);
  1295. break;
  1296. }
  1297. }
  1298. }
  1299. }
  1300. else if(attackingInfo->frame == (attackingInfo->maxframe - 1))
  1301. {
  1302. attackingInfo->reversing = true;
  1303. CStack* aStackp = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
  1304. if(aStackp == NULL)
  1305. return;
  1306. CStack aStack = *aStackp;
  1307. if(aStack.attackerOwned)
  1308. {
  1309. if(aStack.creature->isDoubleWide())
  1310. {
  1311. switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
  1312. {
  1313. case 0:
  1314. //reverseCreature(ID, aStack.position, true);
  1315. break;
  1316. case 1:
  1317. break;
  1318. case 2:
  1319. break;
  1320. case 3:
  1321. break;
  1322. case 4:
  1323. //reverseCreature(ID, aStack.position, true);
  1324. break;
  1325. case 5:
  1326. reverseCreature(attackingInfo->ID, aStack.position, true);
  1327. break;
  1328. }
  1329. }
  1330. else //else for if(aStack.creature->isDoubleWide())
  1331. {
  1332. switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
  1333. {
  1334. case 0:
  1335. reverseCreature(attackingInfo->ID, aStack.position, true);
  1336. break;
  1337. case 1:
  1338. break;
  1339. case 2:
  1340. break;
  1341. case 3:
  1342. break;
  1343. case 4:
  1344. reverseCreature(attackingInfo->ID, aStack.position, true);
  1345. break;
  1346. case 5:
  1347. reverseCreature(attackingInfo->ID, aStack.position, true);
  1348. break;
  1349. }
  1350. }
  1351. }
  1352. else //if(aStack.attackerOwned)
  1353. {
  1354. if(aStack.creature->isDoubleWide())
  1355. {
  1356. switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
  1357. {
  1358. case 0:
  1359. //reverseCreature(ID, aStack.position, true);
  1360. break;
  1361. case 1:
  1362. break;
  1363. case 2:
  1364. reverseCreature(attackingInfo->ID, aStack.position, true);
  1365. break;
  1366. case 3:
  1367. break;
  1368. case 4:
  1369. //reverseCreature(ID, aStack.position, true);
  1370. break;
  1371. case 5:
  1372. //reverseCreature(ID, aStack.position, true);
  1373. break;
  1374. }
  1375. }
  1376. else //else for if(aStack.creature->isDoubleWide())
  1377. {
  1378. switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
  1379. {
  1380. case 0:
  1381. //reverseCreature(ID, aStack.position, true);
  1382. break;
  1383. case 1:
  1384. reverseCreature(attackingInfo->ID, aStack.position, true);
  1385. break;
  1386. case 2:
  1387. reverseCreature(attackingInfo->ID, aStack.position, true);
  1388. break;
  1389. case 3:
  1390. reverseCreature(attackingInfo->ID, aStack.position, true);
  1391. break;
  1392. case 4:
  1393. //reverseCreature(ID, aStack.position, true);
  1394. break;
  1395. case 5:
  1396. //reverseCreature(ID, aStack.position, true);
  1397. break;
  1398. }
  1399. }
  1400. }
  1401. attackingInfo->reversing = false;
  1402. creAnims[attackingInfo->ID]->setType(2);
  1403. delete attackingInfo;
  1404. attackingInfo = NULL;
  1405. }
  1406. if(attackingInfo)
  1407. {
  1408. attackingInfo->hitCount++;
  1409. if(attackingInfo->hitCount%(4/animSpeed) == 0)
  1410. attackingInfo->frame++;
  1411. }
  1412. }
  1413. }
  1414. void CBattleInterface::redrawBackgroundWithHexes(int activeStack)
  1415. {
  1416. shadedHexes = LOCPLINT->cb->battleGetAvailableHexes(activeStack);
  1417. //preparating background graphic with hexes and shaded hexes
  1418. blitAt(background, 0, 0, backgroundWithHexes);
  1419. if(printCellBorders)
  1420. CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, backgroundWithHexes, NULL);
  1421. if(printStackRange)
  1422. {
  1423. for(int m=0; m<shadedHexes.size(); ++m) //rows
  1424. {
  1425. int i = shadedHexes[m]/17; //row
  1426. int j = shadedHexes[m]%17-1; //column
  1427. int x = 58 + (i%2==0 ? 22 : 0) + 44*j;
  1428. int y = 86 + 42 * i;
  1429. CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, NULL, backgroundWithHexes, &genRect(cellShade->h, cellShade->w, x, y));
  1430. }
  1431. }
  1432. }
  1433. void CBattleInterface::printConsoleAttacked(int ID, int dmg, int killed, int IDby)
  1434. {
  1435. char tabh[200];
  1436. CStack attacker = *LOCPLINT->cb->battleGetStackByID(IDby);
  1437. CStack defender = *LOCPLINT->cb->battleGetStackByID(ID);
  1438. int end = sprintf(tabh, CGI->generaltexth->allTexts[attacker.amount > 1 ? 377 : 376].c_str(),
  1439. (attacker.amount > 1 ? attacker.creature->namePl.c_str() : attacker.creature->nameSing.c_str()),
  1440. dmg);
  1441. if(killed > 0)
  1442. {
  1443. if(killed > 1)
  1444. {
  1445. sprintf(tabh + end, CGI->generaltexth->allTexts[379].c_str(), killed, defender.creature->namePl.c_str());
  1446. }
  1447. else //killed == 1
  1448. {
  1449. sprintf(tabh + end, CGI->generaltexth->allTexts[378].c_str(), defender.creature->nameSing.c_str());
  1450. }
  1451. }
  1452. console->addText(std::string(tabh));
  1453. }
  1454. void CBattleInterface::projectileShowHelper(SDL_Surface * to)
  1455. {
  1456. if(to == NULL)
  1457. to = screen;
  1458. std::list< std::list<SProjectileInfo>::iterator > toBeDeleted;
  1459. for(std::list<SProjectileInfo>::iterator it=projectiles.begin(); it!=projectiles.end(); ++it)
  1460. {
  1461. if(it->animStartDelay>0)
  1462. {
  1463. --(it->animStartDelay);
  1464. continue;
  1465. }
  1466. SDL_Rect dst;
  1467. dst.h = idToProjectile[it->creID]->ourImages[it->frameNum].bitmap->h;
  1468. dst.w = idToProjectile[it->creID]->ourImages[it->frameNum].bitmap->w;
  1469. dst.x = it->x;
  1470. dst.y = it->y;
  1471. CSDL_Ext::blit8bppAlphaTo24bpp(idToProjectile[it->creID]->ourImages[it->frameNum].bitmap, NULL, to, &dst);
  1472. //actualizing projectile
  1473. ++it->step;
  1474. if(it->step == it->lastStep)
  1475. {
  1476. toBeDeleted.insert(toBeDeleted.end(), it);
  1477. }
  1478. else
  1479. {
  1480. it->x += it->dx;
  1481. it->y += it->dy;
  1482. if(it->spin)
  1483. {
  1484. ++(it->frameNum);
  1485. it->frameNum %= idToProjectile[it->creID]->ourImages.size();
  1486. }
  1487. }
  1488. }
  1489. for(std::list< std::list<SProjectileInfo>::iterator >::iterator it = toBeDeleted.begin(); it!= toBeDeleted.end(); ++it)
  1490. {
  1491. projectiles.erase(*it);
  1492. }
  1493. }
  1494. void CBattleHero::show(SDL_Surface *to)
  1495. {
  1496. //animation of flag
  1497. if(flip)
  1498. {
  1499. CSDL_Ext::blit8bppAlphaTo24bpp(flag->ourImages[flagAnim].bitmap, NULL, screen, &genRect(flag->ourImages[flagAnim].bitmap->h, flag->ourImages[flagAnim].bitmap->w, 752, 39));
  1500. }
  1501. else
  1502. {
  1503. CSDL_Ext::blit8bppAlphaTo24bpp(flag->ourImages[flagAnim].bitmap, NULL, screen, &genRect(flag->ourImages[flagAnim].bitmap->h, flag->ourImages[flagAnim].bitmap->w, 31, 39));
  1504. }
  1505. ++flagAnimCount;
  1506. if(flagAnimCount%4==0)
  1507. {
  1508. ++flagAnim;
  1509. flagAnim %= flag->ourImages.size();
  1510. }
  1511. //animation of hero
  1512. int tick=-1;
  1513. for(int i=0; i<dh->ourImages.size(); ++i)
  1514. {
  1515. if(dh->ourImages[i].groupNumber==phase)
  1516. ++tick;
  1517. if(tick==image)
  1518. {
  1519. SDL_Rect posb = pos;
  1520. CSDL_Ext::blit8bppAlphaTo24bpp(dh->ourImages[i].bitmap, NULL, to, &posb);
  1521. ++image;
  1522. if(dh->ourImages[(i+1)%dh->ourImages.size()].groupNumber!=phase) //back to appropriate frame
  1523. {
  1524. image = 0;
  1525. }
  1526. break;
  1527. }
  1528. }
  1529. }
  1530. void CBattleHero::activate()
  1531. {
  1532. ClickableL::activate();
  1533. }
  1534. void CBattleHero::deactivate()
  1535. {
  1536. ClickableL::deactivate();
  1537. }
  1538. void CBattleHero::setPhase(int newPhase)
  1539. {
  1540. phase = newPhase;
  1541. image = 0;
  1542. }
  1543. void CBattleHero::clickLeft(boost::logic::tribool down)
  1544. {
  1545. if(!down && myHero)
  1546. {
  1547. for(int it=0; it<187; ++it) //do nothing when any hex is hovered - hero's animation overlaps battlefield
  1548. {
  1549. if(myOwner->bfield[it].hovered && myOwner->bfield[it].strictHovered)
  1550. return;
  1551. }
  1552. CGI->curh->changeGraphic(0,0);
  1553. LOCPLINT->curint->deactivate();
  1554. CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, 90, 2), myHero);
  1555. spellWindow->activate();
  1556. LOCPLINT->objsToBlit.push_back(spellWindow);
  1557. }
  1558. }
  1559. CBattleHero::CBattleHero(const std::string & defName, int phaseG, int imageG, bool flipG, unsigned char player, const CGHeroInstance * hero, const CBattleInterface * owner): phase(phaseG), image(imageG), flip(flipG), flagAnim(0), myHero(hero), myOwner(owner)
  1560. {
  1561. dh = CDefHandler::giveDef( defName );
  1562. for(int i=0; i<dh->ourImages.size(); ++i) //transforming images
  1563. {
  1564. if(flip)
  1565. {
  1566. SDL_Surface * hlp = CSDL_Ext::rotate01(dh->ourImages[i].bitmap);
  1567. SDL_FreeSurface(dh->ourImages[i].bitmap);
  1568. dh->ourImages[i].bitmap = hlp;
  1569. }
  1570. dh->ourImages[i].bitmap = CSDL_Ext::alphaTransform(dh->ourImages[i].bitmap);
  1571. }
  1572. dh->alphaTransformed = true;
  1573. if(flip)
  1574. flag = CDefHandler::giveDef("CMFLAGR.DEF");
  1575. else
  1576. flag = CDefHandler::giveDef("CMFLAGL.DEF");
  1577. //coloring flag and adding transparency
  1578. for(int i=0; i<flag->ourImages.size(); ++i)
  1579. {
  1580. flag->ourImages[i].bitmap = CSDL_Ext::alphaTransform(flag->ourImages[i].bitmap);
  1581. graphics->blueToPlayersAdv(flag->ourImages[i].bitmap, player);
  1582. }
  1583. }
  1584. CBattleHero::~CBattleHero()
  1585. {
  1586. delete dh;
  1587. delete flag;
  1588. }
  1589. std::pair<int, int> CBattleHex::getXYUnitAnim(const int & hexNum, const bool & attacker, const CCreature * creature)
  1590. {
  1591. std::pair<int, int> ret = std::make_pair(-500, -500); //returned value
  1592. ret.second = -139 + 42 * (hexNum/17); //counting y
  1593. //counting x
  1594. if(attacker)
  1595. {
  1596. ret.first = -160 + 22 * ( ((hexNum/17) + 1)%2 ) + 44 * (hexNum % 17);
  1597. }
  1598. else
  1599. {
  1600. ret.first = -219 + 22 * ( ((hexNum/17) + 1)%2 ) + 44 * (hexNum % 17);
  1601. }
  1602. //shifting position for double - hex creatures
  1603. if(creature && creature->isDoubleWide())
  1604. {
  1605. if(attacker)
  1606. {
  1607. ret.first -= 42;
  1608. }
  1609. else
  1610. {
  1611. ret.first += 42;
  1612. }
  1613. }
  1614. //returning
  1615. return ret;
  1616. }
  1617. void CBattleHex::activate()
  1618. {
  1619. Hoverable::activate();
  1620. MotionInterested::activate();
  1621. ClickableL::activate();
  1622. ClickableR::activate();
  1623. }
  1624. void CBattleHex::deactivate()
  1625. {
  1626. Hoverable::deactivate();
  1627. MotionInterested::deactivate();
  1628. ClickableL::deactivate();
  1629. ClickableR::deactivate();
  1630. }
  1631. void CBattleHex::hover(bool on)
  1632. {
  1633. hovered = on;
  1634. Hoverable::hover(on);
  1635. if(!on && setAlterText)
  1636. {
  1637. myInterface->console->alterTxt = std::string();
  1638. setAlterText = false;
  1639. }
  1640. }
  1641. CBattleHex::CBattleHex() : myNumber(-1), accesible(true), hovered(false), strictHovered(false), myInterface(NULL), setAlterText(false)
  1642. {
  1643. }
  1644. void CBattleHex::mouseMoved(const SDL_MouseMotionEvent &sEvent)
  1645. {
  1646. if(myInterface->cellShade)
  1647. {
  1648. if(CSDL_Ext::SDL_GetPixel(myInterface->cellShade, sEvent.x-pos.x, sEvent.y-pos.y) == 0) //hovered pixel is outside hex
  1649. {
  1650. strictHovered = false;
  1651. }
  1652. else //hovered pixel is inside hex
  1653. {
  1654. strictHovered = true;
  1655. }
  1656. }
  1657. if(hovered && strictHovered) //print attacked creature to console
  1658. {
  1659. if(myInterface->console->alterTxt.size() == 0 && LOCPLINT->cb->battleGetStack(myNumber) != -1 &&
  1660. LOCPLINT->cb->battleGetStackByPos(myNumber)->owner != LOCPLINT->playerID &&
  1661. LOCPLINT->cb->battleGetStackByPos(myNumber)->alive())
  1662. {
  1663. char tabh[160];
  1664. CStack attackedStack = *LOCPLINT->cb->battleGetStackByPos(myNumber);
  1665. const std::string & attackedName = attackedStack.amount == 1 ? attackedStack.creature->nameSing : attackedStack.creature->namePl;
  1666. sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str());
  1667. myInterface->console->alterTxt = std::string(tabh);
  1668. setAlterText = true;
  1669. }
  1670. }
  1671. else if(setAlterText)
  1672. {
  1673. myInterface->console->alterTxt = std::string();
  1674. setAlterText = false;
  1675. }
  1676. }
  1677. void CBattleHex::clickLeft(boost::logic::tribool down)
  1678. {
  1679. if(!down && hovered && strictHovered) //we've been really clicked!
  1680. {
  1681. myInterface->hexLclicked(myNumber);
  1682. }
  1683. }
  1684. void CBattleHex::clickRight(boost::logic::tribool down)
  1685. {
  1686. int stID = LOCPLINT->cb->battleGetStack(myNumber); //id of stack being on this tile
  1687. if(hovered && strictHovered && stID!=-1)
  1688. {
  1689. CStack myst = *LOCPLINT->cb->battleGetStackByID(stID); //stack info
  1690. if(!myst.alive()) return;
  1691. StackState *pom = NULL;
  1692. if(down)
  1693. {
  1694. pom = new StackState();
  1695. const CGHeroInstance *h = myst.owner == myInterface->attackingHeroInstance->tempOwner ? myInterface->attackingHeroInstance : myInterface->defendingHeroInstance;
  1696. if(h)
  1697. {
  1698. pom->attackBonus = h->getPrimSkillLevel(0);
  1699. pom->defenseBonus = h->getPrimSkillLevel(1);
  1700. pom->luck = h->getCurrentLuck();
  1701. pom->morale = h->getCurrentMorale();
  1702. pom->shotsLeft = myst.shots;
  1703. }
  1704. pom->currentHealth = myst.firstHPleft;
  1705. (new CCreInfoWindow(myst.creature->idNumber,0,myst.amount,pom,boost::function<void()>(),boost::function<void()>(),NULL))
  1706. ->activate();
  1707. }
  1708. delete pom;
  1709. }
  1710. }
  1711. CBattleConsole::CBattleConsole() : lastShown(-1), alterTxt("")
  1712. {
  1713. }
  1714. CBattleConsole::~CBattleConsole()
  1715. {
  1716. texts.clear();
  1717. }
  1718. void CBattleConsole::show(SDL_Surface * to)
  1719. {
  1720. if(alterTxt.size())
  1721. {
  1722. CSDL_Ext::printAtMiddleWB(alterTxt, pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to);
  1723. }
  1724. else if(texts.size())
  1725. {
  1726. if(texts.size()==1)
  1727. {
  1728. CSDL_Ext::printAtMiddleWB(texts[0], pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to);
  1729. }
  1730. else
  1731. {
  1732. CSDL_Ext::printAtMiddleWB(texts[lastShown-1], pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to);
  1733. CSDL_Ext::printAtMiddleWB(texts[lastShown], pos.x + pos.w/2, pos.y + 26, GEOR13, 80, zwykly, to);
  1734. }
  1735. }
  1736. }
  1737. bool CBattleConsole::addText(const std::string & text)
  1738. {
  1739. if(text.size()>70)
  1740. return false; //text too long!
  1741. int firstInToken = 0;
  1742. for(int i=0; i<text.size(); ++i) //tokenize
  1743. {
  1744. if(text[i] == 10)
  1745. {
  1746. texts.push_back( text.substr(firstInToken, i-firstInToken) );
  1747. firstInToken = i+1;
  1748. }
  1749. }
  1750. texts.push_back( text.substr(firstInToken, text.size()) );
  1751. lastShown = texts.size()-1;
  1752. return true;
  1753. }
  1754. void CBattleConsole::eraseText(unsigned int pos)
  1755. {
  1756. if(pos < texts.size())
  1757. {
  1758. texts.erase(texts.begin() + pos);
  1759. if(lastShown == texts.size())
  1760. --lastShown;
  1761. }
  1762. }
  1763. void CBattleConsole::changeTextAt(const std::string & text, unsigned int pos)
  1764. {
  1765. if(pos >= texts.size()) //no such pos
  1766. return;
  1767. texts[pos] = text;
  1768. }
  1769. void CBattleConsole::scrollUp(unsigned int by)
  1770. {
  1771. if(lastShown > by)
  1772. lastShown -= by;
  1773. }
  1774. void CBattleConsole::scrollDown(unsigned int by)
  1775. {
  1776. if(lastShown + by < texts.size())
  1777. lastShown += by;
  1778. }
  1779. CBattleReslutWindow::CBattleReslutWindow(const BattleResult &br, const SDL_Rect & pos, const CBattleInterface * owner)
  1780. {
  1781. this->pos = pos;
  1782. background = BitmapHandler::loadBitmap("CPRESULT.BMP", true);
  1783. graphics->blueToPlayersAdv(background, LOCPLINT->playerID);
  1784. SDL_Surface * pom = SDL_ConvertSurface(background, screen->format, screen->flags);
  1785. SDL_FreeSurface(background);
  1786. background = pom;
  1787. exit = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleReslutWindow::bExitf,this), 549, 524, "iok6432.def", SDLK_RETURN);
  1788. if(br.winner==0) //attacker won
  1789. {
  1790. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 60, 122, GEOR13, zwykly, background);
  1791. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 410, 122, GEOR13, zwykly, background);
  1792. }
  1793. else //if(br.winner==1)
  1794. {
  1795. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 60, 122, GEOR13, zwykly, background);
  1796. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 410, 122, GEOR13, zwykly, background);
  1797. }
  1798. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[407], 235, 299, GEOR16, tytulowy, background);
  1799. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[408], 235, 329, GEOR16, zwykly, background);
  1800. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[409], 235, 426, GEOR16, zwykly, background);
  1801. std::string attackerName, defenderName;
  1802. if(owner->attackingHeroInstance) //a hero attacked
  1803. {
  1804. SDL_BlitSurface(graphics->portraitLarge[owner->attackingHeroInstance->portrait], NULL, background, &genRect(64, 58, 21, 38));
  1805. //setting attackerName
  1806. attackerName = owner->attackingHeroInstance->name;
  1807. }
  1808. else //a monster attacked
  1809. {
  1810. int bestMonsterID = -1;
  1811. int bestPower = 0;
  1812. for(std::map<si32,std::pair<ui32,si32> >::const_iterator it = owner->army1->slots.begin(); it!=owner->army1->slots.end(); ++it)
  1813. {
  1814. if( CGI->creh->creatures[it->first].AIValue > bestPower)
  1815. {
  1816. bestPower = CGI->creh->creatures[it->first].AIValue;
  1817. bestMonsterID = it->first;
  1818. }
  1819. }
  1820. SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &genRect(64, 58, 21, 38));
  1821. //setting attackerName
  1822. attackerName = CGI->creh->creatures[bestMonsterID].namePl;
  1823. }
  1824. if(owner->defendingHeroInstance) //a hero defended
  1825. {
  1826. SDL_BlitSurface(graphics->portraitLarge[owner->defendingHeroInstance->portrait], NULL, background, &genRect(64, 58, 391, 38));
  1827. //setting defenderName
  1828. defenderName = owner->defendingHeroInstance->name;
  1829. }
  1830. else //a monster defended
  1831. {
  1832. int bestMonsterID = -1;
  1833. int bestPower = 0;
  1834. for(std::map<si32,std::pair<ui32,si32> >::const_iterator it = owner->army2->slots.begin(); it!=owner->army2->slots.end(); ++it)
  1835. {
  1836. if( CGI->creh->creatures[it->second.first].AIValue > bestPower)
  1837. {
  1838. bestPower = CGI->creh->creatures[it->second.first].AIValue;
  1839. bestMonsterID = it->second.first;
  1840. }
  1841. }
  1842. SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &genRect(64, 58, 391, 38));
  1843. //setting defenderName
  1844. defenderName = CGI->creh->creatures[bestMonsterID].namePl;
  1845. }
  1846. //printing attacker and defender's names
  1847. CSDL_Ext::printAtMiddle(attackerName, 156, 44, GEOR16, zwykly, background);
  1848. CSDL_Ext::printAtMiddle(defenderName, 314, 44, GEOR16, zwykly, background);
  1849. //printing casualities
  1850. for(int step = 0; step < 2; ++step)
  1851. {
  1852. if(br.casualties[step].size()==0)
  1853. {
  1854. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[523], 235, 360 + 97*step, GEOR16, zwykly, background);
  1855. }
  1856. else
  1857. {
  1858. int xPos = 235 - (br.casualties[step].size()*32 + (br.casualties[step].size() - 1)*10)/2; //increment by 42 with each picture
  1859. int yPos = 344 + step*97;
  1860. for(std::set<std::pair<ui32,si32> >::const_iterator it=br.casualties[step].begin(); it!=br.casualties[step].end(); ++it)
  1861. {
  1862. blitAt(graphics->smallImgs[it->first], xPos, yPos, background);
  1863. std::stringstream amount;
  1864. amount<<it->second;
  1865. CSDL_Ext::printAtMiddle(amount.str(), xPos+16, yPos + 42, GEOR13, zwykly, background);
  1866. xPos += 42;
  1867. }
  1868. }
  1869. }
  1870. //printing result description
  1871. bool weAreAttacker = (LOCPLINT->playerID == owner->attackingHeroInstance->tempOwner);
  1872. switch(br.result)
  1873. {
  1874. case 0: //normal victory
  1875. if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won
  1876. {
  1877. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[304], 235, 235, GEOR13, zwykly, background);
  1878. }
  1879. else
  1880. {
  1881. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[311], 235, 235, GEOR13, zwykly, background);
  1882. }
  1883. break;
  1884. case 1: //flee
  1885. if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won
  1886. {
  1887. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[303], 235, 235, GEOR13, zwykly, background);
  1888. }
  1889. else
  1890. {
  1891. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[310], 235, 235, GEOR13, zwykly, background);
  1892. }
  1893. break;
  1894. case 2: //surrender
  1895. if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won
  1896. {
  1897. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[302], 235, 235, GEOR13, zwykly, background);
  1898. }
  1899. else
  1900. {
  1901. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[309], 235, 235, GEOR13, zwykly, background);
  1902. }
  1903. break;
  1904. }
  1905. }
  1906. CBattleReslutWindow::~CBattleReslutWindow()
  1907. {
  1908. SDL_FreeSurface(background);
  1909. }
  1910. void CBattleReslutWindow::activate()
  1911. {
  1912. LOCPLINT->showingDialog->set(true);
  1913. exit->activate();
  1914. }
  1915. void CBattleReslutWindow::deactivate()
  1916. {
  1917. exit->deactivate();
  1918. }
  1919. void CBattleReslutWindow::show(SDL_Surface *to)
  1920. {
  1921. //evaluating to
  1922. if(!to)
  1923. to = screen;
  1924. SDL_BlitSurface(background, NULL, to, &pos);
  1925. exit->show(to);
  1926. }
  1927. void CBattleReslutWindow::bExitf()
  1928. {
  1929. LOCPLINT->battleResultQuited();
  1930. }
  1931. CBattleOptionsWindow::CBattleOptionsWindow(const SDL_Rect & position, CBattleInterface *owner): myInt(owner)
  1932. {
  1933. pos = position;
  1934. background = BitmapHandler::loadBitmap("comopbck.bmp", true);
  1935. graphics->blueToPlayersAdv(background, LOCPLINT->playerID);
  1936. viewGrid = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintCellBorders, owner, true), boost::bind(&CBattleInterface::setPrintCellBorders, owner, false), boost::assign::map_list_of(0,CGI->preth->zelp[427].first)(3,CGI->preth->zelp[427].first), CGI->preth->zelp[427].second, false, "sysopchk.def", NULL, 185, 140, false);
  1937. viewGrid->select(owner->printCellBorders);
  1938. movementShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintStackRange, owner, true), boost::bind(&CBattleInterface::setPrintStackRange, owner, false), boost::assign::map_list_of(0,CGI->preth->zelp[428].first)(3,CGI->preth->zelp[428].first), CGI->preth->zelp[428].second, false, "sysopchk.def", NULL, 185, 173, false);
  1939. movementShadow->select(owner->printStackRange);
  1940. mouseShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintMouseShadow, owner, true), boost::bind(&CBattleInterface::setPrintMouseShadow, owner, false), boost::assign::map_list_of(0,CGI->preth->zelp[429].first)(3,CGI->preth->zelp[429].first), CGI->preth->zelp[429].second, false, "sysopchk.def", NULL, 185, 207, false);
  1941. mouseShadow->select(owner->printMouseShadow);
  1942. animSpeeds = new CHighlightableButtonsGroup(0);
  1943. animSpeeds->addButton(boost::assign::map_list_of(0,CGI->preth->zelp[422].first),CGI->preth->zelp[422].second, "sysopb9.def",188, 309, 1);
  1944. animSpeeds->addButton(boost::assign::map_list_of(0,CGI->preth->zelp[423].first),CGI->preth->zelp[423].second, "sysob10.def",252, 309, 2);
  1945. animSpeeds->addButton(boost::assign::map_list_of(0,CGI->preth->zelp[424].first),CGI->preth->zelp[424].second, "sysob11.def",315, 309, 4);
  1946. animSpeeds->select(owner->getAnimSpeed(), 1);
  1947. animSpeeds->onChange = boost::bind(&CBattleInterface::setAnimSpeed, owner, _1);
  1948. setToDefault = new AdventureMapButton (CGI->preth->zelp[392].first, CGI->preth->zelp[392].second, boost::bind(&CBattleOptionsWindow::bDefaultf,this), 405, 443, "codefaul.def");
  1949. std::swap(setToDefault->imgs[0][0], setToDefault->imgs[0][1]);
  1950. exit = new AdventureMapButton (CGI->preth->zelp[393].first, CGI->preth->zelp[393].second, boost::bind(&CBattleOptionsWindow::bExitf,this), 516, 443, "soretrn.def",SDLK_RETURN);
  1951. std::swap(exit->imgs[0][0], exit->imgs[0][1]);
  1952. //printing texts to background
  1953. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[392], 240, 32, GEOR16, tytulowy, background); //window title
  1954. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[393], 122, 211, GEOR16, tytulowy, background); //animation speed
  1955. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[394], 122, 292, GEOR16, tytulowy, background); //music volume
  1956. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[395], 122, 358, GEOR16, tytulowy, background); //effects' volume
  1957. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[396], 353, 64, GEOR16, tytulowy, background); //auto - combat options
  1958. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[397], 353, 264, GEOR16, tytulowy, background); //creature info
  1959. //auto - combat options
  1960. CSDL_Ext::printAt(CGI->generaltexth->allTexts[398], 283, 87, GEOR16, zwykly, background); //creatures
  1961. CSDL_Ext::printAt(CGI->generaltexth->allTexts[399], 283, 117, GEOR16, zwykly, background); //spells
  1962. CSDL_Ext::printAt(CGI->generaltexth->allTexts[400], 283, 147, GEOR16, zwykly, background); //catapult
  1963. CSDL_Ext::printAt(CGI->generaltexth->allTexts[151], 283, 177, GEOR16, zwykly, background); //ballista
  1964. CSDL_Ext::printAt(CGI->generaltexth->allTexts[401], 283, 207, GEOR16, zwykly, background); //first aid tent
  1965. //creature info
  1966. CSDL_Ext::printAt(CGI->generaltexth->allTexts[402], 283, 286, GEOR16, zwykly, background); //all stats
  1967. CSDL_Ext::printAt(CGI->generaltexth->allTexts[403], 283, 316, GEOR16, zwykly, background); //spells only
  1968. //general options
  1969. CSDL_Ext::printAt(CGI->generaltexth->allTexts[404], 61, 58, GEOR16, zwykly, background); //hex grid
  1970. CSDL_Ext::printAt(CGI->generaltexth->allTexts[405], 61, 91, GEOR16, zwykly, background); //movement shadow
  1971. CSDL_Ext::printAt(CGI->generaltexth->allTexts[406], 61, 124, GEOR16, zwykly, background); //cursor shadow
  1972. CSDL_Ext::printAt(CGI->generaltexth->allTexts[577], 61, 157, GEOR16, zwykly, background); //spellbook animation
  1973. //texts printed
  1974. }
  1975. CBattleOptionsWindow::~CBattleOptionsWindow()
  1976. {
  1977. SDL_FreeSurface(background);
  1978. delete setToDefault;
  1979. delete exit;
  1980. delete viewGrid;
  1981. delete movementShadow;
  1982. delete animSpeeds;
  1983. delete mouseShadow;
  1984. }
  1985. void CBattleOptionsWindow::activate()
  1986. {
  1987. setToDefault->activate();
  1988. exit->activate();
  1989. viewGrid->activate();
  1990. movementShadow->activate();
  1991. animSpeeds->activate();
  1992. mouseShadow->activate();
  1993. }
  1994. void CBattleOptionsWindow::deactivate()
  1995. {
  1996. setToDefault->deactivate();
  1997. exit->deactivate();
  1998. viewGrid->deactivate();
  1999. movementShadow->deactivate();
  2000. animSpeeds->deactivate();
  2001. mouseShadow->deactivate();
  2002. }
  2003. void CBattleOptionsWindow::show(SDL_Surface *to)
  2004. {
  2005. if(!to) //"evaluating" to
  2006. to = screen;
  2007. SDL_BlitSurface(background, NULL, to, &pos);
  2008. setToDefault->show(to);
  2009. exit->show(to);
  2010. viewGrid->show(to);
  2011. movementShadow->show(to);
  2012. animSpeeds->show(to);
  2013. mouseShadow->show(to);
  2014. }
  2015. void CBattleOptionsWindow::bDefaultf()
  2016. {
  2017. }
  2018. void CBattleOptionsWindow::bExitf()
  2019. {
  2020. deactivate();
  2021. for(int g=0; g<LOCPLINT->objsToBlit.size(); ++g)
  2022. {
  2023. if(dynamic_cast<CBattleOptionsWindow*>(LOCPLINT->objsToBlit[g]))
  2024. {
  2025. LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+g);
  2026. break;
  2027. }
  2028. }
  2029. delete this;
  2030. LOCPLINT->curint->activate();
  2031. }