CAdvmapInterface.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  1. #include "stdafx.h"
  2. #include "CAdvmapInterface.h"
  3. #include "client/CBitmapHandler.h"
  4. #include "CPlayerInterface.h"
  5. #include "hch\CPreGameTextHandler.h"
  6. #include "hch\CGeneralTextHandler.h"
  7. #include "hch\CTownHandler.h"
  8. #include "CPathfinder.h"
  9. #include "CGameInfo.h"
  10. #include "SDL_Extensions.h"
  11. #include "CCallback.h"
  12. #include <boost/assign/std/vector.hpp>
  13. #include "mapHandler.h"
  14. #include "CMessage.h"
  15. #include <boost/algorithm/string.hpp>
  16. #include <boost/algorithm/string/replace.hpp>
  17. #include "CLua.h"
  18. #include "hch/CHeroHandler.h"
  19. #include <sstream>
  20. #include "AdventureMapButton.h"
  21. #include "CHeroWindow.h"
  22. #include "client/Graphics.h"
  23. #pragma warning (disable : 4355)
  24. extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
  25. using namespace boost::logic;
  26. using namespace boost::assign;
  27. using namespace CSDL_Ext;
  28. CAdvMapInt::~CAdvMapInt()
  29. {
  30. SDL_FreeSurface(bg);
  31. delete heroWindow;
  32. }
  33. CMinimap::CMinimap(bool draw)
  34. {
  35. statusbarTxt = CGI->preth->zelp[291].first;
  36. rcText = CGI->preth->zelp[291].second;
  37. pos.x=630;
  38. pos.y=26;
  39. pos.h=pos.w=144;
  40. int rx = (((float)19)/(CGI->mh->sizes.x))*((float)pos.w),
  41. ry = (((float)18)/(CGI->mh->sizes.y))*((float)pos.h);
  42. radar = newSurface(rx,ry);
  43. temps = newSurface(144,144);
  44. SDL_FillRect(radar,NULL,0x00FFFF);
  45. for (int i=0; i<radar->w; i++)
  46. {
  47. if (i%4 || (i==0))
  48. {
  49. SDL_PutPixel(radar,i,0,255,75,125);
  50. SDL_PutPixel(radar,i,radar->h-1,255,75,125);
  51. }
  52. }
  53. for (int i=0; i<radar->h; i++)
  54. {
  55. if ((i%4) || (i==0))
  56. {
  57. SDL_PutPixel(radar,0,i,255,75,125);
  58. SDL_PutPixel(radar,radar->w-1,i,255,75,125);
  59. }
  60. }
  61. SDL_SetColorKey(radar,SDL_SRCCOLORKEY,SDL_MapRGB(radar->format,0,255,255));
  62. //radar = CDefHandler::giveDef("RADAR.DEF");
  63. std::ifstream is("config/minimap.txt",std::ifstream::in);
  64. for (int i=0;i<TERRAIN_TYPES;i++)
  65. {
  66. std::pair<int,SDL_Color> vinya;
  67. std::pair<int,SDL_Color> vinya2;
  68. int pom;
  69. is >> pom;
  70. vinya2.first=vinya.first=pom;
  71. is >> pom;
  72. vinya.second.r=pom;
  73. is >> pom;
  74. vinya.second.g=pom;
  75. is >> pom;
  76. vinya.second.b=pom;
  77. is >> pom;
  78. vinya2.second.r=pom;
  79. is >> pom;
  80. vinya2.second.g=pom;
  81. is >> pom;
  82. vinya2.second.b=pom;
  83. vinya.second.unused=vinya2.second.unused=255;
  84. colors.insert(vinya);
  85. colorsBlocked.insert(vinya2);
  86. }
  87. is.close();
  88. if (draw)
  89. redraw();
  90. }
  91. void CMinimap::draw()
  92. {
  93. //draw terrain
  94. blitAt(map[LOCPLINT->adventureInt->position.z],0,0,temps);
  95. //draw heroes
  96. std::vector <const CGHeroInstance *> hh = LOCPLINT->cb->getHeroesInfo(false);
  97. int mw = map[0]->w, mh = map[0]->h,
  98. wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y;
  99. for (int i=0; i<hh.size();i++)
  100. {
  101. int3 hpos = hh[i]->getPosition(false);
  102. if(hpos.z!=LOCPLINT->adventureInt->position.z)
  103. continue;
  104. //float zawx = ((float)hpos.x/CGI->mh->sizes.x), zawy = ((float)hpos.y/CGI->mh->sizes.y);
  105. int3 maplgp ( (hpos.x*mw)/CGI->mh->sizes.x, (hpos.y*mh)/CGI->mh->sizes.y, hpos.z );
  106. for (int ii=0; ii<wo; ii++)
  107. {
  108. for (int jj=0; jj<ho; jj++)
  109. {
  110. SDL_PutPixel(temps,maplgp.x+ii,maplgp.y+jj,graphics->playerColors[hh[i]->getOwner()].r,graphics->playerColors[hh[i]->getOwner()].g,graphics->playerColors[hh[i]->getOwner()].b);
  111. }
  112. }
  113. }
  114. blitAt(FoW[LOCPLINT->adventureInt->position.z],0,0,temps);
  115. //draw radar
  116. int bx = (((float)LOCPLINT->adventureInt->position.x)/(((float)CGI->mh->sizes.x)))*pos.w,
  117. by = (((float)LOCPLINT->adventureInt->position.y)/(((float)CGI->mh->sizes.y)))*pos.h;
  118. blitAt(radar,bx,by,temps);
  119. blitAt(temps,pos.x,pos.y);
  120. //SDL_UpdateRect(screen,pos.x,pos.y,pos.w,pos.h);
  121. }
  122. void CMinimap::redraw(int level)// (level==-1) => redraw all levels
  123. {
  124. (CGI);
  125. for (int i=0; i<CGI->mh->sizes.z; i++)
  126. {
  127. SDL_Surface * pom ;
  128. if ((level>=0) && (i!=level))
  129. continue;
  130. if (map.size()<i+1)
  131. pom = CSDL_Ext::newSurface(pos.w,pos.h,screen);
  132. else pom = map[i];
  133. for (int x=0;x<pos.w;x++)
  134. {
  135. for (int y=0;y<pos.h;y++)
  136. {
  137. int mx=(CGI->mh->sizes.x*x)/pos.w;
  138. int my=(CGI->mh->sizes.y*y)/pos.h;
  139. if (CGI->mh->ttiles[mx][my][i].blocked && (!CGI->mh->ttiles[mx][my][i].visitable))
  140. SDL_PutPixel(pom,x,y,colorsBlocked[CGI->mh->ttiles[mx][my][i].terType].r,colorsBlocked[CGI->mh->ttiles[mx][my][i].terType].g,colorsBlocked[CGI->mh->ttiles[mx][my][i].terType].b);
  141. else SDL_PutPixel(pom,x,y,colors[CGI->mh->ttiles[mx][my][i].terType].r,colors[CGI->mh->ttiles[mx][my][i].terType].g,colors[CGI->mh->ttiles[mx][my][i].terType].b);
  142. }
  143. }
  144. map.push_back(pom);
  145. }
  146. }
  147. void CMinimap::updateRadar()
  148. {}
  149. void CMinimap::clickRight (tribool down)
  150. {
  151. LOCPLINT->adventureInt->handleRightClick(rcText,down,this);
  152. }
  153. void CMinimap::clickLeft (tribool down)
  154. {
  155. if (down && (!pressedL))
  156. MotionInterested::activate();
  157. else if (!down)
  158. {
  159. if (std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this)!=LOCPLINT->motioninterested.end())
  160. MotionInterested::deactivate();
  161. }
  162. ClickableL::clickLeft(down);
  163. if (!((bool)down))
  164. return;
  165. float dx=((float)(LOCPLINT->current->motion.x-pos.x))/((float)pos.w),
  166. dy=((float)(LOCPLINT->current->motion.y-pos.y))/((float)pos.h);
  167. int3 newCPos;
  168. newCPos.x = (CGI->mh->sizes.x*dx);
  169. newCPos.y = (CGI->mh->sizes.y*dy);
  170. newCPos.z = LOCPLINT->adventureInt->position.z;
  171. LOCPLINT->adventureInt->centerOn(newCPos);
  172. }
  173. void CMinimap::hover (bool on)
  174. {
  175. Hoverable::hover(on);
  176. if (on)
  177. LOCPLINT->adventureInt->statusbar.print(statusbarTxt);
  178. else if (LOCPLINT->adventureInt->statusbar.current==statusbarTxt)
  179. LOCPLINT->adventureInt->statusbar.clear();
  180. }
  181. void CMinimap::mouseMoved (SDL_MouseMotionEvent & sEvent)
  182. {
  183. if (pressedL)
  184. {
  185. clickLeft(true);
  186. }
  187. }
  188. void CMinimap::activate()
  189. {
  190. ClickableL::activate();
  191. ClickableR::activate();
  192. Hoverable::activate();
  193. if (pressedL)
  194. MotionInterested::activate();
  195. }
  196. void CMinimap::deactivate()
  197. {
  198. if (pressedL)
  199. MotionInterested::deactivate();
  200. ClickableL::deactivate();
  201. ClickableR::deactivate();
  202. Hoverable::deactivate();
  203. }
  204. void CMinimap::showTile(int3 pos)
  205. {
  206. int mw = map[0]->w, mh = map[0]->h;
  207. double wo = ((double)mw)/CGI->mh->sizes.x, ho = ((double)mh)/CGI->mh->sizes.y;
  208. for (int ii=0; ii<wo; ii++)
  209. {
  210. for (int jj=0; jj<ho; jj++)
  211. {
  212. if ((pos.x*wo+ii<this->pos.w) && (pos.y*ho+jj<this->pos.h))
  213. CSDL_Ext::SDL_PutPixel(FoW[pos.z],pos.x*wo+ii,pos.y*ho+jj,0,0,0,0,0);
  214. }
  215. }
  216. }
  217. void CMinimap::hideTile(int3 pos)
  218. {
  219. }
  220. CTerrainRect::CTerrainRect():currentPath(NULL)
  221. {
  222. tilesw=19;
  223. tilesh=18;
  224. pos.x=7;
  225. pos.y=6;
  226. pos.w=593;
  227. pos.h=547;
  228. arrows = CDefHandler::giveDef("ADAG.DEF");
  229. for(int y=0; y<arrows->ourImages.size(); ++y)
  230. {
  231. arrows->ourImages[y].bitmap = CSDL_Ext::alphaTransform(arrows->ourImages[y].bitmap);
  232. }
  233. }
  234. void CTerrainRect::activate()
  235. {
  236. ClickableL::activate();
  237. ClickableR::activate();
  238. Hoverable::activate();
  239. KeyInterested::activate();
  240. MotionInterested::activate();
  241. };
  242. void CTerrainRect::deactivate()
  243. {
  244. ClickableL::deactivate();
  245. ClickableR::deactivate();
  246. Hoverable::deactivate();
  247. KeyInterested::deactivate();
  248. MotionInterested::deactivate();
  249. };
  250. void CTerrainRect::clickLeft(tribool down)
  251. {
  252. LOGE("Left mouse button down2");
  253. if ((down==false) || indeterminate(down))
  254. return;
  255. if (LOCPLINT->adventureInt->selection.type != HEROI_TYPE)
  256. {
  257. if (currentPath)
  258. {
  259. delete currentPath;
  260. currentPath = NULL;
  261. }
  262. return;
  263. }
  264. int3 mp = whichTileIsIt();
  265. if ((mp.x<0) || (mp.y<0))
  266. return;
  267. bool mres =true;
  268. if (currentPath)
  269. {
  270. if ( (currentPath->endPos()) == mp)
  271. { //move
  272. CPath sended(*currentPath); //temporary path - engine will operate on it
  273. mres = LOCPLINT->cb->moveHero( ((const CGHeroInstance*)LOCPLINT->adventureInt->selection.selected)->type->ID,&sended,1,0);
  274. if(!mres)
  275. {
  276. delete currentPath;
  277. currentPath = NULL;
  278. int i=0;
  279. for(;i<LOCPLINT->adventureInt->heroList.items.size();i++)
  280. {
  281. if(LOCPLINT->adventureInt->heroList.items[i].first->subID == ((const CGHeroInstance*)LOCPLINT->adventureInt->selection.selected)->type->ID)
  282. {
  283. LOCPLINT->adventureInt->heroList.items[i].second = NULL;
  284. break;
  285. }
  286. }
  287. }
  288. }
  289. else
  290. {
  291. delete currentPath;
  292. currentPath=NULL;
  293. }
  294. }
  295. const CGHeroInstance * currentHero = (LOCPLINT->adventureInt->heroList.items.size())?(LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].first):(NULL);
  296. if(!currentHero)
  297. return;
  298. int3 bufpos = currentHero->getPosition(false);
  299. //bufpos.x-=1;
  300. if (mres)
  301. {
  302. vector<Coordinate>* p;
  303. p = CGI->pathf->GetPath(Coordinate(bufpos),Coordinate(mp),currentHero);
  304. //Convert to old format.
  305. currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->ConvertToOldFormat(p);
  306. delete p;
  307. //currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->getPath(bufpos,mp,currentHero,1);
  308. }
  309. }
  310. void CTerrainRect::clickRight(tribool down)
  311. {
  312. }
  313. void CTerrainRect::mouseMoved (SDL_MouseMotionEvent & sEvent)
  314. {
  315. int3 pom=LOCPLINT->adventureInt->verifyPos(whichTileIsIt(sEvent.x,sEvent.y));
  316. if (pom!=curHoveredTile)
  317. curHoveredTile=pom;
  318. else
  319. return;
  320. std::vector<std::string> temp = LOCPLINT->cb->getObjDescriptions(pom);
  321. if (temp.size())
  322. {
  323. LOCPLINT->adventureInt->statusbar.print((*((temp.end())-1)));
  324. }
  325. else
  326. {
  327. LOCPLINT->adventureInt->statusbar.clear();
  328. }
  329. }
  330. void CTerrainRect::keyPressed (SDL_KeyboardEvent & key){}
  331. void CTerrainRect::hover(bool on)
  332. {
  333. if (!on)
  334. LOCPLINT->adventureInt->statusbar.clear();
  335. }
  336. void CTerrainRect::showPath()
  337. {
  338. for (int i=0;i<currentPath->nodes.size()-1;i++)
  339. {
  340. int pn=-1;//number of picture
  341. if (i==0) //last tile
  342. {
  343. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  344. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  345. if (x<0 || y<0 || x>pos.w || y>pos.h)
  346. continue;
  347. pn=0;
  348. }
  349. else
  350. {
  351. std::vector<CPathNode> & cv = currentPath->nodes;
  352. if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1)
  353. {
  354. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  355. {
  356. pn = 3;
  357. }
  358. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  359. {
  360. pn = 12;
  361. }
  362. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  363. {
  364. pn = 21;
  365. }
  366. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  367. {
  368. pn = 22;
  369. }
  370. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  371. {
  372. pn = 2;
  373. }
  374. }
  375. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1)
  376. {
  377. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  378. {
  379. pn = 4;
  380. }
  381. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  382. {
  383. pn = 13;
  384. }
  385. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  386. {
  387. pn = 22;
  388. }
  389. }
  390. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1)
  391. {
  392. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  393. {
  394. pn = 5;
  395. }
  396. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  397. {
  398. pn = 14;
  399. }
  400. else if(cv[i-1].coord.x+1 == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y)
  401. {
  402. pn = 23;
  403. }
  404. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  405. {
  406. pn = 24;
  407. }
  408. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  409. {
  410. pn = 4;
  411. }
  412. }
  413. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y)
  414. {
  415. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  416. {
  417. pn = 6;
  418. }
  419. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
  420. {
  421. pn = 15;
  422. }
  423. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  424. {
  425. pn = 24;
  426. }
  427. }
  428. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1)
  429. {
  430. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
  431. {
  432. pn = 7;
  433. }
  434. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  435. {
  436. pn = 16;
  437. }
  438. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  439. {
  440. pn = 17;
  441. }
  442. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  443. {
  444. pn = 6;
  445. }
  446. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  447. {
  448. pn = 18;
  449. }
  450. }
  451. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1)
  452. {
  453. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  454. {
  455. pn = 8;
  456. }
  457. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  458. {
  459. pn = 9;
  460. }
  461. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  462. {
  463. pn = 18;
  464. }
  465. }
  466. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1)
  467. {
  468. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  469. {
  470. pn = 1;
  471. }
  472. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  473. {
  474. pn = 10;
  475. }
  476. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  477. {
  478. pn = 19;
  479. }
  480. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  481. {
  482. pn = 8;
  483. }
  484. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  485. {
  486. pn = 20;
  487. }
  488. }
  489. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y)
  490. {
  491. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  492. {
  493. pn = 2;
  494. }
  495. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  496. {
  497. pn = 11;
  498. }
  499. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  500. {
  501. pn = 20;
  502. }
  503. }
  504. }
  505. if ( ((currentPath->nodes[i].dist)-(*(currentPath->nodes.end()-1)).dist) > ((const CGHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->movement)
  506. pn+=25;
  507. if (pn>=0)
  508. {
  509. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  510. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  511. if (x<0 || y<0 || x>pos.w || y>pos.h)
  512. continue;
  513. int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
  514. hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
  515. if (hvx<0 && hvy<0)
  516. {
  517. CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, screen, &genRect(32, 32, x, y));
  518. }
  519. else if(hvx<0)
  520. {
  521. CSDL_Ext::blit8bppAlphaTo24bpp
  522. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,0,0),
  523. screen,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,x,y));
  524. }
  525. else if (hvy<0)
  526. {
  527. CSDL_Ext::blit8bppAlphaTo24bpp
  528. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  529. screen,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  530. }
  531. else
  532. {
  533. CSDL_Ext::blit8bppAlphaTo24bpp
  534. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  535. screen,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  536. }
  537. }
  538. } //for (int i=0;i<currentPath->nodes.size()-1;i++)
  539. }
  540. void CTerrainRect::show()
  541. {
  542. SDL_Surface * teren = CGI->mh->terrainRect
  543. (LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
  544. tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim,
  545. LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim,
  546. screen,&genRect(547,594,7,6)
  547. );
  548. //SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));
  549. //SDL_FreeSurface(teren);
  550. if (currentPath && LOCPLINT->adventureInt->position.z==currentPath->startPos().z) //drawing path
  551. {
  552. showPath();
  553. }
  554. }
  555. int3 CTerrainRect::whichTileIsIt(int x, int y)
  556. {
  557. int3 ret;
  558. ret.x = LOCPLINT->adventureInt->position.x + ((LOCPLINT->current->motion.x-pos.x)/32);
  559. ret.y = LOCPLINT->adventureInt->position.y + ((LOCPLINT->current->motion.y-pos.y)/32);
  560. ret.z = LOCPLINT->adventureInt->position.z;
  561. return ret;
  562. }
  563. int3 CTerrainRect::whichTileIsIt()
  564. {
  565. return whichTileIsIt(LOCPLINT->current->motion.x,LOCPLINT->current->motion.y);
  566. }
  567. void CResDataBar::clickRight (tribool down)
  568. {
  569. }
  570. void CResDataBar::activate()
  571. {
  572. ClickableR::activate();
  573. }
  574. void CResDataBar::deactivate()
  575. {
  576. ClickableR::deactivate();
  577. }
  578. CResDataBar::CResDataBar()
  579. {
  580. bg = BitmapHandler::loadBitmap("ZRESBAR.bmp");
  581. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  582. //std::vector<SDL_Color> kolory;
  583. //SDL_Color p1={40,65,139,255}, p2={36,59,125,255}, p3={35,56,121,255};
  584. //kolory+=p1,p2,p3;
  585. //blueToPlayersAdv(bg,LOCPLINT->playerID,2,&kolory);
  586. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  587. pos = genRect(bg->h,bg->w,3,575);
  588. txtpos += (std::pair<int,int>(35,577)),(std::pair<int,int>(120,577)),(std::pair<int,int>(205,577)),
  589. (std::pair<int,int>(290,577)),(std::pair<int,int>(375,577)),(std::pair<int,int>(460,577)),
  590. (std::pair<int,int>(545,577)),(std::pair<int,int>(620,577));
  591. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63] + ": %s, " +
  592. CGI->generaltexth->allTexts[64] + ": %s";
  593. }
  594. CResDataBar::~CResDataBar()
  595. {
  596. SDL_FreeSurface(bg);
  597. }
  598. void CResDataBar::draw()
  599. {
  600. blitAt(bg,pos.x,pos.y);
  601. char * buf = new char[15];
  602. for (int i=0;i<7;i++)
  603. {
  604. itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
  605. printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly);
  606. }
  607. std::vector<std::string> temp;
  608. itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf);
  609. itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf);
  610. itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf);
  611. printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,GEOR13,zwykly);
  612. temp.clear();
  613. //updateRect(&pos,screen);
  614. delete[] buf;
  615. }
  616. CInfoBar::CInfoBar()
  617. {
  618. toNextTick = mode = pom = -1;
  619. pos.x=605;
  620. pos.y=389;
  621. pos.w=194;
  622. pos.h=186;
  623. day = CDefHandler::giveDef("NEWDAY.DEF");
  624. week1 = CDefHandler::giveDef("NEWWEEK1.DEF");
  625. week2 = CDefHandler::giveDef("NEWWEEK2.DEF");
  626. week3 = CDefHandler::giveDef("NEWWEEK3.DEF");
  627. week4 = CDefHandler::giveDef("NEWWEEK4.DEF");
  628. }
  629. CInfoBar::~CInfoBar()
  630. {
  631. delete day;
  632. delete week1;
  633. delete week2;
  634. delete week3;
  635. delete week4;
  636. }
  637. void CInfoBar::draw(const CGObjectInstance * specific)
  638. {
  639. if ((mode>=0) && mode<5)
  640. {
  641. blitAnim(mode);
  642. return;
  643. }
  644. else if (mode==5)
  645. {
  646. mode = -1;
  647. if(!LOCPLINT->adventureInt->selection.selected)
  648. {
  649. if (LOCPLINT->adventureInt->heroList.items.size())
  650. {
  651. LOCPLINT->adventureInt->heroList.select(0);
  652. }
  653. }
  654. draw((const CGObjectInstance *)LOCPLINT->adventureInt->selection.selected);
  655. }
  656. if (!specific)
  657. specific = (const CGObjectInstance *)LOCPLINT->adventureInt->selection.selected;
  658. //TODO: to rzutowanie wyglada groznie, ale dziala. Ale nie powinno wygladac groznie.
  659. if(!specific)
  660. return;
  661. if(specific->ID == 34) //hero
  662. {
  663. if(graphics->heroWins.find(specific->subID)!=graphics->heroWins.end())
  664. blitAt(graphics->heroWins[specific->subID],pos.x,pos.y);
  665. }
  666. else if (specific->ID == 98)
  667. {
  668. const CGTownInstance * t = static_cast<const CGTownInstance*>(specific);
  669. if(graphics->townWins.find(t->identifier)!=graphics->townWins.end())
  670. blitAt(graphics->townWins[t->identifier],pos.x,pos.y);
  671. }
  672. //SDL_Surface * todr = LOCPLINT->infoWin(specific);
  673. //if (!todr)
  674. // return;
  675. //blitAt(todr,pos.x,pos.y);
  676. //SDL_FreeSurface(todr);
  677. }
  678. CDefHandler * CInfoBar::getAnim(int mode)
  679. {
  680. switch(mode)
  681. {
  682. case 0:
  683. return day;
  684. break;
  685. case 1:
  686. return week1;
  687. break;
  688. case 2:
  689. return week2;
  690. break;
  691. case 3:
  692. return week3;
  693. break;
  694. case 4:
  695. return week4;
  696. break;
  697. default:
  698. return NULL;
  699. break;
  700. }
  701. }
  702. void CInfoBar::blitAnim(int mode)//0 - day, 1 - week
  703. {
  704. CDefHandler * anim = NULL;
  705. std::stringstream txt;
  706. anim = getAnim(mode);
  707. if(mode) //new week animation
  708. {
  709. txt << CGI->generaltexth->allTexts[63] << " " << LOCPLINT->cb->getDate(2);
  710. }
  711. else //new day
  712. {
  713. txt << CGI->generaltexth->allTexts[64] << " " << LOCPLINT->cb->getDate(1);
  714. }
  715. blitAt(anim->ourImages[pom].bitmap,pos.x+9,pos.y+10);
  716. printAtMiddle(txt.str(),700,420,TNRB16,zwykly);
  717. if (pom == anim->ourImages.size()-1)
  718. toNextTick+=750;
  719. }
  720. void CInfoBar::newDay(int Day)
  721. {
  722. if(LOCPLINT->cb->getDate(1) != 1)
  723. {
  724. mode = 0; //showing day
  725. }
  726. else
  727. {
  728. switch(LOCPLINT->cb->getDate(2))
  729. {
  730. case 1:
  731. mode = 1;
  732. break;
  733. case 2:
  734. mode = 2;
  735. break;
  736. case 3:
  737. mode = 3;
  738. break;
  739. case 4:
  740. mode = 4;
  741. break;
  742. default:
  743. mode = -1;
  744. break;
  745. }
  746. }
  747. pom = 0;
  748. TimeInterested::activate();
  749. toNextTick = 500;
  750. blitAnim(mode);
  751. //blitAt(day->ourImages[pom].bitmap,pos.x+10,pos.y+10);
  752. }
  753. void CInfoBar::showComp(SComponent * comp, int time)
  754. {
  755. SDL_Surface * b = BitmapHandler::loadBitmap("ADSTATOT.bmp");
  756. blitAt(b,pos.x+8,pos.y+11);
  757. blitAt(comp->getImg(),pos.x+52,pos.y+54);
  758. printAtMiddle(comp->subtitle,pos.x+91,pos.y+158,GEOR13,zwykly);
  759. printAtMiddleWB(comp->description,pos.x+94,pos.y+31,GEOR13,26,zwykly);
  760. SDL_FreeSurface(b);
  761. TimeInterested::activate();
  762. mode = 6;
  763. toNextTick = time;
  764. }
  765. void CInfoBar::tick()
  766. {
  767. if((mode >= 0) && (mode < 5))
  768. {
  769. pom++;
  770. if (pom >= getAnim(mode)->ourImages.size())
  771. {
  772. TimeInterested::deactivate();
  773. toNextTick = -1;
  774. mode = 5;
  775. draw();
  776. return;
  777. }
  778. toNextTick = 150;
  779. blitAnim(mode);
  780. }
  781. else if (mode == 6)
  782. {
  783. TimeInterested::deactivate();
  784. toNextTick = -1;
  785. mode = 5;
  786. draw();
  787. }
  788. }
  789. CAdvMapInt::CAdvMapInt(int Player)
  790. :player(Player),
  791. statusbar(7,556),
  792. kingOverview(CGI->preth->zelp[293].first,CGI->preth->zelp[293].second,
  793. boost::bind(&CAdvMapInt::fshowOverview,this), 679, 196, "IAM002.DEF", false,NULL,true),
  794. underground(CGI->preth->zelp[294].first,CGI->preth->zelp[294].second,
  795. boost::bind(&CAdvMapInt::fswitchLevel,this), 711, 196, "IAM010.DEF", false, new std::vector<std::string>(1,std::string("IAM003.DEF")),true),
  796. questlog(CGI->preth->zelp[295].first,CGI->preth->zelp[295].second,
  797. boost::bind(&CAdvMapInt::fshowQuestlog,this), 679, 228, "IAM004.DEF", false,NULL,true),
  798. sleepWake(CGI->preth->zelp[296].first,CGI->preth->zelp[296].second,
  799. boost::bind(&CAdvMapInt::fsleepWake,this), 711, 228, "IAM005.DEF", false,NULL,true),
  800. moveHero(CGI->preth->zelp[297].first,CGI->preth->zelp[297].second,
  801. boost::bind(&CAdvMapInt::fmoveHero,this), 679, 260, "IAM006.DEF", false,NULL,true),
  802. spellbook(CGI->preth->zelp[298].first,CGI->preth->zelp[298].second,
  803. boost::bind(&CAdvMapInt::fshowSpellbok,this), 711, 260, "IAM007.DEF", false,NULL,true),
  804. advOptions(CGI->preth->zelp[299].first,CGI->preth->zelp[299].second,
  805. boost::bind(&CAdvMapInt::fadventureOPtions,this), 679, 292, "IAM008.DEF", false,NULL,true),
  806. sysOptions(CGI->preth->zelp[300].first,CGI->preth->zelp[300].second,
  807. boost::bind(&CAdvMapInt::fsystemOptions,this), 711, 292, "IAM009.DEF", false,NULL,true),
  808. nextHero(CGI->preth->zelp[301].first,CGI->preth->zelp[301].second,
  809. boost::bind(&CAdvMapInt::fnextHero,this), 679, 324, "IAM000.DEF", false,NULL,true),
  810. endTurn(CGI->preth->zelp[302].first,CGI->preth->zelp[302].second,
  811. boost::bind(&CAdvMapInt::fendTurn,this), 679, 356, "IAM001.DEF", false,NULL,true),
  812. townList(5,&genRect(192,48,747,196),747,196,747,372)
  813. {
  814. townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this);
  815. LOCPLINT->adventureInt=this;
  816. bg = BitmapHandler::loadBitmap("ADVMAP.bmp");
  817. graphics->blueToPlayersAdv(bg,player);
  818. scrollingLeft = false;
  819. scrollingRight = false;
  820. scrollingUp = false ;
  821. scrollingDown = false ;
  822. updateScreen = false;
  823. anim=0;
  824. animValHitCount=0; //animation frame
  825. heroAnim=0;
  826. heroAnimValHitCount=0; // hero animation frame
  827. heroList.init();
  828. heroList.genList();
  829. //townList.init();
  830. townList.genList();
  831. heroWindow = new CHeroWindow(this->player);
  832. gems.push_back(CDefHandler::giveDef("agemLL.def"));
  833. gems.push_back(CDefHandler::giveDef("agemLR.def"));
  834. gems.push_back(CDefHandler::giveDef("agemUL.def"));
  835. gems.push_back(CDefHandler::giveDef("agemUR.def"));
  836. }
  837. void CAdvMapInt::fshowOverview()
  838. {
  839. }
  840. void CAdvMapInt::fswitchLevel()
  841. {
  842. if(!CGI->mh->map->twoLevel)
  843. return;
  844. if (position.z)
  845. {
  846. position.z--;
  847. underground.curimg=0;
  848. underground.show();
  849. }
  850. else
  851. {
  852. underground.curimg=1;
  853. position.z++;
  854. underground.show();
  855. }
  856. updateScreen = true;
  857. minimap.draw();
  858. }
  859. void CAdvMapInt::fshowQuestlog()
  860. {
  861. }
  862. void CAdvMapInt::fsleepWake()
  863. {
  864. }
  865. void CAdvMapInt::fmoveHero()
  866. {
  867. if (selection.type!=HEROI_TYPE)
  868. return;
  869. if (!terrain.currentPath)
  870. return;
  871. CPath sended(*(terrain.currentPath)); //temporary path - engine will operate on it
  872. LOCPLINT->cb->moveHero( ((const CGHeroInstance*)LOCPLINT->adventureInt->selection.selected)->type->ID,&sended,1,0);
  873. }
  874. void CAdvMapInt::fshowSpellbok()
  875. {
  876. }
  877. void CAdvMapInt::fadventureOPtions()
  878. {
  879. }
  880. void CAdvMapInt::fsystemOptions()
  881. {
  882. }
  883. void CAdvMapInt::fnextHero()
  884. {
  885. }
  886. void CAdvMapInt::fendTurn()
  887. {
  888. LOCPLINT->makingTurn = false;
  889. }
  890. void CAdvMapInt::activate()
  891. {
  892. LOCPLINT->curint = this;
  893. LOCPLINT->statusbar = &statusbar;
  894. kingOverview.activate();
  895. underground.activate();
  896. questlog.activate();
  897. sleepWake.activate();
  898. moveHero.activate();
  899. spellbook.activate();
  900. sysOptions.activate();
  901. advOptions.activate();
  902. nextHero.activate();
  903. endTurn.activate();
  904. minimap.activate();
  905. heroList.activate();
  906. townList.activate();
  907. terrain.activate();
  908. show();
  909. }
  910. void CAdvMapInt::deactivate()
  911. {
  912. hide();
  913. }
  914. void CAdvMapInt::show()
  915. {
  916. blitAt(bg,0,0);
  917. kingOverview.show();
  918. underground.show();
  919. questlog.show();
  920. sleepWake.show();
  921. moveHero.show();
  922. spellbook.show();
  923. advOptions.show();
  924. sysOptions.show();
  925. nextHero.show();
  926. endTurn.show();
  927. minimap.draw();
  928. heroList.draw();
  929. townList.draw();
  930. update();
  931. resdatabar.draw();
  932. statusbar.show();
  933. infoBar.draw();
  934. CSDL_Ext::update(screen);
  935. }
  936. void CAdvMapInt::hide()
  937. {
  938. kingOverview.deactivate();
  939. underground.deactivate();
  940. questlog.deactivate();
  941. sleepWake.deactivate();
  942. moveHero.deactivate();
  943. spellbook.deactivate();
  944. advOptions.deactivate();
  945. sysOptions.deactivate();
  946. nextHero.deactivate();
  947. endTurn.deactivate();
  948. minimap.deactivate();
  949. heroList.deactivate();
  950. townList.deactivate();
  951. terrain.deactivate();
  952. if(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar)!=LOCPLINT->timeinterested.end())
  953. LOCPLINT->timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar));
  954. infoBar.mode=-1;
  955. }
  956. void CAdvMapInt::update()
  957. {
  958. terrain.show();
  959. blitAt(gems[2]->ourImages[LOCPLINT->playerID].bitmap,6,6);
  960. blitAt(gems[0]->ourImages[LOCPLINT->playerID].bitmap,6,508);
  961. blitAt(gems[1]->ourImages[LOCPLINT->playerID].bitmap,556,508);
  962. blitAt(gems[3]->ourImages[LOCPLINT->playerID].bitmap,556,6);
  963. //updateRect(&genRect(550,600,6,6));
  964. }
  965. void CAdvMapInt::selectionChanged()
  966. {
  967. const CGTownInstance *to = townList.items[townList.selected];
  968. centerOn(to->pos);
  969. selection.type = TOWNI_TYPE;
  970. selection.selected = to;
  971. terrain.currentPath = NULL;
  972. townList.draw();
  973. heroList.draw();
  974. infoBar.draw(NULL);
  975. }
  976. void CAdvMapInt::centerOn(int3 on)
  977. {
  978. on.x -= (LOCPLINT->adventureInt->terrain.tilesw/2);
  979. on.y -= (LOCPLINT->adventureInt->terrain.tilesh/2);
  980. if (on.x<0)
  981. on.x=-(Woff/2);
  982. else if((on.x+LOCPLINT->adventureInt->terrain.tilesw) > (CGI->mh->sizes.x))
  983. on.x=CGI->mh->sizes.x-LOCPLINT->adventureInt->terrain.tilesw+(Woff/2);
  984. if (on.y<0)
  985. on.y = -(Hoff/2);
  986. else if((on.y+LOCPLINT->adventureInt->terrain.tilesh) > (CGI->mh->sizes.y))
  987. on.y = CGI->mh->sizes.y-LOCPLINT->adventureInt->terrain.tilesh+(Hoff/2);
  988. LOCPLINT->adventureInt->position.x=on.x;
  989. LOCPLINT->adventureInt->position.y=on.y;
  990. LOCPLINT->adventureInt->position.z=on.z;
  991. LOCPLINT->adventureInt->updateScreen=true;
  992. updateMinimap=true;
  993. }
  994. CAdvMapInt::CurrentSelection::CurrentSelection()
  995. {
  996. type=-1;
  997. selected=NULL;
  998. }
  999. void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * client)
  1000. {
  1001. if (down)
  1002. {
  1003. boost::algorithm::erase_all(text,"\"");
  1004. CSimpleWindow * temp = CMessage::genWindow(text,LOCPLINT->playerID);
  1005. temp->pos.x=300-(temp->pos.w/2);
  1006. temp->pos.y=300-(temp->pos.h/2);
  1007. temp->owner = client;
  1008. LOCPLINT->objsToBlit.push_back(temp);
  1009. }
  1010. else
  1011. {
  1012. for (int i=0;i<LOCPLINT->objsToBlit.size();i++)
  1013. {
  1014. //TODO: pewnie da sie to zrobic lepiej, ale nie chce mi sie. Wolajacy obiekt powinien informowac kogo spodziewa sie odwolac (null jesli down)
  1015. CSimpleWindow * pom = dynamic_cast<CSimpleWindow*>(LOCPLINT->objsToBlit[i]);
  1016. if (!pom)
  1017. continue;
  1018. if (pom->owner==client)
  1019. {
  1020. LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+(i));
  1021. delete pom;
  1022. }
  1023. }
  1024. }
  1025. }
  1026. int3 CAdvMapInt::verifyPos(int3 ver)
  1027. {
  1028. if (ver.x<0)
  1029. ver.x=0;
  1030. if (ver.y<0)
  1031. ver.y=0;
  1032. if (ver.z<0)
  1033. ver.z=0;
  1034. if (ver.x>=CGI->mh->sizes.x)
  1035. ver.x=CGI->mh->sizes.x-1;
  1036. if (ver.y>=CGI->mh->sizes.y)
  1037. ver.y=CGI->mh->sizes.y-1;
  1038. if (ver.z>=CGI->mh->sizes.z)
  1039. ver.z=CGI->mh->sizes.z-1;
  1040. return ver;
  1041. }