CPlayerInterface.cpp 75 KB

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