CAdvmapInterface.cpp 40 KB

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