CAdvmapInterface.cpp 42 KB

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