CPlayerInterface.cpp 76 KB

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