CPlayerInterface.cpp 68 KB

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