CPlayerInterface.cpp 77 KB

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