CAdvmapInterface.cpp 49 KB

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