CPlayerInterface.cpp 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  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_Flip(ekran);
  361. SDL_Delay(5); //give time for other apps
  362. SDL_framerateDelay(mainFPSmng);
  363. }
  364. adventureInt->hide();
  365. }
  366. inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, const int & hid)
  367. {
  368. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  369. for(int h=0; h<hlp.objects.size(); ++h)
  370. if(hlp.objects[h].first->id==hid)
  371. {
  372. hlp.objects[h].second.first = r;
  373. return;
  374. }
  375. }
  376. inline void delObjRect(const int & x, const int & y, const int & z, const int & hid)
  377. {
  378. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  379. for(int h=0; h<hlp.objects.size(); ++h)
  380. if(hlp.objects[h].first->id==hid)
  381. {
  382. hlp.objects.erase(hlp.objects.begin()+h);
  383. return;
  384. }
  385. }
  386. int getDir(int3 src, int3 dst)
  387. {
  388. int ret = -1;
  389. if(dst.x+1 == src.x && dst.y+1 == src.y) //tl
  390. {
  391. ret = 1;
  392. }
  393. else if(dst.x == src.x && dst.y+1 == src.y) //t
  394. {
  395. ret = 2;
  396. }
  397. else if(dst.x-1 == src.x && dst.y+1 == src.y) //tr
  398. {
  399. ret = 3;
  400. }
  401. else if(dst.x-1 == src.x && dst.y == src.y) //r
  402. {
  403. ret = 4;
  404. }
  405. else if(dst.x-1 == src.x && dst.y-1 == src.y) //br
  406. {
  407. ret = 5;
  408. }
  409. else if(dst.x == src.x && dst.y-1 == src.y) //b
  410. {
  411. ret = 6;
  412. }
  413. else if(dst.x+1 == src.x && dst.y-1 == src.y) //bl
  414. {
  415. ret = 7;
  416. }
  417. else if(dst.x+1 == src.x && dst.y == src.y) //l
  418. {
  419. ret = 8;
  420. }
  421. return ret;
  422. }
  423. void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
  424. {
  425. //initializing objects and performing first step of move
  426. CGHeroInstance * ho = details.ho; //object representing this hero
  427. int3 hp = details.src;
  428. if (!details.successful)
  429. {
  430. ho->moveDir = getDir(details.src,details.dst);
  431. ho->isStanding = true;
  432. adventureInt->heroList.draw();
  433. if (adventureInt->terrain.currentPath)
  434. {
  435. delete adventureInt->terrain.currentPath;
  436. adventureInt->terrain.currentPath = NULL;
  437. }
  438. return;
  439. }
  440. if (adventureInt->terrain.currentPath) //&& hero is moving
  441. {
  442. adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
  443. }
  444. int3 buff = details.ho->pos;
  445. buff.x-=11;
  446. buff.y-=9;
  447. buff = repairScreenPos(buff);
  448. LOCPLINT->adventureInt->position = buff; //actualizing screen pos
  449. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  450. {
  451. ho->moveDir = 1;
  452. ho->isStanding = false;
  453. 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>>())));
  454. 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>>())));
  455. 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>>())));
  456. 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>>())));
  457. 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>>())));
  458. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 1), ho->id);
  459. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 1), ho->id);
  460. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 1), ho->id);
  461. 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>>())));
  462. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 33), ho->id);
  463. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 33), ho->id);
  464. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 33), ho->id);
  465. 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);
  466. 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);
  467. 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);
  468. 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);
  469. 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);
  470. //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);
  471. //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);
  472. //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);
  473. 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);
  474. //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);
  475. //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);
  476. //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);
  477. }
  478. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  479. {
  480. ho->moveDir = 2;
  481. ho->isStanding = false;
  482. 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>>())));
  483. 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>>())));
  484. 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>>())));
  485. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1), ho->id);
  486. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1), ho->id);
  487. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1), ho->id);
  488. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33), ho->id);
  489. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33), ho->id);
  490. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33), ho->id);
  491. 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);
  492. 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);
  493. 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);
  494. //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);
  495. //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);
  496. //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);
  497. //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);
  498. //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);
  499. //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);
  500. }
  501. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  502. {
  503. ho->moveDir = 3;
  504. ho->isStanding = false;
  505. 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>>())));
  506. 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>>())));
  507. 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>>())));
  508. 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>>())));
  509. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 1), ho->id);
  510. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 1), ho->id);
  511. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 1), ho->id);
  512. 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>>())));
  513. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 33), ho->id);
  514. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 33), ho->id);
  515. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 33), ho->id);
  516. 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>>())));
  517. 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);
  518. 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);
  519. 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);
  520. 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);
  521. //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);
  522. //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);
  523. //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);
  524. 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);
  525. //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);
  526. //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);
  527. //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);
  528. 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);
  529. }
  530. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  531. {
  532. ho->moveDir = 4;
  533. ho->isStanding = false;
  534. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id);
  535. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id);
  536. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id);
  537. 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>>())));
  538. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 32), ho->id);
  539. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 32), ho->id);
  540. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 32), ho->id);
  541. 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>>())));
  542. //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);
  543. //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);
  544. //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);
  545. 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);
  546. //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);
  547. //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);
  548. //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);
  549. 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);
  550. }
  551. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  552. {
  553. ho->moveDir = 5;
  554. ho->isStanding = false;
  555. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, -1), ho->id);
  556. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, -1), ho->id);
  557. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id);
  558. 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>>())));
  559. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 31), ho->id);
  560. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 31), ho->id);
  561. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 31), ho->id);
  562. 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>>())));
  563. 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>>())));
  564. 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>>())));
  565. 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>>())));
  566. 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>>())));
  567. //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);
  568. //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);
  569. //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);
  570. 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);
  571. //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);
  572. //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);
  573. //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);
  574. 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);
  575. 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);
  576. 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);
  577. 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);
  578. 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);
  579. }
  580. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  581. {
  582. ho->moveDir = 6;
  583. ho->isStanding = false;
  584. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1), ho->id);
  585. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1), ho->id);
  586. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1), ho->id);
  587. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31), ho->id);
  588. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31), ho->id);
  589. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31), ho->id);
  590. 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>>())));
  591. 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>>())));
  592. 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>>())));
  593. //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);
  594. //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);
  595. //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);
  596. //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);
  597. //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);
  598. //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);
  599. 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);
  600. 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);
  601. 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);
  602. }
  603. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  604. {
  605. ho->moveDir = 7;
  606. ho->isStanding = false;
  607. 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>>())));
  608. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id);
  609. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id);
  610. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, -1), ho->id);
  611. 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>>())));
  612. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 31), ho->id);
  613. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 31), ho->id);
  614. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 31), ho->id);
  615. 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>>())));
  616. 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>>())));
  617. 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>>())));
  618. 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>>())));
  619. 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);
  620. //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);
  621. //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);
  622. //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);
  623. 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);
  624. //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);
  625. //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);
  626. //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);
  627. 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);
  628. 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);
  629. 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);
  630. 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);
  631. }
  632. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  633. {
  634. ho->moveDir = 8;
  635. ho->isStanding = false;
  636. 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>>())));
  637. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id);
  638. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id);
  639. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 0), ho->id);
  640. 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>>())));
  641. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 32), ho->id);
  642. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 32), ho->id);
  643. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 32), ho->id);
  644. 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);
  645. //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);
  646. //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);
  647. //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);
  648. 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);
  649. //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);
  650. //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);
  651. //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);
  652. }
  653. //first initializing done
  654. SDL_framerateDelay(mainFPSmng); // after first move
  655. //main moving
  656. for(int i=1; i<32; i+=4)
  657. {
  658. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  659. {
  660. subRect(hp.x-3, hp.y-2, hp.z, genRect(32, 32, -31+i, -31+i), ho->id);
  661. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 1+i, -31+i), ho->id);
  662. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 33+i, -31+i), ho->id);
  663. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 65+i, -31+i), ho->id);
  664. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 1+i), ho->id);
  665. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 1+i), ho->id);
  666. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 1+i), ho->id);
  667. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 1+i), ho->id);
  668. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 33+i), ho->id);
  669. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 33+i), ho->id);
  670. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 33+i), ho->id);
  671. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 33+i), ho->id);
  672. /*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);
  673. 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);
  674. 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);
  675. 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);
  676. 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);
  677. 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);
  678. 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);
  679. 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);
  680. 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);
  681. 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);
  682. 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);
  683. 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);*/
  684. }
  685. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  686. {
  687. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 0, -31+i), ho->id);
  688. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 32, -31+i), ho->id);
  689. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 64, -31+i), ho->id);
  690. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1+i), ho->id);
  691. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1+i), ho->id);
  692. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1+i), ho->id);
  693. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33+i), ho->id);
  694. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33+i), ho->id);
  695. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33+i), ho->id);
  696. /*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);
  697. 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);
  698. 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);
  699. 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);
  700. 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);
  701. 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);
  702. 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);
  703. 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);
  704. 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);*/
  705. }
  706. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  707. {
  708. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, -1-i, -31+i), ho->id);
  709. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 31-i, -31+i), ho->id);
  710. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 63-i, -31+i), ho->id);
  711. subRect(hp.x+1, hp.y-2, hp.z, genRect(32, 32, 95-i, -31+i), ho->id);
  712. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 1+i), ho->id);
  713. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 1+i), ho->id);
  714. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 1+i), ho->id);
  715. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 1+i), ho->id);
  716. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 33+i), ho->id);
  717. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 33+i), ho->id);
  718. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 33+i), ho->id);
  719. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 33+i), ho->id);
  720. /*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);
  721. 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);
  722. 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);
  723. 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);
  724. 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);
  725. 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);
  726. 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);
  727. 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);
  728. 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);
  729. 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);
  730. 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);
  731. 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);*/
  732. }
  733. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  734. {
  735. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 0), ho->id);
  736. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 0), ho->id);
  737. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 0), ho->id);
  738. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 0), ho->id);
  739. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 32), ho->id);
  740. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 32), ho->id);
  741. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 32), ho->id);
  742. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 32), ho->id);
  743. /*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);
  744. 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);
  745. 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);
  746. 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);
  747. 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);
  748. 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);
  749. 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);
  750. 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);*/
  751. }
  752. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  753. {
  754. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, -1-i), ho->id);
  755. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, -1-i), ho->id);
  756. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, -1-i), ho->id);
  757. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, -1-i), ho->id);
  758. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 31-i), ho->id);
  759. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 31-i), ho->id);
  760. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 31-i), ho->id);
  761. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 31-i), ho->id);
  762. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, -1-i, 63-i), ho->id);
  763. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 31-i, 63-i), ho->id);
  764. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 63-i, 63-i), ho->id);
  765. subRect(hp.x+1, hp.y+1, hp.z, genRect(32, 32, 95-i, 63-i), ho->id);
  766. /*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);
  767. 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);
  768. 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);
  769. 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);
  770. 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);
  771. 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);
  772. 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);
  773. 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);
  774. 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);
  775. 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);
  776. 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);
  777. 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);*/
  778. }
  779. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  780. {
  781. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1-i), ho->id);
  782. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1-i), ho->id);
  783. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1-i), ho->id);
  784. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31-i), ho->id);
  785. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31-i), ho->id);
  786. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31-i), ho->id);
  787. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 0, 63-i), ho->id);
  788. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 32, 63-i), ho->id);
  789. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 64, 63-i), ho->id);
  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-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  794. 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);
  795. 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);
  796. 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);
  797. 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);
  798. 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);*/
  799. }
  800. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  801. {
  802. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, -1-i), ho->id);
  803. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, -1-i), ho->id);
  804. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, -1-i), ho->id);
  805. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, -1-i), ho->id);
  806. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 31-i), ho->id);
  807. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 31-i), ho->id);
  808. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 31-i), ho->id);
  809. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 31-i), ho->id);
  810. subRect(hp.x-3, hp.y+1, hp.z, genRect(32, 32, -31+i, 63-i), ho->id);
  811. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 1+i, 63-i), ho->id);
  812. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 33+i, 63-i), ho->id);
  813. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 65+i, 63-i), ho->id);
  814. /*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);
  815. 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);
  816. 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);
  817. 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);
  818. 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);
  819. 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);
  820. 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);
  821. 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);
  822. 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);
  823. 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);
  824. 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);
  825. 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);*/
  826. }
  827. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  828. {
  829. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 0), ho->id);
  830. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 0), ho->id);
  831. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 0), ho->id);
  832. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 0), ho->id);
  833. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 32), ho->id);
  834. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 32), ho->id);
  835. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 32), ho->id);
  836. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 32), ho->id);
  837. /*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);
  838. 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);
  839. 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);
  840. 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);
  841. 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);
  842. 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);
  843. 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);
  844. 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);*/
  845. }
  846. LOCPLINT->adventureInt->update(); //updating screen
  847. SDL_Flip(ekran);
  848. CGI->screenh->updateScreen();
  849. LOCPLINT->adventureInt->anim++;
  850. SDL_framerateDelay(mainFPSmng); //for animation purposes
  851. } //for(int i=1; i<32; i+=4)
  852. //main moving done
  853. //finishing move
  854. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  855. {
  856. delObjRect(hp.x, hp.y-2, hp.z, ho->id);
  857. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  858. delObjRect(hp.x, hp.y, hp.z, ho->id);
  859. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  860. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  861. delObjRect(hp.x-3, hp.y, hp.z, ho->id);
  862. }
  863. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  864. {
  865. delObjRect(hp.x, hp.y, hp.z, ho->id);
  866. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  867. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  868. }
  869. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  870. {
  871. delObjRect(hp.x-2, hp.y-2, hp.z, ho->id);
  872. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  873. delObjRect(hp.x+1, hp.y, hp.z, ho->id);
  874. delObjRect(hp.x, hp.y, hp.z, ho->id);
  875. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  876. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  877. }
  878. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  879. {
  880. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  881. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  882. }
  883. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  884. {
  885. delObjRect(hp.x-2, hp.y+1, hp.z, ho->id);
  886. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  887. delObjRect(hp.x+1, hp.y-1, hp.z, ho->id);
  888. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  889. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  890. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  891. }
  892. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  893. {
  894. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  895. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  896. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  897. }
  898. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  899. {
  900. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  901. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  902. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  903. delObjRect(hp.x-3, hp.y-1, hp.z, ho->id);
  904. delObjRect(hp.x, hp.y, hp.z, ho->id);
  905. delObjRect(hp.x, hp.y+1, hp.z, ho->id);
  906. }
  907. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  908. {
  909. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  910. delObjRect(hp.x, hp.y, hp.z, ho->id);
  911. }
  912. ho->pos = details.dst; //copy of hero's position
  913. //ho->moveDir = 0; //move ended
  914. ho->isStanding = true;
  915. //move finished
  916. CGI->mh->recalculateHideVisPosUnderObj(details.ho, true);
  917. adventureInt->minimap.draw();
  918. adventureInt->heroList.updateMove(ho);
  919. }
  920. void CPlayerInterface::heroKilled(const CGHeroInstance*)
  921. {
  922. }
  923. void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
  924. {
  925. }
  926. 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*
  927. {
  928. if (specific)
  929. ;//TODO: dorobic, ale w ogole to moze lepiej najpierw zastapic tego voida czym innym
  930. else
  931. {
  932. if (adventureInt->selection.type == HEROI_TYPE)
  933. {
  934. char * buf = new char[10];
  935. SDL_Surface * ret = copySurface(hInfo);
  936. SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
  937. blueToPlayersAdv(ret,playerID,1);
  938. const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection.selected;
  939. printAt(curh->name,75,15,GEOR13,zwykly,ret);
  940. for (int i=0;i<PRIMARY_SKILLS;i++)
  941. {
  942. itoa(curh->primSkills[i],buf,10);
  943. printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
  944. }
  945. for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
  946. {
  947. blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
  948. itoa((*i).second.second,buf,10);
  949. printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
  950. }
  951. blitAt(curh->type->portraitLarge,11,12,ret);
  952. itoa(curh->mana,buf,10);
  953. printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points
  954. delete buf;
  955. blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret);
  956. blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret);
  957. //SDL_SaveBMP(ret,"inf1.bmp");
  958. return ret;
  959. }
  960. else if (adventureInt->selection.type == TOWNI_TYPE)
  961. {
  962. char * buf = new char[10];
  963. SDL_Surface * ret = copySurface(hInfo);
  964. return ret;
  965. }
  966. else
  967. return NULL;
  968. }
  969. return NULL;
  970. }
  971. void CPlayerInterface::handleEvent(SDL_Event *sEvent)
  972. {
  973. current = sEvent;
  974. if(sEvent->type == SDL_MOUSEMOTION)
  975. {
  976. CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
  977. }
  978. if(sEvent->type==SDL_QUIT)
  979. exit(0);
  980. else if (sEvent->type==SDL_KEYDOWN)
  981. {
  982. switch (sEvent->key.keysym.sym)
  983. {
  984. case SDLK_LEFT:
  985. {
  986. LOCPLINT->adventureInt->scrollingLeft = true;
  987. break;
  988. }
  989. case (SDLK_RIGHT):
  990. {
  991. LOCPLINT->adventureInt->scrollingRight = true;
  992. break;
  993. }
  994. case (SDLK_UP):
  995. {
  996. LOCPLINT->adventureInt->scrollingUp = true;
  997. break;
  998. }
  999. case (SDLK_DOWN):
  1000. {
  1001. LOCPLINT->adventureInt->scrollingDown = true;
  1002. break;
  1003. }
  1004. case (SDLK_q):
  1005. {
  1006. exit(0);
  1007. break;
  1008. }
  1009. case (SDLK_u):
  1010. {
  1011. adventureInt->underground.clickLeft(true);
  1012. }
  1013. }
  1014. } //keydown end
  1015. else if(sEvent->type==SDL_KEYUP)
  1016. {
  1017. switch (sEvent->key.keysym.sym)
  1018. {
  1019. case SDLK_LEFT:
  1020. {
  1021. LOCPLINT->adventureInt->scrollingLeft = false;
  1022. break;
  1023. }
  1024. case (SDLK_RIGHT):
  1025. {
  1026. LOCPLINT->adventureInt->scrollingRight = false;
  1027. break;
  1028. }
  1029. case (SDLK_UP):
  1030. {
  1031. LOCPLINT->adventureInt->scrollingUp = false;
  1032. break;
  1033. }
  1034. case (SDLK_DOWN):
  1035. {
  1036. LOCPLINT->adventureInt->scrollingDown = false;
  1037. break;
  1038. }
  1039. case (SDLK_u):
  1040. {
  1041. adventureInt->underground.clickLeft(false);
  1042. }
  1043. }
  1044. }//keyup end
  1045. else if(sEvent->type==SDL_MOUSEMOTION)
  1046. {
  1047. for (int i=0; i<hoverable.size();i++)
  1048. {
  1049. if (isItIn(&hoverable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1050. {
  1051. if (!hoverable[i]->hovered)
  1052. hoverable[i]->hover(true);
  1053. }
  1054. else if (hoverable[i]->hovered)
  1055. {
  1056. hoverable[i]->hover(false);
  1057. }
  1058. }
  1059. for(int i=0; i<motioninterested.size();i++)
  1060. {
  1061. if (isItIn(&motioninterested[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1062. {
  1063. motioninterested[i]->mouseMoved(sEvent->motion);
  1064. }
  1065. }
  1066. if(sEvent->motion.x<15)
  1067. {
  1068. LOCPLINT->adventureInt->scrollingLeft = true;
  1069. }
  1070. else
  1071. {
  1072. LOCPLINT->adventureInt->scrollingLeft = false;
  1073. }
  1074. if(sEvent->motion.x>ekran->w-15)
  1075. {
  1076. LOCPLINT->adventureInt->scrollingRight = true;
  1077. }
  1078. else
  1079. {
  1080. LOCPLINT->adventureInt->scrollingRight = false;
  1081. }
  1082. if(sEvent->motion.y<15)
  1083. {
  1084. LOCPLINT->adventureInt->scrollingUp = true;
  1085. }
  1086. else
  1087. {
  1088. LOCPLINT->adventureInt->scrollingUp = false;
  1089. }
  1090. if(sEvent->motion.y>ekran->h-15)
  1091. {
  1092. LOCPLINT->adventureInt->scrollingDown = true;
  1093. }
  1094. else
  1095. {
  1096. LOCPLINT->adventureInt->scrollingDown = false;
  1097. }
  1098. } //mousemotion end
  1099. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1100. {
  1101. LOGE("Left mouse button down1");
  1102. for(int i=0; i<lclickable.size();i++)
  1103. {
  1104. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1105. {
  1106. lclickable[i]->clickLeft(true);
  1107. }
  1108. }
  1109. }
  1110. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1111. {
  1112. for(int i=0; i<lclickable.size();i++)
  1113. {
  1114. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1115. {
  1116. lclickable[i]->clickLeft(false);
  1117. }
  1118. else
  1119. lclickable[i]->clickLeft(boost::logic::indeterminate);
  1120. }
  1121. }
  1122. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1123. {
  1124. for(int i=0; i<rclickable.size();i++)
  1125. {
  1126. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1127. {
  1128. rclickable[i]->clickRight(true);
  1129. }
  1130. }
  1131. }
  1132. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1133. {
  1134. for(int i=0; i<rclickable.size();i++)
  1135. {
  1136. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1137. {
  1138. rclickable[i]->clickRight(false);
  1139. }
  1140. else
  1141. rclickable[i]->clickRight(boost::logic::indeterminate);
  1142. }
  1143. }
  1144. current = NULL;
  1145. } //event end
  1146. int3 CPlayerInterface::repairScreenPos(int3 pos)
  1147. {
  1148. if(pos.x<=-Woff)
  1149. pos.x = -Woff+1;
  1150. if(pos.y<=-Hoff)
  1151. pos.y = -Hoff+1;
  1152. if(pos.x>CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff)
  1153. pos.x = CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff;
  1154. if(pos.y>CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff)
  1155. pos.y = CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff;
  1156. return pos;
  1157. }
  1158. void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)
  1159. {
  1160. if (adventureInt->selection.selected == hero)
  1161. adventureInt->infoBar.draw();
  1162. return;
  1163. }
  1164. void CPlayerInterface::receivedResource(int type, int val)
  1165. {
  1166. adventureInt->resdatabar.draw();
  1167. }
  1168. void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*> & components)
  1169. {
  1170. adventureInt->hide(); //dezaktywacja starego interfejsu
  1171. CInfoWindow * temp = CMessage::genIWindow(text,LOCPLINT->playerID,32,components);
  1172. LOCPLINT->objsToBlit.push_back(temp);
  1173. temp->pos.x=300-(temp->pos.w/2);
  1174. temp->pos.y=300-(temp->pos.h/2);
  1175. temp->okb.pos.x = temp->okb.posr.x + temp->pos.x;
  1176. temp->okb.pos.y = temp->okb.posr.y + temp->pos.y;
  1177. temp->okb.activate();
  1178. for (int i=0;i<temp->components.size();i++)
  1179. {
  1180. temp->components[i]->activate();
  1181. temp->components[i]->pos.x += temp->pos.x;
  1182. temp->components[i]->pos.y += temp->pos.y;
  1183. }
  1184. }
  1185. void CPlayerInterface::removeObjToBlit(IShowable* obj)
  1186. {
  1187. objsToBlit.erase
  1188. (std::find(objsToBlit.begin(),objsToBlit.end(),obj));
  1189. //delete obj;
  1190. }
  1191. void CPlayerInterface::tileRevealed(int3 pos)
  1192. {
  1193. adventureInt->minimap.showTile(pos);
  1194. }
  1195. void CPlayerInterface::tileHidden(int3 pos)
  1196. {
  1197. adventureInt->minimap.hideTile(pos);
  1198. }