CPlayerInterface.cpp 69 KB

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