CAdvmapInterface.cpp 44 KB

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