CAdvmapInterface.cpp 28 KB

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