CAdvmapInterface.cpp 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632
  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. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  581. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  582. if (x<0 || y<0 || x>pos.w || y>pos.h)
  583. continue;
  584. pn=0;
  585. }
  586. else
  587. {
  588. /*
  589. * notation of arrow direction:
  590. * 1 2 3
  591. * 4 5 6
  592. * 7 8 9
  593. * ie. 157 means an arrow from left upper tile to left bottom tile through 5 (all arrows go through 5 in this notation)
  594. */
  595. std::vector<CPathNode> & cv = currentPath->nodes;
  596. if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1) //15x
  597. {
  598. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //156
  599. {
  600. pn = 3;
  601. }
  602. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //159
  603. {
  604. pn = 12;
  605. }
  606. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //158
  607. {
  608. pn = 21;
  609. }
  610. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //157
  611. {
  612. pn = 22;
  613. }
  614. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //153
  615. {
  616. pn = 2;
  617. }
  618. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //154
  619. {
  620. pn = 23;
  621. }
  622. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //152
  623. {
  624. pn = 1;
  625. }
  626. }
  627. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1) //25x
  628. {
  629. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //253
  630. {
  631. pn = 2;
  632. }
  633. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //256
  634. {
  635. pn = 3;
  636. }
  637. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //259
  638. {
  639. pn = 4;
  640. }
  641. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //258
  642. {
  643. pn = 13;
  644. }
  645. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //257
  646. {
  647. pn = 22;
  648. }
  649. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //254
  650. {
  651. pn = 23;
  652. }
  653. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //251
  654. {
  655. pn = 24;
  656. }
  657. }
  658. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1) //35x
  659. {
  660. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //358
  661. {
  662. pn = 5;
  663. }
  664. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //357
  665. {
  666. pn = 14;
  667. }
  668. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //354
  669. {
  670. pn = 23;
  671. }
  672. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //351
  673. {
  674. pn = 24;
  675. }
  676. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //359
  677. {
  678. pn = 4;
  679. }
  680. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //356
  681. {
  682. pn = 3;
  683. }
  684. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //352
  685. {
  686. pn = 17;
  687. }
  688. }
  689. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y) //65x
  690. {
  691. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //657
  692. {
  693. pn = 6;
  694. }
  695. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //654
  696. {
  697. pn = 15;
  698. }
  699. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //651
  700. {
  701. pn = 24;
  702. }
  703. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //652
  704. {
  705. pn = 17;
  706. }
  707. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //658
  708. {
  709. pn = 5;
  710. }
  711. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //653
  712. {
  713. pn = 18;
  714. }
  715. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //659
  716. {
  717. pn = 4;
  718. }
  719. }
  720. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1) //95x
  721. {
  722. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //954
  723. {
  724. pn = 7;
  725. }
  726. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //951
  727. {
  728. pn = 16;
  729. }
  730. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //952
  731. {
  732. pn = 17;
  733. }
  734. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //957
  735. {
  736. pn = 6;
  737. }
  738. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //953
  739. {
  740. pn = 18;
  741. }
  742. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //956
  743. {
  744. pn = 19;
  745. }
  746. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //958
  747. {
  748. pn = 5;
  749. }
  750. }
  751. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1) //85x
  752. {
  753. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //857
  754. {
  755. pn = 6;
  756. }
  757. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //854
  758. {
  759. pn = 7;
  760. }
  761. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //851
  762. {
  763. pn = 8;
  764. }
  765. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //852
  766. {
  767. pn = 9;
  768. }
  769. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //853
  770. {
  771. pn = 18;
  772. }
  773. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //856
  774. {
  775. pn = 19;
  776. }
  777. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //859
  778. {
  779. pn = 20;
  780. }
  781. }
  782. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1) //75x
  783. {
  784. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //752
  785. {
  786. pn = 1;
  787. }
  788. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //753
  789. {
  790. pn = 10;
  791. }
  792. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //756
  793. {
  794. pn = 19;
  795. }
  796. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //751
  797. {
  798. pn = 8;
  799. }
  800. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //759
  801. {
  802. pn = 20;
  803. }
  804. }
  805. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y) //45x
  806. {
  807. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //453
  808. {
  809. pn = 2;
  810. }
  811. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //456
  812. {
  813. pn = 11;
  814. }
  815. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //459
  816. {
  817. pn = 20;
  818. }
  819. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //452
  820. {
  821. pn = 1;
  822. }
  823. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //456
  824. {
  825. pn = 21;
  826. }
  827. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //451
  828. {
  829. pn = 8;
  830. }
  831. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //457
  832. {
  833. pn = 22;
  834. }
  835. }
  836. }
  837. if ( ((currentPath->nodes[i].dist)-(*(currentPath->nodes.end()-1)).dist) > (static_cast<const CGHeroInstance*>(LOCPLINT->adventureInt->selection))->movement)
  838. pn+=25;
  839. if (pn>=0)
  840. {
  841. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  842. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  843. if (x<0 || y<0 || x>pos.w || y>pos.h)
  844. continue;
  845. int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
  846. hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
  847. SDL_Rect prevClip;
  848. SDL_GetClipRect(screen, &prevClip);
  849. SDL_SetClipRect(screen, extRect); //preventing blitting outside of that rect
  850. if(ADVOPT.smoothMove) //version for smooth hero move, with pos shifts
  851. {
  852. if (hvx<0 && hvy<0)
  853. {
  854. CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, screen, &genRect(32, 32, x + moveX, y + moveY));
  855. }
  856. else if(hvx<0)
  857. {
  858. CSDL_Ext::blit8bppAlphaTo24bpp
  859. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0),
  860. screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x + moveX, y + moveY));
  861. }
  862. else if (hvy<0)
  863. {
  864. CSDL_Ext::blit8bppAlphaTo24bpp
  865. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0),
  866. screen, &genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY));
  867. }
  868. else
  869. {
  870. CSDL_Ext::blit8bppAlphaTo24bpp
  871. (arrows->ourImages[pn].bitmap, &genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx, 0, 0),
  872. screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY));
  873. }
  874. }
  875. else //standard version
  876. {
  877. if (hvx<0 && hvy<0)
  878. {
  879. CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, screen, &genRect(32, 32, x, y));
  880. }
  881. else if(hvx<0)
  882. {
  883. CSDL_Ext::blit8bppAlphaTo24bpp
  884. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0),
  885. screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x, y));
  886. }
  887. else if (hvy<0)
  888. {
  889. CSDL_Ext::blit8bppAlphaTo24bpp
  890. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0),
  891. screen, &genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x, y));
  892. }
  893. else
  894. {
  895. CSDL_Ext::blit8bppAlphaTo24bpp
  896. (arrows->ourImages[pn].bitmap, &genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx, 0, 0),
  897. screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x, y));
  898. }
  899. }
  900. SDL_SetClipRect(screen, &prevClip);
  901. }
  902. } //for (int i=0;i<currentPath->nodes.size()-1;i++)
  903. }
  904. void CTerrainRect::show(SDL_Surface * to)
  905. {
  906. CGI->mh->terrainRect
  907. (LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
  908. tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim,
  909. &LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim,
  910. to, &genRect(pos.h, pos.w, pos.x, pos.y), moveX, moveY, ADVOPT.smoothMove && (moveX != 0 || moveY != 0)
  911. );
  912. //SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));
  913. //SDL_FreeSurface(teren);
  914. if (currentPath && LOCPLINT->adventureInt->position.z==currentPath->startPos().z) //drawing path
  915. {
  916. showPath(&genRect(pos.h, pos.w, pos.x, pos.y));
  917. }
  918. }
  919. int3 CTerrainRect::whichTileIsIt(const int & x, const int & y)
  920. {
  921. int3 ret;
  922. ret.x = LOCPLINT->adventureInt->position.x + ((LOCPLINT->current->motion.x-pos.x)/32);
  923. ret.y = LOCPLINT->adventureInt->position.y + ((LOCPLINT->current->motion.y-pos.y)/32);
  924. ret.z = LOCPLINT->adventureInt->position.z;
  925. return ret;
  926. }
  927. int3 CTerrainRect::whichTileIsIt()
  928. {
  929. return whichTileIsIt(LOCPLINT->current->motion.x,LOCPLINT->current->motion.y);
  930. }
  931. void CResDataBar::clickRight (tribool down)
  932. {
  933. }
  934. void CResDataBar::activate()
  935. {
  936. ClickableR::activate();
  937. }
  938. void CResDataBar::deactivate()
  939. {
  940. ClickableR::deactivate();
  941. }
  942. CResDataBar::CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist)
  943. {
  944. bg = BitmapHandler::loadBitmap(defname);
  945. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  946. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  947. pos = genRect(bg->h,bg->w,x,y);
  948. txtpos.resize(8);
  949. for (int i = 0; i < 8 ; i++)
  950. {
  951. txtpos[i].first = pos.x + offx + resdist*i;
  952. txtpos[i].second = pos.y + offy;
  953. }
  954. txtpos[7].first = txtpos[6].first + datedist;
  955. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63]
  956. + ": %s, " + CGI->generaltexth->allTexts[64] + ": %s";
  957. }
  958. CResDataBar::CResDataBar()
  959. {
  960. bg = BitmapHandler::loadBitmap(ADVOPT.resdatabarG);
  961. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  962. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  963. pos = genRect(bg->h,bg->w,ADVOPT.resdatabarX,ADVOPT.resdatabarY);
  964. txtpos.resize(8);
  965. for (int i = 0; i < 8 ; i++)
  966. {
  967. txtpos[i].first = pos.x + ADVOPT.resOffsetX + ADVOPT.resDist*i;
  968. txtpos[i].second = pos.y + ADVOPT.resOffsetY;
  969. }
  970. txtpos[7].first = txtpos[6].first + ADVOPT.resDateDist;
  971. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63]
  972. + ": %s, " + CGI->generaltexth->allTexts[64] + ": %s";
  973. }
  974. CResDataBar::~CResDataBar()
  975. {
  976. SDL_FreeSurface(bg);
  977. }
  978. void CResDataBar::draw(SDL_Surface * to)
  979. {
  980. blitAt(bg,pos.x,pos.y,to);
  981. char * buf = new char[15];
  982. for (int i=0;i<7;i++)
  983. {
  984. SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
  985. printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly,to);
  986. }
  987. std::vector<std::string> temp;
  988. SDL_itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf);
  989. SDL_itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf);
  990. SDL_itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf);
  991. printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,GEOR13,zwykly,to);
  992. temp.clear();
  993. //updateRect(&pos,screen);
  994. delete[] buf;
  995. }
  996. CInfoBar::CInfoBar()
  997. {
  998. toNextTick = mode = pom = -1;
  999. pos.x=ADVOPT.infoboxX;
  1000. pos.y=ADVOPT.infoboxY;
  1001. pos.w=194;
  1002. pos.h=186;
  1003. day = CDefHandler::giveDef("NEWDAY.DEF");
  1004. week1 = CDefHandler::giveDef("NEWWEEK1.DEF");
  1005. week2 = CDefHandler::giveDef("NEWWEEK2.DEF");
  1006. week3 = CDefHandler::giveDef("NEWWEEK3.DEF");
  1007. week4 = CDefHandler::giveDef("NEWWEEK4.DEF");
  1008. }
  1009. CInfoBar::~CInfoBar()
  1010. {
  1011. delete day;
  1012. delete week1;
  1013. delete week2;
  1014. delete week3;
  1015. delete week4;
  1016. }
  1017. void CInfoBar::draw(SDL_Surface * to, const CGObjectInstance * specific)
  1018. {
  1019. if ((mode>=0) && mode<5)
  1020. {
  1021. blitAnim(mode);
  1022. return;
  1023. }
  1024. else if (mode==5)
  1025. {
  1026. mode = -1;
  1027. draw(to,LOCPLINT->adventureInt->selection);
  1028. }
  1029. if (!specific)
  1030. specific = LOCPLINT->adventureInt->selection;
  1031. if(!specific)
  1032. return;
  1033. if(specific->ID == HEROI_TYPE) //hero
  1034. {
  1035. if(graphics->heroWins.find(specific->subID)!=graphics->heroWins.end())
  1036. blitAt(graphics->heroWins[specific->subID],pos.x,pos.y,to);
  1037. }
  1038. else if (specific->ID == TOWNI_TYPE)
  1039. {
  1040. const CGTownInstance * t = static_cast<const CGTownInstance*>(specific);
  1041. if(graphics->townWins.find(t->id)!=graphics->townWins.end())
  1042. blitAt(graphics->townWins[t->id],pos.x,pos.y,to);
  1043. }
  1044. }
  1045. CDefHandler * CInfoBar::getAnim(int mode)
  1046. {
  1047. switch(mode)
  1048. {
  1049. case 0:
  1050. return day;
  1051. break;
  1052. case 1:
  1053. return week1;
  1054. break;
  1055. case 2:
  1056. return week2;
  1057. break;
  1058. case 3:
  1059. return week3;
  1060. break;
  1061. case 4:
  1062. return week4;
  1063. break;
  1064. default:
  1065. return NULL;
  1066. break;
  1067. }
  1068. }
  1069. void CInfoBar::blitAnim(int mode)//0 - day, 1 - week
  1070. {
  1071. CDefHandler * anim = NULL;
  1072. std::stringstream txt;
  1073. anim = getAnim(mode);
  1074. if(mode) //new week animation
  1075. {
  1076. txt << CGI->generaltexth->allTexts[63] << " " << LOCPLINT->cb->getDate(2);
  1077. }
  1078. else //new day
  1079. {
  1080. txt << CGI->generaltexth->allTexts[64] << " " << LOCPLINT->cb->getDate(1);
  1081. }
  1082. blitAt(anim->ourImages[pom].bitmap,pos.x+9,pos.y+10);
  1083. printAtMiddle(txt.str(),pos.x+95,pos.y+31,TNRB16,zwykly);
  1084. if (pom == anim->ourImages.size()-1)
  1085. toNextTick+=750;
  1086. }
  1087. void CInfoBar::newDay(int Day)
  1088. {
  1089. if(LOCPLINT->cb->getDate(1) != 1)
  1090. {
  1091. mode = 0; //showing day
  1092. }
  1093. else
  1094. {
  1095. switch(LOCPLINT->cb->getDate(2))
  1096. {
  1097. case 1:
  1098. mode = 1;
  1099. break;
  1100. case 2:
  1101. mode = 2;
  1102. break;
  1103. case 3:
  1104. mode = 3;
  1105. break;
  1106. case 4:
  1107. mode = 4;
  1108. break;
  1109. default:
  1110. mode = -1;
  1111. break;
  1112. }
  1113. }
  1114. pom = 0;
  1115. TimeInterested::activate();
  1116. toNextTick = 500;
  1117. blitAnim(mode);
  1118. //blitAt(day->ourImages[pom].bitmap,pos.x+10,pos.y+10);
  1119. }
  1120. void CInfoBar::showComp(SComponent * comp, int time)
  1121. {
  1122. SDL_Surface * b = BitmapHandler::loadBitmap("ADSTATOT.bmp");
  1123. blitAt(b,pos.x+8,pos.y+11);
  1124. blitAt(comp->getImg(),pos.x+52,pos.y+54);
  1125. printAtMiddle(comp->subtitle,pos.x+91,pos.y+158,GEOR13,zwykly);
  1126. printAtMiddleWB(comp->description,pos.x+94,pos.y+31,GEOR13,26,zwykly);
  1127. SDL_FreeSurface(b);
  1128. TimeInterested::activate();
  1129. mode = 6;
  1130. toNextTick = time;
  1131. }
  1132. void CInfoBar::tick()
  1133. {
  1134. if((mode >= 0) && (mode < 5))
  1135. {
  1136. pom++;
  1137. if (pom >= getAnim(mode)->ourImages.size())
  1138. {
  1139. TimeInterested::deactivate();
  1140. toNextTick = -1;
  1141. mode = 5;
  1142. draw(screen2);
  1143. return;
  1144. }
  1145. toNextTick = 150;
  1146. blitAnim(mode);
  1147. }
  1148. else if (mode == 6)
  1149. {
  1150. TimeInterested::deactivate();
  1151. toNextTick = -1;
  1152. mode = 5;
  1153. draw(screen2);
  1154. }
  1155. }
  1156. CAdvMapInt::CAdvMapInt(int Player)
  1157. :player(Player),
  1158. statusbar(ADVOPT.statusbarX,ADVOPT.statusbarY,ADVOPT.statusbarG),
  1159. kingOverview(CGI->generaltexth->zelp[293].first,CGI->generaltexth->zelp[293].second,
  1160. boost::bind(&CAdvMapInt::fshowOverview,this),&ADVOPT.kingOverview, SDLK_k),
  1161. underground(CGI->generaltexth->zelp[294].first,CGI->generaltexth->zelp[294].second,
  1162. boost::bind(&CAdvMapInt::fswitchLevel,this),&ADVOPT.underground, SDLK_u),
  1163. questlog(CGI->generaltexth->zelp[295].first,CGI->generaltexth->zelp[295].second,
  1164. boost::bind(&CAdvMapInt::fshowQuestlog,this),&ADVOPT.questlog, SDLK_q),
  1165. sleepWake(CGI->generaltexth->zelp[296].first,CGI->generaltexth->zelp[296].second,
  1166. boost::bind(&CAdvMapInt::fsleepWake,this), &ADVOPT.sleepWake, SDLK_w),
  1167. moveHero(CGI->generaltexth->zelp[297].first,CGI->generaltexth->zelp[297].second,
  1168. boost::bind(&CAdvMapInt::fmoveHero,this), &ADVOPT.moveHero, SDLK_m),
  1169. spellbook(CGI->generaltexth->zelp[298].first,CGI->generaltexth->zelp[298].second,
  1170. boost::bind(&CAdvMapInt::fshowSpellbok,this), &ADVOPT.spellbook, SDLK_c),
  1171. advOptions(CGI->generaltexth->zelp[299].first,CGI->generaltexth->zelp[299].second,
  1172. boost::bind(&CAdvMapInt::fadventureOPtions,this), &ADVOPT.advOptions, SDLK_a),
  1173. sysOptions(CGI->generaltexth->zelp[300].first,CGI->generaltexth->zelp[300].second,
  1174. boost::bind(&CAdvMapInt::fsystemOptions,this), &ADVOPT.sysOptions, SDLK_o),
  1175. nextHero(CGI->generaltexth->zelp[301].first,CGI->generaltexth->zelp[301].second,
  1176. boost::bind(&CAdvMapInt::fnextHero,this), &ADVOPT.nextHero, SDLK_h),
  1177. endTurn(CGI->generaltexth->zelp[302].first,CGI->generaltexth->zelp[302].second,
  1178. boost::bind(&CAdvMapInt::fendTurn,this), &ADVOPT.endTurn, SDLK_e),
  1179. heroList(ADVOPT.hlistSize),
  1180. townList(ADVOPT.tlistSize,ADVOPT.tlistX,ADVOPT.tlistY,ADVOPT.tlistAU,ADVOPT.tlistAD)//(5,&genRect(192,48,747,196),747,196,747,372),
  1181. {
  1182. active = 0;
  1183. subInt = NULL;
  1184. selection = NULL;
  1185. townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this);
  1186. LOCPLINT->adventureInt=this;
  1187. bg = BitmapHandler::loadBitmap(ADVOPT.mainGraphic);
  1188. graphics->blueToPlayersAdv(bg,player);
  1189. scrollingDir = 0;
  1190. updateScreen = false;
  1191. anim=0;
  1192. animValHitCount=0; //animation frame
  1193. heroAnim=0;
  1194. heroAnimValHitCount=0; // hero animation frame
  1195. heroList.init();
  1196. heroList.genList();
  1197. //townList.init();
  1198. townList.genList();
  1199. heroWindow = new CHeroWindow(this->player);
  1200. gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[0]));
  1201. gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[1]));
  1202. gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[2]));
  1203. gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[3]));
  1204. }
  1205. CAdvMapInt::~CAdvMapInt()
  1206. {
  1207. SDL_FreeSurface(bg);
  1208. delete heroWindow;
  1209. for(int i=0; i<gems.size(); i++)
  1210. delete gems[i];
  1211. }
  1212. void CAdvMapInt::fshowOverview()
  1213. {
  1214. }
  1215. void CAdvMapInt::fswitchLevel()
  1216. {
  1217. if(!CGI->mh->map->twoLevel)
  1218. return;
  1219. if (position.z)
  1220. {
  1221. position.z--;
  1222. underground.curimg=0;
  1223. underground.show(screenBuf);
  1224. }
  1225. else
  1226. {
  1227. underground.curimg=1;
  1228. position.z++;
  1229. underground.show(screenBuf);
  1230. }
  1231. updateScreen = true;
  1232. minimap.draw(screenBuf);
  1233. }
  1234. void CAdvMapInt::fshowQuestlog()
  1235. {
  1236. }
  1237. void CAdvMapInt::fsleepWake()
  1238. {
  1239. }
  1240. void CAdvMapInt::fmoveHero()
  1241. {
  1242. if (selection->ID!=HEROI_TYPE)
  1243. return;
  1244. if (!terrain.currentPath)
  1245. return;
  1246. LOCPLINT->pim->unlock();
  1247. LOCPLINT->moveHero(static_cast<const CGHeroInstance*>(LOCPLINT->adventureInt->selection),*terrain.currentPath);
  1248. LOCPLINT->pim->lock();
  1249. }
  1250. void CAdvMapInt::fshowSpellbok()
  1251. {
  1252. if (selection->ID!=HEROI_TYPE) //checking necessary values
  1253. return;
  1254. CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), (static_cast<const CGHeroInstance*>(LOCPLINT->adventureInt->selection)));
  1255. LOCPLINT->pushInt(spellWindow);
  1256. }
  1257. void CAdvMapInt::fadventureOPtions()
  1258. {
  1259. }
  1260. void CAdvMapInt::fsystemOptions()
  1261. {
  1262. CSystemOptionsWindow * sysopWindow = new CSystemOptionsWindow(genRect(487, 481, 159, 57), LOCPLINT);
  1263. LOCPLINT->pushInt(sysopWindow);
  1264. }
  1265. void CAdvMapInt::fnextHero()
  1266. {
  1267. if(!LOCPLINT->wanderingHeroes.size()) //no wandering heroes
  1268. return;
  1269. int start = heroList.selected;
  1270. int i = start;
  1271. do
  1272. {
  1273. i++;
  1274. if(i >= LOCPLINT->wanderingHeroes.size())
  1275. i = 0;
  1276. } while (LOCPLINT->wanderingHeroes[i]->movement && i!=start);
  1277. heroList.select(i);
  1278. }
  1279. void CAdvMapInt::fendTurn()
  1280. {
  1281. LOCPLINT->makingTurn = false;
  1282. }
  1283. void CAdvMapInt::activate()
  1284. {
  1285. if(active++)
  1286. {
  1287. tlog1 << "Error: advmapint already active...\n";
  1288. active--;
  1289. return;
  1290. }
  1291. screenBuf = screen;
  1292. LOCPLINT->statusbar = &statusbar;
  1293. kingOverview.activate();
  1294. underground.activate();
  1295. questlog.activate();
  1296. sleepWake.activate();
  1297. moveHero.activate();
  1298. spellbook.activate();
  1299. sysOptions.activate();
  1300. advOptions.activate();
  1301. nextHero.activate();
  1302. endTurn.activate();
  1303. minimap.activate();
  1304. heroList.activate();
  1305. townList.activate();
  1306. terrain.activate();
  1307. LOCPLINT->cingconsole->activate();
  1308. }
  1309. void CAdvMapInt::deactivate()
  1310. {
  1311. scrollingDir = 0;
  1312. CGI->curh->changeGraphic(0,0);
  1313. kingOverview.deactivate();
  1314. underground.deactivate();
  1315. questlog.deactivate();
  1316. sleepWake.deactivate();
  1317. moveHero.deactivate();
  1318. spellbook.deactivate();
  1319. advOptions.deactivate();
  1320. sysOptions.deactivate();
  1321. nextHero.deactivate();
  1322. endTurn.deactivate();
  1323. minimap.deactivate();
  1324. heroList.deactivate();
  1325. townList.deactivate();
  1326. terrain.deactivate();
  1327. if(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar)!=LOCPLINT->timeinterested.end())
  1328. LOCPLINT->timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar));
  1329. infoBar.mode=-1;
  1330. LOCPLINT->cingconsole->deactivate();
  1331. if(--active)
  1332. {
  1333. tlog1 << "Error: advmapint still active...\n";
  1334. deactivate();
  1335. }
  1336. }
  1337. void CAdvMapInt::showAll(SDL_Surface *to)
  1338. {
  1339. blitAt(bg,0,0,to);
  1340. kingOverview.show(to);
  1341. underground.show(to);
  1342. questlog.show(to);
  1343. sleepWake.show(to);
  1344. moveHero.show(to);
  1345. spellbook.show(to);
  1346. advOptions.show(to);
  1347. sysOptions.show(to);
  1348. nextHero.show(to);
  1349. endTurn.show(to);
  1350. minimap.draw(to);
  1351. heroList.draw(to);
  1352. townList.draw(to);
  1353. updateScreen = true;
  1354. show(to);
  1355. resdatabar.draw(to);
  1356. statusbar.show(to);
  1357. infoBar.draw(to);
  1358. LOCPLINT->cingconsole->show(to);
  1359. }
  1360. void CAdvMapInt::show(SDL_Surface *to)
  1361. {
  1362. ++animValHitCount; //for animations
  1363. if(animValHitCount == 8)
  1364. {
  1365. CGI->mh->updateWater();
  1366. animValHitCount = 0;
  1367. ++anim;
  1368. updateScreen = true;
  1369. }
  1370. ++heroAnim;
  1371. //if advmap needs updating AND (no dialog is shown OR ctrl is pressed)
  1372. if((animValHitCount % (4/LOCPLINT->mapScrollingSpeed)) == 0
  1373. &&
  1374. (LOCPLINT->topInt() == this)
  1375. || SDL_GetKeyState(NULL)[SDLK_LCTRL]
  1376. || SDL_GetKeyState(NULL)[SDLK_RCTRL]
  1377. )
  1378. {
  1379. if( (scrollingDir & LEFT) && (position.x>-Woff) )
  1380. position.x--;
  1381. if( (scrollingDir & RIGHT) && (position.x < CGI->mh->map->width - terrain.tilesw + Woff) )
  1382. position.x++;
  1383. if( (scrollingDir & UP) && (position.y>-Hoff) )
  1384. position.y--;
  1385. if( (scrollingDir & DOWN) && (position.y < CGI->mh->map->height - terrain.tilesh + Hoff) )
  1386. position.y++;
  1387. if(scrollingDir)
  1388. {
  1389. updateScreen = true;
  1390. updateMinimap=true;
  1391. }
  1392. }
  1393. if(updateScreen)
  1394. {
  1395. terrain.show(to);
  1396. for(int i=0;i<4;i++)
  1397. blitAt(gems[i]->ourImages[LOCPLINT->playerID].bitmap,ADVOPT.gemX[i],ADVOPT.gemY[i],to);
  1398. updateScreen=false;
  1399. LOCPLINT->cingconsole->show(to);
  1400. }
  1401. if (updateMinimap)
  1402. {
  1403. minimap.draw(to);
  1404. updateMinimap=false;
  1405. }
  1406. }
  1407. void CAdvMapInt::selectionChanged()
  1408. {
  1409. const CGTownInstance *to = townList.items[townList.selected];
  1410. select(to);
  1411. }
  1412. void CAdvMapInt::centerOn(int3 on)
  1413. {
  1414. on.x -= (LOCPLINT->adventureInt->terrain.tilesw/2);
  1415. on.y -= (LOCPLINT->adventureInt->terrain.tilesh/2);
  1416. on = LOCPLINT->repairScreenPos(on);
  1417. LOCPLINT->adventureInt->position.x=on.x;
  1418. LOCPLINT->adventureInt->position.y=on.y;
  1419. LOCPLINT->adventureInt->position.z=on.z;
  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. }