CAdvmapInterface.cpp 36 KB

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