CAdvmapInterface.cpp 40 KB

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