CAdvmapInterface.cpp 44 KB

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