CAdvmapInterface.cpp 29 KB

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