CAdvmapInterface.cpp 30 KB

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