CAdvmapInterface.cpp 40 KB

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