CAdvmapInterface.cpp 45 KB

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