CGameInterface.cpp 53 KB

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