CAdvmapInterface.cpp 41 KB

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