CAdvmapInterface.cpp 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  1. #include "stdafx.h"
  2. #include "CAdvmapInterface.h"
  3. #include "hch\CLodHandler.h"
  4. #include "hch\CPreGameTextHandler.h"
  5. #include "hch\CGeneralTextHandler.h"
  6. #include "hch\CTownHandler.h"
  7. #include "CPathfinder.h"
  8. #include "CGameInfo.h"
  9. #include "SDL_Extensions.h"
  10. #include "CCallback.h"
  11. #include <boost/assign/std/vector.hpp>
  12. #include "mapHandler.h"
  13. extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
  14. using namespace boost::logic;
  15. using namespace boost::assign;
  16. using namespace CSDL_Ext;
  17. CAdvMapInt::~CAdvMapInt()
  18. {
  19. SDL_FreeSurface(bg);
  20. }
  21. AdventureMapButton::AdventureMapButton ()
  22. {
  23. type=2;
  24. abs=true;
  25. active=false;
  26. ourObj=NULL;
  27. state=0;
  28. }
  29. AdventureMapButton::AdventureMapButton
  30. ( std::string Name, std::string HelpBox, void(CAdvMapInt::*Function)(), int x, int y, std::string defName, bool activ, std::vector<std::string> * add )
  31. {
  32. type=2;
  33. abs=true;
  34. active=false;
  35. ourObj=NULL;
  36. state=0;
  37. name=Name;
  38. helpBox=HelpBox;
  39. int est = LOCPLINT->playerID;
  40. CDefHandler * temp = CGI->spriteh->giveDef(defName); //todo: moze cieknac
  41. for (int i=0;i<temp->ourImages.size();i++)
  42. {
  43. imgs.resize(1);
  44. imgs[0].push_back(temp->ourImages[i].bitmap);
  45. blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
  46. }
  47. if (add)
  48. {
  49. imgs.resize(imgs.size()+add->size());
  50. for (int i=0; i<add->size();i++)
  51. {
  52. temp = CGI->spriteh->giveDef((*add)[i]);
  53. for (int j=0;j<temp->ourImages.size();j++)
  54. {
  55. imgs[i+1].push_back(temp->ourImages[j].bitmap);
  56. blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
  57. }
  58. }
  59. delete add;
  60. }
  61. function = Function;
  62. pos.x=x;
  63. pos.y=y;
  64. pos.w = imgs[curimg][0]->w;
  65. pos.h = imgs[curimg][0]->h -1;
  66. if (activ)
  67. activate();
  68. }
  69. void AdventureMapButton::clickLeft (tribool down)
  70. {
  71. if (down)
  72. {
  73. state=1;
  74. }
  75. else
  76. {
  77. state=0;
  78. }
  79. show();
  80. if (pressedL && (down==false))
  81. (LOCPLINT->adventureInt->*function)();
  82. pressedL=state;
  83. }
  84. void AdventureMapButton::clickRight (tribool down)
  85. {
  86. //TODO: show/hide infobox
  87. }
  88. void AdventureMapButton::hover (bool on)
  89. {
  90. Hoverable::hover(on);
  91. if (on)
  92. LOCPLINT->adventureInt->statusbar.print(name);
  93. else if (LOCPLINT->adventureInt->statusbar.current==name)
  94. LOCPLINT->adventureInt->statusbar.clear();
  95. }
  96. void AdventureMapButton::activate()
  97. {
  98. if (active) return;
  99. active=true;
  100. ClickableL::activate();
  101. Hoverable::activate();
  102. KeyInterested::activate();
  103. }
  104. void AdventureMapButton::keyPressed (SDL_KeyboardEvent & key)
  105. {
  106. //TODO: check if it's shortcut
  107. }
  108. void AdventureMapButton::deactivate()
  109. {
  110. if (!active) return;
  111. active=false;
  112. ClickableL::deactivate();
  113. Hoverable::deactivate();
  114. KeyInterested::deactivate();
  115. }
  116. void CList::activate()
  117. {
  118. ClickableL::activate();
  119. ClickableR::activate();
  120. Hoverable::activate();
  121. KeyInterested::activate();
  122. MotionInterested::activate();
  123. };
  124. void CList::deactivate()
  125. {
  126. ClickableL::deactivate();
  127. ClickableR::deactivate();
  128. Hoverable::deactivate();
  129. KeyInterested::deactivate();
  130. MotionInterested::deactivate();
  131. };
  132. void CList::clickLeft(tribool down)
  133. {
  134. };
  135. CHeroList::CHeroList()
  136. {
  137. pos = genRect(192,64,609,196);
  138. arrupp = genRect(16,64,609,196);
  139. arrdop = genRect(16,64,609,372);
  140. //32px per hero
  141. posmobx = 610;
  142. posmoby = 213;
  143. posporx = 617;
  144. pospory = 212;
  145. posmanx = 666;
  146. posmany = 213;
  147. arrup = CGI->spriteh->giveDef("IAM012.DEF");
  148. arrdo = CGI->spriteh->giveDef("IAM013.DEF");
  149. mobile = CGI->spriteh->giveDef("IMOBIL.DEF");
  150. mana = CGI->spriteh->giveDef("IMANA.DEF");
  151. empty = CGI->bitmaph->loadBitmap("HPSXXX.bmp");
  152. selection = CGI->bitmaph->loadBitmap("HPSYYY.bmp");
  153. SDL_SetColorKey(selection,SDL_SRCCOLORKEY,SDL_MapRGB(selection->format,0,255,255));
  154. from = 0;
  155. pressed = indeterminate;
  156. }
  157. void CHeroList::init()
  158. {
  159. bg = CSDL_Ext::newSurface(68,193,ekran);
  160. SDL_BlitSurface(LOCPLINT->adventureInt->bg,&genRect(193,68,607,196),bg,&genRect(193,68,0,0));
  161. }
  162. void CHeroList::genList()
  163. {
  164. int howMany = LOCPLINT->cb->howManyHeroes(LOCPLINT->playerID);
  165. for (int i=0;i<howMany;i++)
  166. {
  167. items.push_back(std::pair<const CHeroInstance *,CPath *>(LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,i,0),NULL));
  168. }
  169. }
  170. void CHeroList::select(int which)
  171. {
  172. selected = which;
  173. if (which>=items.size())
  174. which=items.size();
  175. draw();
  176. LOCPLINT->adventureInt->centerOn(items[which].first->pos);
  177. LOCPLINT->adventureInt->selection.type = HEROI_TYPE;
  178. LOCPLINT->adventureInt->selection.selected = items[which].first;
  179. LOCPLINT->adventureInt->terrain.currentPath = items[which].second;
  180. }
  181. void CHeroList::clickLeft(tribool down)
  182. {
  183. if (down)
  184. {
  185. /***************************ARROWS*****************************************/
  186. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  187. {
  188. blitAtWR(arrup->ourImages[1].bitmap,arrupp.x,arrupp.y);
  189. pressed = true;
  190. return;
  191. }
  192. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  193. {
  194. blitAtWR(arrdo->ourImages[1].bitmap,arrdop.x,arrdop.y);
  195. pressed = false;
  196. return;
  197. }
  198. /***************************HEROES*****************************************/
  199. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  200. hx-=pos.x;
  201. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  202. float ny = (float)hy/(float)32;
  203. if (ny>5 || ny<0)
  204. return;
  205. select(ny+from);
  206. }
  207. else
  208. {
  209. if (indeterminate(pressed))
  210. return;
  211. if (pressed) //up
  212. {
  213. blitAtWR(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  214. pressed = indeterminate;
  215. if (!down)
  216. {
  217. from--;
  218. if (from<0)
  219. from=0;
  220. draw();
  221. }
  222. }
  223. else if (!pressed) //down
  224. {
  225. blitAtWR(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  226. pressed = indeterminate;
  227. if (!down)
  228. {
  229. from++;
  230. if (from<items.size()-5)
  231. from=items.size()-5;
  232. draw();
  233. }
  234. }
  235. else
  236. throw 0;
  237. }
  238. }
  239. void CHeroList::mouseMoved (SDL_MouseMotionEvent & sEvent)
  240. {
  241. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  242. {
  243. if (from>0)
  244. LOCPLINT->adventureInt->statusbar.print(CGI->preth->advHListUp.first);
  245. else
  246. LOCPLINT->adventureInt->statusbar.clear();
  247. return;
  248. }
  249. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  250. {
  251. if ((items.size()-from) > 5)
  252. LOCPLINT->adventureInt->statusbar.print(CGI->preth->advHListDown.first);
  253. else
  254. LOCPLINT->adventureInt->statusbar.clear();
  255. return;
  256. }
  257. //if not buttons then heroes
  258. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  259. hx-=pos.x;
  260. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  261. float ny = (float)hy/(float)32;
  262. if ((ny>5 || ny<0) || (from+ny>=items.size()))
  263. {
  264. LOCPLINT->adventureInt->statusbar.clear();
  265. return;
  266. }
  267. std::vector<std::string> temp;
  268. temp+=(items[from+ny].first->name),(items[from+ny].first->type->heroClass->name);
  269. LOCPLINT->adventureInt->statusbar.print( processStr(CGI->generaltexth->allTexts[15],temp) );
  270. //select(ny+from);
  271. }
  272. void CHeroList::clickRight(tribool down)
  273. {
  274. }
  275. void CHeroList::hover (bool on)
  276. {
  277. }
  278. void CHeroList::keyPressed (SDL_KeyboardEvent & key)
  279. {
  280. }
  281. void CHeroList::draw()
  282. {
  283. for (int iT=0+from;iT<5+from;iT++)
  284. {
  285. int i = iT-from;
  286. if (iT>=items.size())
  287. {
  288. blitAtWR(mobile->ourImages[0].bitmap,posmobx,posmoby+i*32);
  289. blitAtWR(mana->ourImages[0].bitmap,posmanx,posmany+i*32);
  290. blitAtWR(empty,posporx,pospory+i*32);
  291. continue;
  292. }
  293. int pom = (LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->movement)/100;
  294. if (pom>25) pom=25;
  295. if (pom<0) pom=0;
  296. blitAtWR(mobile->ourImages[pom].bitmap,posmobx,posmoby+i*32); //move point
  297. pom = (LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->mana)/5; //bylo: .../10;
  298. if (pom>25) pom=25;
  299. if (pom<0) pom=0;
  300. blitAtWR(mana->ourImages[pom].bitmap,posmanx,posmany+i*32); //mana
  301. SDL_Surface * temp = LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->type->portraitSmall;
  302. blitAtWR(temp,posporx,pospory+i*32);
  303. if (selected == iT)
  304. {
  305. blitAtWR(selection,posporx,pospory+i*32);
  306. }
  307. //TODO: support for custom portraits
  308. }
  309. if (from>0)
  310. blitAtWR(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  311. else
  312. blitAtWR(arrup->ourImages[2].bitmap,arrupp.x,arrupp.y);
  313. if (items.size()-from>5)
  314. blitAtWR(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  315. else
  316. blitAtWR(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y);
  317. }
  318. CTownList::CTownList()
  319. {
  320. pos = genRect(192,48,747,196);
  321. arrup = CGI->spriteh->giveDef("IAM014.DEF");
  322. arrdo = CGI->spriteh->giveDef("IAM015.DEF");
  323. arrupp.x=747;
  324. arrupp.y=196;
  325. arrdop.x=747;
  326. arrdop.y=372;
  327. posporx = 747;
  328. pospory = 211;
  329. from = 0;
  330. }
  331. void CTownList::genList()
  332. {
  333. int howMany = LOCPLINT->cb->howManyTowns();
  334. for (int i=0;i<howMany;i++)
  335. {
  336. items.push_back(LOCPLINT->cb->getTownInfo(i,0));
  337. }
  338. }
  339. void CTownList::select(int which)
  340. {
  341. }
  342. void CTownList::mouseMoved (SDL_MouseMotionEvent & sEvent)
  343. {
  344. }
  345. void CTownList::clickLeft(tribool down)
  346. {
  347. }
  348. void CTownList::clickRight(tribool down)
  349. {
  350. }
  351. void CTownList::hover (bool on)
  352. {
  353. }
  354. void CTownList::keyPressed (SDL_KeyboardEvent & key)
  355. {
  356. }
  357. void CTownList::draw()
  358. {
  359. for (int iT=0+from;iT<5+from;iT++)
  360. {
  361. int i = iT-from;
  362. if (iT>=items.size())
  363. {
  364. blitAtWR(CGI->townh->getPic(-1),posporx,pospory+i*32);
  365. continue;
  366. }
  367. blitAtWR(CGI->townh->getPic(items[i]->type),posporx,pospory+i*32);
  368. if (selected == iT)
  369. {
  370. blitAtWR(CGI->townh->getPic(-2),posporx,pospory+i*32);
  371. }
  372. //TODO: dodac oznaczanie zbudowania w danej turze i posiadania fortu
  373. }
  374. if (from>0)
  375. blitAtWR(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  376. else
  377. blitAtWR(arrup->ourImages[2].bitmap,arrupp.x,arrupp.y);
  378. if (items.size()-from>5)
  379. blitAtWR(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  380. else
  381. blitAtWR(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y);
  382. }
  383. CStatusBar::CStatusBar(int x, int y)
  384. {
  385. bg=CGI->bitmaph->loadBitmap("ADROLLVR.bmp");
  386. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  387. pos.x=x;
  388. pos.y=y;
  389. pos.w=bg->w;
  390. pos.h=bg->h;
  391. middlex=(bg->w/2)+x;
  392. middley=(bg->h/2)+y;
  393. }
  394. CStatusBar::~CStatusBar()
  395. {
  396. SDL_FreeSurface(bg);
  397. }
  398. void CStatusBar::clear()
  399. {
  400. current="";
  401. blitAtWR(bg,pos.x,pos.y);
  402. }
  403. void CStatusBar::print(std::string text)
  404. {
  405. current=text;
  406. blitAtWR(bg,pos.x,pos.y);
  407. printAtMiddle(current,middlex,middley,GEOR13,zwykly);
  408. }
  409. void CStatusBar::show()
  410. {
  411. blitAtWR(bg,pos.x,pos.y);
  412. printAtMiddle(current,middlex,middley,GEOR13,zwykly);
  413. }
  414. CMinimap::CMinimap(bool draw)
  415. {
  416. statusbarTxt = CGI->preth->advWorldMap.first;
  417. pos.x=630;
  418. pos.y=26;
  419. pos.h=pos.w=144;
  420. radar = CGI->spriteh->giveDef("RADAR.DEF");
  421. std::ifstream is("config/minimap.txt",std::ifstream::in);
  422. for (int i=0;i<TERRAIN_TYPES;i++)
  423. {
  424. std::pair<int,SDL_Color> vinya;
  425. std::pair<int,SDL_Color> vinya2;
  426. int pom;
  427. is >> pom;
  428. vinya2.first=vinya.first=pom;
  429. is >> pom;
  430. vinya.second.r=pom;
  431. is >> pom;
  432. vinya.second.g=pom;
  433. is >> pom;
  434. vinya.second.b=pom;
  435. is >> pom;
  436. vinya2.second.r=pom;
  437. is >> pom;
  438. vinya2.second.g=pom;
  439. is >> pom;
  440. vinya2.second.b=pom;
  441. vinya.second.unused=vinya2.second.unused=255;
  442. colors.insert(vinya);
  443. colorsBlocked.insert(vinya2);
  444. }
  445. is.close();
  446. if (draw)
  447. redraw();
  448. }
  449. void CMinimap::draw()
  450. {
  451. blitAtWR(map[LOCPLINT->adventureInt->position.z],pos.x,pos.y);
  452. }
  453. void CMinimap::redraw(int level)// (level==-1) => redraw all levels
  454. {
  455. (CGameInfo::mainObj);
  456. for (int i=0; i<CGI->mh->sizes.z; i++)
  457. {
  458. SDL_Surface * pom ;
  459. if ((level>=0) && (i!=level))
  460. continue;
  461. if (map.size()<i+1)
  462. pom = CSDL_Ext::newSurface(pos.w,pos.h,ekran);
  463. else pom = map[i];
  464. for (int x=0;x<pos.w;x++)
  465. {
  466. for (int y=0;y<pos.h;y++)
  467. {
  468. int mx=(CGI->mh->sizes.x*x)/pos.w;
  469. int my=(CGI->mh->sizes.y*y)/pos.h;
  470. if (CGI->mh->ttiles[mx][my][i].blocked && (!CGI->mh->ttiles[mx][my][i].visitable))
  471. SDL_PutPixel(pom,x,y,colorsBlocked[CGI->mh->ttiles[mx][my][i].terType].r,colorsBlocked[CGI->mh->ttiles[mx][my][i].terType].g,colorsBlocked[CGI->mh->ttiles[mx][my][i].terType].b);
  472. else SDL_PutPixel(pom,x,y,colors[CGI->mh->ttiles[mx][my][i].terType].r,colors[CGI->mh->ttiles[mx][my][i].terType].g,colors[CGI->mh->ttiles[mx][my][i].terType].b);
  473. }
  474. }
  475. map.push_back(pom);
  476. }
  477. }
  478. void CMinimap::updateRadar()
  479. {}
  480. void CMinimap::clickRight (tribool down)
  481. {}
  482. void CMinimap::clickLeft (tribool down)
  483. {
  484. if (down && (!pressedL))
  485. MotionInterested::activate();
  486. else if (!down)
  487. {
  488. if (std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this)!=LOCPLINT->motioninterested.end())
  489. MotionInterested::deactivate();
  490. }
  491. ClickableL::clickLeft(down);
  492. if (!((bool)down))
  493. return;
  494. float dx=((float)(LOCPLINT->current->motion.x-pos.x))/((float)pos.w),
  495. dy=((float)(LOCPLINT->current->motion.y-pos.y))/((float)pos.h);
  496. int3 newCPos;
  497. newCPos.x = (CGI->mh->sizes.x*dx);
  498. newCPos.y = (CGI->mh->sizes.y*dy);
  499. newCPos.z = LOCPLINT->adventureInt->position.z;
  500. LOCPLINT->adventureInt->centerOn(newCPos);
  501. }
  502. void CMinimap::hover (bool on)
  503. {
  504. Hoverable::hover(on);
  505. if (on)
  506. LOCPLINT->adventureInt->statusbar.print(statusbarTxt);
  507. else if (LOCPLINT->adventureInt->statusbar.current==statusbarTxt)
  508. LOCPLINT->adventureInt->statusbar.clear();
  509. }
  510. void CMinimap::mouseMoved (SDL_MouseMotionEvent & sEvent)
  511. {
  512. if (pressedL)
  513. {
  514. clickLeft(true);
  515. }
  516. }
  517. void CMinimap::activate()
  518. {
  519. ClickableL::activate();
  520. ClickableR::activate();
  521. Hoverable::activate();
  522. if (pressedL)
  523. MotionInterested::activate();
  524. }
  525. void CMinimap::deactivate()
  526. {
  527. if (pressedL)
  528. MotionInterested::deactivate();
  529. ClickableL::deactivate();
  530. ClickableR::deactivate();
  531. Hoverable::deactivate();
  532. }
  533. CTerrainRect::CTerrainRect():currentPath(NULL)
  534. {
  535. tilesw=19;
  536. tilesh=18;
  537. pos.x=7;
  538. pos.y=6;
  539. pos.w=593;
  540. pos.h=547;
  541. arrows = CGI->spriteh->giveDef("ADAG.DEF");
  542. for(int y=0; y<arrows->ourImages.size(); ++y)
  543. {
  544. CSDL_Ext::fullAlphaTransform(arrows->ourImages[y].bitmap);
  545. }
  546. }
  547. void CTerrainRect::activate()
  548. {
  549. ClickableL::activate();
  550. ClickableR::activate();
  551. Hoverable::activate();
  552. KeyInterested::activate();
  553. };
  554. void CTerrainRect::deactivate()
  555. {
  556. ClickableL::deactivate();
  557. ClickableR::deactivate();
  558. Hoverable::deactivate();
  559. KeyInterested::deactivate();
  560. };
  561. void CTerrainRect::clickLeft(tribool down)
  562. {
  563. if ((down==false) || indeterminate(down))
  564. return;
  565. if (LOCPLINT->adventureInt->selection.type != HEROI_TYPE)
  566. {
  567. if (currentPath)
  568. {
  569. delete currentPath;
  570. currentPath = NULL;
  571. }
  572. return;
  573. }
  574. int3 mp;
  575. mp.x = LOCPLINT->adventureInt->position.x + ((LOCPLINT->current->motion.x-pos.x)/32);
  576. mp.y = LOCPLINT->adventureInt->position.y + ((LOCPLINT->current->motion.y-pos.y)/32);
  577. mp.z = LOCPLINT->adventureInt->position.z;
  578. if ((mp.x<0) || (mp.y<0))
  579. return;
  580. if (currentPath)
  581. {
  582. if ( (currentPath->endPos()) == mp)
  583. { //move
  584. LOCPLINT->cb->moveHero(0,currentPath->endPos(), 1);//todo - move selected hero
  585. return;
  586. }
  587. else
  588. {
  589. delete currentPath;
  590. currentPath=NULL;
  591. }
  592. }
  593. const CHeroInstance * currentHero = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].first;
  594. int3 bufpos = currentHero->pos;
  595. //bufpos.x-=1;
  596. currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->getPath(bufpos,mp,currentHero,1);
  597. }
  598. void CTerrainRect::clickRight(tribool down)
  599. {
  600. }
  601. void CTerrainRect::mouseMoved (SDL_MouseMotionEvent & sEvent)
  602. {
  603. //TODO: print names of objects in toolbar
  604. }
  605. void CTerrainRect::hover(bool on){}
  606. void CTerrainRect::keyPressed (SDL_KeyboardEvent & key){}
  607. void CTerrainRect::show()
  608. {
  609. SDL_Surface * teren = CGI->mh->terrainRect
  610. (LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
  611. tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim);
  612. SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),ekran,&genRect(547,594,7,6));
  613. SDL_FreeSurface(teren);
  614. if (currentPath) //drawing path
  615. {
  616. for (int i=0;i<currentPath->nodes.size()-1;i++)
  617. {
  618. int pn=-1;//number of picture
  619. if (i==0) //last tile
  620. {
  621. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  622. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  623. if (x<0 || y<0 || x>pos.w || y>pos.h)
  624. continue;
  625. pn=0;
  626. }
  627. else
  628. {
  629. std::vector<CPathNode> & cv = currentPath->nodes;
  630. if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1)
  631. {
  632. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  633. {
  634. pn = 3;
  635. }
  636. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  637. {
  638. pn = 12;
  639. }
  640. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  641. {
  642. pn = 21;
  643. }
  644. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  645. {
  646. pn = 22;
  647. }
  648. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  649. {
  650. pn = 2;
  651. }
  652. }
  653. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1)
  654. {
  655. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  656. {
  657. pn = 4;
  658. }
  659. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  660. {
  661. pn = 13;
  662. }
  663. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  664. {
  665. pn = 22;
  666. }
  667. }
  668. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1)
  669. {
  670. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  671. {
  672. pn = 5;
  673. }
  674. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  675. {
  676. pn = 14;
  677. }
  678. else if(cv[i-1].coord.x-1 == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y)
  679. {
  680. pn = 23;
  681. }
  682. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  683. {
  684. pn = 24;
  685. }
  686. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  687. {
  688. pn = 4;
  689. }
  690. }
  691. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y)
  692. {
  693. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  694. {
  695. pn = 6;
  696. }
  697. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
  698. {
  699. pn = 15;
  700. }
  701. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  702. {
  703. pn = 24;
  704. }
  705. }
  706. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1)
  707. {
  708. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
  709. {
  710. pn = 7;
  711. }
  712. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  713. {
  714. pn = 16;
  715. }
  716. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  717. {
  718. pn = 17;
  719. }
  720. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  721. {
  722. pn = 6;
  723. }
  724. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  725. {
  726. pn = 18;
  727. }
  728. }
  729. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1)
  730. {
  731. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  732. {
  733. pn = 8;
  734. }
  735. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  736. {
  737. pn = 9;
  738. }
  739. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  740. {
  741. pn = 18;
  742. }
  743. }
  744. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1)
  745. {
  746. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  747. {
  748. pn = 1;
  749. }
  750. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  751. {
  752. pn = 10;
  753. }
  754. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  755. {
  756. pn = 19;
  757. }
  758. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  759. {
  760. pn = 8;
  761. }
  762. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  763. {
  764. pn = 20;
  765. }
  766. }
  767. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y)
  768. {
  769. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  770. {
  771. pn = 2;
  772. }
  773. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  774. {
  775. pn = 11;
  776. }
  777. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  778. {
  779. pn = 20;
  780. }
  781. }
  782. }
  783. if (pn>=0)
  784. {
  785. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  786. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  787. if (x<0 || y<0 || x>pos.w || y>pos.h)
  788. continue;
  789. int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
  790. hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
  791. if (hvx<0 && hvy<0)
  792. blitAtWR(arrows->ourImages[pn].bitmap,x,y);
  793. else if(hvx<0)
  794. SDL_BlitSurface
  795. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,0,0),
  796. ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,x,y));
  797. else if (hvy<0)
  798. {
  799. SDL_BlitSurface
  800. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  801. ekran,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  802. }
  803. else
  804. SDL_BlitSurface
  805. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  806. ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  807. }
  808. } //for (int i=0;i<currentPath->nodes.size()-1;i++)
  809. } // if (currentPath)
  810. }
  811. void CResDataBar::clickRight (tribool down)
  812. {
  813. }
  814. void CResDataBar::activate()
  815. {
  816. ClickableR::activate();
  817. }
  818. void CResDataBar::deactivate()
  819. {
  820. ClickableR::deactivate();
  821. }
  822. CResDataBar::CResDataBar()
  823. {
  824. bg = CGI->bitmaph->loadBitmap("ZRESBAR.bmp");
  825. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  826. blueToPlayersAdv(bg,LOCPLINT->playerID);
  827. //blueToPlayersNice(bg,LOCPLINT->playerID);
  828. pos = genRect(bg->h,bg->w,3,575);
  829. txtpos += (std::pair<int,int>(35,577)),(std::pair<int,int>(120,577)),(std::pair<int,int>(205,577)),
  830. (std::pair<int,int>(290,577)),(std::pair<int,int>(375,577)),(std::pair<int,int>(460,577)),
  831. (std::pair<int,int>(545,577)),(std::pair<int,int>(620,577));
  832. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63] + ": %s, " +
  833. CGI->generaltexth->allTexts[64] + ": %s";
  834. }
  835. CResDataBar::~CResDataBar()
  836. {
  837. SDL_FreeSurface(bg);
  838. }
  839. void CResDataBar::draw()
  840. {
  841. blitAt(bg,pos.x,pos.y);
  842. char * buf = new char[15];
  843. for (int i=0;i<7;i++)
  844. {
  845. itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
  846. printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly);
  847. }
  848. std::vector<std::string> temp;
  849. itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf);
  850. itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf);
  851. itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf);
  852. printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,GEOR13,zwykly);
  853. temp.clear();
  854. updateRect(&pos,ekran);
  855. delete buf;
  856. }
  857. CInfoBar::CInfoBar()
  858. {
  859. pos.x=604;
  860. pos.y=389;
  861. pos.w=194;
  862. pos.h=186;
  863. }
  864. void CInfoBar::draw(void * specific)
  865. {
  866. SDL_Surface * todr = LOCPLINT->infoWin(specific);
  867. blitAt(todr,pos.x,pos.y);
  868. SDL_FreeSurface(todr);
  869. }
  870. CAdvMapInt::CAdvMapInt(int Player)
  871. :player(Player),
  872. statusbar(7,556),
  873. kingOverview(CGI->preth->advKingdomOverview.first,CGI->preth->advKingdomOverview.second,
  874. &CAdvMapInt::fshowOverview, 679, 196, "IAM002.DEF"),
  875. underground(CGI->preth->advSurfaceSwitch.first,CGI->preth->advSurfaceSwitch.second,
  876. &CAdvMapInt::fswitchLevel, 711, 196, "IAM010.DEF", false, new std::vector<std::string>(1,std::string("IAM003.DEF"))),
  877. questlog(CGI->preth->advQuestlog.first,CGI->preth->advQuestlog.second,
  878. &CAdvMapInt::fshowQuestlog, 679, 228, "IAM004.DEF"),
  879. sleepWake(CGI->preth->advSleepWake.first,CGI->preth->advSleepWake.second,
  880. &CAdvMapInt::fsleepWake, 711, 228, "IAM005.DEF"),
  881. moveHero(CGI->preth->advMoveHero.first,CGI->preth->advMoveHero.second,
  882. &CAdvMapInt::fmoveHero, 679, 260, "IAM006.DEF"),
  883. spellbook(CGI->preth->advCastSpell.first,CGI->preth->advCastSpell.second,
  884. &CAdvMapInt::fshowSpellbok, 711, 260, "IAM007.DEF"),
  885. advOptions(CGI->preth->advAdvOptions.first,CGI->preth->advAdvOptions.second,
  886. &CAdvMapInt::fadventureOPtions, 679, 292, "IAM008.DEF"),
  887. sysOptions(CGI->preth->advSystemOptions.first,CGI->preth->advSystemOptions.second,
  888. &CAdvMapInt::fsystemOptions, 711, 292, "IAM009.DEF"),
  889. nextHero(CGI->preth->advNextHero.first,CGI->preth->advNextHero.second,
  890. &CAdvMapInt::fnextHero, 679, 324, "IAM000.DEF"),
  891. endTurn(CGI->preth->advEndTurn.first,CGI->preth->advEndTurn.second,
  892. &CAdvMapInt::fendTurn, 679, 356, "IAM001.DEF")
  893. {
  894. LOCPLINT->adventureInt=this;
  895. bg = CGI->bitmaph->loadBitmap("ADVMAP.bmp");
  896. blueToPlayersAdv(bg,player);
  897. scrollingLeft = false;
  898. scrollingRight = false;
  899. scrollingUp = false ;
  900. scrollingDown = false ;
  901. updateScreen = false;
  902. anim=0;
  903. animValHitCount=0; //animation frame
  904. heroList.init();
  905. heroList.genList();
  906. //townList.init();
  907. townList.genList();
  908. gems.push_back(CGI->spriteh->giveDef("agemLL.def"));
  909. gems.push_back(CGI->spriteh->giveDef("agemLR.def"));
  910. gems.push_back(CGI->spriteh->giveDef("agemUL.def"));
  911. gems.push_back(CGI->spriteh->giveDef("agemUR.def"));
  912. }
  913. void CAdvMapInt::fshowOverview()
  914. {
  915. }
  916. void CAdvMapInt::fswitchLevel()
  917. {
  918. if(!CGI->ac->map.twoLevel)
  919. return;
  920. if (position.z)
  921. {
  922. position.z--;
  923. underground.curimg=0;
  924. underground.show();
  925. }
  926. else
  927. {
  928. underground.curimg=1;
  929. position.z++;
  930. underground.show();
  931. }
  932. updateScreen = true;
  933. minimap.draw();
  934. }
  935. void CAdvMapInt::fshowQuestlog()
  936. {
  937. }
  938. void CAdvMapInt::fsleepWake()
  939. {
  940. }
  941. void CAdvMapInt::fmoveHero()
  942. {
  943. }
  944. void CAdvMapInt::fshowSpellbok()
  945. {
  946. }
  947. void CAdvMapInt::fadventureOPtions()
  948. {
  949. }
  950. void CAdvMapInt::fsystemOptions()
  951. {
  952. }
  953. void CAdvMapInt::fnextHero()
  954. {
  955. }
  956. void CAdvMapInt::fendTurn()
  957. {
  958. }
  959. void CAdvMapInt::show()
  960. {
  961. blitAt(bg,0,0);
  962. kingOverview.show();
  963. kingOverview.activate();
  964. underground.show();
  965. underground.activate();
  966. questlog.show();
  967. questlog.activate();
  968. sleepWake.show();
  969. sleepWake.activate();
  970. moveHero.show();
  971. moveHero.activate();
  972. spellbook.show();
  973. spellbook.activate();
  974. advOptions.show();
  975. advOptions.activate();
  976. sysOptions.show();
  977. sysOptions.activate();
  978. nextHero.show();
  979. nextHero.activate();
  980. endTurn.show();
  981. endTurn.activate();
  982. minimap.activate();
  983. minimap.draw();
  984. heroList.activate();
  985. heroList.draw();
  986. townList.activate();
  987. townList.draw();
  988. terrain.activate();
  989. resdatabar.draw();
  990. statusbar.show();
  991. SDL_Flip(ekran);
  992. }
  993. void CAdvMapInt::update()
  994. {
  995. terrain.show();
  996. blitAt(gems[2]->ourImages[LOCPLINT->playerID].bitmap,6,6);
  997. blitAt(gems[0]->ourImages[LOCPLINT->playerID].bitmap,6,508);
  998. blitAt(gems[1]->ourImages[LOCPLINT->playerID].bitmap,556,508);
  999. blitAt(gems[3]->ourImages[LOCPLINT->playerID].bitmap,556,6);
  1000. updateRect(&genRect(550,600,6,6));
  1001. }
  1002. void CAdvMapInt::centerOn(int3 on)
  1003. {
  1004. on.x -= (LOCPLINT->adventureInt->terrain.tilesw/2);
  1005. on.y -= (LOCPLINT->adventureInt->terrain.tilesh/2);
  1006. if (on.x<0)
  1007. on.x=-(Woff/2);
  1008. else if((on.x+LOCPLINT->adventureInt->terrain.tilesw) > (CGI->mh->sizes.x))
  1009. on.x=CGI->mh->sizes.x-LOCPLINT->adventureInt->terrain.tilesw+(Woff/2);
  1010. if (on.y<0)
  1011. on.y = -(Hoff/2);
  1012. else if((on.y+LOCPLINT->adventureInt->terrain.tilesh) > (CGI->mh->sizes.y))
  1013. on.y = CGI->mh->sizes.y-LOCPLINT->adventureInt->terrain.tilesh+(Hoff/2);
  1014. LOCPLINT->adventureInt->position.x=on.x;
  1015. LOCPLINT->adventureInt->position.y=on.y;
  1016. LOCPLINT->adventureInt->updateScreen=true;
  1017. }
  1018. CAdvMapInt::CurrentSelection::CurrentSelection()
  1019. {
  1020. type=-1;
  1021. selected=NULL;
  1022. }