CAdvmapInterface.cpp 33 KB

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