CAdvmapInterface.cpp 48 KB

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