CAdvmapInterface.cpp 42 KB

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