CAdvmapInterface.cpp 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
  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)/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());//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. currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->getPath(currentHero->pos,mp,currentHero);
  595. }
  596. void CTerrainRect::clickRight(tribool down)
  597. {
  598. }
  599. void CTerrainRect::mouseMoved (SDL_MouseMotionEvent & sEvent)
  600. {
  601. //TODO: print names of objects in toolbar
  602. }
  603. void CTerrainRect::hover(bool on){}
  604. void CTerrainRect::keyPressed (SDL_KeyboardEvent & key){}
  605. void CTerrainRect::show()
  606. {
  607. SDL_Surface * teren = CGI->mh->terrainRect
  608. (LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
  609. tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim);
  610. SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),ekran,&genRect(547,594,7,6));
  611. SDL_FreeSurface(teren);
  612. if (currentPath) //drawing path
  613. {
  614. for (int i=0;i<currentPath->nodes.size()-1;i++)
  615. {
  616. int pn=-1;//number of picture
  617. if (i==0) //last tile
  618. {
  619. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  620. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  621. if (x<0 || y<0 || x>pos.w || y>pos.h)
  622. continue;
  623. pn=0;
  624. }
  625. else
  626. {
  627. std::vector<CPathNode> & cv = currentPath->nodes;
  628. if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1)
  629. {
  630. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  631. {
  632. pn = 3;
  633. }
  634. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  635. {
  636. pn = 12;
  637. }
  638. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  639. {
  640. pn = 21;
  641. }
  642. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  643. {
  644. pn = 22;
  645. }
  646. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  647. {
  648. pn = 2;
  649. }
  650. }
  651. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1)
  652. {
  653. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  654. {
  655. pn = 4;
  656. }
  657. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  658. {
  659. pn = 13;
  660. }
  661. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  662. {
  663. pn = 22;
  664. }
  665. }
  666. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1)
  667. {
  668. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  669. {
  670. pn = 5;
  671. }
  672. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  673. {
  674. pn = 14;
  675. }
  676. else if(cv[i-1].coord.x-1 == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y)
  677. {
  678. pn = 23;
  679. }
  680. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  681. {
  682. pn = 24;
  683. }
  684. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  685. {
  686. pn = 4;
  687. }
  688. }
  689. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y)
  690. {
  691. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  692. {
  693. pn = 6;
  694. }
  695. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
  696. {
  697. pn = 15;
  698. }
  699. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  700. {
  701. pn = 24;
  702. }
  703. }
  704. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1)
  705. {
  706. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
  707. {
  708. pn = 7;
  709. }
  710. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  711. {
  712. pn = 16;
  713. }
  714. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  715. {
  716. pn = 17;
  717. }
  718. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  719. {
  720. pn = 6;
  721. }
  722. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  723. {
  724. pn = 18;
  725. }
  726. }
  727. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1)
  728. {
  729. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  730. {
  731. pn = 8;
  732. }
  733. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  734. {
  735. pn = 9;
  736. }
  737. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  738. {
  739. pn = 18;
  740. }
  741. }
  742. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1)
  743. {
  744. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  745. {
  746. pn = 1;
  747. }
  748. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  749. {
  750. pn = 10;
  751. }
  752. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  753. {
  754. pn = 19;
  755. }
  756. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  757. {
  758. pn = 8;
  759. }
  760. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  761. {
  762. pn = 20;
  763. }
  764. }
  765. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y)
  766. {
  767. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  768. {
  769. pn = 2;
  770. }
  771. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  772. {
  773. pn = 11;
  774. }
  775. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  776. {
  777. pn = 20;
  778. }
  779. }
  780. }
  781. if (pn>=0)
  782. {
  783. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  784. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  785. if (x<0 || y<0 || x>pos.w || y>pos.h)
  786. continue;
  787. int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
  788. hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
  789. if (hvx<0 && hvy<0)
  790. blitAtWR(arrows->ourImages[pn].bitmap,x,y);
  791. else if(hvx<0)
  792. SDL_BlitSurface
  793. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,0,0),
  794. ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,x,y));
  795. else if (hvy<0)
  796. {
  797. SDL_BlitSurface
  798. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  799. ekran,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  800. }
  801. else
  802. SDL_BlitSurface
  803. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  804. ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  805. }
  806. } //for (int i=0;i<currentPath->nodes.size()-1;i++)
  807. } // if (currentPath)
  808. }
  809. void CResDataBar::clickRight (tribool down)
  810. {
  811. }
  812. void CResDataBar::activate()
  813. {
  814. ClickableR::activate();
  815. }
  816. void CResDataBar::deactivate()
  817. {
  818. ClickableR::deactivate();
  819. }
  820. CResDataBar::CResDataBar()
  821. {
  822. bg = CGI->bitmaph->loadBitmap("ZRESBAR.bmp");
  823. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  824. blueToPlayersAdv(bg,LOCPLINT->playerID);
  825. //blueToPlayersNice(bg,LOCPLINT->playerID);
  826. pos = genRect(bg->h,bg->w,3,575);
  827. txtpos += (std::pair<int,int>(35,577)),(std::pair<int,int>(120,577)),(std::pair<int,int>(205,577)),
  828. (std::pair<int,int>(290,577)),(std::pair<int,int>(375,577)),(std::pair<int,int>(460,577)),
  829. (std::pair<int,int>(545,577)),(std::pair<int,int>(620,577));
  830. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63] + ": %s, " +
  831. CGI->generaltexth->allTexts[64] + ": %s";
  832. }
  833. CResDataBar::~CResDataBar()
  834. {
  835. SDL_FreeSurface(bg);
  836. }
  837. void CResDataBar::draw()
  838. {
  839. blitAt(bg,pos.x,pos.y);
  840. char * buf = new char[15];
  841. for (int i=0;i<7;i++)
  842. {
  843. itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
  844. printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly);
  845. }
  846. std::vector<std::string> temp;
  847. itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf);
  848. itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf);
  849. itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf);
  850. printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,GEOR13,zwykly);
  851. temp.clear();
  852. updateRect(&pos,ekran);
  853. delete buf;
  854. }
  855. CInfoBar::CInfoBar()
  856. {
  857. pos.x=604;
  858. pos.y=389;
  859. pos.w=194;
  860. pos.h=186;
  861. }
  862. void CInfoBar::draw(void * specific)
  863. {
  864. SDL_Surface * todr = LOCPLINT->infoWin(specific);
  865. blitAt(todr,pos.x,pos.y);
  866. SDL_FreeSurface(todr);
  867. }
  868. CAdvMapInt::CAdvMapInt(int Player)
  869. :player(Player),
  870. statusbar(7,556),
  871. kingOverview(CGI->preth->advKingdomOverview.first,CGI->preth->advKingdomOverview.second,
  872. &CAdvMapInt::fshowOverview, 679, 196, "IAM002.DEF"),
  873. underground(CGI->preth->advSurfaceSwitch.first,CGI->preth->advSurfaceSwitch.second,
  874. &CAdvMapInt::fswitchLevel, 711, 196, "IAM010.DEF", false, new std::vector<std::string>(1,std::string("IAM003.DEF"))),
  875. questlog(CGI->preth->advQuestlog.first,CGI->preth->advQuestlog.second,
  876. &CAdvMapInt::fshowQuestlog, 679, 228, "IAM004.DEF"),
  877. sleepWake(CGI->preth->advSleepWake.first,CGI->preth->advSleepWake.second,
  878. &CAdvMapInt::fsleepWake, 711, 228, "IAM005.DEF"),
  879. moveHero(CGI->preth->advMoveHero.first,CGI->preth->advMoveHero.second,
  880. &CAdvMapInt::fmoveHero, 679, 260, "IAM006.DEF"),
  881. spellbook(CGI->preth->advCastSpell.first,CGI->preth->advCastSpell.second,
  882. &CAdvMapInt::fshowSpellbok, 711, 260, "IAM007.DEF"),
  883. advOptions(CGI->preth->advAdvOptions.first,CGI->preth->advAdvOptions.second,
  884. &CAdvMapInt::fadventureOPtions, 679, 292, "IAM008.DEF"),
  885. sysOptions(CGI->preth->advSystemOptions.first,CGI->preth->advSystemOptions.second,
  886. &CAdvMapInt::fsystemOptions, 711, 292, "IAM009.DEF"),
  887. nextHero(CGI->preth->advNextHero.first,CGI->preth->advNextHero.second,
  888. &CAdvMapInt::fnextHero, 679, 324, "IAM000.DEF"),
  889. endTurn(CGI->preth->advEndTurn.first,CGI->preth->advEndTurn.second,
  890. &CAdvMapInt::fendTurn, 679, 356, "IAM001.DEF")
  891. {
  892. LOCPLINT->adventureInt=this;
  893. bg = CGI->bitmaph->loadBitmap("ADVMAP.bmp");
  894. blueToPlayersAdv(bg,player);
  895. scrollingLeft = false;
  896. scrollingRight = false;
  897. scrollingUp = false ;
  898. scrollingDown = false ;
  899. updateScreen = false;
  900. anim=0;
  901. animValHitCount=0; //animation frame
  902. heroList.init();
  903. heroList.genList();
  904. //townList.init();
  905. townList.genList();
  906. gems.push_back(CGI->spriteh->giveDef("agemLL.def"));
  907. gems.push_back(CGI->spriteh->giveDef("agemLR.def"));
  908. gems.push_back(CGI->spriteh->giveDef("agemUL.def"));
  909. gems.push_back(CGI->spriteh->giveDef("agemUR.def"));
  910. }
  911. void CAdvMapInt::fshowOverview()
  912. {
  913. }
  914. void CAdvMapInt::fswitchLevel()
  915. {
  916. if(!CGI->ac->map.twoLevel)
  917. return;
  918. if (position.z)
  919. {
  920. position.z--;
  921. underground.curimg=0;
  922. underground.show();
  923. }
  924. else
  925. {
  926. underground.curimg=1;
  927. position.z++;
  928. underground.show();
  929. }
  930. updateScreen = true;
  931. minimap.draw();
  932. }
  933. void CAdvMapInt::fshowQuestlog()
  934. {
  935. }
  936. void CAdvMapInt::fsleepWake()
  937. {
  938. }
  939. void CAdvMapInt::fmoveHero()
  940. {
  941. }
  942. void CAdvMapInt::fshowSpellbok()
  943. {
  944. }
  945. void CAdvMapInt::fadventureOPtions()
  946. {
  947. }
  948. void CAdvMapInt::fsystemOptions()
  949. {
  950. }
  951. void CAdvMapInt::fnextHero()
  952. {
  953. }
  954. void CAdvMapInt::fendTurn()
  955. {
  956. }
  957. void CAdvMapInt::show()
  958. {
  959. blitAt(bg,0,0);
  960. kingOverview.show();
  961. kingOverview.activate();
  962. underground.show();
  963. underground.activate();
  964. questlog.show();
  965. questlog.activate();
  966. sleepWake.show();
  967. sleepWake.activate();
  968. moveHero.show();
  969. moveHero.activate();
  970. spellbook.show();
  971. spellbook.activate();
  972. advOptions.show();
  973. advOptions.activate();
  974. sysOptions.show();
  975. sysOptions.activate();
  976. nextHero.show();
  977. nextHero.activate();
  978. endTurn.show();
  979. endTurn.activate();
  980. minimap.activate();
  981. minimap.draw();
  982. heroList.activate();
  983. heroList.draw();
  984. townList.activate();
  985. townList.draw();
  986. terrain.activate();
  987. resdatabar.draw();
  988. statusbar.show();
  989. SDL_Flip(ekran);
  990. }
  991. void CAdvMapInt::update()
  992. {
  993. terrain.show();
  994. blitAt(gems[2]->ourImages[LOCPLINT->playerID].bitmap,6,6);
  995. blitAt(gems[0]->ourImages[LOCPLINT->playerID].bitmap,6,508);
  996. blitAt(gems[1]->ourImages[LOCPLINT->playerID].bitmap,556,508);
  997. blitAt(gems[3]->ourImages[LOCPLINT->playerID].bitmap,556,6);
  998. updateRect(&genRect(550,600,6,6));
  999. }
  1000. void CAdvMapInt::centerOn(int3 on)
  1001. {
  1002. on.x -= (LOCPLINT->adventureInt->terrain.tilesw/2);
  1003. on.y -= (LOCPLINT->adventureInt->terrain.tilesh/2);
  1004. if (on.x<0)
  1005. on.x=-(Woff/2);
  1006. else if((on.x+LOCPLINT->adventureInt->terrain.tilesw) > (CGI->mh->sizes.x))
  1007. on.x=CGI->mh->sizes.x-LOCPLINT->adventureInt->terrain.tilesw+(Woff/2);
  1008. if (on.y<0)
  1009. on.y = -(Hoff/2);
  1010. else if((on.y+LOCPLINT->adventureInt->terrain.tilesh) > (CGI->mh->sizes.y))
  1011. on.y = CGI->mh->sizes.y-LOCPLINT->adventureInt->terrain.tilesh+(Hoff/2);
  1012. LOCPLINT->adventureInt->position.x=on.x;
  1013. LOCPLINT->adventureInt->position.y=on.y;
  1014. LOCPLINT->adventureInt->updateScreen=true;
  1015. }
  1016. CAdvMapInt::CurrentSelection::CurrentSelection()
  1017. {
  1018. type=-1;
  1019. selected=NULL;
  1020. }