CAdvmapInterface.cpp 39 KB

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