CAdvmapInterface.cpp 34 KB

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