CPlayerInterface.cpp 59 KB

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