CAdvmapInterface.cpp 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372
  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(const 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(const 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. MotionInterested::activate();
  298. };
  299. void CTerrainRect::deactivate()
  300. {
  301. ClickableL::deactivate();
  302. ClickableR::deactivate();
  303. Hoverable::deactivate();
  304. MotionInterested::deactivate();
  305. };
  306. void CTerrainRect::clickLeft(tribool down)
  307. {
  308. if ((down==false) || indeterminate(down))
  309. return;
  310. int3 mp = whichTileIsIt();
  311. if ((mp.x<0) || (mp.y<0))
  312. return;
  313. std::vector < const CGObjectInstance * > objs;
  314. if (LOCPLINT->adventureInt->selection->ID != HEROI_TYPE)
  315. {
  316. if (currentPath)
  317. {
  318. tlog2<<"Warning: Lost path?" << std::endl;
  319. delete currentPath;
  320. currentPath = NULL;
  321. }
  322. objs = LOCPLINT->cb->getBlockingObjs(mp);
  323. for(int i=0; i<objs.size();i++)
  324. {
  325. if(objs[i]->ID == 98 && objs[i]->tempOwner == LOCPLINT->playerID) //town
  326. {
  327. if(LOCPLINT->adventureInt->selection == (objs[i]))
  328. {
  329. LOCPLINT->openTownWindow(static_cast<const CGTownInstance*>(objs[i]));
  330. }
  331. else
  332. {
  333. LOCPLINT->adventureInt->select(static_cast<const CArmedInstance*>(objs[i]));
  334. return;
  335. }
  336. }
  337. else if(objs[i]->ID == 34 && objs[i]->tempOwner == LOCPLINT->playerID)
  338. {
  339. LOCPLINT->adventureInt->select(static_cast<const CArmedInstance*>(objs[i]));
  340. return;
  341. }
  342. }
  343. return;
  344. }
  345. else
  346. {
  347. objs = LOCPLINT->cb->getVisitableObjs(mp);
  348. for(int i=0; i<objs.size();i++)
  349. {
  350. if(objs[i]->ID == 98)
  351. goto endchkpt;
  352. }
  353. objs = LOCPLINT->cb->getBlockingObjs(mp);
  354. for(int i=0; i<objs.size();i++)
  355. {
  356. if(objs[i]->ID == 98 && objs[i]->tempOwner == LOCPLINT->playerID) //town
  357. {
  358. LOCPLINT->adventureInt->select(static_cast<const CArmedInstance*>(objs[i]));
  359. return;
  360. }
  361. else if(objs[i]->ID == 34 && objs[i]->tempOwner == LOCPLINT->playerID && LOCPLINT->adventureInt->selection == (objs[i]))
  362. {
  363. LOCPLINT->openHeroWindow(static_cast<const CGHeroInstance*>(objs[i]));
  364. return;
  365. }
  366. }
  367. }
  368. endchkpt:
  369. bool mres =true;
  370. if (currentPath)
  371. {
  372. if ( (currentPath->endPos()) == mp)
  373. { //move
  374. CPath sended(*currentPath); //temporary path - engine will operate on it
  375. LOCPLINT->pim->unlock();
  376. mres = LOCPLINT->cb->moveHero( ((const CGHeroInstance*)LOCPLINT->adventureInt->selection)->type->ID,&sended,1,0);
  377. LOCPLINT->pim->lock();
  378. if(mres)
  379. {
  380. delete currentPath;
  381. currentPath = NULL;
  382. LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.getPosOfHero(LOCPLINT->adventureInt->selection)].second = NULL;
  383. }
  384. }
  385. else
  386. {
  387. delete currentPath;
  388. currentPath=NULL;
  389. LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.getPosOfHero(LOCPLINT->adventureInt->selection)].second = NULL;
  390. }
  391. }
  392. const CGHeroInstance * currentHero = (LOCPLINT->adventureInt->heroList.items.size())?(LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].first):(NULL);
  393. if(currentHero)
  394. {
  395. int3 bufpos = currentHero->getPosition(false);
  396. if (mres)
  397. {
  398. vector<Coordinate>* p;
  399. p = CGI->pathf->GetPath(Coordinate(bufpos),Coordinate(mp),currentHero);
  400. //Convert to old format.
  401. currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->ConvertToOldFormat(p);
  402. delete p;
  403. }
  404. return;
  405. }
  406. }
  407. void CTerrainRect::clickRight(tribool down)
  408. {
  409. }
  410. void CTerrainRect::mouseMoved (const SDL_MouseMotionEvent & sEvent)
  411. {
  412. int3 pom=LOCPLINT->adventureInt->verifyPos(whichTileIsIt(sEvent.x,sEvent.y));
  413. if (pom!=curHoveredTile)
  414. curHoveredTile=pom;
  415. else
  416. return;
  417. std::vector<std::string> temp = LOCPLINT->cb->getObjDescriptions(pom);
  418. if (temp.size())
  419. {
  420. LOCPLINT->adventureInt->statusbar.print((*((temp.end())-1)));
  421. }
  422. else
  423. {
  424. LOCPLINT->adventureInt->statusbar.clear();
  425. }
  426. std::vector<const CGObjectInstance *> objs = LOCPLINT->cb->getVisitableObjs(pom);
  427. for(int i=0; i<objs.size();i++)
  428. {
  429. if(objs[i]->ID == 98) //town
  430. {
  431. CGI->curh->changeGraphic(0,0);
  432. return;
  433. }
  434. }
  435. objs = LOCPLINT->cb->getBlockingObjs(pom);
  436. for(int i=0; i<objs.size();i++)
  437. {
  438. if(objs[i]->ID == 98 && objs[i]->tempOwner == LOCPLINT->playerID) //town
  439. {
  440. CGI->curh->changeGraphic(0,3);
  441. return;
  442. }
  443. else if(objs[i]->ID == 34 //mouse over hero
  444. && (objs[i]==LOCPLINT->adventureInt->selection || LOCPLINT->adventureInt->selection->ID==98)
  445. && objs[i]->tempOwner == LOCPLINT->playerID) //this hero is selected or we've selected a town
  446. {
  447. CGI->curh->changeGraphic(0,2);
  448. return;
  449. }
  450. }
  451. CGI->curh->changeGraphic(0,0);
  452. }
  453. void CTerrainRect::hover(bool on)
  454. {
  455. if (!on)
  456. LOCPLINT->adventureInt->statusbar.clear();
  457. }
  458. void CTerrainRect::showPath()
  459. {
  460. for (int i=0;i<currentPath->nodes.size()-1;i++)
  461. {
  462. int pn=-1;//number of picture
  463. if (i==0) //last tile
  464. {
  465. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  466. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  467. if (x<0 || y<0 || x>pos.w || y>pos.h)
  468. continue;
  469. pn=0;
  470. }
  471. else
  472. {
  473. /*
  474. * notation of arrow direction:
  475. * 1 2 3
  476. * 4 5 6
  477. * 7 8 9
  478. * ie. 157 means an arrow from left upper tile to left bottom tile through 5 (all arrows go through 5 in this notation)
  479. */
  480. std::vector<CPathNode> & cv = currentPath->nodes;
  481. if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1) //15x
  482. {
  483. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //156
  484. {
  485. pn = 3;
  486. }
  487. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //159
  488. {
  489. pn = 12;
  490. }
  491. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //158
  492. {
  493. pn = 21;
  494. }
  495. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //157
  496. {
  497. pn = 22;
  498. }
  499. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //153
  500. {
  501. pn = 2;
  502. }
  503. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //154
  504. {
  505. pn = 23;
  506. }
  507. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //152
  508. {
  509. pn = 1;
  510. }
  511. }
  512. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1) //25x
  513. {
  514. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //253
  515. {
  516. pn = 2;
  517. }
  518. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //256
  519. {
  520. pn = 3;
  521. }
  522. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //259
  523. {
  524. pn = 4;
  525. }
  526. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //258
  527. {
  528. pn = 13;
  529. }
  530. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //257
  531. {
  532. pn = 22;
  533. }
  534. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //254
  535. {
  536. pn = 23;
  537. }
  538. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //251
  539. {
  540. pn = 24;
  541. }
  542. }
  543. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1) //35x
  544. {
  545. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  546. {
  547. pn = 5;
  548. }
  549. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  550. {
  551. pn = 14;
  552. }
  553. else if(cv[i-1].coord.x+1 == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y)
  554. {
  555. pn = 23;
  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 = 24;
  560. }
  561. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  562. {
  563. pn = 4;
  564. }
  565. }
  566. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y) //65x
  567. {
  568. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  569. {
  570. pn = 6;
  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 = 15;
  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 = 24;
  579. }
  580. }
  581. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1) //95x
  582. {
  583. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
  584. {
  585. pn = 7;
  586. }
  587. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  588. {
  589. pn = 16;
  590. }
  591. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  592. {
  593. pn = 17;
  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 = 6;
  598. }
  599. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  600. {
  601. pn = 18;
  602. }
  603. }
  604. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1) //85x
  605. {
  606. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  607. {
  608. pn = 6;
  609. }
  610. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
  611. {
  612. pn = 7;
  613. }
  614. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  615. {
  616. pn = 8;
  617. }
  618. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  619. {
  620. pn = 9;
  621. }
  622. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  623. {
  624. pn = 18;
  625. }
  626. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  627. {
  628. pn = 19;
  629. }
  630. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  631. {
  632. pn = 20;
  633. }
  634. }
  635. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1) //75x
  636. {
  637. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  638. {
  639. pn = 1;
  640. }
  641. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  642. {
  643. pn = 10;
  644. }
  645. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  646. {
  647. pn = 19;
  648. }
  649. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  650. {
  651. pn = 8;
  652. }
  653. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  654. {
  655. pn = 20;
  656. }
  657. }
  658. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y) //45x
  659. {
  660. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  661. {
  662. pn = 2;
  663. }
  664. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  665. {
  666. pn = 11;
  667. }
  668. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  669. {
  670. pn = 20;
  671. }
  672. }
  673. }
  674. if ( ((currentPath->nodes[i].dist)-(*(currentPath->nodes.end()-1)).dist) > ((const CGHeroInstance*)(LOCPLINT->adventureInt->selection))->movement)
  675. pn+=25;
  676. if (pn>=0)
  677. {
  678. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  679. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  680. if (x<0 || y<0 || x>pos.w || y>pos.h)
  681. continue;
  682. int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
  683. hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
  684. if (hvx<0 && hvy<0)
  685. {
  686. CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, screen, &genRect(32, 32, x, y));
  687. }
  688. else if(hvx<0)
  689. {
  690. CSDL_Ext::blit8bppAlphaTo24bpp
  691. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,0,0),
  692. screen,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,x,y));
  693. }
  694. else if (hvy<0)
  695. {
  696. CSDL_Ext::blit8bppAlphaTo24bpp
  697. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  698. screen,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  699. }
  700. else
  701. {
  702. CSDL_Ext::blit8bppAlphaTo24bpp
  703. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  704. screen,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  705. }
  706. }
  707. } //for (int i=0;i<currentPath->nodes.size()-1;i++)
  708. }
  709. void CTerrainRect::show()
  710. {
  711. SDL_Surface * teren = CGI->mh->terrainRect
  712. (LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
  713. tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim,
  714. &LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim,
  715. screen, &genRect(547, 594, 7, 6)
  716. );
  717. //SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));
  718. //SDL_FreeSurface(teren);
  719. if (currentPath && LOCPLINT->adventureInt->position.z==currentPath->startPos().z) //drawing path
  720. {
  721. showPath();
  722. }
  723. }
  724. int3 CTerrainRect::whichTileIsIt(const int & x, const int & y)
  725. {
  726. int3 ret;
  727. ret.x = LOCPLINT->adventureInt->position.x + ((LOCPLINT->current->motion.x-pos.x)/32);
  728. ret.y = LOCPLINT->adventureInt->position.y + ((LOCPLINT->current->motion.y-pos.y)/32);
  729. ret.z = LOCPLINT->adventureInt->position.z;
  730. return ret;
  731. }
  732. int3 CTerrainRect::whichTileIsIt()
  733. {
  734. return whichTileIsIt(LOCPLINT->current->motion.x,LOCPLINT->current->motion.y);
  735. }
  736. void CResDataBar::clickRight (tribool down)
  737. {
  738. }
  739. void CResDataBar::activate()
  740. {
  741. ClickableR::activate();
  742. }
  743. void CResDataBar::deactivate()
  744. {
  745. ClickableR::deactivate();
  746. }
  747. CResDataBar::CResDataBar()
  748. {
  749. bg = BitmapHandler::loadBitmap("ZRESBAR.bmp");
  750. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  751. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  752. pos = genRect(bg->h,bg->w,3,575);
  753. txtpos += (std::pair<int,int>(35,577)),(std::pair<int,int>(120,577)),(std::pair<int,int>(205,577)),
  754. (std::pair<int,int>(290,577)),(std::pair<int,int>(375,577)),(std::pair<int,int>(460,577)),
  755. (std::pair<int,int>(545,577)),(std::pair<int,int>(620,577));
  756. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63] + ": %s, " +
  757. CGI->generaltexth->allTexts[64] + ": %s";
  758. }
  759. CResDataBar::~CResDataBar()
  760. {
  761. SDL_FreeSurface(bg);
  762. }
  763. void CResDataBar::draw()
  764. {
  765. blitAt(bg,pos.x,pos.y);
  766. char * buf = new char[15];
  767. for (int i=0;i<7;i++)
  768. {
  769. SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
  770. printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly);
  771. }
  772. std::vector<std::string> temp;
  773. SDL_itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf);
  774. SDL_itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf);
  775. SDL_itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf);
  776. printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,GEOR13,zwykly);
  777. temp.clear();
  778. //updateRect(&pos,screen);
  779. delete[] buf;
  780. }
  781. CInfoBar::CInfoBar()
  782. {
  783. toNextTick = mode = pom = -1;
  784. pos.x=605;
  785. pos.y=389;
  786. pos.w=194;
  787. pos.h=186;
  788. day = CDefHandler::giveDef("NEWDAY.DEF");
  789. week1 = CDefHandler::giveDef("NEWWEEK1.DEF");
  790. week2 = CDefHandler::giveDef("NEWWEEK2.DEF");
  791. week3 = CDefHandler::giveDef("NEWWEEK3.DEF");
  792. week4 = CDefHandler::giveDef("NEWWEEK4.DEF");
  793. }
  794. CInfoBar::~CInfoBar()
  795. {
  796. delete day;
  797. delete week1;
  798. delete week2;
  799. delete week3;
  800. delete week4;
  801. }
  802. void CInfoBar::draw(const CGObjectInstance * specific)
  803. {
  804. if ((mode>=0) && mode<5)
  805. {
  806. blitAnim(mode);
  807. return;
  808. }
  809. else if (mode==5)
  810. {
  811. mode = -1;
  812. draw(LOCPLINT->adventureInt->selection);
  813. }
  814. if (!specific)
  815. specific = LOCPLINT->adventureInt->selection;
  816. if(!specific)
  817. return;
  818. if(specific->ID == 34) //hero
  819. {
  820. if(graphics->heroWins.find(specific->subID)!=graphics->heroWins.end())
  821. blitAt(graphics->heroWins[specific->subID],pos.x,pos.y);
  822. }
  823. else if (specific->ID == 98)
  824. {
  825. const CGTownInstance * t = static_cast<const CGTownInstance*>(specific);
  826. if(graphics->townWins.find(t->id)!=graphics->townWins.end())
  827. blitAt(graphics->townWins[t->id],pos.x,pos.y);
  828. }
  829. //SDL_Surface * todr = LOCPLINT->infoWin(specific);
  830. //if (!todr)
  831. // return;
  832. //blitAt(todr,pos.x,pos.y);
  833. //SDL_FreeSurface(todr);
  834. }
  835. CDefHandler * CInfoBar::getAnim(int mode)
  836. {
  837. switch(mode)
  838. {
  839. case 0:
  840. return day;
  841. break;
  842. case 1:
  843. return week1;
  844. break;
  845. case 2:
  846. return week2;
  847. break;
  848. case 3:
  849. return week3;
  850. break;
  851. case 4:
  852. return week4;
  853. break;
  854. default:
  855. return NULL;
  856. break;
  857. }
  858. }
  859. void CInfoBar::blitAnim(int mode)//0 - day, 1 - week
  860. {
  861. CDefHandler * anim = NULL;
  862. std::stringstream txt;
  863. anim = getAnim(mode);
  864. if(mode) //new week animation
  865. {
  866. txt << CGI->generaltexth->allTexts[63] << " " << LOCPLINT->cb->getDate(2);
  867. }
  868. else //new day
  869. {
  870. txt << CGI->generaltexth->allTexts[64] << " " << LOCPLINT->cb->getDate(1);
  871. }
  872. blitAt(anim->ourImages[pom].bitmap,pos.x+9,pos.y+10);
  873. printAtMiddle(txt.str(),700,420,TNRB16,zwykly);
  874. if (pom == anim->ourImages.size()-1)
  875. toNextTick+=750;
  876. }
  877. void CInfoBar::newDay(int Day)
  878. {
  879. if(LOCPLINT->cb->getDate(1) != 1)
  880. {
  881. mode = 0; //showing day
  882. }
  883. else
  884. {
  885. switch(LOCPLINT->cb->getDate(2))
  886. {
  887. case 1:
  888. mode = 1;
  889. break;
  890. case 2:
  891. mode = 2;
  892. break;
  893. case 3:
  894. mode = 3;
  895. break;
  896. case 4:
  897. mode = 4;
  898. break;
  899. default:
  900. mode = -1;
  901. break;
  902. }
  903. }
  904. pom = 0;
  905. TimeInterested::activate();
  906. toNextTick = 500;
  907. blitAnim(mode);
  908. //blitAt(day->ourImages[pom].bitmap,pos.x+10,pos.y+10);
  909. }
  910. void CInfoBar::showComp(SComponent * comp, int time)
  911. {
  912. SDL_Surface * b = BitmapHandler::loadBitmap("ADSTATOT.bmp");
  913. blitAt(b,pos.x+8,pos.y+11);
  914. blitAt(comp->getImg(),pos.x+52,pos.y+54);
  915. printAtMiddle(comp->subtitle,pos.x+91,pos.y+158,GEOR13,zwykly);
  916. printAtMiddleWB(comp->description,pos.x+94,pos.y+31,GEOR13,26,zwykly);
  917. SDL_FreeSurface(b);
  918. TimeInterested::activate();
  919. mode = 6;
  920. toNextTick = time;
  921. }
  922. void CInfoBar::tick()
  923. {
  924. if((mode >= 0) && (mode < 5))
  925. {
  926. pom++;
  927. if (pom >= getAnim(mode)->ourImages.size())
  928. {
  929. TimeInterested::deactivate();
  930. toNextTick = -1;
  931. mode = 5;
  932. draw();
  933. return;
  934. }
  935. toNextTick = 150;
  936. blitAnim(mode);
  937. }
  938. else if (mode == 6)
  939. {
  940. TimeInterested::deactivate();
  941. toNextTick = -1;
  942. mode = 5;
  943. draw();
  944. }
  945. }
  946. CAdvMapInt::CAdvMapInt(int Player)
  947. :player(Player),
  948. statusbar(7,556),
  949. kingOverview(CGI->preth->zelp[293].first,CGI->preth->zelp[293].second,
  950. boost::bind(&CAdvMapInt::fshowOverview,this), 679, 196, "IAM002.DEF", SDLK_k, NULL,true),
  951. underground(CGI->preth->zelp[294].first,CGI->preth->zelp[294].second,
  952. boost::bind(&CAdvMapInt::fswitchLevel,this), 711, 196, "IAM010.DEF", SDLK_u, new std::vector<std::string>(1,std::string("IAM003.DEF")),true),
  953. questlog(CGI->preth->zelp[295].first,CGI->preth->zelp[295].second,
  954. boost::bind(&CAdvMapInt::fshowQuestlog,this), 679, 228, "IAM004.DEF", SDLK_q, NULL,true),
  955. sleepWake(CGI->preth->zelp[296].first,CGI->preth->zelp[296].second,
  956. boost::bind(&CAdvMapInt::fsleepWake,this), 711, 228, "IAM005.DEF", SDLK_w, NULL,true),
  957. moveHero(CGI->preth->zelp[297].first,CGI->preth->zelp[297].second,
  958. boost::bind(&CAdvMapInt::fmoveHero,this), 679, 260, "IAM006.DEF", SDLK_m, NULL,true),
  959. spellbook(CGI->preth->zelp[298].first,CGI->preth->zelp[298].second,
  960. boost::bind(&CAdvMapInt::fshowSpellbok,this), 711, 260, "IAM007.DEF", SDLK_c, NULL,true),
  961. advOptions(CGI->preth->zelp[299].first,CGI->preth->zelp[299].second,
  962. boost::bind(&CAdvMapInt::fadventureOPtions,this), 679, 292, "IAM008.DEF", SDLK_a, NULL,true),
  963. sysOptions(CGI->preth->zelp[300].first,CGI->preth->zelp[300].second,
  964. boost::bind(&CAdvMapInt::fsystemOptions,this), 711, 292, "IAM009.DEF", SDLK_o, NULL,true),
  965. nextHero(CGI->preth->zelp[301].first,CGI->preth->zelp[301].second,
  966. boost::bind(&CAdvMapInt::fnextHero,this), 679, 324, "IAM000.DEF", SDLK_h, NULL,true),
  967. endTurn(CGI->preth->zelp[302].first,CGI->preth->zelp[302].second,
  968. boost::bind(&CAdvMapInt::fendTurn,this), 679, 356, "IAM001.DEF", SDLK_e, NULL,true),
  969. townList(5,&genRect(192,48,747,196),747,196,747,372)
  970. {
  971. selection = NULL;
  972. townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this);
  973. LOCPLINT->adventureInt=this;
  974. bg = BitmapHandler::loadBitmap("ADVMAP.bmp");
  975. graphics->blueToPlayersAdv(bg,player);
  976. scrollingLeft = false;
  977. scrollingRight = false;
  978. scrollingUp = false ;
  979. scrollingDown = false ;
  980. updateScreen = false;
  981. anim=0;
  982. animValHitCount=0; //animation frame
  983. heroAnim=0;
  984. heroAnimValHitCount=0; // hero animation frame
  985. heroList.init();
  986. heroList.genList();
  987. //townList.init();
  988. townList.genList();
  989. heroWindow = new CHeroWindow(this->player);
  990. gems.push_back(CDefHandler::giveDef("agemLL.def"));
  991. gems.push_back(CDefHandler::giveDef("agemLR.def"));
  992. gems.push_back(CDefHandler::giveDef("agemUL.def"));
  993. gems.push_back(CDefHandler::giveDef("agemUR.def"));
  994. }
  995. void CAdvMapInt::fshowOverview()
  996. {
  997. }
  998. void CAdvMapInt::fswitchLevel()
  999. {
  1000. if(!CGI->mh->map->twoLevel)
  1001. return;
  1002. if (position.z)
  1003. {
  1004. position.z--;
  1005. underground.curimg=0;
  1006. underground.show();
  1007. }
  1008. else
  1009. {
  1010. underground.curimg=1;
  1011. position.z++;
  1012. underground.show();
  1013. }
  1014. updateScreen = true;
  1015. minimap.draw();
  1016. }
  1017. void CAdvMapInt::fshowQuestlog()
  1018. {
  1019. }
  1020. void CAdvMapInt::fsleepWake()
  1021. {
  1022. }
  1023. void CAdvMapInt::fmoveHero()
  1024. {
  1025. if (selection->ID!=HEROI_TYPE)
  1026. return;
  1027. if (!terrain.currentPath)
  1028. return;
  1029. CPath sended(*(terrain.currentPath)); //temporary path - engine will operate on it
  1030. LOCPLINT->pim->unlock();
  1031. LOCPLINT->cb->moveHero( ((const CGHeroInstance*)LOCPLINT->adventureInt->selection)->type->ID,&sended,1,0);
  1032. LOCPLINT->pim->lock();
  1033. }
  1034. void CAdvMapInt::fshowSpellbok()
  1035. {
  1036. if (selection->ID!=HEROI_TYPE) //checking necessary values
  1037. return;
  1038. LOCPLINT->curint->deactivate();
  1039. CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, 90, 2), ((const CGHeroInstance*)LOCPLINT->adventureInt->selection));
  1040. spellWindow->activate();
  1041. LOCPLINT->objsToBlit.push_back(spellWindow);
  1042. }
  1043. void CAdvMapInt::fadventureOPtions()
  1044. {
  1045. }
  1046. void CAdvMapInt::fsystemOptions()
  1047. {
  1048. LOCPLINT->curint->deactivate();
  1049. CSystemOptionsWindow * sysopWindow = new CSystemOptionsWindow(genRect(487, 481, 159, 57), LOCPLINT);
  1050. sysopWindow->activate();
  1051. LOCPLINT->objsToBlit.push_back(sysopWindow);
  1052. }
  1053. void CAdvMapInt::fnextHero()
  1054. {
  1055. }
  1056. void CAdvMapInt::fendTurn()
  1057. {
  1058. LOCPLINT->makingTurn = false;
  1059. }
  1060. void CAdvMapInt::activate()
  1061. {
  1062. if(subInt == heroWindow)
  1063. {
  1064. heroWindow->activate();
  1065. return;
  1066. }
  1067. LOCPLINT->curint = this;
  1068. LOCPLINT->statusbar = &statusbar;
  1069. kingOverview.activate();
  1070. underground.activate();
  1071. questlog.activate();
  1072. sleepWake.activate();
  1073. moveHero.activate();
  1074. spellbook.activate();
  1075. sysOptions.activate();
  1076. advOptions.activate();
  1077. nextHero.activate();
  1078. endTurn.activate();
  1079. minimap.activate();
  1080. heroList.activate();
  1081. townList.activate();
  1082. terrain.activate();
  1083. KeyInterested::activate();
  1084. show();
  1085. }
  1086. void CAdvMapInt::deactivate()
  1087. {
  1088. KeyInterested::deactivate();
  1089. if(subInt == heroWindow)
  1090. {
  1091. heroWindow->deactivate();
  1092. return;
  1093. }
  1094. hide();
  1095. }
  1096. void CAdvMapInt::show(SDL_Surface *to)
  1097. {
  1098. blitAt(bg,0,0);
  1099. kingOverview.show();
  1100. underground.show();
  1101. questlog.show();
  1102. sleepWake.show();
  1103. moveHero.show();
  1104. spellbook.show();
  1105. advOptions.show();
  1106. sysOptions.show();
  1107. nextHero.show();
  1108. endTurn.show();
  1109. minimap.draw();
  1110. heroList.draw();
  1111. townList.draw();
  1112. updateScreen = true;
  1113. update();
  1114. resdatabar.draw();
  1115. statusbar.show();
  1116. infoBar.draw();
  1117. }
  1118. void CAdvMapInt::hide()
  1119. {
  1120. CGI->curh->changeGraphic(0,0);
  1121. kingOverview.deactivate();
  1122. underground.deactivate();
  1123. questlog.deactivate();
  1124. sleepWake.deactivate();
  1125. moveHero.deactivate();
  1126. spellbook.deactivate();
  1127. advOptions.deactivate();
  1128. sysOptions.deactivate();
  1129. nextHero.deactivate();
  1130. endTurn.deactivate();
  1131. minimap.deactivate();
  1132. heroList.deactivate();
  1133. townList.deactivate();
  1134. terrain.deactivate();
  1135. if(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar)!=LOCPLINT->timeinterested.end())
  1136. LOCPLINT->timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar));
  1137. infoBar.mode=-1;
  1138. }
  1139. void CAdvMapInt::update()
  1140. {
  1141. ++animValHitCount; //for animations
  1142. if(animValHitCount == 8)
  1143. {
  1144. animValHitCount = 0;
  1145. ++anim;
  1146. updateScreen = true;
  1147. }
  1148. ++heroAnim;
  1149. if((animValHitCount % 4) && !LOCPLINT->showingDialog->get())
  1150. {
  1151. if(scrollingLeft)
  1152. {
  1153. if(position.x>-Woff)
  1154. {
  1155. position.x--;
  1156. updateScreen = true;
  1157. updateMinimap=true;
  1158. }
  1159. }
  1160. if(scrollingRight)
  1161. {
  1162. if(position.x<CGI->mh->map->width-19+4)
  1163. {
  1164. position.x++;
  1165. updateScreen = true;
  1166. updateMinimap=true;
  1167. }
  1168. }
  1169. if(scrollingUp)
  1170. {
  1171. if(position.y>-Hoff)
  1172. {
  1173. position.y--;
  1174. updateScreen = true;
  1175. updateMinimap=true;
  1176. }
  1177. }
  1178. if(scrollingDown)
  1179. {
  1180. if(position.y<CGI->mh->map->height-18+4)
  1181. {
  1182. position.y++;
  1183. updateScreen = true;
  1184. updateMinimap=true;
  1185. }
  1186. }
  1187. }
  1188. if(updateScreen)
  1189. {
  1190. terrain.show();
  1191. blitAt(gems[2]->ourImages[LOCPLINT->playerID].bitmap,6,6);
  1192. blitAt(gems[0]->ourImages[LOCPLINT->playerID].bitmap,6,508);
  1193. blitAt(gems[1]->ourImages[LOCPLINT->playerID].bitmap,556,508);
  1194. blitAt(gems[3]->ourImages[LOCPLINT->playerID].bitmap,556,6);
  1195. updateScreen=false;
  1196. }
  1197. if (updateMinimap)
  1198. {
  1199. minimap.draw();
  1200. updateMinimap=false;
  1201. }
  1202. }
  1203. void CAdvMapInt::selectionChanged()
  1204. {
  1205. const CGTownInstance *to = townList.items[townList.selected];
  1206. select(to);
  1207. }
  1208. void CAdvMapInt::centerOn(int3 on)
  1209. {
  1210. on.x -= (LOCPLINT->adventureInt->terrain.tilesw/2);
  1211. on.y -= (LOCPLINT->adventureInt->terrain.tilesh/2);
  1212. if (on.x<0)
  1213. on.x=-(Woff/2);
  1214. else if((on.x+LOCPLINT->adventureInt->terrain.tilesw) > (CGI->mh->sizes.x))
  1215. on.x=CGI->mh->sizes.x-LOCPLINT->adventureInt->terrain.tilesw+(Woff/2);
  1216. if (on.y<0)
  1217. on.y = -(Hoff/2);
  1218. else if((on.y+LOCPLINT->adventureInt->terrain.tilesh) > (CGI->mh->sizes.y))
  1219. on.y = CGI->mh->sizes.y-LOCPLINT->adventureInt->terrain.tilesh+(Hoff/2);
  1220. LOCPLINT->adventureInt->position.x=on.x;
  1221. LOCPLINT->adventureInt->position.y=on.y;
  1222. LOCPLINT->adventureInt->position.z=on.z;
  1223. LOCPLINT->adventureInt->updateScreen=true;
  1224. updateMinimap=true;
  1225. }
  1226. void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
  1227. {
  1228. bool CAdvMapInt::* scrollDir;
  1229. switch(key.keysym.sym)
  1230. {
  1231. case SDLK_UP:
  1232. scrollDir = &CAdvMapInt::scrollingUp;
  1233. break;
  1234. case SDLK_LEFT:
  1235. scrollDir = &CAdvMapInt::scrollingLeft;
  1236. break;
  1237. case SDLK_RIGHT:
  1238. scrollDir = &CAdvMapInt::scrollingRight;
  1239. break;
  1240. case SDLK_DOWN:
  1241. scrollDir = &CAdvMapInt::scrollingDown;
  1242. break;
  1243. default:
  1244. return;
  1245. }
  1246. this->*scrollDir = key.state==SDL_PRESSED;
  1247. }
  1248. void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * client)
  1249. {
  1250. if (down)
  1251. {
  1252. boost::algorithm::erase_all(text,"\"");
  1253. CSimpleWindow * temp = CMessage::genWindow(text,LOCPLINT->playerID);
  1254. temp->pos.x=300-(temp->pos.w/2);
  1255. temp->pos.y=300-(temp->pos.h/2);
  1256. temp->owner = client;
  1257. LOCPLINT->objsToBlit.push_back(temp);
  1258. }
  1259. else
  1260. {
  1261. for (int i=0;i<LOCPLINT->objsToBlit.size();i++)
  1262. {
  1263. //TODO: pewnie da sie to zrobic lepiej, ale nie chce mi sie. Wolajacy obiekt powinien informowac kogo spodziewa sie odwolac (null jesli down)
  1264. CSimpleWindow * pom = dynamic_cast<CSimpleWindow*>(LOCPLINT->objsToBlit[i]);
  1265. if (!pom)
  1266. continue;
  1267. if (pom->owner==client)
  1268. {
  1269. LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+(i));
  1270. delete pom;
  1271. if((LOCPLINT->curint == LOCPLINT->castleInt) && !LOCPLINT->castleInt->subInt)
  1272. LOCPLINT->castleInt->showAll(0,true);
  1273. }
  1274. }
  1275. }
  1276. }
  1277. int3 CAdvMapInt::verifyPos(int3 ver)
  1278. {
  1279. if (ver.x<0)
  1280. ver.x=0;
  1281. if (ver.y<0)
  1282. ver.y=0;
  1283. if (ver.z<0)
  1284. ver.z=0;
  1285. if (ver.x>=CGI->mh->sizes.x)
  1286. ver.x=CGI->mh->sizes.x-1;
  1287. if (ver.y>=CGI->mh->sizes.y)
  1288. ver.y=CGI->mh->sizes.y-1;
  1289. if (ver.z>=CGI->mh->sizes.z)
  1290. ver.z=CGI->mh->sizes.z-1;
  1291. return ver;
  1292. }
  1293. void CAdvMapInt::select(const CArmedInstance *sel )
  1294. {
  1295. LOCPLINT->cb->setSelection(sel);
  1296. centerOn(sel->pos);
  1297. selection = sel;
  1298. if(sel->ID==98)
  1299. {
  1300. int pos = vstd::findPos(townList.items,sel);
  1301. townList.selected = pos;
  1302. terrain.currentPath = NULL;
  1303. }
  1304. else
  1305. {
  1306. int pos = heroList.getPosOfHero(sel);
  1307. heroList.selected = pos;
  1308. terrain.currentPath = heroList.items[pos].second;
  1309. }
  1310. townList.draw();
  1311. heroList.draw();
  1312. infoBar.draw(NULL);
  1313. }