CAdvmapInterface.cpp 38 KB

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