CPlayerInterface.cpp 68 KB

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