CPlayerInterface.cpp 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  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 CSimpleWindow::show(SDL_Surface * to)
  106. {
  107. if(!to)
  108. to=ekran;
  109. blitAt(bitmap,pos.x,pos.y,to);
  110. }
  111. CSimpleWindow::~CSimpleWindow()
  112. {
  113. if (bitmap)
  114. {
  115. SDL_FreeSurface(bitmap);
  116. bitmap=NULL;
  117. }
  118. }
  119. template <typename T>CSCButton<T>::CSCButton(CDefHandler * img, CIntObject * obj, void(T::*poin)(tribool), T* Delg)
  120. {
  121. ourObj = obj;
  122. delg = Delg;
  123. func = poin;
  124. imgs.resize(1);
  125. for (int i =0; i<img->ourImages.size();i++)
  126. {
  127. imgs[0].push_back(img->ourImages[i].bitmap);
  128. }
  129. pos.w = imgs[0][0]->w;
  130. pos.h = imgs[0][0]->h;
  131. state = 0;
  132. }
  133. template <typename T> void CSCButton<T>::clickLeft (tribool down)
  134. {
  135. if (down)
  136. {
  137. state=1;
  138. }
  139. else
  140. {
  141. state=0;
  142. }
  143. show();
  144. if (delg)
  145. (delg->*func)(down);
  146. pressedL=state;
  147. }
  148. template <typename T> void CSCButton<typename T>::activate()
  149. {
  150. ClickableL::activate();
  151. }
  152. template <typename T> void CSCButton<typename T>::deactivate()
  153. {
  154. ClickableL::deactivate();
  155. }
  156. template <typename T> void CSCButton<typename T>::show(SDL_Surface * to)
  157. {
  158. if (delg) //we blit on our owner's bitmap
  159. {
  160. blitAt(imgs[curimg][state],posr.x,posr.y,delg->bitmap);
  161. updateRect(&genRect(pos.h,pos.w,posr.x,posr.y),delg->bitmap);
  162. }
  163. else
  164. {
  165. CButtonBase::show(to);
  166. }
  167. }
  168. CButtonBase::CButtonBase()
  169. {
  170. curimg=0;
  171. type=-1;
  172. abs=false;
  173. active=false;
  174. ourObj=NULL;
  175. state=0;
  176. }
  177. void CButtonBase::show(SDL_Surface * to)
  178. {
  179. if(!to)
  180. to=ekran;
  181. if (abs)
  182. {
  183. blitAt(imgs[curimg][state],pos.x,pos.y,to);
  184. updateRect(&pos,to);
  185. }
  186. else
  187. {
  188. blitAt(imgs[curimg][state],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y,to);
  189. updateRect(&genRect(pos.h,pos.w,pos.x+ourObj->pos.x,pos.y+ourObj->pos.y),to);
  190. }
  191. }
  192. ClickableL::ClickableL()
  193. {
  194. pressedL=false;
  195. }
  196. void ClickableL::clickLeft(tribool down)
  197. {
  198. if (down)
  199. pressedL=true;
  200. else
  201. pressedL=false;
  202. }
  203. void ClickableL::activate()
  204. {
  205. LOCPLINT->lclickable.push_back(this);
  206. }
  207. void ClickableL::deactivate()
  208. {
  209. LOCPLINT->lclickable.erase
  210. (std::find(LOCPLINT->lclickable.begin(),LOCPLINT->lclickable.end(),this));
  211. }
  212. ClickableR::ClickableR()
  213. {
  214. pressedR=false;
  215. }
  216. void ClickableR::activate()
  217. {
  218. LOCPLINT->rclickable.push_back(this);
  219. }
  220. void ClickableR::deactivate()
  221. {
  222. LOCPLINT->rclickable.erase(std::find(LOCPLINT->rclickable.begin(),LOCPLINT->rclickable.end(),this));
  223. }
  224. void Hoverable::activate()
  225. {
  226. LOCPLINT->hoverable.push_back(this);
  227. }
  228. void Hoverable::deactivate()
  229. {
  230. LOCPLINT->hoverable.erase(std::find(LOCPLINT->hoverable.begin(),LOCPLINT->hoverable.end(),this));
  231. }
  232. void Hoverable::hover(bool on)
  233. {
  234. hovered=on;
  235. }
  236. void KeyInterested::activate()
  237. {
  238. LOCPLINT->keyinterested.push_back(this);
  239. }
  240. void KeyInterested::deactivate()
  241. {
  242. LOCPLINT->
  243. keyinterested.erase(std::find(LOCPLINT->keyinterested.begin(),LOCPLINT->keyinterested.end(),this));
  244. }
  245. void MotionInterested::activate()
  246. {
  247. LOCPLINT->motioninterested.push_back(this);
  248. }
  249. void MotionInterested::deactivate()
  250. {
  251. LOCPLINT->
  252. motioninterested.erase(std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this));
  253. }
  254. CPlayerInterface::CPlayerInterface(int Player, int serial)
  255. {
  256. playerID=Player;
  257. serialID=serial;
  258. CGI->localPlayer = playerID;
  259. human=true;
  260. hInfo = CGI->bitmaph->loadBitmap("HEROQVBK.bmp");
  261. SDL_SetColorKey(hInfo,SDL_SRCCOLORKEY,SDL_MapRGB(hInfo->format,0,255,255));
  262. slotsPos.push_back(std::pair<int,int>(44,82));
  263. slotsPos.push_back(std::pair<int,int>(80,82));
  264. slotsPos.push_back(std::pair<int,int>(116,82));
  265. slotsPos.push_back(std::pair<int,int>(26,131));
  266. slotsPos.push_back(std::pair<int,int>(62,131));
  267. slotsPos.push_back(std::pair<int,int>(98,131));
  268. slotsPos.push_back(std::pair<int,int>(134,131));
  269. luck22 = CGI->spriteh->giveDefEss("ILCK22.DEF");
  270. luck30 = CGI->spriteh->giveDefEss("ILCK30.DEF");
  271. luck42 = CGI->spriteh->giveDefEss("ILCK42.DEF");
  272. luck82 = CGI->spriteh->giveDefEss("ILCK82.DEF");
  273. morale22 = CGI->spriteh->giveDefEss("IMRL22.DEF");
  274. morale30 = CGI->spriteh->giveDefEss("IMRL30.DEF");
  275. morale42 = CGI->spriteh->giveDefEss("IMRL42.DEF");
  276. morale82 = CGI->spriteh->giveDefEss("IMRL82.DEF");
  277. }
  278. void CPlayerInterface::init(ICallback * CB)
  279. {
  280. cb = dynamic_cast<CCallback*>(CB);
  281. CGI->localPlayer = serialID;
  282. adventureInt = new CAdvMapInt(playerID);
  283. }
  284. void CPlayerInterface::yourTurn()
  285. {
  286. makingTurn = true;
  287. CGI->localPlayer = serialID;
  288. unsigned char & animVal = LOCPLINT->adventureInt->anim; //for animations handling
  289. adventureInt->show();
  290. //show rest of things
  291. //initializing framerate keeper
  292. mainFPSmng = new FPSmanager;
  293. SDL_initFramerate(mainFPSmng);
  294. SDL_setFramerate(mainFPSmng, 24);
  295. SDL_Event sEvent;
  296. //framerate keeper initialized
  297. for(;makingTurn;) // main loop
  298. {
  299. CGI->screenh->updateScreen();
  300. LOCPLINT->adventureInt->updateScreen = false;
  301. while (SDL_PollEvent(&sEvent)) //wait for event...
  302. {
  303. handleEvent(&sEvent);
  304. }
  305. ++LOCPLINT->adventureInt->animValHitCount; //for animations
  306. if(LOCPLINT->adventureInt->animValHitCount == 2)
  307. {
  308. LOCPLINT->adventureInt->animValHitCount = 0;
  309. ++animVal;
  310. LOCPLINT->adventureInt->updateScreen = true;
  311. }
  312. if(LOCPLINT->adventureInt->scrollingLeft)
  313. {
  314. if(LOCPLINT->adventureInt->position.x>-Woff)
  315. {
  316. LOCPLINT->adventureInt->position.x--;
  317. LOCPLINT->adventureInt->updateScreen = true;
  318. adventureInt->updateMinimap=true;
  319. }
  320. }
  321. if(LOCPLINT->adventureInt->scrollingRight)
  322. {
  323. if(LOCPLINT->adventureInt->position.x<CGI->ac->map.width-19+4)
  324. {
  325. LOCPLINT->adventureInt->position.x++;
  326. LOCPLINT->adventureInt->updateScreen = true;
  327. adventureInt->updateMinimap=true;
  328. }
  329. }
  330. if(LOCPLINT->adventureInt->scrollingUp)
  331. {
  332. if(LOCPLINT->adventureInt->position.y>-Hoff)
  333. {
  334. LOCPLINT->adventureInt->position.y--;
  335. LOCPLINT->adventureInt->updateScreen = true;
  336. adventureInt->updateMinimap=true;
  337. }
  338. }
  339. if(LOCPLINT->adventureInt->scrollingDown)
  340. {
  341. if(LOCPLINT->adventureInt->position.y<CGI->ac->map.height-18+4)
  342. {
  343. LOCPLINT->adventureInt->position.y++;
  344. LOCPLINT->adventureInt->updateScreen = true;
  345. adventureInt->updateMinimap=true;
  346. }
  347. }
  348. if(LOCPLINT->adventureInt->updateScreen)
  349. {
  350. adventureInt->update();
  351. adventureInt->updateScreen=false;
  352. }
  353. if (LOCPLINT->adventureInt->updateMinimap)
  354. {
  355. adventureInt->minimap.draw();
  356. adventureInt->updateMinimap=false;
  357. }
  358. for(int i=0;i<objsToBlit.size();i++)
  359. objsToBlit[i]->show();
  360. SDL_Delay(5); //give time for other apps
  361. SDL_framerateDelay(mainFPSmng);
  362. }
  363. adventureInt->hide();
  364. }
  365. inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, const int & hid)
  366. {
  367. for(int h=0; h<CGI->mh->ttiles[x][y][z].objects.size(); ++h)
  368. if(CGI->mh->ttiles[x][y][z].objects[h].first->id==hid)
  369. {
  370. CGI->mh->ttiles[x][y][z].objects[h].second.first = r;
  371. break;
  372. }
  373. }
  374. inline void delObjRect(const int & x, const int & y, const int & z, const int & hid)
  375. {
  376. for(int h=0; h<CGI->mh->ttiles[x][y][z].objects.size(); ++h)
  377. if(CGI->mh->ttiles[x][y][z].objects[h].first->id==hid)
  378. {
  379. CGI->mh->ttiles[x][y][z].objects.erase(CGI->mh->ttiles[x][y][z].objects.begin()+h);
  380. break;
  381. }
  382. }
  383. int getDir(int3 src, int3 dst)
  384. {
  385. int ret = -1;
  386. if(dst.x+1 == src.x && dst.y+1 == src.y) //tl
  387. {
  388. ret = 1;
  389. }
  390. else if(dst.x == src.x && dst.y+1 == src.y) //t
  391. {
  392. ret = 2;
  393. }
  394. else if(dst.x-1 == src.x && dst.y+1 == src.y) //tr
  395. {
  396. ret = 3;
  397. }
  398. else if(dst.x-1 == src.x && dst.y == src.y) //r
  399. {
  400. ret = 4;
  401. }
  402. else if(dst.x-1 == src.x && dst.y-1 == src.y) //br
  403. {
  404. ret = 5;
  405. }
  406. else if(dst.x == src.x && dst.y-1 == src.y) //b
  407. {
  408. ret = 6;
  409. }
  410. else if(dst.x+1 == src.x && dst.y-1 == src.y) //bl
  411. {
  412. ret = 7;
  413. }
  414. else if(dst.x+1 == src.x && dst.y == src.y) //l
  415. {
  416. ret = 8;
  417. }
  418. return ret;
  419. }
  420. void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
  421. {
  422. //initializing objects and performing first step of move
  423. CGHeroInstance * ho = details.ho; //object representing this hero
  424. int3 hp = details.src;
  425. if (!details.successful)
  426. {
  427. ho->moveDir = getDir(details.src,details.dst);
  428. ho->isStanding = true;
  429. adventureInt->heroList.draw();
  430. if (adventureInt->terrain.currentPath)
  431. {
  432. delete adventureInt->terrain.currentPath;
  433. adventureInt->terrain.currentPath = NULL;
  434. }
  435. return;
  436. }
  437. if (adventureInt->terrain.currentPath) //&& hero is moving
  438. {
  439. adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
  440. }
  441. int3 buff = details.ho->pos;
  442. buff.x-=11;
  443. buff.y-=9;
  444. buff = repairScreenPos(buff);
  445. LOCPLINT->adventureInt->position = buff; //actualizing screen pos
  446. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  447. {
  448. ho->moveDir = 1;
  449. ho->isStanding = false;
  450. 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>>())));
  451. 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>>())));
  452. 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>>())));
  453. 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>>())));
  454. 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>>())));
  455. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 1), ho->id);
  456. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 1), ho->id);
  457. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 1), ho->id);
  458. 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>>())));
  459. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 33), ho->id);
  460. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 33), ho->id);
  461. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 33), ho->id);
  462. 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);
  463. 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);
  464. 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);
  465. 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);
  466. 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);
  467. 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);
  468. 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);
  469. 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);
  470. 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);
  471. 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);
  472. 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);
  473. 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);
  474. }
  475. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  476. {
  477. ho->moveDir = 2;
  478. ho->isStanding = false;
  479. 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>>())));
  480. 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>>())));
  481. 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>>())));
  482. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1), ho->id);
  483. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1), ho->id);
  484. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1), ho->id);
  485. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33), ho->id);
  486. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33), ho->id);
  487. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33), ho->id);
  488. 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);
  489. 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);
  490. 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);
  491. 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);
  492. 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);
  493. 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);
  494. 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);
  495. 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);
  496. 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);
  497. }
  498. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  499. {
  500. ho->moveDir = 3;
  501. ho->isStanding = false;
  502. 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>>())));
  503. 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>>())));
  504. 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>>())));
  505. 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>>())));
  506. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 1), ho->id);
  507. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 1), ho->id);
  508. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 1), ho->id);
  509. 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>>())));
  510. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 33), ho->id);
  511. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 33), ho->id);
  512. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 33), ho->id);
  513. 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>>())));
  514. 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);
  515. 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);
  516. 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);
  517. 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);
  518. 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);
  519. 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);
  520. 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);
  521. 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);
  522. 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);
  523. 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);
  524. 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);
  525. 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);
  526. }
  527. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  528. {
  529. ho->moveDir = 4;
  530. ho->isStanding = false;
  531. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id);
  532. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id);
  533. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id);
  534. 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>>())));
  535. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 32), ho->id);
  536. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 32), ho->id);
  537. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 32), ho->id);
  538. 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>>())));
  539. 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);
  540. 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);
  541. 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);
  542. 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);
  543. 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);
  544. 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);
  545. 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);
  546. 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);
  547. }
  548. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  549. {
  550. ho->moveDir = 5;
  551. ho->isStanding = false;
  552. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, -1), ho->id);
  553. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, -1), ho->id);
  554. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id);
  555. 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>>())));
  556. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 31), ho->id);
  557. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 31), ho->id);
  558. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 31), ho->id);
  559. 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>>())));
  560. 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>>())));
  561. 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>>())));
  562. 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>>())));
  563. 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>>())));
  564. 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);
  565. 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);
  566. 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);
  567. 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);
  568. 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);
  569. 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);
  570. 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);
  571. 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);
  572. 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);
  573. 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);
  574. 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);
  575. 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);
  576. }
  577. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  578. {
  579. ho->moveDir = 6;
  580. ho->isStanding = false;
  581. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1), ho->id);
  582. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1), ho->id);
  583. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1), ho->id);
  584. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31), ho->id);
  585. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31), ho->id);
  586. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31), ho->id);
  587. 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>>())));
  588. 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>>())));
  589. 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>>())));
  590. 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);
  591. 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);
  592. 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);
  593. 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);
  594. 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);
  595. 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);
  596. 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);
  597. 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);
  598. 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);
  599. }
  600. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  601. {
  602. ho->moveDir = 7;
  603. ho->isStanding = false;
  604. 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>>())));
  605. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id);
  606. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id);
  607. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, -1), ho->id);
  608. 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>>())));
  609. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 31), ho->id);
  610. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 31), ho->id);
  611. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 31), ho->id);
  612. 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>>())));
  613. 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>>())));
  614. 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>>())));
  615. 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>>())));
  616. 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);
  617. 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);
  618. 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);
  619. 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);
  620. 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);
  621. 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);
  622. 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);
  623. 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);
  624. 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);
  625. 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);
  626. 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);
  627. 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);
  628. }
  629. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  630. {
  631. ho->moveDir = 8;
  632. ho->isStanding = false;
  633. 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>>())));
  634. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id);
  635. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id);
  636. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 0), ho->id);
  637. 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>>())));
  638. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 32), ho->id);
  639. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 32), ho->id);
  640. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 32), ho->id);
  641. 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);
  642. 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);
  643. 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);
  644. 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);
  645. 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);
  646. 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);
  647. 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);
  648. 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);
  649. }
  650. //first initializing done
  651. SDL_framerateDelay(mainFPSmng); // after first move
  652. //main moving
  653. for(int i=1; i<32; i+=4)
  654. {
  655. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  656. {
  657. subRect(hp.x-3, hp.y-2, hp.z, genRect(32, 32, -31+i, -31+i), ho->id);
  658. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 1+i, -31+i), ho->id);
  659. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 33+i, -31+i), ho->id);
  660. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 65+i, -31+i), ho->id);
  661. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 1+i), ho->id);
  662. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 1+i), ho->id);
  663. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 1+i), ho->id);
  664. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 1+i), ho->id);
  665. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 33+i), ho->id);
  666. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 33+i), ho->id);
  667. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 33+i), ho->id);
  668. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 33+i), ho->id);
  669. /*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);
  670. 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);
  671. 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);
  672. 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);
  673. 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);
  674. 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);
  675. 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);
  676. 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);
  677. 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);
  678. 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);
  679. 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);
  680. 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);*/
  681. }
  682. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  683. {
  684. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 0, -31+i), ho->id);
  685. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 32, -31+i), ho->id);
  686. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 64, -31+i), ho->id);
  687. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1+i), ho->id);
  688. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1+i), ho->id);
  689. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1+i), ho->id);
  690. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33+i), ho->id);
  691. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33+i), ho->id);
  692. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33+i), ho->id);
  693. /*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);
  694. 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);
  695. 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);
  696. 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);
  697. 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);
  698. 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);
  699. 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);
  700. 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);
  701. 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);*/
  702. }
  703. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  704. {
  705. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, -1-i, -31+i), ho->id);
  706. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 31-i, -31+i), ho->id);
  707. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 63-i, -31+i), ho->id);
  708. subRect(hp.x+1, hp.y-2, hp.z, genRect(32, 32, 95-i, -31+i), ho->id);
  709. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 1+i), ho->id);
  710. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 1+i), ho->id);
  711. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 1+i), ho->id);
  712. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 1+i), ho->id);
  713. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 33+i), ho->id);
  714. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 33+i), ho->id);
  715. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 33+i), ho->id);
  716. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 33+i), ho->id);
  717. /*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);
  718. 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);
  719. 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);
  720. 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);
  721. 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);
  722. 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);
  723. 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);
  724. 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);
  725. 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);
  726. 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);
  727. 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);
  728. 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);*/
  729. }
  730. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  731. {
  732. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 0), ho->id);
  733. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 0), ho->id);
  734. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 0), ho->id);
  735. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 0), ho->id);
  736. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 32), ho->id);
  737. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 32), ho->id);
  738. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 32), ho->id);
  739. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 32), ho->id);
  740. /*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);
  741. 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);
  742. 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);
  743. 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);
  744. 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);
  745. 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);
  746. 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);
  747. 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);*/
  748. }
  749. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  750. {
  751. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, -1-i), ho->id);
  752. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, -1-i), ho->id);
  753. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, -1-i), ho->id);
  754. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, -1-i), ho->id);
  755. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 31-i), ho->id);
  756. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 31-i), ho->id);
  757. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 31-i), ho->id);
  758. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 31-i), ho->id);
  759. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, -1-i, 63-i), ho->id);
  760. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 31-i, 63-i), ho->id);
  761. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 63-i, 63-i), ho->id);
  762. subRect(hp.x+1, hp.y+1, hp.z, genRect(32, 32, 95-i, 63-i), ho->id);
  763. /*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);
  764. 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);
  765. 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);
  766. 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);
  767. 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);
  768. 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);
  769. 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);
  770. 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);
  771. 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);
  772. 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);
  773. 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);
  774. 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);*/
  775. }
  776. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  777. {
  778. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1-i), ho->id);
  779. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1-i), ho->id);
  780. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1-i), ho->id);
  781. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31-i), ho->id);
  782. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31-i), ho->id);
  783. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31-i), ho->id);
  784. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 0, 63-i), ho->id);
  785. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 32, 63-i), ho->id);
  786. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 64, 63-i), ho->id);
  787. /*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);
  788. 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);
  789. 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);
  790. 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);
  791. 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);
  792. 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);
  793. 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);
  794. 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);
  795. 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);*/
  796. }
  797. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  798. {
  799. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, -1-i), ho->id);
  800. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, -1-i), ho->id);
  801. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, -1-i), ho->id);
  802. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, -1-i), ho->id);
  803. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 31-i), ho->id);
  804. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 31-i), ho->id);
  805. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 31-i), ho->id);
  806. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 31-i), ho->id);
  807. subRect(hp.x-3, hp.y+1, hp.z, genRect(32, 32, -31+i, 63-i), ho->id);
  808. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 1+i, 63-i), ho->id);
  809. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 33+i, 63-i), ho->id);
  810. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 65+i, 63-i), ho->id);
  811. /*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);
  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-3][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  816. 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);
  817. 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);
  818. 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);
  819. 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);
  820. 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);
  821. 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);
  822. 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);*/
  823. }
  824. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  825. {
  826. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 0), ho->id);
  827. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 0), ho->id);
  828. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 0), ho->id);
  829. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 0), ho->id);
  830. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 32), ho->id);
  831. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 32), ho->id);
  832. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 32), ho->id);
  833. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 32), ho->id);
  834. /*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);
  835. 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);
  836. 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);
  837. 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);
  838. 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);
  839. 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);
  840. 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);
  841. 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);*/
  842. }
  843. LOCPLINT->adventureInt->update(); //updating screen
  844. CGI->screenh->updateScreen();
  845. LOCPLINT->adventureInt->anim++;
  846. SDL_framerateDelay(mainFPSmng); //for animation purposes
  847. } //for(int i=1; i<32; i+=4)
  848. //main moving done
  849. //finishing move
  850. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  851. {
  852. delObjRect(hp.x, hp.y-2, hp.z, ho->id);
  853. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  854. delObjRect(hp.x, hp.y, hp.z, ho->id);
  855. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  856. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  857. delObjRect(hp.x-3, hp.y, hp.z, ho->id);
  858. }
  859. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  860. {
  861. delObjRect(hp.x, hp.y, hp.z, ho->id);
  862. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  863. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  864. }
  865. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  866. {
  867. delObjRect(hp.x-2, hp.y-2, hp.z, ho->id);
  868. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  869. delObjRect(hp.x+1, hp.y, hp.z, ho->id);
  870. delObjRect(hp.x, hp.y, hp.z, ho->id);
  871. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  872. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  873. }
  874. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  875. {
  876. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  877. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  878. }
  879. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  880. {
  881. delObjRect(hp.x-2, hp.y+1, hp.z, ho->id);
  882. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  883. delObjRect(hp.x+1, hp.y-1, hp.z, ho->id);
  884. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  885. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  886. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  887. }
  888. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  889. {
  890. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  891. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  892. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  893. }
  894. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  895. {
  896. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  897. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  898. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  899. delObjRect(hp.x-3, hp.y-1, hp.z, ho->id);
  900. delObjRect(hp.x, hp.y, hp.z, ho->id);
  901. delObjRect(hp.x, hp.y+1, hp.z, ho->id);
  902. }
  903. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  904. {
  905. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  906. delObjRect(hp.x, hp.y, hp.z, ho->id);
  907. }
  908. ho->pos = details.dst; //copy of hero's position
  909. //ho->moveDir = 0; //move ended
  910. ho->isStanding = true;
  911. //move finished
  912. CGI->mh->recalculateHideVisPosUnderObj(details.ho, true);
  913. adventureInt->minimap.draw();
  914. adventureInt->heroList.draw();
  915. }
  916. void CPlayerInterface::heroKilled(const CGHeroInstance*)
  917. {
  918. }
  919. void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
  920. {
  921. }
  922. SDL_Surface * CPlayerInterface::infoWin(const void * specific) //specific=0 => draws info about selected town/hero //TODO - gdy sie dorobi sensowna hierarchie klas ins. to wywalic tego brzydkiego void*
  923. {
  924. if (specific)
  925. ;//TODO: dorobic, ale w ogole to moze lepiej najpierw zastapic tego voida czym innym
  926. else
  927. {
  928. if (adventureInt->selection.type == HEROI_TYPE)
  929. {
  930. char * buf = new char[10];
  931. SDL_Surface * ret = copySurface(hInfo);
  932. SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
  933. blueToPlayersAdv(ret,playerID,1);
  934. const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection.selected;
  935. printAt(curh->name,75,15,GEOR13,zwykly,ret);
  936. for (int i=0;i<PRIMARY_SKILLS;i++)
  937. {
  938. itoa(curh->primSkills[i],buf,10);
  939. printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
  940. }
  941. for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
  942. {
  943. blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
  944. itoa((*i).second.second,buf,10);
  945. printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
  946. }
  947. blitAt(curh->type->portraitLarge,11,12,ret);
  948. itoa(curh->mana,buf,10);
  949. printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points
  950. delete buf;
  951. blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret);
  952. blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret);
  953. //SDL_SaveBMP(ret,"inf1.bmp");
  954. return ret;
  955. }
  956. else if (adventureInt->selection.type == TOWNI_TYPE)
  957. {
  958. char * buf = new char[10];
  959. SDL_Surface * ret = copySurface(hInfo);
  960. return ret;
  961. }
  962. else
  963. return NULL;
  964. }
  965. return NULL;
  966. }
  967. void CPlayerInterface::handleEvent(SDL_Event *sEvent)
  968. {
  969. current = sEvent;
  970. if(sEvent->type == SDL_MOUSEMOTION)
  971. {
  972. CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
  973. }
  974. if(sEvent->type==SDL_QUIT)
  975. exit(0);
  976. else if (sEvent->type==SDL_KEYDOWN)
  977. {
  978. switch (sEvent->key.keysym.sym)
  979. {
  980. case SDLK_LEFT:
  981. {
  982. LOCPLINT->adventureInt->scrollingLeft = true;
  983. break;
  984. }
  985. case (SDLK_RIGHT):
  986. {
  987. LOCPLINT->adventureInt->scrollingRight = true;
  988. break;
  989. }
  990. case (SDLK_UP):
  991. {
  992. LOCPLINT->adventureInt->scrollingUp = true;
  993. break;
  994. }
  995. case (SDLK_DOWN):
  996. {
  997. LOCPLINT->adventureInt->scrollingDown = true;
  998. break;
  999. }
  1000. case (SDLK_q):
  1001. {
  1002. exit(0);
  1003. break;
  1004. }
  1005. case (SDLK_u):
  1006. {
  1007. adventureInt->underground.clickLeft(true);
  1008. }
  1009. }
  1010. } //keydown end
  1011. else if(sEvent->type==SDL_KEYUP)
  1012. {
  1013. switch (sEvent->key.keysym.sym)
  1014. {
  1015. case SDLK_LEFT:
  1016. {
  1017. LOCPLINT->adventureInt->scrollingLeft = false;
  1018. break;
  1019. }
  1020. case (SDLK_RIGHT):
  1021. {
  1022. LOCPLINT->adventureInt->scrollingRight = false;
  1023. break;
  1024. }
  1025. case (SDLK_UP):
  1026. {
  1027. LOCPLINT->adventureInt->scrollingUp = false;
  1028. break;
  1029. }
  1030. case (SDLK_DOWN):
  1031. {
  1032. LOCPLINT->adventureInt->scrollingDown = false;
  1033. break;
  1034. }
  1035. case (SDLK_u):
  1036. {
  1037. adventureInt->underground.clickLeft(false);
  1038. }
  1039. }
  1040. }//keyup end
  1041. else if(sEvent->type==SDL_MOUSEMOTION)
  1042. {
  1043. for (int i=0; i<hoverable.size();i++)
  1044. {
  1045. if (isItIn(&hoverable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1046. {
  1047. if (!hoverable[i]->hovered)
  1048. hoverable[i]->hover(true);
  1049. }
  1050. else if (hoverable[i]->hovered)
  1051. {
  1052. hoverable[i]->hover(false);
  1053. }
  1054. }
  1055. for(int i=0; i<motioninterested.size();i++)
  1056. {
  1057. if (isItIn(&motioninterested[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1058. {
  1059. motioninterested[i]->mouseMoved(sEvent->motion);
  1060. }
  1061. }
  1062. if(sEvent->motion.x<15)
  1063. {
  1064. LOCPLINT->adventureInt->scrollingLeft = true;
  1065. }
  1066. else
  1067. {
  1068. LOCPLINT->adventureInt->scrollingLeft = false;
  1069. }
  1070. if(sEvent->motion.x>ekran->w-15)
  1071. {
  1072. LOCPLINT->adventureInt->scrollingRight = true;
  1073. }
  1074. else
  1075. {
  1076. LOCPLINT->adventureInt->scrollingRight = false;
  1077. }
  1078. if(sEvent->motion.y<15)
  1079. {
  1080. LOCPLINT->adventureInt->scrollingUp = true;
  1081. }
  1082. else
  1083. {
  1084. LOCPLINT->adventureInt->scrollingUp = false;
  1085. }
  1086. if(sEvent->motion.y>ekran->h-15)
  1087. {
  1088. LOCPLINT->adventureInt->scrollingDown = true;
  1089. }
  1090. else
  1091. {
  1092. LOCPLINT->adventureInt->scrollingDown = false;
  1093. }
  1094. } //mousemotion end
  1095. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1096. {
  1097. LOGE("Left mouse button down1");
  1098. for(int i=0; i<lclickable.size();i++)
  1099. {
  1100. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1101. {
  1102. lclickable[i]->clickLeft(true);
  1103. }
  1104. }
  1105. }
  1106. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1107. {
  1108. for(int i=0; i<lclickable.size();i++)
  1109. {
  1110. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1111. {
  1112. lclickable[i]->clickLeft(false);
  1113. }
  1114. else
  1115. lclickable[i]->clickLeft(boost::logic::indeterminate);
  1116. }
  1117. }
  1118. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1119. {
  1120. for(int i=0; i<rclickable.size();i++)
  1121. {
  1122. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1123. {
  1124. rclickable[i]->clickRight(true);
  1125. }
  1126. }
  1127. }
  1128. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1129. {
  1130. for(int i=0; i<rclickable.size();i++)
  1131. {
  1132. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1133. {
  1134. rclickable[i]->clickRight(false);
  1135. }
  1136. else
  1137. rclickable[i]->clickRight(boost::logic::indeterminate);
  1138. }
  1139. }
  1140. current = NULL;
  1141. } //event end
  1142. int3 CPlayerInterface::repairScreenPos(int3 pos)
  1143. {
  1144. if(pos.x<=-Woff)
  1145. pos.x = -Woff+1;
  1146. if(pos.y<=-Hoff)
  1147. pos.y = -Hoff+1;
  1148. if(pos.x>CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff)
  1149. pos.x = CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff;
  1150. if(pos.y>CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff)
  1151. pos.y = CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff;
  1152. return pos;
  1153. }
  1154. void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)
  1155. {
  1156. if (adventureInt->selection.selected == hero)
  1157. adventureInt->infoBar.draw();
  1158. return;
  1159. }
  1160. void CPlayerInterface::receivedResource(int type, int val)
  1161. {
  1162. adventureInt->resdatabar.draw();
  1163. }
  1164. void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*> & components)
  1165. {
  1166. adventureInt->hide(); //dezaktywacja starego interfejsu
  1167. CInfoWindow * temp = CMessage::genIWindow(text,LOCPLINT->playerID,32,components);
  1168. LOCPLINT->objsToBlit.push_back(temp);
  1169. temp->pos.x=300-(temp->pos.w/2);
  1170. temp->pos.y=300-(temp->pos.h/2);
  1171. temp->okb.pos.x = temp->okb.posr.x + temp->pos.x;
  1172. temp->okb.pos.y = temp->okb.posr.y + temp->pos.y;
  1173. temp->okb.activate();
  1174. for (int i=0;i<temp->components.size();i++)
  1175. {
  1176. temp->components[i]->activate();
  1177. temp->components[i]->pos.x += temp->pos.x;
  1178. temp->components[i]->pos.y += temp->pos.y;
  1179. }
  1180. }
  1181. void CPlayerInterface::removeObjToBlit(IShowable* obj)
  1182. {
  1183. objsToBlit.erase
  1184. (std::find(objsToBlit.begin(),objsToBlit.end(),obj));
  1185. //delete obj;
  1186. }