CAdvmapInterface.cpp 40 KB

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