CPlayerInterface.cpp 65 KB

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