CPlayerInterface.cpp 81 KB

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