CPlayerInterface.cpp 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  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. using namespace CSDL_Ext;
  19. class OCM_HLP_CGIN
  20. {
  21. public:
  22. 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
  23. {
  24. return (*a.first)<(*b.first);
  25. }
  26. } ocmptwo_cgin ;
  27. CInfoWindow::CInfoWindow()
  28. :okb(NMessage::ok,NULL,&CInfoWindow::okClicked)
  29. {
  30. okb.ourObj = this;
  31. okb.delg = this;
  32. }
  33. void CInfoWindow::okClicked(tribool down)
  34. {
  35. if (!down)
  36. close();
  37. }
  38. void CInfoWindow::close()
  39. {
  40. for (int i=0;i<components.size();i++)
  41. {
  42. components[i]->deactivate();
  43. delete components[i];
  44. }
  45. components.clear();
  46. okb.deactivate();
  47. SDL_FreeSurface(bitmap);
  48. bitmap = NULL;
  49. LOCPLINT->removeObjToBlit(this);
  50. //delete this;
  51. LOCPLINT->adventureInt->show();
  52. }
  53. CInfoWindow::~CInfoWindow()
  54. {
  55. }
  56. SComponent::SComponent(Etype Type, int Subtype, int Val)
  57. {
  58. std::ostringstream oss;
  59. switch (Type)
  60. {
  61. case primskill:
  62. description = CGI->generaltexth->arraytxt[2+Subtype];
  63. oss << ((Val>0)?("+"):("-")) << Val << " " << CGI->heroh->pskillsn[Subtype];
  64. subtitle = oss.str();
  65. break;
  66. case resource:
  67. description = CGI->generaltexth->allTexts[242];
  68. std::ostringstream oss;
  69. oss << Val;
  70. subtitle = oss.str();
  71. break;
  72. }
  73. type = Type;
  74. subtype = Subtype;
  75. val = Val;
  76. SDL_Surface * temp = getImg();
  77. pos.w = temp->w;
  78. pos.h = temp->h;
  79. }
  80. SDL_Surface * SComponent::getImg()
  81. {
  82. switch (type)
  83. {
  84. case primskill:
  85. return CGI->heroh->pskillsb->ourImages[subtype].bitmap;
  86. break;
  87. case resource:
  88. return CGI->heroh->resources->ourImages[subtype].bitmap;
  89. break;
  90. }
  91. return NULL;
  92. }
  93. void SComponent::clickRight (tribool down)
  94. {
  95. LOCPLINT->adventureInt->handleRightClick(description,down,this);
  96. }
  97. void SComponent::activate()
  98. {
  99. ClickableR::activate();
  100. }
  101. void SComponent::deactivate()
  102. {
  103. ClickableR::deactivate();
  104. }
  105. void CSelectableComponent::clickLeft(tribool down)
  106. {
  107. if (down)
  108. {
  109. select(true);
  110. }
  111. }
  112. CSelectableComponent::CSelectableComponent(Etype Type, int Sub, int Val, SDL_Surface * Border)
  113. :SComponent(Type,Sub,Val)
  114. {
  115. if (Border) //use custom border
  116. {
  117. border = Border;
  118. }
  119. else //we need to draw border
  120. {
  121. SDL_Surface * symb = SComponent::getImg();
  122. border = CSDL_Ext::newSurface(symb->w+2,symb->h+2,symb);
  123. SDL_FillRect(border,NULL,0x00FFFF);
  124. for (int i=0;i<border->w;i++)
  125. {
  126. SDL_PutPixel(border,i,0,239,215,123);
  127. SDL_PutPixel(border,i,(border->h)-1,239,215,123);
  128. }
  129. for (int i=0;i<border->h;i++)
  130. {
  131. SDL_PutPixel(border,0,i,239,215,123);
  132. SDL_PutPixel(border,(border->w)-1,i,239,215,123);
  133. }
  134. SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255));
  135. }
  136. selected = false;
  137. }
  138. void CSelectableComponent::activate()
  139. {
  140. SComponent::activate();
  141. ClickableL::activate();
  142. }
  143. void CSelectableComponent::deactivate()
  144. {
  145. SComponent::deactivate();
  146. ClickableL::deactivate();
  147. }
  148. SDL_Surface * CSelectableComponent::getImg()
  149. {
  150. return myBitmap;
  151. }
  152. void CSelectableComponent::select(bool on)
  153. {
  154. if(on != selected)
  155. {
  156. blitAt(SComponent::getImg(),1,1,myBitmap);
  157. if (on)
  158. {
  159. blitAt(SComponent::getImg(),0,0,border);
  160. }
  161. selected = on;
  162. return;
  163. }
  164. else
  165. {
  166. return;
  167. }
  168. }
  169. void CSimpleWindow::show(SDL_Surface * to)
  170. {
  171. if(!to)
  172. to=ekran;
  173. blitAt(bitmap,pos.x,pos.y,to);
  174. }
  175. CSimpleWindow::~CSimpleWindow()
  176. {
  177. if (bitmap)
  178. {
  179. SDL_FreeSurface(bitmap);
  180. bitmap=NULL;
  181. }
  182. }
  183. void CSelWindow::selectionChange(SComponent * to)
  184. {
  185. for (int i=0;i<components.size();i++)
  186. {
  187. if(components[i]==to)
  188. continue;
  189. CSelectableComponent * pom = dynamic_cast<CSelectableComponent*>(components[i]);
  190. if (!pom)
  191. continue;
  192. pom->select(false);
  193. }
  194. }
  195. void CSelWindow::okClicked(tribool down)
  196. {
  197. if(!down)
  198. close();
  199. }
  200. void CSelWindow::close()
  201. {
  202. //call owner with selection result
  203. CInfoWindow::close();
  204. }
  205. template <typename T>CSCButton<T>::CSCButton(CDefHandler * img, CIntObject * obj, void(T::*poin)(tribool), T* Delg)
  206. {
  207. ourObj = obj;
  208. delg = Delg;
  209. func = poin;
  210. imgs.resize(1);
  211. for (int i =0; i<img->ourImages.size();i++)
  212. {
  213. imgs[0].push_back(img->ourImages[i].bitmap);
  214. }
  215. pos.w = imgs[0][0]->w;
  216. pos.h = imgs[0][0]->h;
  217. state = 0;
  218. }
  219. template <typename T> void CSCButton<T>::clickLeft (tribool down)
  220. {
  221. if (down)
  222. {
  223. state=1;
  224. }
  225. else
  226. {
  227. state=0;
  228. }
  229. show();
  230. if (delg)
  231. (delg->*func)(down);
  232. pressedL=state;
  233. }
  234. template <typename T> void CSCButton<typename T>::activate()
  235. {
  236. ClickableL::activate();
  237. }
  238. template <typename T> void CSCButton<typename T>::deactivate()
  239. {
  240. ClickableL::deactivate();
  241. }
  242. template <typename T> void CSCButton<typename T>::show(SDL_Surface * to)
  243. {
  244. if (delg) //we blit on our owner's bitmap
  245. {
  246. blitAt(imgs[curimg][state],posr.x,posr.y,delg->bitmap);
  247. //updateRect(&genRect(pos.h,pos.w,posr.x,posr.y),delg->bitmap);
  248. }
  249. else
  250. {
  251. CButtonBase::show(to);
  252. }
  253. }
  254. CButtonBase::CButtonBase()
  255. {
  256. curimg=0;
  257. type=-1;
  258. abs=false;
  259. active=false;
  260. ourObj=NULL;
  261. state=0;
  262. }
  263. void CButtonBase::show(SDL_Surface * to)
  264. {
  265. if(!to)
  266. to=ekran;
  267. if (abs)
  268. {
  269. blitAt(imgs[curimg][state],pos.x,pos.y,to);
  270. //updateRect(&pos,to);
  271. }
  272. else
  273. {
  274. blitAt(imgs[curimg][state],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y,to);
  275. //updateRect(&genRect(pos.h,pos.w,pos.x+ourObj->pos.x,pos.y+ourObj->pos.y),to);
  276. }
  277. }
  278. ClickableL::ClickableL()
  279. {
  280. pressedL=false;
  281. }
  282. void ClickableL::clickLeft(tribool down)
  283. {
  284. if (down)
  285. pressedL=true;
  286. else
  287. pressedL=false;
  288. }
  289. void ClickableL::activate()
  290. {
  291. LOCPLINT->lclickable.push_back(this);
  292. }
  293. void ClickableL::deactivate()
  294. {
  295. LOCPLINT->lclickable.erase
  296. (std::find(LOCPLINT->lclickable.begin(),LOCPLINT->lclickable.end(),this));
  297. }
  298. ClickableR::ClickableR()
  299. {
  300. pressedR=false;
  301. }
  302. void ClickableR::activate()
  303. {
  304. LOCPLINT->rclickable.push_back(this);
  305. }
  306. void ClickableR::deactivate()
  307. {
  308. LOCPLINT->rclickable.erase(std::find(LOCPLINT->rclickable.begin(),LOCPLINT->rclickable.end(),this));
  309. }
  310. void Hoverable::activate()
  311. {
  312. LOCPLINT->hoverable.push_back(this);
  313. }
  314. void Hoverable::deactivate()
  315. {
  316. LOCPLINT->hoverable.erase(std::find(LOCPLINT->hoverable.begin(),LOCPLINT->hoverable.end(),this));
  317. }
  318. void Hoverable::hover(bool on)
  319. {
  320. hovered=on;
  321. }
  322. void KeyInterested::activate()
  323. {
  324. LOCPLINT->keyinterested.push_back(this);
  325. }
  326. void KeyInterested::deactivate()
  327. {
  328. LOCPLINT->
  329. keyinterested.erase(std::find(LOCPLINT->keyinterested.begin(),LOCPLINT->keyinterested.end(),this));
  330. }
  331. void MotionInterested::activate()
  332. {
  333. LOCPLINT->motioninterested.push_back(this);
  334. }
  335. void MotionInterested::deactivate()
  336. {
  337. LOCPLINT->
  338. motioninterested.erase(std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this));
  339. }
  340. void TimeInterested::activate()
  341. {
  342. LOCPLINT->timeinterested.push_back(this);
  343. }
  344. void TimeInterested::deactivate()
  345. {
  346. LOCPLINT->
  347. timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),this));
  348. }
  349. CPlayerInterface::CPlayerInterface(int Player, int serial)
  350. {
  351. playerID=Player;
  352. serialID=serial;
  353. CGI->localPlayer = playerID;
  354. human=true;
  355. hInfo = CGI->bitmaph->loadBitmap("HEROQVBK.bmp");
  356. SDL_SetColorKey(hInfo,SDL_SRCCOLORKEY,SDL_MapRGB(hInfo->format,0,255,255));
  357. slotsPos.push_back(std::pair<int,int>(44,82));
  358. slotsPos.push_back(std::pair<int,int>(80,82));
  359. slotsPos.push_back(std::pair<int,int>(116,82));
  360. slotsPos.push_back(std::pair<int,int>(26,131));
  361. slotsPos.push_back(std::pair<int,int>(62,131));
  362. slotsPos.push_back(std::pair<int,int>(98,131));
  363. slotsPos.push_back(std::pair<int,int>(134,131));
  364. luck22 = CGI->spriteh->giveDefEss("ILCK22.DEF");
  365. luck30 = CGI->spriteh->giveDefEss("ILCK30.DEF");
  366. luck42 = CGI->spriteh->giveDefEss("ILCK42.DEF");
  367. luck82 = CGI->spriteh->giveDefEss("ILCK82.DEF");
  368. morale22 = CGI->spriteh->giveDefEss("IMRL22.DEF");
  369. morale30 = CGI->spriteh->giveDefEss("IMRL30.DEF");
  370. morale42 = CGI->spriteh->giveDefEss("IMRL42.DEF");
  371. morale82 = CGI->spriteh->giveDefEss("IMRL82.DEF");
  372. }
  373. void CPlayerInterface::init(ICallback * CB)
  374. {
  375. cb = dynamic_cast<CCallback*>(CB);
  376. CGI->localPlayer = serialID;
  377. adventureInt = new CAdvMapInt(playerID);
  378. std::vector <const CGHeroInstance *> hh = cb->getHeroesInfo(false);
  379. for(int i=0;i<hh.size();i++)
  380. {
  381. SDL_Surface * pom = infoWin(hh[i]);
  382. heroWins.insert(std::pair<int,SDL_Surface*>(hh[i]->subID,pom));
  383. }
  384. }
  385. void CPlayerInterface::yourTurn()
  386. {
  387. makingTurn = true;
  388. CGI->localPlayer = serialID;
  389. unsigned char & animVal = LOCPLINT->adventureInt->anim; //for animations handling
  390. adventureInt->infoBar.newDay(cb->getDate(1));
  391. adventureInt->show();
  392. //show rest of things
  393. //initializing framerate keeper
  394. mainFPSmng = new FPSmanager;
  395. SDL_initFramerate(mainFPSmng);
  396. SDL_setFramerate(mainFPSmng, 24);
  397. SDL_Event sEvent;
  398. //framerate keeper initialized
  399. timeHandler th;
  400. th.getDif();
  401. for(;makingTurn;) // main loop
  402. {
  403. CGI->screenh->updateScreen();
  404. int tv = th.getDif();
  405. for (int i=0;i<timeinterested.size();i++)
  406. {
  407. if (timeinterested[i]->toNextTick>=0)
  408. timeinterested[i]->toNextTick-=tv;
  409. if (timeinterested[i]->toNextTick<0)
  410. timeinterested[i]->tick();
  411. }
  412. LOCPLINT->adventureInt->updateScreen = false;
  413. while (SDL_PollEvent(&sEvent)) //wait for event...
  414. {
  415. handleEvent(&sEvent);
  416. }
  417. ++LOCPLINT->adventureInt->animValHitCount; //for animations
  418. if(LOCPLINT->adventureInt->animValHitCount == 4)
  419. {
  420. LOCPLINT->adventureInt->animValHitCount = 0;
  421. ++animVal;
  422. LOCPLINT->adventureInt->updateScreen = true;
  423. }
  424. if(LOCPLINT->adventureInt->scrollingLeft)
  425. {
  426. if(LOCPLINT->adventureInt->position.x>-Woff)
  427. {
  428. LOCPLINT->adventureInt->position.x--;
  429. LOCPLINT->adventureInt->updateScreen = true;
  430. adventureInt->updateMinimap=true;
  431. }
  432. }
  433. if(LOCPLINT->adventureInt->scrollingRight)
  434. {
  435. if(LOCPLINT->adventureInt->position.x<CGI->ac->map.width-19+4)
  436. {
  437. LOCPLINT->adventureInt->position.x++;
  438. LOCPLINT->adventureInt->updateScreen = true;
  439. adventureInt->updateMinimap=true;
  440. }
  441. }
  442. if(LOCPLINT->adventureInt->scrollingUp)
  443. {
  444. if(LOCPLINT->adventureInt->position.y>-Hoff)
  445. {
  446. LOCPLINT->adventureInt->position.y--;
  447. LOCPLINT->adventureInt->updateScreen = true;
  448. adventureInt->updateMinimap=true;
  449. }
  450. }
  451. if(LOCPLINT->adventureInt->scrollingDown)
  452. {
  453. if(LOCPLINT->adventureInt->position.y<CGI->ac->map.height-18+4)
  454. {
  455. LOCPLINT->adventureInt->position.y++;
  456. LOCPLINT->adventureInt->updateScreen = true;
  457. adventureInt->updateMinimap=true;
  458. }
  459. }
  460. if(LOCPLINT->adventureInt->updateScreen)
  461. {
  462. adventureInt->update();
  463. adventureInt->updateScreen=false;
  464. }
  465. if (LOCPLINT->adventureInt->updateMinimap)
  466. {
  467. adventureInt->minimap.draw();
  468. adventureInt->updateMinimap=false;
  469. }
  470. for(int i=0;i<objsToBlit.size();i++)
  471. objsToBlit[i]->show();
  472. //SDL_Flip(ekran);
  473. CSDL_Ext::update(ekran);
  474. SDL_Delay(5); //give time for other apps
  475. SDL_framerateDelay(mainFPSmng);
  476. }
  477. adventureInt->hide();
  478. }
  479. inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, const int & hid)
  480. {
  481. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  482. for(int h=0; h<hlp.objects.size(); ++h)
  483. if(hlp.objects[h].first->id==hid)
  484. {
  485. hlp.objects[h].second.first = r;
  486. return;
  487. }
  488. }
  489. inline void delObjRect(const int & x, const int & y, const int & z, const int & hid)
  490. {
  491. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  492. for(int h=0; h<hlp.objects.size(); ++h)
  493. if(hlp.objects[h].first->id==hid)
  494. {
  495. hlp.objects.erase(hlp.objects.begin()+h);
  496. return;
  497. }
  498. }
  499. int getDir(int3 src, int3 dst)
  500. {
  501. int ret = -1;
  502. if(dst.x+1 == src.x && dst.y+1 == src.y) //tl
  503. {
  504. ret = 1;
  505. }
  506. else if(dst.x == src.x && dst.y+1 == src.y) //t
  507. {
  508. ret = 2;
  509. }
  510. else if(dst.x-1 == src.x && dst.y+1 == src.y) //tr
  511. {
  512. ret = 3;
  513. }
  514. else if(dst.x-1 == src.x && dst.y == src.y) //r
  515. {
  516. ret = 4;
  517. }
  518. else if(dst.x-1 == src.x && dst.y-1 == src.y) //br
  519. {
  520. ret = 5;
  521. }
  522. else if(dst.x == src.x && dst.y-1 == src.y) //b
  523. {
  524. ret = 6;
  525. }
  526. else if(dst.x+1 == src.x && dst.y-1 == src.y) //bl
  527. {
  528. ret = 7;
  529. }
  530. else if(dst.x+1 == src.x && dst.y == src.y) //l
  531. {
  532. ret = 8;
  533. }
  534. return ret;
  535. }
  536. void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
  537. {
  538. //initializing objects and performing first step of move
  539. CGHeroInstance * ho = details.ho; //object representing this hero
  540. int3 hp = details.src;
  541. if (!details.successful)
  542. {
  543. ho->moveDir = getDir(details.src,details.dst);
  544. ho->isStanding = true;
  545. adventureInt->heroList.draw();
  546. if (adventureInt->terrain.currentPath)
  547. {
  548. delete adventureInt->terrain.currentPath;
  549. adventureInt->terrain.currentPath = NULL;
  550. }
  551. return;
  552. }
  553. if (adventureInt->terrain.currentPath) //&& hero is moving
  554. {
  555. adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
  556. }
  557. int3 buff = details.ho->pos;
  558. buff.x-=11;
  559. buff.y-=9;
  560. buff = repairScreenPos(buff);
  561. LOCPLINT->adventureInt->position = buff; //actualizing screen pos
  562. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  563. {
  564. ho->moveDir = 1;
  565. ho->isStanding = false;
  566. 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>>())));
  567. 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>>())));
  568. 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>>())));
  569. 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>>())));
  570. 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>>())));
  571. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 1), ho->id);
  572. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 1), ho->id);
  573. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 1), ho->id);
  574. 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>>())));
  575. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 33), ho->id);
  576. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 33), ho->id);
  577. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 33), ho->id);
  578. 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);
  579. 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);
  580. 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);
  581. 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);
  582. 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);
  583. //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);
  584. //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);
  585. //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);
  586. 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);
  587. //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);
  588. //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);
  589. //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);
  590. }
  591. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  592. {
  593. ho->moveDir = 2;
  594. ho->isStanding = false;
  595. 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>>())));
  596. 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>>())));
  597. 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>>())));
  598. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1), ho->id);
  599. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1), ho->id);
  600. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1), ho->id);
  601. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33), ho->id);
  602. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33), ho->id);
  603. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33), ho->id);
  604. 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);
  605. 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);
  606. 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);
  607. //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);
  608. //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);
  609. //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);
  610. //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);
  611. //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);
  612. //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);
  613. }
  614. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  615. {
  616. ho->moveDir = 3;
  617. ho->isStanding = false;
  618. 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>>())));
  619. 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>>())));
  620. 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>>())));
  621. 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>>())));
  622. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 1), ho->id);
  623. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 1), ho->id);
  624. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 1), ho->id);
  625. 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>>())));
  626. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 33), ho->id);
  627. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 33), ho->id);
  628. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 33), ho->id);
  629. 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>>())));
  630. 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);
  631. 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);
  632. 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);
  633. 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);
  634. //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);
  635. //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);
  636. //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);
  637. 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);
  638. //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);
  639. //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);
  640. //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);
  641. 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);
  642. }
  643. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  644. {
  645. ho->moveDir = 4;
  646. ho->isStanding = false;
  647. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id);
  648. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id);
  649. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id);
  650. 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>>())));
  651. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 32), ho->id);
  652. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 32), ho->id);
  653. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 32), ho->id);
  654. 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>>())));
  655. //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);
  656. //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);
  657. //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);
  658. 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);
  659. //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);
  660. //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);
  661. //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);
  662. 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);
  663. }
  664. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  665. {
  666. ho->moveDir = 5;
  667. ho->isStanding = false;
  668. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, -1), ho->id);
  669. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, -1), ho->id);
  670. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id);
  671. 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>>())));
  672. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 31), ho->id);
  673. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 31), ho->id);
  674. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 31), ho->id);
  675. 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>>())));
  676. 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>>())));
  677. 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>>())));
  678. 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>>())));
  679. 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>>())));
  680. //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);
  681. //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);
  682. //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);
  683. 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);
  684. //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);
  685. //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);
  686. //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);
  687. 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);
  688. 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);
  689. 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);
  690. 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);
  691. 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);
  692. }
  693. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  694. {
  695. ho->moveDir = 6;
  696. ho->isStanding = false;
  697. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1), ho->id);
  698. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1), ho->id);
  699. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1), ho->id);
  700. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31), ho->id);
  701. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31), ho->id);
  702. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31), ho->id);
  703. 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>>())));
  704. 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>>())));
  705. 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>>())));
  706. //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);
  707. //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);
  708. //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);
  709. //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);
  710. //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);
  711. //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);
  712. 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);
  713. 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);
  714. 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);
  715. }
  716. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  717. {
  718. ho->moveDir = 7;
  719. ho->isStanding = false;
  720. 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>>())));
  721. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id);
  722. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id);
  723. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, -1), ho->id);
  724. 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>>())));
  725. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 31), ho->id);
  726. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 31), ho->id);
  727. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 31), ho->id);
  728. 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>>())));
  729. 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>>())));
  730. 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>>())));
  731. 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>>())));
  732. 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);
  733. //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);
  734. //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);
  735. //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);
  736. 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);
  737. //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);
  738. //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);
  739. //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);
  740. 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);
  741. 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);
  742. 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);
  743. 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);
  744. }
  745. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  746. {
  747. ho->moveDir = 8;
  748. ho->isStanding = false;
  749. 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>>())));
  750. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id);
  751. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id);
  752. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 0), ho->id);
  753. 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>>())));
  754. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 32), ho->id);
  755. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 32), ho->id);
  756. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 32), ho->id);
  757. 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);
  758. //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);
  759. //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);
  760. //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);
  761. 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);
  762. //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);
  763. //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);
  764. //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);
  765. }
  766. //first initializing done
  767. SDL_framerateDelay(mainFPSmng); // after first move
  768. //main moving
  769. for(int i=1; i<32; i+=4)
  770. {
  771. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  772. {
  773. subRect(hp.x-3, hp.y-2, hp.z, genRect(32, 32, -31+i, -31+i), ho->id);
  774. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 1+i, -31+i), ho->id);
  775. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 33+i, -31+i), ho->id);
  776. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 65+i, -31+i), ho->id);
  777. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 1+i), ho->id);
  778. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 1+i), ho->id);
  779. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 1+i), ho->id);
  780. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 1+i), ho->id);
  781. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 33+i), ho->id);
  782. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 33+i), ho->id);
  783. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 33+i), ho->id);
  784. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 33+i), ho->id);
  785. /*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);
  786. 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);
  787. 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);
  788. 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);
  789. 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);
  790. 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);
  791. 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);
  792. 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);
  793. 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);
  794. 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);
  795. 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);
  796. 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);*/
  797. }
  798. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  799. {
  800. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 0, -31+i), ho->id);
  801. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 32, -31+i), ho->id);
  802. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 64, -31+i), ho->id);
  803. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1+i), ho->id);
  804. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1+i), ho->id);
  805. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1+i), ho->id);
  806. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33+i), ho->id);
  807. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33+i), ho->id);
  808. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33+i), ho->id);
  809. /*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);
  810. 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);
  811. 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);
  812. 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);
  813. 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);
  814. 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);
  815. 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);
  816. 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);
  817. 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);*/
  818. }
  819. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  820. {
  821. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, -1-i, -31+i), ho->id);
  822. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 31-i, -31+i), ho->id);
  823. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 63-i, -31+i), ho->id);
  824. subRect(hp.x+1, hp.y-2, hp.z, genRect(32, 32, 95-i, -31+i), ho->id);
  825. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 1+i), ho->id);
  826. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 1+i), ho->id);
  827. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 1+i), ho->id);
  828. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 1+i), ho->id);
  829. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 33+i), ho->id);
  830. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 33+i), ho->id);
  831. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 33+i), ho->id);
  832. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 33+i), ho->id);
  833. /*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);
  834. 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);
  835. 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);
  836. 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);
  837. 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);
  838. 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);
  839. 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);
  840. 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);
  841. 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);
  842. 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);
  843. 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);
  844. 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);*/
  845. }
  846. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  847. {
  848. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 0), ho->id);
  849. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 0), ho->id);
  850. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 0), ho->id);
  851. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 0), ho->id);
  852. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 32), ho->id);
  853. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 32), ho->id);
  854. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 32), ho->id);
  855. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 32), ho->id);
  856. /*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);
  857. 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);
  858. 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);
  859. 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);
  860. 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);
  861. 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);
  862. 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);
  863. 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);*/
  864. }
  865. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  866. {
  867. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, -1-i), ho->id);
  868. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, -1-i), ho->id);
  869. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, -1-i), ho->id);
  870. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, -1-i), ho->id);
  871. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 31-i), ho->id);
  872. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 31-i), ho->id);
  873. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 31-i), ho->id);
  874. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 31-i), ho->id);
  875. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, -1-i, 63-i), ho->id);
  876. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 31-i, 63-i), ho->id);
  877. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 63-i, 63-i), ho->id);
  878. subRect(hp.x+1, hp.y+1, hp.z, genRect(32, 32, 95-i, 63-i), ho->id);
  879. /*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);
  880. 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);
  881. 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);
  882. 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);
  883. 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);
  884. 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);
  885. 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);
  886. 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);
  887. 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);
  888. 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);
  889. 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);
  890. 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);*/
  891. }
  892. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  893. {
  894. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1-i), ho->id);
  895. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1-i), ho->id);
  896. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1-i), ho->id);
  897. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31-i), ho->id);
  898. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31-i), ho->id);
  899. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31-i), ho->id);
  900. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 0, 63-i), ho->id);
  901. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 32, 63-i), ho->id);
  902. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 64, 63-i), ho->id);
  903. /*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);
  904. 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);
  905. 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);
  906. 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);
  907. 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);
  908. 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);
  909. 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);
  910. 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);
  911. 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);*/
  912. }
  913. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  914. {
  915. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, -1-i), ho->id);
  916. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, -1-i), ho->id);
  917. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, -1-i), ho->id);
  918. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, -1-i), ho->id);
  919. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 31-i), ho->id);
  920. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 31-i), ho->id);
  921. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 31-i), ho->id);
  922. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 31-i), ho->id);
  923. subRect(hp.x-3, hp.y+1, hp.z, genRect(32, 32, -31+i, 63-i), ho->id);
  924. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 1+i, 63-i), ho->id);
  925. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 33+i, 63-i), ho->id);
  926. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 65+i, 63-i), ho->id);
  927. /*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);
  928. 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);
  929. 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);
  930. 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);
  931. 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);
  932. 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);
  933. 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);
  934. 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);
  935. 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);
  936. 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);
  937. 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);
  938. 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);*/
  939. }
  940. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  941. {
  942. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 0), ho->id);
  943. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 0), ho->id);
  944. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 0), ho->id);
  945. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 0), ho->id);
  946. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 32), ho->id);
  947. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 32), ho->id);
  948. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 32), ho->id);
  949. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 32), ho->id);
  950. /*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);
  951. 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);
  952. 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);
  953. 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);
  954. 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);
  955. 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);
  956. 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);
  957. 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);*/
  958. }
  959. LOCPLINT->adventureInt->update(); //updating screen
  960. CSDL_Ext::update(ekran);
  961. CGI->screenh->updateScreen();
  962. LOCPLINT->adventureInt->anim++;
  963. adventureInt->animValHitCount=0;
  964. SDL_framerateDelay(mainFPSmng); //for animation purposes
  965. } //for(int i=1; i<32; i+=4)
  966. //main moving done
  967. //finishing move
  968. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  969. {
  970. delObjRect(hp.x, hp.y-2, hp.z, ho->id);
  971. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  972. delObjRect(hp.x, hp.y, hp.z, ho->id);
  973. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  974. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  975. delObjRect(hp.x-3, hp.y, hp.z, ho->id);
  976. }
  977. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  978. {
  979. delObjRect(hp.x, hp.y, hp.z, ho->id);
  980. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  981. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  982. }
  983. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  984. {
  985. delObjRect(hp.x-2, hp.y-2, hp.z, ho->id);
  986. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  987. delObjRect(hp.x+1, hp.y, hp.z, ho->id);
  988. delObjRect(hp.x, hp.y, hp.z, ho->id);
  989. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  990. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  991. }
  992. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  993. {
  994. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  995. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  996. }
  997. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  998. {
  999. delObjRect(hp.x-2, hp.y+1, hp.z, ho->id);
  1000. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1001. delObjRect(hp.x+1, hp.y-1, hp.z, ho->id);
  1002. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1003. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1004. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1005. }
  1006. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1007. {
  1008. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1009. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1010. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1011. }
  1012. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1013. {
  1014. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1015. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1016. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1017. delObjRect(hp.x-3, hp.y-1, hp.z, ho->id);
  1018. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1019. delObjRect(hp.x, hp.y+1, hp.z, ho->id);
  1020. }
  1021. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1022. {
  1023. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1024. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1025. }
  1026. ho->pos = details.dst; //copy of hero's position
  1027. //ho->moveDir = 0; //move ended
  1028. ho->isStanding = true;
  1029. //move finished
  1030. CGI->mh->recalculateHideVisPosUnderObj(details.ho, true);
  1031. adventureInt->minimap.draw();
  1032. adventureInt->heroList.updateMove(ho);
  1033. }
  1034. void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
  1035. {
  1036. heroWins.erase(hero->ID);
  1037. }
  1038. void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
  1039. {
  1040. if(heroWins.find(hero->subID)==heroWins.end())
  1041. heroWins.insert(std::pair<int,SDL_Surface*>(hero->subID,infoWin(hero)));
  1042. }
  1043. SDL_Surface * CPlayerInterface::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to)
  1044. {
  1045. char * buf = new char[10];
  1046. for (int i=from;i<to;i++)
  1047. {
  1048. itoa(curh->primSkills[i],buf,10);
  1049. printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
  1050. }
  1051. delete buf;
  1052. return ret;
  1053. }
  1054. SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh)
  1055. {
  1056. char * buf = new char[10];
  1057. SDL_Surface * ret = copySurface(hInfo);
  1058. SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
  1059. blueToPlayersAdv(ret,playerID,1);
  1060. printAt(curh->name,75,15,GEOR13,zwykly,ret);
  1061. drawPrimarySkill(curh, ret);
  1062. for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
  1063. {
  1064. blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
  1065. itoa((*i).second.second,buf,10);
  1066. printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
  1067. }
  1068. blitAt(curh->type->portraitLarge,11,12,ret);
  1069. itoa(curh->mana,buf,10);
  1070. printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points
  1071. delete buf;
  1072. blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret);
  1073. blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret);
  1074. //SDL_SaveBMP(ret,"inf1.bmp");
  1075. return ret;
  1076. }
  1077. SDL_Surface * CPlayerInterface::drawTownInfoWin(const CGTownInstance * curh)
  1078. {
  1079. return NULL;
  1080. }
  1081. SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //specific=0 => draws info about selected town/hero
  1082. {
  1083. if (specific)
  1084. {
  1085. switch (specific->ID)
  1086. {
  1087. case 34:
  1088. return drawHeroInfoWin(dynamic_cast<const CGHeroInstance*>(specific));
  1089. break;
  1090. default:
  1091. return NULL;
  1092. break;
  1093. }
  1094. }
  1095. else
  1096. {
  1097. switch (adventureInt->selection.type)
  1098. {
  1099. case HEROI_TYPE:
  1100. {
  1101. const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection.selected;
  1102. return drawHeroInfoWin(curh);
  1103. }
  1104. case TOWNI_TYPE:
  1105. {
  1106. return drawTownInfoWin((const CGTownInstance *)adventureInt->selection.selected);
  1107. }
  1108. default:
  1109. return NULL;
  1110. }
  1111. }
  1112. return NULL;
  1113. }
  1114. void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent)
  1115. {
  1116. for (int i=0; i<hoverable.size();i++)
  1117. {
  1118. if (isItIn(&hoverable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1119. {
  1120. if (!hoverable[i]->hovered)
  1121. hoverable[i]->hover(true);
  1122. }
  1123. else if (hoverable[i]->hovered)
  1124. {
  1125. hoverable[i]->hover(false);
  1126. }
  1127. }
  1128. for(int i=0; i<motioninterested.size();i++)
  1129. {
  1130. if (isItIn(&motioninterested[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1131. {
  1132. motioninterested[i]->mouseMoved(sEvent->motion);
  1133. }
  1134. }
  1135. if(sEvent->motion.x<15)
  1136. {
  1137. LOCPLINT->adventureInt->scrollingLeft = true;
  1138. }
  1139. else
  1140. {
  1141. LOCPLINT->adventureInt->scrollingLeft = false;
  1142. }
  1143. if(sEvent->motion.x>ekran->w-15)
  1144. {
  1145. LOCPLINT->adventureInt->scrollingRight = true;
  1146. }
  1147. else
  1148. {
  1149. LOCPLINT->adventureInt->scrollingRight = false;
  1150. }
  1151. if(sEvent->motion.y<15)
  1152. {
  1153. LOCPLINT->adventureInt->scrollingUp = true;
  1154. }
  1155. else
  1156. {
  1157. LOCPLINT->adventureInt->scrollingUp = false;
  1158. }
  1159. if(sEvent->motion.y>ekran->h-15)
  1160. {
  1161. LOCPLINT->adventureInt->scrollingDown = true;
  1162. }
  1163. else
  1164. {
  1165. LOCPLINT->adventureInt->scrollingDown = false;
  1166. }
  1167. }
  1168. void CPlayerInterface::handleKeyUp(SDL_Event *sEvent)
  1169. {
  1170. switch (sEvent->key.keysym.sym)
  1171. {
  1172. case SDLK_LEFT:
  1173. {
  1174. LOCPLINT->adventureInt->scrollingLeft = false;
  1175. break;
  1176. }
  1177. case (SDLK_RIGHT):
  1178. {
  1179. LOCPLINT->adventureInt->scrollingRight = false;
  1180. break;
  1181. }
  1182. case (SDLK_UP):
  1183. {
  1184. LOCPLINT->adventureInt->scrollingUp = false;
  1185. break;
  1186. }
  1187. case (SDLK_DOWN):
  1188. {
  1189. LOCPLINT->adventureInt->scrollingDown = false;
  1190. break;
  1191. }
  1192. case (SDLK_u):
  1193. {
  1194. adventureInt->underground.clickLeft(false);
  1195. break;
  1196. }
  1197. case (SDLK_m):
  1198. {
  1199. adventureInt->moveHero.clickLeft(false);
  1200. break;
  1201. }
  1202. case (SDLK_e):
  1203. {
  1204. adventureInt->endTurn.clickLeft(false);
  1205. break;
  1206. }
  1207. }
  1208. }
  1209. void CPlayerInterface::handleKeyDown(SDL_Event *sEvent)
  1210. {
  1211. switch (sEvent->key.keysym.sym)
  1212. {
  1213. case SDLK_LEFT:
  1214. {
  1215. LOCPLINT->adventureInt->scrollingLeft = true;
  1216. break;
  1217. }
  1218. case (SDLK_RIGHT):
  1219. {
  1220. LOCPLINT->adventureInt->scrollingRight = true;
  1221. break;
  1222. }
  1223. case (SDLK_UP):
  1224. {
  1225. LOCPLINT->adventureInt->scrollingUp = true;
  1226. break;
  1227. }
  1228. case (SDLK_DOWN):
  1229. {
  1230. LOCPLINT->adventureInt->scrollingDown = true;
  1231. break;
  1232. }
  1233. case (SDLK_q):
  1234. {
  1235. exit(0);
  1236. break;
  1237. }
  1238. case (SDLK_u):
  1239. {
  1240. adventureInt->underground.clickLeft(true);
  1241. break;
  1242. }
  1243. case (SDLK_m):
  1244. {
  1245. adventureInt->moveHero.clickLeft(true);
  1246. break;
  1247. }
  1248. case (SDLK_e):
  1249. {
  1250. adventureInt->endTurn.clickLeft(true);
  1251. break;
  1252. }
  1253. }
  1254. }
  1255. void CPlayerInterface::handleEvent(SDL_Event *sEvent)
  1256. {
  1257. current = sEvent;
  1258. if(sEvent->type == SDL_MOUSEMOTION)
  1259. {
  1260. CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
  1261. }
  1262. if(sEvent->type==SDL_QUIT)
  1263. exit(0);
  1264. else if (sEvent->type==SDL_KEYDOWN)
  1265. {
  1266. handleKeyDown(sEvent);
  1267. } //keydown end
  1268. else if(sEvent->type==SDL_KEYUP)
  1269. {
  1270. handleKeyUp(sEvent);
  1271. }//keyup end
  1272. else if(sEvent->type==SDL_MOUSEMOTION)
  1273. {
  1274. handleMouseMotion(sEvent);
  1275. } //mousemotion end
  1276. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1277. {
  1278. LOGE("Left mouse button down1");
  1279. for(int i=0; i<lclickable.size();i++)
  1280. {
  1281. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1282. {
  1283. lclickable[i]->clickLeft(true);
  1284. }
  1285. }
  1286. }
  1287. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1288. {
  1289. for(int i=0; i<lclickable.size();i++)
  1290. {
  1291. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1292. {
  1293. lclickable[i]->clickLeft(false);
  1294. }
  1295. else
  1296. lclickable[i]->clickLeft(boost::logic::indeterminate);
  1297. }
  1298. }
  1299. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1300. {
  1301. for(int i=0; i<rclickable.size();i++)
  1302. {
  1303. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1304. {
  1305. rclickable[i]->clickRight(true);
  1306. }
  1307. }
  1308. }
  1309. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1310. {
  1311. for(int i=0; i<rclickable.size();i++)
  1312. {
  1313. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1314. {
  1315. rclickable[i]->clickRight(false);
  1316. }
  1317. else
  1318. rclickable[i]->clickRight(boost::logic::indeterminate);
  1319. }
  1320. }
  1321. current = NULL;
  1322. } //event end
  1323. int3 CPlayerInterface::repairScreenPos(int3 pos)
  1324. {
  1325. if(pos.x<=-Woff)
  1326. pos.x = -Woff+1;
  1327. if(pos.y<=-Hoff)
  1328. pos.y = -Hoff+1;
  1329. if(pos.x>CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff)
  1330. pos.x = CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff;
  1331. if(pos.y>CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff)
  1332. pos.y = CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff;
  1333. return pos;
  1334. }
  1335. void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)
  1336. {
  1337. SDL_FreeSurface(heroWins[hero->subID]);//TODO: moznaby zmieniac jedynie fragment bitmapy zwiazany z dana umiejetnoscia
  1338. heroWins[hero->subID] = infoWin(hero); //a nie przerysowywac calosc. Troche roboty, obecnie chyba nie wartej swieczki.
  1339. if (adventureInt->selection.selected == hero)
  1340. adventureInt->infoBar.draw();
  1341. return;
  1342. }
  1343. void CPlayerInterface::receivedResource(int type, int val)
  1344. {
  1345. adventureInt->resdatabar.draw();
  1346. }
  1347. void CPlayerInterface::showComp(SComponent comp)
  1348. {
  1349. adventureInt->infoBar.showComp(&comp,4000);
  1350. }
  1351. void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*> & components)
  1352. {
  1353. adventureInt->hide(); //dezaktywacja starego interfejsu
  1354. CInfoWindow * temp = CMessage::genIWindow(text,LOCPLINT->playerID,32,components);
  1355. LOCPLINT->objsToBlit.push_back(temp);
  1356. temp->pos.x=300-(temp->pos.w/2);
  1357. temp->pos.y=300-(temp->pos.h/2);
  1358. temp->okb.pos.x = temp->okb.posr.x + temp->pos.x;
  1359. temp->okb.pos.y = temp->okb.posr.y + temp->pos.y;
  1360. temp->okb.activate();
  1361. for (int i=0;i<temp->components.size();i++)
  1362. {
  1363. temp->components[i]->activate();
  1364. temp->components[i]->pos.x += temp->pos.x;
  1365. temp->components[i]->pos.y += temp->pos.y;
  1366. }
  1367. }
  1368. void CPlayerInterface::removeObjToBlit(IShowable* obj)
  1369. {
  1370. objsToBlit.erase
  1371. (std::find(objsToBlit.begin(),objsToBlit.end(),obj));
  1372. //delete obj;
  1373. }
  1374. void CPlayerInterface::tileRevealed(int3 pos)
  1375. {
  1376. adventureInt->minimap.showTile(pos);
  1377. }
  1378. void CPlayerInterface::tileHidden(int3 pos)
  1379. {
  1380. adventureInt->minimap.hideTile(pos);
  1381. }