CPlayerInterface.cpp 55 KB

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