CAdvmapInterface.cpp 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682
  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.front();
  485. switch(obj->ID)
  486. {
  487. case HEROI_TYPE:
  488. {
  489. if(!vstd::contains(graphics->heroWins,obj->subID) || obj->tempOwner != LOCPLINT->playerID)
  490. {
  491. InfoAboutHero iah;
  492. if(LOCPLINT->cb->getHeroInfo(obj, iah))
  493. {
  494. SDL_Surface *iwin = graphics->drawHeroInfoWin(iah);
  495. CInfoPopup * ip = new CInfoPopup(iwin, LOCPLINT->current->motion.x-iwin->w,
  496. LOCPLINT->current->motion.y-iwin->h, true);
  497. LOCPLINT->pushInt(ip);
  498. }
  499. else
  500. {
  501. tlog3 << "Warning - no infowin for hero " << obj->id << std::endl;
  502. }
  503. }
  504. else
  505. {
  506. CInfoPopup * ip = new CInfoPopup(graphics->heroWins[obj->subID],
  507. LOCPLINT->current->motion.x-graphics->heroWins[obj->subID]->w,
  508. LOCPLINT->current->motion.y-graphics->heroWins[obj->subID]->h,false
  509. );
  510. LOCPLINT->pushInt(ip);
  511. }
  512. break;
  513. }
  514. case TOWNI_TYPE:
  515. {
  516. if(!vstd::contains(graphics->townWins,obj->id) || obj->tempOwner != LOCPLINT->playerID)
  517. {
  518. InfoAboutTown iah;
  519. if(LOCPLINT->cb->getTownInfo(obj, iah))
  520. {
  521. SDL_Surface *iwin = graphics->drawTownInfoWin(iah);
  522. CInfoPopup * ip = new CInfoPopup(iwin, LOCPLINT->current->motion.x-iwin->w,
  523. LOCPLINT->current->motion.y-iwin->h, true);
  524. LOCPLINT->pushInt(ip);
  525. }
  526. else
  527. {
  528. tlog3 << "Warning - no infowin for town " << obj->id << std::endl;
  529. }
  530. }
  531. else
  532. {
  533. CInfoPopup * ip = new CInfoPopup(graphics->townWins[obj->id],
  534. LOCPLINT->current->motion.x-graphics->townWins[obj->id]->w,
  535. LOCPLINT->current->motion.y-graphics->townWins[obj->id]->h,false
  536. );
  537. LOCPLINT->pushInt(ip);
  538. }
  539. break;
  540. }
  541. default:
  542. {
  543. LOCPLINT->adventureInt->handleRightClick(obj->getHoverText(),down,this);
  544. break;
  545. }
  546. }
  547. }
  548. void CTerrainRect::mouseMoved (const SDL_MouseMotionEvent & sEvent)
  549. {
  550. int3 pom=LOCPLINT->adventureInt->verifyPos(whichTileIsIt(sEvent.x,sEvent.y));
  551. if (pom!=curHoveredTile)
  552. curHoveredTile=pom;
  553. else
  554. return;
  555. std::vector<std::string> temp = LOCPLINT->cb->getObjDescriptions(pom);
  556. if (temp.size())
  557. {
  558. boost::replace_all(temp.back(),"\n"," ");
  559. LOCPLINT->adventureInt->statusbar.print(temp.back());
  560. }
  561. else
  562. {
  563. LOCPLINT->adventureInt->statusbar.clear();
  564. }
  565. std::vector<const CGObjectInstance *> objs = LOCPLINT->cb->getVisitableObjs(pom);
  566. for(int i=0; i<objs.size();i++)
  567. {
  568. if(objs[i]->ID == TOWNI_TYPE) //town
  569. {
  570. CGI->curh->changeGraphic(0,0);
  571. return;
  572. }
  573. }
  574. objs = LOCPLINT->cb->getBlockingObjs(pom);
  575. for(size_t i=0; i < objs.size(); ++i)
  576. {
  577. if(objs[i]->ID == TOWNI_TYPE && objs[i]->tempOwner == LOCPLINT->playerID) //town
  578. {
  579. CGI->curh->changeGraphic(0,3);
  580. return;
  581. }
  582. else if(objs[i]->ID == HEROI_TYPE //mouse over hero
  583. && (objs[i]==LOCPLINT->adventureInt->selection || LOCPLINT->adventureInt->selection->ID==TOWNI_TYPE)
  584. && objs[i]->tempOwner == LOCPLINT->playerID) //this hero is selected or we've selected a town
  585. {
  586. CGI->curh->changeGraphic(0,2);
  587. return;
  588. }
  589. }
  590. CGI->curh->changeGraphic(0,0);
  591. }
  592. void CTerrainRect::hover(bool on)
  593. {
  594. if (!on)
  595. {
  596. LOCPLINT->adventureInt->statusbar.clear();
  597. CGI->curh->changeGraphic(0,0);
  598. }
  599. Hoverable::hover(on);
  600. }
  601. void CTerrainRect::showPath(const SDL_Rect * extRect)
  602. {
  603. for (size_t i=0; i < currentPath->nodes.size()-1; ++i)
  604. {
  605. int pn=-1;//number of picture
  606. if (i==0) //last tile
  607. {
  608. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+CGI->mh->offsetX + pos.x,
  609. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+CGI->mh->offsetY + pos.y;
  610. if (x<0 || y<0 || x>pos.w || y>pos.h)
  611. continue;
  612. pn=0;
  613. }
  614. else
  615. {
  616. /*
  617. * notation of arrow direction:
  618. * 1 2 3
  619. * 4 5 6
  620. * 7 8 9
  621. * ie. 157 means an arrow from left upper tile to left bottom tile through 5 (all arrows go through 5 in this notation)
  622. */
  623. std::vector<CPathNode> & cv = currentPath->nodes;
  624. if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1) //15x
  625. {
  626. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //156
  627. {
  628. pn = 3;
  629. }
  630. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //159
  631. {
  632. pn = 12;
  633. }
  634. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //158
  635. {
  636. pn = 21;
  637. }
  638. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //157
  639. {
  640. pn = 22;
  641. }
  642. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //153
  643. {
  644. pn = 2;
  645. }
  646. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //154
  647. {
  648. pn = 23;
  649. }
  650. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //152
  651. {
  652. pn = 1;
  653. }
  654. }
  655. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1) //25x
  656. {
  657. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //253
  658. {
  659. pn = 2;
  660. }
  661. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //256
  662. {
  663. pn = 3;
  664. }
  665. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //259
  666. {
  667. pn = 4;
  668. }
  669. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //258
  670. {
  671. pn = 13;
  672. }
  673. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //257
  674. {
  675. pn = 22;
  676. }
  677. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //254
  678. {
  679. pn = 23;
  680. }
  681. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //251
  682. {
  683. pn = 24;
  684. }
  685. }
  686. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1) //35x
  687. {
  688. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //358
  689. {
  690. pn = 5;
  691. }
  692. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //357
  693. {
  694. pn = 14;
  695. }
  696. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //354
  697. {
  698. pn = 23;
  699. }
  700. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //351
  701. {
  702. pn = 24;
  703. }
  704. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //359
  705. {
  706. pn = 4;
  707. }
  708. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //356
  709. {
  710. pn = 3;
  711. }
  712. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //352
  713. {
  714. pn = 17;
  715. }
  716. }
  717. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y) //65x
  718. {
  719. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //657
  720. {
  721. pn = 6;
  722. }
  723. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //654
  724. {
  725. pn = 15;
  726. }
  727. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //651
  728. {
  729. pn = 24;
  730. }
  731. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //652
  732. {
  733. pn = 17;
  734. }
  735. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //658
  736. {
  737. pn = 5;
  738. }
  739. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //653
  740. {
  741. pn = 18;
  742. }
  743. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //659
  744. {
  745. pn = 4;
  746. }
  747. }
  748. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1) //95x
  749. {
  750. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //954
  751. {
  752. pn = 7;
  753. }
  754. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //951
  755. {
  756. pn = 16;
  757. }
  758. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //952
  759. {
  760. pn = 17;
  761. }
  762. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //957
  763. {
  764. pn = 6;
  765. }
  766. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //953
  767. {
  768. pn = 18;
  769. }
  770. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //956
  771. {
  772. pn = 19;
  773. }
  774. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //958
  775. {
  776. pn = 5;
  777. }
  778. }
  779. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1) //85x
  780. {
  781. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //857
  782. {
  783. pn = 6;
  784. }
  785. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //854
  786. {
  787. pn = 7;
  788. }
  789. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //851
  790. {
  791. pn = 8;
  792. }
  793. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //852
  794. {
  795. pn = 9;
  796. }
  797. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //853
  798. {
  799. pn = 18;
  800. }
  801. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //856
  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) //859
  806. {
  807. pn = 20;
  808. }
  809. }
  810. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1) //75x
  811. {
  812. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //752
  813. {
  814. pn = 1;
  815. }
  816. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //753
  817. {
  818. pn = 10;
  819. }
  820. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //756
  821. {
  822. pn = 19;
  823. }
  824. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //751
  825. {
  826. pn = 8;
  827. }
  828. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //759
  829. {
  830. pn = 20;
  831. }
  832. }
  833. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y) //45x
  834. {
  835. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //453
  836. {
  837. pn = 2;
  838. }
  839. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //456
  840. {
  841. pn = 11;
  842. }
  843. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //459
  844. {
  845. pn = 20;
  846. }
  847. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //452
  848. {
  849. pn = 1;
  850. }
  851. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //456
  852. {
  853. pn = 21;
  854. }
  855. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //451
  856. {
  857. pn = 8;
  858. }
  859. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //457
  860. {
  861. pn = 22;
  862. }
  863. }
  864. }
  865. if ( ((currentPath->nodes[i].dist)-(*(currentPath->nodes.end()-1)).dist) > (static_cast<const CGHeroInstance*>(LOCPLINT->adventureInt->selection))->movement)
  866. pn+=25;
  867. if (pn>=0)
  868. {
  869. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+CGI->mh->offsetX + pos.x,
  870. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+CGI->mh->offsetY + pos.y;
  871. if (x<0 || y<0 || x>pos.w || y>pos.h)
  872. continue;
  873. int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
  874. hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
  875. SDL_Rect prevClip;
  876. SDL_GetClipRect(screen, &prevClip);
  877. SDL_SetClipRect(screen, extRect); //preventing blitting outside of that rect
  878. if(ADVOPT.smoothMove) //version for smooth hero move, with pos shifts
  879. {
  880. if (hvx<0 && hvy<0)
  881. {
  882. CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, screen, &genRect(32, 32, x + moveX, y + moveY));
  883. }
  884. else if(hvx<0)
  885. {
  886. CSDL_Ext::blit8bppAlphaTo24bpp
  887. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0),
  888. screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x + moveX, y + moveY));
  889. }
  890. else if (hvy<0)
  891. {
  892. CSDL_Ext::blit8bppAlphaTo24bpp
  893. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0),
  894. screen, &genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY));
  895. }
  896. else
  897. {
  898. CSDL_Ext::blit8bppAlphaTo24bpp
  899. (arrows->ourImages[pn].bitmap, &genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx, 0, 0),
  900. screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY));
  901. }
  902. }
  903. else //standard version
  904. {
  905. if (hvx<0 && hvy<0)
  906. {
  907. CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, screen, &genRect(32, 32, x, y));
  908. }
  909. else if(hvx<0)
  910. {
  911. CSDL_Ext::blit8bppAlphaTo24bpp
  912. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0),
  913. screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x, y));
  914. }
  915. else if (hvy<0)
  916. {
  917. CSDL_Ext::blit8bppAlphaTo24bpp
  918. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0),
  919. screen, &genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x, y));
  920. }
  921. else
  922. {
  923. CSDL_Ext::blit8bppAlphaTo24bpp
  924. (arrows->ourImages[pn].bitmap, &genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx, 0, 0),
  925. screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x, y));
  926. }
  927. }
  928. SDL_SetClipRect(screen, &prevClip);
  929. }
  930. } //for (int i=0;i<currentPath->nodes.size()-1;i++)
  931. }
  932. void CTerrainRect::show(SDL_Surface * to)
  933. {
  934. if(ADVOPT.smoothMove)
  935. CGI->mh->terrainRect
  936. (LOCPLINT->adventureInt->position, LOCPLINT->adventureInt->anim,
  937. &LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim,
  938. to, &pos, moveX, moveY);
  939. else
  940. CGI->mh->terrainRect
  941. (LOCPLINT->adventureInt->position, LOCPLINT->adventureInt->anim,
  942. &LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim,
  943. to, &pos, 0, 0);
  944. //SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));
  945. //SDL_FreeSurface(teren);
  946. if (currentPath && LOCPLINT->adventureInt->position.z==currentPath->startPos().z) //drawing path
  947. {
  948. showPath(&pos);
  949. }
  950. }
  951. int3 CTerrainRect::whichTileIsIt(const int & x, const int & y)
  952. {
  953. int3 ret;
  954. ret.x = LOCPLINT->adventureInt->position.x + ((LOCPLINT->current->motion.x-CGI->mh->offsetX-pos.x)/32);
  955. ret.y = LOCPLINT->adventureInt->position.y + ((LOCPLINT->current->motion.y-CGI->mh->offsetY-pos.y)/32);
  956. ret.z = LOCPLINT->adventureInt->position.z;
  957. return ret;
  958. }
  959. int3 CTerrainRect::whichTileIsIt()
  960. {
  961. return whichTileIsIt(LOCPLINT->current->motion.x,LOCPLINT->current->motion.y);
  962. }
  963. void CResDataBar::clickRight (tribool down)
  964. {
  965. }
  966. void CResDataBar::activate()
  967. {
  968. ClickableR::activate();
  969. }
  970. void CResDataBar::deactivate()
  971. {
  972. ClickableR::deactivate();
  973. }
  974. CResDataBar::CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist)
  975. {
  976. bg = BitmapHandler::loadBitmap(defname);
  977. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  978. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  979. pos = genRect(bg->h,bg->w,x,y);
  980. txtpos.resize(8);
  981. for (int i = 0; i < 8 ; i++)
  982. {
  983. txtpos[i].first = pos.x + offx + resdist*i;
  984. txtpos[i].second = pos.y + offy;
  985. }
  986. txtpos[7].first = txtpos[6].first + datedist;
  987. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63]
  988. + ": %s, " + CGI->generaltexth->allTexts[64] + ": %s";
  989. }
  990. CResDataBar::CResDataBar()
  991. {
  992. bg = BitmapHandler::loadBitmap(ADVOPT.resdatabarG);
  993. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  994. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  995. pos = genRect(bg->h,bg->w,ADVOPT.resdatabarX,ADVOPT.resdatabarY);
  996. txtpos.resize(8);
  997. for (int i = 0; i < 8 ; i++)
  998. {
  999. txtpos[i].first = pos.x + ADVOPT.resOffsetX + ADVOPT.resDist*i;
  1000. txtpos[i].second = pos.y + ADVOPT.resOffsetY;
  1001. }
  1002. txtpos[7].first = txtpos[6].first + ADVOPT.resDateDist;
  1003. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63]
  1004. + ": %s, " + CGI->generaltexth->allTexts[64] + ": %s";
  1005. }
  1006. CResDataBar::~CResDataBar()
  1007. {
  1008. SDL_FreeSurface(bg);
  1009. }
  1010. void CResDataBar::draw(SDL_Surface * to)
  1011. {
  1012. blitAt(bg,pos.x,pos.y,to);
  1013. char * buf = new char[15];
  1014. for (int i=0;i<7;i++)
  1015. {
  1016. SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
  1017. printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly,to);
  1018. }
  1019. std::vector<std::string> temp;
  1020. SDL_itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf);
  1021. SDL_itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf);
  1022. SDL_itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf);
  1023. printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,GEOR13,zwykly,to);
  1024. temp.clear();
  1025. //updateRect(&pos,screen);
  1026. delete[] buf;
  1027. }
  1028. CInfoBar::CInfoBar()
  1029. {
  1030. toNextTick = mode = pom = -1;
  1031. pos.x=ADVOPT.infoboxX;
  1032. pos.y=ADVOPT.infoboxY;
  1033. pos.w=194;
  1034. pos.h=186;
  1035. day = CDefHandler::giveDef("NEWDAY.DEF");
  1036. week1 = CDefHandler::giveDef("NEWWEEK1.DEF");
  1037. week2 = CDefHandler::giveDef("NEWWEEK2.DEF");
  1038. week3 = CDefHandler::giveDef("NEWWEEK3.DEF");
  1039. week4 = CDefHandler::giveDef("NEWWEEK4.DEF");
  1040. }
  1041. CInfoBar::~CInfoBar()
  1042. {
  1043. delete day;
  1044. delete week1;
  1045. delete week2;
  1046. delete week3;
  1047. delete week4;
  1048. }
  1049. void CInfoBar::draw(SDL_Surface * to, const CGObjectInstance * specific)
  1050. {
  1051. if ((mode>=0) && mode<5)
  1052. {
  1053. blitAnim(mode);
  1054. return;
  1055. }
  1056. else if (mode==5)
  1057. {
  1058. mode = -1;
  1059. draw(to,LOCPLINT->adventureInt->selection);
  1060. }
  1061. if (!specific)
  1062. specific = LOCPLINT->adventureInt->selection;
  1063. if(!specific)
  1064. return;
  1065. if(specific->ID == HEROI_TYPE) //hero
  1066. {
  1067. if(graphics->heroWins.find(specific->subID)!=graphics->heroWins.end())
  1068. blitAt(graphics->heroWins[specific->subID],pos.x,pos.y,to);
  1069. }
  1070. else if (specific->ID == TOWNI_TYPE)
  1071. {
  1072. const CGTownInstance * t = static_cast<const CGTownInstance*>(specific);
  1073. if(graphics->townWins.find(t->id)!=graphics->townWins.end())
  1074. blitAt(graphics->townWins[t->id],pos.x,pos.y,to);
  1075. }
  1076. }
  1077. CDefHandler * CInfoBar::getAnim(int mode)
  1078. {
  1079. switch(mode)
  1080. {
  1081. case 0:
  1082. return day;
  1083. break;
  1084. case 1:
  1085. return week1;
  1086. break;
  1087. case 2:
  1088. return week2;
  1089. break;
  1090. case 3:
  1091. return week3;
  1092. break;
  1093. case 4:
  1094. return week4;
  1095. break;
  1096. default:
  1097. return NULL;
  1098. break;
  1099. }
  1100. }
  1101. void CInfoBar::blitAnim(int mode)//0 - day, 1 - week
  1102. {
  1103. CDefHandler * anim = NULL;
  1104. std::ostringstream txt;
  1105. anim = getAnim(mode);
  1106. if(mode) //new week animation
  1107. {
  1108. txt << CGI->generaltexth->allTexts[63] << " " << LOCPLINT->cb->getDate(2);
  1109. }
  1110. else //new day
  1111. {
  1112. txt << CGI->generaltexth->allTexts[64] << " " << LOCPLINT->cb->getDate(1);
  1113. }
  1114. blitAt(anim->ourImages[pom].bitmap,pos.x+9,pos.y+10);
  1115. printAtMiddle(txt.str(),pos.x+95,pos.y+31,TNRB16,zwykly);
  1116. if (pom == anim->ourImages.size()-1)
  1117. toNextTick+=750;
  1118. }
  1119. void CInfoBar::newDay(int Day)
  1120. {
  1121. if(LOCPLINT->cb->getDate(1) != 1)
  1122. {
  1123. mode = 0; //showing day
  1124. }
  1125. else
  1126. {
  1127. switch(LOCPLINT->cb->getDate(2))
  1128. {
  1129. case 1:
  1130. mode = 1;
  1131. break;
  1132. case 2:
  1133. mode = 2;
  1134. break;
  1135. case 3:
  1136. mode = 3;
  1137. break;
  1138. case 4:
  1139. mode = 4;
  1140. break;
  1141. default:
  1142. mode = -1;
  1143. break;
  1144. }
  1145. }
  1146. pom = 0;
  1147. TimeInterested::activate();
  1148. toNextTick = 500;
  1149. blitAnim(mode);
  1150. //blitAt(day->ourImages[pom].bitmap,pos.x+10,pos.y+10);
  1151. }
  1152. void CInfoBar::showComp(SComponent * comp, int time)
  1153. {
  1154. SDL_Surface * b = BitmapHandler::loadBitmap("ADSTATOT.bmp");
  1155. blitAt(b,pos.x+8,pos.y+11);
  1156. blitAt(comp->getImg(),pos.x+52,pos.y+54);
  1157. printAtMiddle(comp->subtitle,pos.x+91,pos.y+158,GEOR13,zwykly);
  1158. printAtMiddleWB(comp->description,pos.x+94,pos.y+31,GEOR13,26,zwykly);
  1159. SDL_FreeSurface(b);
  1160. TimeInterested::activate();
  1161. mode = 6;
  1162. toNextTick = time;
  1163. }
  1164. void CInfoBar::tick()
  1165. {
  1166. if((mode >= 0) && (mode < 5))
  1167. {
  1168. pom++;
  1169. if (pom >= getAnim(mode)->ourImages.size())
  1170. {
  1171. TimeInterested::deactivate();
  1172. toNextTick = -1;
  1173. mode = 5;
  1174. draw(screen2);
  1175. return;
  1176. }
  1177. toNextTick = 150;
  1178. blitAnim(mode);
  1179. }
  1180. else if (mode == 6)
  1181. {
  1182. TimeInterested::deactivate();
  1183. toNextTick = -1;
  1184. mode = 5;
  1185. draw(screen2);
  1186. }
  1187. }
  1188. CAdvMapInt::CAdvMapInt(int Player)
  1189. :player(Player),
  1190. statusbar(ADVOPT.statusbarX,ADVOPT.statusbarY,ADVOPT.statusbarG),
  1191. kingOverview(CGI->generaltexth->zelp[293].first,CGI->generaltexth->zelp[293].second,
  1192. boost::bind(&CAdvMapInt::fshowOverview,this),&ADVOPT.kingOverview, SDLK_k),
  1193. underground(CGI->generaltexth->zelp[294].first,CGI->generaltexth->zelp[294].second,
  1194. boost::bind(&CAdvMapInt::fswitchLevel,this),&ADVOPT.underground, SDLK_u),
  1195. questlog(CGI->generaltexth->zelp[295].first,CGI->generaltexth->zelp[295].second,
  1196. boost::bind(&CAdvMapInt::fshowQuestlog,this),&ADVOPT.questlog, SDLK_q),
  1197. sleepWake(CGI->generaltexth->zelp[296].first,CGI->generaltexth->zelp[296].second,
  1198. boost::bind(&CAdvMapInt::fsleepWake,this), &ADVOPT.sleepWake, SDLK_w),
  1199. moveHero(CGI->generaltexth->zelp[297].first,CGI->generaltexth->zelp[297].second,
  1200. boost::bind(&CAdvMapInt::fmoveHero,this), &ADVOPT.moveHero, SDLK_m),
  1201. spellbook(CGI->generaltexth->zelp[298].first,CGI->generaltexth->zelp[298].second,
  1202. boost::bind(&CAdvMapInt::fshowSpellbok,this), &ADVOPT.spellbook, SDLK_c),
  1203. advOptions(CGI->generaltexth->zelp[299].first,CGI->generaltexth->zelp[299].second,
  1204. boost::bind(&CAdvMapInt::fadventureOPtions,this), &ADVOPT.advOptions, SDLK_a),
  1205. sysOptions(CGI->generaltexth->zelp[300].first,CGI->generaltexth->zelp[300].second,
  1206. boost::bind(&CAdvMapInt::fsystemOptions,this), &ADVOPT.sysOptions, SDLK_o),
  1207. nextHero(CGI->generaltexth->zelp[301].first,CGI->generaltexth->zelp[301].second,
  1208. boost::bind(&CAdvMapInt::fnextHero,this), &ADVOPT.nextHero, SDLK_h),
  1209. endTurn(CGI->generaltexth->zelp[302].first,CGI->generaltexth->zelp[302].second,
  1210. boost::bind(&CAdvMapInt::fendTurn,this), &ADVOPT.endTurn, SDLK_e),
  1211. heroList(ADVOPT.hlistSize),
  1212. townList(ADVOPT.tlistSize,ADVOPT.tlistX,ADVOPT.tlistY,ADVOPT.tlistAU,ADVOPT.tlistAD)//(5,&genRect(192,48,747,196),747,196,747,372),
  1213. {
  1214. active = 0;
  1215. subInt = NULL;
  1216. selection = NULL;
  1217. townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this);
  1218. LOCPLINT->adventureInt=this;
  1219. bg = BitmapHandler::loadBitmap(ADVOPT.mainGraphic);
  1220. graphics->blueToPlayersAdv(bg,player);
  1221. scrollingDir = 0;
  1222. updateScreen = false;
  1223. anim=0;
  1224. animValHitCount=0; //animation frame
  1225. heroAnim=0;
  1226. heroAnimValHitCount=0; // hero animation frame
  1227. heroList.init();
  1228. heroList.genList();
  1229. //townList.init();
  1230. townList.genList();
  1231. heroWindow = new CHeroWindow(this->player);
  1232. gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[0]));
  1233. gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[1]));
  1234. gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[2]));
  1235. gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[3]));
  1236. }
  1237. CAdvMapInt::~CAdvMapInt()
  1238. {
  1239. SDL_FreeSurface(bg);
  1240. delete heroWindow;
  1241. for(int i=0; i<gems.size(); i++)
  1242. delete gems[i];
  1243. }
  1244. void CAdvMapInt::fshowOverview()
  1245. {
  1246. }
  1247. void CAdvMapInt::fswitchLevel()
  1248. {
  1249. if(!CGI->mh->map->twoLevel)
  1250. return;
  1251. if (position.z)
  1252. {
  1253. position.z--;
  1254. underground.curimg=0;
  1255. underground.show(screenBuf);
  1256. }
  1257. else
  1258. {
  1259. underground.curimg=1;
  1260. position.z++;
  1261. underground.show(screenBuf);
  1262. }
  1263. updateScreen = true;
  1264. minimap.draw(screenBuf);
  1265. }
  1266. void CAdvMapInt::fshowQuestlog()
  1267. {
  1268. }
  1269. void CAdvMapInt::fsleepWake()
  1270. {
  1271. }
  1272. void CAdvMapInt::fmoveHero()
  1273. {
  1274. if (selection->ID!=HEROI_TYPE)
  1275. return;
  1276. if (!terrain.currentPath)
  1277. return;
  1278. LOCPLINT->pim->unlock();
  1279. LOCPLINT->moveHero(static_cast<const CGHeroInstance*>(LOCPLINT->adventureInt->selection),*terrain.currentPath);
  1280. LOCPLINT->pim->lock();
  1281. }
  1282. void CAdvMapInt::fshowSpellbok()
  1283. {
  1284. if (selection->ID!=HEROI_TYPE) //checking necessary values
  1285. return;
  1286. 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);
  1287. LOCPLINT->pushInt(spellWindow);
  1288. }
  1289. void CAdvMapInt::fadventureOPtions()
  1290. {
  1291. }
  1292. void CAdvMapInt::fsystemOptions()
  1293. {
  1294. CSystemOptionsWindow * sysopWindow = new CSystemOptionsWindow(genRect(487, 481, 159, 57), LOCPLINT);
  1295. LOCPLINT->pushInt(sysopWindow);
  1296. }
  1297. void CAdvMapInt::fnextHero()
  1298. {
  1299. if(!LOCPLINT->wanderingHeroes.size()) //no wandering heroes
  1300. return;
  1301. int start = heroList.selected;
  1302. int i = start;
  1303. do
  1304. {
  1305. i++;
  1306. if(i >= LOCPLINT->wanderingHeroes.size())
  1307. i = 0;
  1308. } while (LOCPLINT->wanderingHeroes[i]->movement && i!=start);
  1309. heroList.select(i);
  1310. }
  1311. void CAdvMapInt::fendTurn()
  1312. {
  1313. LOCPLINT->makingTurn = false;
  1314. }
  1315. void CAdvMapInt::activate()
  1316. {
  1317. if(active++)
  1318. {
  1319. tlog1 << "Error: advmapint already active...\n";
  1320. active--;
  1321. return;
  1322. }
  1323. screenBuf = screen;
  1324. LOCPLINT->statusbar = &statusbar;
  1325. kingOverview.activate();
  1326. underground.activate();
  1327. questlog.activate();
  1328. sleepWake.activate();
  1329. moveHero.activate();
  1330. spellbook.activate();
  1331. sysOptions.activate();
  1332. advOptions.activate();
  1333. nextHero.activate();
  1334. endTurn.activate();
  1335. minimap.activate();
  1336. heroList.activate();
  1337. townList.activate();
  1338. terrain.activate();
  1339. LOCPLINT->cingconsole->activate();
  1340. }
  1341. void CAdvMapInt::deactivate()
  1342. {
  1343. scrollingDir = 0;
  1344. CGI->curh->changeGraphic(0,0);
  1345. kingOverview.deactivate();
  1346. underground.deactivate();
  1347. questlog.deactivate();
  1348. sleepWake.deactivate();
  1349. moveHero.deactivate();
  1350. spellbook.deactivate();
  1351. advOptions.deactivate();
  1352. sysOptions.deactivate();
  1353. nextHero.deactivate();
  1354. endTurn.deactivate();
  1355. minimap.deactivate();
  1356. heroList.deactivate();
  1357. townList.deactivate();
  1358. terrain.deactivate();
  1359. if(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar)!=LOCPLINT->timeinterested.end())
  1360. LOCPLINT->timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar));
  1361. infoBar.mode=-1;
  1362. LOCPLINT->cingconsole->deactivate();
  1363. if(--active)
  1364. {
  1365. tlog1 << "Error: advmapint still active...\n";
  1366. deactivate();
  1367. }
  1368. }
  1369. void CAdvMapInt::showAll(SDL_Surface *to)
  1370. {
  1371. blitAt(bg,0,0,to);
  1372. kingOverview.show(to);
  1373. underground.show(to);
  1374. questlog.show(to);
  1375. sleepWake.show(to);
  1376. moveHero.show(to);
  1377. spellbook.show(to);
  1378. advOptions.show(to);
  1379. sysOptions.show(to);
  1380. nextHero.show(to);
  1381. endTurn.show(to);
  1382. minimap.draw(to);
  1383. heroList.draw(to);
  1384. townList.draw(to);
  1385. updateScreen = true;
  1386. show(to);
  1387. resdatabar.draw(to);
  1388. statusbar.show(to);
  1389. infoBar.draw(to);
  1390. LOCPLINT->cingconsole->show(to);
  1391. }
  1392. void CAdvMapInt::show(SDL_Surface *to)
  1393. {
  1394. ++animValHitCount; //for animations
  1395. if(animValHitCount == 8)
  1396. {
  1397. CGI->mh->updateWater();
  1398. animValHitCount = 0;
  1399. ++anim;
  1400. updateScreen = true;
  1401. }
  1402. ++heroAnim;
  1403. //if advmap needs updating AND (no dialog is shown OR ctrl is pressed)
  1404. if((animValHitCount % (4/LOCPLINT->sysOpts.mapScrollingSpeed)) == 0
  1405. &&
  1406. (LOCPLINT->topInt() == this)
  1407. || SDL_GetKeyState(NULL)[SDLK_LCTRL]
  1408. || SDL_GetKeyState(NULL)[SDLK_RCTRL]
  1409. )
  1410. {
  1411. if( (scrollingDir & LEFT) && (position.x>-CGI->mh->frameW) )
  1412. position.x--;
  1413. if( (scrollingDir & RIGHT) && (position.x < CGI->mh->map->width - CGI->mh->tilesW + CGI->mh->frameW) )
  1414. position.x++;
  1415. if( (scrollingDir & UP) && (position.y>-CGI->mh->frameH) )
  1416. position.y--;
  1417. if( (scrollingDir & DOWN) && (position.y < CGI->mh->map->height - CGI->mh->tilesH + CGI->mh->frameH) )
  1418. position.y++;
  1419. if(scrollingDir)
  1420. {
  1421. updateScreen = true;
  1422. updateMinimap=true;
  1423. }
  1424. }
  1425. if(updateScreen)
  1426. {
  1427. terrain.show(to);
  1428. for(int i=0;i<4;i++)
  1429. blitAt(gems[i]->ourImages[LOCPLINT->playerID].bitmap,ADVOPT.gemX[i],ADVOPT.gemY[i],to);
  1430. updateScreen=false;
  1431. LOCPLINT->cingconsole->show(to);
  1432. }
  1433. if (updateMinimap)
  1434. {
  1435. minimap.draw(to);
  1436. updateMinimap=false;
  1437. }
  1438. }
  1439. void CAdvMapInt::selectionChanged()
  1440. {
  1441. const CGTownInstance *to = townList.items[townList.selected];
  1442. select(to);
  1443. }
  1444. void CAdvMapInt::centerOn(int3 on)
  1445. {
  1446. // TODO:convertPosition should not belong to CGHeroInstance, and it
  1447. // should be split in 2 methods.
  1448. on = CGHeroInstance::convertPosition(on, false);
  1449. on.x -= CGI->mh->frameW;
  1450. on.y -= CGI->mh->frameH;
  1451. on = LOCPLINT->repairScreenPos(on);
  1452. LOCPLINT->adventureInt->position = on;
  1453. LOCPLINT->adventureInt->updateScreen=true;
  1454. updateMinimap=true;
  1455. }
  1456. void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
  1457. {
  1458. ui8 Dir;
  1459. switch(key.keysym.sym)
  1460. {
  1461. case SDLK_UP:
  1462. Dir = UP;
  1463. break;
  1464. case SDLK_LEFT:
  1465. Dir = LEFT;
  1466. break;
  1467. case SDLK_RIGHT:
  1468. Dir = RIGHT;
  1469. break;
  1470. case SDLK_DOWN:
  1471. Dir = DOWN;
  1472. break;
  1473. case SDLK_SPACE: //space - try to revisit current object with selected hero
  1474. {
  1475. if(!active)
  1476. return;
  1477. const CGHeroInstance *h = dynamic_cast<const CGHeroInstance*>(selection);
  1478. if(h && key.state == SDL_PRESSED)
  1479. {
  1480. LOCPLINT->pim->unlock();
  1481. LOCPLINT->cb->moveHero(h,h->pos);
  1482. LOCPLINT->pim->lock();
  1483. }
  1484. }
  1485. return;
  1486. case SDLK_RETURN:
  1487. {
  1488. if(!active || !selection || key.state != SDL_PRESSED)
  1489. return;
  1490. if(selection->ID == 34)
  1491. LOCPLINT->openHeroWindow(static_cast<const CGHeroInstance*>(selection));
  1492. else if(selection->ID == 98)
  1493. LOCPLINT->openTownWindow(static_cast<const CGTownInstance*>(selection));
  1494. return;
  1495. }
  1496. case SDLK_t:
  1497. {
  1498. //act on key down if marketplace windows is not already opened
  1499. if(key.state != SDL_PRESSED || dynamic_cast<CMarketplaceWindow*>(LOCPLINT->topInt())) return;
  1500. //check if we have aby marketplace
  1501. std::vector<const CGTownInstance*> towns = LOCPLINT->cb->getTownsInfo();
  1502. size_t i = 0;
  1503. for(; i<towns.size(); i++)
  1504. if(vstd::contains(towns[i]->builtBuildings, 14))
  1505. break;
  1506. if(i != towns.size()) //if any town has marketplace, open window
  1507. LOCPLINT->pushInt(new CMarketplaceWindow);
  1508. else //if not - complain
  1509. LOCPLINT->showInfoDialog("No available marketplace!", std::vector<SComponent*>(), soundBase::sound_todo);
  1510. return;
  1511. }
  1512. default:
  1513. return;
  1514. }
  1515. if(key.state == SDL_PRESSED //arrow is pressed
  1516. && (SDL_GetKeyState(NULL)[SDLK_LCTRL]
  1517. || SDL_GetKeyState(NULL)[SDLK_RCTRL])
  1518. )
  1519. scrollingDir |= Dir;
  1520. else
  1521. scrollingDir &= ~Dir;
  1522. }
  1523. void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * client)
  1524. {
  1525. if (down)
  1526. {
  1527. //boost::algorithm::erase_all(text,"\"");
  1528. CSimpleWindow * temp = CMessage::genWindow(text,LOCPLINT->playerID);
  1529. temp->pos.x=screen->w/2-(temp->pos.w/2);
  1530. temp->pos.y=screen->h/2-(temp->pos.h/2);
  1531. temp->owner = client;
  1532. CRClickPopupInt *rcpi = new CRClickPopupInt(temp,true);
  1533. LOCPLINT->pushInt(rcpi);
  1534. }
  1535. }
  1536. int3 CAdvMapInt::verifyPos(int3 ver)
  1537. {
  1538. if (ver.x<0)
  1539. ver.x=0;
  1540. if (ver.y<0)
  1541. ver.y=0;
  1542. if (ver.z<0)
  1543. ver.z=0;
  1544. if (ver.x>=CGI->mh->sizes.x)
  1545. ver.x=CGI->mh->sizes.x-1;
  1546. if (ver.y>=CGI->mh->sizes.y)
  1547. ver.y=CGI->mh->sizes.y-1;
  1548. if (ver.z>=CGI->mh->sizes.z)
  1549. ver.z=CGI->mh->sizes.z-1;
  1550. return ver;
  1551. }
  1552. void CAdvMapInt::select(const CArmedInstance *sel )
  1553. {
  1554. LOCPLINT->cb->setSelection(sel);
  1555. centerOn(sel->pos);
  1556. selection = sel;
  1557. terrain.currentPath = NULL;
  1558. if(sel->ID==TOWNI_TYPE)
  1559. {
  1560. int pos = vstd::findPos(townList.items,sel);
  1561. townList.selected = pos;
  1562. }
  1563. else //hero selected
  1564. {
  1565. const CGHeroInstance *h = static_cast<const CGHeroInstance*>(sel);
  1566. if(LOCPLINT->getWHero(heroList.selected) != h)
  1567. heroList.selected = heroList.getPosOfHero(h);
  1568. if(vstd::contains(paths,h)) //hero has assigned path
  1569. {
  1570. CPath &path = paths[h];
  1571. //update the hero path in case of something has changed on map
  1572. if(LOCPLINT->cb->getPath(path.startPos(), path.endPos(), h, path))
  1573. terrain.currentPath = &path;
  1574. else
  1575. paths.erase(h);
  1576. }
  1577. }
  1578. townList.draw(screen);
  1579. heroList.draw(screen);
  1580. infoBar.draw(screen);
  1581. }