CAdvmapInterface.cpp 40 KB

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