CBattleInterface.cpp 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744
  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 "hch/CSpellHandler.h"
  11. #include "CMessage.h"
  12. #include "CCursorHandler.h"
  13. #include "CCallback.h"
  14. #include "CGameState.h"
  15. #include "hch/CGeneralTextHandler.h"
  16. #include "client/CCreatureAnimation.h"
  17. #include "client/Graphics.h"
  18. #include "client/CSpellWindow.h"
  19. #include "client/CConfigHandler.h"
  20. #include <queue>
  21. #include <sstream>
  22. #include "lib/CondSh.h"
  23. #include "lib/NetPacks.h"
  24. #include <boost/assign/list_of.hpp>
  25. #ifndef __GNUC__
  26. const double M_PI = 3.14159265358979323846;
  27. #else
  28. #define _USE_MATH_DEFINES
  29. #include <cmath>
  30. #endif
  31. extern SDL_Surface * screen;
  32. extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16;
  33. extern SDL_Color zwykly;
  34. struct CMP_stack2
  35. {
  36. inline bool operator ()(const CStack& a, const CStack& b)
  37. {
  38. return (a.speed())>(b.speed());
  39. }
  40. } cmpst2 ;
  41. CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, const SDL_Rect & myRect)
  42. : printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL),
  43. attackingInfo(NULL), myTurn(false), resWindow(NULL), showStackQueue(false), animSpeed(2), printStackRange(true),
  44. printMouseShadow(true), spellDestSelectMode(false), spellToCast(NULL), previouslyHoveredHex(-1)
  45. {
  46. pos = myRect;
  47. strongInterest = true;
  48. givenCommand = new CondSh<BattleAction *>(NULL);
  49. //initializing armies
  50. this->army1 = army1;
  51. this->army2 = army2;
  52. std::map<int, CStack> stacks = LOCPLINT->cb->battleGetStacks();
  53. for(std::map<int, CStack>::iterator b=stacks.begin(); b!=stacks.end(); ++b)
  54. {
  55. std::pair <int, int> coords = CBattleHex::getXYUnitAnim(b->second.position, b->second.owner == attackingHeroInstance->tempOwner, b->second.creature);
  56. creAnims[b->second.ID] = (new CCreatureAnimation(b->second.creature->animDefName));
  57. creAnims[b->second.ID]->setType(2);
  58. creAnims[b->second.ID]->pos = genRect(creAnims[b->second.ID]->fullHeight, creAnims[b->second.ID]->fullWidth, coords.first, coords.second);
  59. creDir[b->second.ID] = b->second.owner==attackingHeroInstance->tempOwner;
  60. }
  61. //preparing menu background and terrain
  62. std::vector< std::string > & backref = graphics->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ];
  63. background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()] );
  64. menu = BitmapHandler::loadBitmap("CBAR.BMP");
  65. graphics->blueToPlayersAdv(menu, hero1->tempOwner);
  66. //preparing graphics for displaying amounts of creatures
  67. amountNormal = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
  68. CSDL_Ext::alphaTransform(amountNormal);
  69. for(int g=0; g<amountNormal->format->palette->ncolors; ++g)
  70. {
  71. if((amountNormal->format->palette->colors+g)->b != 132 &&
  72. (amountNormal->format->palette->colors+g)->g != 231 &&
  73. (amountNormal->format->palette->colors+g)->r != 255) //it's not yellow border
  74. {
  75. (amountNormal->format->palette->colors+g)->r = (float)((amountNormal->format->palette->colors+g)->r) * 0.54f;
  76. (amountNormal->format->palette->colors+g)->g = (float)((amountNormal->format->palette->colors+g)->g) * 0.19f;
  77. (amountNormal->format->palette->colors+g)->b = (float)((amountNormal->format->palette->colors+g)->b) * 0.93f;
  78. }
  79. }
  80. amountPositive = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
  81. CSDL_Ext::alphaTransform(amountPositive);
  82. for(int g=0; g<amountPositive->format->palette->ncolors; ++g)
  83. {
  84. if((amountPositive->format->palette->colors+g)->b != 132 &&
  85. (amountPositive->format->palette->colors+g)->g != 231 &&
  86. (amountPositive->format->palette->colors+g)->r != 255) //it's not yellow border
  87. {
  88. (amountPositive->format->palette->colors+g)->r = (float)((amountPositive->format->palette->colors+g)->r) * 0.18f;
  89. (amountPositive->format->palette->colors+g)->g = (float)((amountPositive->format->palette->colors+g)->g) * 1.00f;
  90. (amountPositive->format->palette->colors+g)->b = (float)((amountPositive->format->palette->colors+g)->b) * 0.18f;
  91. }
  92. }
  93. amountNegative = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
  94. CSDL_Ext::alphaTransform(amountNegative);
  95. for(int g=0; g<amountNegative->format->palette->ncolors; ++g)
  96. {
  97. if((amountNegative->format->palette->colors+g)->b != 132 &&
  98. (amountNegative->format->palette->colors+g)->g != 231 &&
  99. (amountNegative->format->palette->colors+g)->r != 255) //it's not yellow border
  100. {
  101. (amountNegative->format->palette->colors+g)->r = (float)((amountNegative->format->palette->colors+g)->r) * 1.00f;
  102. (amountNegative->format->palette->colors+g)->g = (float)((amountNegative->format->palette->colors+g)->g) * 0.18f;
  103. (amountNegative->format->palette->colors+g)->b = (float)((amountNegative->format->palette->colors+g)->b) * 0.18f;
  104. }
  105. }
  106. amountEffNeutral = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
  107. CSDL_Ext::alphaTransform(amountNegative);
  108. for(int g=0; g<amountNegative->format->palette->ncolors; ++g)
  109. {
  110. if((amountNegative->format->palette->colors+g)->b != 132 &&
  111. (amountNegative->format->palette->colors+g)->g != 231 &&
  112. (amountNegative->format->palette->colors+g)->r != 255) //it's not yellow border
  113. {
  114. (amountNegative->format->palette->colors+g)->r = (float)((amountNegative->format->palette->colors+g)->r) * 1.00f;
  115. (amountNegative->format->palette->colors+g)->g = (float)((amountNegative->format->palette->colors+g)->g) * 1.00f;
  116. (amountNegative->format->palette->colors+g)->b = (float)((amountNegative->format->palette->colors+g)->b) * 0.18f;
  117. }
  118. }
  119. ////blitting menu background and terrain
  120. blitAt(background, pos.x, pos.y);
  121. blitAt(menu, pos.x, 556 + pos.y);
  122. CSDL_Ext::update();
  123. //preparing buttons and console
  124. bOptions = new AdventureMapButton (CGI->generaltexth->zelp[381].first, CGI->generaltexth->zelp[381].second, boost::bind(&CBattleInterface::bOptionsf,this), 3 + pos.x, 561 + pos.y, "icm003.def", SDLK_o);
  125. bSurrender = new AdventureMapButton (CGI->generaltexth->zelp[379].first, CGI->generaltexth->zelp[379].second, boost::bind(&CBattleInterface::bSurrenderf,this), 54 + pos.x, 561 + pos.y, "icm001.def", SDLK_s);
  126. bFlee = new AdventureMapButton (CGI->generaltexth->zelp[380].first, CGI->generaltexth->zelp[380].second, boost::bind(&CBattleInterface::bFleef,this), 105 + pos.x, 561 + pos.y, "icm002.def", SDLK_r);
  127. bAutofight = new AdventureMapButton (CGI->generaltexth->zelp[382].first, CGI->generaltexth->zelp[382].second, boost::bind(&CBattleInterface::bAutofightf,this), 157 + pos.x, 561 + pos.y, "icm004.def", SDLK_a);
  128. bSpell = new AdventureMapButton (CGI->generaltexth->zelp[385].first, CGI->generaltexth->zelp[385].second, boost::bind(&CBattleInterface::bSpellf,this), 645 + pos.x, 561 + pos.y, "icm005.def", SDLK_c);
  129. bWait = new AdventureMapButton (CGI->generaltexth->zelp[386].first, CGI->generaltexth->zelp[386].second, boost::bind(&CBattleInterface::bWaitf,this), 696 + pos.x, 561 + pos.y, "icm006.def", SDLK_w);
  130. bDefence = new AdventureMapButton (CGI->generaltexth->zelp[387].first, CGI->generaltexth->zelp[387].second, boost::bind(&CBattleInterface::bDefencef,this), 747 + pos.x, 561 + pos.y, "icm007.def", SDLK_d);
  131. bDefence->assignedKeys.insert(SDLK_SPACE);
  132. bConsoleUp = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleUpf,this), 624 + pos.x, 561 + pos.y, "ComSlide.def", SDLK_UP);
  133. bConsoleDown = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleDownf,this), 624 + pos.x, 580 + pos.y, "ComSlide.def", SDLK_DOWN);
  134. bConsoleDown->bitmapOffset = 2;
  135. console = new CBattleConsole();
  136. console->pos.x = 211 + pos.x;
  137. console->pos.y = 560 + pos.y;
  138. console->pos.w = 406;
  139. console->pos.h = 38;
  140. //loading hero animations
  141. if(hero1) // attacking hero
  142. {
  143. attackingHero = new CBattleHero(graphics->battleHeroes[hero1->type->heroType], 0, 0, false, hero1->tempOwner, hero1->tempOwner == LOCPLINT->playerID ? hero1 : NULL, this);
  144. attackingHero->pos = genRect(attackingHero->dh->ourImages[0].bitmap->h, attackingHero->dh->ourImages[0].bitmap->w, -40 + pos.x, pos.y);
  145. }
  146. else
  147. {
  148. attackingHero = NULL;
  149. }
  150. if(hero2) // defending hero
  151. {
  152. defendingHero = new CBattleHero(graphics->battleHeroes[hero2->type->heroType], 0, 0, true, hero2->tempOwner, hero2->tempOwner == LOCPLINT->playerID ? hero2 : NULL, this);
  153. defendingHero->pos = genRect(defendingHero->dh->ourImages[0].bitmap->h, defendingHero->dh->ourImages[0].bitmap->w, 690 + pos.x, pos.y);
  154. }
  155. else
  156. {
  157. defendingHero = NULL;
  158. }
  159. //preparing cells and hexes
  160. cellBorder = BitmapHandler::loadBitmap("CCELLGRD.BMP");
  161. CSDL_Ext::alphaTransform(cellBorder);
  162. cellShade = BitmapHandler::loadBitmap("CCELLSHD.BMP");
  163. CSDL_Ext::alphaTransform(cellShade);
  164. for(int h=0; h<BFIELD_SIZE; ++h)
  165. {
  166. bfield[h].myNumber = h;
  167. int x = 14 + ((h/BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(h%BFIELD_WIDTH);
  168. int y = 86 + 42 * (h/BFIELD_WIDTH);
  169. bfield[h].pos = genRect(cellShade->h, cellShade->w, x + pos.x, y + pos.y);
  170. bfield[h].accesible = true;
  171. bfield[h].myInterface = this;
  172. }
  173. //locking occupied positions on batlefield
  174. for(std::map<int, CStack>::iterator it = stacks.begin(); it!=stacks.end(); ++it) //stacks gained at top of this function
  175. {
  176. bfield[it->second.position].accesible = false;
  177. }
  178. //loading projectiles for units
  179. for(std::map<int, CStack>::iterator g = stacks.begin(); g != stacks.end(); ++g)
  180. {
  181. if(g->second.creature->isShooting() && CGI->creh->idToProjectile[g->second.creature->idNumber] != std::string())
  182. {
  183. idToProjectile[g->second.creature->idNumber] = CDefHandler::giveDef(CGI->creh->idToProjectile[g->second.creature->idNumber]);
  184. if(idToProjectile[g->second.creature->idNumber]->ourImages.size() > 2) //add symmetric images
  185. {
  186. for(int k = idToProjectile[g->second.creature->idNumber]->ourImages.size()-2; k > 1; --k)
  187. {
  188. Cimage ci;
  189. ci.bitmap = CSDL_Ext::rotate01(idToProjectile[g->second.creature->idNumber]->ourImages[k].bitmap);
  190. ci.groupNumber = 0;
  191. ci.imName = std::string();
  192. idToProjectile[g->second.creature->idNumber]->ourImages.push_back(ci);
  193. }
  194. }
  195. for(int s=0; s<idToProjectile[g->second.creature->idNumber]->ourImages.size(); ++s) //alpha transforming
  196. {
  197. CSDL_Ext::alphaTransform(idToProjectile[g->second.creature->idNumber]->ourImages[s].bitmap);
  198. }
  199. }
  200. }
  201. //preparing graphic with cell borders
  202. cellBorders = CSDL_Ext::newSurface(background->w, background->h, cellBorder);
  203. //copying palette
  204. for(int g=0; g<cellBorder->format->palette->ncolors; ++g) //we assume that cellBorders->format->palette->ncolors == 256
  205. {
  206. cellBorders->format->palette->colors[g] = cellBorder->format->palette->colors[g];
  207. }
  208. //palette copied
  209. for(int i=0; i<BFIELD_HEIGHT; ++i) //rows
  210. {
  211. for(int j=0; j<BFIELD_WIDTH-2; ++j) //columns
  212. {
  213. int x = 58 + (i%2==0 ? 22 : 0) + 44*j;
  214. int y = 86 + 42 * i;
  215. for(int cellX = 0; cellX < cellBorder->w; ++cellX)
  216. {
  217. for(int cellY = 0; cellY < cellBorder->h; ++cellY)
  218. {
  219. if(y+cellY < cellBorders->h && x+cellX < cellBorders->w)
  220. * ((Uint8*)cellBorders->pixels + (y+cellY) * cellBorders->pitch + (x+cellX)) |= * ((Uint8*)cellBorder->pixels + cellY * cellBorder->pitch + cellX);
  221. }
  222. }
  223. }
  224. }
  225. backgroundWithHexes = CSDL_Ext::newSurface(background->w, background->h, screen);
  226. }
  227. CBattleInterface::~CBattleInterface()
  228. {
  229. SDL_FreeSurface(background);
  230. SDL_FreeSurface(menu);
  231. SDL_FreeSurface(amountNormal);
  232. SDL_FreeSurface(amountNegative);
  233. SDL_FreeSurface(amountPositive);
  234. SDL_FreeSurface(amountEffNeutral);
  235. SDL_FreeSurface(cellBorders);
  236. SDL_FreeSurface(backgroundWithHexes);
  237. delete bOptions;
  238. delete bSurrender;
  239. delete bFlee;
  240. delete bAutofight;
  241. delete bSpell;
  242. delete bWait;
  243. delete bDefence;
  244. delete bConsoleUp;
  245. delete bConsoleDown;
  246. delete console;
  247. delete resWindow;
  248. delete givenCommand;
  249. delete attackingHero;
  250. delete defendingHero;
  251. SDL_FreeSurface(cellBorder);
  252. SDL_FreeSurface(cellShade);
  253. for(std::map< int, CCreatureAnimation * >::iterator g=creAnims.begin(); g!=creAnims.end(); ++g)
  254. delete g->second;
  255. for(std::map< int, CDefHandler * >::iterator g=idToProjectile.begin(); g!=idToProjectile.end(); ++g)
  256. delete g->second;
  257. }
  258. void CBattleInterface::setPrintCellBorders(bool set)
  259. {
  260. printCellBorders = set;
  261. redrawBackgroundWithHexes(activeStack);
  262. }
  263. void CBattleInterface::setPrintStackRange(bool set)
  264. {
  265. printStackRange = set;
  266. redrawBackgroundWithHexes(activeStack);
  267. }
  268. void CBattleInterface::setPrintMouseShadow(bool set)
  269. {
  270. printMouseShadow = set;
  271. }
  272. void CBattleInterface::activate()
  273. {
  274. KeyInterested::activate();
  275. MotionInterested::activate();
  276. subInt = NULL;
  277. bOptions->activate();
  278. bSurrender->activate();
  279. bFlee->activate();
  280. bAutofight->activate();
  281. bSpell->activate();
  282. bWait->activate();
  283. bDefence->activate();
  284. bConsoleUp->activate();
  285. bConsoleDown->activate();
  286. for(int b=0; b<BFIELD_SIZE; ++b)
  287. {
  288. bfield[b].activate();
  289. }
  290. if(attackingHero)
  291. attackingHero->activate();
  292. if(defendingHero)
  293. defendingHero->activate();
  294. }
  295. void CBattleInterface::deactivate()
  296. {
  297. KeyInterested::deactivate();
  298. MotionInterested::deactivate();
  299. bOptions->deactivate();
  300. bSurrender->deactivate();
  301. bFlee->deactivate();
  302. bAutofight->deactivate();
  303. bSpell->deactivate();
  304. bWait->deactivate();
  305. bDefence->deactivate();
  306. bConsoleUp->deactivate();
  307. bConsoleDown->deactivate();
  308. for(int b=0; b<BFIELD_SIZE; ++b)
  309. {
  310. bfield[b].deactivate();
  311. }
  312. if(attackingHero)
  313. attackingHero->deactivate();
  314. if(defendingHero)
  315. defendingHero->deactivate();
  316. }
  317. void CBattleInterface::show(SDL_Surface * to)
  318. {
  319. std::map<int, CStack> stacks = LOCPLINT->cb->battleGetStacks(); //used in a few places
  320. ++animCount;
  321. if(!to) //"evaluating" to
  322. to = screen;
  323. SDL_Rect buf;
  324. SDL_GetClipRect(to, &buf);
  325. SDL_SetClipRect(to, &pos);
  326. //printing background and hexes
  327. if(activeStack != -1 && creAnims[activeStack]->getType() != 0) //show everything with range
  328. {
  329. blitAt(backgroundWithHexes, pos.x, pos.y, to);
  330. }
  331. else
  332. {
  333. //showing background
  334. blitAt(background, pos.x, pos.y, to);
  335. if(printCellBorders)
  336. {
  337. CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, to, &pos);
  338. }
  339. }
  340. //printing hovered cell
  341. for(int b=0; b<BFIELD_SIZE; ++b)
  342. {
  343. if(bfield[b].strictHovered && bfield[b].hovered)
  344. {
  345. if(previouslyHoveredHex == -1) previouslyHoveredHex = b; //something to start with
  346. if(currentlyHoveredHex == -1) currentlyHoveredHex = b; //something to start with
  347. if(currentlyHoveredHex != b) //repair hover info
  348. {
  349. previouslyHoveredHex = currentlyHoveredHex;
  350. currentlyHoveredHex = b;
  351. }
  352. //print shade
  353. if(printMouseShadow)
  354. {
  355. int x = 14 + ((b/BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(b%BFIELD_WIDTH) + pos.x;
  356. int y = 86 + 42 * (b/BFIELD_WIDTH) + pos.y;
  357. CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, NULL, to, &genRect(cellShade->h, cellShade->w, x, y));
  358. }
  359. }
  360. }
  361. SDL_SetClipRect(to, &buf); //restoring previous clip_rect
  362. //showing menu background and console
  363. blitAt(menu, pos.x, 556 + pos.y, to);
  364. console->show(to);
  365. //showing buttons
  366. bOptions->show(to);
  367. bSurrender->show(to);
  368. bFlee->show(to);
  369. bAutofight->show(to);
  370. bSpell->show(to);
  371. bWait->show(to);
  372. bDefence->show(to);
  373. bConsoleUp->show(to);
  374. bConsoleDown->show(to);
  375. SDL_GetClipRect(to, &buf);
  376. SDL_SetClipRect(to, &pos);
  377. //showing hero animations
  378. if(attackingHero)
  379. attackingHero->show(to);
  380. if(defendingHero)
  381. defendingHero->show(to);
  382. ////showing units //a lot of work...
  383. std::vector<int> stackAliveByHex[BFIELD_SIZE];
  384. //double loop because dead stacks should be printed first
  385. for(std::map<int, CStack>::iterator j=stacks.begin(); j!=stacks.end(); ++j)
  386. {
  387. if(j->second.alive())
  388. stackAliveByHex[j->second.position].push_back(j->second.ID);
  389. }
  390. std::vector<int> stackDeadByHex[BFIELD_SIZE];
  391. for(std::map<int, CStack>::iterator j=stacks.begin(); j!=stacks.end(); ++j)
  392. {
  393. if(!j->second.alive())
  394. stackDeadByHex[j->second.position].push_back(j->second.ID);
  395. }
  396. attackingShowHelper(); // handle attack animation
  397. for(int b=0; b<BFIELD_SIZE; ++b) //showing dead stacks
  398. {
  399. for(size_t v=0; v<stackDeadByHex[b].size(); ++v)
  400. {
  401. creAnims[stackDeadByHex[b][v]]->nextFrame(to, creAnims[stackDeadByHex[b][v]]->pos.x + pos.x, creAnims[stackDeadByHex[b][v]]->pos.y + pos.y, creDir[stackDeadByHex[b][v]], false, stackDeadByHex[b][v]==activeStack); //increment always when moving, never if stack died
  402. }
  403. }
  404. for(int b=0; b<BFIELD_SIZE; ++b) //showing alive stacks
  405. {
  406. for(size_t v=0; v<stackAliveByHex[b].size(); ++v)
  407. {
  408. int animType = creAnims[stackAliveByHex[b][v]]->getType();
  409. bool incrementFrame = (animCount%(4/animSpeed)==0) && animType!=0 && animType!=5 && animType!=20 && animType!=21 && animType!=3;
  410. creAnims[stackAliveByHex[b][v]]->nextFrame(to, creAnims[stackAliveByHex[b][v]]->pos.x + pos.x, creAnims[stackAliveByHex[b][v]]->pos.y + pos.y, creDir[stackAliveByHex[b][v]], incrementFrame, stackAliveByHex[b][v]==activeStack); //increment always when moving, never if stack died
  411. //printing amount
  412. if(stacks[stackAliveByHex[b][v]].amount > 0) //don't print if stack is not alive
  413. {
  414. int xAdd = stacks[stackAliveByHex[b][v]].attackerOwned ? 220 : 202;
  415. //blitting amoutn background box
  416. SDL_Surface *amountBG = NULL;
  417. if(stacks[stackAliveByHex[b][v]].effects.size() == 0)
  418. {
  419. amountBG = amountNormal;
  420. }
  421. else
  422. {
  423. int pos=0; //determining total positiveness of effects
  424. for(int c=0; c<stacks[stackAliveByHex[b][v]].effects.size(); ++c)
  425. {
  426. pos += CGI->spellh->spells[ stacks[stackAliveByHex[b][v]].effects[c].id ].positiveness;
  427. }
  428. if(pos > 0)
  429. {
  430. amountBG = amountPositive;
  431. }
  432. else if(pos < 0)
  433. {
  434. amountBG = amountNegative;
  435. }
  436. else
  437. {
  438. amountBG = amountEffNeutral;
  439. }
  440. }
  441. SDL_BlitSurface(amountBG, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackAliveByHex[b][v]]->pos.x + xAdd + pos.x, creAnims[stackAliveByHex[b][v]]->pos.y + 260 + pos.y));
  442. //blitting amount
  443. std::stringstream ss;
  444. ss<<stacks[stackAliveByHex[b][v]].amount;
  445. CSDL_Ext::printAtMiddleWB(
  446. ss.str(),
  447. creAnims[stackAliveByHex[b][v]]->pos.x + xAdd + 14 + pos.x,
  448. creAnims[stackAliveByHex[b][v]]->pos.y + 260 + 4 + pos.y,
  449. GEOR13,
  450. 20,
  451. zwykly,
  452. to
  453. );
  454. }
  455. }
  456. }
  457. //units shown
  458. projectileShowHelper(to);//showing projectiles
  459. //showing spell effects
  460. if(battleEffects.size())
  461. {
  462. std::vector< std::list<SBattleEffect>::iterator > toErase;
  463. for(std::list<SBattleEffect>::iterator it = battleEffects.begin(); it!=battleEffects.end(); ++it)
  464. {
  465. SDL_Surface * bitmapToBlit = it->anim->ourImages[(it->frame)%it->anim->ourImages.size()].bitmap;
  466. SDL_BlitSurface(bitmapToBlit, NULL, to, &genRect(bitmapToBlit->h, bitmapToBlit->w, pos.x + it->x, pos.y + it->y));
  467. ++(it->frame);
  468. if(it->frame == it->maxFrame)
  469. {
  470. toErase.push_back(it);
  471. }
  472. }
  473. for(size_t b=0; b<toErase.size(); ++b)
  474. {
  475. delete toErase[b]->anim;
  476. battleEffects.erase(toErase[b]);
  477. }
  478. }
  479. //showing queue of stacks
  480. if(showStackQueue)
  481. {
  482. int xPos = screen->w/2 - ( stacks.size() * 37 )/2;
  483. int yPos = (screen->h - 600)/2 + 10;
  484. std::vector<CStack> stacksSorted;
  485. stacksSorted = LOCPLINT->cb->battleGetStackQueue();
  486. int startFrom = -1;
  487. for(size_t n=0; n<stacksSorted.size(); ++n)
  488. {
  489. if(stacksSorted[n].ID == activeStack)
  490. {
  491. startFrom = n;
  492. break;
  493. }
  494. }
  495. if(startFrom != -1)
  496. {
  497. for(size_t b=startFrom; b<stacksSorted.size()+startFrom; ++b)
  498. {
  499. SDL_BlitSurface(graphics->smallImgs[-2], NULL, to, &genRect(32, 32, xPos, yPos));
  500. //printing colored border
  501. for(int xFrom = xPos-1; xFrom<xPos+33; ++xFrom)
  502. {
  503. for(int yFrom = yPos-1; yFrom<yPos+33; ++yFrom)
  504. {
  505. if(xFrom == xPos-1 || xFrom == xPos+32 || yFrom == yPos-1 || yFrom == yPos+32)
  506. {
  507. SDL_Color pc;
  508. if(stacksSorted[b % stacksSorted.size()].owner != 255)
  509. {
  510. pc = graphics->playerColors[stacksSorted[b % stacksSorted.size()].owner];
  511. }
  512. else
  513. {
  514. pc = *graphics->neutralColor;
  515. }
  516. CSDL_Ext::SDL_PutPixelWithoutRefresh(to, xFrom, yFrom, pc.r, pc.g, pc.b);
  517. }
  518. }
  519. }
  520. //colored border printed
  521. SDL_BlitSurface(graphics->smallImgs[stacksSorted[b % stacksSorted.size()].creature->idNumber], NULL, to, &genRect(32, 32, xPos, yPos));
  522. xPos += 37;
  523. }
  524. }
  525. }
  526. SDL_SetClipRect(to, &buf); //restoring previous clip_rect
  527. //showing window with result of battle
  528. if(resWindow)
  529. {
  530. resWindow->show(to);
  531. }
  532. //printing border around interface
  533. if(screen->w != 800 || screen->h !=600)
  534. CMessage::drawBorder(LOCPLINT->playerID,to,828,628,pos.x-14,pos.y-15);
  535. }
  536. void CBattleInterface::keyPressed(const SDL_KeyboardEvent & key)
  537. {
  538. if(key.keysym.sym == SDLK_q)
  539. {
  540. showStackQueue = key.state==SDL_PRESSED;
  541. }
  542. }
  543. void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
  544. {
  545. if(activeStack>=0 && !spellDestSelectMode)
  546. {
  547. int myNumber = -1; //number of hovered tile
  548. for(int g=0; g<BFIELD_SIZE; ++g)
  549. {
  550. if(bfield[g].hovered && bfield[g].strictHovered)
  551. {
  552. myNumber = g;
  553. break;
  554. }
  555. }
  556. if(myNumber == -1)
  557. {
  558. CGI->curh->changeGraphic(1, 6);
  559. if(console->whoSetAlter == 0)
  560. {
  561. console->alterTxt = "";
  562. }
  563. }
  564. else
  565. {
  566. if(std::find(shadedHexes.begin(),shadedHexes.end(),myNumber) == shadedHexes.end())
  567. {
  568. CStack *shere = LOCPLINT->cb->battleGetStackByPos(myNumber);
  569. CStack *sactive = LOCPLINT->cb->battleGetStackByID(activeStack);
  570. if(shere)
  571. {
  572. if(shere->owner == LOCPLINT->playerID) //our stack
  573. {
  574. CGI->curh->changeGraphic(1,5);
  575. //setting console text
  576. char buf[500];
  577. sprintf(buf, CGI->generaltexth->allTexts[297].c_str(), shere->amount == 1 ? shere->creature->nameSing.c_str() : shere->creature->namePl.c_str());
  578. console->alterTxt = buf;
  579. console->whoSetAlter = 0;
  580. }
  581. else if(LOCPLINT->cb->battleCanShoot(activeStack,myNumber)) //we can shoot enemy
  582. {
  583. CGI->curh->changeGraphic(1,3);
  584. //setting console text
  585. char buf[500];
  586. sprintf(buf, CGI->generaltexth->allTexts[296].c_str(), shere->amount == 1 ? shere->creature->nameSing.c_str() : shere->creature->namePl.c_str(), sactive->shots, "?");
  587. console->alterTxt = buf;
  588. console->whoSetAlter = 0;
  589. }
  590. else if(isTileAttackable(myNumber)) //available enemy (melee attackable)
  591. {
  592. int fromHex = previouslyHoveredHex;
  593. if(fromHex!=-1 && fromHex%BFIELD_WIDTH!=0 && fromHex%BFIELD_WIDTH!=(BFIELD_WIDTH-1) && vstd::contains(shadedHexes, fromHex))
  594. {
  595. switch(BattleInfo::mutualPosition(fromHex, myNumber))
  596. {
  597. case 0:
  598. CGI->curh->changeGraphic(1,12);
  599. break;
  600. case 1:
  601. CGI->curh->changeGraphic(1,7);
  602. break;
  603. case 2:
  604. CGI->curh->changeGraphic(1,8);
  605. break;
  606. case 3:
  607. CGI->curh->changeGraphic(1,9);
  608. break;
  609. case 4:
  610. CGI->curh->changeGraphic(1,10);
  611. break;
  612. case 5:
  613. CGI->curh->changeGraphic(1,11);
  614. break;
  615. }
  616. }
  617. }
  618. else //unavailable enemy
  619. {
  620. CGI->curh->changeGraphic(1,0);
  621. console->alterTxt = "";
  622. console->whoSetAlter = 0;
  623. }
  624. }
  625. else //empty unavailable tile
  626. {
  627. CGI->curh->changeGraphic(1,0);
  628. console->alterTxt = "";
  629. console->whoSetAlter = 0;
  630. }
  631. }
  632. else //available tile
  633. {
  634. CStack *sactive = LOCPLINT->cb->battleGetStackByID(activeStack);
  635. if(LOCPLINT->cb->battleGetStackByID(activeStack)->creature->isFlying())
  636. {
  637. CGI->curh->changeGraphic(1,2);
  638. //setting console text
  639. char buf[500];
  640. sprintf(buf, CGI->generaltexth->allTexts[295].c_str(), sactive->amount == 1 ? sactive->creature->nameSing.c_str() : sactive->creature->namePl.c_str());
  641. console->alterTxt = buf;
  642. console->whoSetAlter = 0;
  643. }
  644. else
  645. {
  646. CGI->curh->changeGraphic(1,1);
  647. //setting console text
  648. char buf[500];
  649. sprintf(buf, CGI->generaltexth->allTexts[294].c_str(), sactive->amount == 1 ? sactive->creature->nameSing.c_str() : sactive->creature->namePl.c_str());
  650. console->alterTxt = buf;
  651. console->whoSetAlter = 0;
  652. }
  653. }
  654. }
  655. }
  656. else if(spellDestSelectMode)
  657. {
  658. int myNumber = -1; //number of hovered tile
  659. for(int g=0; g<BFIELD_SIZE; ++g)
  660. {
  661. if(bfield[g].hovered && bfield[g].strictHovered)
  662. {
  663. myNumber = g;
  664. break;
  665. }
  666. }
  667. if(myNumber == -1)
  668. {
  669. CGI->curh->changeGraphic(1, 0);
  670. //setting console text
  671. console->alterTxt = CGI->generaltexth->allTexts[23];
  672. console->whoSetAlter = 0;
  673. }
  674. else
  675. {
  676. CStack * stackUnder = LOCPLINT->cb->battleGetStackByPos(myNumber);
  677. switch(spellSelMode)
  678. {
  679. case 0:
  680. CGI->curh->changeGraphic(3, 0);
  681. //setting console text
  682. char buf[500];
  683. sprintf(buf, CGI->generaltexth->allTexts[26].c_str(), CGI->spellh->spells[spellToCast->additionalInfo].name.c_str());
  684. console->alterTxt = buf;
  685. console->whoSetAlter = 0;
  686. break;
  687. case 1:
  688. if(stackUnder && LOCPLINT->playerID == stackUnder->owner )
  689. {
  690. CGI->curh->changeGraphic(3, 0);
  691. //setting console text
  692. char buf[500];
  693. std::string creName = stackUnder->amount > 1 ? stackUnder->creature->namePl : stackUnder->creature->nameSing;
  694. sprintf(buf, CGI->generaltexth->allTexts[27].c_str(), CGI->spellh->spells[spellToCast->additionalInfo].name.c_str(), creName.c_str());
  695. console->alterTxt = buf;
  696. console->whoSetAlter = 0;
  697. break;
  698. }
  699. else
  700. {
  701. CGI->curh->changeGraphic(1, 0);
  702. //setting console text
  703. console->alterTxt = CGI->generaltexth->allTexts[23];
  704. console->whoSetAlter = 0;
  705. }
  706. break;
  707. case 2:
  708. if(stackUnder && LOCPLINT->playerID != stackUnder->owner )
  709. {
  710. CGI->curh->changeGraphic(3, 0);
  711. //setting console text
  712. char buf[500];
  713. std::string creName = stackUnder->amount > 1 ? stackUnder->creature->namePl : stackUnder->creature->nameSing;
  714. sprintf(buf, CGI->generaltexth->allTexts[27].c_str(), CGI->spellh->spells[spellToCast->additionalInfo].name.c_str(), creName.c_str());
  715. console->alterTxt = buf;
  716. console->whoSetAlter = 0;
  717. }
  718. else
  719. {
  720. CGI->curh->changeGraphic(1, 0);
  721. //setting console text
  722. console->alterTxt = CGI->generaltexth->allTexts[23];
  723. console->whoSetAlter = 0;
  724. }
  725. break;
  726. case 3:
  727. if(stackUnder)
  728. {
  729. CGI->curh->changeGraphic(3, 0);
  730. //setting console text
  731. char buf[500];
  732. std::string creName = stackUnder->amount > 1 ? stackUnder->creature->namePl : stackUnder->creature->nameSing;
  733. sprintf(buf, CGI->generaltexth->allTexts[27].c_str(), CGI->spellh->spells[spellToCast->additionalInfo].name.c_str(), creName.c_str());
  734. console->alterTxt = buf;
  735. console->whoSetAlter = 0;
  736. }
  737. else
  738. {
  739. CGI->curh->changeGraphic(1, 0);
  740. //setting console text
  741. console->alterTxt = CGI->generaltexth->allTexts[23];
  742. console->whoSetAlter = 0;
  743. }
  744. break;
  745. case 4: //TODO: implement this case
  746. break;
  747. }
  748. }
  749. }
  750. }
  751. bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick)
  752. {
  753. if(creAnims[number]==NULL)
  754. return false; //there is no such creature
  755. creAnims[number]->setType(8);
  756. int firstFrame = creAnims[number]->getFrame();
  757. for(int g=0; creAnims[number]->getFrame() != creAnims[number]->framesInGroup(8) + firstFrame - 1; ++g)
  758. {
  759. show();
  760. CSDL_Ext::update();
  761. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  762. }
  763. creDir[number] = !creDir[number];
  764. CStack curs = *LOCPLINT->cb->battleGetStackByID(number);
  765. std::pair <int, int> coords = CBattleHex::getXYUnitAnim(hex, creDir[number], curs.creature);
  766. creAnims[number]->pos.x = coords.first;
  767. //creAnims[number]->pos.y = coords.second;
  768. if(wideTrick && curs.creature->isDoubleWide())
  769. {
  770. if(curs.attackerOwned)
  771. {
  772. if(!creDir[number])
  773. creAnims[number]->pos.x -= 44;
  774. }
  775. else
  776. {
  777. if(creDir[number])
  778. creAnims[number]->pos.x += 44;
  779. }
  780. }
  781. creAnims[number]->setType(7);
  782. firstFrame = creAnims[number]->getFrame();
  783. for(int g=0; creAnims[number]->getFrame() != creAnims[number]->framesInGroup(7) + firstFrame - 1; ++g)
  784. {
  785. show();
  786. CSDL_Ext::update();
  787. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  788. }
  789. creAnims[number]->setType(2);
  790. return true;
  791. }
  792. void CBattleInterface::bOptionsf()
  793. {
  794. CGI->curh->changeGraphic(0,0);
  795. deactivate();
  796. SDL_Rect temp_rect = genRect(431, 481, 160, 84);
  797. CBattleOptionsWindow * optionsWin = new CBattleOptionsWindow(temp_rect, this);
  798. optionsWin->activate();
  799. LOCPLINT->objsToBlit.push_back(optionsWin);
  800. }
  801. void CBattleInterface::bSurrenderf()
  802. {
  803. }
  804. void CBattleInterface::bFleef()
  805. {
  806. CFunctionList<void()> ony = boost::bind(&CBattleInterface::activate,this);
  807. ony += boost::bind(&CBattleInterface::reallyFlee,this);
  808. LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[28],std::vector<SComponent*>(), ony, boost::bind(&CBattleInterface::activate,this), true, false);
  809. }
  810. void CBattleInterface::reallyFlee()
  811. {
  812. giveCommand(4,0,0);
  813. CGI->curh->changeGraphic(0, 0);
  814. }
  815. void CBattleInterface::bAutofightf()
  816. {
  817. }
  818. void CBattleInterface::bSpellf()
  819. {
  820. CGI->curh->changeGraphic(0,0);
  821. deactivate();
  822. const CGHeroInstance * chi = NULL;
  823. if(attackingHeroInstance->tempOwner == LOCPLINT->playerID)
  824. chi = attackingHeroInstance;
  825. else
  826. chi = defendingHeroInstance;
  827. CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), chi);
  828. spellWindow->activate();
  829. LOCPLINT->objsToBlit.push_back(spellWindow);
  830. }
  831. void CBattleInterface::bWaitf()
  832. {
  833. giveCommand(8,0,activeStack);
  834. }
  835. void CBattleInterface::bDefencef()
  836. {
  837. giveCommand(3,0,activeStack);
  838. }
  839. void CBattleInterface::bConsoleUpf()
  840. {
  841. console->scrollUp();
  842. }
  843. void CBattleInterface::bConsoleDownf()
  844. {
  845. console->scrollDown();
  846. }
  847. void CBattleInterface::newStack(CStack stack)
  848. {
  849. creAnims[stack.ID] = new CCreatureAnimation(stack.creature->animDefName);
  850. creAnims[stack.ID]->setType(2);
  851. creDir[stack.ID] = stack.owner==attackingHeroInstance->tempOwner;
  852. }
  853. void CBattleInterface::stackRemoved(CStack stack)
  854. {
  855. delete creAnims[stack.ID];
  856. creAnims.erase(stack.ID);
  857. }
  858. void CBattleInterface::stackActivated(int number)
  859. {
  860. //givenCommand = NULL;
  861. activeStack = number;
  862. myTurn = true;
  863. redrawBackgroundWithHexes(number);
  864. bWait->block(vstd::contains(LOCPLINT->cb->battleGetStackByID(number)->state,WAITING)); //block waiting button if stack has been already waiting
  865. }
  866. void CBattleInterface::stackMoved(int number, int destHex, bool endMoving)
  867. {
  868. bool startMoving = creAnims[number]->type==20;
  869. //a few useful variables
  870. int curStackPos = LOCPLINT->cb->battleGetPos(number);
  871. int steps = creAnims[number]->framesInGroup(0)*getAnimSpeedMultiplier()-1;
  872. int hexWbase = 44, hexHbase = 42;
  873. bool twoTiles = LOCPLINT->cb->battleGetCreature(number).isDoubleWide();
  874. if(startMoving) //animation of starting move; some units don't have this animation (ie. halberdier)
  875. {
  876. CGI->curh->hide();
  877. for(int i=0; i<creAnims[number]->framesInGroup(20)*getAnimSpeedMultiplier()-1; ++i)
  878. {
  879. show();
  880. CSDL_Ext::update();
  881. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  882. if((animCount+1)%(4/animSpeed)==0)
  883. creAnims[number]->incrementFrame();
  884. }
  885. }
  886. int mutPos = BattleInfo::mutualPosition(curStackPos, destHex);
  887. {
  888. switch(mutPos) //reverse unit if necessary
  889. {
  890. case 0: case 4: case 5:
  891. if(creDir[number] == true)
  892. reverseCreature(number, curStackPos, twoTiles);
  893. break;
  894. case 1: case 2: case 3:
  895. if(creDir[number] == false)
  896. reverseCreature(number, curStackPos, twoTiles);
  897. break;
  898. }
  899. //moving instructions
  900. creAnims[number]->setType(0);
  901. float posX = creAnims[number]->pos.x, posY = creAnims[number]->pos.y; // for precise calculations ;]
  902. for(int i=0; i<steps; ++i)
  903. {
  904. switch(mutPos)
  905. {
  906. case 0:
  907. posX -= ((float)hexWbase)/(2.0f*steps);
  908. creAnims[number]->pos.x = posX;
  909. posY -= ((float)hexHbase)/((float)steps);
  910. creAnims[number]->pos.y = posY;
  911. break;
  912. case 1:
  913. posX += ((float)hexWbase)/(2.0f*steps);
  914. creAnims[number]->pos.x = posX;
  915. posY -= ((float)hexHbase)/((float)steps);
  916. creAnims[number]->pos.y = posY;
  917. break;
  918. case 2:
  919. posX += ((float)hexWbase)/((float)steps);
  920. creAnims[number]->pos.x = posX;
  921. break;
  922. case 3:
  923. posX += ((float)hexWbase)/(2.0f*steps);
  924. creAnims[number]->pos.x = posX;
  925. posY += ((float)hexHbase)/((float)steps);
  926. creAnims[number]->pos.y = posY;
  927. break;
  928. case 4:
  929. posX -= ((float)hexWbase)/(2.0f*steps);
  930. creAnims[number]->pos.x = posX;
  931. posY += ((float)hexHbase)/((float)steps);
  932. creAnims[number]->pos.y = posY;
  933. break;
  934. case 5:
  935. posX -= ((float)hexWbase)/((float)steps);
  936. creAnims[number]->pos.x = posX;
  937. break;
  938. }
  939. show();
  940. CSDL_Ext::update();
  941. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  942. if((animCount+1)%(4/animSpeed)==0)
  943. creAnims[number]->incrementFrame();
  944. }
  945. }
  946. if(endMoving) //animation of ending move
  947. {
  948. if(creAnims[number]->framesInGroup(21)!=0) // some units don't have this animation (ie. halberdier)
  949. {
  950. creAnims[number]->setType(21);
  951. for(int i=0; i<creAnims[number]->framesInGroup(21)*getAnimSpeedMultiplier()-1; ++i)
  952. {
  953. show();
  954. CSDL_Ext::update();
  955. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  956. if((animCount+1)%(4/animSpeed)==0)
  957. creAnims[number]->incrementFrame();
  958. }
  959. }
  960. creAnims[number]->setType(2); //resetting to default
  961. CGI->curh->show();
  962. }
  963. CStack curs = *LOCPLINT->cb->battleGetStackByID(number);
  964. if(endMoving) //resetting to default
  965. {
  966. if(creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))
  967. reverseCreature(number, destHex, twoTiles);
  968. }
  969. std::pair <int, int> coords = CBattleHex::getXYUnitAnim(destHex, creDir[number], curs.creature);
  970. creAnims[number]->pos.x = coords.first;
  971. if(!endMoving && twoTiles && (curs.owner == attackingHeroInstance->tempOwner) && (creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))) //big attacker creature is reversed
  972. creAnims[number]->pos.x -= 44;
  973. else if(!endMoving && twoTiles && (curs.owner != attackingHeroInstance->tempOwner) && (creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))) //big defender creature is reversed
  974. creAnims[number]->pos.x += 44;
  975. creAnims[number]->pos.y = coords.second;
  976. }
  977. void CBattleInterface::stacksAreAttacked(std::vector<CBattleInterface::SStackAttackedInfo> attackedInfos)
  978. {
  979. //restoring default state of battleWindow by calling show func
  980. while(true)
  981. {
  982. show();
  983. CSDL_Ext::update();
  984. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  985. //checking break conditions
  986. bool break_loop = true;
  987. for(size_t g=0; g<attackedInfos.size(); ++g)
  988. {
  989. if(creAnims[attackedInfos[g].ID]->getType() != 2)
  990. {
  991. break_loop = false;
  992. }
  993. if(attackingInfo && attackingInfo->IDby == attackedInfos[g].IDby)
  994. {
  995. break_loop = false;
  996. }
  997. }
  998. if(break_loop) break;
  999. }
  1000. if(attackedInfos.size() == 1 && attackedInfos[0].byShooting) //delay hit animation
  1001. {
  1002. CStack attacker = *LOCPLINT->cb->battleGetStackByID(attackedInfos[0].IDby);
  1003. while(true)
  1004. {
  1005. bool found = false;
  1006. for(std::list<SProjectileInfo>::const_iterator it = projectiles.begin(); it!=projectiles.end(); ++it)
  1007. {
  1008. if(it->creID == attacker.creature->idNumber)
  1009. {
  1010. found = true;
  1011. break;
  1012. }
  1013. }
  1014. if(!found)
  1015. break;
  1016. else
  1017. {
  1018. show();
  1019. CSDL_Ext::update();
  1020. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  1021. }
  1022. }
  1023. }
  1024. //initializing
  1025. std::map<int, int> animLengths;
  1026. std::map<int, int> increments;
  1027. int maxLen = 0;
  1028. for(size_t g=0; g<attackedInfos.size(); ++g)
  1029. {
  1030. int animLen;
  1031. if(attackedInfos[g].killed)
  1032. {
  1033. creAnims[attackedInfos[g].ID]->setType(5); //death
  1034. animLen = creAnims[attackedInfos[g].ID]->framesInGroup(5);
  1035. }
  1036. else
  1037. {
  1038. creAnims[attackedInfos[g].ID]->setType(3); //getting hit
  1039. animLen = creAnims[attackedInfos[g].ID]->framesInGroup(3);
  1040. }
  1041. animLengths.insert(std::make_pair(attackedInfos[g].ID, animLen));
  1042. increments.insert(std::make_pair(attackedInfos[g].ID, 0));
  1043. if(animLen > maxLen)
  1044. {
  1045. maxLen = animLen;
  1046. }
  1047. }
  1048. //main showing loop
  1049. bool continueLoop = true;
  1050. while(continueLoop)
  1051. {
  1052. show();
  1053. CSDL_Ext::update();
  1054. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  1055. for(size_t g=0; g<attackedInfos.size(); ++g)
  1056. {
  1057. if((animCount+1)%(4/animSpeed)==0 && increments[attackedInfos[g].ID]<animLengths[attackedInfos[g].ID])
  1058. {
  1059. creAnims[attackedInfos[g].ID]->incrementFrame();
  1060. ++(increments[attackedInfos[g].ID]);
  1061. }
  1062. if(increments[attackedInfos[g].ID]>=animLengths[attackedInfos[g].ID] && creAnims[attackedInfos[g].ID]->getType() == 3)
  1063. creAnims[attackedInfos[g].ID]->setType(2);
  1064. }
  1065. bool isAnotherOne = false; //if true, there is a stack whose hit/death anim must be continued
  1066. for(size_t g=0; g<attackedInfos.size(); ++g)
  1067. {
  1068. if(increments[attackedInfos[g].ID] < animLengths[attackedInfos[g].ID]-1)
  1069. {
  1070. isAnotherOne = true;
  1071. break;
  1072. }
  1073. }
  1074. if(!isAnotherOne)
  1075. continueLoop = false;
  1076. }
  1077. //restoring animType
  1078. for(size_t g=0; g<attackedInfos.size(); ++g)
  1079. {
  1080. if(creAnims[attackedInfos[g].ID]->getType() == 3)
  1081. creAnims[attackedInfos[g].ID]->setType(2);
  1082. }
  1083. //printing info to console
  1084. for(size_t g=0; g<attackedInfos.size(); ++g)
  1085. {
  1086. if(attackedInfos[g].IDby!=-1)
  1087. printConsoleAttacked(attackedInfos[g].ID, attackedInfos[g].dmg, attackedInfos[g].amountKilled, attackedInfos[g].IDby);
  1088. }
  1089. }
  1090. void CBattleInterface::stackAttacking(int ID, int dest)
  1091. {
  1092. while(attackingInfo != NULL || creAnims[ID]->getType()!=2)
  1093. {
  1094. show();
  1095. CSDL_Ext::update();
  1096. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  1097. }
  1098. CStack aStack = *LOCPLINT->cb->battleGetStackByID(ID); //attacking stack
  1099. int reversedShift = 0; //shift of attacking stack's position due to reversing
  1100. if(aStack.attackerOwned)
  1101. {
  1102. if(aStack.creature->isDoubleWide())
  1103. {
  1104. switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction
  1105. {
  1106. case 0:
  1107. //reverseCreature(ID, aStack.position, true);
  1108. break;
  1109. case 1:
  1110. break;
  1111. case 2:
  1112. break;
  1113. case 3:
  1114. break;
  1115. case 4:
  1116. //reverseCreature(ID, aStack.position, true);
  1117. break;
  1118. case 5:
  1119. reverseCreature(ID, aStack.position, true);
  1120. break;
  1121. case -1:
  1122. if(BattleInfo::mutualPosition(aStack.position + (aStack.attackerOwned ? -1 : 1), dest) >= 0) //if reversing stack will make its position adjacent to dest
  1123. {
  1124. reverseCreature(ID, aStack.position, true);
  1125. reversedShift = (aStack.attackerOwned ? -1 : 1);
  1126. }
  1127. break;
  1128. }
  1129. }
  1130. else //else for if(aStack.creature->isDoubleWide())
  1131. {
  1132. switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction
  1133. {
  1134. case 0:
  1135. reverseCreature(ID, aStack.position, true);
  1136. break;
  1137. case 1:
  1138. break;
  1139. case 2:
  1140. break;
  1141. case 3:
  1142. break;
  1143. case 4:
  1144. reverseCreature(ID, aStack.position, true);
  1145. break;
  1146. case 5:
  1147. reverseCreature(ID, aStack.position, true);
  1148. break;
  1149. }
  1150. }
  1151. }
  1152. else //if(aStack.attackerOwned)
  1153. {
  1154. if(aStack.creature->isDoubleWide())
  1155. {
  1156. switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction
  1157. {
  1158. case 0:
  1159. //reverseCreature(ID, aStack.position, true);
  1160. break;
  1161. case 1:
  1162. break;
  1163. case 2:
  1164. reverseCreature(ID, aStack.position, true);
  1165. break;
  1166. case 3:
  1167. break;
  1168. case 4:
  1169. //reverseCreature(ID, aStack.position, true);
  1170. break;
  1171. case 5:
  1172. //reverseCreature(ID, aStack.position, true);
  1173. break;
  1174. case -1:
  1175. if(BattleInfo::mutualPosition(aStack.position + (aStack.attackerOwned ? -1 : 1), dest) >= 0) //if reversing stack will make its position adjacent to dest
  1176. {
  1177. reverseCreature(ID, aStack.position, true);
  1178. reversedShift = (aStack.attackerOwned ? -1 : 1);
  1179. }
  1180. break;
  1181. }
  1182. }
  1183. else //else for if(aStack.creature->isDoubleWide())
  1184. {
  1185. switch(BattleInfo::mutualPosition(aStack.position, dest)) //attack direction
  1186. {
  1187. case 0:
  1188. //reverseCreature(ID, aStack.position, true);
  1189. break;
  1190. case 1:
  1191. reverseCreature(ID, aStack.position, true);
  1192. break;
  1193. case 2:
  1194. reverseCreature(ID, aStack.position, true);
  1195. break;
  1196. case 3:
  1197. reverseCreature(ID, aStack.position, true);
  1198. break;
  1199. case 4:
  1200. //reverseCreature(ID, aStack.position, true);
  1201. break;
  1202. case 5:
  1203. //reverseCreature(ID, aStack.position, true);
  1204. break;
  1205. }
  1206. }
  1207. }
  1208. attackingInfo = new CAttHelper;
  1209. attackingInfo->dest = dest;
  1210. attackingInfo->frame = 0;
  1211. attackingInfo->hitCount = 0;
  1212. attackingInfo->ID = ID;
  1213. attackingInfo->IDby = LOCPLINT->cb->battleGetStackByPos(dest)->ID;
  1214. attackingInfo->reversing = false;
  1215. attackingInfo->posShiftDueToDist = reversedShift;
  1216. attackingInfo->shooting = false;
  1217. switch(BattleInfo::mutualPosition(aStack.position + reversedShift, dest)) //attack direction
  1218. {
  1219. case 0:
  1220. attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
  1221. break;
  1222. case 1:
  1223. attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
  1224. break;
  1225. case 2:
  1226. attackingInfo->maxframe = creAnims[ID]->framesInGroup(12);
  1227. break;
  1228. case 3:
  1229. attackingInfo->maxframe = creAnims[ID]->framesInGroup(13);
  1230. break;
  1231. case 4:
  1232. attackingInfo->maxframe = creAnims[ID]->framesInGroup(13);
  1233. break;
  1234. case 5:
  1235. attackingInfo->maxframe = creAnims[ID]->framesInGroup(12);
  1236. break;
  1237. default:
  1238. tlog1<<"Critical Error! Wrong dest in stackAttacking!"<<std::endl;
  1239. }
  1240. }
  1241. void CBattleInterface::newRound(int number)
  1242. {
  1243. console->addText(CGI->generaltexth->allTexts[412]);
  1244. }
  1245. void CBattleInterface::giveCommand(ui8 action, ui16 tile, ui32 stack, si32 additional)
  1246. {
  1247. BattleAction * ba = new BattleAction(); //is deleted in CPlayerInterface::activeStack()
  1248. ba->side = defendingHeroInstance ? (LOCPLINT->playerID == defendingHeroInstance->tempOwner) : false;
  1249. ba->actionType = action;
  1250. ba->destinationTile = tile;
  1251. ba->stackNumber = stack;
  1252. ba->additionalInfo = additional;
  1253. givenCommand->setn(ba);
  1254. myTurn = false;
  1255. activeStack = -1;
  1256. }
  1257. bool CBattleInterface::isTileAttackable(const int & number) const
  1258. {
  1259. for(size_t b=0; b<shadedHexes.size(); ++b)
  1260. {
  1261. if(BattleInfo::mutualPosition(shadedHexes[b], number) != -1 || shadedHexes[b] == number)
  1262. return true;
  1263. }
  1264. return false;
  1265. }
  1266. void CBattleInterface::hexLclicked(int whichOne)
  1267. {
  1268. if((whichOne%BFIELD_WIDTH)!=0 && (whichOne%BFIELD_WIDTH)!=(BFIELD_WIDTH-1)) //if player is trying to attack enemey unit or move creature stack
  1269. {
  1270. if(!myTurn)
  1271. return; //we are not permit to do anything
  1272. if(spellDestSelectMode)
  1273. {
  1274. //checking destination
  1275. bool allowCasting = true;
  1276. switch(spellSelMode)
  1277. {
  1278. case 1:
  1279. if(!LOCPLINT->cb->battleGetStackByPos(whichOne) || LOCPLINT->playerID != LOCPLINT->cb->battleGetStackByPos(whichOne)->owner )
  1280. allowCasting = false;
  1281. break;
  1282. case 2:
  1283. if(!LOCPLINT->cb->battleGetStackByPos(whichOne) || LOCPLINT->playerID == LOCPLINT->cb->battleGetStackByPos(whichOne)->owner )
  1284. allowCasting = false;
  1285. break;
  1286. case 3:
  1287. if(!LOCPLINT->cb->battleGetStackByPos(whichOne))
  1288. allowCasting = false;
  1289. break;
  1290. case 4: //TODO: implement this case
  1291. break;
  1292. }
  1293. //destination checked
  1294. if(allowCasting)
  1295. {
  1296. spellToCast->destinationTile = whichOne;
  1297. LOCPLINT->cb->battleMakeAction(spellToCast);
  1298. delete spellToCast;
  1299. spellToCast = NULL;
  1300. spellDestSelectMode = false;
  1301. CGI->curh->changeGraphic(1, 6);
  1302. }
  1303. }
  1304. else
  1305. {
  1306. CStack* dest = LOCPLINT->cb->battleGetStackByPos(whichOne); //creature at destination tile; -1 if there is no one
  1307. if(!dest || !dest->alive()) //no creature at that tile
  1308. {
  1309. if(std::find(shadedHexes.begin(),shadedHexes.end(),whichOne)!=shadedHexes.end())// and it's in our range
  1310. {
  1311. CGI->curh->changeGraphic(1, 6); //cursor should be changed
  1312. if(LOCPLINT->cb->battleGetStackByID(activeStack)->creature->isDoubleWide())
  1313. {
  1314. std::vector<int> acc = LOCPLINT->cb->battleGetAvailableHexes(activeStack, false);
  1315. if(vstd::contains(acc, whichOne))
  1316. giveCommand(2,whichOne,activeStack);
  1317. else
  1318. giveCommand(2,whichOne + (LOCPLINT->cb->battleGetStackByID(activeStack)->attackerOwned ? 1 : -1),activeStack);
  1319. }
  1320. else
  1321. {
  1322. giveCommand(2,whichOne,activeStack);
  1323. }
  1324. }
  1325. }
  1326. else if(dest->owner != attackingHeroInstance->tempOwner
  1327. && LOCPLINT->cb->battleCanShoot(activeStack, whichOne) ) //shooting
  1328. {
  1329. CGI->curh->changeGraphic(1, 6); //cursor should be changed
  1330. giveCommand(7,whichOne,activeStack);
  1331. }
  1332. else if(dest->owner != attackingHeroInstance->tempOwner) //attacking
  1333. {
  1334. switch(CGI->curh->number)
  1335. {
  1336. case 12:
  1337. giveCommand(6,whichOne + ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH+1 ),activeStack,whichOne);
  1338. break;
  1339. case 7:
  1340. giveCommand(6,whichOne + ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH-1 : BFIELD_WIDTH ),activeStack,whichOne);
  1341. break;
  1342. case 8:
  1343. if(LOCPLINT->cb->battleGetStackByID(activeStack)->creature->isDoubleWide() && !LOCPLINT->cb->battleGetStackByID(activeStack)->attackerOwned)
  1344. {
  1345. std::vector<int> acc = LOCPLINT->cb->battleGetAvailableHexes(activeStack, false);
  1346. if(vstd::contains(acc, whichOne))
  1347. giveCommand(6,whichOne - 1,activeStack,whichOne);
  1348. else
  1349. giveCommand(6,whichOne - 2,activeStack,whichOne);
  1350. }
  1351. else
  1352. {
  1353. giveCommand(6,whichOne - 1,activeStack,whichOne);
  1354. }
  1355. break;
  1356. case 9:
  1357. giveCommand(6,whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH+1 : BFIELD_WIDTH ),activeStack,whichOne);
  1358. break;
  1359. case 10:
  1360. giveCommand(6,whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH-1 ),activeStack,whichOne);
  1361. break;
  1362. case 11:
  1363. if(LOCPLINT->cb->battleGetStackByID(activeStack)->creature->isDoubleWide() && LOCPLINT->cb->battleGetStackByID(activeStack)->attackerOwned)
  1364. {
  1365. std::vector<int> acc = LOCPLINT->cb->battleGetAvailableHexes(activeStack, false);
  1366. if(vstd::contains(acc, whichOne))
  1367. giveCommand(6,whichOne + 1,activeStack,whichOne);
  1368. else
  1369. giveCommand(6,whichOne + 2,activeStack,whichOne);
  1370. }
  1371. else
  1372. {
  1373. giveCommand(6,whichOne + 1,activeStack,whichOne);
  1374. }
  1375. break;
  1376. }
  1377. CGI->curh->changeGraphic(1, 6); //cursor should be changed
  1378. }
  1379. }
  1380. }
  1381. }
  1382. void CBattleInterface::stackIsShooting(int ID, int dest)
  1383. {
  1384. if(attackingInfo != NULL)
  1385. {
  1386. return; //something went wrong
  1387. }
  1388. //projectile
  1389. float projectileAngle; //in radians; if positive, projectiles goes up
  1390. 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)
  1391. int fromHex = LOCPLINT->cb->battleGetPos(ID);
  1392. projectileAngle = atan2(float(abs(dest - fromHex)/BFIELD_WIDTH), float(abs(dest - fromHex)%BFIELD_WIDTH));
  1393. if(fromHex < dest)
  1394. projectileAngle = -projectileAngle;
  1395. SProjectileInfo spi;
  1396. spi.creID = LOCPLINT->cb->battleGetStackByID(ID)->creature->idNumber;
  1397. spi.reverse = !LOCPLINT->cb->battleGetStackByID(ID)->attackerOwned;
  1398. spi.step = 0;
  1399. spi.frameNum = 0;
  1400. spi.spin = CGI->creh->idToProjectileSpin[spi.creID];
  1401. std::pair<int, int> xycoord = CBattleHex::getXYUnitAnim(LOCPLINT->cb->battleGetPos(ID), true, &LOCPLINT->cb->battleGetCreature(ID));
  1402. std::pair<int, int> destcoord = CBattleHex::getXYUnitAnim(dest, false, &LOCPLINT->cb->battleGetCreature(ID));
  1403. destcoord.first += 250; destcoord.second += 210; //TODO: find a better place to shoot
  1404. if(projectileAngle > straightAngle) //upper shot
  1405. {
  1406. spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).upperRightMissleOffsetX;
  1407. spi.y = xycoord.second + 100 - LOCPLINT->cb->battleGetCreature(ID).upperRightMissleOffsetY;
  1408. }
  1409. else if(projectileAngle < -straightAngle) //lower shot
  1410. {
  1411. spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).lowerRightMissleOffsetX;
  1412. spi.y = xycoord.second + 150 - LOCPLINT->cb->battleGetCreature(ID).lowerRightMissleOffsetY;
  1413. }
  1414. else //straight shot
  1415. {
  1416. spi.x = xycoord.first + 200 + LOCPLINT->cb->battleGetCreature(ID).rightMissleOffsetX;
  1417. spi.y = xycoord.second + 125 - LOCPLINT->cb->battleGetCreature(ID).rightMissleOffsetY;
  1418. }
  1419. spi.lastStep = sqrt((float)((destcoord.first - spi.x)*(destcoord.first - spi.x) + (destcoord.second - spi.y) * (destcoord.second - spi.y))) / 40;
  1420. if(spi.lastStep == 0)
  1421. spi.lastStep = 1;
  1422. spi.dx = (destcoord.first - spi.x) / spi.lastStep;
  1423. spi.dy = (destcoord.second - spi.y) / spi.lastStep;
  1424. //set starting frame
  1425. if(spi.spin)
  1426. {
  1427. spi.frameNum = 0;
  1428. }
  1429. else
  1430. {
  1431. 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);
  1432. }
  1433. //set delay
  1434. spi.animStartDelay = CGI->creh->creatures[spi.creID].attackClimaxFrame;
  1435. projectiles.push_back(spi);
  1436. //attack aniamtion
  1437. attackingInfo = new CAttHelper;
  1438. attackingInfo->dest = dest;
  1439. attackingInfo->frame = 0;
  1440. attackingInfo->hitCount = 0;
  1441. attackingInfo->ID = ID;
  1442. attackingInfo->reversing = false;
  1443. attackingInfo->posShiftDueToDist = 0;
  1444. attackingInfo->shooting = true;
  1445. if(projectileAngle > straightAngle) //upper shot
  1446. attackingInfo->shootingGroup = 14;
  1447. else if(projectileAngle < -straightAngle) //lower shot
  1448. attackingInfo->shootingGroup = 16;
  1449. else //straight shot
  1450. attackingInfo->shootingGroup = 15;
  1451. attackingInfo->maxframe = creAnims[ID]->framesInGroup(attackingInfo->shootingGroup);
  1452. }
  1453. void CBattleInterface::battleFinished(const BattleResult& br)
  1454. {
  1455. deactivate();
  1456. CGI->curh->changeGraphic(0,0);
  1457. SDL_Rect temp_rect = genRect(561, 470, (screen->w - 800)/2 + 165, (screen->h - 600)/2 + 19);
  1458. resWindow = new CBattleReslutWindow(br, temp_rect, this);
  1459. resWindow->activate();
  1460. }
  1461. void CBattleInterface::spellCasted(SpellCasted * sc)
  1462. {
  1463. std::vector< std::string > anims; //for magic arrow and ice bolt
  1464. switch(sc->id)
  1465. {
  1466. case 15: //magic arrow
  1467. {
  1468. //initialization of anims
  1469. 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");
  1470. }
  1471. case 16: //ice bolt
  1472. {
  1473. if(anims.size() == 0) //initialiaztion of anims
  1474. {
  1475. anims.push_back("C08SPW0.DEF"); anims.push_back("C08SPW1.DEF"); anims.push_back("C08SPW2.DEF"); anims.push_back("C08SPW3.DEF"); anims.push_back("C08SPW4.DEF");
  1476. }
  1477. } //end of ice bolt only part
  1478. { //common ice bolt and magic arrow part
  1479. //initial variables
  1480. std::string animToDisplay;
  1481. std::pair<int, int> srccoord = sc->side ? std::make_pair(770, 60) : std::make_pair(30, 60);
  1482. std::pair<int, int> destcoord = CBattleHex::getXYUnitAnim(sc->tile, !sc->side, LOCPLINT->cb->battleGetStackByPos(sc->tile)->creature); //position attacked by arrow
  1483. destcoord.first += 250; destcoord.second += 240;
  1484. //animation angle
  1485. float angle = atan2(float(destcoord.first - srccoord.first), float(destcoord.second - srccoord.second));
  1486. //choosing animation by angle
  1487. if(angle > 1.50)
  1488. animToDisplay = anims[0];
  1489. else if(angle > 1.20)
  1490. animToDisplay = anims[1];
  1491. else if(angle > 0.90)
  1492. animToDisplay = anims[2];
  1493. else if(angle > 0.60)
  1494. animToDisplay = anims[3];
  1495. else
  1496. animToDisplay = anims[4];
  1497. //displaying animation
  1498. int steps = sqrt((float)((destcoord.first - srccoord.first)*(destcoord.first - srccoord.first) + (destcoord.second - srccoord.second) * (destcoord.second - srccoord.second))) / 40;
  1499. if(steps <= 0)
  1500. steps = 1;
  1501. CDefHandler * animDef = CDefHandler::giveDef(animToDisplay);
  1502. int dx = (destcoord.first - srccoord.first - animDef->ourImages[0].bitmap->w)/steps, dy = (destcoord.second - srccoord.second - animDef->ourImages[0].bitmap->h)/steps;
  1503. SDL_Rect buf;
  1504. SDL_GetClipRect(screen, &buf);
  1505. SDL_SetClipRect(screen, &pos); //setting rect we can blit to
  1506. for(int g=0; g<steps; ++g)
  1507. {
  1508. show();
  1509. SDL_Rect & srcr = animDef->ourImages[g%animDef->ourImages.size()].bitmap->clip_rect;
  1510. SDL_Rect dstr = genRect(srcr.h, srcr.w, srccoord.first + g*dx, srccoord.second + g*dy);
  1511. SDL_BlitSurface(animDef->ourImages[g%animDef->ourImages.size()].bitmap, &srcr, screen, &dstr);
  1512. CSDL_Ext::update();
  1513. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  1514. }
  1515. SDL_SetClipRect(screen, &buf); //restoring previous clip rect
  1516. int b=0; //TODO use me
  1517. break; //for 15 and 16 cases
  1518. }
  1519. case 17: //lightning bolt
  1520. {
  1521. displayEffect(1, sc->tile);
  1522. break;
  1523. }
  1524. case 18: //implosion
  1525. {
  1526. displayEffect(10, sc->tile);
  1527. break;
  1528. }
  1529. case 27: //shield
  1530. {
  1531. displayEffect(27, sc->tile);
  1532. break;
  1533. }
  1534. case 28: //air shield
  1535. {
  1536. displayEffect(2, sc->tile);
  1537. break;
  1538. }
  1539. case 41: //bless
  1540. {
  1541. displayEffect(36, sc->tile);
  1542. break;
  1543. }
  1544. case 42: //curse
  1545. {
  1546. displayEffect(40, sc->tile);
  1547. break;
  1548. }
  1549. case 43: //bloodlust
  1550. {
  1551. displayEffect(4, sc->tile);
  1552. //TODO: give better animation for this spell
  1553. break;
  1554. }
  1555. case 45: //weakness
  1556. {
  1557. displayEffect(56, sc->tile);
  1558. //TODO: give better animation for this spell
  1559. break;
  1560. }
  1561. case 46: //stone skin
  1562. {
  1563. displayEffect(54, sc->tile);
  1564. break;
  1565. }
  1566. case 48: //prayer
  1567. {
  1568. displayEffect(0, sc->tile);
  1569. break;
  1570. }
  1571. case 49: //mirth
  1572. {
  1573. displayEffect(20, sc->tile);
  1574. break;
  1575. }
  1576. case 50: //sorrow
  1577. {
  1578. displayEffect(30, sc->tile);
  1579. break;
  1580. }
  1581. case 51: //fortune
  1582. {
  1583. displayEffect(18, sc->tile);
  1584. break;
  1585. }
  1586. case 52: //misfortune
  1587. {
  1588. displayEffect(48, sc->tile);
  1589. break;
  1590. }
  1591. case 53: //haste
  1592. {
  1593. displayEffect(31, sc->tile);
  1594. break;
  1595. }
  1596. case 54: //slow
  1597. {
  1598. displayEffect(19, sc->tile);
  1599. break;
  1600. }
  1601. case 56: //frenzy
  1602. {
  1603. displayEffect(17, sc->tile);
  1604. break;
  1605. }
  1606. case 61: //forgetfulness
  1607. {
  1608. displayEffect(42, sc->tile);
  1609. break;
  1610. }
  1611. }
  1612. }
  1613. void CBattleInterface::castThisSpell(int spellID)
  1614. {
  1615. BattleAction * ba = new BattleAction;
  1616. ba->actionType = 1;
  1617. ba->additionalInfo = spellID; //spell number
  1618. ba->destinationTile = -1;
  1619. ba->stackNumber = (attackingHeroInstance->tempOwner == LOCPLINT->playerID) ? -1 : -2;
  1620. ba->side = defendingHeroInstance ? (LOCPLINT->playerID == defendingHeroInstance->tempOwner) : false;
  1621. spellToCast = ba;
  1622. spellDestSelectMode = true;
  1623. //choosing possible tragets
  1624. const CGHeroInstance * castingHero = (attackingHeroInstance->tempOwner == LOCPLINT->playerID) ? attackingHeroInstance : attackingHeroInstance;
  1625. spellSelMode = 0;
  1626. if(CGI->spellh->spells[spellID].attributes.find("CREATURE_TARGET") != std::string::npos)
  1627. {
  1628. switch(CGI->spellh->spells[spellID].positiveness)
  1629. {
  1630. case -1 :
  1631. spellSelMode = 2;
  1632. break;
  1633. case 0:
  1634. spellSelMode = 3;
  1635. break;
  1636. case 1:
  1637. spellSelMode = 1;
  1638. break;
  1639. }
  1640. }
  1641. if(CGI->spellh->spells[spellID].attributes.find("CREATURE_TARGET_2") != std::string::npos)
  1642. {
  1643. if(castingHero && castingHero->getSpellSecLevel(spellID) < 3)
  1644. {
  1645. switch(CGI->spellh->spells[spellID].positiveness)
  1646. {
  1647. case -1 :
  1648. spellSelMode = 2;
  1649. break;
  1650. case 0:
  1651. spellSelMode = 3;
  1652. break;
  1653. case 1:
  1654. spellSelMode = 1;
  1655. break;
  1656. }
  1657. }
  1658. else
  1659. {
  1660. spellSelMode = -1;
  1661. }
  1662. }
  1663. if(spellSelMode == -1) //user does not have to select location
  1664. {
  1665. spellToCast->destinationTile = -1;
  1666. LOCPLINT->cb->battleMakeAction(spellToCast);
  1667. delete spellToCast;
  1668. spellToCast = NULL;
  1669. spellDestSelectMode = false;
  1670. CGI->curh->changeGraphic(1, 6);
  1671. }
  1672. else
  1673. {
  1674. CGI->curh->changeGraphic(3, 0);
  1675. }
  1676. }
  1677. void CBattleInterface::displayEffect(ui32 effect, int destTile)
  1678. {
  1679. if(graphics->battleACToDef[effect].size() != 0)
  1680. {
  1681. SBattleEffect be;
  1682. be.anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]);
  1683. be.frame = 0;
  1684. be.maxFrame = be.anim->ourImages.size();
  1685. be.x = 22 * ( ((destTile/BFIELD_WIDTH) + 1)%2 ) + 44 * (destTile % BFIELD_WIDTH) + 45;
  1686. be.y = 105 + 42 * (destTile/BFIELD_WIDTH);
  1687. if(effect != 1 && effect != 0)
  1688. {
  1689. be.x -= be.anim->ourImages[0].bitmap->w/2;
  1690. be.y -= be.anim->ourImages[0].bitmap->h/2;
  1691. }
  1692. else if(effect == 1)
  1693. {
  1694. be.x -= be.anim->ourImages[0].bitmap->w;
  1695. be.y -= be.anim->ourImages[0].bitmap->h;
  1696. }
  1697. else if (effect == 0)
  1698. {
  1699. be.x -= be.anim->ourImages[0].bitmap->w/2;
  1700. be.y -= be.anim->ourImages[0].bitmap->h;
  1701. }
  1702. battleEffects.push_back(be);
  1703. }
  1704. //battleEffects
  1705. }
  1706. void CBattleInterface::setAnimSpeed(int set)
  1707. {
  1708. animSpeed = set;
  1709. }
  1710. int CBattleInterface::getAnimSpeed() const
  1711. {
  1712. return animSpeed;
  1713. }
  1714. float CBattleInterface::getAnimSpeedMultiplier() const
  1715. {
  1716. switch(animSpeed)
  1717. {
  1718. case 1:
  1719. return 3.5f;
  1720. case 2:
  1721. return 2.2f;
  1722. case 4:
  1723. return 1.0f;
  1724. default:
  1725. return 0.0f;
  1726. }
  1727. }
  1728. void CBattleInterface::attackingShowHelper()
  1729. {
  1730. if(attackingInfo && !attackingInfo->reversing)
  1731. {
  1732. if(attackingInfo->frame == 0)
  1733. {
  1734. CStack aStack = *LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
  1735. if(attackingInfo->shooting)
  1736. {
  1737. creAnims[attackingInfo->ID]->setType(attackingInfo->shootingGroup);
  1738. }
  1739. else
  1740. {
  1741. if(aStack.creature->isDoubleWide())
  1742. {
  1743. switch(BattleInfo::mutualPosition(aStack.position+attackingInfo->posShiftDueToDist, attackingInfo->dest)) //attack direction
  1744. {
  1745. case 0:
  1746. creAnims[attackingInfo->ID]->setType(11);
  1747. break;
  1748. case 1:
  1749. creAnims[attackingInfo->ID]->setType(11);
  1750. break;
  1751. case 2:
  1752. creAnims[attackingInfo->ID]->setType(12);
  1753. break;
  1754. case 3:
  1755. creAnims[attackingInfo->ID]->setType(13);
  1756. break;
  1757. case 4:
  1758. creAnims[attackingInfo->ID]->setType(13);
  1759. break;
  1760. case 5:
  1761. creAnims[attackingInfo->ID]->setType(12);
  1762. break;
  1763. }
  1764. }
  1765. else //else for if(aStack.creature->isDoubleWide())
  1766. {
  1767. switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
  1768. {
  1769. case 0:
  1770. creAnims[attackingInfo->ID]->setType(11);
  1771. break;
  1772. case 1:
  1773. creAnims[attackingInfo->ID]->setType(11);
  1774. break;
  1775. case 2:
  1776. creAnims[attackingInfo->ID]->setType(12);
  1777. break;
  1778. case 3:
  1779. creAnims[attackingInfo->ID]->setType(13);
  1780. break;
  1781. case 4:
  1782. creAnims[attackingInfo->ID]->setType(13);
  1783. break;
  1784. case 5:
  1785. creAnims[attackingInfo->ID]->setType(12);
  1786. break;
  1787. }
  1788. }
  1789. }
  1790. }
  1791. else if(attackingInfo->frame == (attackingInfo->maxframe - 1))
  1792. {
  1793. attackingInfo->reversing = true;
  1794. CStack* aStackp = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
  1795. if(aStackp == NULL)
  1796. return;
  1797. CStack aStack = *aStackp;
  1798. if(aStack.attackerOwned)
  1799. {
  1800. if(aStack.creature->isDoubleWide())
  1801. {
  1802. switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
  1803. {
  1804. case 0:
  1805. //reverseCreature(ID, aStack.position, true);
  1806. break;
  1807. case 1:
  1808. break;
  1809. case 2:
  1810. break;
  1811. case 3:
  1812. break;
  1813. case 4:
  1814. //reverseCreature(ID, aStack.position, true);
  1815. break;
  1816. case 5:
  1817. reverseCreature(attackingInfo->ID, aStack.position, true);
  1818. break;
  1819. case -1:
  1820. if(attackingInfo->posShiftDueToDist) //if reversing stack will make its position adjacent to dest
  1821. {
  1822. reverseCreature(attackingInfo->ID, aStack.position, true);
  1823. }
  1824. break;
  1825. }
  1826. }
  1827. else //else for if(aStack.creature->isDoubleWide())
  1828. {
  1829. switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
  1830. {
  1831. case 0:
  1832. reverseCreature(attackingInfo->ID, aStack.position, true);
  1833. break;
  1834. case 1:
  1835. break;
  1836. case 2:
  1837. break;
  1838. case 3:
  1839. break;
  1840. case 4:
  1841. reverseCreature(attackingInfo->ID, aStack.position, true);
  1842. break;
  1843. case 5:
  1844. reverseCreature(attackingInfo->ID, aStack.position, true);
  1845. break;
  1846. }
  1847. }
  1848. }
  1849. else //if(aStack.attackerOwned)
  1850. {
  1851. if(aStack.creature->isDoubleWide())
  1852. {
  1853. switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
  1854. {
  1855. case 0:
  1856. //reverseCreature(ID, aStack.position, true);
  1857. break;
  1858. case 1:
  1859. break;
  1860. case 2:
  1861. reverseCreature(attackingInfo->ID, aStack.position, true);
  1862. break;
  1863. case 3:
  1864. break;
  1865. case 4:
  1866. //reverseCreature(ID, aStack.position, true);
  1867. break;
  1868. case 5:
  1869. //reverseCreature(ID, aStack.position, true);
  1870. break;
  1871. case -1:
  1872. if(attackingInfo->posShiftDueToDist) //if reversing stack will make its position adjacent to dest
  1873. {
  1874. reverseCreature(attackingInfo->ID, aStack.position, true);
  1875. }
  1876. break;
  1877. }
  1878. }
  1879. else //else for if(aStack.creature->isDoubleWide())
  1880. {
  1881. switch(BattleInfo::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
  1882. {
  1883. case 0:
  1884. //reverseCreature(ID, aStack.position, true);
  1885. break;
  1886. case 1:
  1887. reverseCreature(attackingInfo->ID, aStack.position, true);
  1888. break;
  1889. case 2:
  1890. reverseCreature(attackingInfo->ID, aStack.position, true);
  1891. break;
  1892. case 3:
  1893. reverseCreature(attackingInfo->ID, aStack.position, true);
  1894. break;
  1895. case 4:
  1896. //reverseCreature(ID, aStack.position, true);
  1897. break;
  1898. case 5:
  1899. //reverseCreature(ID, aStack.position, true);
  1900. break;
  1901. }
  1902. }
  1903. }
  1904. attackingInfo->reversing = false;
  1905. creAnims[attackingInfo->ID]->setType(2);
  1906. delete attackingInfo;
  1907. attackingInfo = NULL;
  1908. }
  1909. if(attackingInfo)
  1910. {
  1911. attackingInfo->hitCount++;
  1912. if(attackingInfo->hitCount%(4/animSpeed) == 0)
  1913. attackingInfo->frame++;
  1914. }
  1915. }
  1916. }
  1917. void CBattleInterface::redrawBackgroundWithHexes(int activeStack)
  1918. {
  1919. shadedHexes = LOCPLINT->cb->battleGetAvailableHexes(activeStack, true);
  1920. //preparating background graphic with hexes and shaded hexes
  1921. blitAt(background, 0, 0, backgroundWithHexes);
  1922. if(printCellBorders)
  1923. CSDL_Ext::blit8bppAlphaTo24bpp(cellBorders, NULL, backgroundWithHexes, NULL);
  1924. if(printStackRange)
  1925. {
  1926. for(size_t m=0; m<shadedHexes.size(); ++m) //rows
  1927. {
  1928. int i = shadedHexes[m]/BFIELD_WIDTH; //row
  1929. int j = shadedHexes[m]%BFIELD_WIDTH-1; //column
  1930. int x = 58 + (i%2==0 ? 22 : 0) + 44*j;
  1931. int y = 86 + 42 * i;
  1932. CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, NULL, backgroundWithHexes, &genRect(cellShade->h, cellShade->w, x, y));
  1933. }
  1934. }
  1935. }
  1936. void CBattleInterface::printConsoleAttacked(int ID, int dmg, int killed, int IDby)
  1937. {
  1938. char tabh[200];
  1939. CStack attacker = *LOCPLINT->cb->battleGetStackByID(IDby);
  1940. CStack defender = *LOCPLINT->cb->battleGetStackByID(ID);
  1941. int end = sprintf(tabh, CGI->generaltexth->allTexts[attacker.amount > 1 ? 377 : 376].c_str(),
  1942. (attacker.amount > 1 ? attacker.creature->namePl.c_str() : attacker.creature->nameSing.c_str()),
  1943. dmg);
  1944. if(killed > 0)
  1945. {
  1946. if(killed > 1)
  1947. {
  1948. sprintf(tabh + end, CGI->generaltexth->allTexts[379].c_str(), killed, defender.creature->namePl.c_str());
  1949. }
  1950. else //killed == 1
  1951. {
  1952. sprintf(tabh + end, CGI->generaltexth->allTexts[378].c_str(), defender.creature->nameSing.c_str());
  1953. }
  1954. }
  1955. console->addText(std::string(tabh));
  1956. }
  1957. void CBattleInterface::projectileShowHelper(SDL_Surface * to)
  1958. {
  1959. if(to == NULL)
  1960. to = screen;
  1961. std::list< std::list<SProjectileInfo>::iterator > toBeDeleted;
  1962. for(std::list<SProjectileInfo>::iterator it=projectiles.begin(); it!=projectiles.end(); ++it)
  1963. {
  1964. if(it->animStartDelay>0)
  1965. {
  1966. --(it->animStartDelay);
  1967. continue;
  1968. }
  1969. SDL_Rect dst;
  1970. dst.h = idToProjectile[it->creID]->ourImages[it->frameNum].bitmap->h;
  1971. dst.w = idToProjectile[it->creID]->ourImages[it->frameNum].bitmap->w;
  1972. dst.x = it->x;
  1973. dst.y = it->y;
  1974. if(it->reverse)
  1975. {
  1976. SDL_Surface * rev = CSDL_Ext::rotate01(idToProjectile[it->creID]->ourImages[it->frameNum].bitmap);
  1977. CSDL_Ext::blit8bppAlphaTo24bpp(rev, NULL, to, &dst);
  1978. SDL_FreeSurface(rev);
  1979. }
  1980. else
  1981. {
  1982. CSDL_Ext::blit8bppAlphaTo24bpp(idToProjectile[it->creID]->ourImages[it->frameNum].bitmap, NULL, to, &dst);
  1983. }
  1984. //actualizing projectile
  1985. ++it->step;
  1986. if(it->step == it->lastStep)
  1987. {
  1988. toBeDeleted.insert(toBeDeleted.end(), it);
  1989. }
  1990. else
  1991. {
  1992. it->x += it->dx;
  1993. it->y += it->dy;
  1994. if(it->spin)
  1995. {
  1996. ++(it->frameNum);
  1997. it->frameNum %= idToProjectile[it->creID]->ourImages.size();
  1998. }
  1999. }
  2000. }
  2001. for(std::list< std::list<SProjectileInfo>::iterator >::iterator it = toBeDeleted.begin(); it!= toBeDeleted.end(); ++it)
  2002. {
  2003. projectiles.erase(*it);
  2004. }
  2005. }
  2006. void CBattleHero::show(SDL_Surface *to)
  2007. {
  2008. //animation of flag
  2009. if(flip)
  2010. {
  2011. CSDL_Ext::blit8bppAlphaTo24bpp(
  2012. flag->ourImages[flagAnim].bitmap,
  2013. NULL,
  2014. screen,
  2015. &genRect(
  2016. flag->ourImages[flagAnim].bitmap->h,
  2017. flag->ourImages[flagAnim].bitmap->w,
  2018. 62 + pos.x,
  2019. 39 + pos.y
  2020. )
  2021. );
  2022. }
  2023. else
  2024. {
  2025. CSDL_Ext::blit8bppAlphaTo24bpp(
  2026. flag->ourImages[flagAnim].bitmap,
  2027. NULL,
  2028. screen,
  2029. &genRect(
  2030. flag->ourImages[flagAnim].bitmap->h,
  2031. flag->ourImages[flagAnim].bitmap->w,
  2032. 71 + pos.x,
  2033. 39 + pos.y
  2034. )
  2035. );
  2036. }
  2037. ++flagAnimCount;
  2038. if(flagAnimCount%4==0)
  2039. {
  2040. ++flagAnim;
  2041. flagAnim %= flag->ourImages.size();
  2042. }
  2043. //animation of hero
  2044. int tick=-1;
  2045. for(int i=0; i<dh->ourImages.size(); ++i)
  2046. {
  2047. if(dh->ourImages[i].groupNumber==phase)
  2048. ++tick;
  2049. if(tick==image)
  2050. {
  2051. SDL_Rect posb = pos;
  2052. CSDL_Ext::blit8bppAlphaTo24bpp(dh->ourImages[i].bitmap, NULL, to, &posb);
  2053. ++image;
  2054. if(dh->ourImages[(i+1)%dh->ourImages.size()].groupNumber!=phase) //back to appropriate frame
  2055. {
  2056. image = 0;
  2057. }
  2058. break;
  2059. }
  2060. }
  2061. }
  2062. void CBattleHero::activate()
  2063. {
  2064. ClickableL::activate();
  2065. }
  2066. void CBattleHero::deactivate()
  2067. {
  2068. ClickableL::deactivate();
  2069. }
  2070. void CBattleHero::setPhase(int newPhase)
  2071. {
  2072. phase = newPhase;
  2073. image = 0;
  2074. }
  2075. void CBattleHero::clickLeft(boost::logic::tribool down)
  2076. {
  2077. if(!down && myHero)
  2078. {
  2079. for(int it=0; it<BFIELD_SIZE; ++it) //do nothing when any hex is hovered - hero's animation overlaps battlefield
  2080. {
  2081. if(myOwner->bfield[it].hovered && myOwner->bfield[it].strictHovered)
  2082. return;
  2083. }
  2084. CGI->curh->changeGraphic(0,0);
  2085. LOCPLINT->curint->deactivate();
  2086. CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), myHero);
  2087. spellWindow->activate();
  2088. LOCPLINT->objsToBlit.push_back(spellWindow);
  2089. }
  2090. }
  2091. 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)
  2092. {
  2093. dh = CDefHandler::giveDef( defName );
  2094. for(int i=0; i<dh->ourImages.size(); ++i) //transforming images
  2095. {
  2096. if(flip)
  2097. {
  2098. SDL_Surface * hlp = CSDL_Ext::rotate01(dh->ourImages[i].bitmap);
  2099. SDL_FreeSurface(dh->ourImages[i].bitmap);
  2100. dh->ourImages[i].bitmap = hlp;
  2101. }
  2102. dh->ourImages[i].bitmap = CSDL_Ext::alphaTransform(dh->ourImages[i].bitmap);
  2103. }
  2104. dh->alphaTransformed = true;
  2105. if(flip)
  2106. flag = CDefHandler::giveDef("CMFLAGR.DEF");
  2107. else
  2108. flag = CDefHandler::giveDef("CMFLAGL.DEF");
  2109. //coloring flag and adding transparency
  2110. for(int i=0; i<flag->ourImages.size(); ++i)
  2111. {
  2112. flag->ourImages[i].bitmap = CSDL_Ext::alphaTransform(flag->ourImages[i].bitmap);
  2113. graphics->blueToPlayersAdv(flag->ourImages[i].bitmap, player);
  2114. }
  2115. }
  2116. CBattleHero::~CBattleHero()
  2117. {
  2118. delete dh;
  2119. delete flag;
  2120. }
  2121. std::pair<int, int> CBattleHex::getXYUnitAnim(const int & hexNum, const bool & attacker, const CCreature * creature)
  2122. {
  2123. std::pair<int, int> ret = std::make_pair(-500, -500); //returned value
  2124. ret.second = -139 + 42 * (hexNum/BFIELD_WIDTH); //counting y
  2125. //counting x
  2126. if(attacker)
  2127. {
  2128. ret.first = -160 + 22 * ( ((hexNum/BFIELD_WIDTH) + 1)%2 ) + 44 * (hexNum % BFIELD_WIDTH);
  2129. }
  2130. else
  2131. {
  2132. ret.first = -219 + 22 * ( ((hexNum/BFIELD_WIDTH) + 1)%2 ) + 44 * (hexNum % BFIELD_WIDTH);
  2133. }
  2134. //shifting position for double - hex creatures
  2135. if(creature && creature->isDoubleWide())
  2136. {
  2137. if(attacker)
  2138. {
  2139. ret.first -= 42;
  2140. }
  2141. else
  2142. {
  2143. ret.first += 42;
  2144. }
  2145. }
  2146. //returning
  2147. return ret;
  2148. }
  2149. void CBattleHex::activate()
  2150. {
  2151. Hoverable::activate();
  2152. MotionInterested::activate();
  2153. ClickableL::activate();
  2154. ClickableR::activate();
  2155. }
  2156. void CBattleHex::deactivate()
  2157. {
  2158. Hoverable::deactivate();
  2159. MotionInterested::deactivate();
  2160. ClickableL::deactivate();
  2161. ClickableR::deactivate();
  2162. }
  2163. void CBattleHex::hover(bool on)
  2164. {
  2165. hovered = on;
  2166. Hoverable::hover(on);
  2167. if(!on && setAlterText)
  2168. {
  2169. myInterface->console->alterTxt = std::string();
  2170. setAlterText = false;
  2171. }
  2172. }
  2173. CBattleHex::CBattleHex() : myNumber(-1), accesible(true), hovered(false), strictHovered(false), myInterface(NULL), setAlterText(false)
  2174. {
  2175. }
  2176. void CBattleHex::mouseMoved(const SDL_MouseMotionEvent &sEvent)
  2177. {
  2178. if(myInterface->cellShade)
  2179. {
  2180. if(CSDL_Ext::SDL_GetPixel(myInterface->cellShade, sEvent.x-pos.x, sEvent.y-pos.y) == 0) //hovered pixel is outside hex
  2181. {
  2182. strictHovered = false;
  2183. }
  2184. else //hovered pixel is inside hex
  2185. {
  2186. strictHovered = true;
  2187. }
  2188. }
  2189. if(hovered && strictHovered) //print attacked creature to console
  2190. {
  2191. if(myInterface->console->alterTxt.size() == 0 && LOCPLINT->cb->battleGetStack(myNumber) != -1 &&
  2192. LOCPLINT->cb->battleGetStackByPos(myNumber)->owner != LOCPLINT->playerID &&
  2193. LOCPLINT->cb->battleGetStackByPos(myNumber)->alive())
  2194. {
  2195. char tabh[160];
  2196. CStack attackedStack = *LOCPLINT->cb->battleGetStackByPos(myNumber);
  2197. const std::string & attackedName = attackedStack.amount == 1 ? attackedStack.creature->nameSing : attackedStack.creature->namePl;
  2198. sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str());
  2199. myInterface->console->alterTxt = std::string(tabh);
  2200. setAlterText = true;
  2201. }
  2202. }
  2203. else if(setAlterText)
  2204. {
  2205. myInterface->console->alterTxt = std::string();
  2206. setAlterText = false;
  2207. }
  2208. }
  2209. void CBattleHex::clickLeft(boost::logic::tribool down)
  2210. {
  2211. if(!down && hovered && strictHovered) //we've been really clicked!
  2212. {
  2213. myInterface->hexLclicked(myNumber);
  2214. }
  2215. }
  2216. void CBattleHex::clickRight(boost::logic::tribool down)
  2217. {
  2218. int stID = LOCPLINT->cb->battleGetStack(myNumber); //id of stack being on this tile
  2219. if(hovered && strictHovered && stID!=-1)
  2220. {
  2221. CStack myst = *LOCPLINT->cb->battleGetStackByID(stID); //stack info
  2222. if(!myst.alive()) return;
  2223. StackState *pom = NULL;
  2224. if(down)
  2225. {
  2226. pom = new StackState();
  2227. const CGHeroInstance *h = myst.owner == myInterface->attackingHeroInstance->tempOwner ? myInterface->attackingHeroInstance : myInterface->defendingHeroInstance;
  2228. if(h)
  2229. {
  2230. pom->attackBonus = h->getPrimSkillLevel(0);
  2231. pom->defenseBonus = h->getPrimSkillLevel(1);
  2232. pom->luck = myst.Luck();
  2233. pom->morale = myst.Morale();
  2234. pom->speedBonus = myst.speed() - myst.creature->speed;
  2235. }
  2236. pom->shotsLeft = myst.shots;
  2237. for(int vb=0; vb<myst.effects.size(); ++vb)
  2238. {
  2239. pom->effects.insert(myst.effects[vb].id);
  2240. }
  2241. pom->currentHealth = myst.firstHPleft;
  2242. (new CCreInfoWindow(myst.creature->idNumber,0,myst.amount,pom,boost::function<void()>(),boost::function<void()>(),NULL))
  2243. ->activate();
  2244. }
  2245. delete pom;
  2246. }
  2247. }
  2248. CBattleConsole::CBattleConsole() : lastShown(-1), alterTxt(""), whoSetAlter(0)
  2249. {
  2250. }
  2251. CBattleConsole::~CBattleConsole()
  2252. {
  2253. texts.clear();
  2254. }
  2255. void CBattleConsole::show(SDL_Surface * to)
  2256. {
  2257. if(alterTxt.size())
  2258. {
  2259. CSDL_Ext::printAtMiddleWB(alterTxt, pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to);
  2260. }
  2261. else if(texts.size())
  2262. {
  2263. if(texts.size()==1)
  2264. {
  2265. CSDL_Ext::printAtMiddleWB(texts[0], pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to);
  2266. }
  2267. else
  2268. {
  2269. CSDL_Ext::printAtMiddleWB(texts[lastShown-1], pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to);
  2270. CSDL_Ext::printAtMiddleWB(texts[lastShown], pos.x + pos.w/2, pos.y + 26, GEOR13, 80, zwykly, to);
  2271. }
  2272. }
  2273. }
  2274. bool CBattleConsole::addText(const std::string & text)
  2275. {
  2276. if(text.size()>70)
  2277. return false; //text too long!
  2278. int firstInToken = 0;
  2279. for(int i=0; i<text.size(); ++i) //tokenize
  2280. {
  2281. if(text[i] == 10)
  2282. {
  2283. texts.push_back( text.substr(firstInToken, i-firstInToken) );
  2284. firstInToken = i+1;
  2285. }
  2286. }
  2287. texts.push_back( text.substr(firstInToken, text.size()) );
  2288. lastShown = texts.size()-1;
  2289. return true;
  2290. }
  2291. void CBattleConsole::eraseText(unsigned int pos)
  2292. {
  2293. if(pos < texts.size())
  2294. {
  2295. texts.erase(texts.begin() + pos);
  2296. if(lastShown == texts.size())
  2297. --lastShown;
  2298. }
  2299. }
  2300. void CBattleConsole::changeTextAt(const std::string & text, unsigned int pos)
  2301. {
  2302. if(pos >= texts.size()) //no such pos
  2303. return;
  2304. texts[pos] = text;
  2305. }
  2306. void CBattleConsole::scrollUp(unsigned int by)
  2307. {
  2308. if(lastShown > by)
  2309. lastShown -= by;
  2310. }
  2311. void CBattleConsole::scrollDown(unsigned int by)
  2312. {
  2313. if(lastShown + by < texts.size())
  2314. lastShown += by;
  2315. }
  2316. CBattleReslutWindow::CBattleReslutWindow(const BattleResult &br, const SDL_Rect & pos, const CBattleInterface * owner)
  2317. {
  2318. this->pos = pos;
  2319. background = BitmapHandler::loadBitmap("CPRESULT.BMP", true);
  2320. graphics->blueToPlayersAdv(background, LOCPLINT->playerID);
  2321. SDL_Surface * pom = SDL_ConvertSurface(background, screen->format, screen->flags);
  2322. SDL_FreeSurface(background);
  2323. background = pom;
  2324. exit = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleReslutWindow::bExitf,this), 384 + pos.x, 505 + pos.y, "iok6432.def", SDLK_RETURN);
  2325. if(br.winner==0) //attacker won
  2326. {
  2327. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 60, 122, GEOR13, zwykly, background);
  2328. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 410, 122, GEOR13, zwykly, background);
  2329. }
  2330. else //if(br.winner==1)
  2331. {
  2332. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[411], 60, 122, GEOR13, zwykly, background);
  2333. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[410], 410, 122, GEOR13, zwykly, background);
  2334. }
  2335. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[407], 235, 299, GEOR16, tytulowy, background);
  2336. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[408], 235, 329, GEOR16, zwykly, background);
  2337. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[409], 235, 426, GEOR16, zwykly, background);
  2338. std::string attackerName, defenderName;
  2339. if(owner->attackingHeroInstance) //a hero attacked
  2340. {
  2341. SDL_BlitSurface(graphics->portraitLarge[owner->attackingHeroInstance->portrait], NULL, background, &genRect(64, 58, 21, 38));
  2342. //setting attackerName
  2343. attackerName = owner->attackingHeroInstance->name;
  2344. }
  2345. else //a monster attacked
  2346. {
  2347. int bestMonsterID = -1;
  2348. int bestPower = 0;
  2349. for(std::map<si32,std::pair<ui32,si32> >::const_iterator it = owner->army1->slots.begin(); it!=owner->army1->slots.end(); ++it)
  2350. {
  2351. if( CGI->creh->creatures[it->first].AIValue > bestPower)
  2352. {
  2353. bestPower = CGI->creh->creatures[it->first].AIValue;
  2354. bestMonsterID = it->first;
  2355. }
  2356. }
  2357. SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &genRect(64, 58, 21, 38));
  2358. //setting attackerName
  2359. attackerName = CGI->creh->creatures[bestMonsterID].namePl;
  2360. }
  2361. if(owner->defendingHeroInstance) //a hero defended
  2362. {
  2363. SDL_BlitSurface(graphics->portraitLarge[owner->defendingHeroInstance->portrait], NULL, background, &genRect(64, 58, 391, 38));
  2364. //setting defenderName
  2365. defenderName = owner->defendingHeroInstance->name;
  2366. }
  2367. else //a monster defended
  2368. {
  2369. int bestMonsterID = -1;
  2370. int bestPower = 0;
  2371. for(std::map<si32,std::pair<ui32,si32> >::const_iterator it = owner->army2->slots.begin(); it!=owner->army2->slots.end(); ++it)
  2372. {
  2373. if( CGI->creh->creatures[it->second.first].AIValue > bestPower)
  2374. {
  2375. bestPower = CGI->creh->creatures[it->second.first].AIValue;
  2376. bestMonsterID = it->second.first;
  2377. }
  2378. }
  2379. SDL_BlitSurface(graphics->bigImgs[bestMonsterID], NULL, background, &genRect(64, 58, 391, 38));
  2380. //setting defenderName
  2381. defenderName = CGI->creh->creatures[bestMonsterID].namePl;
  2382. }
  2383. //printing attacker and defender's names
  2384. CSDL_Ext::printAtMiddle(attackerName, 156, 44, GEOR16, zwykly, background);
  2385. CSDL_Ext::printAtMiddle(defenderName, 314, 44, GEOR16, zwykly, background);
  2386. //printing casualities
  2387. for(int step = 0; step < 2; ++step)
  2388. {
  2389. if(br.casualties[step].size()==0)
  2390. {
  2391. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[523], 235, 360 + 97*step, GEOR16, zwykly, background);
  2392. }
  2393. else
  2394. {
  2395. int xPos = 235 - (br.casualties[step].size()*32 + (br.casualties[step].size() - 1)*10)/2; //increment by 42 with each picture
  2396. int yPos = 344 + step*97;
  2397. for(std::set<std::pair<ui32,si32> >::const_iterator it=br.casualties[step].begin(); it!=br.casualties[step].end(); ++it)
  2398. {
  2399. blitAt(graphics->smallImgs[it->first], xPos, yPos, background);
  2400. std::stringstream amount;
  2401. amount<<it->second;
  2402. CSDL_Ext::printAtMiddle(amount.str(), xPos+16, yPos + 42, GEOR13, zwykly, background);
  2403. xPos += 42;
  2404. }
  2405. }
  2406. }
  2407. //printing result description
  2408. bool weAreAttacker = (LOCPLINT->playerID == owner->attackingHeroInstance->tempOwner);
  2409. switch(br.result)
  2410. {
  2411. case 0: //normal victory
  2412. if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won
  2413. {
  2414. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[304], 235, 235, GEOR13, zwykly, background);
  2415. }
  2416. else
  2417. {
  2418. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[311], 235, 235, GEOR13, zwykly, background);
  2419. }
  2420. break;
  2421. case 1: //flee
  2422. if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won
  2423. {
  2424. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[303], 235, 235, GEOR13, zwykly, background);
  2425. }
  2426. else
  2427. {
  2428. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[310], 235, 235, GEOR13, zwykly, background);
  2429. }
  2430. break;
  2431. case 2: //surrender
  2432. if((br.winner == 0 && weAreAttacker) || (br.winner == 1 && !weAreAttacker)) //we've won
  2433. {
  2434. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[302], 235, 235, GEOR13, zwykly, background);
  2435. }
  2436. else
  2437. {
  2438. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[309], 235, 235, GEOR13, zwykly, background);
  2439. }
  2440. break;
  2441. }
  2442. }
  2443. CBattleReslutWindow::~CBattleReslutWindow()
  2444. {
  2445. SDL_FreeSurface(background);
  2446. }
  2447. void CBattleReslutWindow::activate()
  2448. {
  2449. LOCPLINT->showingDialog->set(true);
  2450. exit->activate();
  2451. }
  2452. void CBattleReslutWindow::deactivate()
  2453. {
  2454. exit->deactivate();
  2455. }
  2456. void CBattleReslutWindow::show(SDL_Surface *to)
  2457. {
  2458. //evaluating to
  2459. if(!to)
  2460. to = screen;
  2461. SDL_BlitSurface(background, NULL, to, &pos);
  2462. exit->show(to);
  2463. }
  2464. void CBattleReslutWindow::bExitf()
  2465. {
  2466. LOCPLINT->battleResultQuited();
  2467. }
  2468. CBattleOptionsWindow::CBattleOptionsWindow(const SDL_Rect & position, CBattleInterface *owner): myInt(owner)
  2469. {
  2470. pos = position;
  2471. background = BitmapHandler::loadBitmap("comopbck.bmp", true);
  2472. graphics->blueToPlayersAdv(background, LOCPLINT->playerID);
  2473. viewGrid = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintCellBorders, owner, true), boost::bind(&CBattleInterface::setPrintCellBorders, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[427].first)(3,CGI->generaltexth->zelp[427].first), CGI->generaltexth->zelp[427].second, false, "sysopchk.def", NULL, 185, 140, false);
  2474. viewGrid->select(owner->printCellBorders);
  2475. movementShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintStackRange, owner, true), boost::bind(&CBattleInterface::setPrintStackRange, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[428].first)(3,CGI->generaltexth->zelp[428].first), CGI->generaltexth->zelp[428].second, false, "sysopchk.def", NULL, 185, 173, false);
  2476. movementShadow->select(owner->printStackRange);
  2477. mouseShadow = new CHighlightableButton(boost::bind(&CBattleInterface::setPrintMouseShadow, owner, true), boost::bind(&CBattleInterface::setPrintMouseShadow, owner, false), boost::assign::map_list_of(0,CGI->generaltexth->zelp[429].first)(3,CGI->generaltexth->zelp[429].first), CGI->generaltexth->zelp[429].second, false, "sysopchk.def", NULL, 185, 207, false);
  2478. mouseShadow->select(owner->printMouseShadow);
  2479. animSpeeds = new CHighlightableButtonsGroup(0);
  2480. animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[422].first),CGI->generaltexth->zelp[422].second, "sysopb9.def",188, 309, 1);
  2481. animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[423].first),CGI->generaltexth->zelp[423].second, "sysob10.def",252, 309, 2);
  2482. animSpeeds->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[424].first),CGI->generaltexth->zelp[424].second, "sysob11.def",315, 309, 4);
  2483. animSpeeds->select(owner->getAnimSpeed(), 1);
  2484. animSpeeds->onChange = boost::bind(&CBattleInterface::setAnimSpeed, owner, _1);
  2485. setToDefault = new AdventureMapButton (CGI->generaltexth->zelp[392].first, CGI->generaltexth->zelp[392].second, boost::bind(&CBattleOptionsWindow::bDefaultf,this), 405, 443, "codefaul.def");
  2486. std::swap(setToDefault->imgs[0][0], setToDefault->imgs[0][1]);
  2487. exit = new AdventureMapButton (CGI->generaltexth->zelp[393].first, CGI->generaltexth->zelp[393].second, boost::bind(&CBattleOptionsWindow::bExitf,this), 516, 443, "soretrn.def",SDLK_RETURN);
  2488. std::swap(exit->imgs[0][0], exit->imgs[0][1]);
  2489. //printing texts to background
  2490. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[392], 240, 32, GEOR16, tytulowy, background); //window title
  2491. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[393], 122, 211, GEOR16, tytulowy, background); //animation speed
  2492. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[394], 122, 292, GEOR16, tytulowy, background); //music volume
  2493. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[395], 122, 358, GEOR16, tytulowy, background); //effects' volume
  2494. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[396], 353, 64, GEOR16, tytulowy, background); //auto - combat options
  2495. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[397], 353, 264, GEOR16, tytulowy, background); //creature info
  2496. //auto - combat options
  2497. CSDL_Ext::printAt(CGI->generaltexth->allTexts[398], 283, 87, GEOR16, zwykly, background); //creatures
  2498. CSDL_Ext::printAt(CGI->generaltexth->allTexts[399], 283, 117, GEOR16, zwykly, background); //spells
  2499. CSDL_Ext::printAt(CGI->generaltexth->allTexts[400], 283, 147, GEOR16, zwykly, background); //catapult
  2500. CSDL_Ext::printAt(CGI->generaltexth->allTexts[151], 283, 177, GEOR16, zwykly, background); //ballista
  2501. CSDL_Ext::printAt(CGI->generaltexth->allTexts[401], 283, 207, GEOR16, zwykly, background); //first aid tent
  2502. //creature info
  2503. CSDL_Ext::printAt(CGI->generaltexth->allTexts[402], 283, 286, GEOR16, zwykly, background); //all stats
  2504. CSDL_Ext::printAt(CGI->generaltexth->allTexts[403], 283, 316, GEOR16, zwykly, background); //spells only
  2505. //general options
  2506. CSDL_Ext::printAt(CGI->generaltexth->allTexts[404], 61, 58, GEOR16, zwykly, background); //hex grid
  2507. CSDL_Ext::printAt(CGI->generaltexth->allTexts[405], 61, 91, GEOR16, zwykly, background); //movement shadow
  2508. CSDL_Ext::printAt(CGI->generaltexth->allTexts[406], 61, 124, GEOR16, zwykly, background); //cursor shadow
  2509. CSDL_Ext::printAt(CGI->generaltexth->allTexts[577], 61, 157, GEOR16, zwykly, background); //spellbook animation
  2510. //texts printed
  2511. }
  2512. CBattleOptionsWindow::~CBattleOptionsWindow()
  2513. {
  2514. SDL_FreeSurface(background);
  2515. delete setToDefault;
  2516. delete exit;
  2517. delete viewGrid;
  2518. delete movementShadow;
  2519. delete animSpeeds;
  2520. delete mouseShadow;
  2521. }
  2522. void CBattleOptionsWindow::activate()
  2523. {
  2524. setToDefault->activate();
  2525. exit->activate();
  2526. viewGrid->activate();
  2527. movementShadow->activate();
  2528. animSpeeds->activate();
  2529. mouseShadow->activate();
  2530. }
  2531. void CBattleOptionsWindow::deactivate()
  2532. {
  2533. setToDefault->deactivate();
  2534. exit->deactivate();
  2535. viewGrid->deactivate();
  2536. movementShadow->deactivate();
  2537. animSpeeds->deactivate();
  2538. mouseShadow->deactivate();
  2539. }
  2540. void CBattleOptionsWindow::show(SDL_Surface *to)
  2541. {
  2542. if(!to) //"evaluating" to
  2543. to = screen;
  2544. SDL_BlitSurface(background, NULL, to, &pos);
  2545. setToDefault->show(to);
  2546. exit->show(to);
  2547. viewGrid->show(to);
  2548. movementShadow->show(to);
  2549. animSpeeds->show(to);
  2550. mouseShadow->show(to);
  2551. }
  2552. void CBattleOptionsWindow::bDefaultf()
  2553. {
  2554. }
  2555. void CBattleOptionsWindow::bExitf()
  2556. {
  2557. deactivate();
  2558. for(size_t g=0; g<LOCPLINT->objsToBlit.size(); ++g)
  2559. {
  2560. if(dynamic_cast<CBattleOptionsWindow*>(LOCPLINT->objsToBlit[g]))
  2561. {
  2562. LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+g);
  2563. break;
  2564. }
  2565. }
  2566. delete this;
  2567. LOCPLINT->curint->activate();
  2568. }