CAdvmapInterface.cpp 38 KB

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