CAdvmapInterface.cpp 34 KB

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