CPlayerInterface.cpp 59 KB

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