CPlayerInterface.cpp 66 KB

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