CBattleInterface.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  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\CHeroHandler.h"
  8. #include "hch\CDefHandler.h"
  9. #include "CCallback.h"
  10. #include "CGameState.h"
  11. #include "hch\CGeneralTextHandler.h"
  12. #include "client/CCreatureAnimation.h"
  13. #include <queue>
  14. #include <sstream>
  15. extern SDL_Surface * screen;
  16. extern TTF_Font * GEOR13;
  17. extern SDL_Color zwykly;
  18. SDL_Surface * CBattleInterface::cellBorder, * CBattleInterface::cellShade;
  19. CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2)
  20. : printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL), attackingInfo(NULL)
  21. {
  22. //initializing armies
  23. this->army1 = army1;
  24. this->army2 = army2;
  25. std::map<int, CStack> stacks = LOCPLINT->cb->battleGetStacks();
  26. for(std::map<int, CStack>::iterator b=stacks.begin(); b!=stacks.end(); ++b)
  27. {
  28. std::pair <int, int> coords = CBattleHex::getXYUnitAnim(b->second.position, b->second.owner == attackingHeroInstance->tempOwner, b->second.creature);
  29. creAnims[b->second.ID] = (new CCreatureAnimation(b->second.creature->animDefName));
  30. creAnims[b->second.ID]->setType(2);
  31. creAnims[b->second.ID]->pos = genRect(creAnims[b->second.ID]->fullHeight, creAnims[b->second.ID]->fullWidth, coords.first, coords.second);
  32. creDir[b->second.ID] = b->second.owner==attackingHeroInstance->tempOwner;
  33. }
  34. //preparing menu background and terrain
  35. std::vector< std::string > & backref = CGI->mh->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ];
  36. background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()] );
  37. menu = BitmapHandler::loadBitmap("CBAR.BMP");
  38. CSDL_Ext::blueToPlayersAdv(menu, hero1->tempOwner);
  39. //preparing graphics for displaying amounts of creatures
  40. amountBasic = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
  41. amountNormal = BitmapHandler::loadBitmap("CMNUMWIN.BMP");
  42. CSDL_Ext::alphaTransform(amountNormal);
  43. for(int g=0; g<amountNormal->format->palette->ncolors; ++g)
  44. {
  45. if((amountNormal->format->palette->colors+g)->b != 132 &&
  46. (amountNormal->format->palette->colors+g)->g != 231 &&
  47. (amountNormal->format->palette->colors+g)->r != 255) //it's not yellow border
  48. {
  49. (amountNormal->format->palette->colors+g)->r = (float)((amountNormal->format->palette->colors+g)->r) * 0.54f;
  50. (amountNormal->format->palette->colors+g)->g = (float)((amountNormal->format->palette->colors+g)->g) * 0.19f;
  51. (amountNormal->format->palette->colors+g)->b = (float)((amountNormal->format->palette->colors+g)->b) * 0.93f;
  52. }
  53. }
  54. ////blitting menu background and terrain
  55. blitAt(background, 0, 0);
  56. blitAt(menu, 0, 556);
  57. CSDL_Ext::update();
  58. //preparing buttons and console
  59. bOptions = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bOptionsf,this), 3, 561, "icm003.def", false, NULL, false);
  60. bSurrender = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSurrenderf,this), 54, 561, "icm001.def", false, NULL, false);
  61. bFlee = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bFleef,this), 105, 561, "icm002.def", false, NULL, false);
  62. bAutofight = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bAutofightf,this), 157, 561, "icm004.def", false, NULL, false);
  63. bSpell = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSpellf,this), 645, 561, "icm005.def", false, NULL, false);
  64. bWait = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bWaitf,this), 696, 561, "icm006.def", false, NULL, false);
  65. bDefence = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bDefencef,this), 747, 561, "icm007.def", false, NULL, false);
  66. bConsoleUp = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleUpf,this), 624, 561, "ComSlide.def", false, NULL, false);
  67. bConsoleDown = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleDownf,this), 624, 580, "ComSlide.def", false, NULL, false);
  68. bConsoleDown->bitmapOffset = 2;
  69. console = new CBattleConsole();
  70. console->pos.x = 211;
  71. console->pos.y = 560;
  72. console->pos.w = 406;
  73. console->pos.h = 38;
  74. //loading hero animations
  75. if(hero1) // attacking hero
  76. {
  77. attackingHero = new CBattleHero(CGI->mh->battleHeroes[hero1->type->heroType], 0, 0, false, hero1->tempOwner);
  78. attackingHero->pos = genRect(attackingHero->dh->ourImages[0].bitmap->h, attackingHero->dh->ourImages[0].bitmap->w, -40, 0);
  79. }
  80. else
  81. {
  82. attackingHero = NULL;
  83. }
  84. if(hero2) // defending hero
  85. {
  86. defendingHero = new CBattleHero(CGI->mh->battleHeroes[hero2->type->heroType], 0, 0, true, hero2->tempOwner);
  87. defendingHero->pos = genRect(defendingHero->dh->ourImages[0].bitmap->h, defendingHero->dh->ourImages[0].bitmap->w, 690, 0);
  88. }
  89. else
  90. {
  91. defendingHero = NULL;
  92. }
  93. //preparing cells and hexes
  94. cellBorder = BitmapHandler::loadBitmap("CCELLGRD.BMP");
  95. CSDL_Ext::alphaTransform(cellBorder);
  96. cellShade = BitmapHandler::loadBitmap("CCELLSHD.BMP");
  97. CSDL_Ext::alphaTransform(cellShade);
  98. for(int h=0; h<187; ++h)
  99. {
  100. bfield[h].myNumber = h;
  101. int x = 14 + ((h/17)%2==0 ? 22 : 0) + 44*(h%17);
  102. int y = 86 + 42 * (h/17);
  103. bfield[h].pos = genRect(cellShade->h, cellShade->w, x, y);
  104. bfield[h].accesible = true;
  105. bfield[h].myInterface = this;
  106. }
  107. //locking occupied positions on batlefield
  108. for(std::map<int, CStack>::iterator it = stacks.begin(); it!=stacks.end(); ++it) //stacks gained at top of this function
  109. {
  110. bfield[it->second.position].accesible = false;
  111. }
  112. }
  113. CBattleInterface::~CBattleInterface()
  114. {
  115. SDL_FreeSurface(background);
  116. SDL_FreeSurface(menu);
  117. SDL_FreeSurface(amountBasic);
  118. SDL_FreeSurface(amountNormal);
  119. delete bOptions;
  120. delete bSurrender;
  121. delete bFlee;
  122. delete bAutofight;
  123. delete bSpell;
  124. delete bWait;
  125. delete bDefence;
  126. delete bConsoleUp;
  127. delete bConsoleDown;
  128. delete console;
  129. delete attackingHero;
  130. delete defendingHero;
  131. SDL_FreeSurface(cellBorder);
  132. SDL_FreeSurface(cellShade);
  133. for(std::map< int, CCreatureAnimation * >::iterator g=creAnims.begin(); g!=creAnims.end(); ++g)
  134. delete g->second;
  135. }
  136. void CBattleInterface::activate()
  137. {
  138. bOptions->activate();
  139. bSurrender->activate();
  140. bFlee->activate();
  141. bAutofight->activate();
  142. bSpell->activate();
  143. bWait->activate();
  144. bDefence->activate();
  145. bConsoleUp->activate();
  146. bConsoleDown->activate();
  147. for(int b=0; b<187; ++b)
  148. {
  149. bfield[b].activate();
  150. }
  151. }
  152. void CBattleInterface::deactivate()
  153. {
  154. bOptions->deactivate();
  155. bSurrender->deactivate();
  156. bFlee->deactivate();
  157. bAutofight->deactivate();
  158. bSpell->deactivate();
  159. bWait->deactivate();
  160. bDefence->deactivate();
  161. bConsoleUp->deactivate();
  162. bConsoleDown->deactivate();
  163. for(int b=0; b<187; ++b)
  164. {
  165. bfield[b].deactivate();
  166. }
  167. }
  168. void CBattleInterface::show(SDL_Surface * to)
  169. {
  170. std::map<int, CStack> stacks = LOCPLINT->cb->battleGetStacks(); //used in a few places
  171. ++animCount;
  172. if(!to) //"evaluating" to
  173. to = screen;
  174. //showing background
  175. blitAt(background, 0, 0, to);
  176. if(printCellBorders) //printing cell borders
  177. {
  178. for(int i=0; i<11; ++i) //rows
  179. {
  180. for(int j=0; j<15; ++j) //columns
  181. {
  182. int x = 58 + (i%2==0 ? 22 : 0) + 44*j;
  183. int y = 86 + 42 * i;
  184. CSDL_Ext::blit8bppAlphaTo24bpp(cellBorder, NULL, to, &genRect(cellBorder->h, cellBorder->w, x, y));
  185. }
  186. }
  187. }
  188. //printing hovered cell
  189. for(int b=0; b<187; ++b)
  190. {
  191. if(bfield[b].strictHovered && bfield[b].hovered)
  192. {
  193. int x = 14 + ((b/17)%2==0 ? 22 : 0) + 44*(b%17);
  194. int y = 86 + 42 * (b/17);
  195. CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, NULL, to, &genRect(cellShade->h, cellShade->w, x, y));
  196. }
  197. }
  198. //showing selected unit's range
  199. if(activeStack != -1 && creAnims[activeStack]->getType() != 0) //don't show if unit is moving
  200. {
  201. showRange(to, activeStack);
  202. }
  203. //showing menu background and console
  204. blitAt(menu, 0, 556, to);
  205. console->show(to);
  206. //showing buttons
  207. bOptions->show(to);
  208. bSurrender->show(to);
  209. bFlee->show(to);
  210. bAutofight->show(to);
  211. bSpell->show(to);
  212. bWait->show(to);
  213. bDefence->show(to);
  214. bConsoleUp->show(to);
  215. bConsoleDown->show(to);
  216. //showing hero animations
  217. if(attackingHero)
  218. attackingHero->show(to);
  219. if(defendingHero)
  220. defendingHero->show(to);
  221. //showing units //a lot of work...
  222. std::vector<int> stackAliveByHex[187];
  223. //double loop because dead stacks should be printed first
  224. for(std::map<int, CStack>::iterator j=stacks.begin(); j!=stacks.end(); ++j)
  225. {
  226. if(j->second.alive)
  227. stackAliveByHex[j->second.position].push_back(j->second.ID);
  228. }
  229. std::vector<int> stackDeadByHex[187];
  230. for(std::map<int, CStack>::iterator j=stacks.begin(); j!=stacks.end(); ++j)
  231. {
  232. if(!j->second.alive)
  233. stackDeadByHex[j->second.position].push_back(j->second.ID);
  234. }
  235. attackingShowHelper(); // handle attack animation
  236. for(int b=0; b<187; ++b) //showing dead stacks
  237. {
  238. for(int v=0; v<stackDeadByHex[b].size(); ++v)
  239. {
  240. creAnims[stackDeadByHex[b][v]]->nextFrame(to, creAnims[stackDeadByHex[b][v]]->pos.x, creAnims[stackDeadByHex[b][v]]->pos.y, creDir[stackDeadByHex[b][v]], (animCount%2==0 || creAnims[stackDeadByHex[b][v]]->getType()!=2) && stacks[stackDeadByHex[b][v]].alive, stackDeadByHex[b][v]==activeStack); //increment always when moving, never if stack died
  241. //printing amount
  242. if(stacks[stackDeadByHex[b][v]].amount > 0) //don't print if stack is not alive
  243. {
  244. if(stacks[stackDeadByHex[b][v]].attackerOwned)
  245. {
  246. CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackDeadByHex[b][v]]->pos.x + 220, creAnims[stackDeadByHex[b][v]]->pos.y + 260));
  247. std::stringstream ss;
  248. ss<<stacks[stackDeadByHex[b][v]].amount;
  249. CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackDeadByHex[b][v]]->pos.x + 220 + 14, creAnims[stackDeadByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
  250. }
  251. else
  252. {
  253. CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackDeadByHex[b][v]]->pos.x + 202, creAnims[stackDeadByHex[b][v]]->pos.y + 260));
  254. std::stringstream ss;
  255. ss<<stacks[stackDeadByHex[b][v]].amount;
  256. CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackDeadByHex[b][v]]->pos.x + 202 + 14, creAnims[stackDeadByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
  257. }
  258. }
  259. }
  260. }
  261. for(int b=0; b<187; ++b) //showing alive stacks
  262. {
  263. for(int v=0; v<stackAliveByHex[b].size(); ++v)
  264. {
  265. creAnims[stackAliveByHex[b][v]]->nextFrame(to, creAnims[stackAliveByHex[b][v]]->pos.x, creAnims[stackAliveByHex[b][v]]->pos.y, creDir[stackAliveByHex[b][v]], (animCount%2==0 || creAnims[stackAliveByHex[b][v]]->getType()!=2) && stacks[stackAliveByHex[b][v]].alive, stackAliveByHex[b][v]==activeStack); //increment always when moving, never if stack died
  266. //printing amount
  267. if(stacks[stackAliveByHex[b][v]].amount > 0) //don't print if stack is not alive
  268. {
  269. if(stacks[stackAliveByHex[b][v]].attackerOwned)
  270. {
  271. CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackAliveByHex[b][v]]->pos.x + 220, creAnims[stackAliveByHex[b][v]]->pos.y + 260));
  272. std::stringstream ss;
  273. ss<<stacks[stackAliveByHex[b][v]].amount;
  274. CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackAliveByHex[b][v]]->pos.x + 220 + 14, creAnims[stackAliveByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
  275. }
  276. else
  277. {
  278. CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackAliveByHex[b][v]]->pos.x + 202, creAnims[stackAliveByHex[b][v]]->pos.y + 260));
  279. std::stringstream ss;
  280. ss<<stacks[stackAliveByHex[b][v]].amount;
  281. CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackAliveByHex[b][v]]->pos.x + 202 + 14, creAnims[stackAliveByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
  282. }
  283. }
  284. }
  285. }
  286. //units shown
  287. }
  288. bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick)
  289. {
  290. if(creAnims[number]==NULL)
  291. return false; //there is no such creature
  292. creAnims[number]->setType(8);
  293. for(int g=0; g<creAnims[number]->framesInGroup(8); ++g)
  294. {
  295. show();
  296. CSDL_Ext::update();
  297. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  298. }
  299. creDir[number] = !creDir[number];
  300. CStack curs = LOCPLINT->cb->battleGetStackByID(number);
  301. std::pair <int, int> coords = CBattleHex::getXYUnitAnim(hex, creDir[number], curs.creature);
  302. creAnims[number]->pos.x = coords.first;
  303. //creAnims[number]->pos.y = coords.second;
  304. if(wideTrick && curs.creature->isDoubleWide())
  305. {
  306. creAnims[number]->pos.x -= 44;
  307. }
  308. creAnims[number]->setType(7);
  309. for(int g=0; g<creAnims[number]->framesInGroup(7); ++g)
  310. {
  311. show();
  312. CSDL_Ext::update();
  313. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  314. }
  315. creAnims[number]->setType(2);
  316. return true;
  317. }
  318. void CBattleInterface::bOptionsf()
  319. {
  320. }
  321. void CBattleInterface::bSurrenderf()
  322. {
  323. }
  324. void CBattleInterface::bFleef()
  325. {
  326. BattleAction * ba = new BattleAction;
  327. ba->actionType = 4;
  328. givenCommand = ba;
  329. }
  330. void CBattleInterface::bAutofightf()
  331. {
  332. }
  333. void CBattleInterface::bSpellf()
  334. {
  335. }
  336. void CBattleInterface::bWaitf()
  337. {
  338. }
  339. void CBattleInterface::bDefencef()
  340. {
  341. BattleAction * ba = new BattleAction;
  342. ba->actionType = 3;
  343. ba->stackNumber = activeStack;
  344. givenCommand = ba;
  345. }
  346. void CBattleInterface::bConsoleUpf()
  347. {
  348. console->scrollUp();
  349. }
  350. void CBattleInterface::bConsoleDownf()
  351. {
  352. console->scrollDown();
  353. }
  354. void CBattleInterface::newStack(CStack stack)
  355. {
  356. creAnims[stack.ID] = new CCreatureAnimation(stack.creature->animDefName);
  357. creAnims[stack.ID]->setType(2);
  358. creDir[stack.ID] = stack.owner==attackingHeroInstance->tempOwner;
  359. }
  360. void CBattleInterface::stackRemoved(CStack stack)
  361. {
  362. delete creAnims[stack.ID];
  363. creAnims.erase(stack.ID);
  364. }
  365. void CBattleInterface::stackKilled(int ID, int dmg, int killed, int IDby)
  366. {
  367. creAnims[ID]->setType(5); //death
  368. for(int i=0; i<creAnims[ID]->framesInGroup(5)-1; ++i)
  369. {
  370. show();
  371. CSDL_Ext::update();
  372. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  373. }
  374. printConsoleAttacked(ID, dmg, killed, IDby);
  375. }
  376. void CBattleInterface::stackActivated(int number)
  377. {
  378. givenCommand = NULL;
  379. activeStack = number;
  380. }
  381. void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, bool endMoving)
  382. {
  383. //a few useful variables
  384. int curStackPos = LOCPLINT->cb->battleGetPos(number);
  385. int steps = creAnims[number]->framesInGroup(0);
  386. int hexWbase = 44, hexHbase = 42;
  387. if(startMoving) //animation of starting move
  388. {
  389. for(int i=0; i<creAnims[number]->framesInGroup(20); ++i)
  390. {
  391. show();
  392. CSDL_Ext::update();
  393. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  394. }
  395. }
  396. int mutPos = CBattleHex::mutualPosition(curStackPos, destHex);
  397. if(LOCPLINT->cb->battleGetCreature(number).isDoubleWide() &&
  398. ((creDir[number] && mutPos == 5) || (creDir[number] && mutPos == 0) || (creDir[number] && mutPos == 4))) //for special cases
  399. {
  400. switch(CBattleHex::mutualPosition(curStackPos, destHex)) //reverse unit if necessary
  401. {
  402. case 0:
  403. if(creDir[number] == true)
  404. reverseCreature(number, curStackPos, true);
  405. break;
  406. case 1:
  407. if(creDir[number] == false)
  408. reverseCreature(number, curStackPos, true);
  409. break;
  410. case 2:
  411. if(creDir[number] == false)
  412. reverseCreature(number, curStackPos, true);
  413. break;
  414. case 3:
  415. if(creDir[number] == false)
  416. reverseCreature(number, curStackPos, true);
  417. break;
  418. case 4:
  419. if(creDir[number] == true)
  420. reverseCreature(number, curStackPos, true);
  421. break;
  422. case 5:
  423. if(creDir[number] == true)
  424. reverseCreature(number, curStackPos, true);
  425. break;
  426. }
  427. //moving instructions
  428. creAnims[number]->setType(0);
  429. for(int i=0; i<steps; ++i)
  430. {
  431. switch(CBattleHex::mutualPosition(curStackPos, destHex))
  432. {
  433. case 0:
  434. creAnims[number]->pos.x -= hexWbase/(2*steps);
  435. creAnims[number]->pos.y -= hexHbase/steps;
  436. break;
  437. case 1:
  438. creAnims[number]->pos.x += hexWbase/(2*steps);
  439. creAnims[number]->pos.y -= hexHbase/steps;
  440. break;
  441. case 2:
  442. creAnims[number]->pos.x += hexWbase/steps;
  443. break;
  444. case 3:
  445. creAnims[number]->pos.x += hexWbase/(2*steps);
  446. creAnims[number]->pos.y += hexHbase/steps;
  447. break;
  448. case 4:
  449. creAnims[number]->pos.x -= hexWbase/(2*steps);
  450. creAnims[number]->pos.y += hexHbase/steps;
  451. break;
  452. case 5:
  453. creAnims[number]->pos.x -= hexWbase/steps;
  454. break;
  455. }
  456. show();
  457. CSDL_Ext::update();
  458. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  459. }
  460. if( (LOCPLINT->cb->battleGetStackByID(number).owner == attackingHeroInstance->tempOwner ) != creDir[number])
  461. {
  462. reverseCreature(number, curStackPos, true);
  463. }
  464. }
  465. else //normal move instructions
  466. {
  467. switch(CBattleHex::mutualPosition(curStackPos, destHex)) //reverse unit if necessary
  468. {
  469. case 0:
  470. if(creDir[number] == true)
  471. reverseCreature(number, curStackPos);
  472. break;
  473. case 1:
  474. if(creDir[number] == false)
  475. reverseCreature(number, curStackPos);
  476. break;
  477. case 2:
  478. if(creDir[number] == false)
  479. reverseCreature(number, curStackPos);
  480. break;
  481. case 3:
  482. if(creDir[number] == false)
  483. reverseCreature(number, curStackPos);
  484. break;
  485. case 4:
  486. if(creDir[number] == true)
  487. reverseCreature(number, curStackPos);
  488. break;
  489. case 5:
  490. if(creDir[number] == true)
  491. reverseCreature(number, curStackPos);
  492. break;
  493. }
  494. //moving instructions
  495. creAnims[number]->setType(0);
  496. for(int i=0; i<steps; ++i)
  497. {
  498. switch(CBattleHex::mutualPosition(curStackPos, destHex))
  499. {
  500. case 0:
  501. creAnims[number]->pos.x -= hexWbase/(2*steps);
  502. creAnims[number]->pos.y -= hexHbase/steps;
  503. break;
  504. case 1:
  505. creAnims[number]->pos.x += hexWbase/(2*steps);
  506. creAnims[number]->pos.y -= hexHbase/steps;
  507. break;
  508. case 2:
  509. creAnims[number]->pos.x += hexWbase/steps;
  510. break;
  511. case 3:
  512. creAnims[number]->pos.x += hexWbase/(2*steps);
  513. creAnims[number]->pos.y += hexHbase/steps;
  514. break;
  515. case 4:
  516. creAnims[number]->pos.x -= hexWbase/(2*steps);
  517. creAnims[number]->pos.y += hexHbase/steps;
  518. break;
  519. case 5:
  520. creAnims[number]->pos.x -= hexWbase/steps;
  521. break;
  522. }
  523. show();
  524. CSDL_Ext::update();
  525. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  526. }
  527. }
  528. if(endMoving) //animation of ending move
  529. {
  530. for(int i=0; i<creAnims[number]->framesInGroup(21); ++i)
  531. {
  532. show();
  533. CSDL_Ext::update();
  534. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  535. }
  536. }
  537. creAnims[number]->setType(2); //resetting to default
  538. CStack curs = LOCPLINT->cb->battleGetStackByID(number);
  539. if(endMoving) //resetting to default
  540. {
  541. if(creDir[number] != (curs.owner == attackingHeroInstance->tempOwner))
  542. reverseCreature(number, destHex);
  543. //creDir[number] = (curs.owner == attackingHeroInstance->tempOwner);
  544. }
  545. std::pair <int, int> coords = CBattleHex::getXYUnitAnim(destHex, creDir[number], curs.creature);
  546. creAnims[number]->pos.x = coords.first;
  547. creAnims[number]->pos.y = coords.second;
  548. }
  549. void CBattleInterface::stackIsAttacked(int ID, int dmg, int killed, int IDby)
  550. {
  551. creAnims[ID]->setType(3); //getting hit
  552. for(int i=0; i<creAnims[ID]->framesInGroup(3); ++i)
  553. {
  554. show();
  555. CSDL_Ext::update();
  556. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  557. }
  558. creAnims[ID]->setType(2);
  559. printConsoleAttacked(ID, dmg, killed, IDby);
  560. }
  561. void CBattleInterface::stackAttacking(int ID, int dest)
  562. {
  563. CStack aStack = LOCPLINT->cb->battleGetStackByID(ID); //attacking stack
  564. if(aStack.creature->isDoubleWide())
  565. {
  566. switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction
  567. {
  568. case 0:
  569. //reverseCreature(ID, aStack.position, true);
  570. break;
  571. case 1:
  572. break;
  573. case 2:
  574. break;
  575. case 3:
  576. break;
  577. case 4:
  578. //reverseCreature(ID, aStack.position, true);
  579. break;
  580. case 5:
  581. reverseCreature(ID, aStack.position, true);
  582. break;
  583. }
  584. }
  585. else //else for if(aStack.creature->isDoubleWide())
  586. {
  587. switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction
  588. {
  589. case 0:
  590. reverseCreature(ID, aStack.position, true);
  591. break;
  592. case 1:
  593. break;
  594. case 2:
  595. break;
  596. case 3:
  597. break;
  598. case 4:
  599. reverseCreature(ID, aStack.position, true);
  600. break;
  601. case 5:
  602. reverseCreature(ID, aStack.position, true);
  603. break;
  604. }
  605. }
  606. attackingInfo = new CAttHelper;
  607. attackingInfo->dest = dest;
  608. attackingInfo->frame = 0;
  609. attackingInfo->ID = ID;
  610. attackingInfo->reversing = false;
  611. if(aStack.creature->isDoubleWide())
  612. {
  613. switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction
  614. {
  615. case 0:
  616. attackingInfo->maxframe = creAnims[ID]->framesInGroup(10);
  617. break;
  618. case 1:
  619. attackingInfo->maxframe = creAnims[ID]->framesInGroup(10);
  620. break;
  621. case 2:
  622. attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
  623. break;
  624. case 3:
  625. attackingInfo->maxframe = creAnims[ID]->framesInGroup(12);
  626. break;
  627. case 4:
  628. attackingInfo->maxframe = creAnims[ID]->framesInGroup(12);
  629. break;
  630. case 5:
  631. attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
  632. break;
  633. }
  634. }
  635. else //else for if(aStack.creature->isDoubleWide())
  636. {
  637. switch(CBattleHex::mutualPosition(aStack.position, dest)) //attack direction
  638. {
  639. case 0:
  640. attackingInfo->maxframe = creAnims[ID]->framesInGroup(10);
  641. break;
  642. case 1:
  643. attackingInfo->maxframe = creAnims[ID]->framesInGroup(10);
  644. break;
  645. case 2:
  646. attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
  647. break;
  648. case 3:
  649. attackingInfo->maxframe = creAnims[ID]->framesInGroup(12);
  650. break;
  651. case 4:
  652. attackingInfo->maxframe = creAnims[ID]->framesInGroup(12);
  653. break;
  654. case 5:
  655. attackingInfo->maxframe = creAnims[ID]->framesInGroup(11);
  656. break;
  657. }
  658. }
  659. }
  660. void CBattleInterface::newRound(int number)
  661. {
  662. console->addText(CGI->generaltexth->allTexts[412]);
  663. }
  664. void CBattleInterface::hexLclicked(int whichOne)
  665. {
  666. if((whichOne%17)!=0 && (whichOne%17)!=16) //if player is trying to attack enemey unit or move creature stack
  667. {
  668. int atCre = LOCPLINT->cb->battleGetStack(whichOne); //creature at destination tile; -1 if there is no one
  669. //LOCPLINT->cb->battleGetCreature();
  670. if(atCre==-1) //normal move action
  671. {
  672. BattleAction * ba = new BattleAction(); //to be deleted by engine
  673. ba->actionType = 2;
  674. ba->destinationTile = whichOne;
  675. ba->stackNumber = activeStack;
  676. givenCommand = ba;
  677. }
  678. else if(LOCPLINT->cb->battleGetStackByID(atCre).owner != attackingHeroInstance->tempOwner) //attacking
  679. {
  680. BattleAction * ba = new BattleAction(); //to be deleted by engine
  681. ba->actionType = 6;
  682. ba->destinationTile = whichOne;
  683. ba->stackNumber = activeStack;
  684. givenCommand = ba;
  685. }
  686. }
  687. }
  688. void CBattleInterface::showRange(SDL_Surface * to, int ID)
  689. {
  690. std::vector<int> shadedHexes = LOCPLINT->cb->battleGetAvailableHexes(ID);
  691. for(int i=0; i<shadedHexes.size(); ++i)
  692. {
  693. CSDL_Ext::blit8bppAlphaTo24bpp(CBattleInterface::cellShade, NULL, to, &bfield[shadedHexes[i]].pos);
  694. }
  695. }
  696. void CBattleInterface::attackingShowHelper()
  697. {
  698. if(attackingInfo && !attackingInfo->reversing)
  699. {
  700. if(attackingInfo->frame == 0)
  701. {
  702. CStack aStack = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
  703. if(aStack.creature->isDoubleWide())
  704. {
  705. switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
  706. {
  707. case 0:
  708. creAnims[attackingInfo->ID]->setType(10);
  709. break;
  710. case 1:
  711. creAnims[attackingInfo->ID]->setType(10);
  712. break;
  713. case 2:
  714. creAnims[attackingInfo->ID]->setType(11);
  715. break;
  716. case 3:
  717. creAnims[attackingInfo->ID]->setType(12);
  718. break;
  719. case 4:
  720. creAnims[attackingInfo->ID]->setType(12);
  721. break;
  722. case 5:
  723. creAnims[attackingInfo->ID]->setType(11);
  724. break;
  725. }
  726. }
  727. else //else for if(aStack.creature->isDoubleWide())
  728. {
  729. switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
  730. {
  731. case 0:
  732. creAnims[attackingInfo->ID]->setType(10);
  733. break;
  734. case 1:
  735. creAnims[attackingInfo->ID]->setType(10);
  736. break;
  737. case 2:
  738. creAnims[attackingInfo->ID]->setType(11);
  739. break;
  740. case 3:
  741. creAnims[attackingInfo->ID]->setType(12);
  742. break;
  743. case 4:
  744. creAnims[attackingInfo->ID]->setType(12);
  745. break;
  746. case 5:
  747. creAnims[attackingInfo->ID]->setType(11);
  748. break;
  749. }
  750. }
  751. }
  752. else if(attackingInfo->frame == (attackingInfo->maxframe - 1))
  753. {
  754. attackingInfo->reversing = true;
  755. CStack aStack = LOCPLINT->cb->battleGetStackByID(attackingInfo->ID); //attacking stack
  756. if(aStack.creature->isDoubleWide())
  757. {
  758. switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
  759. {
  760. case 0:
  761. //reverseCreature(ID, aStack.position, true);
  762. break;
  763. case 1:
  764. break;
  765. case 2:
  766. break;
  767. case 3:
  768. break;
  769. case 4:
  770. //reverseCreature(ID, aStack.position, true);
  771. break;
  772. case 5:
  773. reverseCreature(attackingInfo->ID, aStack.position, true);
  774. break;
  775. }
  776. }
  777. else //else for if(aStack.creature->isDoubleWide())
  778. {
  779. switch(CBattleHex::mutualPosition(aStack.position, attackingInfo->dest)) //attack direction
  780. {
  781. case 0:
  782. reverseCreature(attackingInfo->ID, aStack.position, true);
  783. break;
  784. case 1:
  785. break;
  786. case 2:
  787. break;
  788. case 3:
  789. break;
  790. case 4:
  791. reverseCreature(attackingInfo->ID, aStack.position, true);
  792. break;
  793. case 5:
  794. reverseCreature(attackingInfo->ID, aStack.position, true);
  795. break;
  796. }
  797. }
  798. attackingInfo->reversing = false;
  799. creAnims[attackingInfo->ID]->setType(2);
  800. delete attackingInfo;
  801. attackingInfo = NULL;
  802. }
  803. if(attackingInfo)
  804. {
  805. attackingInfo->frame++;
  806. }
  807. }
  808. }
  809. void CBattleInterface::printConsoleAttacked(int ID, int dmg, int killed, int IDby)
  810. {
  811. char tabh[200];
  812. CStack attacker = LOCPLINT->cb->battleGetStackByID(IDby);
  813. CStack defender = LOCPLINT->cb->battleGetStackByID(ID);
  814. int end = sprintf(tabh, CGI->generaltexth->allTexts[attacker.amount > 1 ? 377 : 376].c_str(),
  815. (attacker.amount > 1 ? attacker.creature->namePl.c_str() : attacker.creature->nameSing.c_str()),
  816. dmg);
  817. if(killed > 0)
  818. {
  819. if(killed > 1)
  820. {
  821. sprintf(tabh + end, CGI->generaltexth->allTexts[379].c_str(), killed, defender.creature->namePl.c_str());
  822. }
  823. else //killed == 1
  824. {
  825. sprintf(tabh + end, CGI->generaltexth->allTexts[378].c_str(), defender.creature->nameSing.c_str());
  826. }
  827. }
  828. console->addText(std::string(tabh));
  829. }
  830. void CBattleHero::show(SDL_Surface *to)
  831. {
  832. //animation of flag
  833. if(flip)
  834. {
  835. CSDL_Ext::blit8bppAlphaTo24bpp(flag->ourImages[flagAnim].bitmap, NULL, screen, &genRect(flag->ourImages[flagAnim].bitmap->h, flag->ourImages[flagAnim].bitmap->w, 752, 39));
  836. }
  837. else
  838. {
  839. CSDL_Ext::blit8bppAlphaTo24bpp(flag->ourImages[flagAnim].bitmap, NULL, screen, &genRect(flag->ourImages[flagAnim].bitmap->h, flag->ourImages[flagAnim].bitmap->w, 31, 39));
  840. }
  841. {
  842. ++flagAnim;
  843. flagAnim %= flag->ourImages.size();
  844. }
  845. //animation of hero
  846. int tick=-1;
  847. for(int i=0; i<dh->ourImages.size(); ++i)
  848. {
  849. if(dh->ourImages[i].groupNumber==phase)
  850. ++tick;
  851. if(tick==image)
  852. {
  853. SDL_Rect posb = pos;
  854. CSDL_Ext::blit8bppAlphaTo24bpp(dh->ourImages[i].bitmap, NULL, to, &posb);
  855. ++image;
  856. if(dh->ourImages[i+1].groupNumber!=phase) //back to appropriate frame
  857. {
  858. image = 0;
  859. }
  860. break;
  861. }
  862. }
  863. }
  864. CBattleHero::CBattleHero(std::string defName, int phaseG, int imageG, bool flipG, unsigned char player): phase(phaseG), image(imageG), flip(flipG), flagAnim(0)
  865. {
  866. dh = CDefHandler::giveDef( defName );
  867. for(int i=0; i<dh->ourImages.size(); ++i) //transforming images
  868. {
  869. if(flip)
  870. {
  871. SDL_Surface * hlp = CSDL_Ext::rotate01(dh->ourImages[i].bitmap);
  872. SDL_FreeSurface(dh->ourImages[i].bitmap);
  873. dh->ourImages[i].bitmap = hlp;
  874. }
  875. dh->ourImages[i].bitmap = CSDL_Ext::alphaTransform(dh->ourImages[i].bitmap);
  876. }
  877. dh->alphaTransformed = true;
  878. if(flip)
  879. flag = CDefHandler::giveDef("CMFLAGR.DEF");
  880. else
  881. flag = CDefHandler::giveDef("CMFLAGL.DEF");
  882. //coloring flag and adding transparency
  883. for(int i=0; i<flag->ourImages.size(); ++i)
  884. {
  885. flag->ourImages[i].bitmap = CSDL_Ext::alphaTransform(flag->ourImages[i].bitmap);
  886. CSDL_Ext::blueToPlayersAdv(flag->ourImages[i].bitmap, player);
  887. }
  888. }
  889. CBattleHero::~CBattleHero()
  890. {
  891. delete dh;
  892. delete flag;
  893. }
  894. std::pair<int, int> CBattleHex::getXYUnitAnim(int hexNum, bool attacker, CCreature * creature)
  895. {
  896. std::pair<int, int> ret = std::make_pair(-500, -500); //returned value
  897. ret.second = -139 + 42 * (hexNum/17); //counting y
  898. //counting x
  899. if(attacker)
  900. {
  901. ret.first = -160 + 22 * ( ((hexNum/17) + 1)%2 ) + 44 * (hexNum % 17);
  902. }
  903. else
  904. {
  905. ret.first = -219 + 22 * ( ((hexNum/17) + 1)%2 ) + 44 * (hexNum % 17);
  906. }
  907. //shifting position for double - hex creatures
  908. if(creature->isDoubleWide())
  909. {
  910. if(attacker)
  911. {
  912. ret.first -= 42;
  913. }
  914. else
  915. {
  916. ret.first += 42;
  917. }
  918. }
  919. //returning
  920. return ret;
  921. }
  922. signed char CBattleHex::mutualPosition(int hex1, int hex2)
  923. {
  924. if(hex2 == hex1 - ( (hex1/17)%2 ? 18 : 17 )) //top left
  925. return 0;
  926. if(hex2 == hex1 - ( (hex1/17)%2 ? 17 : 16 )) //top right
  927. return 1;
  928. if(hex2 == hex1 - 1 && hex1%17 != 0) //left
  929. return 5;
  930. if(hex2 == hex1 + 1 && hex1%17 != 16) //right
  931. return 2;
  932. if(hex2 == hex1 + ( (hex1/17)%2 ? 16 : 17 )) //bottom left
  933. return 4;
  934. if(hex2 == hex1 + ( (hex1/17)%2 ? 17 : 18 )) //bottom right
  935. return 3;
  936. return -1;
  937. }
  938. void CBattleHex::activate()
  939. {
  940. Hoverable::activate();
  941. MotionInterested::activate();
  942. ClickableL::activate();
  943. ClickableR::activate();
  944. }
  945. void CBattleHex::deactivate()
  946. {
  947. Hoverable::deactivate();
  948. MotionInterested::deactivate();
  949. ClickableL::deactivate();
  950. ClickableR::deactivate();
  951. }
  952. void CBattleHex::hover(bool on)
  953. {
  954. hovered = on;
  955. Hoverable::hover(on);
  956. if(!on && setAlterText)
  957. {
  958. myInterface->console->alterTxt = std::string();
  959. setAlterText = false;
  960. }
  961. }
  962. CBattleHex::CBattleHex() : myNumber(-1), accesible(true), hovered(false), strictHovered(false), myInterface(NULL), setAlterText(false)
  963. {
  964. }
  965. void CBattleHex::mouseMoved(SDL_MouseMotionEvent &sEvent)
  966. {
  967. if(CBattleInterface::cellShade)
  968. {
  969. if(CSDL_Ext::SDL_GetPixel(CBattleInterface::cellShade, sEvent.x-pos.x, sEvent.y-pos.y) == 0) //hovered pixel is outside hex
  970. {
  971. strictHovered = false;
  972. }
  973. else //hovered pixel is inside hex
  974. {
  975. strictHovered = true;
  976. }
  977. }
  978. if(hovered && strictHovered) //print attacked creature to console
  979. {
  980. if(myInterface->console->alterTxt.size() == 0 && LOCPLINT->cb->battleGetStack(myNumber) != -1 &&
  981. LOCPLINT->cb->battleGetStackByPos(myNumber).owner != LOCPLINT->playerID &&
  982. LOCPLINT->cb->battleGetStackByPos(myNumber).alive)
  983. {
  984. char tabh[160];
  985. CStack attackedStack = LOCPLINT->cb->battleGetStackByPos(myNumber);
  986. std::string attackedName = attackedStack.amount == 1 ? attackedStack.creature->nameSing : attackedStack.creature->namePl;
  987. sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str());
  988. myInterface->console->alterTxt = std::string(tabh);
  989. setAlterText = true;
  990. }
  991. }
  992. else if(setAlterText)
  993. {
  994. myInterface->console->alterTxt = std::string();
  995. setAlterText = false;
  996. }
  997. }
  998. void CBattleHex::clickLeft(boost::logic::tribool down)
  999. {
  1000. if(!down && hovered && strictHovered) //we've been really clicked!
  1001. {
  1002. myInterface->hexLclicked(myNumber);
  1003. }
  1004. }
  1005. void CBattleHex::clickRight(boost::logic::tribool down)
  1006. {
  1007. int stID = LOCPLINT->cb->battleGetStack(myNumber); //id of stack being on this tile
  1008. if(hovered && strictHovered && stID!=-1)
  1009. {
  1010. CStack myst = LOCPLINT->cb->battleGetStackByID(stID); //stack info
  1011. StackState *pom = NULL;
  1012. if(down)
  1013. {
  1014. pom = new StackState();
  1015. const CGHeroInstance *h = myst.owner == myInterface->attackingHeroInstance->tempOwner ? myInterface->attackingHeroInstance : myInterface->defendingHeroInstance;
  1016. if(h)
  1017. {
  1018. pom->attackBonus = h->primSkills[0];
  1019. pom->defenseBonus = h->primSkills[1];
  1020. pom->luck = h->getCurrentLuck();
  1021. pom->morale = h->getCurrentMorale();
  1022. }
  1023. (new CCreInfoWindow(myst.creature->idNumber,0,pom,boost::function<void()>(),boost::function<void()>()))
  1024. ->activate();
  1025. }
  1026. delete pom;
  1027. }
  1028. }
  1029. CBattleConsole::CBattleConsole() : lastShown(-1), alterTxt("")
  1030. {
  1031. }
  1032. CBattleConsole::~CBattleConsole()
  1033. {
  1034. texts.clear();
  1035. }
  1036. void CBattleConsole::show(SDL_Surface * to)
  1037. {
  1038. if(alterTxt.size())
  1039. {
  1040. CSDL_Ext::printAtMiddleWB(alterTxt, pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to);
  1041. }
  1042. else if(texts.size())
  1043. {
  1044. if(texts.size()==1)
  1045. {
  1046. CSDL_Ext::printAtMiddleWB(texts[0], pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to);
  1047. }
  1048. else
  1049. {
  1050. CSDL_Ext::printAtMiddleWB(texts[lastShown-1], pos.x + pos.w/2, pos.y + 10, GEOR13, 80, zwykly, to);
  1051. CSDL_Ext::printAtMiddleWB(texts[lastShown], pos.x + pos.w/2, pos.y + 26, GEOR13, 80, zwykly, to);
  1052. }
  1053. }
  1054. }
  1055. bool CBattleConsole::addText(std::string text)
  1056. {
  1057. if(text.size()>70)
  1058. return false; //text too long!
  1059. int firstInToken = 0;
  1060. for(int i=0; i<text.size(); ++i) //tokenize
  1061. {
  1062. if(text[i] == 10)
  1063. {
  1064. texts.push_back( text.substr(firstInToken, i-firstInToken) );
  1065. firstInToken = i+1;
  1066. }
  1067. }
  1068. texts.push_back( text.substr(firstInToken, text.size()) );
  1069. lastShown = texts.size()-1;
  1070. return true;
  1071. }
  1072. void CBattleConsole::eraseText(unsigned int pos)
  1073. {
  1074. if(pos < texts.size())
  1075. {
  1076. texts.erase(texts.begin() + pos);
  1077. if(lastShown == texts.size())
  1078. --lastShown;
  1079. }
  1080. }
  1081. void CBattleConsole::changeTextAt(std::string text, unsigned int pos)
  1082. {
  1083. if(pos >= texts.size()) //no such pos
  1084. return;
  1085. texts[pos] = text;
  1086. }
  1087. void CBattleConsole::scrollUp(unsigned int by)
  1088. {
  1089. if(lastShown > by)
  1090. lastShown -= by;
  1091. }
  1092. void CBattleConsole::scrollDown(unsigned int by)
  1093. {
  1094. if(lastShown + by < texts.size())
  1095. lastShown += by;
  1096. }