2
0

CAdvmapInterface.cpp 35 KB

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