CPlayerInterface.cpp 75 KB

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