CPlayerInterface.cpp 58 KB

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