CPlayerInterface.cpp 66 KB

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