CAdvmapInterface.cpp 39 KB

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