CPlayerInterface.cpp 73 KB

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