CAdvmapInterface.cpp 28 KB

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