CPlayerInterface.cpp 59 KB

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