CAdvmapInterface.cpp 45 KB

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