CAdvmapInterface.cpp 37 KB

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