CPlayerInterface.cpp 81 KB

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