CPlayerInterface.cpp 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  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(ICallback * CB)
  279. {
  280. cb = dynamic_cast<CCallback*>(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_Flip(ekran);
  361. CSDL_Ext::update(ekran);
  362. SDL_Delay(5); //give time for other apps
  363. SDL_framerateDelay(mainFPSmng);
  364. }
  365. adventureInt->hide();
  366. }
  367. inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, const int & hid)
  368. {
  369. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  370. for(int h=0; h<hlp.objects.size(); ++h)
  371. if(hlp.objects[h].first->id==hid)
  372. {
  373. hlp.objects[h].second.first = r;
  374. return;
  375. }
  376. }
  377. inline void delObjRect(const int & x, const int & y, const int & z, const int & hid)
  378. {
  379. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  380. for(int h=0; h<hlp.objects.size(); ++h)
  381. if(hlp.objects[h].first->id==hid)
  382. {
  383. hlp.objects.erase(hlp.objects.begin()+h);
  384. return;
  385. }
  386. }
  387. int getDir(int3 src, int3 dst)
  388. {
  389. int ret = -1;
  390. if(dst.x+1 == src.x && dst.y+1 == src.y) //tl
  391. {
  392. ret = 1;
  393. }
  394. else if(dst.x == src.x && dst.y+1 == src.y) //t
  395. {
  396. ret = 2;
  397. }
  398. else if(dst.x-1 == src.x && dst.y+1 == src.y) //tr
  399. {
  400. ret = 3;
  401. }
  402. else if(dst.x-1 == src.x && dst.y == src.y) //r
  403. {
  404. ret = 4;
  405. }
  406. else if(dst.x-1 == src.x && dst.y-1 == src.y) //br
  407. {
  408. ret = 5;
  409. }
  410. else if(dst.x == src.x && dst.y-1 == src.y) //b
  411. {
  412. ret = 6;
  413. }
  414. else if(dst.x+1 == src.x && dst.y-1 == src.y) //bl
  415. {
  416. ret = 7;
  417. }
  418. else if(dst.x+1 == src.x && dst.y == src.y) //l
  419. {
  420. ret = 8;
  421. }
  422. return ret;
  423. }
  424. void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
  425. {
  426. //initializing objects and performing first step of move
  427. CGHeroInstance * ho = details.ho; //object representing this hero
  428. int3 hp = details.src;
  429. if (!details.successful)
  430. {
  431. ho->moveDir = getDir(details.src,details.dst);
  432. ho->isStanding = true;
  433. adventureInt->heroList.draw();
  434. if (adventureInt->terrain.currentPath)
  435. {
  436. delete adventureInt->terrain.currentPath;
  437. adventureInt->terrain.currentPath = NULL;
  438. }
  439. return;
  440. }
  441. if (adventureInt->terrain.currentPath) //&& hero is moving
  442. {
  443. adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
  444. }
  445. int3 buff = details.ho->pos;
  446. buff.x-=11;
  447. buff.y-=9;
  448. buff = repairScreenPos(buff);
  449. LOCPLINT->adventureInt->position = buff; //actualizing screen pos
  450. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  451. {
  452. ho->moveDir = 1;
  453. ho->isStanding = false;
  454. 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>>())));
  455. 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>>())));
  456. 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>>())));
  457. 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>>())));
  458. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 1), std::vector<std::list<int3>>())));
  459. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 1), ho->id);
  460. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 1), ho->id);
  461. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 1), ho->id);
  462. 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>>())));
  463. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 33), ho->id);
  464. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 33), ho->id);
  465. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 33), ho->id);
  466. 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);
  467. 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);
  468. 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);
  469. 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);
  470. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  471. //std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  472. //std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  473. //std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  474. 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);
  475. //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);
  476. //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);
  477. //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);
  478. }
  479. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  480. {
  481. ho->moveDir = 2;
  482. ho->isStanding = false;
  483. 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>>())));
  484. 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>>())));
  485. 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>>())));
  486. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1), ho->id);
  487. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1), ho->id);
  488. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1), ho->id);
  489. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33), ho->id);
  490. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33), ho->id);
  491. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33), ho->id);
  492. 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);
  493. 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);
  494. 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);
  495. //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);
  496. //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);
  497. //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);
  498. //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);
  499. //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);
  500. //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);
  501. }
  502. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  503. {
  504. ho->moveDir = 3;
  505. ho->isStanding = false;
  506. 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>>())));
  507. 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>>())));
  508. 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>>())));
  509. 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>>())));
  510. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 1), ho->id);
  511. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 1), ho->id);
  512. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 1), ho->id);
  513. 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>>())));
  514. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 33), ho->id);
  515. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 33), ho->id);
  516. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 33), ho->id);
  517. 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>>())));
  518. 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);
  519. 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);
  520. 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);
  521. 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);
  522. //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);
  523. //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);
  524. //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);
  525. 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);
  526. //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);
  527. //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);
  528. //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);
  529. 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);
  530. }
  531. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  532. {
  533. ho->moveDir = 4;
  534. ho->isStanding = false;
  535. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id);
  536. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id);
  537. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id);
  538. 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>>())));
  539. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 32), ho->id);
  540. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 32), ho->id);
  541. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 32), ho->id);
  542. 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>>())));
  543. //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);
  544. //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);
  545. //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);
  546. 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);
  547. //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);
  548. //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);
  549. //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);
  550. 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);
  551. }
  552. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  553. {
  554. ho->moveDir = 5;
  555. ho->isStanding = false;
  556. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, -1), ho->id);
  557. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, -1), ho->id);
  558. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id);
  559. 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>>())));
  560. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 31), ho->id);
  561. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 31), ho->id);
  562. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 31), ho->id);
  563. 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>>())));
  564. 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>>())));
  565. 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>>())));
  566. 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>>())));
  567. 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>>())));
  568. //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);
  569. //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);
  570. //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);
  571. 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);
  572. //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);
  573. //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);
  574. //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);
  575. 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);
  576. 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);
  577. 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);
  578. 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);
  579. 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);
  580. }
  581. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  582. {
  583. ho->moveDir = 6;
  584. ho->isStanding = false;
  585. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1), ho->id);
  586. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1), ho->id);
  587. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1), ho->id);
  588. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31), ho->id);
  589. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31), ho->id);
  590. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31), ho->id);
  591. 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>>())));
  592. 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>>())));
  593. 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>>())));
  594. //std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  595. //std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  596. //std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  597. //std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  598. //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);
  599. //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);
  600. 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);
  601. 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);
  602. 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);
  603. }
  604. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  605. {
  606. ho->moveDir = 7;
  607. ho->isStanding = false;
  608. 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>>())));
  609. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id);
  610. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id);
  611. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, -1), ho->id);
  612. 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>>())));
  613. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 31), ho->id);
  614. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 31), ho->id);
  615. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 31), ho->id);
  616. 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>>())));
  617. 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>>())));
  618. 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>>())));
  619. 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>>())));
  620. 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);
  621. //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);
  622. //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);
  623. //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);
  624. 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);
  625. //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);
  626. //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);
  627. //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);
  628. 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);
  629. 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);
  630. 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);
  631. 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);
  632. }
  633. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  634. {
  635. ho->moveDir = 8;
  636. ho->isStanding = false;
  637. 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>>())));
  638. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id);
  639. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id);
  640. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 0), ho->id);
  641. 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>>())));
  642. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 32), ho->id);
  643. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 32), ho->id);
  644. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 32), ho->id);
  645. 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);
  646. //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);
  647. //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);
  648. //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);
  649. 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);
  650. //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);
  651. //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);
  652. //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);
  653. }
  654. //first initializing done
  655. SDL_framerateDelay(mainFPSmng); // after first move
  656. //main moving
  657. for(int i=1; i<32; i+=4)
  658. {
  659. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  660. {
  661. subRect(hp.x-3, hp.y-2, hp.z, genRect(32, 32, -31+i, -31+i), ho->id);
  662. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 1+i, -31+i), ho->id);
  663. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 33+i, -31+i), ho->id);
  664. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 65+i, -31+i), ho->id);
  665. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 1+i), ho->id);
  666. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 1+i), ho->id);
  667. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 1+i), ho->id);
  668. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 1+i), ho->id);
  669. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 33+i), ho->id);
  670. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 33+i), ho->id);
  671. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 33+i), ho->id);
  672. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 33+i), ho->id);
  673. /*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);
  674. 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);
  675. 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);
  676. 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);
  677. 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);
  678. 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);
  679. 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);
  680. 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);
  681. 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);
  682. 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);
  683. 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);
  684. 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);*/
  685. }
  686. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  687. {
  688. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 0, -31+i), ho->id);
  689. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 32, -31+i), ho->id);
  690. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 64, -31+i), ho->id);
  691. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1+i), ho->id);
  692. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1+i), ho->id);
  693. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1+i), ho->id);
  694. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33+i), ho->id);
  695. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33+i), ho->id);
  696. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33+i), ho->id);
  697. /*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);
  698. 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);
  699. 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);
  700. 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);
  701. 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);
  702. 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);
  703. 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);
  704. 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);
  705. 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);*/
  706. }
  707. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  708. {
  709. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, -1-i, -31+i), ho->id);
  710. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 31-i, -31+i), ho->id);
  711. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 63-i, -31+i), ho->id);
  712. subRect(hp.x+1, hp.y-2, hp.z, genRect(32, 32, 95-i, -31+i), ho->id);
  713. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 1+i), ho->id);
  714. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 1+i), ho->id);
  715. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 1+i), ho->id);
  716. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 1+i), ho->id);
  717. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 33+i), ho->id);
  718. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 33+i), ho->id);
  719. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 33+i), ho->id);
  720. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 33+i), ho->id);
  721. /*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);
  722. 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);
  723. 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);
  724. 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);
  725. 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);
  726. 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);
  727. 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);
  728. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  729. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  730. 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);
  731. 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);
  732. 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);*/
  733. }
  734. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  735. {
  736. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 0), ho->id);
  737. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 0), ho->id);
  738. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 0), ho->id);
  739. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 0), ho->id);
  740. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 32), ho->id);
  741. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 32), ho->id);
  742. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 32), ho->id);
  743. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 32), ho->id);
  744. /*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);
  745. 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);
  746. 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);
  747. 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);
  748. 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);
  749. 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);
  750. 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);
  751. 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);*/
  752. }
  753. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  754. {
  755. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, -1-i), ho->id);
  756. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, -1-i), ho->id);
  757. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, -1-i), ho->id);
  758. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, -1-i), ho->id);
  759. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 31-i), ho->id);
  760. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 31-i), ho->id);
  761. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 31-i), ho->id);
  762. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 31-i), ho->id);
  763. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, -1-i, 63-i), ho->id);
  764. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 31-i, 63-i), ho->id);
  765. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 63-i, 63-i), ho->id);
  766. subRect(hp.x+1, hp.y+1, hp.z, genRect(32, 32, 95-i, 63-i), ho->id);
  767. /*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);
  768. 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);
  769. 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);
  770. 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);
  771. 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);
  772. 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);
  773. 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);
  774. 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);
  775. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  776. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  777. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  778. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);*/
  779. }
  780. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  781. {
  782. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1-i), ho->id);
  783. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1-i), ho->id);
  784. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1-i), ho->id);
  785. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31-i), ho->id);
  786. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31-i), ho->id);
  787. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31-i), ho->id);
  788. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 0, 63-i), ho->id);
  789. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 32, 63-i), ho->id);
  790. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 64, 63-i), ho->id);
  791. /*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);
  792. 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);
  793. 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);
  794. 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);
  795. 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);
  796. 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);
  797. 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);
  798. 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);
  799. 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);*/
  800. }
  801. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  802. {
  803. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, -1-i), ho->id);
  804. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, -1-i), ho->id);
  805. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, -1-i), ho->id);
  806. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, -1-i), ho->id);
  807. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 31-i), ho->id);
  808. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 31-i), ho->id);
  809. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 31-i), ho->id);
  810. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 31-i), ho->id);
  811. subRect(hp.x-3, hp.y+1, hp.z, genRect(32, 32, -31+i, 63-i), ho->id);
  812. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 1+i, 63-i), ho->id);
  813. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 33+i, 63-i), ho->id);
  814. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 65+i, 63-i), ho->id);
  815. /*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);
  816. 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);
  817. 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);
  818. 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);
  819. 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);
  820. 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);
  821. 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);
  822. 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);
  823. 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);
  824. 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);
  825. 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);
  826. 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);*/
  827. }
  828. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  829. {
  830. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 0), ho->id);
  831. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 0), ho->id);
  832. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 0), ho->id);
  833. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 0), ho->id);
  834. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 32), ho->id);
  835. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 32), ho->id);
  836. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 32), ho->id);
  837. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 32), ho->id);
  838. /*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);
  839. 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);
  840. 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);
  841. 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);
  842. 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);
  843. 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);
  844. 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);
  845. 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);*/
  846. }
  847. LOCPLINT->adventureInt->update(); //updating screen
  848. CSDL_Ext::update(ekran);
  849. CGI->screenh->updateScreen();
  850. LOCPLINT->adventureInt->anim++;
  851. SDL_framerateDelay(mainFPSmng); //for animation purposes
  852. } //for(int i=1; i<32; i+=4)
  853. //main moving done
  854. //finishing move
  855. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  856. {
  857. delObjRect(hp.x, hp.y-2, hp.z, ho->id);
  858. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  859. delObjRect(hp.x, hp.y, hp.z, ho->id);
  860. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  861. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  862. delObjRect(hp.x-3, hp.y, hp.z, ho->id);
  863. }
  864. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  865. {
  866. delObjRect(hp.x, hp.y, hp.z, ho->id);
  867. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  868. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  869. }
  870. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  871. {
  872. delObjRect(hp.x-2, hp.y-2, hp.z, ho->id);
  873. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  874. delObjRect(hp.x+1, hp.y, hp.z, ho->id);
  875. delObjRect(hp.x, hp.y, hp.z, ho->id);
  876. delObjRect(hp.x-1, hp.y, 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 == details.src.y) //r
  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. }
  884. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  885. {
  886. delObjRect(hp.x-2, hp.y+1, hp.z, ho->id);
  887. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  888. delObjRect(hp.x+1, hp.y-1, hp.z, ho->id);
  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. }
  893. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  894. {
  895. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  896. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  897. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  898. }
  899. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  900. {
  901. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  902. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  903. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  904. delObjRect(hp.x-3, hp.y-1, hp.z, ho->id);
  905. delObjRect(hp.x, hp.y, hp.z, ho->id);
  906. delObjRect(hp.x, hp.y+1, hp.z, ho->id);
  907. }
  908. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  909. {
  910. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  911. delObjRect(hp.x, hp.y, hp.z, ho->id);
  912. }
  913. ho->pos = details.dst; //copy of hero's position
  914. //ho->moveDir = 0; //move ended
  915. ho->isStanding = true;
  916. //move finished
  917. CGI->mh->recalculateHideVisPosUnderObj(details.ho, true);
  918. adventureInt->minimap.draw();
  919. adventureInt->heroList.updateMove(ho);
  920. }
  921. void CPlayerInterface::heroKilled(const CGHeroInstance*)
  922. {
  923. }
  924. void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
  925. {
  926. }
  927. 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*
  928. {
  929. if (specific)
  930. ;//TODO: dorobic, ale w ogole to moze lepiej najpierw zastapic tego voida czym innym
  931. else
  932. {
  933. if (adventureInt->selection.type == HEROI_TYPE)
  934. {
  935. char * buf = new char[10];
  936. SDL_Surface * ret = copySurface(hInfo);
  937. SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
  938. blueToPlayersAdv(ret,playerID,1);
  939. const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection.selected;
  940. printAt(curh->name,75,15,GEOR13,zwykly,ret);
  941. for (int i=0;i<PRIMARY_SKILLS;i++)
  942. {
  943. itoa(curh->primSkills[i],buf,10);
  944. printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
  945. }
  946. for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
  947. {
  948. blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
  949. itoa((*i).second.second,buf,10);
  950. printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
  951. }
  952. blitAt(curh->type->portraitLarge,11,12,ret);
  953. itoa(curh->mana,buf,10);
  954. printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points
  955. delete buf;
  956. blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret);
  957. blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret);
  958. //SDL_SaveBMP(ret,"inf1.bmp");
  959. return ret;
  960. }
  961. else if (adventureInt->selection.type == TOWNI_TYPE)
  962. {
  963. char * buf = new char[10];
  964. SDL_Surface * ret = copySurface(hInfo);
  965. return ret;
  966. }
  967. else
  968. return NULL;
  969. }
  970. return NULL;
  971. }
  972. void CPlayerInterface::handleEvent(SDL_Event *sEvent)
  973. {
  974. current = sEvent;
  975. if(sEvent->type == SDL_MOUSEMOTION)
  976. {
  977. CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
  978. }
  979. if(sEvent->type==SDL_QUIT)
  980. exit(0);
  981. else if (sEvent->type==SDL_KEYDOWN)
  982. {
  983. switch (sEvent->key.keysym.sym)
  984. {
  985. case SDLK_LEFT:
  986. {
  987. LOCPLINT->adventureInt->scrollingLeft = true;
  988. break;
  989. }
  990. case (SDLK_RIGHT):
  991. {
  992. LOCPLINT->adventureInt->scrollingRight = true;
  993. break;
  994. }
  995. case (SDLK_UP):
  996. {
  997. LOCPLINT->adventureInt->scrollingUp = true;
  998. break;
  999. }
  1000. case (SDLK_DOWN):
  1001. {
  1002. LOCPLINT->adventureInt->scrollingDown = true;
  1003. break;
  1004. }
  1005. case (SDLK_q):
  1006. {
  1007. exit(0);
  1008. break;
  1009. }
  1010. case (SDLK_u):
  1011. {
  1012. adventureInt->underground.clickLeft(true);
  1013. }
  1014. }
  1015. } //keydown end
  1016. else if(sEvent->type==SDL_KEYUP)
  1017. {
  1018. switch (sEvent->key.keysym.sym)
  1019. {
  1020. case SDLK_LEFT:
  1021. {
  1022. LOCPLINT->adventureInt->scrollingLeft = false;
  1023. break;
  1024. }
  1025. case (SDLK_RIGHT):
  1026. {
  1027. LOCPLINT->adventureInt->scrollingRight = false;
  1028. break;
  1029. }
  1030. case (SDLK_UP):
  1031. {
  1032. LOCPLINT->adventureInt->scrollingUp = false;
  1033. break;
  1034. }
  1035. case (SDLK_DOWN):
  1036. {
  1037. LOCPLINT->adventureInt->scrollingDown = false;
  1038. break;
  1039. }
  1040. case (SDLK_u):
  1041. {
  1042. adventureInt->underground.clickLeft(false);
  1043. }
  1044. }
  1045. }//keyup end
  1046. else if(sEvent->type==SDL_MOUSEMOTION)
  1047. {
  1048. for (int i=0; i<hoverable.size();i++)
  1049. {
  1050. if (isItIn(&hoverable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1051. {
  1052. if (!hoverable[i]->hovered)
  1053. hoverable[i]->hover(true);
  1054. }
  1055. else if (hoverable[i]->hovered)
  1056. {
  1057. hoverable[i]->hover(false);
  1058. }
  1059. }
  1060. for(int i=0; i<motioninterested.size();i++)
  1061. {
  1062. if (isItIn(&motioninterested[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1063. {
  1064. motioninterested[i]->mouseMoved(sEvent->motion);
  1065. }
  1066. }
  1067. if(sEvent->motion.x<15)
  1068. {
  1069. LOCPLINT->adventureInt->scrollingLeft = true;
  1070. }
  1071. else
  1072. {
  1073. LOCPLINT->adventureInt->scrollingLeft = false;
  1074. }
  1075. if(sEvent->motion.x>ekran->w-15)
  1076. {
  1077. LOCPLINT->adventureInt->scrollingRight = true;
  1078. }
  1079. else
  1080. {
  1081. LOCPLINT->adventureInt->scrollingRight = false;
  1082. }
  1083. if(sEvent->motion.y<15)
  1084. {
  1085. LOCPLINT->adventureInt->scrollingUp = true;
  1086. }
  1087. else
  1088. {
  1089. LOCPLINT->adventureInt->scrollingUp = false;
  1090. }
  1091. if(sEvent->motion.y>ekran->h-15)
  1092. {
  1093. LOCPLINT->adventureInt->scrollingDown = true;
  1094. }
  1095. else
  1096. {
  1097. LOCPLINT->adventureInt->scrollingDown = false;
  1098. }
  1099. } //mousemotion end
  1100. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1101. {
  1102. LOGE("Left mouse button down1");
  1103. for(int i=0; i<lclickable.size();i++)
  1104. {
  1105. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1106. {
  1107. lclickable[i]->clickLeft(true);
  1108. }
  1109. }
  1110. }
  1111. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1112. {
  1113. for(int i=0; i<lclickable.size();i++)
  1114. {
  1115. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1116. {
  1117. lclickable[i]->clickLeft(false);
  1118. }
  1119. else
  1120. lclickable[i]->clickLeft(boost::logic::indeterminate);
  1121. }
  1122. }
  1123. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1124. {
  1125. for(int i=0; i<rclickable.size();i++)
  1126. {
  1127. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1128. {
  1129. rclickable[i]->clickRight(true);
  1130. }
  1131. }
  1132. }
  1133. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1134. {
  1135. for(int i=0; i<rclickable.size();i++)
  1136. {
  1137. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1138. {
  1139. rclickable[i]->clickRight(false);
  1140. }
  1141. else
  1142. rclickable[i]->clickRight(boost::logic::indeterminate);
  1143. }
  1144. }
  1145. current = NULL;
  1146. } //event end
  1147. int3 CPlayerInterface::repairScreenPos(int3 pos)
  1148. {
  1149. if(pos.x<=-Woff)
  1150. pos.x = -Woff+1;
  1151. if(pos.y<=-Hoff)
  1152. pos.y = -Hoff+1;
  1153. if(pos.x>CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff)
  1154. pos.x = CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff;
  1155. if(pos.y>CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff)
  1156. pos.y = CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff;
  1157. return pos;
  1158. }
  1159. void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)
  1160. {
  1161. if (adventureInt->selection.selected == hero)
  1162. adventureInt->infoBar.draw();
  1163. return;
  1164. }
  1165. void CPlayerInterface::receivedResource(int type, int val)
  1166. {
  1167. adventureInt->resdatabar.draw();
  1168. }
  1169. void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*> & components)
  1170. {
  1171. adventureInt->hide(); //dezaktywacja starego interfejsu
  1172. CInfoWindow * temp = CMessage::genIWindow(text,LOCPLINT->playerID,32,components);
  1173. LOCPLINT->objsToBlit.push_back(temp);
  1174. temp->pos.x=300-(temp->pos.w/2);
  1175. temp->pos.y=300-(temp->pos.h/2);
  1176. temp->okb.pos.x = temp->okb.posr.x + temp->pos.x;
  1177. temp->okb.pos.y = temp->okb.posr.y + temp->pos.y;
  1178. temp->okb.activate();
  1179. for (int i=0;i<temp->components.size();i++)
  1180. {
  1181. temp->components[i]->activate();
  1182. temp->components[i]->pos.x += temp->pos.x;
  1183. temp->components[i]->pos.y += temp->pos.y;
  1184. }
  1185. }
  1186. void CPlayerInterface::removeObjToBlit(IShowable* obj)
  1187. {
  1188. objsToBlit.erase
  1189. (std::find(objsToBlit.begin(),objsToBlit.end(),obj));
  1190. //delete obj;
  1191. }
  1192. void CPlayerInterface::tileRevealed(int3 pos)
  1193. {
  1194. adventureInt->minimap.showTile(pos);
  1195. }
  1196. void CPlayerInterface::tileHidden(int3 pos)
  1197. {
  1198. adventureInt->minimap.hideTile(pos);
  1199. }