CPlayerInterface.cpp 65 KB

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