CAdvmapInterface.cpp 39 KB

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