CAdvmapInterface.cpp 36 KB

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