CAdvmapInterface.cpp 38 KB

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