CAdvmapInterface.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  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("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. MotionInterested::deactivate();
  446. ClickableL::clickLeft(down);
  447. if (!((bool)down))
  448. return;
  449. float dx=((float)(LOCPLINT->current->motion.x-pos.x))/((float)pos.w),
  450. dy=((float)(LOCPLINT->current->motion.y-pos.y))/((float)pos.h);
  451. int3 newCPos;
  452. newCPos.x = (CGI->mh->sizes.x*dx);
  453. newCPos.y = (CGI->mh->sizes.y*dy);
  454. newCPos.z = LOCPLINT->adventureInt->position.z;
  455. LOCPLINT->adventureInt->centerOn(newCPos);
  456. }
  457. void CMinimap::hover (bool on)
  458. {
  459. Hoverable::hover(on);
  460. if (on)
  461. LOCPLINT->adventureInt->statusbar.print(statusbarTxt);
  462. else if (LOCPLINT->adventureInt->statusbar.current==statusbarTxt)
  463. LOCPLINT->adventureInt->statusbar.clear();
  464. }
  465. void CMinimap::mouseMoved (SDL_MouseMotionEvent & sEvent)
  466. {
  467. if (pressedL)
  468. {
  469. clickLeft(true);
  470. }
  471. }
  472. void CMinimap::activate()
  473. {
  474. ClickableL::activate();
  475. ClickableR::activate();
  476. Hoverable::activate();
  477. if (pressedL)
  478. MotionInterested::activate();
  479. }
  480. void CMinimap::deactivate()
  481. {
  482. if (pressedL)
  483. MotionInterested::deactivate();
  484. ClickableL::deactivate();
  485. ClickableR::deactivate();
  486. Hoverable::deactivate();
  487. }
  488. CTerrainRect::CTerrainRect():currentPath(NULL)
  489. {
  490. tilesw=19;
  491. tilesh=18;
  492. pos.x=7;
  493. pos.y=6;
  494. pos.w=594;
  495. pos.h=547;
  496. arrows = CGI->spriteh->giveDef("ADAG.DEF");
  497. for(int y=0; y<arrows->ourImages.size(); ++y)
  498. {
  499. CSDL_Ext::fullAlphaTransform(arrows->ourImages[y].bitmap);
  500. }
  501. }
  502. void CTerrainRect::activate()
  503. {
  504. ClickableL::activate();
  505. ClickableR::activate();
  506. Hoverable::activate();
  507. KeyInterested::activate();
  508. };
  509. void CTerrainRect::deactivate()
  510. {
  511. ClickableL::deactivate();
  512. ClickableR::deactivate();
  513. Hoverable::deactivate();
  514. KeyInterested::deactivate();
  515. };
  516. void CTerrainRect::clickLeft(tribool down){}
  517. void CTerrainRect::clickRight(tribool down){}
  518. void CTerrainRect::hover(bool on){}
  519. void CTerrainRect::keyPressed (SDL_KeyboardEvent & key){}
  520. void CTerrainRect::show()
  521. {
  522. SDL_Surface * teren = CGI->mh->terrainRect
  523. (LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
  524. tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim);
  525. SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),ekran,&genRect(547,594,7,6));
  526. SDL_FreeSurface(teren);
  527. if (currentPath) //drawing path
  528. {
  529. for (int i=0;i<currentPath->nodes.size()-1;i++)
  530. {
  531. int pn=-1;//number of picture
  532. if (i==0) //last tile
  533. {
  534. int x = 32*(currentPath->nodes[i].x-LOCPLINT->adventureInt->position.x)+7,
  535. y = 32*(currentPath->nodes[i].y-LOCPLINT->adventureInt->position.y)+6;
  536. if (x<0 || y<0 || x>pos.w || y>pos.h)
  537. continue;
  538. pn=0;
  539. }
  540. else
  541. {
  542. std::vector<CPathNode> & cv = currentPath->nodes;
  543. if (cv[i+1].x == cv[i].x-1 && cv[i+1].y == cv[i].y-1)
  544. {
  545. if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y)
  546. {
  547. pn = 3;
  548. }
  549. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y+1)
  550. {
  551. pn = 12;
  552. }
  553. else if(cv[i-1].x == cv[i].x && cv[i-1].y == cv[i].y+1)
  554. {
  555. pn = 21;
  556. }
  557. else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y+1)
  558. {
  559. pn = 22;
  560. }
  561. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y-1)
  562. {
  563. pn = 2;
  564. }
  565. }
  566. else if (cv[i+1].x == cv[i].x && cv[i+1].y == cv[i].y-1)
  567. {
  568. if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y+1)
  569. {
  570. pn = 4;
  571. }
  572. else if(cv[i-1].x == cv[i].x && cv[i-1].y == cv[i].y+1)
  573. {
  574. pn = 13;
  575. }
  576. else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y+1)
  577. {
  578. pn = 22;
  579. }
  580. }
  581. else if (cv[i+1].x == cv[i].x+1 && cv[i+1].y == cv[i].y-1)
  582. {
  583. if(cv[i-1].x == cv[i].x && cv[i-1].y == cv[i].y+1)
  584. {
  585. pn = 5;
  586. }
  587. else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y+1)
  588. {
  589. pn = 14;
  590. }
  591. else if(cv[i-1].x-1 == cv[i].x && cv[i-1].y == cv[i].y)
  592. {
  593. pn = 23;
  594. }
  595. else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y-1)
  596. {
  597. pn = 24;
  598. }
  599. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y+1)
  600. {
  601. pn = 4;
  602. }
  603. }
  604. else if (cv[i+1].x == cv[i].x+1 && cv[i+1].y == cv[i].y)
  605. {
  606. if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y+1)
  607. {
  608. pn = 6;
  609. }
  610. else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y)
  611. {
  612. pn = 15;
  613. }
  614. else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y-1)
  615. {
  616. pn = 24;
  617. }
  618. }
  619. else if (cv[i+1].x == cv[i].x+1 && cv[i+1].y == cv[i].y+1)
  620. {
  621. if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y)
  622. {
  623. pn = 7;
  624. }
  625. else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y-1)
  626. {
  627. pn = 16;
  628. }
  629. else if(cv[i-1].x == cv[i].x && cv[i-1].y == cv[i].y-1)
  630. {
  631. pn = 17;
  632. }
  633. else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y+1)
  634. {
  635. pn = 6;
  636. }
  637. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y-1)
  638. {
  639. pn = 18;
  640. }
  641. }
  642. else if (cv[i+1].x == cv[i].x && cv[i+1].y == cv[i].y+1)
  643. {
  644. if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y-1)
  645. {
  646. pn = 8;
  647. }
  648. else if(cv[i-1].x == cv[i].x && cv[i-1].y == cv[i].y-1)
  649. {
  650. pn = 9;
  651. }
  652. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y-1)
  653. {
  654. pn = 18;
  655. }
  656. }
  657. else if (cv[i+1].x == cv[i].x-1 && cv[i+1].y == cv[i].y+1)
  658. {
  659. if(cv[i-1].x == cv[i].x && cv[i-1].y == cv[i].y-1)
  660. {
  661. pn = 1;
  662. }
  663. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y-1)
  664. {
  665. pn = 10;
  666. }
  667. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y)
  668. {
  669. pn = 19;
  670. }
  671. else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y-1)
  672. {
  673. pn = 8;
  674. }
  675. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y+1)
  676. {
  677. pn = 20;
  678. }
  679. }
  680. else if (cv[i+1].x == cv[i].x-1 && cv[i+1].y == cv[i].y)
  681. {
  682. if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y-1)
  683. {
  684. pn = 2;
  685. }
  686. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y)
  687. {
  688. pn = 11;
  689. }
  690. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y+1)
  691. {
  692. pn = 20;
  693. }
  694. }
  695. }
  696. if (pn>=0)
  697. {
  698. int x = 32*(currentPath->nodes[i].x-LOCPLINT->adventureInt->position.x)+7,
  699. y = 32*(currentPath->nodes[i].y-LOCPLINT->adventureInt->position.y)+6;
  700. if (x<0 || y<0 || x>pos.w || y>pos.h)
  701. continue;
  702. int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
  703. hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
  704. if (hvx<0 && hvy<0)
  705. blitAtWR(arrows->ourImages[pn].bitmap,x,y);
  706. else if(hvx<0)
  707. SDL_BlitSurface
  708. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,0,0),
  709. ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,x,y));
  710. else if (hvy<0)
  711. {
  712. SDL_BlitSurface
  713. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  714. ekran,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  715. }
  716. else
  717. SDL_BlitSurface
  718. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  719. ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  720. }
  721. } //for (int i=0;i<currentPath->nodes.size()-1;i++)
  722. } // if (currentPath)
  723. }
  724. CAdvMapInt::CAdvMapInt(int Player)
  725. :player(Player),
  726. statusbar(7,556),
  727. kingOverview(CGI->preth->advKingdomOverview.first,CGI->preth->advKingdomOverview.second,
  728. &CAdvMapInt::fshowOverview, 679, 196, "IAM002.DEF"),
  729. underground(CGI->preth->advSurfaceSwitch.first,CGI->preth->advSurfaceSwitch.second,
  730. &CAdvMapInt::fswitchLevel, 711, 196, "IAM010.DEF", false, new std::vector<std::string>(1,std::string("IAM003.DEF"))),
  731. questlog(CGI->preth->advQuestlog.first,CGI->preth->advQuestlog.second,
  732. &CAdvMapInt::fshowQuestlog, 679, 228, "IAM004.DEF"),
  733. sleepWake(CGI->preth->advSleepWake.first,CGI->preth->advSleepWake.second,
  734. &CAdvMapInt::fsleepWake, 711, 228, "IAM005.DEF"),
  735. moveHero(CGI->preth->advMoveHero.first,CGI->preth->advMoveHero.second,
  736. &CAdvMapInt::fmoveHero, 679, 260, "IAM006.DEF"),
  737. spellbook(CGI->preth->advCastSpell.first,CGI->preth->advCastSpell.second,
  738. &CAdvMapInt::fshowSpellbok, 711, 260, "IAM007.DEF"),
  739. advOptions(CGI->preth->advAdvOptions.first,CGI->preth->advAdvOptions.second,
  740. &CAdvMapInt::fadventureOPtions, 679, 292, "IAM008.DEF"),
  741. sysOptions(CGI->preth->advSystemOptions.first,CGI->preth->advSystemOptions.second,
  742. &CAdvMapInt::fsystemOptions, 711, 292, "IAM009.DEF"),
  743. nextHero(CGI->preth->advNextHero.first,CGI->preth->advNextHero.second,
  744. &CAdvMapInt::fnextHero, 679, 324, "IAM000.DEF"),
  745. endTurn(CGI->preth->advEndTurn.first,CGI->preth->advEndTurn.second,
  746. &CAdvMapInt::fendTurn, 679, 356, "IAM001.DEF")
  747. {
  748. LOCPLINT->adventureInt=this;
  749. bg = CGI->bitmaph->loadBitmap("ADVMAP.bmp");
  750. blueToPlayersAdv(bg,player);
  751. scrollingLeft = false;
  752. scrollingRight = false;
  753. scrollingUp = false ;
  754. scrollingDown = false ;
  755. updateScreen = false;
  756. anim=0;
  757. animValHitCount=0; //animation frame
  758. heroList.init();
  759. heroList.genList();
  760. gems.push_back(CGI->spriteh->giveDef("agemLL.def"));
  761. gems.push_back(CGI->spriteh->giveDef("agemLR.def"));
  762. gems.push_back(CGI->spriteh->giveDef("agemUL.def"));
  763. gems.push_back(CGI->spriteh->giveDef("agemUR.def"));
  764. }
  765. void CAdvMapInt::fshowOverview()
  766. {
  767. }
  768. void CAdvMapInt::fswitchLevel()
  769. {
  770. if(!CGI->ac->map.twoLevel)
  771. return;
  772. if (position.z)
  773. {
  774. position.z--;
  775. underground.curimg=0;
  776. underground.show();
  777. }
  778. else
  779. {
  780. underground.curimg=1;
  781. position.z++;
  782. underground.show();
  783. }
  784. updateScreen = true;
  785. minimap.draw();
  786. }
  787. void CAdvMapInt::fshowQuestlog()
  788. {
  789. }
  790. void CAdvMapInt::fsleepWake()
  791. {
  792. }
  793. void CAdvMapInt::fmoveHero()
  794. {
  795. }
  796. void CAdvMapInt::fshowSpellbok()
  797. {
  798. }
  799. void CAdvMapInt::fadventureOPtions()
  800. {
  801. }
  802. void CAdvMapInt::fsystemOptions()
  803. {
  804. }
  805. void CAdvMapInt::fnextHero()
  806. {
  807. }
  808. void CAdvMapInt::fendTurn()
  809. {
  810. }
  811. void CAdvMapInt::show()
  812. {
  813. blitAt(bg,0,0);
  814. kingOverview.show();
  815. kingOverview.activate();
  816. underground.show();
  817. underground.activate();
  818. questlog.show();
  819. questlog.activate();
  820. sleepWake.show();
  821. sleepWake.activate();
  822. moveHero.show();
  823. moveHero.activate();
  824. spellbook.show();
  825. spellbook.activate();
  826. advOptions.show();
  827. advOptions.activate();
  828. sysOptions.show();
  829. sysOptions.activate();
  830. nextHero.show();
  831. nextHero.activate();
  832. endTurn.show();
  833. endTurn.activate();
  834. minimap.activate();
  835. minimap.draw();
  836. heroList.activate();
  837. heroList.draw();
  838. statusbar.show();
  839. SDL_Flip(ekran);
  840. }
  841. void CAdvMapInt::update()
  842. {
  843. terrain.show();
  844. blitAt(gems[2]->ourImages[LOCPLINT->playerID].bitmap,6,6);
  845. blitAt(gems[0]->ourImages[LOCPLINT->playerID].bitmap,6,508);
  846. blitAt(gems[1]->ourImages[LOCPLINT->playerID].bitmap,556,508);
  847. blitAt(gems[3]->ourImages[LOCPLINT->playerID].bitmap,556,6);
  848. updateRect(&genRect(550,600,6,6));
  849. }
  850. void CAdvMapInt::centerOn(int3 on)
  851. {
  852. on.x -= (LOCPLINT->adventureInt->terrain.tilesw/2);
  853. on.y -= (LOCPLINT->adventureInt->terrain.tilesh/2);
  854. if (on.x<0)
  855. on.x=-(Woff/2);
  856. else if((on.x+LOCPLINT->adventureInt->terrain.tilesw) > (CGI->mh->sizes.x))
  857. on.x=CGI->mh->sizes.x-LOCPLINT->adventureInt->terrain.tilesw+(Woff/2);
  858. if (on.y<0)
  859. on.y = -(Hoff/2);
  860. else if((on.y+LOCPLINT->adventureInt->terrain.tilesh) > (CGI->mh->sizes.y))
  861. on.y = CGI->mh->sizes.y-LOCPLINT->adventureInt->terrain.tilesh+(Hoff/2);
  862. LOCPLINT->adventureInt->position.x=on.x;
  863. LOCPLINT->adventureInt->position.y=on.y;
  864. LOCPLINT->adventureInt->updateScreen=true;
  865. }
  866. CAdvMapInt::CurrentSelection::CurrentSelection()
  867. {
  868. type=NULL;
  869. selected=NULL;
  870. }