CAdvmapInterface.cpp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358
  1. #include "stdafx.h"
  2. #include "CAdvmapInterface.h"
  3. #include "hch\CLodHandler.h"
  4. #include "hch\CPreGameTextHandler.h"
  5. #include "hch\CGeneralTextHandler.h"
  6. #include "hch\CTownHandler.h"
  7. #include "CPathfinder.h"
  8. #include "CGameInfo.h"
  9. #include "SDL_Extensions.h"
  10. #include "CCallback.h"
  11. #include <boost/assign/std/vector.hpp>
  12. #include "mapHandler.h"
  13. #include "CMessage.h"
  14. #include <boost/algorithm/string.hpp>
  15. #include <boost/algorithm/string/replace.hpp>
  16. extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
  17. using namespace boost::logic;
  18. using namespace boost::assign;
  19. using namespace CSDL_Ext;
  20. CAdvMapInt::~CAdvMapInt()
  21. {
  22. SDL_FreeSurface(bg);
  23. }
  24. AdventureMapButton::AdventureMapButton ()
  25. {
  26. type=2;
  27. abs=true;
  28. active=false;
  29. ourObj=NULL;
  30. state=0;
  31. }
  32. AdventureMapButton::AdventureMapButton
  33. ( std::string Name, std::string HelpBox, void(CAdvMapInt::*Function)(), int x, int y, std::string defName, bool activ, std::vector<std::string> * add )
  34. {
  35. type=2;
  36. abs=true;
  37. active=false;
  38. ourObj=NULL;
  39. state=0;
  40. name=Name;
  41. helpBox=HelpBox;
  42. int est = LOCPLINT->playerID;
  43. CDefHandler * temp = CGI->spriteh->giveDef(defName); //todo: moze cieknac
  44. for (int i=0;i<temp->ourImages.size();i++)
  45. {
  46. imgs.resize(1);
  47. imgs[0].push_back(temp->ourImages[i].bitmap);
  48. blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
  49. }
  50. if (add)
  51. {
  52. imgs.resize(imgs.size()+add->size());
  53. for (int i=0; i<add->size();i++)
  54. {
  55. temp = CGI->spriteh->giveDef((*add)[i]);
  56. for (int j=0;j<temp->ourImages.size();j++)
  57. {
  58. imgs[i+1].push_back(temp->ourImages[j].bitmap);
  59. blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
  60. }
  61. }
  62. delete add;
  63. }
  64. function = Function;
  65. pos.x=x;
  66. pos.y=y;
  67. pos.w = imgs[curimg][0]->w;
  68. pos.h = imgs[curimg][0]->h -1;
  69. if (activ)
  70. activate();
  71. }
  72. void AdventureMapButton::clickLeft (tribool down)
  73. {
  74. if (down)
  75. {
  76. state=1;
  77. }
  78. else
  79. {
  80. state=0;
  81. }
  82. show();
  83. if (pressedL && (down==false))
  84. (LOCPLINT->adventureInt->*function)();
  85. pressedL=state;
  86. }
  87. void AdventureMapButton::clickRight (tribool down)
  88. {
  89. LOCPLINT->adventureInt->handleRightClick(helpBox,down,this);
  90. }
  91. void AdventureMapButton::hover (bool on)
  92. {
  93. Hoverable::hover(on);
  94. if (on)
  95. LOCPLINT->adventureInt->statusbar.print(name);
  96. else if (LOCPLINT->adventureInt->statusbar.current==name)
  97. LOCPLINT->adventureInt->statusbar.clear();
  98. }
  99. void AdventureMapButton::activate()
  100. {
  101. if (active) return;
  102. active=true;
  103. ClickableL::activate();
  104. ClickableR::activate();
  105. Hoverable::activate();
  106. KeyInterested::activate();
  107. }
  108. void AdventureMapButton::keyPressed (SDL_KeyboardEvent & key)
  109. {
  110. //TODO: check if it's shortcut
  111. }
  112. void AdventureMapButton::deactivate()
  113. {
  114. if (!active) return;
  115. active=false;
  116. ClickableL::deactivate();
  117. Hoverable::deactivate();
  118. KeyInterested::deactivate();
  119. }
  120. void CList::activate()
  121. {
  122. ClickableL::activate();
  123. ClickableR::activate();
  124. Hoverable::activate();
  125. KeyInterested::activate();
  126. MotionInterested::activate();
  127. };
  128. void CList::deactivate()
  129. {
  130. ClickableL::deactivate();
  131. ClickableR::deactivate();
  132. Hoverable::deactivate();
  133. KeyInterested::deactivate();
  134. MotionInterested::deactivate();
  135. };
  136. void CList::clickLeft(tribool down)
  137. {
  138. };
  139. CHeroList::CHeroList()
  140. {
  141. pos = genRect(192,64,609,196);
  142. arrupp = genRect(16,64,609,196);
  143. arrdop = genRect(16,64,609,372);
  144. //32px per hero
  145. posmobx = 610;
  146. posmoby = 213;
  147. posporx = 617;
  148. pospory = 212;
  149. posmanx = 666;
  150. posmany = 213;
  151. arrup = CGI->spriteh->giveDef("IAM012.DEF");
  152. arrdo = CGI->spriteh->giveDef("IAM013.DEF");
  153. mobile = CGI->spriteh->giveDef("IMOBIL.DEF");
  154. mana = CGI->spriteh->giveDef("IMANA.DEF");
  155. empty = CGI->bitmaph->loadBitmap("HPSXXX.bmp");
  156. selection = CGI->bitmaph->loadBitmap("HPSYYY.bmp");
  157. SDL_SetColorKey(selection,SDL_SRCCOLORKEY,SDL_MapRGB(selection->format,0,255,255));
  158. from = 0;
  159. pressed = indeterminate;
  160. }
  161. void CHeroList::init()
  162. {
  163. bg = CSDL_Ext::newSurface(68,193,ekran);
  164. SDL_BlitSurface(LOCPLINT->adventureInt->bg,&genRect(193,68,607,196),bg,&genRect(193,68,0,0));
  165. }
  166. void CHeroList::genList()
  167. {
  168. int howMany = LOCPLINT->cb->howManyHeroes();
  169. for (int i=0;i<howMany;i++)
  170. {
  171. items.push_back(std::pair<const CHeroInstance *,CPath *>(LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,i,0),NULL));
  172. }
  173. }
  174. void CHeroList::select(int which)
  175. {
  176. selected = which;
  177. if (which>=items.size())
  178. return;
  179. LOCPLINT->adventureInt->centerOn(items[which].first->pos);
  180. LOCPLINT->adventureInt->selection.type = HEROI_TYPE;
  181. LOCPLINT->adventureInt->selection.selected = items[which].first;
  182. LOCPLINT->adventureInt->terrain.currentPath = items[which].second;
  183. draw();
  184. LOCPLINT->adventureInt->townList.draw();
  185. LOCPLINT->adventureInt->infoBar.draw(NULL);
  186. }
  187. void CHeroList::clickLeft(tribool down)
  188. {
  189. if (down)
  190. {
  191. /***************************ARROWS*****************************************/
  192. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  193. {
  194. blitAtWR(arrup->ourImages[1].bitmap,arrupp.x,arrupp.y);
  195. pressed = true;
  196. return;
  197. }
  198. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  199. {
  200. blitAtWR(arrdo->ourImages[1].bitmap,arrdop.x,arrdop.y);
  201. pressed = false;
  202. return;
  203. }
  204. /***************************HEROES*****************************************/
  205. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  206. hx-=pos.x;
  207. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  208. float ny = (float)hy/(float)32;
  209. if (ny>5 || ny<0)
  210. return;
  211. select(ny+from);
  212. }
  213. else
  214. {
  215. if (indeterminate(pressed))
  216. return;
  217. if (pressed) //up
  218. {
  219. blitAtWR(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  220. pressed = indeterminate;
  221. if (!down)
  222. {
  223. from--;
  224. if (from<0)
  225. from=0;
  226. draw();
  227. }
  228. }
  229. else if (!pressed) //down
  230. {
  231. blitAtWR(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  232. pressed = indeterminate;
  233. if (!down)
  234. {
  235. from++;
  236. //if (from<items.size()-5)
  237. // from=items.size()-5;
  238. draw();
  239. }
  240. }
  241. else
  242. throw 0;
  243. }
  244. }
  245. void CHeroList::mouseMoved (SDL_MouseMotionEvent & sEvent)
  246. {
  247. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  248. {
  249. if (from>0)
  250. LOCPLINT->adventureInt->statusbar.print(CGI->preth->advHListUp.first);
  251. else
  252. LOCPLINT->adventureInt->statusbar.clear();
  253. return;
  254. }
  255. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  256. {
  257. if ((items.size()-from) > 5)
  258. LOCPLINT->adventureInt->statusbar.print(CGI->preth->advHListDown.first);
  259. else
  260. LOCPLINT->adventureInt->statusbar.clear();
  261. return;
  262. }
  263. //if not buttons then heroes
  264. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  265. hx-=pos.x;
  266. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  267. float ny = (float)hy/(float)32;
  268. if ((ny>5 || ny<0) || (from+ny>=items.size()))
  269. {
  270. LOCPLINT->adventureInt->statusbar.clear();
  271. return;
  272. }
  273. std::vector<std::string> temp;
  274. temp+=(items[from+ny].first->name),(items[from+ny].first->type->heroClass->name);
  275. LOCPLINT->adventureInt->statusbar.print( processStr(CGI->generaltexth->allTexts[15],temp) );
  276. //select(ny+from);
  277. }
  278. void CHeroList::clickRight(tribool down)
  279. {
  280. if (down)
  281. {
  282. /***************************ARROWS*****************************************/
  283. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  284. {
  285. LOCPLINT->adventureInt->handleRightClick(CGI->preth->advHListUp.second,down,this);
  286. }
  287. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  288. {
  289. LOCPLINT->adventureInt->handleRightClick(CGI->preth->advHListDown.second,down,this);
  290. }
  291. }
  292. else
  293. {
  294. LOCPLINT->adventureInt->handleRightClick(CGI->preth->advHListUp.second,down,this);
  295. LOCPLINT->adventureInt->handleRightClick(CGI->preth->advHListDown.second,down,this);
  296. }
  297. }
  298. void CHeroList::hover (bool on)
  299. {
  300. }
  301. void CHeroList::keyPressed (SDL_KeyboardEvent & key)
  302. {
  303. }
  304. void CHeroList::draw()
  305. {
  306. for (int iT=0+from;iT<5+from;iT++)
  307. {
  308. int i = iT-from;
  309. if (iT>=items.size())
  310. {
  311. blitAtWR(mobile->ourImages[0].bitmap,posmobx,posmoby+i*32);
  312. blitAtWR(mana->ourImages[0].bitmap,posmanx,posmany+i*32);
  313. blitAtWR(empty,posporx,pospory+i*32);
  314. continue;
  315. }
  316. int pom = (LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->movement)/100;
  317. if (pom>25) pom=25;
  318. if (pom<0) pom=0;
  319. blitAtWR(mobile->ourImages[pom].bitmap,posmobx,posmoby+i*32); //move point
  320. pom = (LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->mana)/5; //bylo: .../10;
  321. if (pom>25) pom=25;
  322. if (pom<0) pom=0;
  323. blitAtWR(mana->ourImages[pom].bitmap,posmanx,posmany+i*32); //mana
  324. SDL_Surface * temp = LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->type->portraitSmall;
  325. blitAtWR(temp,posporx,pospory+i*32);
  326. if ((selected == iT) && (LOCPLINT->adventureInt->selection.type == HEROI_TYPE))
  327. {
  328. blitAtWR(selection,posporx,pospory+i*32);
  329. }
  330. //TODO: support for custom portraits
  331. }
  332. if (from>0)
  333. blitAtWR(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  334. else
  335. blitAtWR(arrup->ourImages[2].bitmap,arrupp.x,arrupp.y);
  336. if (items.size()-from>5)
  337. blitAtWR(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  338. else
  339. blitAtWR(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y);
  340. }
  341. CTownList::CTownList()
  342. {
  343. pos = genRect(192,48,747,196);
  344. arrup = CGI->spriteh->giveDef("IAM014.DEF");
  345. arrdo = CGI->spriteh->giveDef("IAM015.DEF");
  346. arrupp.x=747;
  347. arrupp.y=196;
  348. arrupp.w=arrup->ourImages[0].bitmap->w;
  349. arrupp.h=arrup->ourImages[0].bitmap->h;
  350. arrdop.x=747;
  351. arrdop.y=372;
  352. arrdop.w=arrdo->ourImages[0].bitmap->w;
  353. arrdop.h=arrdo->ourImages[0].bitmap->h;
  354. posporx = 747;
  355. pospory = 212;
  356. pressed = indeterminate;
  357. from = 0;
  358. }
  359. void CTownList::genList()
  360. {
  361. int howMany = LOCPLINT->cb->howManyTowns();
  362. for (int i=0;i<howMany;i++)
  363. {
  364. items.push_back(LOCPLINT->cb->getTownInfo(i,0));
  365. }
  366. }
  367. void CTownList::select(int which)
  368. {
  369. selected = which;
  370. if (which>=items.size())
  371. return;
  372. LOCPLINT->adventureInt->centerOn(items[which]->pos);
  373. LOCPLINT->adventureInt->selection.type = TOWNI_TYPE;
  374. LOCPLINT->adventureInt->selection.selected = items[which];
  375. LOCPLINT->adventureInt->terrain.currentPath = NULL;
  376. draw();
  377. LOCPLINT->adventureInt->heroList.draw();
  378. }
  379. void CTownList::mouseMoved (SDL_MouseMotionEvent & sEvent)
  380. {
  381. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  382. {
  383. if (from>0)
  384. LOCPLINT->adventureInt->statusbar.print(CGI->preth->advTListUp.first);
  385. else
  386. LOCPLINT->adventureInt->statusbar.clear();
  387. return;
  388. }
  389. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  390. {
  391. if ((items.size()-from) > 5)
  392. LOCPLINT->adventureInt->statusbar.print(CGI->preth->advTListDown.first);
  393. else
  394. LOCPLINT->adventureInt->statusbar.clear();
  395. return;
  396. }
  397. //if not buttons then heroes
  398. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  399. hx-=pos.x;
  400. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  401. float ny = (float)hy/(float)32;
  402. if ((ny>5 || ny<0) || (from+ny>=items.size()))
  403. {
  404. LOCPLINT->adventureInt->statusbar.clear();
  405. return;
  406. };
  407. //LOCPLINT->adventureInt->statusbar.print( items[from+ny]->name + ", " + items[from+ny]->town->name ); //TODO - uncomment when pointer to the town type is initialized
  408. }
  409. void CTownList::clickLeft(tribool down)
  410. {
  411. if (down)
  412. {
  413. /***************************ARROWS*****************************************/
  414. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  415. {
  416. blitAtWR(arrup->ourImages[1].bitmap,arrupp.x,arrupp.y);
  417. pressed = true;
  418. return;
  419. }
  420. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  421. {
  422. blitAtWR(arrdo->ourImages[1].bitmap,arrdop.x,arrdop.y);
  423. pressed = false;
  424. return;
  425. }
  426. /***************************TOWNS*****************************************/
  427. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  428. hx-=pos.x;
  429. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  430. float ny = (float)hy/(float)32;
  431. if (ny>5 || ny<0)
  432. return;
  433. select(ny+from);
  434. }
  435. else
  436. {
  437. if (indeterminate(pressed))
  438. return;
  439. if (pressed) //up
  440. {
  441. blitAtWR(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  442. pressed = indeterminate;
  443. if (!down)
  444. {
  445. from--;
  446. if (from<0)
  447. from=0;
  448. draw();
  449. }
  450. }
  451. else if (!pressed) //down
  452. {
  453. blitAtWR(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  454. pressed = indeterminate;
  455. if (!down)
  456. {
  457. from++;
  458. //if (from<items.size()-5)
  459. // from=items.size()-5;
  460. draw();
  461. }
  462. }
  463. else
  464. throw 0;
  465. }
  466. }
  467. void CTownList::clickRight(tribool down)
  468. {
  469. if (down)
  470. {
  471. /***************************ARROWS*****************************************/
  472. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  473. {
  474. LOCPLINT->adventureInt->handleRightClick(CGI->preth->advTListUp.second,down,this);
  475. }
  476. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  477. {
  478. LOCPLINT->adventureInt->handleRightClick(CGI->preth->advTListDown.second,down,this);
  479. }
  480. }
  481. else
  482. {
  483. LOCPLINT->adventureInt->handleRightClick(CGI->preth->advTListUp.second,down,this);
  484. LOCPLINT->adventureInt->handleRightClick(CGI->preth->advTListDown.second,down,this);
  485. }
  486. }
  487. void CTownList::hover (bool on)
  488. {
  489. }
  490. void CTownList::keyPressed (SDL_KeyboardEvent & key)
  491. {
  492. }
  493. void CTownList::draw()
  494. {
  495. for (int iT=0+from;iT<5+from;iT++)
  496. {
  497. int i = iT-from;
  498. if (iT>=items.size())
  499. {
  500. blitAtWR(CGI->townh->getPic(-1),posporx,pospory+i*32);
  501. continue;
  502. }
  503. blitAtWR(CGI->townh->getPic(items[i]->town->typeID),posporx,pospory+i*32);
  504. if ((selected == iT) && (LOCPLINT->adventureInt->selection.type == TOWNI_TYPE))
  505. {
  506. blitAtWR(CGI->townh->getPic(-2),posporx,pospory+i*32);
  507. }
  508. //TODO: dodac oznaczanie zbudowania w danej turze i posiadania fortu
  509. }
  510. if (from>0)
  511. blitAtWR(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  512. else
  513. blitAtWR(arrup->ourImages[2].bitmap,arrupp.x,arrupp.y);
  514. if (items.size()-from>5)
  515. blitAtWR(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  516. else
  517. blitAtWR(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y);
  518. }
  519. CStatusBar::CStatusBar(int x, int y)
  520. {
  521. bg=CGI->bitmaph->loadBitmap("ADROLLVR.bmp");
  522. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  523. pos.x=x;
  524. pos.y=y;
  525. pos.w=bg->w;
  526. pos.h=bg->h;
  527. middlex=(bg->w/2)+x;
  528. middley=(bg->h/2)+y;
  529. }
  530. CStatusBar::~CStatusBar()
  531. {
  532. SDL_FreeSurface(bg);
  533. }
  534. void CStatusBar::clear()
  535. {
  536. current="";
  537. blitAtWR(bg,pos.x,pos.y);
  538. }
  539. void CStatusBar::print(std::string text)
  540. {
  541. current=text;
  542. blitAtWR(bg,pos.x,pos.y);
  543. printAtMiddle(current,middlex,middley,GEOR13,zwykly);
  544. }
  545. void CStatusBar::show()
  546. {
  547. blitAtWR(bg,pos.x,pos.y);
  548. printAtMiddle(current,middlex,middley,GEOR13,zwykly);
  549. }
  550. CMinimap::CMinimap(bool draw)
  551. {
  552. statusbarTxt = CGI->preth->advWorldMap.first;
  553. rcText = CGI->preth->advWorldMap.second;
  554. pos.x=630;
  555. pos.y=26;
  556. pos.h=pos.w=144;
  557. //radar = CGI->spriteh->giveDef("RADAR.DEF");
  558. std::ifstream is("config/minimap.txt",std::ifstream::in);
  559. for (int i=0;i<TERRAIN_TYPES;i++)
  560. {
  561. std::pair<int,SDL_Color> vinya;
  562. std::pair<int,SDL_Color> vinya2;
  563. int pom;
  564. is >> pom;
  565. vinya2.first=vinya.first=pom;
  566. is >> pom;
  567. vinya.second.r=pom;
  568. is >> pom;
  569. vinya.second.g=pom;
  570. is >> pom;
  571. vinya.second.b=pom;
  572. is >> pom;
  573. vinya2.second.r=pom;
  574. is >> pom;
  575. vinya2.second.g=pom;
  576. is >> pom;
  577. vinya2.second.b=pom;
  578. vinya.second.unused=vinya2.second.unused=255;
  579. colors.insert(vinya);
  580. colorsBlocked.insert(vinya2);
  581. }
  582. is.close();
  583. if (draw)
  584. redraw();
  585. }
  586. void CMinimap::draw()
  587. {
  588. //draw terrain
  589. blitAtWR(map[LOCPLINT->adventureInt->position.z],pos.x,pos.y);
  590. //draw heroes
  591. std::vector <const CHeroInstance *> * hh = LOCPLINT->cb->getHeroesInfo(false);
  592. int mw = map[0]->w, mh = map[0]->h,
  593. wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y;
  594. for (int i=0; i<hh->size();i++)
  595. {
  596. int3 hpos = (*hh)[i]->getPosition(false);
  597. float zawx = ((float)hpos.x/CGI->mh->sizes.x), zawy = ((float)hpos.y/CGI->mh->sizes.y);
  598. int3 maplgp ( zawx*mw, zawy*mh, hpos.z );
  599. for (int ii=0; ii<wo; ii++)
  600. {
  601. for (int jj=0; jj<ho; jj++)
  602. {
  603. SDL_PutPixel(ekran,maplgp.x+pos.x+ii,maplgp.y+pos.y+jj,CGI->playerColors[(*hh)[i]->owner].r,CGI->playerColors[(*hh)[i]->owner].g,CGI->playerColors[(*hh)[i]->owner].b);
  604. }
  605. }
  606. }
  607. SDL_UpdateRect(ekran,pos.x,pos.y,pos.w,pos.h);
  608. delete hh;
  609. //draw FoW
  610. for (int i=0; i<mw; i++)
  611. {
  612. for (int j=0; j<mh; j++)
  613. {
  614. int3 pp;
  615. pp.x = (((float)i/mw)*CGI->mh->sizes.x);
  616. pp.y = (((float)j/mh)*CGI->mh->sizes.y);
  617. pp.z = LOCPLINT->adventureInt->position.z;
  618. if ( !LOCPLINT->cb->isVisible(pp) )
  619. {
  620. for (int ii=0; ii<wo; ii++)
  621. {
  622. for (int jj=0; jj<ho; jj++)
  623. {
  624. if ((i+ii<pos.w-1) && (j+jj<pos.h-1))
  625. SDL_PutPixel(ekran,i+pos.x+ii,j+pos.y+jj,0,0,0);
  626. }
  627. }
  628. }
  629. }
  630. }
  631. }
  632. void CMinimap::redraw(int level)// (level==-1) => redraw all levels
  633. {
  634. (CGameInfo::mainObj);
  635. for (int i=0; i<CGI->mh->sizes.z; i++)
  636. {
  637. SDL_Surface * pom ;
  638. if ((level>=0) && (i!=level))
  639. continue;
  640. if (map.size()<i+1)
  641. pom = CSDL_Ext::newSurface(pos.w,pos.h,ekran);
  642. else pom = map[i];
  643. for (int x=0;x<pos.w;x++)
  644. {
  645. for (int y=0;y<pos.h;y++)
  646. {
  647. int mx=(CGI->mh->sizes.x*x)/pos.w;
  648. int my=(CGI->mh->sizes.y*y)/pos.h;
  649. if (CGI->mh->ttiles[mx][my][i].blocked && (!CGI->mh->ttiles[mx][my][i].visitable))
  650. SDL_PutPixel(pom,x,y,colorsBlocked[CGI->mh->ttiles[mx][my][i].terType].r,colorsBlocked[CGI->mh->ttiles[mx][my][i].terType].g,colorsBlocked[CGI->mh->ttiles[mx][my][i].terType].b);
  651. else SDL_PutPixel(pom,x,y,colors[CGI->mh->ttiles[mx][my][i].terType].r,colors[CGI->mh->ttiles[mx][my][i].terType].g,colors[CGI->mh->ttiles[mx][my][i].terType].b);
  652. }
  653. }
  654. map.push_back(pom);
  655. }
  656. }
  657. void CMinimap::updateRadar()
  658. {}
  659. void CMinimap::clickRight (tribool down)
  660. {
  661. LOCPLINT->adventureInt->handleRightClick(rcText,down,this);
  662. }
  663. void CMinimap::clickLeft (tribool down)
  664. {
  665. if (down && (!pressedL))
  666. MotionInterested::activate();
  667. else if (!down)
  668. {
  669. if (std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this)!=LOCPLINT->motioninterested.end())
  670. MotionInterested::deactivate();
  671. }
  672. ClickableL::clickLeft(down);
  673. if (!((bool)down))
  674. return;
  675. float dx=((float)(LOCPLINT->current->motion.x-pos.x))/((float)pos.w),
  676. dy=((float)(LOCPLINT->current->motion.y-pos.y))/((float)pos.h);
  677. int3 newCPos;
  678. newCPos.x = (CGI->mh->sizes.x*dx);
  679. newCPos.y = (CGI->mh->sizes.y*dy);
  680. newCPos.z = LOCPLINT->adventureInt->position.z;
  681. LOCPLINT->adventureInt->centerOn(newCPos);
  682. }
  683. void CMinimap::hover (bool on)
  684. {
  685. Hoverable::hover(on);
  686. if (on)
  687. LOCPLINT->adventureInt->statusbar.print(statusbarTxt);
  688. else if (LOCPLINT->adventureInt->statusbar.current==statusbarTxt)
  689. LOCPLINT->adventureInt->statusbar.clear();
  690. }
  691. void CMinimap::mouseMoved (SDL_MouseMotionEvent & sEvent)
  692. {
  693. if (pressedL)
  694. {
  695. clickLeft(true);
  696. }
  697. }
  698. void CMinimap::activate()
  699. {
  700. ClickableL::activate();
  701. ClickableR::activate();
  702. Hoverable::activate();
  703. if (pressedL)
  704. MotionInterested::activate();
  705. }
  706. void CMinimap::deactivate()
  707. {
  708. if (pressedL)
  709. MotionInterested::deactivate();
  710. ClickableL::deactivate();
  711. ClickableR::deactivate();
  712. Hoverable::deactivate();
  713. }
  714. CTerrainRect::CTerrainRect():currentPath(NULL)
  715. {
  716. tilesw=19;
  717. tilesh=18;
  718. pos.x=7;
  719. pos.y=6;
  720. pos.w=593;
  721. pos.h=547;
  722. arrows = CGI->spriteh->giveDef("ADAG.DEF");
  723. for(int y=0; y<arrows->ourImages.size(); ++y)
  724. {
  725. CSDL_Ext::fullAlphaTransform(arrows->ourImages[y].bitmap);
  726. }
  727. }
  728. void CTerrainRect::activate()
  729. {
  730. ClickableL::activate();
  731. ClickableR::activate();
  732. Hoverable::activate();
  733. KeyInterested::activate();
  734. MotionInterested::activate();
  735. };
  736. void CTerrainRect::deactivate()
  737. {
  738. ClickableL::deactivate();
  739. ClickableR::deactivate();
  740. Hoverable::deactivate();
  741. KeyInterested::deactivate();
  742. MotionInterested::deactivate();
  743. };
  744. void CTerrainRect::clickLeft(tribool down)
  745. {
  746. if ((down==false) || indeterminate(down))
  747. return;
  748. if (LOCPLINT->adventureInt->selection.type != HEROI_TYPE)
  749. {
  750. if (currentPath)
  751. {
  752. delete currentPath;
  753. currentPath = NULL;
  754. }
  755. return;
  756. }
  757. int3 mp = whichTileIsIt();
  758. if ((mp.x<0) || (mp.y<0))
  759. return;
  760. if (currentPath)
  761. {
  762. if ( (currentPath->endPos()) == mp)
  763. { //move
  764. CPath sended(*currentPath); //temporary path - engine will operate on it
  765. LOCPLINT->cb->moveHero( ((const CHeroInstance*)LOCPLINT->adventureInt->selection.selected)->type->ID,&sended,1,0);
  766. }
  767. else
  768. {
  769. delete currentPath;
  770. currentPath=NULL;
  771. }
  772. }
  773. const CHeroInstance * currentHero = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].first;
  774. int3 bufpos = currentHero->getPosition(false);
  775. //bufpos.x-=1;
  776. currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->getPath(bufpos,mp,currentHero,1);
  777. //if (LOCPLINT->objsToBlit.size()==0)
  778. //{
  779. // CSimpleWindow * temp = CMessage::genWindow(" Tutaj dlugi dlugo test Tutaj dlugi dlugi dlugo test Tutaj dlugi dlugi dlugo test Tutaj dlugi dlugi dlugo test {Tutaj tytul} Tutaj dlugi dlugi dlugo test",0);
  780. // temp->pos.x=temp->pos.y=0;temp->ID=3;
  781. // LOCPLINT->objsToBlit.push_back(temp);
  782. //}
  783. //SDL_Delay(5000);
  784. }
  785. void CTerrainRect::clickRight(tribool down)
  786. {
  787. }
  788. void CTerrainRect::mouseMoved (SDL_MouseMotionEvent & sEvent)
  789. {
  790. int3 pom=LOCPLINT->adventureInt->verifyPos(whichTileIsIt(sEvent.x,sEvent.y));
  791. if (pom!=curHoveredTile)
  792. curHoveredTile=pom;
  793. else
  794. return;
  795. std::vector<std::string> temp = LOCPLINT->cb->getObjDescriptions(pom);
  796. if (temp.size())
  797. {
  798. LOCPLINT->adventureInt->statusbar.print((*((temp.end())-1)));
  799. }
  800. else
  801. {
  802. LOCPLINT->adventureInt->statusbar.clear();
  803. }
  804. }
  805. void CTerrainRect::keyPressed (SDL_KeyboardEvent & key){}
  806. void CTerrainRect::hover(bool on)
  807. {
  808. if (!on)
  809. LOCPLINT->adventureInt->statusbar.clear();
  810. }
  811. void CTerrainRect::show()
  812. {
  813. SDL_Surface * teren = CGI->mh->terrainRect
  814. (LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
  815. tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim, LOCPLINT->cb->getVisibilityMap());
  816. SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),ekran,&genRect(547,594,7,6));
  817. SDL_FreeSurface(teren);
  818. if (currentPath && LOCPLINT->adventureInt->position.z==currentPath->startPos().z) //drawing path
  819. {
  820. for (int i=0;i<currentPath->nodes.size()-1;i++)
  821. {
  822. int pn=-1;//number of picture
  823. if (i==0) //last tile
  824. {
  825. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  826. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  827. if (x<0 || y<0 || x>pos.w || y>pos.h)
  828. continue;
  829. pn=0;
  830. }
  831. else
  832. {
  833. std::vector<CPathNode> & cv = currentPath->nodes;
  834. if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1)
  835. {
  836. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  837. {
  838. pn = 3;
  839. }
  840. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  841. {
  842. pn = 12;
  843. }
  844. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  845. {
  846. pn = 21;
  847. }
  848. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  849. {
  850. pn = 22;
  851. }
  852. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  853. {
  854. pn = 2;
  855. }
  856. }
  857. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1)
  858. {
  859. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  860. {
  861. pn = 4;
  862. }
  863. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  864. {
  865. pn = 13;
  866. }
  867. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  868. {
  869. pn = 22;
  870. }
  871. }
  872. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1)
  873. {
  874. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  875. {
  876. pn = 5;
  877. }
  878. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  879. {
  880. pn = 14;
  881. }
  882. else if(cv[i-1].coord.x+1 == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y)
  883. {
  884. pn = 23;
  885. }
  886. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  887. {
  888. pn = 24;
  889. }
  890. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  891. {
  892. pn = 4;
  893. }
  894. }
  895. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y)
  896. {
  897. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  898. {
  899. pn = 6;
  900. }
  901. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
  902. {
  903. pn = 15;
  904. }
  905. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  906. {
  907. pn = 24;
  908. }
  909. }
  910. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1)
  911. {
  912. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
  913. {
  914. pn = 7;
  915. }
  916. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  917. {
  918. pn = 16;
  919. }
  920. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  921. {
  922. pn = 17;
  923. }
  924. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  925. {
  926. pn = 6;
  927. }
  928. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  929. {
  930. pn = 18;
  931. }
  932. }
  933. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1)
  934. {
  935. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  936. {
  937. pn = 8;
  938. }
  939. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  940. {
  941. pn = 9;
  942. }
  943. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  944. {
  945. pn = 18;
  946. }
  947. }
  948. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1)
  949. {
  950. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  951. {
  952. pn = 1;
  953. }
  954. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  955. {
  956. pn = 10;
  957. }
  958. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  959. {
  960. pn = 19;
  961. }
  962. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  963. {
  964. pn = 8;
  965. }
  966. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  967. {
  968. pn = 20;
  969. }
  970. }
  971. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y)
  972. {
  973. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  974. {
  975. pn = 2;
  976. }
  977. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  978. {
  979. pn = 11;
  980. }
  981. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  982. {
  983. pn = 20;
  984. }
  985. }
  986. }
  987. if ( ((currentPath->nodes[i].dist)-(*(currentPath->nodes.end()-1)).dist) > ((const CHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->movement)
  988. pn+=25;
  989. if (pn>=0)
  990. {
  991. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  992. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  993. if (x<0 || y<0 || x>pos.w || y>pos.h)
  994. continue;
  995. int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
  996. hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
  997. if (hvx<0 && hvy<0)
  998. blitAtWR(arrows->ourImages[pn].bitmap,x,y);
  999. else if(hvx<0)
  1000. SDL_BlitSurface
  1001. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,0,0),
  1002. ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,x,y));
  1003. else if (hvy<0)
  1004. {
  1005. SDL_BlitSurface
  1006. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  1007. ekran,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  1008. }
  1009. else
  1010. SDL_BlitSurface
  1011. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  1012. ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  1013. }
  1014. } //for (int i=0;i<currentPath->nodes.size()-1;i++)
  1015. } // if (currentPath)
  1016. }
  1017. int3 CTerrainRect::whichTileIsIt(int x, int y)
  1018. {
  1019. int3 ret;
  1020. ret.x = LOCPLINT->adventureInt->position.x + ((LOCPLINT->current->motion.x-pos.x)/32);
  1021. ret.y = LOCPLINT->adventureInt->position.y + ((LOCPLINT->current->motion.y-pos.y)/32);
  1022. ret.z = LOCPLINT->adventureInt->position.z;
  1023. return ret;
  1024. }
  1025. int3 CTerrainRect::whichTileIsIt()
  1026. {
  1027. return whichTileIsIt(LOCPLINT->current->motion.x,LOCPLINT->current->motion.y);
  1028. }
  1029. void CResDataBar::clickRight (tribool down)
  1030. {
  1031. }
  1032. void CResDataBar::activate()
  1033. {
  1034. ClickableR::activate();
  1035. }
  1036. void CResDataBar::deactivate()
  1037. {
  1038. ClickableR::deactivate();
  1039. }
  1040. CResDataBar::CResDataBar()
  1041. {
  1042. bg = CGI->bitmaph->loadBitmap("ZRESBAR.bmp");
  1043. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  1044. //std::vector<SDL_Color> kolory;
  1045. //SDL_Color p1={40,65,139,255}, p2={36,59,125,255}, p3={35,56,121,255};
  1046. //kolory+=p1,p2,p3;
  1047. //blueToPlayersAdv(bg,LOCPLINT->playerID,2,&kolory);
  1048. blueToPlayersAdv(bg,LOCPLINT->playerID,2);
  1049. pos = genRect(bg->h,bg->w,3,575);
  1050. txtpos += (std::pair<int,int>(35,577)),(std::pair<int,int>(120,577)),(std::pair<int,int>(205,577)),
  1051. (std::pair<int,int>(290,577)),(std::pair<int,int>(375,577)),(std::pair<int,int>(460,577)),
  1052. (std::pair<int,int>(545,577)),(std::pair<int,int>(620,577));
  1053. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63] + ": %s, " +
  1054. CGI->generaltexth->allTexts[64] + ": %s";
  1055. }
  1056. CResDataBar::~CResDataBar()
  1057. {
  1058. SDL_FreeSurface(bg);
  1059. }
  1060. void CResDataBar::draw()
  1061. {
  1062. blitAt(bg,pos.x,pos.y);
  1063. char * buf = new char[15];
  1064. for (int i=0;i<7;i++)
  1065. {
  1066. itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
  1067. printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly);
  1068. }
  1069. std::vector<std::string> temp;
  1070. itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf);
  1071. itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf);
  1072. itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf);
  1073. printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,GEOR13,zwykly);
  1074. temp.clear();
  1075. updateRect(&pos,ekran);
  1076. delete buf;
  1077. }
  1078. CInfoBar::CInfoBar()
  1079. {
  1080. pos.x=605;
  1081. pos.y=389;
  1082. pos.w=194;
  1083. pos.h=186;
  1084. }
  1085. void CInfoBar::draw(void * specific)
  1086. {
  1087. SDL_Surface * todr = LOCPLINT->infoWin(specific);
  1088. blitAt(todr,pos.x,pos.y);
  1089. SDL_FreeSurface(todr);
  1090. }
  1091. CAdvMapInt::CAdvMapInt(int Player)
  1092. :player(Player),
  1093. statusbar(7,556),
  1094. kingOverview(CGI->preth->advKingdomOverview.first,CGI->preth->advKingdomOverview.second,
  1095. &CAdvMapInt::fshowOverview, 679, 196, "IAM002.DEF"),
  1096. underground(CGI->preth->advSurfaceSwitch.first,CGI->preth->advSurfaceSwitch.second,
  1097. &CAdvMapInt::fswitchLevel, 711, 196, "IAM010.DEF", false, new std::vector<std::string>(1,std::string("IAM003.DEF"))),
  1098. questlog(CGI->preth->advQuestlog.first,CGI->preth->advQuestlog.second,
  1099. &CAdvMapInt::fshowQuestlog, 679, 228, "IAM004.DEF"),
  1100. sleepWake(CGI->preth->advSleepWake.first,CGI->preth->advSleepWake.second,
  1101. &CAdvMapInt::fsleepWake, 711, 228, "IAM005.DEF"),
  1102. moveHero(CGI->preth->advMoveHero.first,CGI->preth->advMoveHero.second,
  1103. &CAdvMapInt::fmoveHero, 679, 260, "IAM006.DEF"),
  1104. spellbook(CGI->preth->advCastSpell.first,CGI->preth->advCastSpell.second,
  1105. &CAdvMapInt::fshowSpellbok, 711, 260, "IAM007.DEF"),
  1106. advOptions(CGI->preth->advAdvOptions.first,CGI->preth->advAdvOptions.second,
  1107. &CAdvMapInt::fadventureOPtions, 679, 292, "IAM008.DEF"),
  1108. sysOptions(CGI->preth->advSystemOptions.first,CGI->preth->advSystemOptions.second,
  1109. &CAdvMapInt::fsystemOptions, 711, 292, "IAM009.DEF"),
  1110. nextHero(CGI->preth->advNextHero.first,CGI->preth->advNextHero.second,
  1111. &CAdvMapInt::fnextHero, 679, 324, "IAM000.DEF"),
  1112. endTurn(CGI->preth->advEndTurn.first,CGI->preth->advEndTurn.second,
  1113. &CAdvMapInt::fendTurn, 679, 356, "IAM001.DEF")
  1114. {
  1115. LOCPLINT->adventureInt=this;
  1116. bg = CGI->bitmaph->loadBitmap("ADVMAP.bmp");
  1117. blueToPlayersAdv(bg,player);
  1118. scrollingLeft = false;
  1119. scrollingRight = false;
  1120. scrollingUp = false ;
  1121. scrollingDown = false ;
  1122. updateScreen = false;
  1123. anim=0;
  1124. animValHitCount=0; //animation frame
  1125. heroList.init();
  1126. heroList.genList();
  1127. //townList.init();
  1128. townList.genList();
  1129. gems.push_back(CGI->spriteh->giveDef("agemLL.def"));
  1130. gems.push_back(CGI->spriteh->giveDef("agemLR.def"));
  1131. gems.push_back(CGI->spriteh->giveDef("agemUL.def"));
  1132. gems.push_back(CGI->spriteh->giveDef("agemUR.def"));
  1133. }
  1134. void CAdvMapInt::fshowOverview()
  1135. {
  1136. }
  1137. void CAdvMapInt::fswitchLevel()
  1138. {
  1139. if(!CGI->ac->map.twoLevel)
  1140. return;
  1141. if (position.z)
  1142. {
  1143. position.z--;
  1144. underground.curimg=0;
  1145. underground.show();
  1146. }
  1147. else
  1148. {
  1149. underground.curimg=1;
  1150. position.z++;
  1151. underground.show();
  1152. }
  1153. updateScreen = true;
  1154. minimap.draw();
  1155. }
  1156. void CAdvMapInt::fshowQuestlog()
  1157. {
  1158. }
  1159. void CAdvMapInt::fsleepWake()
  1160. {
  1161. }
  1162. void CAdvMapInt::fmoveHero()
  1163. {
  1164. if (selection.type!=HEROI_TYPE)
  1165. return;
  1166. if (!terrain.currentPath)
  1167. return;
  1168. CPath sended(*(terrain.currentPath)); //temporary path - engine will operate on it
  1169. LOCPLINT->cb->moveHero( ((const CHeroInstance*)LOCPLINT->adventureInt->selection.selected)->type->ID,&sended,1,0);
  1170. }
  1171. void CAdvMapInt::fshowSpellbok()
  1172. {
  1173. }
  1174. void CAdvMapInt::fadventureOPtions()
  1175. {
  1176. }
  1177. void CAdvMapInt::fsystemOptions()
  1178. {
  1179. }
  1180. void CAdvMapInt::fnextHero()
  1181. {
  1182. }
  1183. void CAdvMapInt::fendTurn()
  1184. {
  1185. LOCPLINT->makingTurn = false;
  1186. }
  1187. void CAdvMapInt::show()
  1188. {
  1189. blitAt(bg,0,0);
  1190. kingOverview.show();
  1191. kingOverview.activate();
  1192. underground.show();
  1193. underground.activate();
  1194. questlog.show();
  1195. questlog.activate();
  1196. sleepWake.show();
  1197. sleepWake.activate();
  1198. moveHero.show();
  1199. moveHero.activate();
  1200. spellbook.show();
  1201. spellbook.activate();
  1202. advOptions.show();
  1203. advOptions.activate();
  1204. sysOptions.show();
  1205. sysOptions.activate();
  1206. nextHero.show();
  1207. nextHero.activate();
  1208. endTurn.show();
  1209. endTurn.activate();
  1210. minimap.activate();
  1211. minimap.draw();
  1212. heroList.activate();
  1213. heroList.draw();
  1214. townList.activate();
  1215. townList.draw();
  1216. terrain.activate();
  1217. resdatabar.draw();
  1218. statusbar.show();
  1219. SDL_Flip(ekran);
  1220. }
  1221. void CAdvMapInt::hide()
  1222. {
  1223. kingOverview.deactivate();
  1224. underground.deactivate();
  1225. questlog.deactivate();
  1226. sleepWake.deactivate();
  1227. moveHero.deactivate();
  1228. spellbook.deactivate();
  1229. advOptions.deactivate();
  1230. sysOptions.deactivate();
  1231. nextHero.deactivate();
  1232. endTurn.deactivate();
  1233. minimap.deactivate();
  1234. heroList.deactivate();
  1235. townList.deactivate();
  1236. terrain.deactivate();
  1237. }
  1238. void CAdvMapInt::update()
  1239. {
  1240. terrain.show();
  1241. blitAt(gems[2]->ourImages[LOCPLINT->playerID].bitmap,6,6);
  1242. blitAt(gems[0]->ourImages[LOCPLINT->playerID].bitmap,6,508);
  1243. blitAt(gems[1]->ourImages[LOCPLINT->playerID].bitmap,556,508);
  1244. blitAt(gems[3]->ourImages[LOCPLINT->playerID].bitmap,556,6);
  1245. updateRect(&genRect(550,600,6,6));
  1246. }
  1247. void CAdvMapInt::centerOn(int3 on)
  1248. {
  1249. on.x -= (LOCPLINT->adventureInt->terrain.tilesw/2);
  1250. on.y -= (LOCPLINT->adventureInt->terrain.tilesh/2);
  1251. if (on.x<0)
  1252. on.x=-(Woff/2);
  1253. else if((on.x+LOCPLINT->adventureInt->terrain.tilesw) > (CGI->mh->sizes.x))
  1254. on.x=CGI->mh->sizes.x-LOCPLINT->adventureInt->terrain.tilesw+(Woff/2);
  1255. if (on.y<0)
  1256. on.y = -(Hoff/2);
  1257. else if((on.y+LOCPLINT->adventureInt->terrain.tilesh) > (CGI->mh->sizes.y))
  1258. on.y = CGI->mh->sizes.y-LOCPLINT->adventureInt->terrain.tilesh+(Hoff/2);
  1259. LOCPLINT->adventureInt->position.x=on.x;
  1260. LOCPLINT->adventureInt->position.y=on.y;
  1261. LOCPLINT->adventureInt->position.z=on.z;
  1262. LOCPLINT->adventureInt->updateScreen=true;
  1263. }
  1264. CAdvMapInt::CurrentSelection::CurrentSelection()
  1265. {
  1266. type=-1;
  1267. selected=NULL;
  1268. }
  1269. void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * client)
  1270. {
  1271. if (down)
  1272. {
  1273. boost::algorithm::erase_all(text,"\"");
  1274. CSimpleWindow * temp = CMessage::genWindow(text,LOCPLINT->playerID);
  1275. temp->pos.x=300-(temp->pos.w/2);
  1276. temp->pos.y=300-(temp->pos.h/2);
  1277. temp->owner = client;
  1278. LOCPLINT->objsToBlit.push_back(temp);
  1279. }
  1280. else
  1281. {
  1282. for (int i=0;i<LOCPLINT->objsToBlit.size();i++)
  1283. {
  1284. if (LOCPLINT->objsToBlit[i]->owner==client)
  1285. {
  1286. LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+(i));
  1287. }
  1288. }
  1289. }
  1290. }
  1291. int3 CAdvMapInt::verifyPos(int3 ver)
  1292. {
  1293. if (ver.x<0)
  1294. ver.x=0;
  1295. if (ver.y<0)
  1296. ver.y=0;
  1297. if (ver.z<0)
  1298. ver.z=0;
  1299. if (ver.x>=CGI->mh->sizes.x)
  1300. ver.x=CGI->mh->sizes.x-1;
  1301. if (ver.y>=CGI->mh->sizes.y)
  1302. ver.y=CGI->mh->sizes.y-1;
  1303. if (ver.z>=CGI->mh->sizes.z)
  1304. ver.z=CGI->mh->sizes.z-1;
  1305. return ver;
  1306. }