CPlayerInterface.cpp 66 KB

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