CAdvmapInterface.cpp 41 KB

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