CGameInterface.cpp 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  1. #include "stdafx.h"
  2. #include "CGameInterface.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. using namespace CSDL_Ext;
  16. class OCM_HLP_CGIN
  17. {
  18. public:
  19. bool operator ()(const std::pair<CObjectInstance *, SDL_Rect> & a, const std::pair<CObjectInstance *, SDL_Rect> & b) const
  20. {
  21. return (*a.first)<(*b.first);
  22. }
  23. } ocmptwo_cgin ;
  24. CSimpleWindow::~CSimpleWindow()
  25. {
  26. SDL_FreeSurface(bitmap);
  27. bitmap=NULL;
  28. }
  29. CButtonBase::CButtonBase()
  30. {
  31. curimg=0;
  32. type=-1;
  33. abs=false;
  34. active=false;
  35. ourObj=NULL;
  36. state=0;
  37. }
  38. void CButtonBase::show()
  39. {
  40. if (abs)
  41. {
  42. blitAt(imgs[curimg][state],pos.x,pos.y);
  43. updateRect(&pos);
  44. }
  45. else
  46. {
  47. blitAt(imgs[curimg][state],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y);
  48. updateRect(&genRect(pos.h,pos.w,pos.x+ourObj->pos.x,pos.y+ourObj->pos.y));
  49. }
  50. }
  51. ClickableL::ClickableL()
  52. {
  53. pressedL=false;
  54. }
  55. void ClickableL::clickLeft(tribool down)
  56. {
  57. if (down)
  58. pressedL=true;
  59. else
  60. pressedL=false;
  61. }
  62. void ClickableL::activate()
  63. {
  64. LOCPLINT->lclickable.push_back(this);
  65. }
  66. void ClickableL::deactivate()
  67. {
  68. LOCPLINT->lclickable.erase
  69. (std::find(LOCPLINT->lclickable.begin(),LOCPLINT->lclickable.end(),this));
  70. }
  71. ClickableR::ClickableR()
  72. {
  73. pressedR=false;
  74. }
  75. void ClickableR::activate()
  76. {
  77. LOCPLINT->rclickable.push_back(this);
  78. }
  79. void ClickableR::deactivate()
  80. {
  81. LOCPLINT->rclickable.erase(std::find(LOCPLINT->rclickable.begin(),LOCPLINT->rclickable.end(),this));
  82. }
  83. void Hoverable::activate()
  84. {
  85. LOCPLINT->hoverable.push_back(this);
  86. }
  87. void Hoverable::deactivate()
  88. {
  89. LOCPLINT->hoverable.erase(std::find(LOCPLINT->hoverable.begin(),LOCPLINT->hoverable.end(),this));
  90. }
  91. void Hoverable::hover(bool on)
  92. {
  93. hovered=on;
  94. }
  95. void KeyInterested::activate()
  96. {
  97. LOCPLINT->keyinterested.push_back(this);
  98. }
  99. void KeyInterested::deactivate()
  100. {
  101. LOCPLINT->
  102. keyinterested.erase(std::find(LOCPLINT->keyinterested.begin(),LOCPLINT->keyinterested.end(),this));
  103. }
  104. void MotionInterested::activate()
  105. {
  106. LOCPLINT->motioninterested.push_back(this);
  107. }
  108. void MotionInterested::deactivate()
  109. {
  110. LOCPLINT->
  111. motioninterested.erase(std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this));
  112. }
  113. CPlayerInterface::CPlayerInterface(int Player, int serial)
  114. {
  115. playerID=Player;
  116. serialID=serial;
  117. CGI->localPlayer = playerID;
  118. human=true;
  119. hInfo = CGI->bitmaph->loadBitmap("HEROQVBK.bmp");
  120. SDL_SetColorKey(hInfo,SDL_SRCCOLORKEY,SDL_MapRGB(hInfo->format,0,255,255));
  121. slotsPos.push_back(std::pair<int,int>(44,82));
  122. slotsPos.push_back(std::pair<int,int>(80,82));
  123. slotsPos.push_back(std::pair<int,int>(116,82));
  124. slotsPos.push_back(std::pair<int,int>(26,131));
  125. slotsPos.push_back(std::pair<int,int>(62,131));
  126. slotsPos.push_back(std::pair<int,int>(98,131));
  127. slotsPos.push_back(std::pair<int,int>(134,131));
  128. luck22 = CGI->spriteh->giveDefEss("ILCK22.DEF");
  129. luck30 = CGI->spriteh->giveDefEss("ILCK30.DEF");
  130. luck42 = CGI->spriteh->giveDefEss("ILCK42.DEF");
  131. luck82 = CGI->spriteh->giveDefEss("ILCK82.DEF");
  132. morale22 = CGI->spriteh->giveDefEss("IMRL22.DEF");
  133. morale30 = CGI->spriteh->giveDefEss("IMRL30.DEF");
  134. morale42 = CGI->spriteh->giveDefEss("IMRL42.DEF");
  135. morale82 = CGI->spriteh->giveDefEss("IMRL82.DEF");
  136. }
  137. void CPlayerInterface::init(CCallback * CB)
  138. {
  139. cb = CB;
  140. CGI->localPlayer = serialID;
  141. adventureInt = new CAdvMapInt(playerID);
  142. }
  143. void CPlayerInterface::yourTurn()
  144. {
  145. CGI->localPlayer = serialID;
  146. unsigned char & animVal = LOCPLINT->adventureInt->anim; //for animations handling
  147. adventureInt->show();
  148. //show rest of things
  149. //initializing framerate keeper
  150. mainFPSmng = new FPSmanager;
  151. SDL_initFramerate(mainFPSmng);
  152. SDL_setFramerate(mainFPSmng, 24);
  153. SDL_Event sEvent;
  154. //framerate keeper initialized
  155. for(;;) // main loop
  156. {
  157. CGI->screenh->updateScreen();
  158. LOCPLINT->adventureInt->updateScreen = false;
  159. while (SDL_PollEvent(&sEvent)) //wait for event...
  160. {
  161. handleEvent(&sEvent);
  162. }
  163. ++LOCPLINT->adventureInt->animValHitCount; //for animations
  164. if(LOCPLINT->adventureInt->animValHitCount == 2)
  165. {
  166. LOCPLINT->adventureInt->animValHitCount = 0;
  167. ++animVal;
  168. LOCPLINT->adventureInt->updateScreen = true;
  169. }
  170. if(LOCPLINT->adventureInt->scrollingLeft)
  171. {
  172. if(LOCPLINT->adventureInt->position.x>-Woff)
  173. {
  174. LOCPLINT->adventureInt->position.x--;
  175. LOCPLINT->adventureInt->updateScreen = true;
  176. }
  177. }
  178. if(LOCPLINT->adventureInt->scrollingRight)
  179. {
  180. if(LOCPLINT->adventureInt->position.x<CGI->ac->map.width-19+4)
  181. {
  182. LOCPLINT->adventureInt->position.x++;
  183. LOCPLINT->adventureInt->updateScreen = true;
  184. }
  185. }
  186. if(LOCPLINT->adventureInt->scrollingUp)
  187. {
  188. if(LOCPLINT->adventureInt->position.y>-Hoff)
  189. {
  190. LOCPLINT->adventureInt->position.y--;
  191. LOCPLINT->adventureInt->updateScreen = true;
  192. }
  193. }
  194. if(LOCPLINT->adventureInt->scrollingDown)
  195. {
  196. if(LOCPLINT->adventureInt->position.y<CGI->ac->map.height-18+4)
  197. {
  198. LOCPLINT->adventureInt->position.y++;
  199. LOCPLINT->adventureInt->updateScreen = true;
  200. }
  201. }
  202. if(LOCPLINT->adventureInt->updateScreen)
  203. {
  204. adventureInt->update();
  205. LOCPLINT->adventureInt->updateScreen=false;
  206. }
  207. for(int i=0;i<objsToBlit.size();i++)
  208. blitAt(objsToBlit[i]->bitmap,objsToBlit[i]->pos.x,objsToBlit[i]->pos.y);
  209. SDL_Delay(5); //give time for other apps
  210. SDL_framerateDelay(mainFPSmng);
  211. }
  212. }
  213. inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, const int & hid)
  214. {
  215. for(int h=0; h<CGI->mh->ttiles[x][y][z].objects.size(); ++h)
  216. if(CGI->mh->ttiles[x][y][z].objects[h].first->id==hid)
  217. CGI->mh->ttiles[x][y][z].objects[h].second = r;
  218. }
  219. inline void delObjRect(const int & x, const int & y, const int & z, const int & hid)
  220. {
  221. for(int h=0; h<CGI->mh->ttiles[x][y][z].objects.size(); ++h)
  222. if(CGI->mh->ttiles[x][y][z].objects[h].first->id==hid)
  223. CGI->mh->ttiles[x][y][z].objects.erase(CGI->mh->ttiles[x][y][z].objects.begin()+h);
  224. }
  225. void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
  226. {
  227. //initializing objects and performing first step of move
  228. CObjectInstance * ho = details.ho; //object representing this hero
  229. int3 hp = details.src;
  230. if (adventureInt->terrain.currentPath) //&& hero is moving
  231. {
  232. adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
  233. }
  234. int3 buff = details.ho->pos;
  235. buff.x-=11;
  236. buff.y-=9;
  237. buff = repairScreenPos(buff);
  238. LOCPLINT->adventureInt->position = buff; //actualizing screen pos
  239. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  240. {
  241. ho->moveDir = 1;
  242. ho->isStanding = false;
  243. CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -31)));
  244. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, -31)));
  245. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, -31)));
  246. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, -31)));
  247. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 1)));
  248. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 1), ho->id);
  249. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 1), ho->id);
  250. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 1), ho->id);
  251. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 33)));
  252. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 33), ho->id);
  253. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 33), ho->id);
  254. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 33), ho->id);
  255. 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);
  256. 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);
  257. 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);
  258. 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);
  259. 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);
  260. 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);
  261. 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);
  262. 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);
  263. 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);
  264. 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);
  265. 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);
  266. 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);
  267. }
  268. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  269. {
  270. ho->moveDir = 2;
  271. ho->isStanding = false;
  272. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, -31)));
  273. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, -31)));
  274. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, -31)));
  275. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1), ho->id);
  276. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1), ho->id);
  277. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1), ho->id);
  278. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33), ho->id);
  279. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33), ho->id);
  280. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33), ho->id);
  281. 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);
  282. 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);
  283. 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);
  284. 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);
  285. 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);
  286. 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);
  287. 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);
  288. 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);
  289. 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);
  290. }
  291. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  292. {
  293. ho->moveDir = 3;
  294. ho->isStanding = false;
  295. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, -31)));
  296. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, -31)));
  297. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, -31)));
  298. CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -31)));
  299. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 1), ho->id);
  300. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 1), ho->id);
  301. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 1), ho->id);
  302. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 1)));
  303. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 33), ho->id);
  304. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 33), ho->id);
  305. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 33), ho->id);
  306. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 33)));
  307. 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);
  308. 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);
  309. 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);
  310. 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);
  311. 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);
  312. 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);
  313. 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);
  314. 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);
  315. 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);
  316. 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);
  317. 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);
  318. 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);
  319. }
  320. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  321. {
  322. ho->moveDir = 4;
  323. ho->isStanding = false;
  324. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id);
  325. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id);
  326. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id);
  327. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 0)));
  328. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 32), ho->id);
  329. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 32), ho->id);
  330. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 32), ho->id);
  331. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 32)));
  332. 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);
  333. 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);
  334. 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);
  335. 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);
  336. 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);
  337. 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);
  338. 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);
  339. 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);
  340. }
  341. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  342. {
  343. ho->moveDir = 5;
  344. ho->isStanding = false;
  345. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, -1), ho->id);
  346. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, -1), ho->id);
  347. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id);
  348. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -1)));
  349. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 31), ho->id);
  350. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 31), ho->id);
  351. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 31), ho->id);
  352. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 31)));
  353. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, 63)));
  354. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, 63)));
  355. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, 63)));
  356. CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 63)));
  357. 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);
  358. 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);
  359. 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);
  360. 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);
  361. 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);
  362. 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);
  363. 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);
  364. 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);
  365. 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);
  366. 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);
  367. 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);
  368. 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);
  369. }
  370. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  371. {
  372. ho->moveDir = 6;
  373. ho->isStanding = false;
  374. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1), ho->id);
  375. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1), ho->id);
  376. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1), ho->id);
  377. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31), ho->id);
  378. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31), ho->id);
  379. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31), ho->id);
  380. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, 63)));
  381. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, 63)));
  382. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, 63)));
  383. 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);
  384. 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);
  385. 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);
  386. 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);
  387. 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);
  388. 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);
  389. 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);
  390. 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);
  391. 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);
  392. }
  393. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  394. {
  395. ho->moveDir = 7;
  396. ho->isStanding = false;
  397. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -1)));
  398. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id);
  399. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id);
  400. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, -1), ho->id);
  401. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 31)));
  402. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 31), ho->id);
  403. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 31), ho->id);
  404. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 31), ho->id);
  405. CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 63)));
  406. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, 63)));
  407. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, 63)));
  408. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, 63)));
  409. 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);
  410. 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);
  411. 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);
  412. 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);
  413. 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);
  414. 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);
  415. 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);
  416. 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);
  417. 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);
  418. 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);
  419. 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);
  420. 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);
  421. }
  422. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  423. {
  424. ho->moveDir = 8;
  425. ho->isStanding = false;
  426. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 0)));
  427. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id);
  428. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id);
  429. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 0), ho->id);
  430. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 32)));
  431. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 32), ho->id);
  432. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 32), ho->id);
  433. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 32), ho->id);
  434. 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);
  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-3][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  439. 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);
  440. 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);
  441. 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);
  442. }
  443. //first initializing done
  444. SDL_framerateDelay(mainFPSmng); // after first move
  445. //main moving
  446. for(int i=1; i<32; i+=4)
  447. {
  448. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  449. {
  450. subRect(hp.x-3, hp.y-2, hp.z, genRect(32, 32, -31+i, -31+i), ho->id);
  451. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 1+i, -31+i), ho->id);
  452. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 33+i, -31+i), ho->id);
  453. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 65+i, -31+i), ho->id);
  454. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 1+i), ho->id);
  455. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 1+i), ho->id);
  456. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 1+i), ho->id);
  457. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 1+i), ho->id);
  458. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 33+i), ho->id);
  459. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 33+i), ho->id);
  460. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 33+i), ho->id);
  461. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 33+i), ho->id);
  462. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  463. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  464. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  465. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  466. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  467. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  468. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  469. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  470. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  471. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  472. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  473. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  474. }
  475. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  476. {
  477. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 0, -31+i), ho->id);
  478. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 32, -31+i), ho->id);
  479. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 64, -31+i), ho->id);
  480. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1+i), ho->id);
  481. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1+i), ho->id);
  482. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1+i), ho->id);
  483. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33+i), ho->id);
  484. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33+i), ho->id);
  485. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33+i), ho->id);
  486. 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);
  487. 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);
  488. 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);
  489. 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);
  490. 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);
  491. 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);
  492. 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);
  493. 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);
  494. 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);
  495. }
  496. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  497. {
  498. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, -1-i, -31+i), ho->id);
  499. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 31-i, -31+i), ho->id);
  500. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 63-i, -31+i), ho->id);
  501. subRect(hp.x+1, hp.y-2, hp.z, genRect(32, 32, 95-i, -31+i), ho->id);
  502. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 1+i), ho->id);
  503. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 1+i), ho->id);
  504. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 1+i), ho->id);
  505. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 1+i), ho->id);
  506. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 33+i), ho->id);
  507. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 33+i), ho->id);
  508. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 33+i), ho->id);
  509. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 33+i), ho->id);
  510. 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);
  511. 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);
  512. 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);
  513. 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);
  514. 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);
  515. 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);
  516. 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);
  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-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  519. 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);
  520. 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);
  521. 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);
  522. }
  523. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  524. {
  525. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 0), ho->id);
  526. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 0), ho->id);
  527. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 0), ho->id);
  528. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 0), ho->id);
  529. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 32), ho->id);
  530. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 32), ho->id);
  531. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 32), ho->id);
  532. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 32), ho->id);
  533. 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);
  534. 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);
  535. 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);
  536. 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);
  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+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  541. }
  542. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  543. {
  544. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, -1-i), ho->id);
  545. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, -1-i), ho->id);
  546. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, -1-i), ho->id);
  547. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, -1-i), ho->id);
  548. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 31-i), ho->id);
  549. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 31-i), ho->id);
  550. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 31-i), ho->id);
  551. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 31-i), ho->id);
  552. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, -1-i, 63-i), ho->id);
  553. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 31-i, 63-i), ho->id);
  554. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 63-i, 63-i), ho->id);
  555. subRect(hp.x+1, hp.y+1, hp.z, genRect(32, 32, 95-i, 63-i), ho->id);
  556. 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);
  557. 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);
  558. 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);
  559. 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);
  560. 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);
  561. 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);
  562. 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);
  563. 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);
  564. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  565. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  566. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  567. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  568. }
  569. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  570. {
  571. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1-i), ho->id);
  572. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1-i), ho->id);
  573. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1-i), ho->id);
  574. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31-i), ho->id);
  575. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31-i), ho->id);
  576. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31-i), ho->id);
  577. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 0, 63-i), ho->id);
  578. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 32, 63-i), ho->id);
  579. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 64, 63-i), ho->id);
  580. 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);
  581. 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);
  582. 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);
  583. 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);
  584. 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);
  585. 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);
  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. }
  590. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  591. {
  592. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, -1-i), ho->id);
  593. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, -1-i), ho->id);
  594. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, -1-i), ho->id);
  595. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, -1-i), ho->id);
  596. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 31-i), ho->id);
  597. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 31-i), ho->id);
  598. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 31-i), ho->id);
  599. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 31-i), ho->id);
  600. subRect(hp.x-3, hp.y+1, hp.z, genRect(32, 32, -31+i, 63-i), ho->id);
  601. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 1+i, 63-i), ho->id);
  602. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 33+i, 63-i), ho->id);
  603. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 65+i, 63-i), ho->id);
  604. 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);
  605. 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);
  606. 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);
  607. 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);
  608. 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);
  609. 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);
  610. 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);
  611. 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);
  612. 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);
  613. 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);
  614. 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);
  615. 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);
  616. }
  617. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  618. {
  619. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 0), ho->id);
  620. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 0), ho->id);
  621. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 0), ho->id);
  622. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 0), ho->id);
  623. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 32), ho->id);
  624. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 32), ho->id);
  625. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 32), ho->id);
  626. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 32), ho->id);
  627. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  628. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  629. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  630. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  631. 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);
  632. 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);
  633. 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);
  634. 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);
  635. }
  636. LOCPLINT->adventureInt->update(); //updating screen
  637. CGI->screenh->updateScreen();
  638. LOCPLINT->adventureInt->anim++;
  639. SDL_framerateDelay(mainFPSmng); //for animation purposes
  640. } //for(int i=1; i<32; i+=4)
  641. //main moving done
  642. //finishing move
  643. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  644. {
  645. delObjRect(hp.x, hp.y-2, hp.z, ho->id);
  646. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  647. delObjRect(hp.x, hp.y, hp.z, ho->id);
  648. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  649. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  650. delObjRect(hp.x-3, hp.y, hp.z, ho->id);
  651. }
  652. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  653. {
  654. delObjRect(hp.x, hp.y, hp.z, ho->id);
  655. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  656. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  657. }
  658. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  659. {
  660. delObjRect(hp.x-2, hp.y-2, hp.z, ho->id);
  661. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  662. delObjRect(hp.x+1, hp.y, hp.z, ho->id);
  663. delObjRect(hp.x, hp.y, hp.z, ho->id);
  664. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  665. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  666. }
  667. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  668. {
  669. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  670. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  671. }
  672. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  673. {
  674. delObjRect(hp.x-2, hp.y+1, hp.z, ho->id);
  675. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  676. delObjRect(hp.x+1, hp.y-1, hp.z, ho->id);
  677. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  678. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  679. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  680. }
  681. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  682. {
  683. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  684. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  685. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  686. }
  687. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  688. {
  689. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  690. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  691. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  692. delObjRect(hp.x-3, hp.y-1, hp.z, ho->id);
  693. delObjRect(hp.x, hp.y, hp.z, ho->id);
  694. delObjRect(hp.x, hp.y+1, hp.z, ho->id);
  695. }
  696. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  697. {
  698. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  699. delObjRect(hp.x, hp.y, hp.z, ho->id);
  700. }
  701. ho->pos = details.dst; //copy of hero's position
  702. //ho->moveDir = 0; //move ended
  703. ho->isStanding = true;
  704. //move finished
  705. adventureInt->heroList.draw();
  706. }
  707. void CPlayerInterface::heroKilled(const CHeroInstance * hero)
  708. {
  709. }
  710. void CPlayerInterface::heroCreated(const CHeroInstance * hero)
  711. {
  712. }
  713. SDL_Surface * CPlayerInterface::infoWin(void * specific) //specific=0 => draws info about selected town/hero //TODO - gdy sie dorobi sensowna hierarchie klas ins. to wywalic tego brzydkiego void*
  714. {
  715. if (specific)
  716. ;//TODO: dorobic, ale w ogole to moze lepiej najpierw zastapic tego voida czym innym
  717. else
  718. {
  719. if (adventureInt->selection.type == HEROI_TYPE)
  720. {
  721. char * buf = new char[10];
  722. SDL_Surface * ret = copySurface(hInfo);
  723. SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
  724. //blueToPlayersAdv(ret,playerID); // zygzyg - nie koloruje, tylko odrobine smieci
  725. const CHeroInstance * curh = (const CHeroInstance *)adventureInt->selection.selected;
  726. printAt(curh->name,75,15,GEOR13,zwykly,ret);
  727. for (int i=0;i<PRIMARY_SKILLS;i++)
  728. {
  729. itoa(curh->primSkills[i],buf,10);
  730. printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
  731. }
  732. for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
  733. {
  734. blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
  735. itoa((*i).second.second,buf,10);
  736. printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
  737. }
  738. blitAt(curh->type->portraitLarge,11,12,ret);
  739. itoa(curh->mana,buf,10);
  740. printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points
  741. delete buf;
  742. blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret);
  743. blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret);
  744. //SDL_SaveBMP(ret,"inf1.bmp");
  745. return ret;
  746. }
  747. else if (adventureInt->selection.type == TOWNI_TYPE)
  748. {
  749. //TODO: do it
  750. return NULL;
  751. }
  752. else
  753. return NULL;
  754. }
  755. return NULL;
  756. }
  757. void CPlayerInterface::handleEvent(SDL_Event *sEvent)
  758. {
  759. current = sEvent;
  760. if(sEvent->type == SDL_MOUSEMOTION)
  761. {
  762. CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
  763. }
  764. if(sEvent->type==SDL_QUIT)
  765. exit(0);
  766. else if (sEvent->type==SDL_KEYDOWN)
  767. {
  768. switch (sEvent->key.keysym.sym)
  769. {
  770. case SDLK_LEFT:
  771. {
  772. LOCPLINT->adventureInt->scrollingLeft = true;
  773. break;
  774. }
  775. case (SDLK_RIGHT):
  776. {
  777. LOCPLINT->adventureInt->scrollingRight = true;
  778. break;
  779. }
  780. case (SDLK_UP):
  781. {
  782. LOCPLINT->adventureInt->scrollingUp = true;
  783. break;
  784. }
  785. case (SDLK_DOWN):
  786. {
  787. LOCPLINT->adventureInt->scrollingDown = true;
  788. break;
  789. }
  790. case (SDLK_q):
  791. {
  792. exit(0);
  793. break;
  794. }
  795. case (SDLK_u):
  796. {
  797. adventureInt->underground.clickLeft(true);
  798. }
  799. }
  800. } //keydown end
  801. else if(sEvent->type==SDL_KEYUP)
  802. {
  803. switch (sEvent->key.keysym.sym)
  804. {
  805. case SDLK_LEFT:
  806. {
  807. LOCPLINT->adventureInt->scrollingLeft = false;
  808. break;
  809. }
  810. case (SDLK_RIGHT):
  811. {
  812. LOCPLINT->adventureInt->scrollingRight = false;
  813. break;
  814. }
  815. case (SDLK_UP):
  816. {
  817. LOCPLINT->adventureInt->scrollingUp = false;
  818. break;
  819. }
  820. case (SDLK_DOWN):
  821. {
  822. LOCPLINT->adventureInt->scrollingDown = false;
  823. break;
  824. }
  825. case (SDLK_u):
  826. {
  827. adventureInt->underground.clickLeft(false);
  828. }
  829. }
  830. }//keyup end
  831. else if(sEvent->type==SDL_MOUSEMOTION)
  832. {
  833. for (int i=0; i<hoverable.size();i++)
  834. {
  835. if (isItIn(&hoverable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  836. {
  837. if (!hoverable[i]->hovered)
  838. hoverable[i]->hover(true);
  839. }
  840. else if (hoverable[i]->hovered)
  841. {
  842. hoverable[i]->hover(false);
  843. }
  844. }
  845. for(int i=0; i<motioninterested.size();i++)
  846. {
  847. if (isItIn(&motioninterested[i]->pos,sEvent->motion.x,sEvent->motion.y))
  848. {
  849. motioninterested[i]->mouseMoved(sEvent->motion);
  850. }
  851. }
  852. if(sEvent->motion.x<15)
  853. {
  854. LOCPLINT->adventureInt->scrollingLeft = true;
  855. }
  856. else
  857. {
  858. LOCPLINT->adventureInt->scrollingLeft = false;
  859. }
  860. if(sEvent->motion.x>ekran->w-15)
  861. {
  862. LOCPLINT->adventureInt->scrollingRight = true;
  863. }
  864. else
  865. {
  866. LOCPLINT->adventureInt->scrollingRight = false;
  867. }
  868. if(sEvent->motion.y<15)
  869. {
  870. LOCPLINT->adventureInt->scrollingUp = true;
  871. }
  872. else
  873. {
  874. LOCPLINT->adventureInt->scrollingUp = false;
  875. }
  876. if(sEvent->motion.y>ekran->h-15)
  877. {
  878. LOCPLINT->adventureInt->scrollingDown = true;
  879. }
  880. else
  881. {
  882. LOCPLINT->adventureInt->scrollingDown = false;
  883. }
  884. } //mousemotion end
  885. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT))
  886. {
  887. for(int i=0; i<lclickable.size();i++)
  888. {
  889. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  890. {
  891. lclickable[i]->clickLeft(true);
  892. }
  893. }
  894. }
  895. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
  896. {
  897. for(int i=0; i<lclickable.size();i++)
  898. {
  899. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  900. {
  901. lclickable[i]->clickLeft(false);
  902. }
  903. else
  904. lclickable[i]->clickLeft(boost::logic::indeterminate);
  905. }
  906. }
  907. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  908. {
  909. for(int i=0; i<rclickable.size();i++)
  910. {
  911. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  912. {
  913. rclickable[i]->clickRight(true);
  914. }
  915. }
  916. }
  917. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  918. {
  919. for(int i=0; i<rclickable.size();i++)
  920. {
  921. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  922. {
  923. rclickable[i]->clickRight(false);
  924. }
  925. else
  926. rclickable[i]->clickRight(boost::logic::indeterminate);
  927. }
  928. }
  929. current = NULL;
  930. } //event end
  931. int3 CPlayerInterface::repairScreenPos(int3 pos)
  932. {
  933. if(pos.x<=-Woff)
  934. pos.x = -Woff+1;
  935. if(pos.y<=-Hoff)
  936. pos.y = -Hoff+1;
  937. if(pos.x>CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff)
  938. pos.x = CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff;
  939. if(pos.y>CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff)
  940. pos.y = CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff;
  941. return pos;
  942. }