CAdvmapInterface.cpp 24 KB

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