CAdvmapInterface.cpp 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637
  1. #include "AdventureMapButton.h"
  2. #include "CAdvmapInterface.h"
  3. #include "../CCallback.h"
  4. #include "CCastleInterface.h"
  5. #include "CCursorHandler.h"
  6. #include "CGameInfo.h"
  7. #include "CHeroWindow.h"
  8. #include "CMessage.h"
  9. #include "SDL_Extensions.h"
  10. #include "CBitmapHandler.h"
  11. #include "CConfigHandler.h"
  12. #include "CSpellWindow.h"
  13. #include "Graphics.h"
  14. #include "../hch/CDefHandler.h"
  15. #include "../hch/CGeneralTextHandler.h"
  16. #include "../hch/CHeroHandler.h"
  17. #include "../hch/CObjectHandler.h"
  18. #include "../hch/CTownHandler.h"
  19. #include "../lib/map.h"
  20. #include "../mapHandler.h"
  21. #include "../stdafx.h"
  22. #include <boost/algorithm/string.hpp>
  23. #include <boost/algorithm/string/replace.hpp>
  24. #include <boost/assign/std/vector.hpp>
  25. #include <boost/thread.hpp>
  26. #include <sstream>
  27. #ifdef _MSC_VER
  28. #pragma warning (disable : 4355)
  29. #endif
  30. /*
  31. * CAdvMapInterface.cpp, part of VCMI engine
  32. *
  33. * Authors: listed in file AUTHORS in main folder
  34. *
  35. * License: GNU General Public License v2.0 or later
  36. * Full text of license available in license.txt file, in main folder
  37. *
  38. */
  39. extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
  40. #define ADVOPT (conf.go()->ac)
  41. using namespace boost::logic;
  42. using namespace boost::assign;
  43. using namespace CSDL_Ext;
  44. CMinimap::CMinimap(bool draw)
  45. {
  46. int3 mapSizes = LOCPLINT->cb->getMapSize();
  47. statusbarTxt = CGI->generaltexth->zelp[291].first;
  48. rcText = CGI->generaltexth->zelp[291].second;
  49. pos.x=ADVOPT.minimapX;//630
  50. pos.y=ADVOPT.minimapY;//26
  51. pos.h=ADVOPT.minimapW;//144
  52. pos.w=ADVOPT.minimapH;//144
  53. const int tilesw=(ADVOPT.advmapW+31)/32;
  54. const int tilesh=(ADVOPT.advmapH+31)/32;
  55. int rx = (((float)tilesw)/(mapSizes.x))*((float)pos.w),
  56. ry = (((float)tilesh)/(mapSizes.y))*((float)pos.h);
  57. radar = newSurface(rx,ry);
  58. temps = newSurface(pos.w,pos.h);
  59. SDL_FillRect(radar,NULL,0x00FFFF);
  60. for (int i=0; i<radar->w; i++)
  61. {
  62. if (i%4 || (i==0))
  63. {
  64. SDL_PutPixelWithoutRefresh(radar,i,0,255,75,125);
  65. SDL_PutPixelWithoutRefresh(radar,i,radar->h-1,255,75,125);
  66. }
  67. }
  68. for (int i=0; i<radar->h; i++)
  69. {
  70. if ((i%4) || (i==0))
  71. {
  72. SDL_PutPixelWithoutRefresh(radar,0,i,255,75,125);
  73. SDL_PutPixelWithoutRefresh(radar,radar->w-1,i,255,75,125);
  74. }
  75. }
  76. SDL_SetColorKey(radar,SDL_SRCCOLORKEY,SDL_MapRGB(radar->format,0,255,255));
  77. //radar = CDefHandler::giveDef("RADAR.DEF");
  78. std::ifstream is("config/minimap.txt",std::ifstream::in);
  79. for (int i=0;i<TERRAIN_TYPES;i++)
  80. {
  81. std::pair<int,SDL_Color> vinya;
  82. std::pair<int,SDL_Color> vinya2;
  83. int pom;
  84. is >> pom;
  85. vinya2.first=vinya.first=pom;
  86. is >> pom;
  87. vinya.second.r=pom;
  88. is >> pom;
  89. vinya.second.g=pom;
  90. is >> pom;
  91. vinya.second.b=pom;
  92. is >> pom;
  93. vinya2.second.r=pom;
  94. is >> pom;
  95. vinya2.second.g=pom;
  96. is >> pom;
  97. vinya2.second.b=pom;
  98. vinya.second.unused=vinya2.second.unused=255;
  99. colors.insert(vinya);
  100. colorsBlocked.insert(vinya2);
  101. }
  102. is.close();
  103. if (draw)
  104. redraw();
  105. }
  106. CMinimap::~CMinimap()
  107. {
  108. SDL_FreeSurface(radar);
  109. SDL_FreeSurface(temps);
  110. }
  111. void CMinimap::draw(SDL_Surface * to)
  112. {
  113. int3 mapSizes = LOCPLINT->cb->getMapSize();
  114. //draw terrain
  115. blitAt(map[LOCPLINT->adventureInt->position.z],0,0,temps);
  116. //draw heroes
  117. std::vector <const CGHeroInstance *> hh = LOCPLINT->cb->getHeroesInfo(false);
  118. int mw = map[0]->w, mh = map[0]->h,
  119. wo = mw/mapSizes.x, ho = mh/mapSizes.y;
  120. for (size_t i=0; i < hh.size(); ++i)
  121. {
  122. int3 hpos = hh[i]->getPosition(false);
  123. if(hpos.z!=LOCPLINT->adventureInt->position.z)
  124. continue;
  125. //float zawx = ((float)hpos.x/CGI->mh->sizes.x), zawy = ((float)hpos.y/CGI->mh->sizes.y);
  126. int3 maplgp ( (hpos.x*mw)/mapSizes.x, (hpos.y*mh)/mapSizes.y, hpos.z );
  127. for (int ii=0; ii<wo; ii++)
  128. {
  129. for (int jj=0; jj<ho; jj++)
  130. {
  131. SDL_PutPixelWithoutRefresh(temps,maplgp.x+ii,maplgp.y+jj,graphics->playerColors[hh[i]->getOwner()].r,
  132. graphics->playerColors[hh[i]->getOwner()].g,graphics->playerColors[hh[i]->getOwner()].b);
  133. }
  134. }
  135. }
  136. blitAt(flObjs[LOCPLINT->adventureInt->position.z],0,0,temps);
  137. blitAt(FoW[LOCPLINT->adventureInt->position.z],0,0,temps);
  138. //draw radar
  139. int bx = (((float)LOCPLINT->adventureInt->position.x)/(((float)mapSizes.x)))*pos.w,
  140. by = (((float)LOCPLINT->adventureInt->position.y)/(((float)mapSizes.y)))*pos.h;
  141. blitAt(radar,bx,by,temps);
  142. blitAt(temps,pos.x,pos.y,to);
  143. }
  144. void CMinimap::redraw(int level)// (level==-1) => redraw all levels
  145. {
  146. int3 mapSizes = LOCPLINT->cb->getMapSize();
  147. for (size_t i=0; i<CGI->mh->sizes.z; i++)
  148. {
  149. SDL_Surface * pom ;
  150. if ((level>=0) && (i!=level))
  151. continue;
  152. if (map.size()<i+1)
  153. pom = CSDL_Ext::newSurface(pos.w,pos.h,screen);
  154. else pom = map[i];
  155. for (int x=0;x<pos.w;x++)
  156. {
  157. for (int y=0;y<pos.h;y++)
  158. {
  159. int mx=(mapSizes.x*x)/pos.w;
  160. int my=(mapSizes.y*y)/pos.h;
  161. const TerrainTile * tile = LOCPLINT->cb->getTileInfo(int3(mx, my, i));
  162. if(tile)
  163. {
  164. if (tile->blocked && (!tile->visitable))
  165. SDL_PutPixelWithoutRefresh(pom, x, y, colorsBlocked[tile->tertype].r, colorsBlocked[tile->tertype].g, colorsBlocked[tile->tertype].b);
  166. else SDL_PutPixelWithoutRefresh(pom, x, y, colors[tile->tertype].r, colors[tile->tertype].g, colors[tile->tertype].b);
  167. }
  168. }
  169. }
  170. map.push_back(pom);
  171. }
  172. //FoW
  173. int mw = map[0]->w, mh = map[0]->h;//,
  174. //wo = mw/mapSizes.x, ho = mh/mapSizes.y; //TODO use me
  175. for(int d=0; d<CGI->mh->map->twoLevel+1; ++d)
  176. {
  177. if(level>=0 && d!=level)
  178. continue;
  179. SDL_Surface * pt = CSDL_Ext::newSurface(pos.w, pos.h, CSDL_Ext::std32bppSurface);
  180. for (int i=0; i<mw; i++)
  181. {
  182. for (int j=0; j<mh; j++)
  183. {
  184. int3 pp( ((i*mapSizes.x)/mw), ((j*mapSizes.y)/mh), d );
  185. if ( !LOCPLINT->cb->isVisible(pp) )
  186. {
  187. CSDL_Ext::SDL_PutPixelWithoutRefresh(pt,i,j,0,0,0);
  188. }
  189. }
  190. }
  191. FoW.push_back(pt);
  192. }
  193. //FoW end
  194. //flaggable objects
  195. for(int d=0; d<CGI->mh->map->twoLevel+1; ++d)
  196. {
  197. if(level>=0 && d!=level)
  198. continue;
  199. SDL_Surface * pt = CSDL_Ext::newSurface(pos.w, pos.h, CSDL_Ext::std32bppSurface);
  200. for (int i=0; i<mw; i++)
  201. {
  202. for (int j=0; j<mh; j++)
  203. {
  204. CSDL_Ext::SDL_PutPixelWithoutRefresh(pt,i,j,0,0,0,0);
  205. }
  206. }
  207. flObjs.push_back(pt);
  208. }
  209. //showing tiles
  210. for(int d=0; d<CGI->mh->map->twoLevel+1; ++d)
  211. {
  212. if(level>=0 && d!=level)
  213. continue;
  214. for(int x=0; x<mapSizes.x; ++x)
  215. {
  216. for(int y=0; y<mapSizes.y; ++y)
  217. {
  218. if(LOCPLINT->cb->isVisible(int3(x, y, d)))
  219. {
  220. showTile(int3(x, y, d));
  221. }
  222. }
  223. }
  224. }
  225. }
  226. void CMinimap::updateRadar()
  227. {}
  228. void CMinimap::clickRight (tribool down)
  229. {
  230. LOCPLINT->adventureInt->handleRightClick(rcText,down,this);
  231. }
  232. void CMinimap::clickLeft (tribool down)
  233. {
  234. if (down && (!pressedL))
  235. MotionInterested::activate();
  236. else if (!down)
  237. {
  238. if (std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this)!=LOCPLINT->motioninterested.end())
  239. MotionInterested::deactivate();
  240. }
  241. ClickableL::clickLeft(down);
  242. if (!((bool)down))
  243. return;
  244. float dx=((float)(LOCPLINT->current->motion.x-pos.x))/((float)pos.w),
  245. dy=((float)(LOCPLINT->current->motion.y-pos.y))/((float)pos.h);
  246. int3 newCPos;
  247. newCPos.x = (CGI->mh->sizes.x*dx);
  248. newCPos.y = (CGI->mh->sizes.y*dy);
  249. newCPos.z = LOCPLINT->adventureInt->position.z;
  250. LOCPLINT->adventureInt->centerOn(newCPos);
  251. }
  252. void CMinimap::hover (bool on)
  253. {
  254. Hoverable::hover(on);
  255. if (on)
  256. LOCPLINT->adventureInt->statusbar.print(statusbarTxt);
  257. else if (LOCPLINT->adventureInt->statusbar.current==statusbarTxt)
  258. LOCPLINT->adventureInt->statusbar.clear();
  259. }
  260. void CMinimap::mouseMoved (const SDL_MouseMotionEvent & sEvent)
  261. {
  262. if (pressedL)
  263. {
  264. clickLeft(true);
  265. }
  266. }
  267. void CMinimap::activate()
  268. {
  269. ClickableL::activate();
  270. ClickableR::activate();
  271. Hoverable::activate();
  272. if (pressedL)
  273. MotionInterested::activate();
  274. }
  275. void CMinimap::deactivate()
  276. {
  277. if (pressedL)
  278. MotionInterested::deactivate();
  279. ClickableL::deactivate();
  280. ClickableR::deactivate();
  281. Hoverable::deactivate();
  282. }
  283. void CMinimap::showTile(const int3 &pos)
  284. {
  285. int3 mapSizes = LOCPLINT->cb->getMapSize();
  286. //drawing terrain
  287. int mw = map[0]->w, mh = map[0]->h;
  288. double wo = ((double)mw)/mapSizes.x, ho = ((double)mh)/mapSizes.y;
  289. for (int ii=0; ii<wo; ii++)
  290. {
  291. for (int jj=0; jj<ho; jj++)
  292. {
  293. if ((pos.x*wo+ii<this->pos.w) && (pos.y*ho+jj<this->pos.h))
  294. CSDL_Ext::SDL_PutPixelWithoutRefresh(FoW[pos.z],pos.x*wo+ii,pos.y*ho+jj,0,0,0,0);
  295. const TerrainTile * tile = LOCPLINT->cb->getTileInfo(pos);
  296. if(tile)
  297. {
  298. if (tile->blocked && (!tile->visitable))
  299. SDL_PutPixelWithoutRefresh(map[pos.z], pos.x*wo+ii, pos.y*ho+jj, colorsBlocked[tile->tertype].r, colorsBlocked[tile->tertype].g, colorsBlocked[tile->tertype].b);
  300. else SDL_PutPixelWithoutRefresh(map[pos.z], pos.x*wo+ii, pos.y*ho+jj, colors[tile->tertype].r, colors[tile->tertype].g, colors[tile->tertype].b);
  301. }
  302. }
  303. }
  304. //drawing flaggable objects
  305. int woShifted = wo, hoShifted = ho; //for better minimap rendering on L-sized maps
  306. std::vector < const CGObjectInstance * > oo = LOCPLINT->cb->getFlaggableObjects(pos);
  307. for(size_t v=0; v<oo.size(); ++v)
  308. {
  309. if(!dynamic_cast< const CGHeroInstance * >(oo[v])) //heroes have been printed
  310. {
  311. int3 maplgp ( (pos.x*mw)/mapSizes.x, (pos.y*mh)/mapSizes.y, pos.z );
  312. if(((int)wo) * mapSizes.x != mw) //miniap size in X is not multiple of map size in X
  313. {
  314. std::vector < const CGObjectInstance * > op1x = LOCPLINT->cb->getFlaggableObjects(int3(pos.x+1, pos.y, pos.z));
  315. if(op1x.size()!=0)
  316. {
  317. woShifted = wo + 1;
  318. }
  319. else
  320. {
  321. woShifted = wo;
  322. }
  323. }
  324. if(((int)ho) * mapSizes.y != mh) //miniap size in Y is not multiple of map size in Y
  325. {
  326. std::vector < const CGObjectInstance * > op1y = LOCPLINT->cb->getFlaggableObjects(int3(pos.x, pos.y+1, pos.z));
  327. if(op1y.size()!=0)
  328. {
  329. hoShifted = ho + 1;
  330. }
  331. else
  332. {
  333. hoShifted = ho;
  334. }
  335. }
  336. for (int ii=0; ii<woShifted; ii++) //rendering flaggable objects
  337. {
  338. for (int jj=0; jj<hoShifted; jj++)
  339. {
  340. if(oo[v]->tempOwner == 255)
  341. SDL_PutPixelWithoutRefresh(flObjs[pos.z],maplgp.x+ii,maplgp.y+jj,graphics->neutralColor->b,
  342. graphics->neutralColor->g,graphics->neutralColor->r);
  343. else
  344. SDL_PutPixelWithoutRefresh(flObjs[pos.z],maplgp.x+ii,maplgp.y+jj,graphics->playerColors[oo[v]->getOwner()].b,
  345. graphics->playerColors[oo[v]->getOwner()].g,graphics->playerColors[oo[v]->getOwner()].r);
  346. }
  347. }
  348. }
  349. }
  350. //flaggable objects drawn
  351. }
  352. void CMinimap::hideTile(const int3 &pos)
  353. {
  354. }
  355. CTerrainRect::CTerrainRect()
  356. :currentPath(NULL)
  357. {
  358. tilesw=(ADVOPT.advmapW+31)/32;
  359. tilesh=(ADVOPT.advmapH+31)/32;
  360. pos.x=ADVOPT.advmapX;
  361. pos.y=ADVOPT.advmapY;
  362. pos.w=ADVOPT.advmapW;
  363. pos.h=ADVOPT.advmapH;
  364. moveX = moveY = 0;
  365. arrows = CDefHandler::giveDef("ADAG.DEF");
  366. for(size_t y=0; y < arrows->ourImages.size(); ++y)
  367. {
  368. CSDL_Ext::alphaTransform(arrows->ourImages[y].bitmap);
  369. }
  370. }
  371. CTerrainRect::~CTerrainRect()
  372. {
  373. delete arrows;
  374. }
  375. void CTerrainRect::activate()
  376. {
  377. ClickableL::activate();
  378. ClickableR::activate();
  379. Hoverable::activate();
  380. MotionInterested::activate();
  381. };
  382. void CTerrainRect::deactivate()
  383. {
  384. ClickableL::deactivate();
  385. ClickableR::deactivate();
  386. Hoverable::deactivate();
  387. MotionInterested::deactivate();
  388. };
  389. void CTerrainRect::clickLeft(tribool down)
  390. {
  391. if ((down==false) || indeterminate(down))
  392. return;
  393. int3 mp = whichTileIsIt();
  394. if ((mp.x<0) || (mp.y<0))
  395. return;
  396. std::vector < const CGObjectInstance * > bobjs = LOCPLINT->cb->getBlockingObjs(mp), //blocking objects at tile
  397. vobjs = LOCPLINT->cb->getVisitableObjs(mp); //visitable objects
  398. if (LOCPLINT->adventureInt->selection->ID != HEROI_TYPE) //hero is not selected (presumably town)
  399. {
  400. if(currentPath)
  401. {
  402. tlog2<<"Warning: Lost path?" << std::endl;
  403. //delete currentPath;
  404. currentPath = NULL;
  405. }
  406. for(size_t i=0; i < bobjs.size(); ++i)
  407. {
  408. if(bobjs[i]->ID == TOWNI_TYPE && bobjs[i]->getOwner() == LOCPLINT->playerID) //our town clicked
  409. {
  410. if(LOCPLINT->adventureInt->selection == (bobjs[i])) //selected town clicked
  411. LOCPLINT->openTownWindow(static_cast<const CGTownInstance*>(bobjs[i]));
  412. else
  413. LOCPLINT->adventureInt->select(static_cast<const CArmedInstance*>(bobjs[i]));
  414. return;
  415. }
  416. else if(bobjs[i]->ID == HEROI_TYPE && bobjs[i]->tempOwner == LOCPLINT->playerID) //hero clicked - select him
  417. {
  418. LOCPLINT->adventureInt->select(static_cast<const CArmedInstance*>(bobjs[i]));
  419. return;
  420. }
  421. }
  422. }
  423. else //hero is selected
  424. {
  425. bool townEntrance = false; //town entrance tile has been clicked?
  426. const CGHeroInstance * currentHero = static_cast<const CGHeroInstance*>(LOCPLINT->adventureInt->selection);
  427. for(size_t i=0; i < vobjs.size(); ++i)
  428. {
  429. if(vobjs[i]->ID == TOWNI_TYPE)
  430. townEntrance = true;
  431. }
  432. if(!townEntrance) //not entrance - select town or open hero window
  433. {
  434. for(size_t i=0; i < bobjs.size(); ++i)
  435. {
  436. if(bobjs[i]->ID == TOWNI_TYPE && bobjs[i]->tempOwner == LOCPLINT->playerID) //town - switch selection to it
  437. {
  438. LOCPLINT->adventureInt->select(static_cast<const CArmedInstance*>(bobjs[i]));
  439. return;
  440. }
  441. else if(bobjs[i]->ID == HEROI_TYPE //it's a hero
  442. && bobjs[i]->tempOwner == LOCPLINT->playerID //our hero (is this condition needed?)
  443. && currentHero == (bobjs[i]) ) //and selected one
  444. {
  445. LOCPLINT->openHeroWindow(currentHero);
  446. return;
  447. }
  448. }
  449. }
  450. //still here? we need to move hero if we clicked end of already selected path or calculate a new path otherwise
  451. if (currentPath && currentPath->endPos() == mp)//we'll be moving
  452. {
  453. LOCPLINT->pim->unlock();
  454. LOCPLINT->moveHero(currentHero,*currentPath);
  455. LOCPLINT->pim->lock();
  456. }
  457. else if(mp.z == currentHero->pos.z) //remove old path and find a new one if we clicked on the map level on which hero is present
  458. {
  459. int3 bufpos = currentHero->getPosition(false);
  460. CPath &path = LOCPLINT->adventureInt->paths[currentHero];
  461. currentPath = &path;
  462. if(!LOCPLINT->cb->getPath(bufpos, mp, currentHero, path))
  463. {
  464. LOCPLINT->adventureInt->paths.erase(currentHero);
  465. currentPath = NULL;
  466. }
  467. }
  468. } //end of hero is selected "case"
  469. }
  470. void CTerrainRect::clickRight(tribool down)
  471. {
  472. int3 mp = whichTileIsIt();
  473. if ((mp.x<0)
  474. || (mp.y<0)
  475. || down != true
  476. )
  477. {
  478. LOCPLINT->adventureInt->handleRightClick("",down,this);
  479. return;
  480. }
  481. std::vector < const CGObjectInstance * > objs = LOCPLINT->cb->getBlockingObjs(mp);
  482. if(!objs.size())
  483. return;
  484. const CGObjectInstance * obj = objs[objs.size()-1];
  485. switch(obj->ID)
  486. {
  487. case HEROI_TYPE:
  488. {
  489. if(!vstd::contains(graphics->heroWins,obj->subID))
  490. {
  491. tlog3 << "Warning - no infowin for hero " << obj->subID << std::endl;
  492. break;
  493. }
  494. CInfoPopup * ip = new CInfoPopup(graphics->heroWins[obj->subID],
  495. LOCPLINT->current->motion.x-graphics->heroWins[obj->subID]->w,
  496. LOCPLINT->current->motion.y-graphics->heroWins[obj->subID]->h,false
  497. );
  498. LOCPLINT->pushInt(ip);
  499. break;
  500. }
  501. case TOWNI_TYPE:
  502. {
  503. if(!vstd::contains(graphics->townWins,obj->id))
  504. {
  505. tlog3 << "Warning - no infowin for town " << obj->id << std::endl;
  506. break;
  507. }
  508. CInfoPopup * ip = new CInfoPopup(graphics->townWins[obj->id],
  509. LOCPLINT->current->motion.x-graphics->townWins[obj->id]->w,
  510. LOCPLINT->current->motion.y-graphics->townWins[obj->id]->h,false
  511. );
  512. LOCPLINT->pushInt(ip);
  513. break;
  514. }
  515. default:
  516. {
  517. LOCPLINT->adventureInt->handleRightClick(obj->getHoverText(),down,this);
  518. break;
  519. }
  520. }
  521. }
  522. void CTerrainRect::mouseMoved (const SDL_MouseMotionEvent & sEvent)
  523. {
  524. int3 pom=LOCPLINT->adventureInt->verifyPos(whichTileIsIt(sEvent.x,sEvent.y));
  525. if (pom!=curHoveredTile)
  526. curHoveredTile=pom;
  527. else
  528. return;
  529. std::vector<std::string> temp = LOCPLINT->cb->getObjDescriptions(pom);
  530. if (temp.size())
  531. {
  532. boost::replace_all(temp.back(),"\n"," ");
  533. LOCPLINT->adventureInt->statusbar.print(temp.back());
  534. }
  535. else
  536. {
  537. LOCPLINT->adventureInt->statusbar.clear();
  538. }
  539. std::vector<const CGObjectInstance *> objs = LOCPLINT->cb->getVisitableObjs(pom);
  540. for(int i=0; i<objs.size();i++)
  541. {
  542. if(objs[i]->ID == TOWNI_TYPE) //town
  543. {
  544. CGI->curh->changeGraphic(0,0);
  545. return;
  546. }
  547. }
  548. objs = LOCPLINT->cb->getBlockingObjs(pom);
  549. for(size_t i=0; i < objs.size(); ++i)
  550. {
  551. if(objs[i]->ID == TOWNI_TYPE && objs[i]->tempOwner == LOCPLINT->playerID) //town
  552. {
  553. CGI->curh->changeGraphic(0,3);
  554. return;
  555. }
  556. else if(objs[i]->ID == HEROI_TYPE //mouse over hero
  557. && (objs[i]==LOCPLINT->adventureInt->selection || LOCPLINT->adventureInt->selection->ID==TOWNI_TYPE)
  558. && objs[i]->tempOwner == LOCPLINT->playerID) //this hero is selected or we've selected a town
  559. {
  560. CGI->curh->changeGraphic(0,2);
  561. return;
  562. }
  563. }
  564. CGI->curh->changeGraphic(0,0);
  565. }
  566. void CTerrainRect::hover(bool on)
  567. {
  568. if (!on)
  569. {
  570. LOCPLINT->adventureInt->statusbar.clear();
  571. CGI->curh->changeGraphic(0,0);
  572. }
  573. Hoverable::hover(on);
  574. }
  575. void CTerrainRect::showPath(const SDL_Rect * extRect)
  576. {
  577. for (size_t i=0; i < currentPath->nodes.size()-1; ++i)
  578. {
  579. int pn=-1;//number of picture
  580. if (i==0) //last tile
  581. {
  582. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+CGI->mh->offsetX + pos.x,
  583. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+CGI->mh->offsetY + pos.y;
  584. if (x<0 || y<0 || x>pos.w || y>pos.h)
  585. continue;
  586. pn=0;
  587. }
  588. else
  589. {
  590. /*
  591. * notation of arrow direction:
  592. * 1 2 3
  593. * 4 5 6
  594. * 7 8 9
  595. * ie. 157 means an arrow from left upper tile to left bottom tile through 5 (all arrows go through 5 in this notation)
  596. */
  597. std::vector<CPathNode> & cv = currentPath->nodes;
  598. if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1) //15x
  599. {
  600. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //156
  601. {
  602. pn = 3;
  603. }
  604. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //159
  605. {
  606. pn = 12;
  607. }
  608. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //158
  609. {
  610. pn = 21;
  611. }
  612. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //157
  613. {
  614. pn = 22;
  615. }
  616. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //153
  617. {
  618. pn = 2;
  619. }
  620. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //154
  621. {
  622. pn = 23;
  623. }
  624. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //152
  625. {
  626. pn = 1;
  627. }
  628. }
  629. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1) //25x
  630. {
  631. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //253
  632. {
  633. pn = 2;
  634. }
  635. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //256
  636. {
  637. pn = 3;
  638. }
  639. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //259
  640. {
  641. pn = 4;
  642. }
  643. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //258
  644. {
  645. pn = 13;
  646. }
  647. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //257
  648. {
  649. pn = 22;
  650. }
  651. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //254
  652. {
  653. pn = 23;
  654. }
  655. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //251
  656. {
  657. pn = 24;
  658. }
  659. }
  660. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1) //35x
  661. {
  662. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //358
  663. {
  664. pn = 5;
  665. }
  666. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //357
  667. {
  668. pn = 14;
  669. }
  670. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //354
  671. {
  672. pn = 23;
  673. }
  674. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //351
  675. {
  676. pn = 24;
  677. }
  678. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //359
  679. {
  680. pn = 4;
  681. }
  682. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //356
  683. {
  684. pn = 3;
  685. }
  686. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //352
  687. {
  688. pn = 17;
  689. }
  690. }
  691. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y) //65x
  692. {
  693. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //657
  694. {
  695. pn = 6;
  696. }
  697. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //654
  698. {
  699. pn = 15;
  700. }
  701. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //651
  702. {
  703. pn = 24;
  704. }
  705. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //652
  706. {
  707. pn = 17;
  708. }
  709. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //658
  710. {
  711. pn = 5;
  712. }
  713. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //653
  714. {
  715. pn = 18;
  716. }
  717. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //659
  718. {
  719. pn = 4;
  720. }
  721. }
  722. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1) //95x
  723. {
  724. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //954
  725. {
  726. pn = 7;
  727. }
  728. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //951
  729. {
  730. pn = 16;
  731. }
  732. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //952
  733. {
  734. pn = 17;
  735. }
  736. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //957
  737. {
  738. pn = 6;
  739. }
  740. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //953
  741. {
  742. pn = 18;
  743. }
  744. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //956
  745. {
  746. pn = 19;
  747. }
  748. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //958
  749. {
  750. pn = 5;
  751. }
  752. }
  753. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1) //85x
  754. {
  755. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //857
  756. {
  757. pn = 6;
  758. }
  759. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //854
  760. {
  761. pn = 7;
  762. }
  763. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //851
  764. {
  765. pn = 8;
  766. }
  767. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //852
  768. {
  769. pn = 9;
  770. }
  771. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //853
  772. {
  773. pn = 18;
  774. }
  775. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //856
  776. {
  777. pn = 19;
  778. }
  779. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //859
  780. {
  781. pn = 20;
  782. }
  783. }
  784. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1) //75x
  785. {
  786. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //752
  787. {
  788. pn = 1;
  789. }
  790. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //753
  791. {
  792. pn = 10;
  793. }
  794. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //756
  795. {
  796. pn = 19;
  797. }
  798. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //751
  799. {
  800. pn = 8;
  801. }
  802. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //759
  803. {
  804. pn = 20;
  805. }
  806. }
  807. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y) //45x
  808. {
  809. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //453
  810. {
  811. pn = 2;
  812. }
  813. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //456
  814. {
  815. pn = 11;
  816. }
  817. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //459
  818. {
  819. pn = 20;
  820. }
  821. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //452
  822. {
  823. pn = 1;
  824. }
  825. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //456
  826. {
  827. pn = 21;
  828. }
  829. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //451
  830. {
  831. pn = 8;
  832. }
  833. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //457
  834. {
  835. pn = 22;
  836. }
  837. }
  838. }
  839. if ( ((currentPath->nodes[i].dist)-(*(currentPath->nodes.end()-1)).dist) > (static_cast<const CGHeroInstance*>(LOCPLINT->adventureInt->selection))->movement)
  840. pn+=25;
  841. if (pn>=0)
  842. {
  843. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+CGI->mh->offsetX + pos.x,
  844. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+CGI->mh->offsetY + pos.y;
  845. if (x<0 || y<0 || x>pos.w || y>pos.h)
  846. continue;
  847. int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
  848. hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
  849. SDL_Rect prevClip;
  850. SDL_GetClipRect(screen, &prevClip);
  851. SDL_SetClipRect(screen, extRect); //preventing blitting outside of that rect
  852. if(ADVOPT.smoothMove) //version for smooth hero move, with pos shifts
  853. {
  854. if (hvx<0 && hvy<0)
  855. {
  856. CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, screen, &genRect(32, 32, x + moveX, y + moveY));
  857. }
  858. else if(hvx<0)
  859. {
  860. CSDL_Ext::blit8bppAlphaTo24bpp
  861. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0),
  862. screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x + moveX, y + moveY));
  863. }
  864. else if (hvy<0)
  865. {
  866. CSDL_Ext::blit8bppAlphaTo24bpp
  867. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0),
  868. screen, &genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY));
  869. }
  870. else
  871. {
  872. CSDL_Ext::blit8bppAlphaTo24bpp
  873. (arrows->ourImages[pn].bitmap, &genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx, 0, 0),
  874. screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY));
  875. }
  876. }
  877. else //standard version
  878. {
  879. if (hvx<0 && hvy<0)
  880. {
  881. CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, screen, &genRect(32, 32, x, y));
  882. }
  883. else if(hvx<0)
  884. {
  885. CSDL_Ext::blit8bppAlphaTo24bpp
  886. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0),
  887. screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x, y));
  888. }
  889. else if (hvy<0)
  890. {
  891. CSDL_Ext::blit8bppAlphaTo24bpp
  892. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0),
  893. screen, &genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x, y));
  894. }
  895. else
  896. {
  897. CSDL_Ext::blit8bppAlphaTo24bpp
  898. (arrows->ourImages[pn].bitmap, &genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx, 0, 0),
  899. screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x, y));
  900. }
  901. }
  902. SDL_SetClipRect(screen, &prevClip);
  903. }
  904. } //for (int i=0;i<currentPath->nodes.size()-1;i++)
  905. }
  906. void CTerrainRect::show(SDL_Surface * to)
  907. {
  908. if(ADVOPT.smoothMove)
  909. CGI->mh->terrainRect
  910. (LOCPLINT->adventureInt->position, LOCPLINT->adventureInt->anim,
  911. &LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim,
  912. to, &pos, moveX, moveY);
  913. else
  914. CGI->mh->terrainRect
  915. (LOCPLINT->adventureInt->position, LOCPLINT->adventureInt->anim,
  916. &LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim,
  917. to, &pos, 0, 0);
  918. //SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));
  919. //SDL_FreeSurface(teren);
  920. if (currentPath && LOCPLINT->adventureInt->position.z==currentPath->startPos().z) //drawing path
  921. {
  922. showPath(&pos);
  923. }
  924. }
  925. int3 CTerrainRect::whichTileIsIt(const int & x, const int & y)
  926. {
  927. int3 ret;
  928. ret.x = LOCPLINT->adventureInt->position.x + ((LOCPLINT->current->motion.x-CGI->mh->offsetX-pos.x)/32);
  929. ret.y = LOCPLINT->adventureInt->position.y + ((LOCPLINT->current->motion.y-CGI->mh->offsetY-pos.y)/32);
  930. ret.z = LOCPLINT->adventureInt->position.z;
  931. return ret;
  932. }
  933. int3 CTerrainRect::whichTileIsIt()
  934. {
  935. return whichTileIsIt(LOCPLINT->current->motion.x,LOCPLINT->current->motion.y);
  936. }
  937. void CResDataBar::clickRight (tribool down)
  938. {
  939. }
  940. void CResDataBar::activate()
  941. {
  942. ClickableR::activate();
  943. }
  944. void CResDataBar::deactivate()
  945. {
  946. ClickableR::deactivate();
  947. }
  948. CResDataBar::CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist)
  949. {
  950. bg = BitmapHandler::loadBitmap(defname);
  951. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  952. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  953. pos = genRect(bg->h,bg->w,x,y);
  954. txtpos.resize(8);
  955. for (int i = 0; i < 8 ; i++)
  956. {
  957. txtpos[i].first = pos.x + offx + resdist*i;
  958. txtpos[i].second = pos.y + offy;
  959. }
  960. txtpos[7].first = txtpos[6].first + datedist;
  961. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63]
  962. + ": %s, " + CGI->generaltexth->allTexts[64] + ": %s";
  963. }
  964. CResDataBar::CResDataBar()
  965. {
  966. bg = BitmapHandler::loadBitmap(ADVOPT.resdatabarG);
  967. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  968. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  969. pos = genRect(bg->h,bg->w,ADVOPT.resdatabarX,ADVOPT.resdatabarY);
  970. txtpos.resize(8);
  971. for (int i = 0; i < 8 ; i++)
  972. {
  973. txtpos[i].first = pos.x + ADVOPT.resOffsetX + ADVOPT.resDist*i;
  974. txtpos[i].second = pos.y + ADVOPT.resOffsetY;
  975. }
  976. txtpos[7].first = txtpos[6].first + ADVOPT.resDateDist;
  977. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63]
  978. + ": %s, " + CGI->generaltexth->allTexts[64] + ": %s";
  979. }
  980. CResDataBar::~CResDataBar()
  981. {
  982. SDL_FreeSurface(bg);
  983. }
  984. void CResDataBar::draw(SDL_Surface * to)
  985. {
  986. blitAt(bg,pos.x,pos.y,to);
  987. char * buf = new char[15];
  988. for (int i=0;i<7;i++)
  989. {
  990. SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
  991. printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly,to);
  992. }
  993. std::vector<std::string> temp;
  994. SDL_itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf);
  995. SDL_itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf);
  996. SDL_itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf);
  997. printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,GEOR13,zwykly,to);
  998. temp.clear();
  999. //updateRect(&pos,screen);
  1000. delete[] buf;
  1001. }
  1002. CInfoBar::CInfoBar()
  1003. {
  1004. toNextTick = mode = pom = -1;
  1005. pos.x=ADVOPT.infoboxX;
  1006. pos.y=ADVOPT.infoboxY;
  1007. pos.w=194;
  1008. pos.h=186;
  1009. day = CDefHandler::giveDef("NEWDAY.DEF");
  1010. week1 = CDefHandler::giveDef("NEWWEEK1.DEF");
  1011. week2 = CDefHandler::giveDef("NEWWEEK2.DEF");
  1012. week3 = CDefHandler::giveDef("NEWWEEK3.DEF");
  1013. week4 = CDefHandler::giveDef("NEWWEEK4.DEF");
  1014. }
  1015. CInfoBar::~CInfoBar()
  1016. {
  1017. delete day;
  1018. delete week1;
  1019. delete week2;
  1020. delete week3;
  1021. delete week4;
  1022. }
  1023. void CInfoBar::draw(SDL_Surface * to, const CGObjectInstance * specific)
  1024. {
  1025. if ((mode>=0) && mode<5)
  1026. {
  1027. blitAnim(mode);
  1028. return;
  1029. }
  1030. else if (mode==5)
  1031. {
  1032. mode = -1;
  1033. draw(to,LOCPLINT->adventureInt->selection);
  1034. }
  1035. if (!specific)
  1036. specific = LOCPLINT->adventureInt->selection;
  1037. if(!specific)
  1038. return;
  1039. if(specific->ID == HEROI_TYPE) //hero
  1040. {
  1041. if(graphics->heroWins.find(specific->subID)!=graphics->heroWins.end())
  1042. blitAt(graphics->heroWins[specific->subID],pos.x,pos.y,to);
  1043. }
  1044. else if (specific->ID == TOWNI_TYPE)
  1045. {
  1046. const CGTownInstance * t = static_cast<const CGTownInstance*>(specific);
  1047. if(graphics->townWins.find(t->id)!=graphics->townWins.end())
  1048. blitAt(graphics->townWins[t->id],pos.x,pos.y,to);
  1049. }
  1050. }
  1051. CDefHandler * CInfoBar::getAnim(int mode)
  1052. {
  1053. switch(mode)
  1054. {
  1055. case 0:
  1056. return day;
  1057. break;
  1058. case 1:
  1059. return week1;
  1060. break;
  1061. case 2:
  1062. return week2;
  1063. break;
  1064. case 3:
  1065. return week3;
  1066. break;
  1067. case 4:
  1068. return week4;
  1069. break;
  1070. default:
  1071. return NULL;
  1072. break;
  1073. }
  1074. }
  1075. void CInfoBar::blitAnim(int mode)//0 - day, 1 - week
  1076. {
  1077. CDefHandler * anim = NULL;
  1078. std::ostringstream txt;
  1079. anim = getAnim(mode);
  1080. if(mode) //new week animation
  1081. {
  1082. txt << CGI->generaltexth->allTexts[63] << " " << LOCPLINT->cb->getDate(2);
  1083. }
  1084. else //new day
  1085. {
  1086. txt << CGI->generaltexth->allTexts[64] << " " << LOCPLINT->cb->getDate(1);
  1087. }
  1088. blitAt(anim->ourImages[pom].bitmap,pos.x+9,pos.y+10);
  1089. printAtMiddle(txt.str(),pos.x+95,pos.y+31,TNRB16,zwykly);
  1090. if (pom == anim->ourImages.size()-1)
  1091. toNextTick+=750;
  1092. }
  1093. void CInfoBar::newDay(int Day)
  1094. {
  1095. if(LOCPLINT->cb->getDate(1) != 1)
  1096. {
  1097. mode = 0; //showing day
  1098. }
  1099. else
  1100. {
  1101. switch(LOCPLINT->cb->getDate(2))
  1102. {
  1103. case 1:
  1104. mode = 1;
  1105. break;
  1106. case 2:
  1107. mode = 2;
  1108. break;
  1109. case 3:
  1110. mode = 3;
  1111. break;
  1112. case 4:
  1113. mode = 4;
  1114. break;
  1115. default:
  1116. mode = -1;
  1117. break;
  1118. }
  1119. }
  1120. pom = 0;
  1121. TimeInterested::activate();
  1122. toNextTick = 500;
  1123. blitAnim(mode);
  1124. //blitAt(day->ourImages[pom].bitmap,pos.x+10,pos.y+10);
  1125. }
  1126. void CInfoBar::showComp(SComponent * comp, int time)
  1127. {
  1128. SDL_Surface * b = BitmapHandler::loadBitmap("ADSTATOT.bmp");
  1129. blitAt(b,pos.x+8,pos.y+11);
  1130. blitAt(comp->getImg(),pos.x+52,pos.y+54);
  1131. printAtMiddle(comp->subtitle,pos.x+91,pos.y+158,GEOR13,zwykly);
  1132. printAtMiddleWB(comp->description,pos.x+94,pos.y+31,GEOR13,26,zwykly);
  1133. SDL_FreeSurface(b);
  1134. TimeInterested::activate();
  1135. mode = 6;
  1136. toNextTick = time;
  1137. }
  1138. void CInfoBar::tick()
  1139. {
  1140. if((mode >= 0) && (mode < 5))
  1141. {
  1142. pom++;
  1143. if (pom >= getAnim(mode)->ourImages.size())
  1144. {
  1145. TimeInterested::deactivate();
  1146. toNextTick = -1;
  1147. mode = 5;
  1148. draw(screen2);
  1149. return;
  1150. }
  1151. toNextTick = 150;
  1152. blitAnim(mode);
  1153. }
  1154. else if (mode == 6)
  1155. {
  1156. TimeInterested::deactivate();
  1157. toNextTick = -1;
  1158. mode = 5;
  1159. draw(screen2);
  1160. }
  1161. }
  1162. CAdvMapInt::CAdvMapInt(int Player)
  1163. :player(Player),
  1164. statusbar(ADVOPT.statusbarX,ADVOPT.statusbarY,ADVOPT.statusbarG),
  1165. kingOverview(CGI->generaltexth->zelp[293].first,CGI->generaltexth->zelp[293].second,
  1166. boost::bind(&CAdvMapInt::fshowOverview,this),&ADVOPT.kingOverview, SDLK_k),
  1167. underground(CGI->generaltexth->zelp[294].first,CGI->generaltexth->zelp[294].second,
  1168. boost::bind(&CAdvMapInt::fswitchLevel,this),&ADVOPT.underground, SDLK_u),
  1169. questlog(CGI->generaltexth->zelp[295].first,CGI->generaltexth->zelp[295].second,
  1170. boost::bind(&CAdvMapInt::fshowQuestlog,this),&ADVOPT.questlog, SDLK_q),
  1171. sleepWake(CGI->generaltexth->zelp[296].first,CGI->generaltexth->zelp[296].second,
  1172. boost::bind(&CAdvMapInt::fsleepWake,this), &ADVOPT.sleepWake, SDLK_w),
  1173. moveHero(CGI->generaltexth->zelp[297].first,CGI->generaltexth->zelp[297].second,
  1174. boost::bind(&CAdvMapInt::fmoveHero,this), &ADVOPT.moveHero, SDLK_m),
  1175. spellbook(CGI->generaltexth->zelp[298].first,CGI->generaltexth->zelp[298].second,
  1176. boost::bind(&CAdvMapInt::fshowSpellbok,this), &ADVOPT.spellbook, SDLK_c),
  1177. advOptions(CGI->generaltexth->zelp[299].first,CGI->generaltexth->zelp[299].second,
  1178. boost::bind(&CAdvMapInt::fadventureOPtions,this), &ADVOPT.advOptions, SDLK_a),
  1179. sysOptions(CGI->generaltexth->zelp[300].first,CGI->generaltexth->zelp[300].second,
  1180. boost::bind(&CAdvMapInt::fsystemOptions,this), &ADVOPT.sysOptions, SDLK_o),
  1181. nextHero(CGI->generaltexth->zelp[301].first,CGI->generaltexth->zelp[301].second,
  1182. boost::bind(&CAdvMapInt::fnextHero,this), &ADVOPT.nextHero, SDLK_h),
  1183. endTurn(CGI->generaltexth->zelp[302].first,CGI->generaltexth->zelp[302].second,
  1184. boost::bind(&CAdvMapInt::fendTurn,this), &ADVOPT.endTurn, SDLK_e),
  1185. heroList(ADVOPT.hlistSize),
  1186. townList(ADVOPT.tlistSize,ADVOPT.tlistX,ADVOPT.tlistY,ADVOPT.tlistAU,ADVOPT.tlistAD)//(5,&genRect(192,48,747,196),747,196,747,372),
  1187. {
  1188. active = 0;
  1189. subInt = NULL;
  1190. selection = NULL;
  1191. townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this);
  1192. LOCPLINT->adventureInt=this;
  1193. bg = BitmapHandler::loadBitmap(ADVOPT.mainGraphic);
  1194. graphics->blueToPlayersAdv(bg,player);
  1195. scrollingDir = 0;
  1196. updateScreen = false;
  1197. anim=0;
  1198. animValHitCount=0; //animation frame
  1199. heroAnim=0;
  1200. heroAnimValHitCount=0; // hero animation frame
  1201. heroList.init();
  1202. heroList.genList();
  1203. //townList.init();
  1204. townList.genList();
  1205. heroWindow = new CHeroWindow(this->player);
  1206. gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[0]));
  1207. gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[1]));
  1208. gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[2]));
  1209. gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[3]));
  1210. }
  1211. CAdvMapInt::~CAdvMapInt()
  1212. {
  1213. SDL_FreeSurface(bg);
  1214. delete heroWindow;
  1215. for(int i=0; i<gems.size(); i++)
  1216. delete gems[i];
  1217. }
  1218. void CAdvMapInt::fshowOverview()
  1219. {
  1220. }
  1221. void CAdvMapInt::fswitchLevel()
  1222. {
  1223. if(!CGI->mh->map->twoLevel)
  1224. return;
  1225. if (position.z)
  1226. {
  1227. position.z--;
  1228. underground.curimg=0;
  1229. underground.show(screenBuf);
  1230. }
  1231. else
  1232. {
  1233. underground.curimg=1;
  1234. position.z++;
  1235. underground.show(screenBuf);
  1236. }
  1237. updateScreen = true;
  1238. minimap.draw(screenBuf);
  1239. }
  1240. void CAdvMapInt::fshowQuestlog()
  1241. {
  1242. }
  1243. void CAdvMapInt::fsleepWake()
  1244. {
  1245. }
  1246. void CAdvMapInt::fmoveHero()
  1247. {
  1248. if (selection->ID!=HEROI_TYPE)
  1249. return;
  1250. if (!terrain.currentPath)
  1251. return;
  1252. LOCPLINT->pim->unlock();
  1253. LOCPLINT->moveHero(static_cast<const CGHeroInstance*>(LOCPLINT->adventureInt->selection),*terrain.currentPath);
  1254. LOCPLINT->pim->lock();
  1255. }
  1256. void CAdvMapInt::fshowSpellbok()
  1257. {
  1258. if (selection->ID!=HEROI_TYPE) //checking necessary values
  1259. return;
  1260. CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), (static_cast<const CGHeroInstance*>(LOCPLINT->adventureInt->selection)));
  1261. LOCPLINT->pushInt(spellWindow);
  1262. }
  1263. void CAdvMapInt::fadventureOPtions()
  1264. {
  1265. }
  1266. void CAdvMapInt::fsystemOptions()
  1267. {
  1268. CSystemOptionsWindow * sysopWindow = new CSystemOptionsWindow(genRect(487, 481, 159, 57), LOCPLINT);
  1269. LOCPLINT->pushInt(sysopWindow);
  1270. }
  1271. void CAdvMapInt::fnextHero()
  1272. {
  1273. if(!LOCPLINT->wanderingHeroes.size()) //no wandering heroes
  1274. return;
  1275. int start = heroList.selected;
  1276. int i = start;
  1277. do
  1278. {
  1279. i++;
  1280. if(i >= LOCPLINT->wanderingHeroes.size())
  1281. i = 0;
  1282. } while (LOCPLINT->wanderingHeroes[i]->movement && i!=start);
  1283. heroList.select(i);
  1284. }
  1285. void CAdvMapInt::fendTurn()
  1286. {
  1287. LOCPLINT->makingTurn = false;
  1288. }
  1289. void CAdvMapInt::activate()
  1290. {
  1291. if(active++)
  1292. {
  1293. tlog1 << "Error: advmapint already active...\n";
  1294. active--;
  1295. return;
  1296. }
  1297. screenBuf = screen;
  1298. LOCPLINT->statusbar = &statusbar;
  1299. kingOverview.activate();
  1300. underground.activate();
  1301. questlog.activate();
  1302. sleepWake.activate();
  1303. moveHero.activate();
  1304. spellbook.activate();
  1305. sysOptions.activate();
  1306. advOptions.activate();
  1307. nextHero.activate();
  1308. endTurn.activate();
  1309. minimap.activate();
  1310. heroList.activate();
  1311. townList.activate();
  1312. terrain.activate();
  1313. LOCPLINT->cingconsole->activate();
  1314. }
  1315. void CAdvMapInt::deactivate()
  1316. {
  1317. scrollingDir = 0;
  1318. CGI->curh->changeGraphic(0,0);
  1319. kingOverview.deactivate();
  1320. underground.deactivate();
  1321. questlog.deactivate();
  1322. sleepWake.deactivate();
  1323. moveHero.deactivate();
  1324. spellbook.deactivate();
  1325. advOptions.deactivate();
  1326. sysOptions.deactivate();
  1327. nextHero.deactivate();
  1328. endTurn.deactivate();
  1329. minimap.deactivate();
  1330. heroList.deactivate();
  1331. townList.deactivate();
  1332. terrain.deactivate();
  1333. if(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar)!=LOCPLINT->timeinterested.end())
  1334. LOCPLINT->timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar));
  1335. infoBar.mode=-1;
  1336. LOCPLINT->cingconsole->deactivate();
  1337. if(--active)
  1338. {
  1339. tlog1 << "Error: advmapint still active...\n";
  1340. deactivate();
  1341. }
  1342. }
  1343. void CAdvMapInt::showAll(SDL_Surface *to)
  1344. {
  1345. blitAt(bg,0,0,to);
  1346. kingOverview.show(to);
  1347. underground.show(to);
  1348. questlog.show(to);
  1349. sleepWake.show(to);
  1350. moveHero.show(to);
  1351. spellbook.show(to);
  1352. advOptions.show(to);
  1353. sysOptions.show(to);
  1354. nextHero.show(to);
  1355. endTurn.show(to);
  1356. minimap.draw(to);
  1357. heroList.draw(to);
  1358. townList.draw(to);
  1359. updateScreen = true;
  1360. show(to);
  1361. resdatabar.draw(to);
  1362. statusbar.show(to);
  1363. infoBar.draw(to);
  1364. LOCPLINT->cingconsole->show(to);
  1365. }
  1366. void CAdvMapInt::show(SDL_Surface *to)
  1367. {
  1368. ++animValHitCount; //for animations
  1369. if(animValHitCount == 8)
  1370. {
  1371. CGI->mh->updateWater();
  1372. animValHitCount = 0;
  1373. ++anim;
  1374. updateScreen = true;
  1375. }
  1376. ++heroAnim;
  1377. //if advmap needs updating AND (no dialog is shown OR ctrl is pressed)
  1378. if((animValHitCount % (4/LOCPLINT->mapScrollingSpeed)) == 0
  1379. &&
  1380. (LOCPLINT->topInt() == this)
  1381. || SDL_GetKeyState(NULL)[SDLK_LCTRL]
  1382. || SDL_GetKeyState(NULL)[SDLK_RCTRL]
  1383. )
  1384. {
  1385. if( (scrollingDir & LEFT) && (position.x>-CGI->mh->frameW) )
  1386. position.x--;
  1387. if( (scrollingDir & RIGHT) && (position.x < CGI->mh->map->width - CGI->mh->tilesW + CGI->mh->frameW) )
  1388. position.x++;
  1389. if( (scrollingDir & UP) && (position.y>-CGI->mh->frameH) )
  1390. position.y--;
  1391. if( (scrollingDir & DOWN) && (position.y < CGI->mh->map->height - CGI->mh->tilesH + CGI->mh->frameH) )
  1392. position.y++;
  1393. if(scrollingDir)
  1394. {
  1395. updateScreen = true;
  1396. updateMinimap=true;
  1397. }
  1398. }
  1399. if(updateScreen)
  1400. {
  1401. terrain.show(to);
  1402. for(int i=0;i<4;i++)
  1403. blitAt(gems[i]->ourImages[LOCPLINT->playerID].bitmap,ADVOPT.gemX[i],ADVOPT.gemY[i],to);
  1404. updateScreen=false;
  1405. LOCPLINT->cingconsole->show(to);
  1406. }
  1407. if (updateMinimap)
  1408. {
  1409. minimap.draw(to);
  1410. updateMinimap=false;
  1411. }
  1412. }
  1413. void CAdvMapInt::selectionChanged()
  1414. {
  1415. const CGTownInstance *to = townList.items[townList.selected];
  1416. select(to);
  1417. }
  1418. void CAdvMapInt::centerOn(int3 on)
  1419. {
  1420. // TODO:convertPosition should not belong to CGHeroInstance, and it
  1421. // should be split in 2 methods.
  1422. on = CGHeroInstance::convertPosition(on, false);
  1423. on.x -= CGI->mh->frameW;
  1424. on.y -= CGI->mh->frameH;
  1425. on = LOCPLINT->repairScreenPos(on);
  1426. LOCPLINT->adventureInt->position = on;
  1427. LOCPLINT->adventureInt->updateScreen=true;
  1428. updateMinimap=true;
  1429. }
  1430. void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
  1431. {
  1432. ui8 Dir;
  1433. switch(key.keysym.sym)
  1434. {
  1435. case SDLK_UP:
  1436. Dir = UP;
  1437. break;
  1438. case SDLK_LEFT:
  1439. Dir = LEFT;
  1440. break;
  1441. case SDLK_RIGHT:
  1442. Dir = RIGHT;
  1443. break;
  1444. case SDLK_DOWN:
  1445. Dir = DOWN;
  1446. break;
  1447. case SDLK_SPACE: //space - try to revisit current object with selected hero
  1448. {
  1449. if(!active)
  1450. return;
  1451. const CGHeroInstance *h = dynamic_cast<const CGHeroInstance*>(selection);
  1452. if(h && key.state == SDL_PRESSED)
  1453. {
  1454. LOCPLINT->pim->unlock();
  1455. LOCPLINT->cb->moveHero(h,h->pos);
  1456. LOCPLINT->pim->lock();
  1457. }
  1458. }
  1459. return;
  1460. case SDLK_RETURN:
  1461. {
  1462. if(!active || !selection || key.state != SDL_PRESSED)
  1463. return;
  1464. if(selection->ID == 34)
  1465. LOCPLINT->openHeroWindow(static_cast<const CGHeroInstance*>(selection));
  1466. else if(selection->ID == 98)
  1467. LOCPLINT->openTownWindow(static_cast<const CGTownInstance*>(selection));
  1468. return;
  1469. }
  1470. default:
  1471. return;
  1472. }
  1473. if(key.state == SDL_PRESSED //arrow is pressed
  1474. && (SDL_GetKeyState(NULL)[SDLK_LCTRL]
  1475. || SDL_GetKeyState(NULL)[SDLK_RCTRL])
  1476. )
  1477. scrollingDir |= Dir;
  1478. else
  1479. scrollingDir &= ~Dir;
  1480. }
  1481. void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * client)
  1482. {
  1483. if (down)
  1484. {
  1485. //boost::algorithm::erase_all(text,"\"");
  1486. CSimpleWindow * temp = CMessage::genWindow(text,LOCPLINT->playerID);
  1487. temp->pos.x=screen->w/2-(temp->pos.w/2);
  1488. temp->pos.y=screen->h/2-(temp->pos.h/2);
  1489. temp->owner = client;
  1490. CRClickPopupInt *rcpi = new CRClickPopupInt(temp,true);
  1491. LOCPLINT->pushInt(rcpi);
  1492. }
  1493. }
  1494. int3 CAdvMapInt::verifyPos(int3 ver)
  1495. {
  1496. if (ver.x<0)
  1497. ver.x=0;
  1498. if (ver.y<0)
  1499. ver.y=0;
  1500. if (ver.z<0)
  1501. ver.z=0;
  1502. if (ver.x>=CGI->mh->sizes.x)
  1503. ver.x=CGI->mh->sizes.x-1;
  1504. if (ver.y>=CGI->mh->sizes.y)
  1505. ver.y=CGI->mh->sizes.y-1;
  1506. if (ver.z>=CGI->mh->sizes.z)
  1507. ver.z=CGI->mh->sizes.z-1;
  1508. return ver;
  1509. }
  1510. void CAdvMapInt::select(const CArmedInstance *sel )
  1511. {
  1512. LOCPLINT->cb->setSelection(sel);
  1513. centerOn(sel->pos);
  1514. selection = sel;
  1515. terrain.currentPath = NULL;
  1516. if(sel->ID==TOWNI_TYPE)
  1517. {
  1518. int pos = vstd::findPos(townList.items,sel);
  1519. townList.selected = pos;
  1520. }
  1521. else //hero selected
  1522. {
  1523. const CGHeroInstance *h = static_cast<const CGHeroInstance*>(sel);
  1524. if(LOCPLINT->getWHero(heroList.selected) != h)
  1525. heroList.selected = heroList.getPosOfHero(h);
  1526. if(vstd::contains(paths,h)) //hero has assigned path
  1527. {
  1528. CPath &path = paths[h];
  1529. //update the hero path in case of something has changed on map
  1530. if(LOCPLINT->cb->getPath(path.startPos(), path.endPos(), h, path))
  1531. terrain.currentPath = &path;
  1532. else
  1533. paths.erase(h);
  1534. }
  1535. }
  1536. townList.draw(screen);
  1537. heroList.draw(screen);
  1538. infoBar.draw(screen);
  1539. }