CGameInterface.cpp 52 KB

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