CPlayerInterface.cpp 72 KB

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