CPlayerInterface.cpp 68 KB

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