CPlayerInterface.cpp 81 KB

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