CAdvmapInterface.cpp 37 KB

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