CPlayerInterface.cpp 59 KB

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