CAdvmapInterface.cpp 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255
  1. #include "stdafx.h"
  2. #include "CAdvmapInterface.h"
  3. #include "client/CBitmapHandler.h"
  4. #include "CPlayerInterface.h"
  5. #include "CCastleInterface.h"
  6. #include "CCursorHandler.h"
  7. #include "hch/CPreGameTextHandler.h"
  8. #include "hch/CGeneralTextHandler.h"
  9. #include "hch/CDefHandler.h"
  10. #include "hch/CTownHandler.h"
  11. #include "CPathfinder.h"
  12. #include "CGameInfo.h"
  13. #include "SDL_Extensions.h"
  14. #include "CCallback.h"
  15. #include <boost/assign/std/vector.hpp>
  16. #include "mapHandler.h"
  17. #include "CMessage.h"
  18. #include <boost/algorithm/string.hpp>
  19. #include <boost/algorithm/string/replace.hpp>
  20. #include "hch/CHeroHandler.h"
  21. #include <sstream>
  22. #include "AdventureMapButton.h"
  23. #include "CHeroWindow.h"
  24. #include "client/Graphics.h"
  25. #include "hch/CObjectHandler.h"
  26. #include <boost/thread.hpp>
  27. #include "map.h"
  28. #pragma warning (disable : 4355)
  29. extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
  30. using namespace boost::logic;
  31. using namespace boost::assign;
  32. using namespace CSDL_Ext;
  33. CAdvMapInt::~CAdvMapInt()
  34. {
  35. SDL_FreeSurface(bg);
  36. delete heroWindow;
  37. }
  38. CMinimap::CMinimap(bool draw)
  39. {
  40. statusbarTxt = CGI->preth->zelp[291].first;
  41. rcText = CGI->preth->zelp[291].second;
  42. pos.x=630;
  43. pos.y=26;
  44. pos.h=pos.w=144;
  45. int rx = (((float)19)/(CGI->mh->sizes.x))*((float)pos.w),
  46. ry = (((float)18)/(CGI->mh->sizes.y))*((float)pos.h);
  47. radar = newSurface(rx,ry);
  48. temps = newSurface(144,144);
  49. SDL_FillRect(radar,NULL,0x00FFFF);
  50. for (int i=0; i<radar->w; i++)
  51. {
  52. if (i%4 || (i==0))
  53. {
  54. SDL_PutPixel(radar,i,0,255,75,125);
  55. SDL_PutPixel(radar,i,radar->h-1,255,75,125);
  56. }
  57. }
  58. for (int i=0; i<radar->h; i++)
  59. {
  60. if ((i%4) || (i==0))
  61. {
  62. SDL_PutPixel(radar,0,i,255,75,125);
  63. SDL_PutPixel(radar,radar->w-1,i,255,75,125);
  64. }
  65. }
  66. SDL_SetColorKey(radar,SDL_SRCCOLORKEY,SDL_MapRGB(radar->format,0,255,255));
  67. //radar = CDefHandler::giveDef("RADAR.DEF");
  68. std::ifstream is("config/minimap.txt",std::ifstream::in);
  69. for (int i=0;i<TERRAIN_TYPES;i++)
  70. {
  71. std::pair<int,SDL_Color> vinya;
  72. std::pair<int,SDL_Color> vinya2;
  73. int pom;
  74. is >> pom;
  75. vinya2.first=vinya.first=pom;
  76. is >> pom;
  77. vinya.second.r=pom;
  78. is >> pom;
  79. vinya.second.g=pom;
  80. is >> pom;
  81. vinya.second.b=pom;
  82. is >> pom;
  83. vinya2.second.r=pom;
  84. is >> pom;
  85. vinya2.second.g=pom;
  86. is >> pom;
  87. vinya2.second.b=pom;
  88. vinya.second.unused=vinya2.second.unused=255;
  89. colors.insert(vinya);
  90. colorsBlocked.insert(vinya2);
  91. }
  92. is.close();
  93. if (draw)
  94. redraw();
  95. }
  96. void CMinimap::draw()
  97. {
  98. //draw terrain
  99. blitAt(map[LOCPLINT->adventureInt->position.z],0,0,temps);
  100. //draw heroes
  101. std::vector <const CGHeroInstance *> hh = LOCPLINT->cb->getHeroesInfo(false);
  102. int mw = map[0]->w, mh = map[0]->h,
  103. wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y;
  104. for (int i=0; i<hh.size();i++)
  105. {
  106. int3 hpos = hh[i]->getPosition(false);
  107. if(hpos.z!=LOCPLINT->adventureInt->position.z)
  108. continue;
  109. //float zawx = ((float)hpos.x/CGI->mh->sizes.x), zawy = ((float)hpos.y/CGI->mh->sizes.y);
  110. int3 maplgp ( (hpos.x*mw)/CGI->mh->sizes.x, (hpos.y*mh)/CGI->mh->sizes.y, hpos.z );
  111. for (int ii=0; ii<wo; ii++)
  112. {
  113. for (int jj=0; jj<ho; jj++)
  114. {
  115. SDL_PutPixel(temps,maplgp.x+ii,maplgp.y+jj,graphics->playerColors[hh[i]->getOwner()].r,graphics->playerColors[hh[i]->getOwner()].g,graphics->playerColors[hh[i]->getOwner()].b);
  116. }
  117. }
  118. }
  119. blitAt(FoW[LOCPLINT->adventureInt->position.z],0,0,temps);
  120. //draw radar
  121. int bx = (((float)LOCPLINT->adventureInt->position.x)/(((float)CGI->mh->sizes.x)))*pos.w,
  122. by = (((float)LOCPLINT->adventureInt->position.y)/(((float)CGI->mh->sizes.y)))*pos.h;
  123. blitAt(radar,bx,by,temps);
  124. blitAt(temps,pos.x,pos.y);
  125. //SDL_UpdateRect(screen,pos.x,pos.y,pos.w,pos.h);
  126. }
  127. void CMinimap::redraw(int level)// (level==-1) => redraw all levels
  128. {
  129. (CGI);
  130. for (int i=0; i<CGI->mh->sizes.z; i++)
  131. {
  132. SDL_Surface * pom ;
  133. if ((level>=0) && (i!=level))
  134. continue;
  135. if (map.size()<i+1)
  136. pom = CSDL_Ext::newSurface(pos.w,pos.h,screen);
  137. else pom = map[i];
  138. for (int x=0;x<pos.w;x++)
  139. {
  140. for (int y=0;y<pos.h;y++)
  141. {
  142. int mx=(CGI->mh->sizes.x*x)/pos.w;
  143. int my=(CGI->mh->sizes.y*y)/pos.h;
  144. if (CGI->mh->ttiles[mx][my][i].tileInfo->blocked && (!CGI->mh->ttiles[mx][my][i].tileInfo->visitable))
  145. SDL_PutPixel(pom,x,y,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].r,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].g,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].b);
  146. else SDL_PutPixel(pom,x,y,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].r,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].g,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].b);
  147. }
  148. }
  149. map.push_back(pom);
  150. }
  151. //FoW
  152. int mw = map[0]->w, mh = map[0]->h,
  153. wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y;
  154. for(int d=0; d<CGI->mh->map->twoLevel+1; ++d)
  155. {
  156. if(level>=0 && d!=level)
  157. continue;
  158. SDL_Surface * pt = CSDL_Ext::newSurface(pos.w, pos.h, CSDL_Ext::std32bppSurface);
  159. for (int i=0; i<mw; i++)
  160. {
  161. for (int j=0; j<mh; j++)
  162. {
  163. int3 pp( ((i*CGI->mh->sizes.x)/mw), ((j*CGI->mh->sizes.y)/mh), d );
  164. if ( !LOCPLINT->cb->isVisible(pp) )
  165. {
  166. CSDL_Ext::SDL_PutPixelWithoutRefresh(pt,i,j,0,0,0);
  167. }
  168. }
  169. }
  170. CSDL_Ext::update(pt);
  171. FoW.push_back(pt);
  172. }
  173. //FoW end
  174. }
  175. void CMinimap::updateRadar()
  176. {}
  177. void CMinimap::clickRight (tribool down)
  178. {
  179. LOCPLINT->adventureInt->handleRightClick(rcText,down,this);
  180. }
  181. void CMinimap::clickLeft (tribool down)
  182. {
  183. if (down && (!pressedL))
  184. MotionInterested::activate();
  185. else if (!down)
  186. {
  187. if (std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this)!=LOCPLINT->motioninterested.end())
  188. MotionInterested::deactivate();
  189. }
  190. ClickableL::clickLeft(down);
  191. if (!((bool)down))
  192. return;
  193. float dx=((float)(LOCPLINT->current->motion.x-pos.x))/((float)pos.w),
  194. dy=((float)(LOCPLINT->current->motion.y-pos.y))/((float)pos.h);
  195. int3 newCPos;
  196. newCPos.x = (CGI->mh->sizes.x*dx);
  197. newCPos.y = (CGI->mh->sizes.y*dy);
  198. newCPos.z = LOCPLINT->adventureInt->position.z;
  199. LOCPLINT->adventureInt->centerOn(newCPos);
  200. }
  201. void CMinimap::hover (bool on)
  202. {
  203. Hoverable::hover(on);
  204. if (on)
  205. LOCPLINT->adventureInt->statusbar.print(statusbarTxt);
  206. else if (LOCPLINT->adventureInt->statusbar.current==statusbarTxt)
  207. LOCPLINT->adventureInt->statusbar.clear();
  208. }
  209. void CMinimap::mouseMoved (SDL_MouseMotionEvent & sEvent)
  210. {
  211. if (pressedL)
  212. {
  213. clickLeft(true);
  214. }
  215. }
  216. void CMinimap::activate()
  217. {
  218. ClickableL::activate();
  219. ClickableR::activate();
  220. Hoverable::activate();
  221. if (pressedL)
  222. MotionInterested::activate();
  223. }
  224. void CMinimap::deactivate()
  225. {
  226. if (pressedL)
  227. MotionInterested::deactivate();
  228. ClickableL::deactivate();
  229. ClickableR::deactivate();
  230. Hoverable::deactivate();
  231. }
  232. void CMinimap::showTile(int3 pos)
  233. {
  234. int mw = map[0]->w, mh = map[0]->h;
  235. double wo = ((double)mw)/CGI->mh->sizes.x, ho = ((double)mh)/CGI->mh->sizes.y;
  236. for (int ii=0; ii<wo; ii++)
  237. {
  238. for (int jj=0; jj<ho; jj++)
  239. {
  240. if ((pos.x*wo+ii<this->pos.w) && (pos.y*ho+jj<this->pos.h))
  241. CSDL_Ext::SDL_PutPixel(FoW[pos.z],pos.x*wo+ii,pos.y*ho+jj,0,0,0,0,0);
  242. }
  243. }
  244. }
  245. void CMinimap::hideTile(int3 pos)
  246. {
  247. }
  248. CTerrainRect::CTerrainRect():currentPath(NULL)
  249. {
  250. tilesw=19;
  251. tilesh=18;
  252. pos.x=7;
  253. pos.y=6;
  254. pos.w=593;
  255. pos.h=547;
  256. arrows = CDefHandler::giveDef("ADAG.DEF");
  257. for(int y=0; y<arrows->ourImages.size(); ++y)
  258. {
  259. arrows->ourImages[y].bitmap = CSDL_Ext::alphaTransform(arrows->ourImages[y].bitmap);
  260. }
  261. }
  262. void CTerrainRect::activate()
  263. {
  264. ClickableL::activate();
  265. ClickableR::activate();
  266. Hoverable::activate();
  267. KeyInterested::activate();
  268. MotionInterested::activate();
  269. };
  270. void CTerrainRect::deactivate()
  271. {
  272. ClickableL::deactivate();
  273. ClickableR::deactivate();
  274. Hoverable::deactivate();
  275. KeyInterested::deactivate();
  276. MotionInterested::deactivate();
  277. };
  278. void CTerrainRect::clickLeft(tribool down)
  279. {
  280. if ((down==false) || indeterminate(down))
  281. return;
  282. int3 mp = whichTileIsIt();
  283. if ((mp.x<0) || (mp.y<0))
  284. return;
  285. std::vector < const CGObjectInstance * > objs;
  286. if (LOCPLINT->adventureInt->selection->ID != HEROI_TYPE)
  287. {
  288. if (currentPath)
  289. {
  290. std::cout<<"Warning: Lost path?" << std::endl;
  291. delete currentPath;
  292. currentPath = NULL;
  293. }
  294. objs = LOCPLINT->cb->getBlockingObjs(mp);
  295. for(int i=0; i<objs.size();i++)
  296. {
  297. if(objs[i]->ID == 98 && objs[i]->tempOwner == LOCPLINT->playerID) //town
  298. {
  299. if(LOCPLINT->adventureInt->selection == (objs[i]))
  300. {
  301. LOCPLINT->openTownWindow(static_cast<const CGTownInstance*>(objs[i]));
  302. }
  303. else
  304. {
  305. LOCPLINT->adventureInt->select(static_cast<const CArmedInstance*>(objs[i]));
  306. return;
  307. }
  308. }
  309. else if(objs[i]->ID == 34 && objs[i]->tempOwner == LOCPLINT->playerID)
  310. {
  311. LOCPLINT->adventureInt->select(static_cast<const CArmedInstance*>(objs[i]));
  312. return;
  313. }
  314. }
  315. return;
  316. }
  317. else
  318. {
  319. objs = LOCPLINT->cb->getVisitableObjs(mp);
  320. for(int i=0; i<objs.size();i++)
  321. {
  322. if(objs[i]->ID == 98)
  323. goto endchkpt;
  324. }
  325. objs = LOCPLINT->cb->getBlockingObjs(mp);
  326. for(int i=0; i<objs.size();i++)
  327. {
  328. if(objs[i]->ID == 98 && objs[i]->tempOwner == LOCPLINT->playerID) //town
  329. {
  330. LOCPLINT->adventureInt->select(static_cast<const CArmedInstance*>(objs[i]));
  331. return;
  332. }
  333. else if(objs[i]->ID == 34 && objs[i]->tempOwner == LOCPLINT->playerID && LOCPLINT->adventureInt->selection == (objs[i]))
  334. {
  335. LOCPLINT->openHeroWindow(static_cast<const CGHeroInstance*>(objs[i]));
  336. return;
  337. }
  338. }
  339. }
  340. endchkpt:
  341. bool mres =true;
  342. if (currentPath)
  343. {
  344. if ( (currentPath->endPos()) == mp)
  345. { //move
  346. CPath sended(*currentPath); //temporary path - engine will operate on it
  347. LOCPLINT->pim->unlock();
  348. mres = LOCPLINT->cb->moveHero( ((const CGHeroInstance*)LOCPLINT->adventureInt->selection)->type->ID,&sended,1,0);
  349. LOCPLINT->pim->lock();
  350. if(mres)
  351. {
  352. delete currentPath;
  353. currentPath = NULL;
  354. LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.getPosOfHero(LOCPLINT->adventureInt->selection)].second = NULL;
  355. }
  356. }
  357. else
  358. {
  359. delete currentPath;
  360. currentPath=NULL;
  361. LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.getPosOfHero(LOCPLINT->adventureInt->selection)].second = NULL;
  362. }
  363. return;
  364. }
  365. const CGHeroInstance * currentHero = (LOCPLINT->adventureInt->heroList.items.size())?(LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].first):(NULL);
  366. if(currentHero)
  367. {
  368. int3 bufpos = currentHero->getPosition(false);
  369. if (mres)
  370. {
  371. vector<Coordinate>* p;
  372. p = CGI->pathf->GetPath(Coordinate(bufpos),Coordinate(mp),currentHero);
  373. //Convert to old format.
  374. currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->ConvertToOldFormat(p);
  375. delete p;
  376. }
  377. return;
  378. }
  379. }
  380. void CTerrainRect::clickRight(tribool down)
  381. {
  382. }
  383. void CTerrainRect::mouseMoved (SDL_MouseMotionEvent & sEvent)
  384. {
  385. int3 pom=LOCPLINT->adventureInt->verifyPos(whichTileIsIt(sEvent.x,sEvent.y));
  386. if (pom!=curHoveredTile)
  387. curHoveredTile=pom;
  388. else
  389. return;
  390. std::vector<std::string> temp = LOCPLINT->cb->getObjDescriptions(pom);
  391. if (temp.size())
  392. {
  393. LOCPLINT->adventureInt->statusbar.print((*((temp.end())-1)));
  394. }
  395. else
  396. {
  397. LOCPLINT->adventureInt->statusbar.clear();
  398. }
  399. std::vector<const CGObjectInstance *> objs = LOCPLINT->cb->getVisitableObjs(pom);
  400. for(int i=0; i<objs.size();i++)
  401. {
  402. if(objs[i]->ID == 98) //town
  403. {
  404. CGI->curh->changeGraphic(0,0);
  405. return;
  406. }
  407. }
  408. objs = LOCPLINT->cb->getBlockingObjs(pom);
  409. for(int i=0; i<objs.size();i++)
  410. {
  411. if(objs[i]->ID == 98 && objs[i]->tempOwner == LOCPLINT->playerID) //town
  412. {
  413. CGI->curh->changeGraphic(0,3);
  414. return;
  415. }
  416. else if(objs[i]->ID == 34 //mouse over hero
  417. && (objs[i]==LOCPLINT->adventureInt->selection || LOCPLINT->adventureInt->selection->ID==98)
  418. && objs[i]->tempOwner == LOCPLINT->playerID) //this hero is selected or we've selected a town
  419. {
  420. CGI->curh->changeGraphic(0,2);
  421. return;
  422. }
  423. }
  424. CGI->curh->changeGraphic(0,0);
  425. }
  426. void CTerrainRect::keyPressed (SDL_KeyboardEvent & key){}
  427. void CTerrainRect::hover(bool on)
  428. {
  429. if (!on)
  430. LOCPLINT->adventureInt->statusbar.clear();
  431. }
  432. void CTerrainRect::showPath()
  433. {
  434. for (int i=0;i<currentPath->nodes.size()-1;i++)
  435. {
  436. int pn=-1;//number of picture
  437. if (i==0) //last tile
  438. {
  439. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  440. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  441. if (x<0 || y<0 || x>pos.w || y>pos.h)
  442. continue;
  443. pn=0;
  444. }
  445. else
  446. {
  447. std::vector<CPathNode> & cv = currentPath->nodes;
  448. if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1)
  449. {
  450. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  451. {
  452. pn = 3;
  453. }
  454. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  455. {
  456. pn = 12;
  457. }
  458. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  459. {
  460. pn = 21;
  461. }
  462. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  463. {
  464. pn = 22;
  465. }
  466. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  467. {
  468. pn = 2;
  469. }
  470. }
  471. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1)
  472. {
  473. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  474. {
  475. pn = 4;
  476. }
  477. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  478. {
  479. pn = 13;
  480. }
  481. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  482. {
  483. pn = 22;
  484. }
  485. }
  486. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1)
  487. {
  488. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  489. {
  490. pn = 5;
  491. }
  492. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  493. {
  494. pn = 14;
  495. }
  496. else if(cv[i-1].coord.x+1 == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y)
  497. {
  498. pn = 23;
  499. }
  500. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  501. {
  502. pn = 24;
  503. }
  504. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  505. {
  506. pn = 4;
  507. }
  508. }
  509. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y)
  510. {
  511. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  512. {
  513. pn = 6;
  514. }
  515. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
  516. {
  517. pn = 15;
  518. }
  519. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  520. {
  521. pn = 24;
  522. }
  523. }
  524. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1)
  525. {
  526. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
  527. {
  528. pn = 7;
  529. }
  530. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  531. {
  532. pn = 16;
  533. }
  534. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  535. {
  536. pn = 17;
  537. }
  538. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  539. {
  540. pn = 6;
  541. }
  542. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  543. {
  544. pn = 18;
  545. }
  546. }
  547. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1)
  548. {
  549. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  550. {
  551. pn = 8;
  552. }
  553. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  554. {
  555. pn = 9;
  556. }
  557. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  558. {
  559. pn = 18;
  560. }
  561. }
  562. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1)
  563. {
  564. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  565. {
  566. pn = 1;
  567. }
  568. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  569. {
  570. pn = 10;
  571. }
  572. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  573. {
  574. pn = 19;
  575. }
  576. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  577. {
  578. pn = 8;
  579. }
  580. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  581. {
  582. pn = 20;
  583. }
  584. }
  585. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y)
  586. {
  587. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  588. {
  589. pn = 2;
  590. }
  591. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  592. {
  593. pn = 11;
  594. }
  595. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  596. {
  597. pn = 20;
  598. }
  599. }
  600. }
  601. if ( ((currentPath->nodes[i].dist)-(*(currentPath->nodes.end()-1)).dist) > ((const CGHeroInstance*)(LOCPLINT->adventureInt->selection))->movement)
  602. pn+=25;
  603. if (pn>=0)
  604. {
  605. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  606. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  607. if (x<0 || y<0 || x>pos.w || y>pos.h)
  608. continue;
  609. int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
  610. hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
  611. if (hvx<0 && hvy<0)
  612. {
  613. CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, screen, &genRect(32, 32, x, y));
  614. }
  615. else if(hvx<0)
  616. {
  617. CSDL_Ext::blit8bppAlphaTo24bpp
  618. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,0,0),
  619. screen,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,x,y));
  620. }
  621. else if (hvy<0)
  622. {
  623. CSDL_Ext::blit8bppAlphaTo24bpp
  624. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  625. screen,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  626. }
  627. else
  628. {
  629. CSDL_Ext::blit8bppAlphaTo24bpp
  630. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  631. screen,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  632. }
  633. }
  634. } //for (int i=0;i<currentPath->nodes.size()-1;i++)
  635. }
  636. void CTerrainRect::show()
  637. {
  638. SDL_Surface * teren = CGI->mh->terrainRect
  639. (LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
  640. tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim,
  641. &LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim,
  642. screen,&genRect(547,594,7,6)
  643. );
  644. //SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));
  645. //SDL_FreeSurface(teren);
  646. if (currentPath && LOCPLINT->adventureInt->position.z==currentPath->startPos().z) //drawing path
  647. {
  648. showPath();
  649. }
  650. }
  651. int3 CTerrainRect::whichTileIsIt(int x, int y)
  652. {
  653. int3 ret;
  654. ret.x = LOCPLINT->adventureInt->position.x + ((LOCPLINT->current->motion.x-pos.x)/32);
  655. ret.y = LOCPLINT->adventureInt->position.y + ((LOCPLINT->current->motion.y-pos.y)/32);
  656. ret.z = LOCPLINT->adventureInt->position.z;
  657. return ret;
  658. }
  659. int3 CTerrainRect::whichTileIsIt()
  660. {
  661. return whichTileIsIt(LOCPLINT->current->motion.x,LOCPLINT->current->motion.y);
  662. }
  663. void CResDataBar::clickRight (tribool down)
  664. {
  665. }
  666. void CResDataBar::activate()
  667. {
  668. ClickableR::activate();
  669. }
  670. void CResDataBar::deactivate()
  671. {
  672. ClickableR::deactivate();
  673. }
  674. CResDataBar::CResDataBar()
  675. {
  676. bg = BitmapHandler::loadBitmap("ZRESBAR.bmp");
  677. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  678. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  679. pos = genRect(bg->h,bg->w,3,575);
  680. txtpos += (std::pair<int,int>(35,577)),(std::pair<int,int>(120,577)),(std::pair<int,int>(205,577)),
  681. (std::pair<int,int>(290,577)),(std::pair<int,int>(375,577)),(std::pair<int,int>(460,577)),
  682. (std::pair<int,int>(545,577)),(std::pair<int,int>(620,577));
  683. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63] + ": %s, " +
  684. CGI->generaltexth->allTexts[64] + ": %s";
  685. }
  686. CResDataBar::~CResDataBar()
  687. {
  688. SDL_FreeSurface(bg);
  689. }
  690. void CResDataBar::draw()
  691. {
  692. blitAt(bg,pos.x,pos.y);
  693. char * buf = new char[15];
  694. for (int i=0;i<7;i++)
  695. {
  696. SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
  697. printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly);
  698. }
  699. std::vector<std::string> temp;
  700. SDL_itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf);
  701. SDL_itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf);
  702. SDL_itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf);
  703. printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,GEOR13,zwykly);
  704. temp.clear();
  705. //updateRect(&pos,screen);
  706. delete[] buf;
  707. }
  708. CInfoBar::CInfoBar()
  709. {
  710. toNextTick = mode = pom = -1;
  711. pos.x=605;
  712. pos.y=389;
  713. pos.w=194;
  714. pos.h=186;
  715. day = CDefHandler::giveDef("NEWDAY.DEF");
  716. week1 = CDefHandler::giveDef("NEWWEEK1.DEF");
  717. week2 = CDefHandler::giveDef("NEWWEEK2.DEF");
  718. week3 = CDefHandler::giveDef("NEWWEEK3.DEF");
  719. week4 = CDefHandler::giveDef("NEWWEEK4.DEF");
  720. }
  721. CInfoBar::~CInfoBar()
  722. {
  723. delete day;
  724. delete week1;
  725. delete week2;
  726. delete week3;
  727. delete week4;
  728. }
  729. void CInfoBar::draw(const CGObjectInstance * specific)
  730. {
  731. if ((mode>=0) && mode<5)
  732. {
  733. blitAnim(mode);
  734. return;
  735. }
  736. else if (mode==5)
  737. {
  738. mode = -1;
  739. draw(LOCPLINT->adventureInt->selection);
  740. }
  741. if (!specific)
  742. specific = LOCPLINT->adventureInt->selection;
  743. if(!specific)
  744. return;
  745. if(specific->ID == 34) //hero
  746. {
  747. if(graphics->heroWins.find(specific->subID)!=graphics->heroWins.end())
  748. blitAt(graphics->heroWins[specific->subID],pos.x,pos.y);
  749. }
  750. else if (specific->ID == 98)
  751. {
  752. const CGTownInstance * t = static_cast<const CGTownInstance*>(specific);
  753. if(graphics->townWins.find(t->id)!=graphics->townWins.end())
  754. blitAt(graphics->townWins[t->id],pos.x,pos.y);
  755. }
  756. //SDL_Surface * todr = LOCPLINT->infoWin(specific);
  757. //if (!todr)
  758. // return;
  759. //blitAt(todr,pos.x,pos.y);
  760. //SDL_FreeSurface(todr);
  761. }
  762. CDefHandler * CInfoBar::getAnim(int mode)
  763. {
  764. switch(mode)
  765. {
  766. case 0:
  767. return day;
  768. break;
  769. case 1:
  770. return week1;
  771. break;
  772. case 2:
  773. return week2;
  774. break;
  775. case 3:
  776. return week3;
  777. break;
  778. case 4:
  779. return week4;
  780. break;
  781. default:
  782. return NULL;
  783. break;
  784. }
  785. }
  786. void CInfoBar::blitAnim(int mode)//0 - day, 1 - week
  787. {
  788. CDefHandler * anim = NULL;
  789. std::stringstream txt;
  790. anim = getAnim(mode);
  791. if(mode) //new week animation
  792. {
  793. txt << CGI->generaltexth->allTexts[63] << " " << LOCPLINT->cb->getDate(2);
  794. }
  795. else //new day
  796. {
  797. txt << CGI->generaltexth->allTexts[64] << " " << LOCPLINT->cb->getDate(1);
  798. }
  799. blitAt(anim->ourImages[pom].bitmap,pos.x+9,pos.y+10);
  800. printAtMiddle(txt.str(),700,420,TNRB16,zwykly);
  801. if (pom == anim->ourImages.size()-1)
  802. toNextTick+=750;
  803. }
  804. void CInfoBar::newDay(int Day)
  805. {
  806. if(LOCPLINT->cb->getDate(1) != 1)
  807. {
  808. mode = 0; //showing day
  809. }
  810. else
  811. {
  812. switch(LOCPLINT->cb->getDate(2))
  813. {
  814. case 1:
  815. mode = 1;
  816. break;
  817. case 2:
  818. mode = 2;
  819. break;
  820. case 3:
  821. mode = 3;
  822. break;
  823. case 4:
  824. mode = 4;
  825. break;
  826. default:
  827. mode = -1;
  828. break;
  829. }
  830. }
  831. pom = 0;
  832. TimeInterested::activate();
  833. toNextTick = 500;
  834. blitAnim(mode);
  835. //blitAt(day->ourImages[pom].bitmap,pos.x+10,pos.y+10);
  836. }
  837. void CInfoBar::showComp(SComponent * comp, int time)
  838. {
  839. SDL_Surface * b = BitmapHandler::loadBitmap("ADSTATOT.bmp");
  840. blitAt(b,pos.x+8,pos.y+11);
  841. blitAt(comp->getImg(),pos.x+52,pos.y+54);
  842. printAtMiddle(comp->subtitle,pos.x+91,pos.y+158,GEOR13,zwykly);
  843. printAtMiddleWB(comp->description,pos.x+94,pos.y+31,GEOR13,26,zwykly);
  844. SDL_FreeSurface(b);
  845. TimeInterested::activate();
  846. mode = 6;
  847. toNextTick = time;
  848. }
  849. void CInfoBar::tick()
  850. {
  851. if((mode >= 0) && (mode < 5))
  852. {
  853. pom++;
  854. if (pom >= getAnim(mode)->ourImages.size())
  855. {
  856. TimeInterested::deactivate();
  857. toNextTick = -1;
  858. mode = 5;
  859. draw();
  860. return;
  861. }
  862. toNextTick = 150;
  863. blitAnim(mode);
  864. }
  865. else if (mode == 6)
  866. {
  867. TimeInterested::deactivate();
  868. toNextTick = -1;
  869. mode = 5;
  870. draw();
  871. }
  872. }
  873. CAdvMapInt::CAdvMapInt(int Player)
  874. :player(Player),
  875. statusbar(7,556),
  876. kingOverview(CGI->preth->zelp[293].first,CGI->preth->zelp[293].second,
  877. boost::bind(&CAdvMapInt::fshowOverview,this), 679, 196, "IAM002.DEF", false,NULL,true),
  878. underground(CGI->preth->zelp[294].first,CGI->preth->zelp[294].second,
  879. boost::bind(&CAdvMapInt::fswitchLevel,this), 711, 196, "IAM010.DEF", false, new std::vector<std::string>(1,std::string("IAM003.DEF")),true),
  880. questlog(CGI->preth->zelp[295].first,CGI->preth->zelp[295].second,
  881. boost::bind(&CAdvMapInt::fshowQuestlog,this), 679, 228, "IAM004.DEF", false,NULL,true),
  882. sleepWake(CGI->preth->zelp[296].first,CGI->preth->zelp[296].second,
  883. boost::bind(&CAdvMapInt::fsleepWake,this), 711, 228, "IAM005.DEF", false,NULL,true),
  884. moveHero(CGI->preth->zelp[297].first,CGI->preth->zelp[297].second,
  885. boost::bind(&CAdvMapInt::fmoveHero,this), 679, 260, "IAM006.DEF", false,NULL,true),
  886. spellbook(CGI->preth->zelp[298].first,CGI->preth->zelp[298].second,
  887. boost::bind(&CAdvMapInt::fshowSpellbok,this), 711, 260, "IAM007.DEF", false,NULL,true),
  888. advOptions(CGI->preth->zelp[299].first,CGI->preth->zelp[299].second,
  889. boost::bind(&CAdvMapInt::fadventureOPtions,this), 679, 292, "IAM008.DEF", false,NULL,true),
  890. sysOptions(CGI->preth->zelp[300].first,CGI->preth->zelp[300].second,
  891. boost::bind(&CAdvMapInt::fsystemOptions,this), 711, 292, "IAM009.DEF", false,NULL,true),
  892. nextHero(CGI->preth->zelp[301].first,CGI->preth->zelp[301].second,
  893. boost::bind(&CAdvMapInt::fnextHero,this), 679, 324, "IAM000.DEF", false,NULL,true),
  894. endTurn(CGI->preth->zelp[302].first,CGI->preth->zelp[302].second,
  895. boost::bind(&CAdvMapInt::fendTurn,this), 679, 356, "IAM001.DEF", false,NULL,true),
  896. townList(5,&genRect(192,48,747,196),747,196,747,372)
  897. {
  898. selection = NULL;
  899. townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this);
  900. LOCPLINT->adventureInt=this;
  901. bg = BitmapHandler::loadBitmap("ADVMAP.bmp");
  902. graphics->blueToPlayersAdv(bg,player);
  903. scrollingLeft = false;
  904. scrollingRight = false;
  905. scrollingUp = false ;
  906. scrollingDown = false ;
  907. updateScreen = false;
  908. anim=0;
  909. animValHitCount=0; //animation frame
  910. heroAnim=0;
  911. heroAnimValHitCount=0; // hero animation frame
  912. heroList.init();
  913. heroList.genList();
  914. //townList.init();
  915. townList.genList();
  916. heroWindow = new CHeroWindow(this->player);
  917. gems.push_back(CDefHandler::giveDef("agemLL.def"));
  918. gems.push_back(CDefHandler::giveDef("agemLR.def"));
  919. gems.push_back(CDefHandler::giveDef("agemUL.def"));
  920. gems.push_back(CDefHandler::giveDef("agemUR.def"));
  921. }
  922. void CAdvMapInt::fshowOverview()
  923. {
  924. }
  925. void CAdvMapInt::fswitchLevel()
  926. {
  927. if(!CGI->mh->map->twoLevel)
  928. return;
  929. if (position.z)
  930. {
  931. position.z--;
  932. underground.curimg=0;
  933. underground.show();
  934. }
  935. else
  936. {
  937. underground.curimg=1;
  938. position.z++;
  939. underground.show();
  940. }
  941. updateScreen = true;
  942. minimap.draw();
  943. }
  944. void CAdvMapInt::fshowQuestlog()
  945. {
  946. }
  947. void CAdvMapInt::fsleepWake()
  948. {
  949. }
  950. void CAdvMapInt::fmoveHero()
  951. {
  952. if (selection->ID!=HEROI_TYPE)
  953. return;
  954. if (!terrain.currentPath)
  955. return;
  956. CPath sended(*(terrain.currentPath)); //temporary path - engine will operate on it
  957. LOCPLINT->cb->moveHero( ((const CGHeroInstance*)LOCPLINT->adventureInt->selection)->type->ID,&sended,1,0);
  958. }
  959. void CAdvMapInt::fshowSpellbok()
  960. {
  961. }
  962. void CAdvMapInt::fadventureOPtions()
  963. {
  964. }
  965. void CAdvMapInt::fsystemOptions()
  966. {
  967. }
  968. void CAdvMapInt::fnextHero()
  969. {
  970. }
  971. void CAdvMapInt::fendTurn()
  972. {
  973. LOCPLINT->makingTurn = false;
  974. }
  975. void CAdvMapInt::activate()
  976. {
  977. if(subInt == heroWindow)
  978. {
  979. heroWindow->activate();
  980. return;
  981. }
  982. LOCPLINT->curint = this;
  983. LOCPLINT->statusbar = &statusbar;
  984. kingOverview.activate();
  985. underground.activate();
  986. questlog.activate();
  987. sleepWake.activate();
  988. moveHero.activate();
  989. spellbook.activate();
  990. sysOptions.activate();
  991. advOptions.activate();
  992. nextHero.activate();
  993. endTurn.activate();
  994. minimap.activate();
  995. heroList.activate();
  996. townList.activate();
  997. terrain.activate();
  998. show();
  999. }
  1000. void CAdvMapInt::deactivate()
  1001. {
  1002. if(subInt == heroWindow)
  1003. {
  1004. heroWindow->deactivate();
  1005. return;
  1006. }
  1007. hide();
  1008. }
  1009. void CAdvMapInt::show(SDL_Surface *to)
  1010. {
  1011. blitAt(bg,0,0);
  1012. kingOverview.show();
  1013. underground.show();
  1014. questlog.show();
  1015. sleepWake.show();
  1016. moveHero.show();
  1017. spellbook.show();
  1018. advOptions.show();
  1019. sysOptions.show();
  1020. nextHero.show();
  1021. endTurn.show();
  1022. minimap.draw();
  1023. heroList.draw();
  1024. townList.draw();
  1025. updateScreen = true;
  1026. update();
  1027. resdatabar.draw();
  1028. statusbar.show();
  1029. infoBar.draw();
  1030. }
  1031. void CAdvMapInt::hide()
  1032. {
  1033. CGI->curh->changeGraphic(0,0);
  1034. kingOverview.deactivate();
  1035. underground.deactivate();
  1036. questlog.deactivate();
  1037. sleepWake.deactivate();
  1038. moveHero.deactivate();
  1039. spellbook.deactivate();
  1040. advOptions.deactivate();
  1041. sysOptions.deactivate();
  1042. nextHero.deactivate();
  1043. endTurn.deactivate();
  1044. minimap.deactivate();
  1045. heroList.deactivate();
  1046. townList.deactivate();
  1047. terrain.deactivate();
  1048. if(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar)!=LOCPLINT->timeinterested.end())
  1049. LOCPLINT->timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar));
  1050. infoBar.mode=-1;
  1051. }
  1052. void CAdvMapInt::update()
  1053. {
  1054. ++animValHitCount; //for animations
  1055. if(animValHitCount == 8)
  1056. {
  1057. animValHitCount = 0;
  1058. ++anim;
  1059. updateScreen = true;
  1060. }
  1061. ++heroAnim;
  1062. if(scrollingLeft)
  1063. {
  1064. if(position.x>-Woff)
  1065. {
  1066. position.x--;
  1067. updateScreen = true;
  1068. updateMinimap=true;
  1069. }
  1070. }
  1071. if(scrollingRight)
  1072. {
  1073. if(position.x<CGI->mh->map->width-19+4)
  1074. {
  1075. position.x++;
  1076. updateScreen = true;
  1077. updateMinimap=true;
  1078. }
  1079. }
  1080. if(scrollingUp)
  1081. {
  1082. if(position.y>-Hoff)
  1083. {
  1084. position.y--;
  1085. updateScreen = true;
  1086. updateMinimap=true;
  1087. }
  1088. }
  1089. if(scrollingDown)
  1090. {
  1091. if(position.y<CGI->mh->map->height-18+4)
  1092. {
  1093. position.y++;
  1094. updateScreen = true;
  1095. updateMinimap=true;
  1096. }
  1097. }
  1098. if(updateScreen)
  1099. {
  1100. terrain.show();
  1101. blitAt(gems[2]->ourImages[LOCPLINT->playerID].bitmap,6,6);
  1102. blitAt(gems[0]->ourImages[LOCPLINT->playerID].bitmap,6,508);
  1103. blitAt(gems[1]->ourImages[LOCPLINT->playerID].bitmap,556,508);
  1104. blitAt(gems[3]->ourImages[LOCPLINT->playerID].bitmap,556,6);
  1105. updateScreen=false;
  1106. }
  1107. if (updateMinimap)
  1108. {
  1109. minimap.draw();
  1110. updateMinimap=false;
  1111. }
  1112. }
  1113. void CAdvMapInt::selectionChanged()
  1114. {
  1115. const CGTownInstance *to = townList.items[townList.selected];
  1116. select(to);
  1117. }
  1118. void CAdvMapInt::centerOn(int3 on)
  1119. {
  1120. on.x -= (LOCPLINT->adventureInt->terrain.tilesw/2);
  1121. on.y -= (LOCPLINT->adventureInt->terrain.tilesh/2);
  1122. if (on.x<0)
  1123. on.x=-(Woff/2);
  1124. else if((on.x+LOCPLINT->adventureInt->terrain.tilesw) > (CGI->mh->sizes.x))
  1125. on.x=CGI->mh->sizes.x-LOCPLINT->adventureInt->terrain.tilesw+(Woff/2);
  1126. if (on.y<0)
  1127. on.y = -(Hoff/2);
  1128. else if((on.y+LOCPLINT->adventureInt->terrain.tilesh) > (CGI->mh->sizes.y))
  1129. on.y = CGI->mh->sizes.y-LOCPLINT->adventureInt->terrain.tilesh+(Hoff/2);
  1130. LOCPLINT->adventureInt->position.x=on.x;
  1131. LOCPLINT->adventureInt->position.y=on.y;
  1132. LOCPLINT->adventureInt->position.z=on.z;
  1133. LOCPLINT->adventureInt->updateScreen=true;
  1134. updateMinimap=true;
  1135. }
  1136. void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * client)
  1137. {
  1138. if (down)
  1139. {
  1140. boost::algorithm::erase_all(text,"\"");
  1141. CSimpleWindow * temp = CMessage::genWindow(text,LOCPLINT->playerID);
  1142. temp->pos.x=300-(temp->pos.w/2);
  1143. temp->pos.y=300-(temp->pos.h/2);
  1144. temp->owner = client;
  1145. LOCPLINT->objsToBlit.push_back(temp);
  1146. }
  1147. else
  1148. {
  1149. for (int i=0;i<LOCPLINT->objsToBlit.size();i++)
  1150. {
  1151. //TODO: pewnie da sie to zrobic lepiej, ale nie chce mi sie. Wolajacy obiekt powinien informowac kogo spodziewa sie odwolac (null jesli down)
  1152. CSimpleWindow * pom = dynamic_cast<CSimpleWindow*>(LOCPLINT->objsToBlit[i]);
  1153. if (!pom)
  1154. continue;
  1155. if (pom->owner==client)
  1156. {
  1157. LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+(i));
  1158. delete pom;
  1159. if((LOCPLINT->curint == LOCPLINT->castleInt) && !LOCPLINT->castleInt->subInt)
  1160. LOCPLINT->castleInt->showAll(0,true);
  1161. }
  1162. }
  1163. }
  1164. }
  1165. int3 CAdvMapInt::verifyPos(int3 ver)
  1166. {
  1167. if (ver.x<0)
  1168. ver.x=0;
  1169. if (ver.y<0)
  1170. ver.y=0;
  1171. if (ver.z<0)
  1172. ver.z=0;
  1173. if (ver.x>=CGI->mh->sizes.x)
  1174. ver.x=CGI->mh->sizes.x-1;
  1175. if (ver.y>=CGI->mh->sizes.y)
  1176. ver.y=CGI->mh->sizes.y-1;
  1177. if (ver.z>=CGI->mh->sizes.z)
  1178. ver.z=CGI->mh->sizes.z-1;
  1179. return ver;
  1180. }
  1181. void CAdvMapInt::select(const CArmedInstance *sel )
  1182. {
  1183. centerOn(sel->pos);
  1184. selection = sel;
  1185. if(sel->ID==98)
  1186. {
  1187. int pos = vstd::findPos(townList.items,sel);
  1188. townList.selected = pos;
  1189. terrain.currentPath = NULL;
  1190. }
  1191. else
  1192. {
  1193. int pos = heroList.getPosOfHero(sel);
  1194. heroList.selected = pos;
  1195. terrain.currentPath = heroList.items[pos].second;
  1196. }
  1197. townList.draw();
  1198. heroList.draw();
  1199. infoBar.draw(NULL);
  1200. }