CPlayerInterface.cpp 74 KB

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