CPlayerInterface.cpp 58 KB

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