CPlayerInterface.cpp 74 KB

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