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/CDefHandler.h"
  8. #include "hch/CTownHandler.h"
  9. #include "CPathfinder.h"
  10. #include "CGameInfo.h"
  11. #include "SDL_Extensions.h"
  12. #include "CCallback.h"
  13. #include <boost/assign/std/vector.hpp>
  14. #include "mapHandler.h"
  15. #include "CMessage.h"
  16. #include <boost/algorithm/string.hpp>
  17. #include <boost/algorithm/string/replace.hpp>
  18. #include "CLua.h"
  19. #include "hch/CHeroHandler.h"
  20. #include <sstream>
  21. #include "AdventureMapButton.h"
  22. #include "CHeroWindow.h"
  23. #include "client/Graphics.h"
  24. #include "hch/CObjectHandler.h"
  25. #include <boost/thread.hpp>
  26. #include "map.h"
  27. #pragma warning (disable : 4355)
  28. extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
  29. using namespace boost::logic;
  30. using namespace boost::assign;
  31. using namespace CSDL_Ext;
  32. CAdvMapInt::~CAdvMapInt()
  33. {
  34. SDL_FreeSurface(bg);
  35. delete heroWindow;
  36. }
  37. CMinimap::CMinimap(bool draw)
  38. {
  39. statusbarTxt = CGI->preth->zelp[291].first;
  40. rcText = CGI->preth->zelp[291].second;
  41. pos.x=630;
  42. pos.y=26;
  43. pos.h=pos.w=144;
  44. int rx = (((float)19)/(CGI->mh->sizes.x))*((float)pos.w),
  45. ry = (((float)18)/(CGI->mh->sizes.y))*((float)pos.h);
  46. radar = newSurface(rx,ry);
  47. temps = newSurface(144,144);
  48. SDL_FillRect(radar,NULL,0x00FFFF);
  49. for (int i=0; i<radar->w; i++)
  50. {
  51. if (i%4 || (i==0))
  52. {
  53. SDL_PutPixel(radar,i,0,255,75,125);
  54. SDL_PutPixel(radar,i,radar->h-1,255,75,125);
  55. }
  56. }
  57. for (int i=0; i<radar->h; i++)
  58. {
  59. if ((i%4) || (i==0))
  60. {
  61. SDL_PutPixel(radar,0,i,255,75,125);
  62. SDL_PutPixel(radar,radar->w-1,i,255,75,125);
  63. }
  64. }
  65. SDL_SetColorKey(radar,SDL_SRCCOLORKEY,SDL_MapRGB(radar->format,0,255,255));
  66. //radar = CDefHandler::giveDef("RADAR.DEF");
  67. std::ifstream is("config/minimap.txt",std::ifstream::in);
  68. for (int i=0;i<TERRAIN_TYPES;i++)
  69. {
  70. std::pair<int,SDL_Color> vinya;
  71. std::pair<int,SDL_Color> vinya2;
  72. int pom;
  73. is >> pom;
  74. vinya2.first=vinya.first=pom;
  75. is >> pom;
  76. vinya.second.r=pom;
  77. is >> pom;
  78. vinya.second.g=pom;
  79. is >> pom;
  80. vinya.second.b=pom;
  81. is >> pom;
  82. vinya2.second.r=pom;
  83. is >> pom;
  84. vinya2.second.g=pom;
  85. is >> pom;
  86. vinya2.second.b=pom;
  87. vinya.second.unused=vinya2.second.unused=255;
  88. colors.insert(vinya);
  89. colorsBlocked.insert(vinya2);
  90. }
  91. is.close();
  92. if (draw)
  93. redraw();
  94. }
  95. void CMinimap::draw()
  96. {
  97. //draw terrain
  98. blitAt(map[LOCPLINT->adventureInt->position.z],0,0,temps);
  99. //draw heroes
  100. std::vector <const CGHeroInstance *> hh = LOCPLINT->cb->getHeroesInfo(false);
  101. int mw = map[0]->w, mh = map[0]->h,
  102. wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y;
  103. for (int i=0; i<hh.size();i++)
  104. {
  105. int3 hpos = hh[i]->getPosition(false);
  106. if(hpos.z!=LOCPLINT->adventureInt->position.z)
  107. continue;
  108. //float zawx = ((float)hpos.x/CGI->mh->sizes.x), zawy = ((float)hpos.y/CGI->mh->sizes.y);
  109. int3 maplgp ( (hpos.x*mw)/CGI->mh->sizes.x, (hpos.y*mh)/CGI->mh->sizes.y, hpos.z );
  110. for (int ii=0; ii<wo; ii++)
  111. {
  112. for (int jj=0; jj<ho; jj++)
  113. {
  114. 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);
  115. }
  116. }
  117. }
  118. //blitAt(FoW[LOCPLINT->adventureInt->position.z],0,0,temps);
  119. //draw radar
  120. int bx = (((float)LOCPLINT->adventureInt->position.x)/(((float)CGI->mh->sizes.x)))*pos.w,
  121. by = (((float)LOCPLINT->adventureInt->position.y)/(((float)CGI->mh->sizes.y)))*pos.h;
  122. blitAt(radar,bx,by,temps);
  123. blitAt(temps,pos.x,pos.y);
  124. //SDL_UpdateRect(screen,pos.x,pos.y,pos.w,pos.h);
  125. }
  126. void CMinimap::redraw(int level)// (level==-1) => redraw all levels
  127. {
  128. (CGI);
  129. for (int i=0; i<CGI->mh->sizes.z; i++)
  130. {
  131. SDL_Surface * pom ;
  132. if ((level>=0) && (i!=level))
  133. continue;
  134. if (map.size()<i+1)
  135. pom = CSDL_Ext::newSurface(pos.w,pos.h,screen);
  136. else pom = map[i];
  137. for (int x=0;x<pos.w;x++)
  138. {
  139. for (int y=0;y<pos.h;y++)
  140. {
  141. int mx=(CGI->mh->sizes.x*x)/pos.w;
  142. int my=(CGI->mh->sizes.y*y)/pos.h;
  143. if (CGI->mh->ttiles[mx][my][i].tileInfo->blocked && (!CGI->mh->ttiles[mx][my][i].tileInfo->visitable))
  144. SDL_PutPixel(pom,x,y,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].r,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].g,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].b);
  145. else SDL_PutPixel(pom,x,y,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].r,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].g,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].b);
  146. }
  147. }
  148. map.push_back(pom);
  149. }
  150. }
  151. void CMinimap::updateRadar()
  152. {}
  153. void CMinimap::clickRight (tribool down)
  154. {
  155. LOCPLINT->adventureInt->handleRightClick(rcText,down,this);
  156. }
  157. void CMinimap::clickLeft (tribool down)
  158. {
  159. if (down && (!pressedL))
  160. MotionInterested::activate();
  161. else if (!down)
  162. {
  163. if (std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this)!=LOCPLINT->motioninterested.end())
  164. MotionInterested::deactivate();
  165. }
  166. ClickableL::clickLeft(down);
  167. if (!((bool)down))
  168. return;
  169. float dx=((float)(LOCPLINT->current->motion.x-pos.x))/((float)pos.w),
  170. dy=((float)(LOCPLINT->current->motion.y-pos.y))/((float)pos.h);
  171. int3 newCPos;
  172. newCPos.x = (CGI->mh->sizes.x*dx);
  173. newCPos.y = (CGI->mh->sizes.y*dy);
  174. newCPos.z = LOCPLINT->adventureInt->position.z;
  175. LOCPLINT->adventureInt->centerOn(newCPos);
  176. }
  177. void CMinimap::hover (bool on)
  178. {
  179. Hoverable::hover(on);
  180. if (on)
  181. LOCPLINT->adventureInt->statusbar.print(statusbarTxt);
  182. else if (LOCPLINT->adventureInt->statusbar.current==statusbarTxt)
  183. LOCPLINT->adventureInt->statusbar.clear();
  184. }
  185. void CMinimap::mouseMoved (SDL_MouseMotionEvent & sEvent)
  186. {
  187. if (pressedL)
  188. {
  189. clickLeft(true);
  190. }
  191. }
  192. void CMinimap::activate()
  193. {
  194. ClickableL::activate();
  195. ClickableR::activate();
  196. Hoverable::activate();
  197. if (pressedL)
  198. MotionInterested::activate();
  199. }
  200. void CMinimap::deactivate()
  201. {
  202. if (pressedL)
  203. MotionInterested::deactivate();
  204. ClickableL::deactivate();
  205. ClickableR::deactivate();
  206. Hoverable::deactivate();
  207. }
  208. void CMinimap::showTile(int3 pos)
  209. {
  210. //int mw = map[0]->w, mh = map[0]->h;
  211. //double wo = ((double)mw)/CGI->mh->sizes.x, ho = ((double)mh)/CGI->mh->sizes.y;
  212. //for (int ii=0; ii<wo; ii++)
  213. //{
  214. // for (int jj=0; jj<ho; jj++)
  215. // {
  216. // if ((pos.x*wo+ii<this->pos.w) && (pos.y*ho+jj<this->pos.h))
  217. // CSDL_Ext::SDL_PutPixel(FoW[pos.z],pos.x*wo+ii,pos.y*ho+jj,0,0,0,0,0);
  218. // }
  219. //}
  220. }
  221. void CMinimap::hideTile(int3 pos)
  222. {
  223. }
  224. CTerrainRect::CTerrainRect():currentPath(NULL)
  225. {
  226. tilesw=19;
  227. tilesh=18;
  228. pos.x=7;
  229. pos.y=6;
  230. pos.w=593;
  231. pos.h=547;
  232. arrows = CDefHandler::giveDef("ADAG.DEF");
  233. for(int y=0; y<arrows->ourImages.size(); ++y)
  234. {
  235. arrows->ourImages[y].bitmap = CSDL_Ext::alphaTransform(arrows->ourImages[y].bitmap);
  236. }
  237. }
  238. void CTerrainRect::activate()
  239. {
  240. ClickableL::activate();
  241. ClickableR::activate();
  242. Hoverable::activate();
  243. KeyInterested::activate();
  244. MotionInterested::activate();
  245. };
  246. void CTerrainRect::deactivate()
  247. {
  248. ClickableL::deactivate();
  249. ClickableR::deactivate();
  250. Hoverable::deactivate();
  251. KeyInterested::deactivate();
  252. MotionInterested::deactivate();
  253. };
  254. void CTerrainRect::clickLeft(tribool down)
  255. {
  256. if ((down==false) || indeterminate(down))
  257. return;
  258. if (LOCPLINT->adventureInt->selection.type != HEROI_TYPE)
  259. {
  260. if (currentPath)
  261. {
  262. delete currentPath;
  263. currentPath = NULL;
  264. }
  265. return;
  266. }
  267. int3 mp = whichTileIsIt();
  268. if ((mp.x<0) || (mp.y<0))
  269. return;
  270. bool mres =true;
  271. if (currentPath)
  272. {
  273. if ( (currentPath->endPos()) == mp)
  274. { //move
  275. CPath sended(*currentPath); //temporary path - engine will operate on it
  276. LOCPLINT->pim->unlock();
  277. mres = LOCPLINT->cb->moveHero( ((const CGHeroInstance*)LOCPLINT->adventureInt->selection.selected)->type->ID,&sended,1,0);
  278. LOCPLINT->pim->lock();
  279. if(!mres)
  280. {
  281. delete currentPath;
  282. currentPath = NULL;
  283. int i=0;
  284. for(;i<LOCPLINT->adventureInt->heroList.items.size();i++)
  285. {
  286. if(LOCPLINT->adventureInt->heroList.items[i].first->subID == ((const CGHeroInstance*)LOCPLINT->adventureInt->selection.selected)->type->ID)
  287. {
  288. LOCPLINT->adventureInt->heroList.items[i].second = NULL;
  289. break;
  290. }
  291. }
  292. }
  293. }
  294. else
  295. {
  296. delete currentPath;
  297. currentPath=NULL;
  298. }
  299. }
  300. const CGHeroInstance * currentHero = (LOCPLINT->adventureInt->heroList.items.size())?(LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].first):(NULL);
  301. if(!currentHero)
  302. return;
  303. int3 bufpos = currentHero->getPosition(false);
  304. //bufpos.x-=1;
  305. if (mres)
  306. {
  307. vector<Coordinate>* p;
  308. p = CGI->pathf->GetPath(Coordinate(bufpos),Coordinate(mp),currentHero);
  309. //Convert to old format.
  310. currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->ConvertToOldFormat(p);
  311. delete p;
  312. //currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->getPath(bufpos,mp,currentHero,1);
  313. }
  314. }
  315. void CTerrainRect::clickRight(tribool down)
  316. {
  317. }
  318. void CTerrainRect::mouseMoved (SDL_MouseMotionEvent & sEvent)
  319. {
  320. int3 pom=LOCPLINT->adventureInt->verifyPos(whichTileIsIt(sEvent.x,sEvent.y));
  321. if (pom!=curHoveredTile)
  322. curHoveredTile=pom;
  323. else
  324. return;
  325. std::vector<std::string> temp = LOCPLINT->cb->getObjDescriptions(pom);
  326. if (temp.size())
  327. {
  328. LOCPLINT->adventureInt->statusbar.print((*((temp.end())-1)));
  329. }
  330. else
  331. {
  332. LOCPLINT->adventureInt->statusbar.clear();
  333. }
  334. }
  335. void CTerrainRect::keyPressed (SDL_KeyboardEvent & key){}
  336. void CTerrainRect::hover(bool on)
  337. {
  338. if (!on)
  339. LOCPLINT->adventureInt->statusbar.clear();
  340. }
  341. void CTerrainRect::showPath()
  342. {
  343. for (int i=0;i<currentPath->nodes.size()-1;i++)
  344. {
  345. int pn=-1;//number of picture
  346. if (i==0) //last tile
  347. {
  348. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  349. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  350. if (x<0 || y<0 || x>pos.w || y>pos.h)
  351. continue;
  352. pn=0;
  353. }
  354. else
  355. {
  356. std::vector<CPathNode> & cv = currentPath->nodes;
  357. if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1)
  358. {
  359. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  360. {
  361. pn = 3;
  362. }
  363. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  364. {
  365. pn = 12;
  366. }
  367. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  368. {
  369. pn = 21;
  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 = 22;
  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 = 2;
  378. }
  379. }
  380. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1)
  381. {
  382. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  383. {
  384. pn = 4;
  385. }
  386. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  387. {
  388. pn = 13;
  389. }
  390. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  391. {
  392. pn = 22;
  393. }
  394. }
  395. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1)
  396. {
  397. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  398. {
  399. pn = 5;
  400. }
  401. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  402. {
  403. pn = 14;
  404. }
  405. else if(cv[i-1].coord.x+1 == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y)
  406. {
  407. pn = 23;
  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 = 24;
  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 = 4;
  416. }
  417. }
  418. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y)
  419. {
  420. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  421. {
  422. pn = 6;
  423. }
  424. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
  425. {
  426. pn = 15;
  427. }
  428. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  429. {
  430. pn = 24;
  431. }
  432. }
  433. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1)
  434. {
  435. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
  436. {
  437. pn = 7;
  438. }
  439. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  440. {
  441. pn = 16;
  442. }
  443. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  444. {
  445. pn = 17;
  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 = 6;
  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 && cv[i+1].coord.y == cv[i].coord.y+1)
  457. {
  458. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  459. {
  460. pn = 8;
  461. }
  462. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  463. {
  464. pn = 9;
  465. }
  466. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  467. {
  468. pn = 18;
  469. }
  470. }
  471. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1)
  472. {
  473. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  474. {
  475. pn = 1;
  476. }
  477. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  478. {
  479. pn = 10;
  480. }
  481. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  482. {
  483. pn = 19;
  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 = 8;
  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. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y)
  495. {
  496. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  497. {
  498. pn = 2;
  499. }
  500. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  501. {
  502. pn = 11;
  503. }
  504. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  505. {
  506. pn = 20;
  507. }
  508. }
  509. }
  510. if ( ((currentPath->nodes[i].dist)-(*(currentPath->nodes.end()-1)).dist) > ((const CGHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->movement)
  511. pn+=25;
  512. if (pn>=0)
  513. {
  514. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  515. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  516. if (x<0 || y<0 || x>pos.w || y>pos.h)
  517. continue;
  518. int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
  519. hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
  520. if (hvx<0 && hvy<0)
  521. {
  522. CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, screen, &genRect(32, 32, x, y));
  523. }
  524. else if(hvx<0)
  525. {
  526. CSDL_Ext::blit8bppAlphaTo24bpp
  527. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,0,0),
  528. screen,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,x,y));
  529. }
  530. else if (hvy<0)
  531. {
  532. CSDL_Ext::blit8bppAlphaTo24bpp
  533. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  534. screen,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  535. }
  536. else
  537. {
  538. CSDL_Ext::blit8bppAlphaTo24bpp
  539. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  540. screen,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  541. }
  542. }
  543. } //for (int i=0;i<currentPath->nodes.size()-1;i++)
  544. }
  545. void CTerrainRect::show()
  546. {
  547. SDL_Surface * teren = CGI->mh->terrainRect
  548. (LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
  549. tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim,
  550. &LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim,
  551. screen,&genRect(547,594,7,6)
  552. );
  553. //SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));
  554. //SDL_FreeSurface(teren);
  555. if (currentPath && LOCPLINT->adventureInt->position.z==currentPath->startPos().z) //drawing path
  556. {
  557. showPath();
  558. }
  559. }
  560. int3 CTerrainRect::whichTileIsIt(int x, int y)
  561. {
  562. int3 ret;
  563. ret.x = LOCPLINT->adventureInt->position.x + ((LOCPLINT->current->motion.x-pos.x)/32);
  564. ret.y = LOCPLINT->adventureInt->position.y + ((LOCPLINT->current->motion.y-pos.y)/32);
  565. ret.z = LOCPLINT->adventureInt->position.z;
  566. return ret;
  567. }
  568. int3 CTerrainRect::whichTileIsIt()
  569. {
  570. return whichTileIsIt(LOCPLINT->current->motion.x,LOCPLINT->current->motion.y);
  571. }
  572. void CResDataBar::clickRight (tribool down)
  573. {
  574. }
  575. void CResDataBar::activate()
  576. {
  577. ClickableR::activate();
  578. }
  579. void CResDataBar::deactivate()
  580. {
  581. ClickableR::deactivate();
  582. }
  583. CResDataBar::CResDataBar()
  584. {
  585. bg = BitmapHandler::loadBitmap("ZRESBAR.bmp");
  586. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  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. SDL_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. SDL_itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf);
  610. SDL_itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf);
  611. SDL_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. }