CAdvmapInterface.cpp 29 KB

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