CPlayerInterface.cpp 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117
  1. #include "stdafx.h"
  2. #include "CPlayerInterface.h"
  3. #include "CAdvMapInterface.h"
  4. #include "CMessage.h"
  5. #include "mapHandler.h"
  6. #include "SDL_Extensions.h"
  7. #include "SDL_framerate.h"
  8. #include "CScreenHandler.h"
  9. #include "CCursorHandler.h"
  10. #include "CCallback.h"
  11. #include "SDL_Extensions.h"
  12. #include "hch/CLodHandler.h"
  13. #include "CPathfinder.h"
  14. #include <sstream>
  15. #include "hch/CHeroHandler.h"
  16. #include "hch/CTownHandler.h"
  17. #include "SDL_framerate.h"
  18. #include "hch/CGeneralTextHandler.h"
  19. #include "CCastleInterface.h"
  20. #include "CHeroWindow.h"
  21. #include "timeHandler.h"
  22. #include <boost/algorithm/string.hpp>
  23. #include <boost/algorithm/string/replace.hpp>
  24. #include "hch\CPreGameTextHandler.h"
  25. using namespace CSDL_Ext;
  26. extern TTF_Font * GEOR16;
  27. class OCM_HLP_CGIN
  28. {
  29. public:
  30. bool operator ()(const std::pair<CGObjectInstance*,SDL_Rect> & a, const std::pair<CGObjectInstance*,SDL_Rect> & b) const
  31. {
  32. return (*a.first)<(*b.first);
  33. }
  34. } ocmptwo_cgin ;
  35. void CGarrisonSlot::hover (bool on)
  36. {
  37. Hoverable::hover(on);
  38. if(on)
  39. {
  40. std::string temp;
  41. if(creature)
  42. {
  43. if(owner->highlighted)
  44. {
  45. if(owner->highlighted == this)
  46. {
  47. temp = CGI->townh->tcommands[4];
  48. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  49. }
  50. else if (owner->highlighted->creature == creature)
  51. {
  52. temp = CGI->townh->tcommands[2];
  53. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  54. }
  55. else
  56. {
  57. temp = CGI->townh->tcommands[7];
  58. boost::algorithm::replace_first(temp,"%s",owner->highlighted->creature->nameSing);
  59. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  60. }
  61. }
  62. else
  63. {
  64. if(upg)
  65. {
  66. temp = CGI->townh->tcommands[32];
  67. }
  68. else
  69. {
  70. temp = CGI->townh->tcommands[12];
  71. }
  72. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  73. };
  74. }
  75. else
  76. {
  77. if(owner->highlighted)
  78. {
  79. temp = CGI->townh->tcommands[6];
  80. boost::algorithm::replace_first(temp,"%s",owner->highlighted->creature->nameSing);
  81. }
  82. else
  83. {
  84. temp = CGI->townh->tcommands[11];
  85. }
  86. }
  87. LOCPLINT->statusbar->print(temp);
  88. }
  89. else
  90. {
  91. LOCPLINT->statusbar->clear();
  92. }
  93. }
  94. void CGarrisonSlot::clickRight (tribool down)
  95. {
  96. }
  97. void CGarrisonSlot::clickLeft(tribool down)
  98. {
  99. if(owner->ignoreEvent)
  100. {
  101. owner->ignoreEvent = false;
  102. return;
  103. }
  104. if(down)
  105. {
  106. if(owner->highlighted)
  107. {
  108. LOCPLINT->cb->swapCreatures(
  109. (!upg)?(owner->oup):(owner->odown),
  110. (!owner->highlighted->upg)?(owner->oup):(owner->odown),
  111. ID,owner->highlighted->ID);
  112. owner->highlighted = NULL;
  113. owner->recreateSlots();
  114. }
  115. else
  116. {
  117. if(creature)
  118. owner->highlighted = this;
  119. }
  120. }
  121. }
  122. void CGarrisonSlot::activate()
  123. {
  124. ClickableL::activate();
  125. ClickableR::activate();
  126. Hoverable::activate();
  127. }
  128. void CGarrisonSlot::deactivate()
  129. {
  130. ClickableL::deactivate();
  131. ClickableR::deactivate();
  132. Hoverable::deactivate();
  133. }
  134. CGarrisonSlot::CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg, const CCreature * Creature, int Count)
  135. {
  136. upg = Upg;
  137. count = Count;
  138. ID = IID;
  139. creature = Creature;
  140. pos.x = x;
  141. pos.y = y;
  142. pos.w = 58;
  143. pos.h = 64;
  144. owner = Owner;
  145. }
  146. void CGarrisonSlot::show()
  147. {
  148. if(creature)
  149. {
  150. char* buf = new char[15];
  151. itoa(count,buf,10);
  152. blitAt(CGI->creh->bigImgs[creature->idNumber],pos);
  153. printTo(buf,pos.x+56,pos.y+62,GEOR16,zwykly);
  154. if(owner->highlighted==this)
  155. blitAt(CGI->creh->bigImgs[-1],pos);
  156. if(owner->update)
  157. updateRect(&pos,ekran);
  158. delete [] buf;
  159. }
  160. else
  161. {
  162. SDL_Rect jakis1 = genRect(pos.h,pos.w,owner->offx+ID*(pos.w+owner->interx),owner->offy+upg*(pos.h+owner->intery)), jakis2 = pos;
  163. SDL_BlitSurface(owner->sur,&jakis1,ekran,&jakis2);
  164. if(owner->update)
  165. SDL_UpdateRect(ekran,pos.x,pos.y,pos.w,pos.h);
  166. }
  167. }
  168. CGarrisonInt::~CGarrisonInt()
  169. {
  170. if(sup)
  171. {
  172. for(int i=0;i<sup->size();i++)
  173. delete (*sup)[i];
  174. delete sup;
  175. }
  176. if(sdown)
  177. {
  178. for(int i=0;i<sdown->size();i++)
  179. delete (*sdown)[i];
  180. delete sdown;
  181. }
  182. }
  183. void CGarrisonInt::show()
  184. {
  185. if(sup)
  186. {
  187. for(int i = 0; i<sup->size(); i++)
  188. if((*sup)[i])
  189. (*sup)[i]->show();
  190. }
  191. if(sdown)
  192. {
  193. for(int i = 0; i<sdown->size(); i++)
  194. if((*sdown)[i])
  195. (*sdown)[i]->show();
  196. }
  197. }
  198. void CGarrisonInt::deactiveteSlots()
  199. {
  200. if(sup)
  201. {
  202. for(int i = 0; i<sup->size(); i++)
  203. {
  204. if((*sup)[i])
  205. {
  206. (*sup)[i]->deactivate();
  207. }
  208. }
  209. }
  210. if(sdown)
  211. {
  212. for(int i = 0; i<sdown->size(); i++)
  213. {
  214. if((*sdown)[i])
  215. {
  216. (*sdown)[i]->deactivate();
  217. }
  218. }
  219. }
  220. }
  221. void CGarrisonInt::activeteSlots()
  222. {
  223. if(sup)
  224. {
  225. for(int i = 0; i<sup->size(); i++)
  226. {
  227. if((*sup)[i])
  228. {
  229. (*sup)[i]->activate();
  230. }
  231. }
  232. }
  233. if(sdown)
  234. {
  235. for(int i = 0; i<sdown->size(); i++)
  236. {
  237. if((*sdown)[i])
  238. {
  239. (*sdown)[i]->activate();
  240. }
  241. }
  242. }
  243. }
  244. void CGarrisonInt::createSlots()
  245. {
  246. if(set1)
  247. {
  248. sup = new std::vector<CGarrisonSlot*>(7,(CGarrisonSlot *)(NULL));
  249. for
  250. (std::map<int,std::pair<CCreature*,int> >::const_iterator i=set1->slots.begin();
  251. i!=set1->slots.end(); i++)
  252. {
  253. (*sup)[i->first] =
  254. new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y,i->first, 0, i->second.first,i->second.second);
  255. }
  256. for(int i=0; i<sup->size(); i++)
  257. if((*sup)[i] == NULL)
  258. (*sup)[i] = new CGarrisonSlot(this, pos.x + (i*(58+interx)), pos.y,i,0,NULL, 0);
  259. }
  260. if(set2)
  261. {
  262. sdown = new std::vector<CGarrisonSlot*>(7,(CGarrisonSlot *)(NULL));
  263. for
  264. (std::map<int,std::pair<CCreature*,int> >::const_iterator i=set2->slots.begin();
  265. i!=set2->slots.end(); i++)
  266. {
  267. (*sdown)[i->first] =
  268. new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y + 64 + intery,i->first,1, i->second.first,i->second.second);
  269. }
  270. for(int i=0; i<sup->size(); i++)
  271. if((*sdown)[i] == NULL)
  272. (*sdown)[i] = new CGarrisonSlot(this, pos.x + (i*(58+interx)), pos.y + 64 + intery,i,1, NULL, 0);
  273. }
  274. }
  275. void CGarrisonInt::deleteSlots()
  276. {
  277. if(sup)
  278. {
  279. for(int i = 0; i<sup->size(); i++)
  280. {
  281. if((*sup)[i])
  282. {
  283. delete (*sup)[i];
  284. }
  285. }
  286. }
  287. if(sdown)
  288. {
  289. for(int i = 0; i<sdown->size(); i++)
  290. {
  291. if((*sdown)[i])
  292. {
  293. delete (*sdown)[i];
  294. }
  295. }
  296. }
  297. }
  298. void CGarrisonInt::recreateSlots()
  299. {
  300. deactiveteSlots();
  301. deleteSlots();
  302. createSlots();
  303. ignoreEvent = true;
  304. activeteSlots();
  305. show();
  306. }
  307. CGarrisonInt::CGarrisonInt(int x, int y, int inx, int iny, SDL_Surface *pomsur, int OX, int OY, const CGObjectInstance *s1, const CGObjectInstance *s2)
  308. :interx(inx),intery(iny),sur(pomsur),highlighted(NULL),sup(NULL),sdown(NULL),oup(s1),odown(s2),
  309. offx(OX),offy(OY)
  310. {
  311. set1 = LOCPLINT->cb->getGarrison(s1);
  312. set2 = LOCPLINT->cb->getGarrison(s2);
  313. ignoreEvent = false;
  314. update = true;
  315. pos.x=(x);
  316. pos.y=(y);
  317. pos.w=(58);
  318. pos.h=(64);
  319. createSlots();
  320. }
  321. void CGarrisonInt::activate()
  322. {
  323. if(sup)
  324. {
  325. for(int i = 0; i<sup->size(); i++)
  326. if((*sup)[i])
  327. (*sup)[i]->activate();
  328. }
  329. if(sdown)
  330. {
  331. for(int i = 0; i<sdown->size(); i++)
  332. if((*sdown)[i])
  333. (*sdown)[i]->activate();
  334. }
  335. }
  336. void CGarrisonInt::deactivate()
  337. {
  338. deactiveteSlots();
  339. }
  340. CInfoWindow::CInfoWindow()
  341. :okb(NMessage::ok,NULL,&CInfoWindow::okClicked)
  342. {
  343. okb.ourObj = this;
  344. okb.delg = this;
  345. okb.notFreeButton=true;
  346. }
  347. void CInfoWindow::okClicked(tribool down)
  348. {
  349. if (!down)
  350. close();
  351. }
  352. void CInfoWindow::close()
  353. {
  354. for (int i=0;i<components.size();i++)
  355. {
  356. components[i]->deactivate();
  357. delete components[i];
  358. }
  359. components.clear();
  360. okb.deactivate();
  361. SDL_FreeSurface(bitmap);
  362. bitmap = NULL;
  363. LOCPLINT->removeObjToBlit(this);
  364. LOCPLINT->curint->activate();
  365. delete this;
  366. }
  367. CInfoWindow::~CInfoWindow()
  368. {
  369. }
  370. SComponent::SComponent(Etype Type, int Subtype, int Val)
  371. {
  372. std::ostringstream oss;
  373. switch (Type)
  374. {
  375. case primskill:
  376. description = CGI->generaltexth->arraytxt[2+Subtype];
  377. oss << ((Val>0)?("+"):("-")) << Val << " " << CGI->heroh->pskillsn[Subtype];
  378. subtitle = oss.str();
  379. break;
  380. case resource:
  381. description = CGI->generaltexth->allTexts[242];
  382. oss << Val;
  383. subtitle = oss.str();
  384. break;
  385. case experience:
  386. description = CGI->generaltexth->allTexts[241];
  387. oss << Val ;
  388. subtitle = oss.str();
  389. break;
  390. }
  391. type = Type;
  392. subtype = Subtype;
  393. val = Val;
  394. SDL_Surface * temp = getImg();
  395. pos.w = temp->w;
  396. pos.h = temp->h;
  397. }
  398. SDL_Surface * SComponent::getImg()
  399. {
  400. switch (type)
  401. {
  402. case primskill:
  403. return CGI->heroh->pskillsb->ourImages[subtype].bitmap;
  404. break;
  405. case secskill:
  406. return CGI->abilh->abils82->ourImages[subtype*3 + 3 + val].bitmap;
  407. break;
  408. case resource:
  409. return CGI->heroh->resources->ourImages[subtype].bitmap;
  410. break;
  411. case experience:
  412. return CGI->heroh->pskillsb->ourImages[4].bitmap;
  413. break;
  414. }
  415. return NULL;
  416. }
  417. void SComponent::clickRight (tribool down)
  418. {
  419. LOCPLINT->adventureInt->handleRightClick(description,down,this);
  420. }
  421. void SComponent::activate()
  422. {
  423. ClickableR::activate();
  424. }
  425. void SComponent::deactivate()
  426. {
  427. ClickableR::deactivate();
  428. }
  429. void CSelectableComponent::clickLeft(tribool down)
  430. {
  431. if (down)
  432. {
  433. select(true);
  434. owner->selectionChange(this);
  435. }
  436. }
  437. CSelectableComponent::CSelectableComponent(Etype Type, int Sub, int Val, CSelWindow * Owner, SDL_Surface * Border)
  438. :SComponent(Type,Sub,Val),owner(Owner)
  439. {
  440. SDL_Surface * symb = SComponent::getImg();
  441. myBitmap = CSDL_Ext::newSurface(symb->w+2,symb->h+2,ekran);
  442. SDL_SetColorKey(myBitmap,SDL_SRCCOLORKEY,SDL_MapRGB(myBitmap->format,0,255,255));
  443. blitAt(symb,1,1,myBitmap);
  444. if (Border) //use custom border
  445. {
  446. border = Border;
  447. customB = true;
  448. }
  449. else //we need to draw border
  450. {
  451. customB = false;
  452. border = CSDL_Ext::newSurface(symb->w+2,symb->h+2,ekran);
  453. SDL_FillRect(border,NULL,0x00FFFF);
  454. for (int i=0;i<border->w;i++)
  455. {
  456. SDL_PutPixel(border,i,0,239,215,123);
  457. SDL_PutPixel(border,i,(border->h)-1,239,215,123);
  458. }
  459. for (int i=0;i<border->h;i++)
  460. {
  461. SDL_PutPixel(border,0,i,239,215,123);
  462. SDL_PutPixel(border,(border->w)-1,i,239,215,123);
  463. }
  464. SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255));
  465. }
  466. selected = false;
  467. }
  468. CSelectableComponent::~CSelectableComponent()
  469. {
  470. SDL_FreeSurface(myBitmap);
  471. if (!customB)
  472. SDL_FreeSurface(border);
  473. }
  474. void CSelectableComponent::activate()
  475. {
  476. SComponent::activate();
  477. ClickableL::activate();
  478. }
  479. void CSelectableComponent::deactivate()
  480. {
  481. SComponent::deactivate();
  482. ClickableL::deactivate();
  483. }
  484. SDL_Surface * CSelectableComponent::getImg()
  485. {
  486. return myBitmap;
  487. }
  488. void CSelectableComponent::select(bool on)
  489. {
  490. if(on != selected)
  491. {
  492. SDL_FillRect(myBitmap,NULL,0x000000);
  493. blitAt(SComponent::getImg(),1,1,myBitmap);
  494. if (on)
  495. {
  496. blitAt(border,0,0,myBitmap);
  497. }
  498. selected = on;
  499. return;
  500. }
  501. else
  502. {
  503. return;
  504. }
  505. }
  506. void CSimpleWindow::show(SDL_Surface * to)
  507. {
  508. if(!to)
  509. to=ekran;
  510. blitAt(bitmap,pos.x,pos.y,to);
  511. }
  512. CSimpleWindow::~CSimpleWindow()
  513. {
  514. if (bitmap)
  515. {
  516. SDL_FreeSurface(bitmap);
  517. bitmap=NULL;
  518. }
  519. }
  520. void CSelWindow::selectionChange(CSelectableComponent * to)
  521. {
  522. blitAt(to->getImg(),to->pos.x-pos.x,to->pos.y-pos.y,bitmap);
  523. for (int i=0;i<components.size();i++)
  524. {
  525. if(components[i]==to)
  526. {
  527. if (to->selected)
  528. continue;
  529. else
  530. to->select(true);
  531. }
  532. CSelectableComponent * pom = dynamic_cast<CSelectableComponent*>(components[i]);
  533. if (!pom)
  534. continue;
  535. pom->select(false);
  536. blitAt(pom->getImg(),pom->pos.x-pos.x,pom->pos.y-pos.y,bitmap);
  537. }
  538. }
  539. void CSelWindow::okClicked(tribool down)
  540. {
  541. if(!down)
  542. close();
  543. }
  544. void CSelWindow::close()
  545. {
  546. int ret = -1;
  547. for (int i=0;i<components.size();i++)
  548. {
  549. if(dynamic_cast<CSelectableComponent*>(components[i])->selected)
  550. {
  551. ret = i;
  552. }
  553. components[i]->deactivate();
  554. }
  555. components.clear();
  556. okb.deactivate();
  557. SDL_FreeSurface(bitmap);
  558. bitmap = NULL;
  559. LOCPLINT->removeObjToBlit(this);
  560. LOCPLINT->curint->activate();
  561. LOCPLINT->cb->selectionMade(ret,ID);
  562. delete this;
  563. //call owner with selection result
  564. }
  565. template <typename T>CSCButton<T>::CSCButton(CDefHandler * img, CIntObject * obj, void(T::*poin)(tribool), T* Delg)
  566. {
  567. ourObj = obj;
  568. delg = Delg;
  569. func = poin;
  570. imgs.resize(1);
  571. for (int i =0; i<img->ourImages.size();i++)
  572. {
  573. imgs[0].push_back(img->ourImages[i].bitmap);
  574. }
  575. pos.w = imgs[0][0]->w;
  576. pos.h = imgs[0][0]->h;
  577. state = 0;
  578. }
  579. template <typename T> void CSCButton<T>::clickLeft (tribool down)
  580. {
  581. if (down)
  582. {
  583. state=1;
  584. }
  585. else
  586. {
  587. state=0;
  588. }
  589. pressedL=state;
  590. show();
  591. if (delg)
  592. (delg->*func)(down);
  593. }
  594. template <typename T> void CSCButton<typename T>::activate()
  595. {
  596. ClickableL::activate();
  597. }
  598. template <typename T> void CSCButton<typename T>::deactivate()
  599. {
  600. ClickableL::deactivate();
  601. }
  602. template <typename T> void CSCButton<typename T>::show(SDL_Surface * to)
  603. {
  604. if (delg) //we blit on our owner's bitmap
  605. {
  606. blitAt(imgs[curimg][state],posr.x,posr.y,delg->bitmap);
  607. //updateRect(&genRect(pos.h,pos.w,posr.x,posr.y),delg->bitmap);
  608. }
  609. else
  610. {
  611. CButtonBase::show(to);
  612. }
  613. }
  614. CButtonBase::CButtonBase()
  615. {
  616. bitmapOffset = 0;
  617. curimg=0;
  618. type=-1;
  619. abs=false;
  620. active=false;
  621. notFreeButton = false;
  622. ourObj=NULL;
  623. state=0;
  624. }
  625. CButtonBase::~CButtonBase()
  626. {
  627. if(notFreeButton)
  628. return;
  629. for(int i =0; i<imgs.size();i++)
  630. for(int j=0;j<imgs[i].size();j++)
  631. SDL_FreeSurface(imgs[i][j]);
  632. }
  633. void CButtonBase::show(SDL_Surface * to)
  634. {
  635. if(!to)
  636. to=ekran;
  637. if (abs)
  638. {
  639. blitAt(imgs[curimg][state+bitmapOffset],pos.x,pos.y,to);
  640. //updateRect(&pos,to);
  641. }
  642. else
  643. {
  644. blitAt(imgs[curimg][state+bitmapOffset],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y,to);
  645. //updateRect(&genRect(pos.h,pos.w,pos.x+ourObj->pos.x,pos.y+ourObj->pos.y),to);
  646. }
  647. }
  648. ClickableL::ClickableL()
  649. {
  650. pressedL=false;
  651. }
  652. void ClickableL::clickLeft(tribool down)
  653. {
  654. if (down)
  655. pressedL=true;
  656. else
  657. pressedL=false;
  658. }
  659. void ClickableL::activate()
  660. {
  661. LOCPLINT->lclickable.push_back(this);
  662. }
  663. void ClickableL::deactivate()
  664. {
  665. LOCPLINT->lclickable.erase
  666. (std::find(LOCPLINT->lclickable.begin(),LOCPLINT->lclickable.end(),this));
  667. }
  668. ClickableR::ClickableR()
  669. {
  670. pressedR=false;
  671. }
  672. void ClickableR::activate()
  673. {
  674. LOCPLINT->rclickable.push_back(this);
  675. }
  676. void ClickableR::deactivate()
  677. {
  678. LOCPLINT->rclickable.erase(std::find(LOCPLINT->rclickable.begin(),LOCPLINT->rclickable.end(),this));
  679. }
  680. void Hoverable::activate()
  681. {
  682. LOCPLINT->hoverable.push_back(this);
  683. }
  684. void Hoverable::deactivate()
  685. {
  686. LOCPLINT->hoverable.erase(std::find(LOCPLINT->hoverable.begin(),LOCPLINT->hoverable.end(),this));
  687. }
  688. void Hoverable::hover(bool on)
  689. {
  690. hovered=on;
  691. }
  692. void KeyInterested::activate()
  693. {
  694. LOCPLINT->keyinterested.push_back(this);
  695. }
  696. void KeyInterested::deactivate()
  697. {
  698. LOCPLINT->
  699. keyinterested.erase(std::find(LOCPLINT->keyinterested.begin(),LOCPLINT->keyinterested.end(),this));
  700. }
  701. void MotionInterested::activate()
  702. {
  703. LOCPLINT->motioninterested.push_back(this);
  704. }
  705. void MotionInterested::deactivate()
  706. {
  707. LOCPLINT->
  708. motioninterested.erase(std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this));
  709. }
  710. void TimeInterested::activate()
  711. {
  712. LOCPLINT->timeinterested.push_back(this);
  713. }
  714. void TimeInterested::deactivate()
  715. {
  716. LOCPLINT->
  717. timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),this));
  718. }
  719. CPlayerInterface::CPlayerInterface(int Player, int serial)
  720. {
  721. playerID=Player;
  722. serialID=serial;
  723. CGI->localPlayer = playerID;
  724. human=true;
  725. hInfo = CGI->bitmaph->loadBitmap("HEROQVBK.bmp");
  726. SDL_SetColorKey(hInfo,SDL_SRCCOLORKEY,SDL_MapRGB(hInfo->format,0,255,255));
  727. tInfo = CGI->bitmaph->loadBitmap("TOWNQVBK.bmp");
  728. SDL_SetColorKey(tInfo,SDL_SRCCOLORKEY,SDL_MapRGB(tInfo->format,0,255,255));
  729. slotsPos.push_back(std::pair<int,int>(44,82));
  730. slotsPos.push_back(std::pair<int,int>(80,82));
  731. slotsPos.push_back(std::pair<int,int>(116,82));
  732. slotsPos.push_back(std::pair<int,int>(26,131));
  733. slotsPos.push_back(std::pair<int,int>(62,131));
  734. slotsPos.push_back(std::pair<int,int>(98,131));
  735. slotsPos.push_back(std::pair<int,int>(134,131));
  736. luck22 = CGI->spriteh->giveDefEss("ILCK22.DEF");
  737. luck30 = CGI->spriteh->giveDefEss("ILCK30.DEF");
  738. luck42 = CGI->spriteh->giveDefEss("ILCK42.DEF");
  739. luck82 = CGI->spriteh->giveDefEss("ILCK82.DEF");
  740. morale22 = CGI->spriteh->giveDefEss("IMRL22.DEF");
  741. morale30 = CGI->spriteh->giveDefEss("IMRL30.DEF");
  742. morale42 = CGI->spriteh->giveDefEss("IMRL42.DEF");
  743. morale82 = CGI->spriteh->giveDefEss("IMRL82.DEF");
  744. halls = CGI->spriteh->giveDefEss("ITMTLS.DEF");
  745. forts = CGI->spriteh->giveDefEss("ITMCLS.DEF");
  746. bigTownPic = CGI->spriteh->giveDefEss("ITPT.DEF");
  747. }
  748. void CPlayerInterface::init(ICallback * CB)
  749. {
  750. cb = dynamic_cast<CCallback*>(CB);
  751. CGI->localPlayer = serialID;
  752. adventureInt = new CAdvMapInt(playerID);
  753. castleInt = NULL;
  754. std::vector <const CGHeroInstance *> hh = cb->getHeroesInfo(false);
  755. for(int i=0;i<hh.size();i++)
  756. {
  757. SDL_Surface * pom = infoWin(hh[i]);
  758. heroWins.insert(std::pair<int,SDL_Surface*>(hh[i]->subID,pom));
  759. }
  760. std::vector<const CGTownInstance*> tt = cb->getTownsInfo(false);
  761. for(int i=0;i<tt.size();i++)
  762. {
  763. SDL_Surface * pom = infoWin(tt[i]);
  764. townWins.insert(std::pair<int,SDL_Surface*>(tt[i]->identifier,pom));
  765. }
  766. }
  767. void CPlayerInterface::yourTurn()
  768. {
  769. makingTurn = true;
  770. CGI->localPlayer = serialID;
  771. unsigned char & animVal = LOCPLINT->adventureInt->anim; //for animations handling
  772. unsigned char & heroAnimVal = LOCPLINT->adventureInt->heroAnim;
  773. adventureInt->infoBar.newDay(cb->getDate(1));
  774. adventureInt->show();
  775. //show rest of things
  776. //initializing framerate keeper
  777. mainFPSmng = new FPSmanager;
  778. SDL_initFramerate(mainFPSmng);
  779. SDL_setFramerate(mainFPSmng, 24);
  780. SDL_Event sEvent;
  781. //framerate keeper initialized
  782. timeHandler th;
  783. th.getDif();
  784. for(;makingTurn;) // main loop
  785. {
  786. CGI->screenh->updateScreen();
  787. int tv = th.getDif();
  788. for (int i=0;i<timeinterested.size();i++)
  789. {
  790. if (timeinterested[i]->toNextTick>=0)
  791. timeinterested[i]->toNextTick-=tv;
  792. if (timeinterested[i]->toNextTick<0)
  793. timeinterested[i]->tick();
  794. }
  795. LOCPLINT->adventureInt->updateScreen = false;
  796. while (SDL_PollEvent(&sEvent)) //wait for event...
  797. {
  798. handleEvent(&sEvent);
  799. }
  800. if (!castleInt) //stuff for advMapInt
  801. {
  802. ++LOCPLINT->adventureInt->animValHitCount; //for animations
  803. if(LOCPLINT->adventureInt->animValHitCount == 4)
  804. {
  805. LOCPLINT->adventureInt->animValHitCount = 0;
  806. ++animVal;
  807. LOCPLINT->adventureInt->updateScreen = true;
  808. }
  809. ++heroAnimVal;
  810. if(LOCPLINT->adventureInt->scrollingLeft)
  811. {
  812. if(LOCPLINT->adventureInt->position.x>-Woff)
  813. {
  814. LOCPLINT->adventureInt->position.x--;
  815. LOCPLINT->adventureInt->updateScreen = true;
  816. adventureInt->updateMinimap=true;
  817. }
  818. }
  819. if(LOCPLINT->adventureInt->scrollingRight)
  820. {
  821. if(LOCPLINT->adventureInt->position.x<CGI->ac->map.width-19+4)
  822. {
  823. LOCPLINT->adventureInt->position.x++;
  824. LOCPLINT->adventureInt->updateScreen = true;
  825. adventureInt->updateMinimap=true;
  826. }
  827. }
  828. if(LOCPLINT->adventureInt->scrollingUp)
  829. {
  830. if(LOCPLINT->adventureInt->position.y>-Hoff)
  831. {
  832. LOCPLINT->adventureInt->position.y--;
  833. LOCPLINT->adventureInt->updateScreen = true;
  834. adventureInt->updateMinimap=true;
  835. }
  836. }
  837. if(LOCPLINT->adventureInt->scrollingDown)
  838. {
  839. if(LOCPLINT->adventureInt->position.y<CGI->ac->map.height-18+4)
  840. {
  841. LOCPLINT->adventureInt->position.y++;
  842. LOCPLINT->adventureInt->updateScreen = true;
  843. adventureInt->updateMinimap=true;
  844. }
  845. }
  846. if(LOCPLINT->adventureInt->updateScreen)
  847. {
  848. adventureInt->update();
  849. adventureInt->updateScreen=false;
  850. }
  851. if (LOCPLINT->adventureInt->updateMinimap)
  852. {
  853. adventureInt->minimap.draw();
  854. adventureInt->updateMinimap=false;
  855. }
  856. }
  857. for(int i=0;i<objsToBlit.size();i++)
  858. objsToBlit[i]->show();
  859. //SDL_Flip(ekran);
  860. CSDL_Ext::update(ekran);
  861. SDL_Delay(5); //give time for other apps
  862. SDL_framerateDelay(mainFPSmng);
  863. }
  864. adventureInt->hide();
  865. }
  866. inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, const int & hid)
  867. {
  868. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  869. for(int h=0; h<hlp.objects.size(); ++h)
  870. if(hlp.objects[h].first->id==hid)
  871. {
  872. hlp.objects[h].second = r;
  873. return;
  874. }
  875. }
  876. inline void delObjRect(const int & x, const int & y, const int & z, const int & hid)
  877. {
  878. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  879. for(int h=0; h<hlp.objects.size(); ++h)
  880. if(hlp.objects[h].first->id==hid)
  881. {
  882. hlp.objects.erase(hlp.objects.begin()+h);
  883. return;
  884. }
  885. }
  886. int getDir(int3 src, int3 dst)
  887. {
  888. int ret = -1;
  889. if(dst.x+1 == src.x && dst.y+1 == src.y) //tl
  890. {
  891. ret = 1;
  892. }
  893. else if(dst.x == src.x && dst.y+1 == src.y) //t
  894. {
  895. ret = 2;
  896. }
  897. else if(dst.x-1 == src.x && dst.y+1 == src.y) //tr
  898. {
  899. ret = 3;
  900. }
  901. else if(dst.x-1 == src.x && dst.y == src.y) //r
  902. {
  903. ret = 4;
  904. }
  905. else if(dst.x-1 == src.x && dst.y-1 == src.y) //br
  906. {
  907. ret = 5;
  908. }
  909. else if(dst.x == src.x && dst.y-1 == src.y) //b
  910. {
  911. ret = 6;
  912. }
  913. else if(dst.x+1 == src.x && dst.y-1 == src.y) //bl
  914. {
  915. ret = 7;
  916. }
  917. else if(dst.x+1 == src.x && dst.y == src.y) //l
  918. {
  919. ret = 8;
  920. }
  921. return ret;
  922. }
  923. void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
  924. {
  925. //initializing objects and performing first step of move
  926. CGHeroInstance * ho = details.ho; //object representing this hero
  927. int3 hp = details.src;
  928. if (!details.successful)
  929. {
  930. ho->moveDir = getDir(details.src,details.dst);
  931. ho->isStanding = true;
  932. adventureInt->heroList.draw();
  933. if (adventureInt->terrain.currentPath)
  934. {
  935. delete adventureInt->terrain.currentPath;
  936. adventureInt->terrain.currentPath = NULL;
  937. }
  938. return;
  939. }
  940. if (adventureInt->terrain.currentPath) //&& hero is moving
  941. {
  942. adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
  943. }
  944. int3 buff = details.ho->pos;
  945. buff.x-=11;
  946. buff.y-=9;
  947. buff = repairScreenPos(buff);
  948. LOCPLINT->adventureInt->position = buff; //actualizing screen pos
  949. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  950. {
  951. ho->moveDir = 1;
  952. ho->isStanding = false;
  953. CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -31)));
  954. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, -31)));
  955. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, -31)));
  956. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, -31)));
  957. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 1)));
  958. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 1), ho->id);
  959. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 1), ho->id);
  960. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 1), ho->id);
  961. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 33)));
  962. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 33), ho->id);
  963. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 33), ho->id);
  964. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 33), ho->id);
  965. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  966. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  967. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  968. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  969. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  970. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  971. }
  972. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  973. {
  974. ho->moveDir = 2;
  975. ho->isStanding = false;
  976. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, -31)));
  977. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, -31)));
  978. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, -31)));
  979. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1), ho->id);
  980. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1), ho->id);
  981. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1), ho->id);
  982. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33), ho->id);
  983. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33), ho->id);
  984. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33), ho->id);
  985. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  986. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  987. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  988. }
  989. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  990. {
  991. ho->moveDir = 3;
  992. ho->isStanding = false;
  993. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, -31)));
  994. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, -31)));
  995. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, -31)));
  996. CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -31)));
  997. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 1), ho->id);
  998. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 1), ho->id);
  999. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 1), ho->id);
  1000. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 1)));
  1001. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 33), ho->id);
  1002. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 33), ho->id);
  1003. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 33), ho->id);
  1004. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 33)));
  1005. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1006. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1007. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1008. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1009. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1010. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1011. }
  1012. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1013. {
  1014. ho->moveDir = 4;
  1015. ho->isStanding = false;
  1016. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id);
  1017. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id);
  1018. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id);
  1019. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 0)));
  1020. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 32), ho->id);
  1021. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 32), ho->id);
  1022. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 32), ho->id);
  1023. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 32)));
  1024. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1025. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1026. }
  1027. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1028. {
  1029. ho->moveDir = 5;
  1030. ho->isStanding = false;
  1031. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, -1), ho->id);
  1032. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, -1), ho->id);
  1033. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id);
  1034. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -1)));
  1035. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 31), ho->id);
  1036. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 31), ho->id);
  1037. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 31), ho->id);
  1038. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 31)));
  1039. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, 63)));
  1040. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, 63)));
  1041. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, 63)));
  1042. CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 63)));
  1043. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1044. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1045. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1046. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1047. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1048. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1049. }
  1050. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1051. {
  1052. ho->moveDir = 6;
  1053. ho->isStanding = false;
  1054. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1), ho->id);
  1055. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1), ho->id);
  1056. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1), ho->id);
  1057. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31), ho->id);
  1058. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31), ho->id);
  1059. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31), ho->id);
  1060. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, 63)));
  1061. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, 63)));
  1062. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, 63)));
  1063. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1064. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1065. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1066. }
  1067. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1068. {
  1069. ho->moveDir = 7;
  1070. ho->isStanding = false;
  1071. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -1)));
  1072. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id);
  1073. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id);
  1074. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, -1), ho->id);
  1075. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 31)));
  1076. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 31), ho->id);
  1077. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 31), ho->id);
  1078. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 31), ho->id);
  1079. CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 63)));
  1080. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, 63)));
  1081. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, 63)));
  1082. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, 63)));
  1083. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1084. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1085. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1086. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1087. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1088. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1089. }
  1090. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1091. {
  1092. ho->moveDir = 8;
  1093. ho->isStanding = false;
  1094. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 0)));
  1095. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id);
  1096. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id);
  1097. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 0), ho->id);
  1098. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 32)));
  1099. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 32), ho->id);
  1100. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 32), ho->id);
  1101. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 32), ho->id);
  1102. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1103. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1104. }
  1105. //first initializing done
  1106. SDL_framerateDelay(mainFPSmng); // after first move
  1107. //main moving
  1108. for(int i=1; i<32; i+=4)
  1109. {
  1110. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  1111. {
  1112. subRect(hp.x-3, hp.y-2, hp.z, genRect(32, 32, -31+i, -31+i), ho->id);
  1113. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 1+i, -31+i), ho->id);
  1114. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 33+i, -31+i), ho->id);
  1115. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 65+i, -31+i), ho->id);
  1116. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 1+i), ho->id);
  1117. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 1+i), ho->id);
  1118. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 1+i), ho->id);
  1119. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 1+i), ho->id);
  1120. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 33+i), ho->id);
  1121. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 33+i), ho->id);
  1122. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 33+i), ho->id);
  1123. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 33+i), ho->id);
  1124. }
  1125. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  1126. {
  1127. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 0, -31+i), ho->id);
  1128. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 32, -31+i), ho->id);
  1129. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 64, -31+i), ho->id);
  1130. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1+i), ho->id);
  1131. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1+i), ho->id);
  1132. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1+i), ho->id);
  1133. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33+i), ho->id);
  1134. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33+i), ho->id);
  1135. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33+i), ho->id);
  1136. }
  1137. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  1138. {
  1139. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, -1-i, -31+i), ho->id);
  1140. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 31-i, -31+i), ho->id);
  1141. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 63-i, -31+i), ho->id);
  1142. subRect(hp.x+1, hp.y-2, hp.z, genRect(32, 32, 95-i, -31+i), ho->id);
  1143. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 1+i), ho->id);
  1144. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 1+i), ho->id);
  1145. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 1+i), ho->id);
  1146. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 1+i), ho->id);
  1147. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 33+i), ho->id);
  1148. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 33+i), ho->id);
  1149. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 33+i), ho->id);
  1150. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 33+i), ho->id);
  1151. }
  1152. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1153. {
  1154. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 0), ho->id);
  1155. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 0), ho->id);
  1156. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 0), ho->id);
  1157. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 0), ho->id);
  1158. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 32), ho->id);
  1159. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 32), ho->id);
  1160. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 32), ho->id);
  1161. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 32), ho->id);
  1162. }
  1163. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1164. {
  1165. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, -1-i), ho->id);
  1166. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, -1-i), ho->id);
  1167. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, -1-i), ho->id);
  1168. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, -1-i), ho->id);
  1169. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 31-i), ho->id);
  1170. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 31-i), ho->id);
  1171. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 31-i), ho->id);
  1172. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 31-i), ho->id);
  1173. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, -1-i, 63-i), ho->id);
  1174. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 31-i, 63-i), ho->id);
  1175. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 63-i, 63-i), ho->id);
  1176. subRect(hp.x+1, hp.y+1, hp.z, genRect(32, 32, 95-i, 63-i), ho->id);
  1177. }
  1178. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1179. {
  1180. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1-i), ho->id);
  1181. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1-i), ho->id);
  1182. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1-i), ho->id);
  1183. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31-i), ho->id);
  1184. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31-i), ho->id);
  1185. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31-i), ho->id);
  1186. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 0, 63-i), ho->id);
  1187. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 32, 63-i), ho->id);
  1188. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 64, 63-i), ho->id);
  1189. }
  1190. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1191. {
  1192. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, -1-i), ho->id);
  1193. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, -1-i), ho->id);
  1194. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, -1-i), ho->id);
  1195. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, -1-i), ho->id);
  1196. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 31-i), ho->id);
  1197. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 31-i), ho->id);
  1198. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 31-i), ho->id);
  1199. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 31-i), ho->id);
  1200. subRect(hp.x-3, hp.y+1, hp.z, genRect(32, 32, -31+i, 63-i), ho->id);
  1201. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 1+i, 63-i), ho->id);
  1202. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 33+i, 63-i), ho->id);
  1203. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 65+i, 63-i), ho->id);
  1204. }
  1205. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1206. {
  1207. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 0), ho->id);
  1208. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 0), ho->id);
  1209. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 0), ho->id);
  1210. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 0), ho->id);
  1211. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 32), ho->id);
  1212. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 32), ho->id);
  1213. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 32), ho->id);
  1214. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 32), ho->id);
  1215. }
  1216. LOCPLINT->adventureInt->update(); //updating screen
  1217. CSDL_Ext::update(ekran);
  1218. CGI->screenh->updateScreen();
  1219. ++LOCPLINT->adventureInt->animValHitCount; //for animations
  1220. if(LOCPLINT->adventureInt->animValHitCount == 4)
  1221. {
  1222. LOCPLINT->adventureInt->animValHitCount = 0;
  1223. ++LOCPLINT->adventureInt->anim;
  1224. LOCPLINT->adventureInt->updateScreen = true;
  1225. }
  1226. ++LOCPLINT->adventureInt->heroAnim;
  1227. SDL_Delay(5);
  1228. SDL_framerateDelay(mainFPSmng); //for animation purposes
  1229. } //for(int i=1; i<32; i+=4)
  1230. //main moving done
  1231. //finishing move
  1232. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  1233. {
  1234. delObjRect(hp.x, hp.y-2, hp.z, ho->id);
  1235. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1236. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1237. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1238. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1239. delObjRect(hp.x-3, hp.y, hp.z, ho->id);
  1240. }
  1241. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  1242. {
  1243. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1244. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1245. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1246. }
  1247. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  1248. {
  1249. delObjRect(hp.x-2, hp.y-2, hp.z, ho->id);
  1250. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1251. delObjRect(hp.x+1, hp.y, hp.z, ho->id);
  1252. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1253. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1254. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1255. }
  1256. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1257. {
  1258. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1259. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1260. }
  1261. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1262. {
  1263. delObjRect(hp.x-2, hp.y+1, hp.z, ho->id);
  1264. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1265. delObjRect(hp.x+1, hp.y-1, hp.z, ho->id);
  1266. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1267. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1268. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1269. }
  1270. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1271. {
  1272. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1273. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1274. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1275. }
  1276. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1277. {
  1278. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1279. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1280. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1281. delObjRect(hp.x-3, hp.y-1, hp.z, ho->id);
  1282. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1283. delObjRect(hp.x, hp.y+1, hp.z, ho->id);
  1284. }
  1285. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1286. {
  1287. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1288. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1289. }
  1290. ho->pos = details.dst; //copy of hero's position
  1291. //ho->moveDir = 0; //move ended
  1292. ho->isStanding = true;
  1293. //move finished
  1294. CGI->mh->recalculateHideVisPosUnderObj(details.ho, true);
  1295. adventureInt->minimap.draw();
  1296. adventureInt->heroList.updateMove(ho);
  1297. }
  1298. void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
  1299. {
  1300. heroWins.erase(hero->ID);
  1301. }
  1302. void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
  1303. {
  1304. if(heroWins.find(hero->subID)==heroWins.end())
  1305. heroWins.insert(std::pair<int,SDL_Surface*>(hero->subID,infoWin(hero)));
  1306. }
  1307. SDL_Surface * CPlayerInterface::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to)
  1308. {
  1309. char * buf = new char[10];
  1310. for (int i=from;i<to;i++)
  1311. {
  1312. itoa(curh->primSkills[i],buf,10);
  1313. printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
  1314. }
  1315. delete[] buf;
  1316. return ret;
  1317. }
  1318. SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh)
  1319. {
  1320. char * buf = new char[10];
  1321. SDL_Surface * ret = SDL_DisplayFormat(hInfo);
  1322. SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
  1323. blueToPlayersAdv(ret,playerID,1);
  1324. printAt(curh->name,75,15,GEOR13,zwykly,ret);
  1325. drawPrimarySkill(curh, ret);
  1326. for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
  1327. {
  1328. blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
  1329. itoa((*i).second.second,buf,10);
  1330. printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
  1331. }
  1332. blitAt(curh->type->portraitLarge,11,12,ret);
  1333. itoa(curh->mana,buf,10);
  1334. printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points
  1335. delete[] buf;
  1336. blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret);
  1337. blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret);
  1338. //SDL_SaveBMP(ret,"inf1.bmp");
  1339. return ret;
  1340. }
  1341. SDL_Surface * CPlayerInterface::drawTownInfoWin(const CGTownInstance * curh)
  1342. {
  1343. char * buf = new char[10];
  1344. SDL_Surface * ret = SDL_DisplayFormat(tInfo);
  1345. SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
  1346. blueToPlayersAdv(ret,playerID,1);
  1347. printAt(curh->name,75,15,GEOR13,zwykly,ret);
  1348. int pom = curh->fortLevel() - 1; if(pom<0) pom = 3;
  1349. blitAt(forts->ourImages[pom].bitmap,115,42,ret);
  1350. if((pom=curh->hallLevel())>=0)
  1351. blitAt(halls->ourImages[pom].bitmap,77,42,ret);
  1352. itoa(curh->dailyIncome(),buf,10);
  1353. printAtMiddle(buf,167,70,GEORM,zwykly,ret);
  1354. for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->garrison.slots.begin(); i!=curh->garrison.slots.end();i++)
  1355. {
  1356. blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
  1357. itoa((*i).second.second,buf,10);
  1358. printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
  1359. }
  1360. //blit town icon
  1361. pom = curh->subID*2;
  1362. if (!curh->hasFort())
  1363. pom += F_NUMBER*2;
  1364. if(curh->builded >= MAX_BUILDING_PER_TURN)
  1365. pom++;
  1366. blitAt(bigTownPic->ourImages[pom].bitmap,13,13,ret);
  1367. delete[] buf;
  1368. return ret;
  1369. }
  1370. void CPlayerInterface::openTownWindow(const CGTownInstance * town)
  1371. {
  1372. adventureInt->hide();
  1373. //timeHandler t;
  1374. //t.getDif();
  1375. castleInt = new CCastleInterface(town,true);
  1376. //std::cout << "Loading town screen: " << t.getDif() <<std::endl;
  1377. }
  1378. SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //specific=0 => draws info about selected town/hero
  1379. {
  1380. if (specific)
  1381. {
  1382. switch (specific->ID)
  1383. {
  1384. case 34:
  1385. return drawHeroInfoWin(dynamic_cast<const CGHeroInstance*>(specific));
  1386. break;
  1387. case 98:
  1388. return drawTownInfoWin(dynamic_cast<const CGTownInstance*>(specific));
  1389. break;
  1390. default:
  1391. return NULL;
  1392. break;
  1393. }
  1394. }
  1395. else
  1396. {
  1397. switch (adventureInt->selection.type)
  1398. {
  1399. case HEROI_TYPE:
  1400. {
  1401. const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection.selected;
  1402. return drawHeroInfoWin(curh);
  1403. }
  1404. case TOWNI_TYPE:
  1405. {
  1406. return drawTownInfoWin((const CGTownInstance *)adventureInt->selection.selected);
  1407. }
  1408. default:
  1409. return NULL;
  1410. }
  1411. }
  1412. return NULL;
  1413. }
  1414. void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent)
  1415. {
  1416. for (int i=0; i<hoverable.size();i++)
  1417. {
  1418. if (isItIn(&hoverable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1419. {
  1420. if (!hoverable[i]->hovered)
  1421. hoverable[i]->hover(true);
  1422. }
  1423. else if (hoverable[i]->hovered)
  1424. {
  1425. hoverable[i]->hover(false);
  1426. }
  1427. }
  1428. for(int i=0; i<motioninterested.size();i++)
  1429. {
  1430. if (isItIn(&motioninterested[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1431. {
  1432. motioninterested[i]->mouseMoved(sEvent->motion);
  1433. }
  1434. }
  1435. if(sEvent->motion.x<15)
  1436. {
  1437. LOCPLINT->adventureInt->scrollingLeft = true;
  1438. }
  1439. else
  1440. {
  1441. LOCPLINT->adventureInt->scrollingLeft = false;
  1442. }
  1443. if(sEvent->motion.x>ekran->w-15)
  1444. {
  1445. LOCPLINT->adventureInt->scrollingRight = true;
  1446. }
  1447. else
  1448. {
  1449. LOCPLINT->adventureInt->scrollingRight = false;
  1450. }
  1451. if(sEvent->motion.y<15)
  1452. {
  1453. LOCPLINT->adventureInt->scrollingUp = true;
  1454. }
  1455. else
  1456. {
  1457. LOCPLINT->adventureInt->scrollingUp = false;
  1458. }
  1459. if(sEvent->motion.y>ekran->h-15)
  1460. {
  1461. LOCPLINT->adventureInt->scrollingDown = true;
  1462. }
  1463. else
  1464. {
  1465. LOCPLINT->adventureInt->scrollingDown = false;
  1466. }
  1467. }
  1468. void CPlayerInterface::handleKeyUp(SDL_Event *sEvent)
  1469. {
  1470. switch (sEvent->key.keysym.sym)
  1471. {
  1472. case SDLK_LEFT:
  1473. {
  1474. LOCPLINT->adventureInt->scrollingLeft = false;
  1475. break;
  1476. }
  1477. case (SDLK_RIGHT):
  1478. {
  1479. LOCPLINT->adventureInt->scrollingRight = false;
  1480. break;
  1481. }
  1482. case (SDLK_UP):
  1483. {
  1484. LOCPLINT->adventureInt->scrollingUp = false;
  1485. break;
  1486. }
  1487. case (SDLK_DOWN):
  1488. {
  1489. LOCPLINT->adventureInt->scrollingDown = false;
  1490. break;
  1491. }
  1492. case (SDLK_u):
  1493. {
  1494. adventureInt->underground.clickLeft(false);
  1495. break;
  1496. }
  1497. case (SDLK_m):
  1498. {
  1499. adventureInt->moveHero.clickLeft(false);
  1500. break;
  1501. }
  1502. case (SDLK_e):
  1503. {
  1504. adventureInt->endTurn.clickLeft(false);
  1505. break;
  1506. }
  1507. }
  1508. }
  1509. void CPlayerInterface::handleKeyDown(SDL_Event *sEvent)
  1510. {
  1511. switch (sEvent->key.keysym.sym)
  1512. {
  1513. case SDLK_LEFT:
  1514. {
  1515. LOCPLINT->adventureInt->scrollingLeft = true;
  1516. break;
  1517. }
  1518. case (SDLK_RIGHT):
  1519. {
  1520. LOCPLINT->adventureInt->scrollingRight = true;
  1521. break;
  1522. }
  1523. case (SDLK_UP):
  1524. {
  1525. LOCPLINT->adventureInt->scrollingUp = true;
  1526. break;
  1527. }
  1528. case (SDLK_DOWN):
  1529. {
  1530. LOCPLINT->adventureInt->scrollingDown = true;
  1531. break;
  1532. }
  1533. case (SDLK_q):
  1534. {
  1535. exit(0);
  1536. break;
  1537. }
  1538. case (SDLK_u):
  1539. {
  1540. adventureInt->underground.clickLeft(true);
  1541. break;
  1542. }
  1543. case (SDLK_m):
  1544. {
  1545. adventureInt->moveHero.clickLeft(true);
  1546. break;
  1547. }
  1548. case (SDLK_e):
  1549. {
  1550. adventureInt->endTurn.clickLeft(true);
  1551. break;
  1552. }
  1553. }
  1554. }
  1555. void CPlayerInterface::handleEvent(SDL_Event *sEvent)
  1556. {
  1557. current = sEvent;
  1558. if(sEvent->type == SDL_MOUSEMOTION)
  1559. {
  1560. CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
  1561. }
  1562. if(sEvent->type==SDL_QUIT)
  1563. exit(0);
  1564. else if (sEvent->type==SDL_KEYDOWN)
  1565. {
  1566. handleKeyDown(sEvent);
  1567. } //keydown end
  1568. else if(sEvent->type==SDL_KEYUP)
  1569. {
  1570. handleKeyUp(sEvent);
  1571. }//keyup end
  1572. else if(sEvent->type==SDL_MOUSEMOTION)
  1573. {
  1574. handleMouseMotion(sEvent);
  1575. } //mousemotion end
  1576. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1577. {
  1578. LOGE("Left mouse button down1");
  1579. for(int i=0; i<lclickable.size();i++)
  1580. {
  1581. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1582. {
  1583. lclickable[i]->clickLeft(true);
  1584. }
  1585. }
  1586. }
  1587. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1588. {
  1589. for(int i=0; i<lclickable.size();i++)
  1590. {
  1591. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1592. {
  1593. lclickable[i]->clickLeft(false);
  1594. }
  1595. else
  1596. lclickable[i]->clickLeft(boost::logic::indeterminate);
  1597. }
  1598. }
  1599. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1600. {
  1601. for(int i=0; i<rclickable.size();i++)
  1602. {
  1603. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1604. {
  1605. rclickable[i]->clickRight(true);
  1606. }
  1607. }
  1608. }
  1609. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1610. {
  1611. for(int i=0; i<rclickable.size();i++)
  1612. {
  1613. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1614. {
  1615. rclickable[i]->clickRight(false);
  1616. }
  1617. else
  1618. rclickable[i]->clickRight(boost::logic::indeterminate);
  1619. }
  1620. }
  1621. current = NULL;
  1622. } //event end
  1623. int3 CPlayerInterface::repairScreenPos(int3 pos)
  1624. {
  1625. if(pos.x<=-Woff)
  1626. pos.x = -Woff+1;
  1627. if(pos.y<=-Hoff)
  1628. pos.y = -Hoff+1;
  1629. if(pos.x>CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff)
  1630. pos.x = CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff;
  1631. if(pos.y>CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff)
  1632. pos.y = CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff;
  1633. return pos;
  1634. }
  1635. void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)
  1636. {
  1637. SDL_FreeSurface(heroWins[hero->subID]);//TODO: moznaby zmieniac jedynie fragment bitmapy zwiazany z dana umiejetnoscia
  1638. heroWins[hero->subID] = infoWin(hero); //a nie przerysowywac calosc. Troche roboty, obecnie chyba nie wartej swieczki.
  1639. if (adventureInt->selection.selected == hero)
  1640. adventureInt->infoBar.draw();
  1641. return;
  1642. }
  1643. void CPlayerInterface::receivedResource(int type, int val)
  1644. {
  1645. adventureInt->resdatabar.draw();
  1646. }
  1647. void CPlayerInterface::showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID)
  1648. {
  1649. adventureInt->hide(); //dezaktywacja starego interfejsu
  1650. CSelWindow * temp = CMessage::genSelWindow(text,LOCPLINT->playerID,35,components,playerID);
  1651. LOCPLINT->objsToBlit.push_back(temp);
  1652. temp->pos.x=300-(temp->pos.w/2);
  1653. temp->pos.y=300-(temp->pos.h/2);
  1654. temp->okb.pos.x = temp->okb.posr.x + temp->pos.x;
  1655. temp->okb.pos.y = temp->okb.posr.y + temp->pos.y;
  1656. temp->okb.activate();
  1657. for (int i=0;i<temp->components.size();i++)
  1658. {
  1659. temp->components[i]->activate();
  1660. temp->components[i]->pos.x += temp->pos.x;
  1661. temp->components[i]->pos.y += temp->pos.y;
  1662. }
  1663. temp->ID = askID;
  1664. components[0]->clickLeft(true);
  1665. }
  1666. void CPlayerInterface::heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town)
  1667. {
  1668. openTownWindow(town);
  1669. }
  1670. void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj)
  1671. {
  1672. if(obj->ID == 34) //hero
  1673. {
  1674. const CGHeroInstance * hh;
  1675. if(hh = dynamic_cast<const CGHeroInstance*>(obj))
  1676. {
  1677. SDL_FreeSurface(heroWins[hh->subID]);
  1678. heroWins[hh->subID] = infoWin(hh);
  1679. }
  1680. }
  1681. else if (obj->ID == 98) //town
  1682. {
  1683. const CGTownInstance * tt;
  1684. if(tt = dynamic_cast<const CGTownInstance*>(obj))
  1685. {
  1686. SDL_FreeSurface(heroWins[tt->identifier]);
  1687. heroWins[tt->identifier] = infoWin(tt);
  1688. }
  1689. }
  1690. }
  1691. void CPlayerInterface::showComp(SComponent comp)
  1692. {
  1693. adventureInt->infoBar.showComp(&comp,4000);
  1694. }
  1695. void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*> & components)
  1696. {
  1697. curint->deactivate(); //dezaktywacja starego interfejsu
  1698. CInfoWindow * temp = CMessage::genIWindow(text,LOCPLINT->playerID,32,components);
  1699. LOCPLINT->objsToBlit.push_back(temp);
  1700. temp->pos.x=300-(temp->pos.w/2);
  1701. temp->pos.y=300-(temp->pos.h/2);
  1702. temp->okb.pos.x = temp->okb.posr.x + temp->pos.x;
  1703. temp->okb.pos.y = temp->okb.posr.y + temp->pos.y;
  1704. temp->okb.activate();
  1705. for (int i=0;i<temp->components.size();i++)
  1706. {
  1707. temp->components[i]->activate();
  1708. temp->components[i]->pos.x += temp->pos.x;
  1709. temp->components[i]->pos.y += temp->pos.y;
  1710. }
  1711. }
  1712. void CPlayerInterface::removeObjToBlit(IShowable* obj)
  1713. {
  1714. objsToBlit.erase
  1715. (std::find(objsToBlit.begin(),objsToBlit.end(),obj));
  1716. //delete obj;
  1717. }
  1718. void CPlayerInterface::tileRevealed(int3 pos)
  1719. {
  1720. adventureInt->minimap.showTile(pos);
  1721. }
  1722. void CPlayerInterface::tileHidden(int3 pos)
  1723. {
  1724. adventureInt->minimap.hideTile(pos);
  1725. }
  1726. void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero)
  1727. {
  1728. adventureInt->heroWindow->setHero(hero);
  1729. this->objsToBlit.push_back(adventureInt->heroWindow);
  1730. adventureInt->hide();
  1731. adventureInt->heroWindow->activate();
  1732. }
  1733. CStatusBar::CStatusBar(int x, int y, std::string name, int maxw)
  1734. {
  1735. bg=CGI->bitmaph->loadBitmap(name);
  1736. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  1737. pos.x=x;
  1738. pos.y=y;
  1739. if(maxw >= 0)
  1740. pos.w = std::min(bg->w,maxw);
  1741. else
  1742. pos.w=bg->w;
  1743. pos.h=bg->h;
  1744. middlex=(pos.w/2)+x;
  1745. middley=(bg->h/2)+y;
  1746. }
  1747. CStatusBar::~CStatusBar()
  1748. {
  1749. SDL_FreeSurface(bg);
  1750. }
  1751. void CStatusBar::clear()
  1752. {
  1753. current="";
  1754. SDL_Rect pom = genRect(pos.h,pos.w,pos.x,pos.y);
  1755. SDL_BlitSurface(bg,&genRect(pos.h,pos.w,0,0),ekran,&pom);
  1756. }
  1757. void CStatusBar::print(std::string text)
  1758. {
  1759. current=text;
  1760. SDL_Rect pom = genRect(pos.h,pos.w,pos.x,pos.y);
  1761. SDL_BlitSurface(bg,&genRect(pos.h,pos.w,0,0),ekran,&pom);
  1762. printAtMiddle(current,middlex,middley,GEOR13,zwykly);
  1763. }
  1764. void CStatusBar::show()
  1765. {
  1766. SDL_Rect pom = genRect(pos.h,pos.w,pos.x,pos.y);
  1767. SDL_BlitSurface(bg,&genRect(pos.h,pos.w,0,0),ekran,&pom);
  1768. printAtMiddle(current,middlex,middley,GEOR13,zwykly);
  1769. }
  1770. std::string CStatusBar::getCurrent()
  1771. {
  1772. return current;
  1773. }
  1774. void CList::activate()
  1775. {
  1776. ClickableL::activate();
  1777. ClickableR::activate();
  1778. Hoverable::activate();
  1779. KeyInterested::activate();
  1780. MotionInterested::activate();
  1781. };
  1782. void CList::deactivate()
  1783. {
  1784. ClickableL::deactivate();
  1785. ClickableR::deactivate();
  1786. Hoverable::deactivate();
  1787. KeyInterested::deactivate();
  1788. MotionInterested::deactivate();
  1789. };
  1790. void CList::clickLeft(tribool down)
  1791. {
  1792. };
  1793. CList::CList(int Size)
  1794. :SIZE(Size)
  1795. {
  1796. }
  1797. CHeroList::CHeroList(int Size)
  1798. :CList(Size)
  1799. {
  1800. pos = genRect(192,64,609,196);
  1801. arrupp = genRect(16,64,609,196);
  1802. arrdop = genRect(16,64,609,372);
  1803. //32px per hero
  1804. posmobx = 610;
  1805. posmoby = 213;
  1806. posporx = 617;
  1807. pospory = 212;
  1808. posmanx = 666;
  1809. posmany = 213;
  1810. arrup = CGI->spriteh->giveDef("IAM012.DEF");
  1811. arrdo = CGI->spriteh->giveDef("IAM013.DEF");
  1812. mobile = CGI->spriteh->giveDef("IMOBIL.DEF");
  1813. mana = CGI->spriteh->giveDef("IMANA.DEF");
  1814. empty = CGI->bitmaph->loadBitmap("HPSXXX.bmp");
  1815. selection = CGI->bitmaph->loadBitmap("HPSYYY.bmp");
  1816. SDL_SetColorKey(selection,SDL_SRCCOLORKEY,SDL_MapRGB(selection->format,0,255,255));
  1817. from = 0;
  1818. pressed = indeterminate;
  1819. }
  1820. void CHeroList::init()
  1821. {
  1822. bg = CSDL_Ext::newSurface(68,193,ekran);
  1823. SDL_BlitSurface(LOCPLINT->adventureInt->bg,&genRect(193,68,607,196),bg,&genRect(193,68,0,0));
  1824. }
  1825. void CHeroList::genList()
  1826. {
  1827. int howMany = LOCPLINT->cb->howManyHeroes();
  1828. for (int i=0;i<howMany;i++)
  1829. {
  1830. items.push_back(std::pair<const CGHeroInstance *,CPath *>(LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,i,0),NULL));
  1831. }
  1832. }
  1833. void CHeroList::select(int which)
  1834. {
  1835. if (which<0)
  1836. {
  1837. selected = which;
  1838. LOCPLINT->adventureInt->selection.selected = LOCPLINT->adventureInt->terrain.currentPath = NULL;
  1839. draw();
  1840. LOCPLINT->adventureInt->infoBar.draw(NULL);
  1841. }
  1842. if (which>=items.size())
  1843. return;
  1844. selected = which;
  1845. LOCPLINT->adventureInt->centerOn(items[which].first->pos);
  1846. LOCPLINT->adventureInt->selection.type = HEROI_TYPE;
  1847. LOCPLINT->adventureInt->selection.selected = items[which].first;
  1848. LOCPLINT->adventureInt->terrain.currentPath = items[which].second;
  1849. draw();
  1850. LOCPLINT->adventureInt->townList.draw();
  1851. LOCPLINT->adventureInt->infoBar.draw(NULL);
  1852. }
  1853. void CHeroList::clickLeft(tribool down)
  1854. {
  1855. if (down)
  1856. {
  1857. /***************************ARROWS*****************************************/
  1858. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  1859. {
  1860. blitAt(arrup->ourImages[1].bitmap,arrupp.x,arrupp.y);
  1861. pressed = true;
  1862. return;
  1863. }
  1864. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  1865. {
  1866. blitAt(arrdo->ourImages[1].bitmap,arrdop.x,arrdop.y);
  1867. pressed = false;
  1868. return;
  1869. }
  1870. /***************************HEROES*****************************************/
  1871. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  1872. hx-=pos.x;
  1873. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  1874. float ny = (float)hy/(float)32;
  1875. if (ny>=5 || ny<0)
  1876. return;
  1877. if (((int)(ny+from))==selected && (LOCPLINT->adventureInt->selection.type == HEROI_TYPE))
  1878. LOCPLINT->openHeroWindow(items[selected].first);//print hero screen
  1879. select(ny+from);
  1880. }
  1881. else
  1882. {
  1883. if (indeterminate(pressed))
  1884. return;
  1885. if (pressed) //up
  1886. {
  1887. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  1888. pressed = indeterminate;
  1889. if (!down)
  1890. {
  1891. from--;
  1892. if (from<0)
  1893. from=0;
  1894. draw();
  1895. }
  1896. }
  1897. else if (!pressed) //down
  1898. {
  1899. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  1900. pressed = indeterminate;
  1901. if (!down)
  1902. {
  1903. from++;
  1904. //if (from<items.size()-5)
  1905. // from=items.size()-5;
  1906. draw();
  1907. }
  1908. }
  1909. else
  1910. throw 0;
  1911. }
  1912. }
  1913. void CHeroList::mouseMoved (SDL_MouseMotionEvent & sEvent)
  1914. {
  1915. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  1916. {
  1917. if (from>0)
  1918. LOCPLINT->adventureInt->statusbar.print(CGI->preth->zelp[303].first);
  1919. else
  1920. LOCPLINT->adventureInt->statusbar.clear();
  1921. return;
  1922. }
  1923. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  1924. {
  1925. if ((items.size()-from) > 5)
  1926. LOCPLINT->adventureInt->statusbar.print(CGI->preth->zelp[304].first);
  1927. else
  1928. LOCPLINT->adventureInt->statusbar.clear();
  1929. return;
  1930. }
  1931. //if not buttons then heroes
  1932. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  1933. hx-=pos.x;
  1934. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  1935. float ny = (float)hy/(float)32;
  1936. if ((ny>5 || ny<0) || (from+ny>=items.size()))
  1937. {
  1938. LOCPLINT->adventureInt->statusbar.clear();
  1939. return;
  1940. }
  1941. std::vector<std::string> temp;
  1942. temp.push_back(items[from+ny].first->name);
  1943. temp.push_back(items[from+ny].first->type->heroClass->name);
  1944. LOCPLINT->adventureInt->statusbar.print( processStr(CGI->generaltexth->allTexts[15],temp) );
  1945. //select(ny+from);
  1946. }
  1947. void CHeroList::clickRight(tribool down)
  1948. {
  1949. if (down)
  1950. {
  1951. /***************************ARROWS*****************************************/
  1952. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  1953. {
  1954. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[303].second,down,this);
  1955. }
  1956. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  1957. {
  1958. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[304].second,down,this);
  1959. }
  1960. }
  1961. else
  1962. {
  1963. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[303].second,down,this);
  1964. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[304].second,down,this);
  1965. }
  1966. }
  1967. void CHeroList::hover (bool on)
  1968. {
  1969. }
  1970. void CHeroList::keyPressed (SDL_KeyboardEvent & key)
  1971. {
  1972. }
  1973. void CHeroList::updateHList()
  1974. {
  1975. items.clear();
  1976. genList();
  1977. if(selected>=items.size())
  1978. select(items.size()-1);
  1979. }
  1980. void CHeroList::updateMove(const CGHeroInstance* which) //draws move points bar
  1981. {
  1982. int ser = LOCPLINT->cb->getHeroSerial(which);
  1983. ser -= from;
  1984. int pom = (which->movement)/100;
  1985. blitAt(mobile->ourImages[pom].bitmap,posmobx,posmoby+ser*32); //move point
  1986. }
  1987. void CHeroList::draw()
  1988. {
  1989. for (int iT=0+from;iT<5+from;iT++)
  1990. {
  1991. int i = iT-from;
  1992. if (iT>=items.size())
  1993. {
  1994. blitAt(mobile->ourImages[0].bitmap,posmobx,posmoby+i*32);
  1995. blitAt(mana->ourImages[0].bitmap,posmanx,posmany+i*32);
  1996. blitAt(empty,posporx,pospory+i*32);
  1997. continue;
  1998. }
  1999. int pom = (LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->movement)/100;
  2000. if (pom>25) pom=25;
  2001. if (pom<0) pom=0;
  2002. blitAt(mobile->ourImages[pom].bitmap,posmobx,posmoby+i*32); //move point
  2003. pom = (LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->mana)/5; //bylo: .../10;
  2004. if (pom>25) pom=25;
  2005. if (pom<0) pom=0;
  2006. blitAt(mana->ourImages[pom].bitmap,posmanx,posmany+i*32); //mana
  2007. SDL_Surface * temp = LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->type->portraitSmall;
  2008. blitAt(temp,posporx,pospory+i*32);
  2009. if ((selected == iT) && (LOCPLINT->adventureInt->selection.type == HEROI_TYPE))
  2010. {
  2011. blitAt(selection,posporx,pospory+i*32);
  2012. }
  2013. //TODO: support for custom portraits
  2014. }
  2015. if (from>0)
  2016. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  2017. else
  2018. blitAt(arrup->ourImages[2].bitmap,arrupp.x,arrupp.y);
  2019. if (items.size()-from>5)
  2020. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  2021. else
  2022. blitAt(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y);
  2023. }