2
0

CAdvmapInterface.cpp 42 KB

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