CAdvmapInterface.cpp 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548
  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 == TOWNI_TYPE && 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 == HEROI_TYPE && 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 == TOWNI_TYPE)
  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 == TOWNI_TYPE && 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 == HEROI_TYPE && 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 HEROI_TYPE:
  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 TOWNI_TYPE:
  450. {
  451. if(!vstd::contains(graphics->townWins,obj->id))
  452. {
  453. tlog3 << "Warning - no infowin for town " << obj->id << 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. boost::replace_all(temp.back(),"\n"," ");
  481. LOCPLINT->adventureInt->statusbar.print(temp.back());
  482. }
  483. else
  484. {
  485. LOCPLINT->adventureInt->statusbar.clear();
  486. }
  487. std::vector<const CGObjectInstance *> objs = LOCPLINT->cb->getVisitableObjs(pom);
  488. for(int i=0; i<objs.size();i++)
  489. {
  490. if(objs[i]->ID == TOWNI_TYPE) //town
  491. {
  492. CGI->curh->changeGraphic(0,0);
  493. return;
  494. }
  495. }
  496. objs = LOCPLINT->cb->getBlockingObjs(pom);
  497. for(size_t i=0; i < objs.size(); ++i)
  498. {
  499. if(objs[i]->ID == TOWNI_TYPE && objs[i]->tempOwner == LOCPLINT->playerID) //town
  500. {
  501. CGI->curh->changeGraphic(0,3);
  502. return;
  503. }
  504. else if(objs[i]->ID == HEROI_TYPE //mouse over hero
  505. && (objs[i]==LOCPLINT->adventureInt->selection || LOCPLINT->adventureInt->selection->ID==TOWNI_TYPE)
  506. && objs[i]->tempOwner == LOCPLINT->playerID) //this hero is selected or we've selected a town
  507. {
  508. CGI->curh->changeGraphic(0,2);
  509. return;
  510. }
  511. }
  512. CGI->curh->changeGraphic(0,0);
  513. }
  514. void CTerrainRect::hover(bool on)
  515. {
  516. if (!on)
  517. LOCPLINT->adventureInt->statusbar.clear();
  518. }
  519. void CTerrainRect::showPath(const SDL_Rect * extRect)
  520. {
  521. for (size_t i=0; i < currentPath->nodes.size()-1; ++i)
  522. {
  523. int pn=-1;//number of picture
  524. if (i==0) //last tile
  525. {
  526. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  527. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  528. if (x<0 || y<0 || x>pos.w || y>pos.h)
  529. continue;
  530. pn=0;
  531. }
  532. else
  533. {
  534. /*
  535. * notation of arrow direction:
  536. * 1 2 3
  537. * 4 5 6
  538. * 7 8 9
  539. * ie. 157 means an arrow from left upper tile to left bottom tile through 5 (all arrows go through 5 in this notation)
  540. */
  541. std::vector<CPathNode> & cv = currentPath->nodes;
  542. if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1) //15x
  543. {
  544. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //156
  545. {
  546. pn = 3;
  547. }
  548. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //159
  549. {
  550. pn = 12;
  551. }
  552. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //158
  553. {
  554. pn = 21;
  555. }
  556. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //157
  557. {
  558. pn = 22;
  559. }
  560. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //153
  561. {
  562. pn = 2;
  563. }
  564. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //154
  565. {
  566. pn = 23;
  567. }
  568. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //152
  569. {
  570. pn = 1;
  571. }
  572. }
  573. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1) //25x
  574. {
  575. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //253
  576. {
  577. pn = 2;
  578. }
  579. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //256
  580. {
  581. pn = 3;
  582. }
  583. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //259
  584. {
  585. pn = 4;
  586. }
  587. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //258
  588. {
  589. pn = 13;
  590. }
  591. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //257
  592. {
  593. pn = 22;
  594. }
  595. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //254
  596. {
  597. pn = 23;
  598. }
  599. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //251
  600. {
  601. pn = 24;
  602. }
  603. }
  604. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1) //35x
  605. {
  606. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //358
  607. {
  608. pn = 5;
  609. }
  610. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //357
  611. {
  612. pn = 14;
  613. }
  614. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //354
  615. {
  616. pn = 23;
  617. }
  618. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //351
  619. {
  620. pn = 24;
  621. }
  622. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //359
  623. {
  624. pn = 4;
  625. }
  626. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //356
  627. {
  628. pn = 3;
  629. }
  630. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //352
  631. {
  632. pn = 17;
  633. }
  634. }
  635. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y) //65x
  636. {
  637. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //657
  638. {
  639. pn = 6;
  640. }
  641. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //654
  642. {
  643. pn = 15;
  644. }
  645. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //651
  646. {
  647. pn = 24;
  648. }
  649. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //652
  650. {
  651. pn = 17;
  652. }
  653. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //658
  654. {
  655. pn = 5;
  656. }
  657. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //653
  658. {
  659. pn = 18;
  660. }
  661. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //659
  662. {
  663. pn = 4;
  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) //95x
  667. {
  668. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //954
  669. {
  670. pn = 7;
  671. }
  672. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //951
  673. {
  674. pn = 16;
  675. }
  676. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //952
  677. {
  678. pn = 17;
  679. }
  680. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //957
  681. {
  682. pn = 6;
  683. }
  684. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //953
  685. {
  686. pn = 18;
  687. }
  688. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //956
  689. {
  690. pn = 19;
  691. }
  692. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //958
  693. {
  694. pn = 5;
  695. }
  696. }
  697. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1) //85x
  698. {
  699. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //857
  700. {
  701. pn = 6;
  702. }
  703. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y) //854
  704. {
  705. pn = 7;
  706. }
  707. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //851
  708. {
  709. pn = 8;
  710. }
  711. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //852
  712. {
  713. pn = 9;
  714. }
  715. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //853
  716. {
  717. pn = 18;
  718. }
  719. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //856
  720. {
  721. pn = 19;
  722. }
  723. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //859
  724. {
  725. pn = 20;
  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) //75x
  729. {
  730. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //752
  731. {
  732. pn = 1;
  733. }
  734. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //753
  735. {
  736. pn = 10;
  737. }
  738. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //756
  739. {
  740. pn = 19;
  741. }
  742. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //751
  743. {
  744. pn = 8;
  745. }
  746. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //759
  747. {
  748. pn = 20;
  749. }
  750. }
  751. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y) //45x
  752. {
  753. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1) //453
  754. {
  755. pn = 2;
  756. }
  757. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y) //456
  758. {
  759. pn = 11;
  760. }
  761. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1) //459
  762. {
  763. pn = 20;
  764. }
  765. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1) //452
  766. {
  767. pn = 1;
  768. }
  769. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1) //456
  770. {
  771. pn = 21;
  772. }
  773. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1) //451
  774. {
  775. pn = 8;
  776. }
  777. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1) //457
  778. {
  779. pn = 22;
  780. }
  781. }
  782. }
  783. if ( ((currentPath->nodes[i].dist)-(*(currentPath->nodes.end()-1)).dist) > ((const CGHeroInstance*)(LOCPLINT->adventureInt->selection))->movement)
  784. pn+=25;
  785. if (pn>=0)
  786. {
  787. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  788. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  789. if (x<0 || y<0 || x>pos.w || y>pos.h)
  790. continue;
  791. int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
  792. hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
  793. SDL_Rect prevClip;
  794. SDL_GetClipRect(screen, &prevClip);
  795. SDL_SetClipRect(screen, extRect); //preventing blitting outside of that rect
  796. if(ADVOPT.smoothMove) //version for smooth hero move, with pos shifts
  797. {
  798. if (hvx<0 && hvy<0)
  799. {
  800. CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, screen, &genRect(32, 32, x + moveX, y + moveY));
  801. }
  802. else if(hvx<0)
  803. {
  804. CSDL_Ext::blit8bppAlphaTo24bpp
  805. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0),
  806. screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x + moveX, y + moveY));
  807. }
  808. else if (hvy<0)
  809. {
  810. CSDL_Ext::blit8bppAlphaTo24bpp
  811. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0),
  812. screen, &genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY));
  813. }
  814. else
  815. {
  816. CSDL_Ext::blit8bppAlphaTo24bpp
  817. (arrows->ourImages[pn].bitmap, &genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx, 0, 0),
  818. screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY));
  819. }
  820. }
  821. else //standard version
  822. {
  823. if (hvx<0 && hvy<0)
  824. {
  825. CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, screen, &genRect(32, 32, x, y));
  826. }
  827. else if(hvx<0)
  828. {
  829. CSDL_Ext::blit8bppAlphaTo24bpp
  830. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0),
  831. screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x, y));
  832. }
  833. else if (hvy<0)
  834. {
  835. CSDL_Ext::blit8bppAlphaTo24bpp
  836. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0),
  837. screen, &genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x, y));
  838. }
  839. else
  840. {
  841. CSDL_Ext::blit8bppAlphaTo24bpp
  842. (arrows->ourImages[pn].bitmap, &genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx, 0, 0),
  843. screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x, y));
  844. }
  845. }
  846. SDL_SetClipRect(screen, &prevClip);
  847. }
  848. } //for (int i=0;i<currentPath->nodes.size()-1;i++)
  849. }
  850. void CTerrainRect::show()
  851. {
  852. CGI->mh->terrainRect
  853. (LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
  854. tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim,
  855. &LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim,
  856. screen, &genRect(pos.h, pos.w, pos.x, pos.y), moveX, moveY, ADVOPT.smoothMove && (moveX != 0 || moveY != 0)
  857. );
  858. //SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));
  859. //SDL_FreeSurface(teren);
  860. if (currentPath && LOCPLINT->adventureInt->position.z==currentPath->startPos().z) //drawing path
  861. {
  862. showPath(&genRect(pos.h, pos.w, pos.x, pos.y));
  863. }
  864. }
  865. int3 CTerrainRect::whichTileIsIt(const int & x, const int & y)
  866. {
  867. int3 ret;
  868. ret.x = LOCPLINT->adventureInt->position.x + ((LOCPLINT->current->motion.x-pos.x)/32);
  869. ret.y = LOCPLINT->adventureInt->position.y + ((LOCPLINT->current->motion.y-pos.y)/32);
  870. ret.z = LOCPLINT->adventureInt->position.z;
  871. return ret;
  872. }
  873. int3 CTerrainRect::whichTileIsIt()
  874. {
  875. return whichTileIsIt(LOCPLINT->current->motion.x,LOCPLINT->current->motion.y);
  876. }
  877. void CResDataBar::clickRight (tribool down)
  878. {
  879. }
  880. void CResDataBar::activate()
  881. {
  882. ClickableR::activate();
  883. }
  884. void CResDataBar::deactivate()
  885. {
  886. ClickableR::deactivate();
  887. }
  888. CResDataBar::CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist)
  889. {
  890. bg = BitmapHandler::loadBitmap(defname);
  891. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  892. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  893. pos = genRect(bg->h,bg->w,x,y);
  894. txtpos.resize(8);
  895. for (int i = 0; i < 8 ; i++)
  896. {
  897. txtpos[i].first = pos.x + offx + resdist*i;
  898. txtpos[i].second = pos.y + offy;
  899. }
  900. txtpos[7].first = txtpos[6].first + datedist;
  901. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63]
  902. + ": %s, " + CGI->generaltexth->allTexts[64] + ": %s";
  903. }
  904. CResDataBar::CResDataBar()
  905. {
  906. bg = BitmapHandler::loadBitmap(ADVOPT.resdatabarG);
  907. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  908. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  909. pos = genRect(bg->h,bg->w,ADVOPT.resdatabarX,ADVOPT.resdatabarY);
  910. txtpos.resize(8);
  911. for (int i = 0; i < 8 ; i++)
  912. {
  913. txtpos[i].first = pos.x + ADVOPT.resOffsetX + ADVOPT.resDist*i;
  914. txtpos[i].second = pos.y + ADVOPT.resOffsetY;
  915. }
  916. txtpos[7].first = txtpos[6].first + ADVOPT.resDateDist;
  917. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63]
  918. + ": %s, " + CGI->generaltexth->allTexts[64] + ": %s";
  919. }
  920. CResDataBar::~CResDataBar()
  921. {
  922. SDL_FreeSurface(bg);
  923. }
  924. void CResDataBar::draw()
  925. {
  926. blitAt(bg,pos.x,pos.y);
  927. char * buf = new char[15];
  928. for (int i=0;i<7;i++)
  929. {
  930. SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
  931. printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly);
  932. }
  933. std::vector<std::string> temp;
  934. SDL_itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf);
  935. SDL_itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf);
  936. SDL_itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf);
  937. printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,GEOR13,zwykly);
  938. temp.clear();
  939. //updateRect(&pos,screen);
  940. delete[] buf;
  941. }
  942. CInfoBar::CInfoBar()
  943. {
  944. toNextTick = mode = pom = -1;
  945. pos.x=ADVOPT.infoboxX;
  946. pos.y=ADVOPT.infoboxY;
  947. pos.w=194;
  948. pos.h=186;
  949. day = CDefHandler::giveDef("NEWDAY.DEF");
  950. week1 = CDefHandler::giveDef("NEWWEEK1.DEF");
  951. week2 = CDefHandler::giveDef("NEWWEEK2.DEF");
  952. week3 = CDefHandler::giveDef("NEWWEEK3.DEF");
  953. week4 = CDefHandler::giveDef("NEWWEEK4.DEF");
  954. }
  955. CInfoBar::~CInfoBar()
  956. {
  957. delete day;
  958. delete week1;
  959. delete week2;
  960. delete week3;
  961. delete week4;
  962. }
  963. void CInfoBar::draw(const CGObjectInstance * specific)
  964. {
  965. if ((mode>=0) && mode<5)
  966. {
  967. blitAnim(mode);
  968. return;
  969. }
  970. else if (mode==5)
  971. {
  972. mode = -1;
  973. draw(LOCPLINT->adventureInt->selection);
  974. }
  975. if (!specific)
  976. specific = LOCPLINT->adventureInt->selection;
  977. if(!specific)
  978. return;
  979. if(specific->ID == HEROI_TYPE) //hero
  980. {
  981. if(graphics->heroWins.find(specific->subID)!=graphics->heroWins.end())
  982. blitAt(graphics->heroWins[specific->subID],pos.x,pos.y);
  983. }
  984. else if (specific->ID == TOWNI_TYPE)
  985. {
  986. const CGTownInstance * t = static_cast<const CGTownInstance*>(specific);
  987. if(graphics->townWins.find(t->id)!=graphics->townWins.end())
  988. blitAt(graphics->townWins[t->id],pos.x,pos.y);
  989. }
  990. //SDL_Surface * todr = LOCPLINT->infoWin(specific);
  991. //if (!todr)
  992. // return;
  993. //blitAt(todr,pos.x,pos.y);
  994. //SDL_FreeSurface(todr);
  995. }
  996. CDefHandler * CInfoBar::getAnim(int mode)
  997. {
  998. switch(mode)
  999. {
  1000. case 0:
  1001. return day;
  1002. break;
  1003. case 1:
  1004. return week1;
  1005. break;
  1006. case 2:
  1007. return week2;
  1008. break;
  1009. case 3:
  1010. return week3;
  1011. break;
  1012. case 4:
  1013. return week4;
  1014. break;
  1015. default:
  1016. return NULL;
  1017. break;
  1018. }
  1019. }
  1020. void CInfoBar::blitAnim(int mode)//0 - day, 1 - week
  1021. {
  1022. CDefHandler * anim = NULL;
  1023. std::stringstream txt;
  1024. anim = getAnim(mode);
  1025. if(mode) //new week animation
  1026. {
  1027. txt << CGI->generaltexth->allTexts[63] << " " << LOCPLINT->cb->getDate(2);
  1028. }
  1029. else //new day
  1030. {
  1031. txt << CGI->generaltexth->allTexts[64] << " " << LOCPLINT->cb->getDate(1);
  1032. }
  1033. blitAt(anim->ourImages[pom].bitmap,pos.x+9,pos.y+10);
  1034. printAtMiddle(txt.str(),pos.x+95,pos.y+31,TNRB16,zwykly);
  1035. if (pom == anim->ourImages.size()-1)
  1036. toNextTick+=750;
  1037. }
  1038. void CInfoBar::newDay(int Day)
  1039. {
  1040. if(LOCPLINT->cb->getDate(1) != 1)
  1041. {
  1042. mode = 0; //showing day
  1043. }
  1044. else
  1045. {
  1046. switch(LOCPLINT->cb->getDate(2))
  1047. {
  1048. case 1:
  1049. mode = 1;
  1050. break;
  1051. case 2:
  1052. mode = 2;
  1053. break;
  1054. case 3:
  1055. mode = 3;
  1056. break;
  1057. case 4:
  1058. mode = 4;
  1059. break;
  1060. default:
  1061. mode = -1;
  1062. break;
  1063. }
  1064. }
  1065. pom = 0;
  1066. TimeInterested::activate();
  1067. toNextTick = 500;
  1068. blitAnim(mode);
  1069. //blitAt(day->ourImages[pom].bitmap,pos.x+10,pos.y+10);
  1070. }
  1071. void CInfoBar::showComp(SComponent * comp, int time)
  1072. {
  1073. SDL_Surface * b = BitmapHandler::loadBitmap("ADSTATOT.bmp");
  1074. blitAt(b,pos.x+8,pos.y+11);
  1075. blitAt(comp->getImg(),pos.x+52,pos.y+54);
  1076. printAtMiddle(comp->subtitle,pos.x+91,pos.y+158,GEOR13,zwykly);
  1077. printAtMiddleWB(comp->description,pos.x+94,pos.y+31,GEOR13,26,zwykly);
  1078. SDL_FreeSurface(b);
  1079. TimeInterested::activate();
  1080. mode = 6;
  1081. toNextTick = time;
  1082. }
  1083. void CInfoBar::tick()
  1084. {
  1085. if((mode >= 0) && (mode < 5))
  1086. {
  1087. pom++;
  1088. if (pom >= getAnim(mode)->ourImages.size())
  1089. {
  1090. TimeInterested::deactivate();
  1091. toNextTick = -1;
  1092. mode = 5;
  1093. draw();
  1094. return;
  1095. }
  1096. toNextTick = 150;
  1097. blitAnim(mode);
  1098. }
  1099. else if (mode == 6)
  1100. {
  1101. TimeInterested::deactivate();
  1102. toNextTick = -1;
  1103. mode = 5;
  1104. draw();
  1105. }
  1106. }
  1107. CAdvMapInt::CAdvMapInt(int Player)
  1108. :player(Player),
  1109. statusbar(ADVOPT.statusbarX,ADVOPT.statusbarY,ADVOPT.statusbarG),
  1110. kingOverview(CGI->generaltexth->zelp[293].first,CGI->generaltexth->zelp[293].second,
  1111. boost::bind(&CAdvMapInt::fshowOverview,this),&ADVOPT.kingOverview, SDLK_k),
  1112. underground(CGI->generaltexth->zelp[294].first,CGI->generaltexth->zelp[294].second,
  1113. boost::bind(&CAdvMapInt::fswitchLevel,this),&ADVOPT.underground, SDLK_u),
  1114. questlog(CGI->generaltexth->zelp[295].first,CGI->generaltexth->zelp[295].second,
  1115. boost::bind(&CAdvMapInt::fshowQuestlog,this),&ADVOPT.questlog, SDLK_q),
  1116. sleepWake(CGI->generaltexth->zelp[296].first,CGI->generaltexth->zelp[296].second,
  1117. boost::bind(&CAdvMapInt::fsleepWake,this), &ADVOPT.sleepWake, SDLK_w),
  1118. moveHero(CGI->generaltexth->zelp[297].first,CGI->generaltexth->zelp[297].second,
  1119. boost::bind(&CAdvMapInt::fmoveHero,this), &ADVOPT.moveHero, SDLK_m),
  1120. spellbook(CGI->generaltexth->zelp[298].first,CGI->generaltexth->zelp[298].second,
  1121. boost::bind(&CAdvMapInt::fshowSpellbok,this), &ADVOPT.spellbook, SDLK_c),
  1122. advOptions(CGI->generaltexth->zelp[299].first,CGI->generaltexth->zelp[299].second,
  1123. boost::bind(&CAdvMapInt::fadventureOPtions,this), &ADVOPT.advOptions, SDLK_a),
  1124. sysOptions(CGI->generaltexth->zelp[300].first,CGI->generaltexth->zelp[300].second,
  1125. boost::bind(&CAdvMapInt::fsystemOptions,this), &ADVOPT.sysOptions, SDLK_o),
  1126. nextHero(CGI->generaltexth->zelp[301].first,CGI->generaltexth->zelp[301].second,
  1127. boost::bind(&CAdvMapInt::fnextHero,this), &ADVOPT.nextHero, SDLK_h),
  1128. endTurn(CGI->generaltexth->zelp[302].first,CGI->generaltexth->zelp[302].second,
  1129. boost::bind(&CAdvMapInt::fendTurn,this), &ADVOPT.endTurn, SDLK_e),
  1130. heroList(ADVOPT.hlistSize),
  1131. townList(ADVOPT.tlistSize,ADVOPT.tlistX,ADVOPT.tlistY,ADVOPT.tlistAU,ADVOPT.tlistAD)//(5,&genRect(192,48,747,196),747,196,747,372),
  1132. {
  1133. subInt = NULL;
  1134. selection = NULL;
  1135. townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this);
  1136. LOCPLINT->adventureInt=this;
  1137. bg = BitmapHandler::loadBitmap(ADVOPT.mainGraphic);
  1138. graphics->blueToPlayersAdv(bg,player);
  1139. scrollingDir = 0;
  1140. updateScreen = false;
  1141. anim=0;
  1142. animValHitCount=0; //animation frame
  1143. heroAnim=0;
  1144. heroAnimValHitCount=0; // hero animation frame
  1145. heroList.init();
  1146. heroList.genList();
  1147. //townList.init();
  1148. townList.genList();
  1149. heroWindow = new CHeroWindow(this->player);
  1150. gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[0]));
  1151. gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[1]));
  1152. gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[2]));
  1153. gems.push_back(CDefHandler::giveDef(ADVOPT.gemG[3]));
  1154. }
  1155. CAdvMapInt::~CAdvMapInt()
  1156. {
  1157. SDL_FreeSurface(bg);
  1158. delete heroWindow;
  1159. for(int i=0; i<gems.size(); i++)
  1160. delete gems[i];
  1161. }
  1162. void CAdvMapInt::fshowOverview()
  1163. {
  1164. }
  1165. void CAdvMapInt::fswitchLevel()
  1166. {
  1167. if(!CGI->mh->map->twoLevel)
  1168. return;
  1169. if (position.z)
  1170. {
  1171. position.z--;
  1172. underground.curimg=0;
  1173. underground.show();
  1174. }
  1175. else
  1176. {
  1177. underground.curimg=1;
  1178. position.z++;
  1179. underground.show();
  1180. }
  1181. updateScreen = true;
  1182. minimap.draw();
  1183. }
  1184. void CAdvMapInt::fshowQuestlog()
  1185. {
  1186. }
  1187. void CAdvMapInt::fsleepWake()
  1188. {
  1189. }
  1190. void CAdvMapInt::fmoveHero()
  1191. {
  1192. if (selection->ID!=HEROI_TYPE)
  1193. return;
  1194. if (!terrain.currentPath)
  1195. return;
  1196. CPath sended(*(terrain.currentPath)); //temporary path - engine will operate on it
  1197. LOCPLINT->pim->unlock();
  1198. LOCPLINT->cb->moveHero( ((const CGHeroInstance*)LOCPLINT->adventureInt->selection)->type->ID,&sended,1,0);
  1199. LOCPLINT->pim->lock();
  1200. }
  1201. void CAdvMapInt::fshowSpellbok()
  1202. {
  1203. if (selection->ID!=HEROI_TYPE) //checking necessary values
  1204. return;
  1205. LOCPLINT->curint->deactivate();
  1206. CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), ((const CGHeroInstance*)LOCPLINT->adventureInt->selection));
  1207. spellWindow->activate();
  1208. LOCPLINT->objsToBlit.push_back(spellWindow);
  1209. }
  1210. void CAdvMapInt::fadventureOPtions()
  1211. {
  1212. }
  1213. void CAdvMapInt::fsystemOptions()
  1214. {
  1215. LOCPLINT->curint->deactivate();
  1216. CSystemOptionsWindow * sysopWindow = new CSystemOptionsWindow(genRect(487, 481, 159, 57), LOCPLINT);
  1217. sysopWindow->activate();
  1218. LOCPLINT->objsToBlit.push_back(sysopWindow);
  1219. }
  1220. void CAdvMapInt::fnextHero()
  1221. {
  1222. if(!heroList.items.size()) //no wandering heroes
  1223. return;
  1224. int start = heroList.selected;
  1225. int i = start;
  1226. do
  1227. {
  1228. i++;
  1229. if(i >= heroList.items.size())
  1230. i = 0;
  1231. } while (!heroList.items[i].first->movement && i!=start);
  1232. heroList.select(i);
  1233. }
  1234. void CAdvMapInt::fendTurn()
  1235. {
  1236. LOCPLINT->makingTurn = false;
  1237. }
  1238. void CAdvMapInt::activate()
  1239. {
  1240. if(subInt == heroWindow)
  1241. {
  1242. heroWindow->activate();
  1243. return;
  1244. }
  1245. LOCPLINT->curint = this;
  1246. LOCPLINT->statusbar = &statusbar;
  1247. kingOverview.activate();
  1248. underground.activate();
  1249. questlog.activate();
  1250. sleepWake.activate();
  1251. moveHero.activate();
  1252. spellbook.activate();
  1253. sysOptions.activate();
  1254. advOptions.activate();
  1255. nextHero.activate();
  1256. endTurn.activate();
  1257. minimap.activate();
  1258. heroList.activate();
  1259. townList.activate();
  1260. terrain.activate();
  1261. KeyInterested::activate();
  1262. show();
  1263. }
  1264. void CAdvMapInt::deactivate()
  1265. {
  1266. if(subInt == heroWindow)
  1267. {
  1268. heroWindow->deactivate();
  1269. return;
  1270. }
  1271. KeyInterested::deactivate();
  1272. hide();
  1273. }
  1274. void CAdvMapInt::show(SDL_Surface *to)
  1275. {
  1276. blitAt(bg,0,0);
  1277. kingOverview.show();
  1278. underground.show();
  1279. questlog.show();
  1280. sleepWake.show();
  1281. moveHero.show();
  1282. spellbook.show();
  1283. advOptions.show();
  1284. sysOptions.show();
  1285. nextHero.show();
  1286. endTurn.show();
  1287. minimap.draw();
  1288. heroList.draw();
  1289. townList.draw();
  1290. updateScreen = true;
  1291. update();
  1292. resdatabar.draw();
  1293. statusbar.show();
  1294. infoBar.draw();
  1295. }
  1296. void CAdvMapInt::hide()
  1297. {
  1298. CGI->curh->changeGraphic(0,0);
  1299. kingOverview.deactivate();
  1300. underground.deactivate();
  1301. questlog.deactivate();
  1302. sleepWake.deactivate();
  1303. moveHero.deactivate();
  1304. spellbook.deactivate();
  1305. advOptions.deactivate();
  1306. sysOptions.deactivate();
  1307. nextHero.deactivate();
  1308. endTurn.deactivate();
  1309. minimap.deactivate();
  1310. heroList.deactivate();
  1311. townList.deactivate();
  1312. terrain.deactivate();
  1313. if(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar)!=LOCPLINT->timeinterested.end())
  1314. LOCPLINT->timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar));
  1315. infoBar.mode=-1;
  1316. }
  1317. void CAdvMapInt::update()
  1318. {
  1319. ++animValHitCount; //for animations
  1320. if(animValHitCount == 8)
  1321. {
  1322. CGI->mh->updateWater();
  1323. animValHitCount = 0;
  1324. ++anim;
  1325. updateScreen = true;
  1326. }
  1327. ++heroAnim;
  1328. //if advmap needs updating AND (no dialog is shown OR ctrl is pressed)
  1329. if((animValHitCount % (4/LOCPLINT->mapScrollingSpeed)) == 0
  1330. &&
  1331. (!LOCPLINT->showingDialog->get()
  1332. && !LOCPLINT->curint->subInt)
  1333. || SDL_GetKeyState(NULL)[SDLK_LCTRL]
  1334. || SDL_GetKeyState(NULL)[SDLK_RCTRL]
  1335. )
  1336. {
  1337. if( (scrollingDir & LEFT) && (position.x>-Woff) )
  1338. position.x--;
  1339. if( (scrollingDir & RIGHT) && (position.x < CGI->mh->map->width - terrain.tilesw + Woff) )
  1340. position.x++;
  1341. if( (scrollingDir & UP) && (position.y>-Hoff) )
  1342. position.y--;
  1343. if( (scrollingDir & DOWN) && (position.y < CGI->mh->map->height - terrain.tilesh + Hoff) )
  1344. position.y++;
  1345. if(scrollingDir)
  1346. {
  1347. updateScreen = true;
  1348. updateMinimap=true;
  1349. }
  1350. }
  1351. if(updateScreen)
  1352. {
  1353. terrain.show();
  1354. for(int i=0;i<4;i++)
  1355. blitAt(gems[i]->ourImages[LOCPLINT->playerID].bitmap,ADVOPT.gemX[i],ADVOPT.gemY[i]);
  1356. updateScreen=false;
  1357. }
  1358. if (updateMinimap)
  1359. {
  1360. minimap.draw();
  1361. updateMinimap=false;
  1362. }
  1363. }
  1364. void CAdvMapInt::selectionChanged()
  1365. {
  1366. const CGTownInstance *to = townList.items[townList.selected];
  1367. select(to);
  1368. }
  1369. void CAdvMapInt::centerOn(int3 on)
  1370. {
  1371. on.x -= (LOCPLINT->adventureInt->terrain.tilesw/2);
  1372. on.y -= (LOCPLINT->adventureInt->terrain.tilesh/2);
  1373. on = LOCPLINT->repairScreenPos(on);
  1374. LOCPLINT->adventureInt->position.x=on.x;
  1375. LOCPLINT->adventureInt->position.y=on.y;
  1376. LOCPLINT->adventureInt->position.z=on.z;
  1377. LOCPLINT->adventureInt->updateScreen=true;
  1378. updateMinimap=true;
  1379. }
  1380. void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
  1381. {
  1382. ui8 Dir;
  1383. switch(key.keysym.sym)
  1384. {
  1385. case SDLK_UP:
  1386. Dir = UP;
  1387. break;
  1388. case SDLK_LEFT:
  1389. Dir = LEFT;
  1390. break;
  1391. case SDLK_RIGHT:
  1392. Dir = RIGHT;
  1393. break;
  1394. case SDLK_DOWN:
  1395. Dir = DOWN;
  1396. break;
  1397. default:
  1398. return;
  1399. }
  1400. if(key.state == SDL_PRESSED //arrow is pressed
  1401. && (SDL_GetKeyState(NULL)[SDLK_LCTRL]
  1402. || SDL_GetKeyState(NULL)[SDLK_RCTRL])
  1403. )
  1404. scrollingDir |= Dir;
  1405. else
  1406. scrollingDir &= ~Dir;
  1407. }
  1408. void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * client)
  1409. {
  1410. if (down)
  1411. {
  1412. boost::algorithm::erase_all(text,"\"");
  1413. CSimpleWindow * temp = CMessage::genWindow(text,LOCPLINT->playerID);
  1414. temp->pos.x=screen->w/2-(temp->pos.w/2);
  1415. temp->pos.y=screen->h/2-(temp->pos.h/2);
  1416. temp->owner = client;
  1417. LOCPLINT->objsToBlit.push_back(temp);
  1418. }
  1419. else
  1420. {
  1421. for (size_t i=0; i < LOCPLINT->objsToBlit.size(); ++i)
  1422. {
  1423. //TODO: pewnie da sie to zrobic lepiej, ale nie chce mi sie. Wolajacy obiekt powinien informowac kogo spodziewa sie odwolac (null jesli down)
  1424. CSimpleWindow * pom = dynamic_cast<CSimpleWindow*>(LOCPLINT->objsToBlit[i]);
  1425. if (!pom)
  1426. continue;
  1427. if (pom->owner==client)
  1428. {
  1429. LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+(i));
  1430. delete pom;
  1431. if((LOCPLINT->curint == LOCPLINT->castleInt) && !LOCPLINT->castleInt->subInt)
  1432. LOCPLINT->castleInt->showAll(0,true);
  1433. }
  1434. }
  1435. }
  1436. }
  1437. int3 CAdvMapInt::verifyPos(int3 ver)
  1438. {
  1439. if (ver.x<0)
  1440. ver.x=0;
  1441. if (ver.y<0)
  1442. ver.y=0;
  1443. if (ver.z<0)
  1444. ver.z=0;
  1445. if (ver.x>=CGI->mh->sizes.x)
  1446. ver.x=CGI->mh->sizes.x-1;
  1447. if (ver.y>=CGI->mh->sizes.y)
  1448. ver.y=CGI->mh->sizes.y-1;
  1449. if (ver.z>=CGI->mh->sizes.z)
  1450. ver.z=CGI->mh->sizes.z-1;
  1451. return ver;
  1452. }
  1453. void CAdvMapInt::select(const CArmedInstance *sel )
  1454. {
  1455. LOCPLINT->cb->setSelection(sel);
  1456. centerOn(sel->pos);
  1457. selection = sel;
  1458. if(sel->ID==TOWNI_TYPE)
  1459. {
  1460. int pos = vstd::findPos(townList.items,sel);
  1461. townList.selected = pos;
  1462. terrain.currentPath = NULL;
  1463. }
  1464. else
  1465. {
  1466. int pos = heroList.getPosOfHero(sel);
  1467. heroList.selected = pos;
  1468. terrain.currentPath = heroList.items[pos].second;
  1469. }
  1470. townList.draw();
  1471. heroList.draw();
  1472. infoBar.draw(NULL);
  1473. }