CPlayerInterface.cpp 66 KB

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