CAdvmapInterface.cpp 42 KB

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