CAdvmapInterface.cpp 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645
  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(subInt == heroWindow)
  1305. {
  1306. heroWindow->activate();
  1307. return;
  1308. }
  1309. if(active++)
  1310. {
  1311. tlog1 << "Error: advmapint already active...\n";
  1312. active--;
  1313. return;
  1314. }
  1315. LOCPLINT->curint = this;
  1316. LOCPLINT->statusbar = &statusbar;
  1317. kingOverview.activate();
  1318. underground.activate();
  1319. questlog.activate();
  1320. sleepWake.activate();
  1321. moveHero.activate();
  1322. spellbook.activate();
  1323. sysOptions.activate();
  1324. advOptions.activate();
  1325. nextHero.activate();
  1326. endTurn.activate();
  1327. minimap.activate();
  1328. heroList.activate();
  1329. townList.activate();
  1330. terrain.activate();
  1331. KeyInterested::activate();
  1332. show();
  1333. LOCPLINT->cingconsole->activate();
  1334. }
  1335. void CAdvMapInt::deactivate()
  1336. {
  1337. if(subInt == heroWindow)
  1338. {
  1339. heroWindow->deactivate();
  1340. return;
  1341. }
  1342. KeyInterested::deactivate();
  1343. hide();
  1344. LOCPLINT->cingconsole->deactivate();
  1345. if(--active)
  1346. {
  1347. tlog1 << "Error: advmapint still active...\n";
  1348. deactivate();
  1349. }
  1350. }
  1351. void CAdvMapInt::show(SDL_Surface *to)
  1352. {
  1353. blitAt(bg,0,0);
  1354. kingOverview.show();
  1355. underground.show();
  1356. questlog.show();
  1357. sleepWake.show();
  1358. moveHero.show();
  1359. spellbook.show();
  1360. advOptions.show();
  1361. sysOptions.show();
  1362. nextHero.show();
  1363. endTurn.show();
  1364. minimap.draw();
  1365. heroList.draw();
  1366. townList.draw();
  1367. updateScreen = true;
  1368. update();
  1369. resdatabar.draw();
  1370. statusbar.show();
  1371. infoBar.draw();
  1372. LOCPLINT->cingconsole->show();
  1373. }
  1374. void CAdvMapInt::hide()
  1375. {
  1376. CGI->curh->changeGraphic(0,0);
  1377. kingOverview.deactivate();
  1378. underground.deactivate();
  1379. questlog.deactivate();
  1380. sleepWake.deactivate();
  1381. moveHero.deactivate();
  1382. spellbook.deactivate();
  1383. advOptions.deactivate();
  1384. sysOptions.deactivate();
  1385. nextHero.deactivate();
  1386. endTurn.deactivate();
  1387. minimap.deactivate();
  1388. heroList.deactivate();
  1389. townList.deactivate();
  1390. terrain.deactivate();
  1391. if(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar)!=LOCPLINT->timeinterested.end())
  1392. LOCPLINT->timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar));
  1393. infoBar.mode=-1;
  1394. }
  1395. void CAdvMapInt::update()
  1396. {
  1397. ++animValHitCount; //for animations
  1398. if(animValHitCount == 8)
  1399. {
  1400. CGI->mh->updateWater();
  1401. animValHitCount = 0;
  1402. ++anim;
  1403. updateScreen = true;
  1404. }
  1405. ++heroAnim;
  1406. //if advmap needs updating AND (no dialog is shown OR ctrl is pressed)
  1407. if((animValHitCount % (4/LOCPLINT->mapScrollingSpeed)) == 0
  1408. &&
  1409. (!LOCPLINT->showingDialog->get()
  1410. && !LOCPLINT->curint->subInt)
  1411. || SDL_GetKeyState(NULL)[SDLK_LCTRL]
  1412. || SDL_GetKeyState(NULL)[SDLK_RCTRL]
  1413. )
  1414. {
  1415. if( (scrollingDir & LEFT) && (position.x>-Woff) )
  1416. position.x--;
  1417. if( (scrollingDir & RIGHT) && (position.x < CGI->mh->map->width - terrain.tilesw + Woff) )
  1418. position.x++;
  1419. if( (scrollingDir & UP) && (position.y>-Hoff) )
  1420. position.y--;
  1421. if( (scrollingDir & DOWN) && (position.y < CGI->mh->map->height - terrain.tilesh + Hoff) )
  1422. position.y++;
  1423. if(scrollingDir)
  1424. {
  1425. updateScreen = true;
  1426. updateMinimap=true;
  1427. }
  1428. }
  1429. if(updateScreen)
  1430. {
  1431. terrain.show();
  1432. for(int i=0;i<4;i++)
  1433. blitAt(gems[i]->ourImages[LOCPLINT->playerID].bitmap,ADVOPT.gemX[i],ADVOPT.gemY[i]);
  1434. updateScreen=false;
  1435. LOCPLINT->cingconsole->show();
  1436. }
  1437. if (updateMinimap)
  1438. {
  1439. minimap.draw();
  1440. updateMinimap=false;
  1441. }
  1442. }
  1443. void CAdvMapInt::selectionChanged()
  1444. {
  1445. const CGTownInstance *to = townList.items[townList.selected];
  1446. select(to);
  1447. }
  1448. void CAdvMapInt::centerOn(int3 on)
  1449. {
  1450. on.x -= (LOCPLINT->adventureInt->terrain.tilesw/2);
  1451. on.y -= (LOCPLINT->adventureInt->terrain.tilesh/2);
  1452. on = LOCPLINT->repairScreenPos(on);
  1453. LOCPLINT->adventureInt->position.x=on.x;
  1454. LOCPLINT->adventureInt->position.y=on.y;
  1455. LOCPLINT->adventureInt->position.z=on.z;
  1456. LOCPLINT->adventureInt->updateScreen=true;
  1457. updateMinimap=true;
  1458. }
  1459. void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
  1460. {
  1461. ui8 Dir;
  1462. switch(key.keysym.sym)
  1463. {
  1464. case SDLK_UP:
  1465. Dir = UP;
  1466. break;
  1467. case SDLK_LEFT:
  1468. Dir = LEFT;
  1469. break;
  1470. case SDLK_RIGHT:
  1471. Dir = RIGHT;
  1472. break;
  1473. case SDLK_DOWN:
  1474. Dir = DOWN;
  1475. break;
  1476. case SDLK_SPACE: //space - try to revisit current object with selected hero
  1477. {
  1478. const CGHeroInstance *h = dynamic_cast<const CGHeroInstance*>(selection);
  1479. if(h && key.state == SDL_PRESSED)
  1480. {
  1481. LOCPLINT->pim->unlock();
  1482. LOCPLINT->cb->moveHero(h,h->pos);
  1483. LOCPLINT->pim->lock();
  1484. }
  1485. }
  1486. return;
  1487. default:
  1488. return;
  1489. }
  1490. if(key.state == SDL_PRESSED //arrow is pressed
  1491. && (SDL_GetKeyState(NULL)[SDLK_LCTRL]
  1492. || SDL_GetKeyState(NULL)[SDLK_RCTRL])
  1493. )
  1494. scrollingDir |= Dir;
  1495. else
  1496. scrollingDir &= ~Dir;
  1497. }
  1498. void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * client)
  1499. {
  1500. if (down)
  1501. {
  1502. boost::algorithm::erase_all(text,"\"");
  1503. CSimpleWindow * temp = CMessage::genWindow(text,LOCPLINT->playerID);
  1504. temp->pos.x=screen->w/2-(temp->pos.w/2);
  1505. temp->pos.y=screen->h/2-(temp->pos.h/2);
  1506. temp->owner = client;
  1507. LOCPLINT->objsToBlit.push_back(temp);
  1508. }
  1509. else
  1510. {
  1511. for (size_t i=0; i < LOCPLINT->objsToBlit.size(); ++i)
  1512. {
  1513. //TODO: pewnie da sie to zrobic lepiej, ale nie chce mi sie. Wolajacy obiekt powinien informowac kogo spodziewa sie odwolac (null jesli down)
  1514. CSimpleWindow * pom = dynamic_cast<CSimpleWindow*>(LOCPLINT->objsToBlit[i]);
  1515. if (!pom)
  1516. continue;
  1517. if (pom->owner==client)
  1518. {
  1519. LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+(i));
  1520. delete pom;
  1521. if((LOCPLINT->curint == LOCPLINT->castleInt) && !LOCPLINT->castleInt->subInt)
  1522. LOCPLINT->castleInt->showAll(0,true);
  1523. }
  1524. }
  1525. }
  1526. }
  1527. int3 CAdvMapInt::verifyPos(int3 ver)
  1528. {
  1529. if (ver.x<0)
  1530. ver.x=0;
  1531. if (ver.y<0)
  1532. ver.y=0;
  1533. if (ver.z<0)
  1534. ver.z=0;
  1535. if (ver.x>=CGI->mh->sizes.x)
  1536. ver.x=CGI->mh->sizes.x-1;
  1537. if (ver.y>=CGI->mh->sizes.y)
  1538. ver.y=CGI->mh->sizes.y-1;
  1539. if (ver.z>=CGI->mh->sizes.z)
  1540. ver.z=CGI->mh->sizes.z-1;
  1541. return ver;
  1542. }
  1543. void CAdvMapInt::select(const CArmedInstance *sel )
  1544. {
  1545. LOCPLINT->cb->setSelection(sel);
  1546. centerOn(sel->pos);
  1547. selection = sel;
  1548. if(sel->ID==TOWNI_TYPE)
  1549. {
  1550. int pos = vstd::findPos(townList.items,sel);
  1551. townList.selected = pos;
  1552. terrain.currentPath = NULL;
  1553. }
  1554. else
  1555. {
  1556. int pos = heroList.getPosOfHero(sel);
  1557. heroList.selected = pos;
  1558. terrain.currentPath = heroList.items[pos].second;
  1559. }
  1560. townList.draw();
  1561. heroList.draw();
  1562. infoBar.draw(NULL);
  1563. }