CAdvmapInterface.cpp 40 KB

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