CAdvmapInterface.cpp 36 KB

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