CPlayerInterface.cpp 67 KB

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