CAdvmapInterface.cpp 30 KB

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