CPlayerInterface.cpp 66 KB

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