CGameInterface.cpp 51 KB

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