CPlayerInterface.cpp 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497
  1. #include "stdafx.h"
  2. #include "CPlayerInterface.h"
  3. #include "CAdvMapInterface.h"
  4. #include "CMessage.h"
  5. #include "mapHandler.h"
  6. #include "SDL_Extensions.h"
  7. #include "SDL_framerate.h"
  8. #include "CScreenHandler.h"
  9. #include "CCursorHandler.h"
  10. #include "CCallback.h"
  11. #include "SDL_Extensions.h"
  12. #include "hch/CLodHandler.h"
  13. #include "CPathfinder.h"
  14. #include <sstream>
  15. #include "hch/CHeroHandler.h"
  16. #include "SDL_framerate.h"
  17. #include "hch/CGeneralTextHandler.h"
  18. using namespace CSDL_Ext;
  19. class OCM_HLP_CGIN
  20. {
  21. public:
  22. bool operator ()(const std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> & a, const std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> & b) const
  23. {
  24. return (*a.first)<(*b.first);
  25. }
  26. } ocmptwo_cgin ;
  27. CInfoWindow::CInfoWindow()
  28. :okb(NMessage::ok,NULL,&CInfoWindow::okClicked)
  29. {
  30. okb.ourObj = this;
  31. okb.delg = this;
  32. }
  33. void CInfoWindow::okClicked(tribool down)
  34. {
  35. if (!down)
  36. close();
  37. }
  38. void CInfoWindow::close()
  39. {
  40. for (int i=0;i<components.size();i++)
  41. {
  42. components[i]->deactivate();
  43. delete components[i];
  44. }
  45. components.clear();
  46. okb.deactivate();
  47. SDL_FreeSurface(bitmap);
  48. bitmap = NULL;
  49. LOCPLINT->removeObjToBlit(this);
  50. //delete this;
  51. LOCPLINT->adventureInt->show();
  52. }
  53. CInfoWindow::~CInfoWindow()
  54. {
  55. }
  56. SComponent::SComponent(Etype Type, int Subtype, int Val)
  57. {
  58. std::ostringstream oss;
  59. switch (Type)
  60. {
  61. case primskill:
  62. description = CGI->generaltexth->arraytxt[2+Subtype];
  63. oss << ((Val>0)?("+"):("-")) << Val << " " << CGI->heroh->pskillsn[Subtype];
  64. subtitle = oss.str();
  65. break;
  66. case resource:
  67. description = CGI->generaltexth->allTexts[242];
  68. oss << Val;
  69. subtitle = oss.str();
  70. break;
  71. case experience:
  72. description = CGI->generaltexth->allTexts[241];
  73. oss << Val ;
  74. subtitle = oss.str();
  75. break;
  76. }
  77. type = Type;
  78. subtype = Subtype;
  79. val = Val;
  80. SDL_Surface * temp = getImg();
  81. pos.w = temp->w;
  82. pos.h = temp->h;
  83. }
  84. SDL_Surface * SComponent::getImg()
  85. {
  86. switch (type)
  87. {
  88. case primskill:
  89. return CGI->heroh->pskillsb->ourImages[subtype].bitmap;
  90. break;
  91. case resource:
  92. return CGI->heroh->resources->ourImages[subtype].bitmap;
  93. break;
  94. case experience:
  95. return CGI->heroh->pskillsb->ourImages[4].bitmap;
  96. break;
  97. }
  98. return NULL;
  99. }
  100. void SComponent::clickRight (tribool down)
  101. {
  102. LOCPLINT->adventureInt->handleRightClick(description,down,this);
  103. }
  104. void SComponent::activate()
  105. {
  106. ClickableR::activate();
  107. }
  108. void SComponent::deactivate()
  109. {
  110. ClickableR::deactivate();
  111. }
  112. void CSelectableComponent::clickLeft(tribool down)
  113. {
  114. if (down)
  115. {
  116. select(true);
  117. owner->selectionChange(this);
  118. }
  119. }
  120. CSelectableComponent::CSelectableComponent(Etype Type, int Sub, int Val, CSelWindow * Owner, SDL_Surface * Border)
  121. :SComponent(Type,Sub,Val),owner(Owner)
  122. {
  123. if (Border) //use custom border
  124. {
  125. border = Border;
  126. }
  127. else //we need to draw border
  128. {
  129. SDL_Surface * symb = SComponent::getImg();
  130. border = CSDL_Ext::newSurface(symb->w+2,symb->h+2,symb);
  131. SDL_FillRect(border,NULL,0x00FFFF);
  132. for (int i=0;i<border->w;i++)
  133. {
  134. SDL_PutPixel(border,i,0,239,215,123);
  135. SDL_PutPixel(border,i,(border->h)-1,239,215,123);
  136. }
  137. for (int i=0;i<border->h;i++)
  138. {
  139. SDL_PutPixel(border,0,i,239,215,123);
  140. SDL_PutPixel(border,(border->w)-1,i,239,215,123);
  141. }
  142. SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255));
  143. }
  144. selected = false;
  145. }
  146. void CSelectableComponent::activate()
  147. {
  148. SComponent::activate();
  149. ClickableL::activate();
  150. }
  151. void CSelectableComponent::deactivate()
  152. {
  153. SComponent::deactivate();
  154. ClickableL::deactivate();
  155. }
  156. SDL_Surface * CSelectableComponent::getImg()
  157. {
  158. return myBitmap;
  159. }
  160. void CSelectableComponent::select(bool on)
  161. {
  162. if(on != selected)
  163. {
  164. blitAt(SComponent::getImg(),1,1,myBitmap);
  165. if (on)
  166. {
  167. blitAt(border,0,0,myBitmap);
  168. }
  169. selected = on;
  170. return;
  171. }
  172. else
  173. {
  174. return;
  175. }
  176. }
  177. void CSimpleWindow::show(SDL_Surface * to)
  178. {
  179. if(!to)
  180. to=ekran;
  181. blitAt(bitmap,pos.x,pos.y,to);
  182. }
  183. CSimpleWindow::~CSimpleWindow()
  184. {
  185. if (bitmap)
  186. {
  187. SDL_FreeSurface(bitmap);
  188. bitmap=NULL;
  189. }
  190. }
  191. void CSelWindow::selectionChange(SComponent * to)
  192. {
  193. for (int i=0;i<components.size();i++)
  194. {
  195. if(components[i]==to)
  196. continue;
  197. CSelectableComponent * pom = dynamic_cast<CSelectableComponent*>(components[i]);
  198. if (!pom)
  199. continue;
  200. pom->select(false);
  201. }
  202. }
  203. void CSelWindow::okClicked(tribool down)
  204. {
  205. if(!down)
  206. close();
  207. }
  208. void CSelWindow::close()
  209. {
  210. //call owner with selection result
  211. CInfoWindow::close();
  212. }
  213. template <typename T>CSCButton<T>::CSCButton(CDefHandler * img, CIntObject * obj, void(T::*poin)(tribool), T* Delg)
  214. {
  215. ourObj = obj;
  216. delg = Delg;
  217. func = poin;
  218. imgs.resize(1);
  219. for (int i =0; i<img->ourImages.size();i++)
  220. {
  221. imgs[0].push_back(img->ourImages[i].bitmap);
  222. }
  223. pos.w = imgs[0][0]->w;
  224. pos.h = imgs[0][0]->h;
  225. state = 0;
  226. }
  227. template <typename T> void CSCButton<T>::clickLeft (tribool down)
  228. {
  229. if (down)
  230. {
  231. state=1;
  232. }
  233. else
  234. {
  235. state=0;
  236. }
  237. show();
  238. if (delg)
  239. (delg->*func)(down);
  240. pressedL=state;
  241. }
  242. template <typename T> void CSCButton<typename T>::activate()
  243. {
  244. ClickableL::activate();
  245. }
  246. template <typename T> void CSCButton<typename T>::deactivate()
  247. {
  248. ClickableL::deactivate();
  249. }
  250. template <typename T> void CSCButton<typename T>::show(SDL_Surface * to)
  251. {
  252. if (delg) //we blit on our owner's bitmap
  253. {
  254. blitAt(imgs[curimg][state],posr.x,posr.y,delg->bitmap);
  255. //updateRect(&genRect(pos.h,pos.w,posr.x,posr.y),delg->bitmap);
  256. }
  257. else
  258. {
  259. CButtonBase::show(to);
  260. }
  261. }
  262. CButtonBase::CButtonBase()
  263. {
  264. curimg=0;
  265. type=-1;
  266. abs=false;
  267. active=false;
  268. ourObj=NULL;
  269. state=0;
  270. }
  271. void CButtonBase::show(SDL_Surface * to)
  272. {
  273. if(!to)
  274. to=ekran;
  275. if (abs)
  276. {
  277. blitAt(imgs[curimg][state],pos.x,pos.y,to);
  278. //updateRect(&pos,to);
  279. }
  280. else
  281. {
  282. blitAt(imgs[curimg][state],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y,to);
  283. //updateRect(&genRect(pos.h,pos.w,pos.x+ourObj->pos.x,pos.y+ourObj->pos.y),to);
  284. }
  285. }
  286. ClickableL::ClickableL()
  287. {
  288. pressedL=false;
  289. }
  290. void ClickableL::clickLeft(tribool down)
  291. {
  292. if (down)
  293. pressedL=true;
  294. else
  295. pressedL=false;
  296. }
  297. void ClickableL::activate()
  298. {
  299. LOCPLINT->lclickable.push_back(this);
  300. }
  301. void ClickableL::deactivate()
  302. {
  303. LOCPLINT->lclickable.erase
  304. (std::find(LOCPLINT->lclickable.begin(),LOCPLINT->lclickable.end(),this));
  305. }
  306. ClickableR::ClickableR()
  307. {
  308. pressedR=false;
  309. }
  310. void ClickableR::activate()
  311. {
  312. LOCPLINT->rclickable.push_back(this);
  313. }
  314. void ClickableR::deactivate()
  315. {
  316. LOCPLINT->rclickable.erase(std::find(LOCPLINT->rclickable.begin(),LOCPLINT->rclickable.end(),this));
  317. }
  318. void Hoverable::activate()
  319. {
  320. LOCPLINT->hoverable.push_back(this);
  321. }
  322. void Hoverable::deactivate()
  323. {
  324. LOCPLINT->hoverable.erase(std::find(LOCPLINT->hoverable.begin(),LOCPLINT->hoverable.end(),this));
  325. }
  326. void Hoverable::hover(bool on)
  327. {
  328. hovered=on;
  329. }
  330. void KeyInterested::activate()
  331. {
  332. LOCPLINT->keyinterested.push_back(this);
  333. }
  334. void KeyInterested::deactivate()
  335. {
  336. LOCPLINT->
  337. keyinterested.erase(std::find(LOCPLINT->keyinterested.begin(),LOCPLINT->keyinterested.end(),this));
  338. }
  339. void MotionInterested::activate()
  340. {
  341. LOCPLINT->motioninterested.push_back(this);
  342. }
  343. void MotionInterested::deactivate()
  344. {
  345. LOCPLINT->
  346. motioninterested.erase(std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this));
  347. }
  348. void TimeInterested::activate()
  349. {
  350. LOCPLINT->timeinterested.push_back(this);
  351. }
  352. void TimeInterested::deactivate()
  353. {
  354. LOCPLINT->
  355. timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),this));
  356. }
  357. CPlayerInterface::CPlayerInterface(int Player, int serial)
  358. {
  359. playerID=Player;
  360. serialID=serial;
  361. CGI->localPlayer = playerID;
  362. human=true;
  363. hInfo = CGI->bitmaph->loadBitmap("HEROQVBK.bmp");
  364. SDL_SetColorKey(hInfo,SDL_SRCCOLORKEY,SDL_MapRGB(hInfo->format,0,255,255));
  365. slotsPos.push_back(std::pair<int,int>(44,82));
  366. slotsPos.push_back(std::pair<int,int>(80,82));
  367. slotsPos.push_back(std::pair<int,int>(116,82));
  368. slotsPos.push_back(std::pair<int,int>(26,131));
  369. slotsPos.push_back(std::pair<int,int>(62,131));
  370. slotsPos.push_back(std::pair<int,int>(98,131));
  371. slotsPos.push_back(std::pair<int,int>(134,131));
  372. luck22 = CGI->spriteh->giveDefEss("ILCK22.DEF");
  373. luck30 = CGI->spriteh->giveDefEss("ILCK30.DEF");
  374. luck42 = CGI->spriteh->giveDefEss("ILCK42.DEF");
  375. luck82 = CGI->spriteh->giveDefEss("ILCK82.DEF");
  376. morale22 = CGI->spriteh->giveDefEss("IMRL22.DEF");
  377. morale30 = CGI->spriteh->giveDefEss("IMRL30.DEF");
  378. morale42 = CGI->spriteh->giveDefEss("IMRL42.DEF");
  379. morale82 = CGI->spriteh->giveDefEss("IMRL82.DEF");
  380. }
  381. void CPlayerInterface::init(ICallback * CB)
  382. {
  383. cb = dynamic_cast<CCallback*>(CB);
  384. CGI->localPlayer = serialID;
  385. adventureInt = new CAdvMapInt(playerID);
  386. std::vector <const CGHeroInstance *> hh = cb->getHeroesInfo(false);
  387. for(int i=0;i<hh.size();i++)
  388. {
  389. SDL_Surface * pom = infoWin(hh[i]);
  390. heroWins.insert(std::pair<int,SDL_Surface*>(hh[i]->subID,pom));
  391. }
  392. }
  393. void CPlayerInterface::yourTurn()
  394. {
  395. makingTurn = true;
  396. CGI->localPlayer = serialID;
  397. unsigned char & animVal = LOCPLINT->adventureInt->anim; //for animations handling
  398. adventureInt->infoBar.newDay(cb->getDate(1));
  399. adventureInt->show();
  400. //show rest of things
  401. //initializing framerate keeper
  402. mainFPSmng = new FPSmanager;
  403. SDL_initFramerate(mainFPSmng);
  404. SDL_setFramerate(mainFPSmng, 24);
  405. SDL_Event sEvent;
  406. //framerate keeper initialized
  407. timeHandler th;
  408. th.getDif();
  409. for(;makingTurn;) // main loop
  410. {
  411. CGI->screenh->updateScreen();
  412. int tv = th.getDif();
  413. for (int i=0;i<timeinterested.size();i++)
  414. {
  415. if (timeinterested[i]->toNextTick>=0)
  416. timeinterested[i]->toNextTick-=tv;
  417. if (timeinterested[i]->toNextTick<0)
  418. timeinterested[i]->tick();
  419. }
  420. LOCPLINT->adventureInt->updateScreen = false;
  421. while (SDL_PollEvent(&sEvent)) //wait for event...
  422. {
  423. handleEvent(&sEvent);
  424. }
  425. ++LOCPLINT->adventureInt->animValHitCount; //for animations
  426. if(LOCPLINT->adventureInt->animValHitCount == 4)
  427. {
  428. LOCPLINT->adventureInt->animValHitCount = 0;
  429. ++animVal;
  430. LOCPLINT->adventureInt->updateScreen = true;
  431. }
  432. if(LOCPLINT->adventureInt->scrollingLeft)
  433. {
  434. if(LOCPLINT->adventureInt->position.x>-Woff)
  435. {
  436. LOCPLINT->adventureInt->position.x--;
  437. LOCPLINT->adventureInt->updateScreen = true;
  438. adventureInt->updateMinimap=true;
  439. }
  440. }
  441. if(LOCPLINT->adventureInt->scrollingRight)
  442. {
  443. if(LOCPLINT->adventureInt->position.x<CGI->ac->map.width-19+4)
  444. {
  445. LOCPLINT->adventureInt->position.x++;
  446. LOCPLINT->adventureInt->updateScreen = true;
  447. adventureInt->updateMinimap=true;
  448. }
  449. }
  450. if(LOCPLINT->adventureInt->scrollingUp)
  451. {
  452. if(LOCPLINT->adventureInt->position.y>-Hoff)
  453. {
  454. LOCPLINT->adventureInt->position.y--;
  455. LOCPLINT->adventureInt->updateScreen = true;
  456. adventureInt->updateMinimap=true;
  457. }
  458. }
  459. if(LOCPLINT->adventureInt->scrollingDown)
  460. {
  461. if(LOCPLINT->adventureInt->position.y<CGI->ac->map.height-18+4)
  462. {
  463. LOCPLINT->adventureInt->position.y++;
  464. LOCPLINT->adventureInt->updateScreen = true;
  465. adventureInt->updateMinimap=true;
  466. }
  467. }
  468. if(LOCPLINT->adventureInt->updateScreen)
  469. {
  470. adventureInt->update();
  471. adventureInt->updateScreen=false;
  472. }
  473. if (LOCPLINT->adventureInt->updateMinimap)
  474. {
  475. adventureInt->minimap.draw();
  476. adventureInt->updateMinimap=false;
  477. }
  478. for(int i=0;i<objsToBlit.size();i++)
  479. objsToBlit[i]->show();
  480. //SDL_Flip(ekran);
  481. CSDL_Ext::update(ekran);
  482. SDL_Delay(5); //give time for other apps
  483. SDL_framerateDelay(mainFPSmng);
  484. }
  485. adventureInt->hide();
  486. }
  487. inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, const int & hid)
  488. {
  489. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  490. for(int h=0; h<hlp.objects.size(); ++h)
  491. if(hlp.objects[h].first->id==hid)
  492. {
  493. hlp.objects[h].second.first = r;
  494. return;
  495. }
  496. }
  497. inline void delObjRect(const int & x, const int & y, const int & z, const int & hid)
  498. {
  499. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  500. for(int h=0; h<hlp.objects.size(); ++h)
  501. if(hlp.objects[h].first->id==hid)
  502. {
  503. hlp.objects.erase(hlp.objects.begin()+h);
  504. return;
  505. }
  506. }
  507. int getDir(int3 src, int3 dst)
  508. {
  509. int ret = -1;
  510. if(dst.x+1 == src.x && dst.y+1 == src.y) //tl
  511. {
  512. ret = 1;
  513. }
  514. else if(dst.x == src.x && dst.y+1 == src.y) //t
  515. {
  516. ret = 2;
  517. }
  518. else if(dst.x-1 == src.x && dst.y+1 == src.y) //tr
  519. {
  520. ret = 3;
  521. }
  522. else if(dst.x-1 == src.x && dst.y == src.y) //r
  523. {
  524. ret = 4;
  525. }
  526. else if(dst.x-1 == src.x && dst.y-1 == src.y) //br
  527. {
  528. ret = 5;
  529. }
  530. else if(dst.x == src.x && dst.y-1 == src.y) //b
  531. {
  532. ret = 6;
  533. }
  534. else if(dst.x+1 == src.x && dst.y-1 == src.y) //bl
  535. {
  536. ret = 7;
  537. }
  538. else if(dst.x+1 == src.x && dst.y == src.y) //l
  539. {
  540. ret = 8;
  541. }
  542. return ret;
  543. }
  544. void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
  545. {
  546. //initializing objects and performing first step of move
  547. CGHeroInstance * ho = details.ho; //object representing this hero
  548. int3 hp = details.src;
  549. if (!details.successful)
  550. {
  551. ho->moveDir = getDir(details.src,details.dst);
  552. ho->isStanding = true;
  553. adventureInt->heroList.draw();
  554. if (adventureInt->terrain.currentPath)
  555. {
  556. delete adventureInt->terrain.currentPath;
  557. adventureInt->terrain.currentPath = NULL;
  558. }
  559. return;
  560. }
  561. if (adventureInt->terrain.currentPath) //&& hero is moving
  562. {
  563. adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
  564. }
  565. int3 buff = details.ho->pos;
  566. buff.x-=11;
  567. buff.y-=9;
  568. buff = repairScreenPos(buff);
  569. LOCPLINT->adventureInt->position = buff; //actualizing screen pos
  570. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  571. {
  572. ho->moveDir = 1;
  573. ho->isStanding = false;
  574. CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, -31), std::vector<std::list<int3>>())));
  575. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 1, -31), std::vector<std::list<int3>>())));
  576. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 33, -31), std::vector<std::list<int3>>())));
  577. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 65, -31), std::vector<std::list<int3>>())));
  578. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 1), std::vector<std::list<int3>>())));
  579. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 1), ho->id);
  580. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 1), ho->id);
  581. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 1), ho->id);
  582. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 33), std::vector<std::list<int3>>())));
  583. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 33), ho->id);
  584. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 33), ho->id);
  585. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 33), ho->id);
  586. 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);
  587. 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);
  588. 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);
  589. 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);
  590. 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);
  591. //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);
  592. //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);
  593. //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);
  594. 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);
  595. //std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  596. //std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  597. //std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  598. }
  599. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  600. {
  601. ho->moveDir = 2;
  602. ho->isStanding = false;
  603. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 0, -31), std::vector<std::list<int3>>())));
  604. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 32, -31), std::vector<std::list<int3>>())));
  605. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 64, -31), std::vector<std::list<int3>>())));
  606. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1), ho->id);
  607. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1), ho->id);
  608. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1), ho->id);
  609. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33), ho->id);
  610. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33), ho->id);
  611. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33), ho->id);
  612. 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);
  613. 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);
  614. 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);
  615. //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);
  616. //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);
  617. //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);
  618. //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);
  619. //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);
  620. //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);
  621. }
  622. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  623. {
  624. ho->moveDir = 3;
  625. ho->isStanding = false;
  626. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -1, -31), std::vector<std::list<int3>>())));
  627. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 31, -31), std::vector<std::list<int3>>())));
  628. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 63, -31), std::vector<std::list<int3>>())));
  629. CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, -31), std::vector<std::list<int3>>())));
  630. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 1), ho->id);
  631. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 1), ho->id);
  632. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 1), ho->id);
  633. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 1), std::vector<std::list<int3>>())));
  634. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 33), ho->id);
  635. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 33), ho->id);
  636. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 33), ho->id);
  637. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 33), std::vector<std::list<int3>>())));
  638. 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);
  639. 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);
  640. 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);
  641. 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);
  642. //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);
  643. //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);
  644. //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);
  645. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  646. //std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  647. //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);
  648. //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);
  649. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  650. }
  651. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  652. {
  653. ho->moveDir = 4;
  654. ho->isStanding = false;
  655. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id);
  656. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id);
  657. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id);
  658. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 0), std::vector<std::list<int3>>())));
  659. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 32), ho->id);
  660. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 32), ho->id);
  661. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 32), ho->id);
  662. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 32), std::vector<std::list<int3>>())));
  663. //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);
  664. //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);
  665. //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);
  666. 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);
  667. //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);
  668. //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);
  669. //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);
  670. 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);
  671. }
  672. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  673. {
  674. ho->moveDir = 5;
  675. ho->isStanding = false;
  676. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, -1), ho->id);
  677. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, -1), ho->id);
  678. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id);
  679. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, -1), std::vector<std::list<int3>>())));
  680. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 31), ho->id);
  681. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 31), ho->id);
  682. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 31), ho->id);
  683. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 31), std::vector<std::list<int3>>())));
  684. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -1, 63), std::vector<std::list<int3>>())));
  685. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 31, 63), std::vector<std::list<int3>>())));
  686. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 63, 63), std::vector<std::list<int3>>())));
  687. CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 63), std::vector<std::list<int3>>())));
  688. //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);
  689. //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);
  690. //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);
  691. 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);
  692. //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);
  693. //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);
  694. //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);
  695. 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);
  696. 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);
  697. 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);
  698. 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);
  699. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  700. }
  701. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  702. {
  703. ho->moveDir = 6;
  704. ho->isStanding = false;
  705. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1), ho->id);
  706. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1), ho->id);
  707. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1), ho->id);
  708. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31), ho->id);
  709. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31), ho->id);
  710. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31), ho->id);
  711. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 0, 63), std::vector<std::list<int3>>())));
  712. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 32, 63), std::vector<std::list<int3>>())));
  713. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 64, 63), std::vector<std::list<int3>>())));
  714. //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);
  715. //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);
  716. //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);
  717. //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);
  718. //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);
  719. //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);
  720. 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);
  721. 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);
  722. 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);
  723. }
  724. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  725. {
  726. ho->moveDir = 7;
  727. ho->isStanding = false;
  728. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, -1), std::vector<std::list<int3>>())));
  729. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id);
  730. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id);
  731. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, -1), ho->id);
  732. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 31), std::vector<std::list<int3>>())));
  733. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 31), ho->id);
  734. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 31), ho->id);
  735. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 31), ho->id);
  736. CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 63), std::vector<std::list<int3>>())));
  737. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 1, 63), std::vector<std::list<int3>>())));
  738. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 33, 63), std::vector<std::list<int3>>())));
  739. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 65, 63), std::vector<std::list<int3>>())));
  740. 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);
  741. //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);
  742. //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);
  743. //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);
  744. 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);
  745. //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);
  746. //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);
  747. //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);
  748. 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);
  749. 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);
  750. 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);
  751. 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);
  752. }
  753. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  754. {
  755. ho->moveDir = 8;
  756. ho->isStanding = false;
  757. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 0), std::vector<std::list<int3>>())));
  758. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id);
  759. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id);
  760. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 0), ho->id);
  761. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 32), std::vector<std::list<int3>>())));
  762. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 32), ho->id);
  763. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 32), ho->id);
  764. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 32), ho->id);
  765. 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);
  766. //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);
  767. //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);
  768. //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);
  769. 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);
  770. //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);
  771. //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);
  772. //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);
  773. }
  774. //first initializing done
  775. SDL_framerateDelay(mainFPSmng); // after first move
  776. //main moving
  777. for(int i=1; i<32; i+=4)
  778. {
  779. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  780. {
  781. subRect(hp.x-3, hp.y-2, hp.z, genRect(32, 32, -31+i, -31+i), ho->id);
  782. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 1+i, -31+i), ho->id);
  783. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 33+i, -31+i), ho->id);
  784. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 65+i, -31+i), ho->id);
  785. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 1+i), ho->id);
  786. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 1+i), ho->id);
  787. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 1+i), ho->id);
  788. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 1+i), ho->id);
  789. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 33+i), ho->id);
  790. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 33+i), ho->id);
  791. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 33+i), ho->id);
  792. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 33+i), ho->id);
  793. /*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);
  794. 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);
  795. 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);
  796. 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);
  797. 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);
  798. 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);
  799. 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);
  800. 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);
  801. 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);
  802. 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);
  803. 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);
  804. 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);*/
  805. }
  806. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  807. {
  808. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 0, -31+i), ho->id);
  809. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 32, -31+i), ho->id);
  810. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 64, -31+i), ho->id);
  811. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1+i), ho->id);
  812. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1+i), ho->id);
  813. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1+i), ho->id);
  814. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33+i), ho->id);
  815. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33+i), ho->id);
  816. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33+i), ho->id);
  817. /*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);
  818. 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);
  819. 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);
  820. 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);
  821. 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);
  822. 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);
  823. 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);
  824. 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);
  825. 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);*/
  826. }
  827. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  828. {
  829. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, -1-i, -31+i), ho->id);
  830. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 31-i, -31+i), ho->id);
  831. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 63-i, -31+i), ho->id);
  832. subRect(hp.x+1, hp.y-2, hp.z, genRect(32, 32, 95-i, -31+i), ho->id);
  833. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 1+i), ho->id);
  834. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 1+i), ho->id);
  835. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 1+i), ho->id);
  836. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 1+i), ho->id);
  837. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 33+i), ho->id);
  838. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 33+i), ho->id);
  839. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 33+i), ho->id);
  840. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 33+i), ho->id);
  841. /*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);
  842. 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);
  843. 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);
  844. 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);
  845. 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);
  846. 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);
  847. 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);
  848. 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);
  849. 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);
  850. 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);
  851. 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);
  852. 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);*/
  853. }
  854. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  855. {
  856. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 0), ho->id);
  857. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 0), ho->id);
  858. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 0), ho->id);
  859. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 0), ho->id);
  860. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 32), ho->id);
  861. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 32), ho->id);
  862. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 32), ho->id);
  863. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 32), ho->id);
  864. /*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);
  865. 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);
  866. 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);
  867. 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);
  868. 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);
  869. 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);
  870. 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);
  871. 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);*/
  872. }
  873. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  874. {
  875. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, -1-i), ho->id);
  876. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, -1-i), ho->id);
  877. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, -1-i), ho->id);
  878. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, -1-i), ho->id);
  879. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 31-i), ho->id);
  880. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 31-i), ho->id);
  881. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 31-i), ho->id);
  882. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 31-i), ho->id);
  883. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, -1-i, 63-i), ho->id);
  884. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 31-i, 63-i), ho->id);
  885. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 63-i, 63-i), ho->id);
  886. subRect(hp.x+1, hp.y+1, hp.z, genRect(32, 32, 95-i, 63-i), ho->id);
  887. /*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);
  888. 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);
  889. 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);
  890. 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);
  891. 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);
  892. 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);
  893. 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);
  894. 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);
  895. 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);
  896. 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);
  897. 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);
  898. 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);*/
  899. }
  900. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  901. {
  902. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1-i), ho->id);
  903. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1-i), ho->id);
  904. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1-i), ho->id);
  905. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31-i), ho->id);
  906. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31-i), ho->id);
  907. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31-i), ho->id);
  908. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 0, 63-i), ho->id);
  909. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 32, 63-i), ho->id);
  910. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 64, 63-i), ho->id);
  911. /*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);
  912. 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);
  913. 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);
  914. 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);
  915. 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);
  916. 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);
  917. 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);
  918. 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);
  919. 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);*/
  920. }
  921. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  922. {
  923. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, -1-i), ho->id);
  924. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, -1-i), ho->id);
  925. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, -1-i), ho->id);
  926. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, -1-i), ho->id);
  927. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 31-i), ho->id);
  928. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 31-i), ho->id);
  929. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 31-i), ho->id);
  930. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 31-i), ho->id);
  931. subRect(hp.x-3, hp.y+1, hp.z, genRect(32, 32, -31+i, 63-i), ho->id);
  932. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 1+i, 63-i), ho->id);
  933. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 33+i, 63-i), ho->id);
  934. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 65+i, 63-i), ho->id);
  935. /*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);
  936. 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);
  937. 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);
  938. 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);
  939. 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);
  940. 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);
  941. 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);
  942. 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);
  943. 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);
  944. 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);
  945. 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);
  946. 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);*/
  947. }
  948. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  949. {
  950. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 0), ho->id);
  951. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 0), ho->id);
  952. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 0), ho->id);
  953. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 0), ho->id);
  954. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 32), ho->id);
  955. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 32), ho->id);
  956. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 32), ho->id);
  957. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 32), ho->id);
  958. /*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);
  959. 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);
  960. 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);
  961. 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);
  962. 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);
  963. 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);
  964. 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);
  965. 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);*/
  966. }
  967. LOCPLINT->adventureInt->update(); //updating screen
  968. CSDL_Ext::update(ekran);
  969. CGI->screenh->updateScreen();
  970. LOCPLINT->adventureInt->anim++;
  971. adventureInt->animValHitCount=0;
  972. SDL_framerateDelay(mainFPSmng); //for animation purposes
  973. } //for(int i=1; i<32; i+=4)
  974. //main moving done
  975. //finishing move
  976. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  977. {
  978. delObjRect(hp.x, hp.y-2, hp.z, ho->id);
  979. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  980. delObjRect(hp.x, hp.y, hp.z, ho->id);
  981. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  982. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  983. delObjRect(hp.x-3, hp.y, hp.z, ho->id);
  984. }
  985. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  986. {
  987. delObjRect(hp.x, hp.y, hp.z, ho->id);
  988. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  989. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  990. }
  991. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  992. {
  993. delObjRect(hp.x-2, hp.y-2, hp.z, ho->id);
  994. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  995. delObjRect(hp.x+1, hp.y, hp.z, ho->id);
  996. delObjRect(hp.x, hp.y, hp.z, ho->id);
  997. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  998. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  999. }
  1000. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1001. {
  1002. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1003. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1004. }
  1005. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1006. {
  1007. delObjRect(hp.x-2, hp.y+1, hp.z, ho->id);
  1008. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1009. delObjRect(hp.x+1, hp.y-1, hp.z, ho->id);
  1010. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1011. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1012. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1013. }
  1014. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1015. {
  1016. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1017. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1018. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1019. }
  1020. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1021. {
  1022. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1023. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1024. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1025. delObjRect(hp.x-3, hp.y-1, hp.z, ho->id);
  1026. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1027. delObjRect(hp.x, hp.y+1, hp.z, ho->id);
  1028. }
  1029. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1030. {
  1031. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1032. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1033. }
  1034. ho->pos = details.dst; //copy of hero's position
  1035. //ho->moveDir = 0; //move ended
  1036. ho->isStanding = true;
  1037. //move finished
  1038. CGI->mh->recalculateHideVisPosUnderObj(details.ho, true);
  1039. adventureInt->minimap.draw();
  1040. adventureInt->heroList.updateMove(ho);
  1041. }
  1042. void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
  1043. {
  1044. heroWins.erase(hero->ID);
  1045. }
  1046. void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
  1047. {
  1048. if(heroWins.find(hero->subID)==heroWins.end())
  1049. heroWins.insert(std::pair<int,SDL_Surface*>(hero->subID,infoWin(hero)));
  1050. }
  1051. SDL_Surface * CPlayerInterface::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to)
  1052. {
  1053. char * buf = new char[10];
  1054. for (int i=from;i<to;i++)
  1055. {
  1056. itoa(curh->primSkills[i],buf,10);
  1057. printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
  1058. }
  1059. delete buf;
  1060. return ret;
  1061. }
  1062. SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh)
  1063. {
  1064. char * buf = new char[10];
  1065. SDL_Surface * ret = copySurface(hInfo);
  1066. SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
  1067. blueToPlayersAdv(ret,playerID,1);
  1068. printAt(curh->name,75,15,GEOR13,zwykly,ret);
  1069. drawPrimarySkill(curh, ret);
  1070. for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
  1071. {
  1072. blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
  1073. itoa((*i).second.second,buf,10);
  1074. printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
  1075. }
  1076. blitAt(curh->type->portraitLarge,11,12,ret);
  1077. itoa(curh->mana,buf,10);
  1078. printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points
  1079. delete buf;
  1080. blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret);
  1081. blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret);
  1082. //SDL_SaveBMP(ret,"inf1.bmp");
  1083. return ret;
  1084. }
  1085. SDL_Surface * CPlayerInterface::drawTownInfoWin(const CGTownInstance * curh)
  1086. {
  1087. return NULL;
  1088. }
  1089. SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //specific=0 => draws info about selected town/hero
  1090. {
  1091. if (specific)
  1092. {
  1093. switch (specific->ID)
  1094. {
  1095. case 34:
  1096. return drawHeroInfoWin(dynamic_cast<const CGHeroInstance*>(specific));
  1097. break;
  1098. default:
  1099. return NULL;
  1100. break;
  1101. }
  1102. }
  1103. else
  1104. {
  1105. switch (adventureInt->selection.type)
  1106. {
  1107. case HEROI_TYPE:
  1108. {
  1109. const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection.selected;
  1110. return drawHeroInfoWin(curh);
  1111. }
  1112. case TOWNI_TYPE:
  1113. {
  1114. return drawTownInfoWin((const CGTownInstance *)adventureInt->selection.selected);
  1115. }
  1116. default:
  1117. return NULL;
  1118. }
  1119. }
  1120. return NULL;
  1121. }
  1122. void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent)
  1123. {
  1124. for (int i=0; i<hoverable.size();i++)
  1125. {
  1126. if (isItIn(&hoverable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1127. {
  1128. if (!hoverable[i]->hovered)
  1129. hoverable[i]->hover(true);
  1130. }
  1131. else if (hoverable[i]->hovered)
  1132. {
  1133. hoverable[i]->hover(false);
  1134. }
  1135. }
  1136. for(int i=0; i<motioninterested.size();i++)
  1137. {
  1138. if (isItIn(&motioninterested[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1139. {
  1140. motioninterested[i]->mouseMoved(sEvent->motion);
  1141. }
  1142. }
  1143. if(sEvent->motion.x<15)
  1144. {
  1145. LOCPLINT->adventureInt->scrollingLeft = true;
  1146. }
  1147. else
  1148. {
  1149. LOCPLINT->adventureInt->scrollingLeft = false;
  1150. }
  1151. if(sEvent->motion.x>ekran->w-15)
  1152. {
  1153. LOCPLINT->adventureInt->scrollingRight = true;
  1154. }
  1155. else
  1156. {
  1157. LOCPLINT->adventureInt->scrollingRight = false;
  1158. }
  1159. if(sEvent->motion.y<15)
  1160. {
  1161. LOCPLINT->adventureInt->scrollingUp = true;
  1162. }
  1163. else
  1164. {
  1165. LOCPLINT->adventureInt->scrollingUp = false;
  1166. }
  1167. if(sEvent->motion.y>ekran->h-15)
  1168. {
  1169. LOCPLINT->adventureInt->scrollingDown = true;
  1170. }
  1171. else
  1172. {
  1173. LOCPLINT->adventureInt->scrollingDown = false;
  1174. }
  1175. }
  1176. void CPlayerInterface::handleKeyUp(SDL_Event *sEvent)
  1177. {
  1178. switch (sEvent->key.keysym.sym)
  1179. {
  1180. case SDLK_LEFT:
  1181. {
  1182. LOCPLINT->adventureInt->scrollingLeft = false;
  1183. break;
  1184. }
  1185. case (SDLK_RIGHT):
  1186. {
  1187. LOCPLINT->adventureInt->scrollingRight = false;
  1188. break;
  1189. }
  1190. case (SDLK_UP):
  1191. {
  1192. LOCPLINT->adventureInt->scrollingUp = false;
  1193. break;
  1194. }
  1195. case (SDLK_DOWN):
  1196. {
  1197. LOCPLINT->adventureInt->scrollingDown = false;
  1198. break;
  1199. }
  1200. case (SDLK_u):
  1201. {
  1202. adventureInt->underground.clickLeft(false);
  1203. break;
  1204. }
  1205. case (SDLK_m):
  1206. {
  1207. adventureInt->moveHero.clickLeft(false);
  1208. break;
  1209. }
  1210. case (SDLK_e):
  1211. {
  1212. adventureInt->endTurn.clickLeft(false);
  1213. break;
  1214. }
  1215. }
  1216. }
  1217. void CPlayerInterface::handleKeyDown(SDL_Event *sEvent)
  1218. {
  1219. switch (sEvent->key.keysym.sym)
  1220. {
  1221. case SDLK_LEFT:
  1222. {
  1223. LOCPLINT->adventureInt->scrollingLeft = true;
  1224. break;
  1225. }
  1226. case (SDLK_RIGHT):
  1227. {
  1228. LOCPLINT->adventureInt->scrollingRight = true;
  1229. break;
  1230. }
  1231. case (SDLK_UP):
  1232. {
  1233. LOCPLINT->adventureInt->scrollingUp = true;
  1234. break;
  1235. }
  1236. case (SDLK_DOWN):
  1237. {
  1238. LOCPLINT->adventureInt->scrollingDown = true;
  1239. break;
  1240. }
  1241. case (SDLK_q):
  1242. {
  1243. exit(0);
  1244. break;
  1245. }
  1246. case (SDLK_u):
  1247. {
  1248. adventureInt->underground.clickLeft(true);
  1249. break;
  1250. }
  1251. case (SDLK_m):
  1252. {
  1253. adventureInt->moveHero.clickLeft(true);
  1254. break;
  1255. }
  1256. case (SDLK_e):
  1257. {
  1258. adventureInt->endTurn.clickLeft(true);
  1259. break;
  1260. }
  1261. }
  1262. }
  1263. void CPlayerInterface::handleEvent(SDL_Event *sEvent)
  1264. {
  1265. current = sEvent;
  1266. if(sEvent->type == SDL_MOUSEMOTION)
  1267. {
  1268. CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
  1269. }
  1270. if(sEvent->type==SDL_QUIT)
  1271. exit(0);
  1272. else if (sEvent->type==SDL_KEYDOWN)
  1273. {
  1274. handleKeyDown(sEvent);
  1275. } //keydown end
  1276. else if(sEvent->type==SDL_KEYUP)
  1277. {
  1278. handleKeyUp(sEvent);
  1279. }//keyup end
  1280. else if(sEvent->type==SDL_MOUSEMOTION)
  1281. {
  1282. handleMouseMotion(sEvent);
  1283. } //mousemotion end
  1284. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1285. {
  1286. LOGE("Left mouse button down1");
  1287. for(int i=0; i<lclickable.size();i++)
  1288. {
  1289. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1290. {
  1291. lclickable[i]->clickLeft(true);
  1292. }
  1293. }
  1294. }
  1295. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1296. {
  1297. for(int i=0; i<lclickable.size();i++)
  1298. {
  1299. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1300. {
  1301. lclickable[i]->clickLeft(false);
  1302. }
  1303. else
  1304. lclickable[i]->clickLeft(boost::logic::indeterminate);
  1305. }
  1306. }
  1307. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1308. {
  1309. for(int i=0; i<rclickable.size();i++)
  1310. {
  1311. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1312. {
  1313. rclickable[i]->clickRight(true);
  1314. }
  1315. }
  1316. }
  1317. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1318. {
  1319. for(int i=0; i<rclickable.size();i++)
  1320. {
  1321. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1322. {
  1323. rclickable[i]->clickRight(false);
  1324. }
  1325. else
  1326. rclickable[i]->clickRight(boost::logic::indeterminate);
  1327. }
  1328. }
  1329. current = NULL;
  1330. } //event end
  1331. int3 CPlayerInterface::repairScreenPos(int3 pos)
  1332. {
  1333. if(pos.x<=-Woff)
  1334. pos.x = -Woff+1;
  1335. if(pos.y<=-Hoff)
  1336. pos.y = -Hoff+1;
  1337. if(pos.x>CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff)
  1338. pos.x = CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff;
  1339. if(pos.y>CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff)
  1340. pos.y = CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff;
  1341. return pos;
  1342. }
  1343. void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)
  1344. {
  1345. SDL_FreeSurface(heroWins[hero->subID]);//TODO: moznaby zmieniac jedynie fragment bitmapy zwiazany z dana umiejetnoscia
  1346. heroWins[hero->subID] = infoWin(hero); //a nie przerysowywac calosc. Troche roboty, obecnie chyba nie wartej swieczki.
  1347. if (adventureInt->selection.selected == hero)
  1348. adventureInt->infoBar.draw();
  1349. return;
  1350. }
  1351. void CPlayerInterface::receivedResource(int type, int val)
  1352. {
  1353. adventureInt->resdatabar.draw();
  1354. }
  1355. void CPlayerInterface::showSelDialog(std::string text, std::vector<SComponent*> & components, int askID)
  1356. {
  1357. }
  1358. void CPlayerInterface::showComp(SComponent comp)
  1359. {
  1360. adventureInt->infoBar.showComp(&comp,4000);
  1361. }
  1362. void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*> & components)
  1363. {
  1364. adventureInt->hide(); //dezaktywacja starego interfejsu
  1365. CInfoWindow * temp = CMessage::genIWindow(text,LOCPLINT->playerID,32,components);
  1366. LOCPLINT->objsToBlit.push_back(temp);
  1367. temp->pos.x=300-(temp->pos.w/2);
  1368. temp->pos.y=300-(temp->pos.h/2);
  1369. temp->okb.pos.x = temp->okb.posr.x + temp->pos.x;
  1370. temp->okb.pos.y = temp->okb.posr.y + temp->pos.y;
  1371. temp->okb.activate();
  1372. for (int i=0;i<temp->components.size();i++)
  1373. {
  1374. temp->components[i]->activate();
  1375. temp->components[i]->pos.x += temp->pos.x;
  1376. temp->components[i]->pos.y += temp->pos.y;
  1377. }
  1378. }
  1379. void CPlayerInterface::removeObjToBlit(IShowable* obj)
  1380. {
  1381. objsToBlit.erase
  1382. (std::find(objsToBlit.begin(),objsToBlit.end(),obj));
  1383. //delete obj;
  1384. }
  1385. void CPlayerInterface::tileRevealed(int3 pos)
  1386. {
  1387. adventureInt->minimap.showTile(pos);
  1388. }
  1389. void CPlayerInterface::tileHidden(int3 pos)
  1390. {
  1391. adventureInt->minimap.hideTile(pos);
  1392. }