CAdvmapInterface.cpp 46 KB

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