CAdvmapInterface.cpp 38 KB

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