CAdvmapInterface.cpp 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. #include "stdafx.h"
  2. #include "CAdvmapInterface.h"
  3. #include "client/CBitmapHandler.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 = CDefHandler::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(screen,pos.x,pos.y,pos.w,pos.h);
  120. }
  121. void CMinimap::redraw(int level)// (level==-1) => redraw all levels
  122. {
  123. (CGI);
  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,screen);
  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. double wo = ((double)mw)/CGI->mh->sizes.x, ho = ((double)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 = CDefHandler::giveDef("ADAG.DEF");
  228. for(int y=0; y<arrows->ourImages.size(); ++y)
  229. {
  230. arrows->ourImages[y].bitmap = CSDL_Ext::alphaTransform(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. if(!mres)
  274. {
  275. delete currentPath;
  276. currentPath = NULL;
  277. int i=0;
  278. for(;i<LOCPLINT->adventureInt->heroList.items.size();i++)
  279. {
  280. if(LOCPLINT->adventureInt->heroList.items[i].first->subID == ((const CGHeroInstance*)LOCPLINT->adventureInt->selection.selected)->type->ID)
  281. {
  282. LOCPLINT->adventureInt->heroList.items[i].second = NULL;
  283. break;
  284. }
  285. }
  286. }
  287. }
  288. else
  289. {
  290. delete currentPath;
  291. currentPath=NULL;
  292. }
  293. }
  294. const CGHeroInstance * currentHero = (LOCPLINT->adventureInt->heroList.items.size())?(LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].first):(NULL);
  295. if(!currentHero)
  296. return;
  297. int3 bufpos = currentHero->getPosition(false);
  298. //bufpos.x-=1;
  299. if (mres)
  300. {
  301. vector<Coordinate>* p;
  302. p = CGI->pathf->GetPath(Coordinate(bufpos),Coordinate(mp),currentHero);
  303. //Convert to old format.
  304. currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->ConvertToOldFormat(p);
  305. //currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->getPath(bufpos,mp,currentHero,1);
  306. }
  307. }
  308. void CTerrainRect::clickRight(tribool down)
  309. {
  310. }
  311. void CTerrainRect::mouseMoved (SDL_MouseMotionEvent & sEvent)
  312. {
  313. int3 pom=LOCPLINT->adventureInt->verifyPos(whichTileIsIt(sEvent.x,sEvent.y));
  314. if (pom!=curHoveredTile)
  315. curHoveredTile=pom;
  316. else
  317. return;
  318. std::vector<std::string> temp = LOCPLINT->cb->getObjDescriptions(pom);
  319. if (temp.size())
  320. {
  321. LOCPLINT->adventureInt->statusbar.print((*((temp.end())-1)));
  322. }
  323. else
  324. {
  325. LOCPLINT->adventureInt->statusbar.clear();
  326. }
  327. }
  328. void CTerrainRect::keyPressed (SDL_KeyboardEvent & key){}
  329. void CTerrainRect::hover(bool on)
  330. {
  331. if (!on)
  332. LOCPLINT->adventureInt->statusbar.clear();
  333. }
  334. void CTerrainRect::showPath()
  335. {
  336. for (int i=0;i<currentPath->nodes.size()-1;i++)
  337. {
  338. int pn=-1;//number of picture
  339. if (i==0) //last tile
  340. {
  341. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  342. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  343. if (x<0 || y<0 || x>pos.w || y>pos.h)
  344. continue;
  345. pn=0;
  346. }
  347. else
  348. {
  349. std::vector<CPathNode> & cv = currentPath->nodes;
  350. if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1)
  351. {
  352. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  353. {
  354. pn = 3;
  355. }
  356. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  357. {
  358. pn = 12;
  359. }
  360. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  361. {
  362. pn = 21;
  363. }
  364. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  365. {
  366. pn = 22;
  367. }
  368. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  369. {
  370. pn = 2;
  371. }
  372. }
  373. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1)
  374. {
  375. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  376. {
  377. pn = 4;
  378. }
  379. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  380. {
  381. pn = 13;
  382. }
  383. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  384. {
  385. pn = 22;
  386. }
  387. }
  388. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1)
  389. {
  390. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  391. {
  392. pn = 5;
  393. }
  394. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  395. {
  396. pn = 14;
  397. }
  398. else if(cv[i-1].coord.x+1 == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y)
  399. {
  400. pn = 23;
  401. }
  402. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  403. {
  404. pn = 24;
  405. }
  406. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  407. {
  408. pn = 4;
  409. }
  410. }
  411. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y)
  412. {
  413. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  414. {
  415. pn = 6;
  416. }
  417. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
  418. {
  419. pn = 15;
  420. }
  421. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  422. {
  423. pn = 24;
  424. }
  425. }
  426. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1)
  427. {
  428. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
  429. {
  430. pn = 7;
  431. }
  432. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  433. {
  434. pn = 16;
  435. }
  436. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  437. {
  438. pn = 17;
  439. }
  440. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  441. {
  442. pn = 6;
  443. }
  444. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  445. {
  446. pn = 18;
  447. }
  448. }
  449. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1)
  450. {
  451. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  452. {
  453. pn = 8;
  454. }
  455. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  456. {
  457. pn = 9;
  458. }
  459. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  460. {
  461. pn = 18;
  462. }
  463. }
  464. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1)
  465. {
  466. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  467. {
  468. pn = 1;
  469. }
  470. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  471. {
  472. pn = 10;
  473. }
  474. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  475. {
  476. pn = 19;
  477. }
  478. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  479. {
  480. pn = 8;
  481. }
  482. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  483. {
  484. pn = 20;
  485. }
  486. }
  487. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y)
  488. {
  489. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  490. {
  491. pn = 2;
  492. }
  493. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  494. {
  495. pn = 11;
  496. }
  497. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  498. {
  499. pn = 20;
  500. }
  501. }
  502. }
  503. if ( ((currentPath->nodes[i].dist)-(*(currentPath->nodes.end()-1)).dist) > ((const CGHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->movement)
  504. pn+=25;
  505. if (pn>=0)
  506. {
  507. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  508. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  509. if (x<0 || y<0 || x>pos.w || y>pos.h)
  510. continue;
  511. int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
  512. hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
  513. if (hvx<0 && hvy<0)
  514. {
  515. CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, screen, &genRect(32, 32, x, y));
  516. }
  517. else if(hvx<0)
  518. {
  519. CSDL_Ext::blit8bppAlphaTo24bpp
  520. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,0,0),
  521. screen,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,x,y));
  522. }
  523. else if (hvy<0)
  524. {
  525. CSDL_Ext::blit8bppAlphaTo24bpp
  526. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  527. screen,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  528. }
  529. else
  530. {
  531. CSDL_Ext::blit8bppAlphaTo24bpp
  532. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  533. screen,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  534. }
  535. }
  536. } //for (int i=0;i<currentPath->nodes.size()-1;i++)
  537. }
  538. void CTerrainRect::show()
  539. {
  540. SDL_Surface * teren = CGI->mh->terrainRect
  541. (LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
  542. tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim,
  543. LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim,
  544. screen,&genRect(547,594,7,6)
  545. );
  546. //SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));
  547. //SDL_FreeSurface(teren);
  548. if (currentPath && LOCPLINT->adventureInt->position.z==currentPath->startPos().z) //drawing path
  549. {
  550. showPath();
  551. }
  552. }
  553. int3 CTerrainRect::whichTileIsIt(int x, int y)
  554. {
  555. int3 ret;
  556. ret.x = LOCPLINT->adventureInt->position.x + ((LOCPLINT->current->motion.x-pos.x)/32);
  557. ret.y = LOCPLINT->adventureInt->position.y + ((LOCPLINT->current->motion.y-pos.y)/32);
  558. ret.z = LOCPLINT->adventureInt->position.z;
  559. return ret;
  560. }
  561. int3 CTerrainRect::whichTileIsIt()
  562. {
  563. return whichTileIsIt(LOCPLINT->current->motion.x,LOCPLINT->current->motion.y);
  564. }
  565. void CResDataBar::clickRight (tribool down)
  566. {
  567. }
  568. void CResDataBar::activate()
  569. {
  570. ClickableR::activate();
  571. }
  572. void CResDataBar::deactivate()
  573. {
  574. ClickableR::deactivate();
  575. }
  576. CResDataBar::CResDataBar()
  577. {
  578. bg = BitmapHandler::loadBitmap("ZRESBAR.bmp");
  579. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  580. //std::vector<SDL_Color> kolory;
  581. //SDL_Color p1={40,65,139,255}, p2={36,59,125,255}, p3={35,56,121,255};
  582. //kolory+=p1,p2,p3;
  583. //blueToPlayersAdv(bg,LOCPLINT->playerID,2,&kolory);
  584. blueToPlayersAdv(bg,LOCPLINT->playerID,2);
  585. pos = genRect(bg->h,bg->w,3,575);
  586. txtpos += (std::pair<int,int>(35,577)),(std::pair<int,int>(120,577)),(std::pair<int,int>(205,577)),
  587. (std::pair<int,int>(290,577)),(std::pair<int,int>(375,577)),(std::pair<int,int>(460,577)),
  588. (std::pair<int,int>(545,577)),(std::pair<int,int>(620,577));
  589. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63] + ": %s, " +
  590. CGI->generaltexth->allTexts[64] + ": %s";
  591. }
  592. CResDataBar::~CResDataBar()
  593. {
  594. SDL_FreeSurface(bg);
  595. }
  596. void CResDataBar::draw()
  597. {
  598. blitAt(bg,pos.x,pos.y);
  599. char * buf = new char[15];
  600. for (int i=0;i<7;i++)
  601. {
  602. itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
  603. printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly);
  604. }
  605. std::vector<std::string> temp;
  606. itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf);
  607. itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf);
  608. itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf);
  609. printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,GEOR13,zwykly);
  610. temp.clear();
  611. //updateRect(&pos,screen);
  612. delete[] buf;
  613. }
  614. CInfoBar::CInfoBar()
  615. {
  616. toNextTick = mode = pom = -1;
  617. pos.x=605;
  618. pos.y=389;
  619. pos.w=194;
  620. pos.h=186;
  621. day = CDefHandler::giveDef("NEWDAY.DEF");
  622. week1 = CDefHandler::giveDef("NEWWEEK1.DEF");
  623. week2 = CDefHandler::giveDef("NEWWEEK2.DEF");
  624. week3 = CDefHandler::giveDef("NEWWEEK3.DEF");
  625. week4 = CDefHandler::giveDef("NEWWEEK4.DEF");
  626. }
  627. CInfoBar::~CInfoBar()
  628. {
  629. delete day;
  630. delete week1;
  631. delete week2;
  632. delete week3;
  633. delete week4;
  634. }
  635. void CInfoBar::draw(const CGObjectInstance * specific)
  636. {
  637. if ((mode>=0) && mode<5)
  638. {
  639. blitAnim(mode);
  640. return;
  641. }
  642. else if (mode==5)
  643. {
  644. mode = -1;
  645. if(!LOCPLINT->adventureInt->selection.selected)
  646. {
  647. if (LOCPLINT->adventureInt->heroList.items.size())
  648. {
  649. LOCPLINT->adventureInt->heroList.select(0);
  650. }
  651. }
  652. draw((const CGObjectInstance *)LOCPLINT->adventureInt->selection.selected);
  653. }
  654. if (!specific)
  655. specific = (const CGObjectInstance *)LOCPLINT->adventureInt->selection.selected;
  656. //TODO: to rzutowanie wyglada groznie, ale dziala. Ale nie powinno wygladac groznie.
  657. if(!specific)
  658. return;
  659. if(specific->ID == 34) //hero
  660. {
  661. if(LOCPLINT->graphics.heroWins.find(specific->subID)!=LOCPLINT->graphics.heroWins.end())
  662. blitAt(LOCPLINT->graphics.heroWins[specific->subID],pos.x,pos.y);
  663. }
  664. else if (specific->ID == 98)
  665. {
  666. const CGTownInstance * t = static_cast<const CGTownInstance*>(specific);
  667. if(LOCPLINT->graphics.townWins.find(t->identifier)!=LOCPLINT->graphics.townWins.end())
  668. blitAt(LOCPLINT->graphics.townWins[t->identifier],pos.x,pos.y);
  669. }
  670. //SDL_Surface * todr = LOCPLINT->infoWin(specific);
  671. //if (!todr)
  672. // return;
  673. //blitAt(todr,pos.x,pos.y);
  674. //SDL_FreeSurface(todr);
  675. }
  676. CDefHandler * CInfoBar::getAnim(int mode)
  677. {
  678. switch(mode)
  679. {
  680. case 0:
  681. return day;
  682. break;
  683. case 1:
  684. return week1;
  685. break;
  686. case 2:
  687. return week2;
  688. break;
  689. case 3:
  690. return week3;
  691. break;
  692. case 4:
  693. return week4;
  694. break;
  695. default:
  696. return NULL;
  697. break;
  698. }
  699. }
  700. void CInfoBar::blitAnim(int mode)//0 - day, 1 - week
  701. {
  702. CDefHandler * anim = NULL;
  703. std::stringstream txt;
  704. anim = getAnim(mode);
  705. if(mode) //new week animation
  706. {
  707. txt << CGI->generaltexth->allTexts[63] << " " << LOCPLINT->cb->getDate(2);
  708. }
  709. else //new day
  710. {
  711. txt << CGI->generaltexth->allTexts[64] << " " << LOCPLINT->cb->getDate(1);
  712. }
  713. blitAt(anim->ourImages[pom].bitmap,pos.x+9,pos.y+10);
  714. printAtMiddle(txt.str(),700,420,TNRB16,zwykly);
  715. if (pom == anim->ourImages.size()-1)
  716. toNextTick+=750;
  717. }
  718. void CInfoBar::newDay(int Day)
  719. {
  720. if(LOCPLINT->cb->getDate(1) != 1)
  721. {
  722. mode = 0; //showing day
  723. }
  724. else
  725. {
  726. switch(LOCPLINT->cb->getDate(2))
  727. {
  728. case 1:
  729. mode = 1;
  730. break;
  731. case 2:
  732. mode = 2;
  733. break;
  734. case 3:
  735. mode = 3;
  736. break;
  737. case 4:
  738. mode = 4;
  739. break;
  740. default:
  741. mode = -1;
  742. break;
  743. }
  744. }
  745. pom = 0;
  746. TimeInterested::activate();
  747. toNextTick = 500;
  748. blitAnim(mode);
  749. //blitAt(day->ourImages[pom].bitmap,pos.x+10,pos.y+10);
  750. }
  751. void CInfoBar::showComp(SComponent * comp, int time)
  752. {
  753. SDL_Surface * b = BitmapHandler::loadBitmap("ADSTATOT.bmp");
  754. blitAt(b,pos.x+8,pos.y+11);
  755. blitAt(comp->getImg(),pos.x+52,pos.y+54);
  756. printAtMiddle(comp->subtitle,pos.x+91,pos.y+158,GEOR13,zwykly);
  757. printAtMiddleWB(comp->description,pos.x+94,pos.y+31,GEOR13,26,zwykly);
  758. SDL_FreeSurface(b);
  759. TimeInterested::activate();
  760. mode = 6;
  761. toNextTick = time;
  762. }
  763. void CInfoBar::tick()
  764. {
  765. if((mode >= 0) && (mode < 5))
  766. {
  767. pom++;
  768. if (pom >= getAnim(mode)->ourImages.size())
  769. {
  770. TimeInterested::deactivate();
  771. toNextTick = -1;
  772. mode = 5;
  773. draw();
  774. return;
  775. }
  776. toNextTick = 150;
  777. blitAnim(mode);
  778. }
  779. else if (mode == 6)
  780. {
  781. TimeInterested::deactivate();
  782. toNextTick = -1;
  783. mode = 5;
  784. draw();
  785. }
  786. }
  787. CAdvMapInt::CAdvMapInt(int Player)
  788. :player(Player),
  789. statusbar(7,556),
  790. kingOverview(CGI->preth->zelp[293].first,CGI->preth->zelp[293].second,
  791. boost::bind(&CAdvMapInt::fshowOverview,this), 679, 196, "IAM002.DEF", false,NULL,true),
  792. underground(CGI->preth->zelp[294].first,CGI->preth->zelp[294].second,
  793. boost::bind(&CAdvMapInt::fswitchLevel,this), 711, 196, "IAM010.DEF", false, new std::vector<std::string>(1,std::string("IAM003.DEF")),true),
  794. questlog(CGI->preth->zelp[295].first,CGI->preth->zelp[295].second,
  795. boost::bind(&CAdvMapInt::fshowQuestlog,this), 679, 228, "IAM004.DEF", false,NULL,true),
  796. sleepWake(CGI->preth->zelp[296].first,CGI->preth->zelp[296].second,
  797. boost::bind(&CAdvMapInt::fsleepWake,this), 711, 228, "IAM005.DEF", false,NULL,true),
  798. moveHero(CGI->preth->zelp[297].first,CGI->preth->zelp[297].second,
  799. boost::bind(&CAdvMapInt::fmoveHero,this), 679, 260, "IAM006.DEF", false,NULL,true),
  800. spellbook(CGI->preth->zelp[298].first,CGI->preth->zelp[298].second,
  801. boost::bind(&CAdvMapInt::fshowSpellbok,this), 711, 260, "IAM007.DEF", false,NULL,true),
  802. advOptions(CGI->preth->zelp[299].first,CGI->preth->zelp[299].second,
  803. boost::bind(&CAdvMapInt::fadventureOPtions,this), 679, 292, "IAM008.DEF", false,NULL,true),
  804. sysOptions(CGI->preth->zelp[300].first,CGI->preth->zelp[300].second,
  805. boost::bind(&CAdvMapInt::fsystemOptions,this), 711, 292, "IAM009.DEF", false,NULL,true),
  806. nextHero(CGI->preth->zelp[301].first,CGI->preth->zelp[301].second,
  807. boost::bind(&CAdvMapInt::fnextHero,this), 679, 324, "IAM000.DEF", false,NULL,true),
  808. endTurn(CGI->preth->zelp[302].first,CGI->preth->zelp[302].second,
  809. boost::bind(&CAdvMapInt::fendTurn,this), 679, 356, "IAM001.DEF", false,NULL,true),
  810. townList(5,&genRect(192,48,747,196),747,196,747,372)
  811. {
  812. townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this);
  813. LOCPLINT->adventureInt=this;
  814. bg = BitmapHandler::loadBitmap("ADVMAP.bmp");
  815. blueToPlayersAdv(bg,player);
  816. scrollingLeft = false;
  817. scrollingRight = false;
  818. scrollingUp = false ;
  819. scrollingDown = false ;
  820. updateScreen = false;
  821. anim=0;
  822. animValHitCount=0; //animation frame
  823. heroAnim=0;
  824. heroAnimValHitCount=0; // hero animation frame
  825. heroList.init();
  826. heroList.genList();
  827. //townList.init();
  828. townList.genList();
  829. heroWindow = new CHeroWindow(this->player);
  830. gems.push_back(CDefHandler::giveDef("agemLL.def"));
  831. gems.push_back(CDefHandler::giveDef("agemLR.def"));
  832. gems.push_back(CDefHandler::giveDef("agemUL.def"));
  833. gems.push_back(CDefHandler::giveDef("agemUR.def"));
  834. }
  835. void CAdvMapInt::fshowOverview()
  836. {
  837. }
  838. void CAdvMapInt::fswitchLevel()
  839. {
  840. if(!CGI->mh->map->twoLevel)
  841. return;
  842. if (position.z)
  843. {
  844. position.z--;
  845. underground.curimg=0;
  846. underground.show();
  847. }
  848. else
  849. {
  850. underground.curimg=1;
  851. position.z++;
  852. underground.show();
  853. }
  854. updateScreen = true;
  855. minimap.draw();
  856. }
  857. void CAdvMapInt::fshowQuestlog()
  858. {
  859. }
  860. void CAdvMapInt::fsleepWake()
  861. {
  862. }
  863. void CAdvMapInt::fmoveHero()
  864. {
  865. if (selection.type!=HEROI_TYPE)
  866. return;
  867. if (!terrain.currentPath)
  868. return;
  869. CPath sended(*(terrain.currentPath)); //temporary path - engine will operate on it
  870. LOCPLINT->cb->moveHero( ((const CGHeroInstance*)LOCPLINT->adventureInt->selection.selected)->type->ID,&sended,1,0);
  871. }
  872. void CAdvMapInt::fshowSpellbok()
  873. {
  874. }
  875. void CAdvMapInt::fadventureOPtions()
  876. {
  877. }
  878. void CAdvMapInt::fsystemOptions()
  879. {
  880. }
  881. void CAdvMapInt::fnextHero()
  882. {
  883. }
  884. void CAdvMapInt::fendTurn()
  885. {
  886. LOCPLINT->makingTurn = false;
  887. }
  888. void CAdvMapInt::activate()
  889. {
  890. LOCPLINT->curint = this;
  891. LOCPLINT->statusbar = &statusbar;
  892. kingOverview.activate();
  893. underground.activate();
  894. questlog.activate();
  895. sleepWake.activate();
  896. moveHero.activate();
  897. spellbook.activate();
  898. sysOptions.activate();
  899. advOptions.activate();
  900. nextHero.activate();
  901. endTurn.activate();
  902. minimap.activate();
  903. heroList.activate();
  904. townList.activate();
  905. terrain.activate();
  906. show();
  907. }
  908. void CAdvMapInt::deactivate()
  909. {
  910. hide();
  911. }
  912. void CAdvMapInt::show()
  913. {
  914. blitAt(bg,0,0);
  915. kingOverview.show();
  916. underground.show();
  917. questlog.show();
  918. sleepWake.show();
  919. moveHero.show();
  920. spellbook.show();
  921. advOptions.show();
  922. sysOptions.show();
  923. nextHero.show();
  924. endTurn.show();
  925. minimap.draw();
  926. heroList.draw();
  927. townList.draw();
  928. update();
  929. resdatabar.draw();
  930. statusbar.show();
  931. infoBar.draw();
  932. CSDL_Ext::update(screen);
  933. }
  934. void CAdvMapInt::hide()
  935. {
  936. kingOverview.deactivate();
  937. underground.deactivate();
  938. questlog.deactivate();
  939. sleepWake.deactivate();
  940. moveHero.deactivate();
  941. spellbook.deactivate();
  942. advOptions.deactivate();
  943. sysOptions.deactivate();
  944. nextHero.deactivate();
  945. endTurn.deactivate();
  946. minimap.deactivate();
  947. heroList.deactivate();
  948. townList.deactivate();
  949. terrain.deactivate();
  950. if(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar)!=LOCPLINT->timeinterested.end())
  951. LOCPLINT->timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar));
  952. infoBar.mode=-1;
  953. }
  954. void CAdvMapInt::update()
  955. {
  956. terrain.show();
  957. blitAt(gems[2]->ourImages[LOCPLINT->playerID].bitmap,6,6);
  958. blitAt(gems[0]->ourImages[LOCPLINT->playerID].bitmap,6,508);
  959. blitAt(gems[1]->ourImages[LOCPLINT->playerID].bitmap,556,508);
  960. blitAt(gems[3]->ourImages[LOCPLINT->playerID].bitmap,556,6);
  961. //updateRect(&genRect(550,600,6,6));
  962. }
  963. void CAdvMapInt::selectionChanged()
  964. {
  965. const CGTownInstance *to = townList.items[townList.selected];
  966. centerOn(to->pos);
  967. selection.type = TOWNI_TYPE;
  968. selection.selected = to;
  969. terrain.currentPath = NULL;
  970. townList.draw();
  971. heroList.draw();
  972. infoBar.draw(NULL);
  973. }
  974. void CAdvMapInt::centerOn(int3 on)
  975. {
  976. on.x -= (LOCPLINT->adventureInt->terrain.tilesw/2);
  977. on.y -= (LOCPLINT->adventureInt->terrain.tilesh/2);
  978. if (on.x<0)
  979. on.x=-(Woff/2);
  980. else if((on.x+LOCPLINT->adventureInt->terrain.tilesw) > (CGI->mh->sizes.x))
  981. on.x=CGI->mh->sizes.x-LOCPLINT->adventureInt->terrain.tilesw+(Woff/2);
  982. if (on.y<0)
  983. on.y = -(Hoff/2);
  984. else if((on.y+LOCPLINT->adventureInt->terrain.tilesh) > (CGI->mh->sizes.y))
  985. on.y = CGI->mh->sizes.y-LOCPLINT->adventureInt->terrain.tilesh+(Hoff/2);
  986. LOCPLINT->adventureInt->position.x=on.x;
  987. LOCPLINT->adventureInt->position.y=on.y;
  988. LOCPLINT->adventureInt->position.z=on.z;
  989. LOCPLINT->adventureInt->updateScreen=true;
  990. updateMinimap=true;
  991. }
  992. CAdvMapInt::CurrentSelection::CurrentSelection()
  993. {
  994. type=-1;
  995. selected=NULL;
  996. }
  997. void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * client)
  998. {
  999. if (down)
  1000. {
  1001. boost::algorithm::erase_all(text,"\"");
  1002. CSimpleWindow * temp = CMessage::genWindow(text,LOCPLINT->playerID);
  1003. temp->pos.x=300-(temp->pos.w/2);
  1004. temp->pos.y=300-(temp->pos.h/2);
  1005. temp->owner = client;
  1006. LOCPLINT->objsToBlit.push_back(temp);
  1007. }
  1008. else
  1009. {
  1010. for (int i=0;i<LOCPLINT->objsToBlit.size();i++)
  1011. {
  1012. //TODO: pewnie da sie to zrobic lepiej, ale nie chce mi sie. Wolajacy obiekt powinien informowac kogo spodziewa sie odwolac (null jesli down)
  1013. CSimpleWindow * pom = dynamic_cast<CSimpleWindow*>(LOCPLINT->objsToBlit[i]);
  1014. if (!pom)
  1015. continue;
  1016. if (pom->owner==client)
  1017. {
  1018. LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+(i));
  1019. delete pom;
  1020. }
  1021. }
  1022. }
  1023. }
  1024. int3 CAdvMapInt::verifyPos(int3 ver)
  1025. {
  1026. if (ver.x<0)
  1027. ver.x=0;
  1028. if (ver.y<0)
  1029. ver.y=0;
  1030. if (ver.z<0)
  1031. ver.z=0;
  1032. if (ver.x>=CGI->mh->sizes.x)
  1033. ver.x=CGI->mh->sizes.x-1;
  1034. if (ver.y>=CGI->mh->sizes.y)
  1035. ver.y=CGI->mh->sizes.y-1;
  1036. if (ver.z>=CGI->mh->sizes.z)
  1037. ver.z=CGI->mh->sizes.z-1;
  1038. return ver;
  1039. }