CAdvmapInterface.cpp 39 KB

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