CGameInterface.cpp 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  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*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> & a, const std::pair<CObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> & 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. adventureInt->updateMinimap=true;
  213. }
  214. }
  215. if(LOCPLINT->adventureInt->scrollingRight)
  216. {
  217. if(LOCPLINT->adventureInt->position.x<CGI->ac->map.width-19+4)
  218. {
  219. LOCPLINT->adventureInt->position.x++;
  220. LOCPLINT->adventureInt->updateScreen = true;
  221. adventureInt->updateMinimap=true;
  222. }
  223. }
  224. if(LOCPLINT->adventureInt->scrollingUp)
  225. {
  226. if(LOCPLINT->adventureInt->position.y>-Hoff)
  227. {
  228. LOCPLINT->adventureInt->position.y--;
  229. LOCPLINT->adventureInt->updateScreen = true;
  230. adventureInt->updateMinimap=true;
  231. }
  232. }
  233. if(LOCPLINT->adventureInt->scrollingDown)
  234. {
  235. if(LOCPLINT->adventureInt->position.y<CGI->ac->map.height-18+4)
  236. {
  237. LOCPLINT->adventureInt->position.y++;
  238. LOCPLINT->adventureInt->updateScreen = true;
  239. adventureInt->updateMinimap=true;
  240. }
  241. }
  242. if(LOCPLINT->adventureInt->updateScreen)
  243. {
  244. adventureInt->update();
  245. adventureInt->updateScreen=false;
  246. }
  247. if (LOCPLINT->adventureInt->updateMinimap)
  248. {
  249. adventureInt->minimap.draw();
  250. adventureInt->updateMinimap=false;
  251. }
  252. for(int i=0;i<objsToBlit.size();i++)
  253. blitAt(objsToBlit[i]->bitmap,objsToBlit[i]->pos.x,objsToBlit[i]->pos.y);
  254. SDL_Delay(5); //give time for other apps
  255. SDL_framerateDelay(mainFPSmng);
  256. }
  257. adventureInt->hide();
  258. }
  259. inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, const int & hid)
  260. {
  261. for(int h=0; h<CGI->mh->ttiles[x][y][z].objects.size(); ++h)
  262. if(CGI->mh->ttiles[x][y][z].objects[h].first->id==hid)
  263. {
  264. CGI->mh->ttiles[x][y][z].objects[h].second.first = r;
  265. break;
  266. }
  267. }
  268. inline void delObjRect(const int & x, const int & y, const int & z, const int & hid)
  269. {
  270. for(int h=0; h<CGI->mh->ttiles[x][y][z].objects.size(); ++h)
  271. if(CGI->mh->ttiles[x][y][z].objects[h].first->id==hid)
  272. {
  273. CGI->mh->ttiles[x][y][z].objects.erase(CGI->mh->ttiles[x][y][z].objects.begin()+h);
  274. break;
  275. }
  276. }
  277. void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
  278. {
  279. adventureInt->minimap.draw();
  280. //initializing objects and performing first step of move
  281. CObjectInstance * ho = details.ho; //object representing this hero
  282. int3 hp = details.src;
  283. if (adventureInt->terrain.currentPath) //&& hero is moving
  284. {
  285. adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
  286. }
  287. int3 buff = details.ho->pos;
  288. buff.x-=11;
  289. buff.y-=9;
  290. buff = repairScreenPos(buff);
  291. LOCPLINT->adventureInt->position = buff; //actualizing screen pos
  292. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  293. {
  294. ho->moveDir = 1;
  295. ho->isStanding = false;
  296. CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, -31), std::vector<std::list<int3>>())));
  297. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 1, -31), std::vector<std::list<int3>>())));
  298. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 33, -31), std::vector<std::list<int3>>())));
  299. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 65, -31), std::vector<std::list<int3>>())));
  300. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 1), std::vector<std::list<int3>>())));
  301. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 1), ho->id);
  302. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 1), ho->id);
  303. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 1), ho->id);
  304. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 33), std::vector<std::list<int3>>())));
  305. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 33), ho->id);
  306. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 33), ho->id);
  307. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 33), ho->id);
  308. 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);
  309. 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);
  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][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  312. 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);
  313. 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);
  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][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  316. 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);
  317. 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);
  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. 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);
  320. }
  321. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  322. {
  323. ho->moveDir = 2;
  324. ho->isStanding = false;
  325. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 0, -31), std::vector<std::list<int3>>())));
  326. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 32, -31), std::vector<std::list<int3>>())));
  327. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 64, -31), std::vector<std::list<int3>>())));
  328. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1), ho->id);
  329. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1), ho->id);
  330. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1), ho->id);
  331. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33), ho->id);
  332. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33), ho->id);
  333. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33), ho->id);
  334. 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);
  335. 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);
  336. 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);
  337. 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);
  338. 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);
  339. 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);
  340. 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);
  341. 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);
  342. 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);
  343. }
  344. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  345. {
  346. ho->moveDir = 3;
  347. ho->isStanding = false;
  348. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -1, -31), std::vector<std::list<int3>>())));
  349. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 31, -31), std::vector<std::list<int3>>())));
  350. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 63, -31), std::vector<std::list<int3>>())));
  351. CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, -31), std::vector<std::list<int3>>())));
  352. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 1), ho->id);
  353. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 1), ho->id);
  354. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 1), ho->id);
  355. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 1), std::vector<std::list<int3>>())));
  356. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 33), ho->id);
  357. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 33), ho->id);
  358. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 33), ho->id);
  359. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 33), std::vector<std::list<int3>>())));
  360. 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);
  361. 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);
  362. 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);
  363. 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);
  364. 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);
  365. 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);
  366. 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);
  367. 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);
  368. 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);
  369. 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);
  370. 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);
  371. 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);
  372. }
  373. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  374. {
  375. ho->moveDir = 4;
  376. ho->isStanding = false;
  377. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id);
  378. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id);
  379. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id);
  380. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 0), std::vector<std::list<int3>>())));
  381. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 32), ho->id);
  382. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 32), ho->id);
  383. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 32), ho->id);
  384. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 32), std::vector<std::list<int3>>())));
  385. 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);
  386. 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);
  387. 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);
  388. 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);
  389. 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);
  390. 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);
  391. 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);
  392. 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);
  393. }
  394. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  395. {
  396. ho->moveDir = 5;
  397. ho->isStanding = false;
  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, 31, -1), ho->id);
  400. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id);
  401. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, -1), std::vector<std::list<int3>>())));
  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, 31, 31), ho->id);
  404. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 31), ho->id);
  405. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 31), std::vector<std::list<int3>>())));
  406. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -1, 63), std::vector<std::list<int3>>())));
  407. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 31, 63), std::vector<std::list<int3>>())));
  408. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 63, 63), std::vector<std::list<int3>>())));
  409. CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 63), std::vector<std::list<int3>>())));
  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+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][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+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][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. 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);
  422. }
  423. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  424. {
  425. ho->moveDir = 6;
  426. ho->isStanding = false;
  427. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1), ho->id);
  428. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1), ho->id);
  429. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1), ho->id);
  430. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31), ho->id);
  431. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31), ho->id);
  432. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31), ho->id);
  433. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 0, 63), std::vector<std::list<int3>>())));
  434. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 32, 63), std::vector<std::list<int3>>())));
  435. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 64, 63), std::vector<std::list<int3>>())));
  436. 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);
  437. 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);
  438. 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);
  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. 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);
  443. 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);
  444. 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);
  445. }
  446. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  447. {
  448. ho->moveDir = 7;
  449. ho->isStanding = false;
  450. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, -1), std::vector<std::list<int3>>())));
  451. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id);
  452. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id);
  453. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, -1), ho->id);
  454. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 31), std::vector<std::list<int3>>())));
  455. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 31), ho->id);
  456. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 31), ho->id);
  457. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 31), ho->id);
  458. CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 63), std::vector<std::list<int3>>())));
  459. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 1, 63), std::vector<std::list<int3>>())));
  460. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 33, 63), std::vector<std::list<int3>>())));
  461. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 65, 63), std::vector<std::list<int3>>())));
  462. 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);
  463. 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);
  464. 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);
  465. 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);
  466. 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);
  467. 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);
  468. 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);
  469. 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);
  470. 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);
  471. 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);
  472. 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);
  473. 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);
  474. }
  475. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  476. {
  477. ho->moveDir = 8;
  478. ho->isStanding = false;
  479. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 0), std::vector<std::list<int3>>())));
  480. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id);
  481. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id);
  482. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 0), ho->id);
  483. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 32), std::vector<std::list<int3>>())));
  484. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 32), ho->id);
  485. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 32), ho->id);
  486. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 32), ho->id);
  487. 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);
  488. 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);
  489. 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);
  490. 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);
  491. 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);
  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. //first initializing done
  497. SDL_framerateDelay(mainFPSmng); // after first move
  498. //main moving
  499. for(int i=1; i<32; i+=4)
  500. {
  501. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  502. {
  503. subRect(hp.x-3, hp.y-2, hp.z, genRect(32, 32, -31+i, -31+i), ho->id);
  504. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 1+i, -31+i), ho->id);
  505. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 33+i, -31+i), ho->id);
  506. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 65+i, -31+i), ho->id);
  507. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 1+i), ho->id);
  508. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 1+i), ho->id);
  509. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 1+i), ho->id);
  510. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 1+i), ho->id);
  511. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 33+i), ho->id);
  512. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 33+i), ho->id);
  513. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 33+i), ho->id);
  514. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 33+i), ho->id);
  515. /*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);
  516. 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);
  517. 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);
  518. 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);
  519. 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);
  520. 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);
  521. 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);
  522. 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);
  523. 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);
  524. 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);
  525. 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);
  526. 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);*/
  527. }
  528. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  529. {
  530. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 0, -31+i), ho->id);
  531. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 32, -31+i), ho->id);
  532. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 64, -31+i), ho->id);
  533. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1+i), ho->id);
  534. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1+i), ho->id);
  535. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1+i), ho->id);
  536. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33+i), ho->id);
  537. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33+i), ho->id);
  538. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33+i), ho->id);
  539. /*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);
  540. 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);
  541. 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);
  542. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  543. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  544. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  545. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  546. 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);
  547. 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);*/
  548. }
  549. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  550. {
  551. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, -1-i, -31+i), ho->id);
  552. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 31-i, -31+i), ho->id);
  553. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 63-i, -31+i), ho->id);
  554. subRect(hp.x+1, hp.y-2, hp.z, genRect(32, 32, 95-i, -31+i), ho->id);
  555. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 1+i), ho->id);
  556. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 1+i), ho->id);
  557. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 1+i), ho->id);
  558. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 1+i), ho->id);
  559. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 33+i), ho->id);
  560. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 33+i), ho->id);
  561. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 33+i), ho->id);
  562. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 33+i), ho->id);
  563. /*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);
  564. 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);
  565. 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);
  566. 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);
  567. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  568. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  569. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  570. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  571. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  572. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  573. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  574. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), ocmptwo_cgin);*/
  575. }
  576. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  577. {
  578. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 0), ho->id);
  579. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 0), ho->id);
  580. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 0), ho->id);
  581. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 0), ho->id);
  582. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 32), ho->id);
  583. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 32), ho->id);
  584. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 32), ho->id);
  585. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 32), ho->id);
  586. /*std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  587. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  588. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  589. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  590. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  591. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  592. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  593. 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);*/
  594. }
  595. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  596. {
  597. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, -1-i), ho->id);
  598. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, -1-i), ho->id);
  599. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, -1-i), ho->id);
  600. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, -1-i), ho->id);
  601. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 31-i), ho->id);
  602. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 31-i), ho->id);
  603. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 31-i), ho->id);
  604. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 31-i), ho->id);
  605. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, -1-i, 63-i), ho->id);
  606. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 31-i, 63-i), ho->id);
  607. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 63-i, 63-i), ho->id);
  608. subRect(hp.x+1, hp.y+1, hp.z, genRect(32, 32, 95-i, 63-i), ho->id);
  609. /*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);
  610. 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);
  611. 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);
  612. 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);
  613. 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);
  614. 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);
  615. 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);
  616. 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);
  617. 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);
  618. 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);
  619. 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);
  620. 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);*/
  621. }
  622. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  623. {
  624. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1-i), ho->id);
  625. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1-i), ho->id);
  626. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1-i), ho->id);
  627. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31-i), ho->id);
  628. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31-i), ho->id);
  629. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31-i), ho->id);
  630. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 0, 63-i), ho->id);
  631. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 32, 63-i), ho->id);
  632. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 64, 63-i), ho->id);
  633. /*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);
  634. 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);
  635. 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);
  636. 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);
  637. 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);
  638. 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);
  639. 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);
  640. 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);
  641. 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);*/
  642. }
  643. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  644. {
  645. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, -1-i), ho->id);
  646. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, -1-i), ho->id);
  647. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, -1-i), ho->id);
  648. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, -1-i), ho->id);
  649. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 31-i), ho->id);
  650. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 31-i), ho->id);
  651. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 31-i), ho->id);
  652. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 31-i), ho->id);
  653. subRect(hp.x-3, hp.y+1, hp.z, genRect(32, 32, -31+i, 63-i), ho->id);
  654. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 1+i, 63-i), ho->id);
  655. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 33+i, 63-i), ho->id);
  656. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 65+i, 63-i), ho->id);
  657. /*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);
  658. 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);
  659. 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);
  660. 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);
  661. 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);
  662. 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);
  663. 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);
  664. 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);
  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. }
  670. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  671. {
  672. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 0), ho->id);
  673. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 0), ho->id);
  674. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 0), ho->id);
  675. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 0), ho->id);
  676. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 32), ho->id);
  677. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 32), ho->id);
  678. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 32), ho->id);
  679. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 32), ho->id);
  680. /*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);
  681. 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);
  682. 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);
  683. 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);
  684. 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);
  685. 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);
  686. 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);
  687. 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);*/
  688. }
  689. LOCPLINT->adventureInt->update(); //updating screen
  690. CGI->screenh->updateScreen();
  691. LOCPLINT->adventureInt->anim++;
  692. SDL_framerateDelay(mainFPSmng); //for animation purposes
  693. } //for(int i=1; i<32; i+=4)
  694. //main moving done
  695. //finishing move
  696. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  697. {
  698. delObjRect(hp.x, hp.y-2, hp.z, ho->id);
  699. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  700. delObjRect(hp.x, hp.y, hp.z, ho->id);
  701. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  702. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  703. delObjRect(hp.x-3, hp.y, hp.z, ho->id);
  704. }
  705. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  706. {
  707. delObjRect(hp.x, hp.y, hp.z, ho->id);
  708. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  709. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  710. }
  711. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  712. {
  713. delObjRect(hp.x-2, hp.y-2, hp.z, ho->id);
  714. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  715. delObjRect(hp.x+1, hp.y, hp.z, ho->id);
  716. delObjRect(hp.x, hp.y, hp.z, ho->id);
  717. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  718. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  719. }
  720. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  721. {
  722. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  723. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  724. }
  725. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  726. {
  727. delObjRect(hp.x-2, hp.y+1, hp.z, ho->id);
  728. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  729. delObjRect(hp.x+1, hp.y-1, hp.z, ho->id);
  730. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  731. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  732. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  733. }
  734. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  735. {
  736. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  737. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  738. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  739. }
  740. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  741. {
  742. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  743. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  744. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  745. delObjRect(hp.x-3, hp.y-1, hp.z, ho->id);
  746. delObjRect(hp.x, hp.y, hp.z, ho->id);
  747. delObjRect(hp.x, hp.y+1, hp.z, ho->id);
  748. }
  749. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  750. {
  751. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  752. delObjRect(hp.x, hp.y, hp.z, ho->id);
  753. }
  754. ho->pos = details.dst; //copy of hero's position
  755. //ho->moveDir = 0; //move ended
  756. ho->isStanding = true;
  757. //move finished
  758. adventureInt->heroList.draw();
  759. }
  760. void CPlayerInterface::heroKilled(const CHeroInstance * hero)
  761. {
  762. }
  763. void CPlayerInterface::heroCreated(const CHeroInstance * hero)
  764. {
  765. }
  766. 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*
  767. {
  768. if (specific)
  769. ;//TODO: dorobic, ale w ogole to moze lepiej najpierw zastapic tego voida czym innym
  770. else
  771. {
  772. if (adventureInt->selection.type == HEROI_TYPE)
  773. {
  774. char * buf = new char[10];
  775. SDL_Surface * ret = copySurface(hInfo);
  776. SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
  777. blueToPlayersAdv(ret,playerID,1);
  778. const CHeroInstance * curh = (const CHeroInstance *)adventureInt->selection.selected;
  779. printAt(curh->name,75,15,GEOR13,zwykly,ret);
  780. for (int i=0;i<PRIMARY_SKILLS;i++)
  781. {
  782. itoa(curh->primSkills[i],buf,10);
  783. printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
  784. }
  785. for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
  786. {
  787. blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
  788. itoa((*i).second.second,buf,10);
  789. printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
  790. }
  791. blitAt(curh->type->portraitLarge,11,12,ret);
  792. itoa(curh->mana,buf,10);
  793. printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points
  794. delete buf;
  795. blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret);
  796. blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret);
  797. //SDL_SaveBMP(ret,"inf1.bmp");
  798. return ret;
  799. }
  800. else if (adventureInt->selection.type == TOWNI_TYPE)
  801. {
  802. char * buf = new char[10];
  803. SDL_Surface * ret = copySurface(hInfo);
  804. return ret;
  805. }
  806. else
  807. return NULL;
  808. }
  809. return NULL;
  810. }
  811. void CPlayerInterface::handleEvent(SDL_Event *sEvent)
  812. {
  813. current = sEvent;
  814. if(sEvent->type == SDL_MOUSEMOTION)
  815. {
  816. CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
  817. }
  818. if(sEvent->type==SDL_QUIT)
  819. exit(0);
  820. else if (sEvent->type==SDL_KEYDOWN)
  821. {
  822. switch (sEvent->key.keysym.sym)
  823. {
  824. case SDLK_LEFT:
  825. {
  826. LOCPLINT->adventureInt->scrollingLeft = true;
  827. break;
  828. }
  829. case (SDLK_RIGHT):
  830. {
  831. LOCPLINT->adventureInt->scrollingRight = true;
  832. break;
  833. }
  834. case (SDLK_UP):
  835. {
  836. LOCPLINT->adventureInt->scrollingUp = true;
  837. break;
  838. }
  839. case (SDLK_DOWN):
  840. {
  841. LOCPLINT->adventureInt->scrollingDown = true;
  842. break;
  843. }
  844. case (SDLK_q):
  845. {
  846. exit(0);
  847. break;
  848. }
  849. case (SDLK_u):
  850. {
  851. adventureInt->underground.clickLeft(true);
  852. }
  853. }
  854. } //keydown end
  855. else if(sEvent->type==SDL_KEYUP)
  856. {
  857. switch (sEvent->key.keysym.sym)
  858. {
  859. case SDLK_LEFT:
  860. {
  861. LOCPLINT->adventureInt->scrollingLeft = false;
  862. break;
  863. }
  864. case (SDLK_RIGHT):
  865. {
  866. LOCPLINT->adventureInt->scrollingRight = false;
  867. break;
  868. }
  869. case (SDLK_UP):
  870. {
  871. LOCPLINT->adventureInt->scrollingUp = false;
  872. break;
  873. }
  874. case (SDLK_DOWN):
  875. {
  876. LOCPLINT->adventureInt->scrollingDown = false;
  877. break;
  878. }
  879. case (SDLK_u):
  880. {
  881. adventureInt->underground.clickLeft(false);
  882. }
  883. }
  884. }//keyup end
  885. else if(sEvent->type==SDL_MOUSEMOTION)
  886. {
  887. for (int i=0; i<hoverable.size();i++)
  888. {
  889. if (isItIn(&hoverable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  890. {
  891. if (!hoverable[i]->hovered)
  892. hoverable[i]->hover(true);
  893. }
  894. else if (hoverable[i]->hovered)
  895. {
  896. hoverable[i]->hover(false);
  897. }
  898. }
  899. for(int i=0; i<motioninterested.size();i++)
  900. {
  901. if (isItIn(&motioninterested[i]->pos,sEvent->motion.x,sEvent->motion.y))
  902. {
  903. motioninterested[i]->mouseMoved(sEvent->motion);
  904. }
  905. }
  906. if(sEvent->motion.x<15)
  907. {
  908. LOCPLINT->adventureInt->scrollingLeft = true;
  909. }
  910. else
  911. {
  912. LOCPLINT->adventureInt->scrollingLeft = false;
  913. }
  914. if(sEvent->motion.x>ekran->w-15)
  915. {
  916. LOCPLINT->adventureInt->scrollingRight = true;
  917. }
  918. else
  919. {
  920. LOCPLINT->adventureInt->scrollingRight = false;
  921. }
  922. if(sEvent->motion.y<15)
  923. {
  924. LOCPLINT->adventureInt->scrollingUp = true;
  925. }
  926. else
  927. {
  928. LOCPLINT->adventureInt->scrollingUp = false;
  929. }
  930. if(sEvent->motion.y>ekran->h-15)
  931. {
  932. LOCPLINT->adventureInt->scrollingDown = true;
  933. }
  934. else
  935. {
  936. LOCPLINT->adventureInt->scrollingDown = false;
  937. }
  938. } //mousemotion end
  939. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT))
  940. {
  941. for(int i=0; i<lclickable.size();i++)
  942. {
  943. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  944. {
  945. lclickable[i]->clickLeft(true);
  946. }
  947. }
  948. }
  949. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
  950. {
  951. for(int i=0; i<lclickable.size();i++)
  952. {
  953. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  954. {
  955. lclickable[i]->clickLeft(false);
  956. }
  957. else
  958. lclickable[i]->clickLeft(boost::logic::indeterminate);
  959. }
  960. }
  961. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  962. {
  963. for(int i=0; i<rclickable.size();i++)
  964. {
  965. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  966. {
  967. rclickable[i]->clickRight(true);
  968. }
  969. }
  970. }
  971. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  972. {
  973. for(int i=0; i<rclickable.size();i++)
  974. {
  975. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  976. {
  977. rclickable[i]->clickRight(false);
  978. }
  979. else
  980. rclickable[i]->clickRight(boost::logic::indeterminate);
  981. }
  982. }
  983. current = NULL;
  984. } //event end
  985. int3 CPlayerInterface::repairScreenPos(int3 pos)
  986. {
  987. if(pos.x<=-Woff)
  988. pos.x = -Woff+1;
  989. if(pos.y<=-Hoff)
  990. pos.y = -Hoff+1;
  991. if(pos.x>CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff)
  992. pos.x = CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff;
  993. if(pos.y>CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff)
  994. pos.y = CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff;
  995. return pos;
  996. }