CCastleInterface.cpp 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803
  1. #include "../stdafx.h"
  2. #include "CCastleInterface.h"
  3. #include "AdventureMapButton.h"
  4. #include "CAdvmapInterface.h"
  5. #include "../CCallback.h"
  6. #include "CGameInfo.h"
  7. #include "CHeroWindow.h"
  8. #include "CMessage.h"
  9. #include "SDL_Extensions.h"
  10. #include "CCreatureAnimation.h"
  11. #include "Graphics.h"
  12. #include "../hch/CArtHandler.h"
  13. #include "../hch/CBuildingHandler.h"
  14. #include "../hch/CDefHandler.h"
  15. #include "../hch/CGeneralTextHandler.h"
  16. #include "../hch/CLodHandler.h"
  17. #include "../hch/CObjectHandler.h"
  18. #include "../hch/CSpellHandler.h"
  19. #include "../hch/CTownHandler.h"
  20. #include <boost/algorithm/string.hpp>
  21. #include <boost/algorithm/string/replace.hpp>
  22. #include <boost/assign/std/vector.hpp>
  23. #include <boost/lexical_cast.hpp>
  24. #include <cmath>
  25. #include <sstream>
  26. using namespace boost::assign;
  27. using namespace CSDL_Ext;
  28. /*
  29. * CCastleInterface.cpp, part of VCMI engine
  30. *
  31. * Authors: listed in file AUTHORS in main folder
  32. *
  33. * License: GNU General Public License v2.0 or later
  34. * Full text of license available in license.txt file, in main folder
  35. *
  36. */
  37. extern TTF_Font * GEOR16;
  38. CBuildingRect::CBuildingRect(Structure *Str)
  39. :moi(false), offset(0), str(Str)
  40. {
  41. def = CDefHandler::giveDef(Str->defName);
  42. max = def->ourImages.size();
  43. if(str->ID == 33 && str->townID == 4) //little 'hack' for estate in necropolis - background color is not always the first color in the palette
  44. {
  45. for(std::vector<Cimage>::iterator i=def->ourImages.begin();i!=def->ourImages.end();i++)
  46. {
  47. SDL_SetColorKey(i->bitmap,SDL_SRCCOLORKEY,*((char*)i->bitmap->pixels));
  48. }
  49. }
  50. pos.x = str->pos.x + LOCPLINT->castleInt->pos.x;
  51. pos.y = str->pos.y + LOCPLINT->castleInt->pos.y;
  52. pos.w = def->ourImages[0].bitmap->w;
  53. pos.h = def->ourImages[0].bitmap->h;
  54. if(Str->ID<0 || (Str->ID>=27 && Str->ID<=29))
  55. {
  56. area = border = NULL;
  57. return;
  58. }
  59. if (border = BitmapHandler::loadBitmap(str->borderName)) //FIXME hmmm if '=' use () else '==' fatal mistake
  60. {
  61. SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255));
  62. }
  63. else
  64. {
  65. tlog2 << "Warning: no border for "<<Str->ID<<std::endl;
  66. }
  67. if (area = BitmapHandler::loadBitmap(str->areaName))//FIXME look up
  68. {
  69. ;//SDL_SetColorKey(area,SDL_SRCCOLORKEY,SDL_MapRGB(area->format,0,255,255));
  70. }
  71. else
  72. {
  73. tlog2 << "Warning: no area for "<<Str->ID<<std::endl;
  74. }
  75. }
  76. CBuildingRect::~CBuildingRect()
  77. {
  78. delete def;
  79. if(border)
  80. SDL_FreeSurface(border);
  81. if(area)
  82. SDL_FreeSurface(area);
  83. }
  84. void CBuildingRect::activate()
  85. {
  86. activateHover();
  87. activateLClick();
  88. activateRClick();
  89. }
  90. void CBuildingRect::deactivate()
  91. {
  92. deactivateHover();
  93. deactivateLClick();
  94. deactivateRClick();
  95. if(moi)
  96. deactivateMouseMove();
  97. moi=false;
  98. }
  99. bool CBuildingRect::operator<(const CBuildingRect & p2) const
  100. {
  101. if(str->pos.z != p2.str->pos.z)
  102. return (str->pos.z) < (p2.str->pos.z);
  103. else
  104. return (str->ID) < (p2.str->ID);
  105. }
  106. void CBuildingRect::hover(bool on)
  107. {
  108. //Hoverable::hover(on);
  109. if(on)
  110. {
  111. if(!moi)
  112. activateMouseMove();
  113. moi = true;
  114. }
  115. else
  116. {
  117. if(moi)
  118. deactivateMouseMove();
  119. moi = false;
  120. if(LOCPLINT->castleInt->hBuild == this)
  121. {
  122. LOCPLINT->castleInt->hBuild = NULL;
  123. LOCPLINT->statusbar->clear();
  124. //call mouseMoved in other buildings, cursor might have been moved while they were inactive (eg. because of r-click popup)
  125. for(size_t i = 0; i < LOCPLINT->castleInt->buildings.size(); i++)
  126. LOCPLINT->castleInt->buildings[i]->mouseMoved(GH.current->motion);
  127. }
  128. }
  129. }
  130. void CBuildingRect::clickLeft(tribool down, bool previousState)
  131. {
  132. if(area && (LOCPLINT->castleInt->hBuild==this) && !(indeterminate(down)) && (CSDL_Ext::SDL_GetPixel(area,GH.current->motion.x-pos.x,GH.current->motion.y-pos.y) != 0)) //na polu
  133. {
  134. if(previousState && !down)
  135. LOCPLINT->castleInt->buildingClicked(str->ID);
  136. //ClickableL::clickLeft(down);
  137. }
  138. }
  139. void CBuildingRect::clickRight(tribool down, bool previousState)
  140. {
  141. if((!area) || (!((bool)down)) || (this!=LOCPLINT->castleInt->hBuild))
  142. return;
  143. if((CSDL_Ext::SDL_GetPixel(area,GH.current->motion.x-pos.x,GH.current->motion.y-pos.y) != 0)) //na polu
  144. {
  145. CBuilding *bld = CGI->buildh->buildings[str->townID][str->ID];
  146. assert(bld);
  147. CInfoPopup *vinya = new CInfoPopup();
  148. vinya->free = true;
  149. vinya->bitmap = CMessage::drawBoxTextBitmapSub
  150. (LOCPLINT->playerID,
  151. bld->Description(),
  152. LOCPLINT->castleInt->bicons->ourImages[str->ID].bitmap,
  153. bld->Name());
  154. vinya->pos.x = screen->w/2 - vinya->bitmap->w/2;
  155. vinya->pos.y = screen->h/2 - vinya->bitmap->h/2;
  156. GH.pushInt(vinya);
  157. }
  158. }
  159. void CBuildingRect::mouseMoved (const SDL_MouseMotionEvent & sEvent)
  160. {
  161. if(area && isItIn(&pos,sEvent.x, sEvent.y))
  162. {
  163. if(CSDL_Ext::SDL_GetPixel(area,sEvent.x-pos.x,sEvent.y-pos.y) == 0) //hovered pixel is inside this building
  164. {
  165. if(LOCPLINT->castleInt->hBuild == this)
  166. {
  167. LOCPLINT->castleInt->hBuild = NULL;
  168. LOCPLINT->statusbar->clear();
  169. }
  170. }
  171. else //inside the area of this building
  172. {
  173. if(LOCPLINT->castleInt->hBuild) //a building is hovered
  174. {
  175. if((*LOCPLINT->castleInt->hBuild)<(*this)) //set if we are on top
  176. {
  177. LOCPLINT->castleInt->hBuild = this;
  178. if(CGI->buildh->buildings[str->townID][str->ID] && CGI->buildh->buildings[str->townID][str->ID]->Name().length())
  179. LOCPLINT->statusbar->print(CGI->buildh->buildings[str->townID][str->ID]->Name());
  180. else
  181. LOCPLINT->statusbar->print(str->name);
  182. }
  183. }
  184. else //no building hovered
  185. {
  186. LOCPLINT->castleInt->hBuild = this;
  187. if(CGI->buildh->buildings[str->townID][str->ID] && CGI->buildh->buildings[str->townID][str->ID]->Name().length())
  188. LOCPLINT->statusbar->print(CGI->buildh->buildings[str->townID][str->ID]->Name());
  189. else
  190. LOCPLINT->statusbar->print(str->name);
  191. }
  192. }
  193. }
  194. //if(border)
  195. // blitAt(border,pos.x,pos.y);
  196. }
  197. void CHeroGSlot::hover (bool on)
  198. {
  199. if(!on) return;
  200. CHeroGSlot *other = upg ? &owner->hslotup : &owner->hslotdown;
  201. std::string temp;
  202. if(hero)
  203. {
  204. if(highlight)//view NNN
  205. {
  206. temp = CGI->generaltexth->tcommands[4];
  207. boost::algorithm::replace_first(temp,"%s",hero->name);
  208. }
  209. else if(other->hero && other->highlight)//exchange
  210. {
  211. temp = CGI->generaltexth->tcommands[7];
  212. boost::algorithm::replace_first(temp,"%s",hero->name);
  213. boost::algorithm::replace_first(temp,"%s",other->hero->name);
  214. }
  215. else// select NNN (in ZZZ)
  216. {
  217. if(upg)//down - visiting
  218. {
  219. temp = CGI->generaltexth->tcommands[32];
  220. boost::algorithm::replace_first(temp,"%s",hero->name);
  221. }
  222. else //up - garrison
  223. {
  224. temp = CGI->generaltexth->tcommands[12];
  225. boost::algorithm::replace_first(temp,"%s",hero->name);
  226. }
  227. }
  228. }
  229. else //we are empty slot
  230. {
  231. if(other->highlight && other->hero) //move NNNN
  232. {
  233. temp = CGI->generaltexth->tcommands[6];
  234. boost::algorithm::replace_first(temp,"%s",other->hero->name);
  235. }
  236. else //empty
  237. {
  238. temp = CGI->generaltexth->allTexts[507];
  239. }
  240. }
  241. if(temp.size())
  242. LOCPLINT->statusbar->print(temp);
  243. }
  244. void CHeroGSlot::clickRight(tribool down, bool previousState)
  245. {
  246. }
  247. void CHeroGSlot::clickLeft(tribool down, bool previousState)
  248. {
  249. CHeroGSlot *other = upg ? &owner->hslotup : &owner->hslotdown;
  250. if(!down)
  251. {
  252. owner->garr->splitting = false;
  253. owner->garr->highlighted = NULL;
  254. if(hero && highlight)
  255. {
  256. setHighlight(false);
  257. LOCPLINT->openHeroWindow(hero);
  258. }
  259. else if(other->hero && other->highlight)
  260. {
  261. bool allow = true;
  262. if(upg) //moving hero out of town - check if it is allowed
  263. {
  264. if(!hero && LOCPLINT->cb->howManyHeroes(false) >= 8)
  265. {
  266. std::string tmp = CGI->generaltexth->allTexts[18]; //You already have %d adventuring heroes under your command.
  267. boost::algorithm::replace_first(tmp,"%d",boost::lexical_cast<std::string>(LOCPLINT->cb->howManyHeroes(false)));
  268. LOCPLINT->showInfoDialog(tmp,std::vector<SComponent*>(), soundBase::sound_todo);
  269. allow = false;
  270. }
  271. else if(!other->hero->army.slots.size()) //hero has no creatures - strange, but if we have appropriate error message...
  272. {
  273. LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[19],std::vector<SComponent*>(), soundBase::sound_todo); //This hero has no creatures. A hero must have creatures before he can brave the dangers of the countryside.
  274. allow = false;
  275. }
  276. }
  277. setHighlight(false);
  278. other->setHighlight(false);
  279. if(allow)
  280. LOCPLINT->cb->swapGarrisonHero(owner->town);
  281. }
  282. else if(hero)
  283. {
  284. setHighlight(true);
  285. owner->garr->highlighted = NULL;
  286. show(screen2);
  287. }
  288. hover(false);hover(true); //refresh statusbar
  289. }
  290. //if(indeterminate(down) && !isItIn(&other->pos,GH.current->motion.x,GH.current->motion.y))
  291. //{
  292. // other->highlight = highlight = false;
  293. // show(screen2);
  294. //}
  295. }
  296. void CHeroGSlot::activate()
  297. {
  298. activateLClick();
  299. activateRClick();
  300. activateHover();
  301. }
  302. void CHeroGSlot::deactivate()
  303. {
  304. highlight = false;
  305. deactivateLClick();
  306. deactivateRClick();
  307. deactivateHover();
  308. }
  309. void CHeroGSlot::show(SDL_Surface * to)
  310. {
  311. if(hero) //there is hero
  312. blitAt(graphics->portraitLarge[hero->portrait],pos,to);
  313. else if(!upg) //up garrison
  314. blitAt(graphics->flags->ourImages[LOCPLINT->castleInt->town->getOwner()].bitmap,pos,to);
  315. if(highlight)
  316. blitAt(graphics->bigImgs[-1],pos,to);
  317. }
  318. CHeroGSlot::CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h, CCastleInterface * Owner)
  319. {
  320. owner = Owner;
  321. pos.x = x;
  322. pos.y = y;
  323. pos.w = 58;
  324. pos.h = 64;
  325. hero = h;
  326. upg = updown;
  327. highlight = false;
  328. }
  329. CHeroGSlot::~CHeroGSlot()
  330. {
  331. }
  332. void CHeroGSlot::setHighlight( bool on )
  333. {
  334. highlight = on;
  335. if(owner->hslotup.hero && owner->hslotdown.hero) //two heroes in town
  336. {
  337. for(size_t i = 0; i<owner->garr->splitButtons.size(); i++) //splitting enabled when slot higlighted
  338. owner->garr->splitButtons[i]->block(!on);
  339. }
  340. }
  341. static std::string getBgName(int type) //TODO - co z tym zrobi�?
  342. {
  343. switch (type)
  344. {
  345. case 0:
  346. return "TBCSBACK.bmp";
  347. case 1:
  348. return "TBRMBACK.bmp";
  349. case 2:
  350. return "TBTWBACK.bmp";
  351. case 3:
  352. return "TBINBACK.bmp";
  353. case 4:
  354. return "TBNCBACK.bmp";
  355. case 5:
  356. return "TBDNBACK.bmp";
  357. case 6:
  358. return "TBSTBACK.bmp";
  359. case 7:
  360. return "TBFRBACK.bmp";
  361. case 8:
  362. return "TBELBACK.bmp";
  363. default:
  364. #ifndef __GNUC__
  365. throw new std::exception("std::string getBgName(int type): invalid type");
  366. #else
  367. throw new std::exception();
  368. #endif
  369. }
  370. }
  371. class SORTHELP
  372. {
  373. public:
  374. bool operator ()
  375. (const CBuildingRect *a ,
  376. const CBuildingRect *b)
  377. {
  378. return (*a)<(*b);
  379. }
  380. } srthlp ;
  381. CCastleInterface::CCastleInterface(const CGTownInstance * Town, int listPos)
  382. :hslotup(241,387,0,Town->garrisonHero,this),hslotdown(241,483,1,Town->visitingHero,this)
  383. {
  384. showing = false;
  385. bars = CDefHandler::giveDefEss("TPTHBAR.DEF");
  386. status = CDefHandler::giveDefEss("TPTHCHK.DEF");
  387. LOCPLINT->castleInt = this;
  388. hall = NULL;
  389. townInt = BitmapHandler::loadBitmap("TOWNSCRN.bmp");
  390. cityBg = BitmapHandler::loadBitmap(getBgName(Town->subID));
  391. pos.x = screen->w/2 - 400;
  392. pos.y = screen->h/2 - 300;
  393. hslotup.pos.x += pos.x;
  394. hslotup.pos.y += pos.y;
  395. hslotdown.pos.x += pos.x;
  396. hslotdown.pos.y += pos.y;
  397. hall = CDefHandler::giveDef("ITMTL.DEF");
  398. fort = CDefHandler::giveDef("ITMCL.DEF");
  399. hBuild = NULL;
  400. count=0;
  401. town = Town;
  402. animval = 0;
  403. //garrison
  404. garr = new CGarrisonInt(pos.x+305,pos.y+387,4,Point(0,96),townInt,Point(62,374),town,town->visitingHero);
  405. townlist = new CTownList(3,pos.x+744,pos.y+414,"IAM014.DEF","IAM015.DEF");//744,526);
  406. exit = new AdventureMapButton
  407. (CGI->generaltexth->tcommands[8],"",boost::bind(&CCastleInterface::close,this),pos.x+744,pos.y+544,"TSBTNS.DEF",SDLK_RETURN);
  408. exit->assignedKeys.insert(SDLK_ESCAPE);
  409. split = new AdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),pos.x+744,pos.y+382,"TSBTNS.DEF");
  410. split->callback += boost::bind(&CCastleInterface::splitClicked,this);
  411. garr->splitButtons.push_back(split);
  412. statusbar = new CStatusBar(pos.x+7,pos.y+555,"TSTATBAR.bmp",732);
  413. resdatabar = new CResDataBar("ZRESBAR.bmp",pos.x+3,pos.y+575,32,2,85,85);
  414. resdatabar->pos.x = pos.x+3; resdatabar->pos.y = pos.y+575;
  415. townlist->fun = boost::bind(&CCastleInterface::townChange,this);
  416. townlist->genList();
  417. townlist->selected = vstd::findPos(townlist->items,Town);
  418. townlist->from = townlist->selected - listPos;
  419. amax(townlist->from, 0);
  420. amin(townlist->from, townlist->items.size() - townlist->SIZE);
  421. graphics->blueToPlayersAdv(townInt,LOCPLINT->playerID);
  422. exit->bitmapOffset = 4;
  423. //buildings
  424. recreateBuildings();
  425. std::string defname;
  426. switch (town->subID)
  427. {
  428. case 0:
  429. defname = "HALLCSTL.DEF";
  430. musicID = musicBase::castleTown;
  431. break;
  432. case 1:
  433. defname = "HALLRAMP.DEF";
  434. musicID = musicBase::rampartTown;
  435. break;
  436. case 2:
  437. defname = "HALLTOWR.DEF";
  438. musicID = musicBase::towerTown;
  439. break;
  440. case 3:
  441. defname = "HALLINFR.DEF";
  442. musicID = musicBase::infernoTown;
  443. break;
  444. case 4:
  445. defname = "HALLNECR.DEF";
  446. musicID = musicBase::necroTown;
  447. break;
  448. case 5:
  449. defname = "HALLDUNG.DEF";
  450. musicID = musicBase::dungeonTown;
  451. break;
  452. case 6:
  453. defname = "HALLSTRN.DEF";
  454. musicID = musicBase::strongHoldTown;
  455. break;
  456. case 7:
  457. defname = "HALLFORT.DEF";
  458. musicID = musicBase::fortressTown;
  459. break;
  460. case 8:
  461. defname = "HALLELEM.DEF";
  462. musicID = musicBase::elemTown;
  463. break;
  464. default:
  465. throw new std::string("Wrong town subID");
  466. }
  467. bicons = CDefHandler::giveDefEss(defname);
  468. CGI->musich->playMusic(musicID, -1);
  469. }
  470. CCastleInterface::~CCastleInterface()
  471. {
  472. delete bars;
  473. delete status;
  474. SDL_FreeSurface(townInt);
  475. SDL_FreeSurface(cityBg);
  476. delete exit;
  477. delete split;
  478. delete hall;
  479. delete fort;
  480. delete garr;
  481. delete townlist;
  482. delete statusbar;
  483. delete resdatabar;
  484. for(size_t i=0;i<buildings.size();i++)
  485. {
  486. delete buildings[i];
  487. }
  488. delete bicons;
  489. }
  490. void CCastleInterface::close()
  491. {
  492. if(town->visitingHero)
  493. LOCPLINT->adventureInt->select(town->visitingHero);
  494. LOCPLINT->castleInt = NULL;
  495. GH.popIntTotally(this);
  496. CGI->musich->stopMusic(5000);
  497. }
  498. void CCastleInterface::splitF()
  499. {
  500. }
  501. void CCastleInterface::buildingClicked(int building)
  502. {
  503. tlog5<<"You've clicked on "<<building<<std::endl;
  504. if(building==19 || building==18)
  505. {
  506. building = town->town->hordeLvl[0] + 30;
  507. }
  508. else if(building==24 || building==25)
  509. {
  510. building = town->town->hordeLvl[1] + 30;
  511. }
  512. if(building >= 30)
  513. {
  514. showRecruitmentWindow(building);
  515. }
  516. else
  517. {
  518. switch(building)
  519. {
  520. case 0: case 1: case 2: case 3: case 4: //mage guild
  521. {
  522. const CGHeroInstance *h = NULL; //hero that "enters" mage guild
  523. if(!town->garrisonHero && !town->visitingHero) //no heroes in town
  524. h = NULL;
  525. else if(!town->garrisonHero) //only visiting hero
  526. h = town->visitingHero;
  527. else if(!town->visitingHero || hslotup.highlight) //only garrisoned hero OR both heroes present, garrisoned hero selected
  528. h = town->garrisonHero;
  529. else //both heroes present, use the visiting one
  530. h = town->visitingHero;
  531. if(h && !vstd::contains(h->artifWorn,ui16(17))) //hero doesn't have spellbok
  532. {
  533. if(LOCPLINT->cb->getResourceAmount(6) < 500) //not enough gold to buy spellbook
  534. {
  535. LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[213],std::vector<SComponent*>(), soundBase::sound_todo);
  536. }
  537. else
  538. {
  539. CFunctionList<void()> fl = boost::bind(&CCallback::buyArtifact,LOCPLINT->cb,h,0);
  540. fl += boost::bind(&CCastleInterface::enterMageGuild,this);
  541. std::vector<SComponent*> vvv(1,new SComponent(SComponent::artifact,0,0));
  542. LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[214],vvv,fl,0,true);
  543. }
  544. }
  545. else
  546. {
  547. enterMageGuild();
  548. }
  549. break;
  550. }
  551. case 5: //tavern
  552. {
  553. enterTavern();
  554. break;
  555. }
  556. case 6: //shipyard
  557. {
  558. LOCPLINT->showShipyardDialog(town);
  559. break;
  560. }
  561. case 7: case 8: case 9: //fort/citadel/castle
  562. {
  563. CFortScreen *fs = new CFortScreen(this);
  564. GH.pushInt(fs);
  565. break;
  566. }
  567. case 10: case 11: case 12: case 13: //hall
  568. enterHall();
  569. break;
  570. case 14: //marketplace
  571. {
  572. CMarketplaceWindow *cmw = new CMarketplaceWindow(0);
  573. GH.pushInt(cmw);
  574. break;
  575. }
  576. case 15: //resource silo
  577. {
  578. LOCPLINT->showInfoDialog(CGI->buildh->buildings[town->subID][15]->Description(),std::vector<SComponent*>(), soundBase::sound_todo);
  579. break;
  580. }
  581. case 16: //blacksmith
  582. {
  583. const CGHeroInstance *hero = town->visitingHero;
  584. if(!hero)
  585. {
  586. std::string pom = CGI->generaltexth->allTexts[273];
  587. boost::algorithm::replace_first(pom,"%s",CGI->buildh->buildings[town->subID][16]->Name());
  588. LOCPLINT->showInfoDialog(pom,std::vector<SComponent*>(), soundBase::sound_todo);
  589. return;
  590. }
  591. int aid = town->town->warMachine;
  592. int price = CGI->arth->artifacts[aid].price;
  593. bool possible = (LOCPLINT->cb->getResourceAmount(6) >= price);
  594. if(vstd::contains(hero->artifWorn,ui16(aid+9))) //hero already has machine
  595. possible = false;
  596. GH.pushInt(new CBlacksmithDialog(possible,CArtHandler::convertMachineID(aid,false),aid,hero->id));
  597. break;
  598. }
  599. //TODO: case 17: //special 1
  600. //TODO: case 18: //basic horde 1
  601. //TODO: case 19: //upg horde 1
  602. case 20: //ship at shipyard
  603. //Do nothing.
  604. break;
  605. //TODO: case 21: //special 2
  606. case 22: //special 3
  607. {
  608. switch(town->subID)
  609. {
  610. case 0: //brotherhood of sword
  611. enterTavern();
  612. break;
  613. default:
  614. tlog4<<"This building isn't handled...\n";
  615. break;
  616. }
  617. break;
  618. }
  619. //TODO: case 23: //special 4
  620. //TODO: case 24: //basic horde 2
  621. //TODO: case 25: //upg horde 2
  622. //TODO: case 26: //grail
  623. default:
  624. tlog4<<"This building isn't handled...\n";
  625. }
  626. }
  627. }
  628. void CCastleInterface::enterHall()
  629. {
  630. CHallInterface *h = new CHallInterface(this);
  631. GH.pushInt(h);
  632. }
  633. void CCastleInterface::showAll( SDL_Surface * to/*=NULL*/)
  634. {
  635. blitAt(cityBg,pos,to);
  636. blitAt(townInt,pos.x,pos.y+374,to);
  637. LOCPLINT->adventureInt->resdatabar.draw(to);
  638. townlist->draw(to);
  639. statusbar->show(to);
  640. resdatabar->draw(to);
  641. garr->show(to);
  642. int pom;
  643. //draw fort icon
  644. if(town->builtBuildings.find(9)!=town->builtBuildings.end())
  645. pom = 2;
  646. else if(town->builtBuildings.find(8)!=town->builtBuildings.end())
  647. pom = 1;
  648. else if(town->builtBuildings.find(7)!=town->builtBuildings.end())
  649. pom = 0;
  650. else pom = 3;
  651. blitAt(fort->ourImages[pom].bitmap,pos.x+122,pos.y+413,to);
  652. //draw ((village/town/city) hall)/capitol icon
  653. if(town->builtBuildings.find(13)!=town->builtBuildings.end())
  654. pom = 3;
  655. else if(town->builtBuildings.find(12)!=town->builtBuildings.end())
  656. pom = 2;
  657. else if(town->builtBuildings.find(11)!=town->builtBuildings.end())
  658. pom = 1;
  659. else pom = 0;
  660. blitAt(hall->ourImages[pom].bitmap,pos.x+80,pos.y+413,to);
  661. //draw creatures icons and their growths
  662. for(int i=0;i<CREATURES_PER_TOWN;i++)
  663. {
  664. int cid = -1;
  665. if (town->builtBuildings.find(30+i)!=town->builtBuildings.end())
  666. {
  667. if (town->builtBuildings.find(30+CREATURES_PER_TOWN+i)!=town->builtBuildings.end())
  668. cid = town->town->upgradedCreatures[i];
  669. else
  670. cid = town->town->basicCreatures[i];
  671. }
  672. if (cid>=0)
  673. {
  674. int pomx, pomy;
  675. pomx = 22 + (55*((i>3)?(i-4):i));
  676. pomy = (i>3)?(507):(459);
  677. blitAt(graphics->smallImgs[cid],pos.x+pomx,pos.y+pomy,to);
  678. std::ostringstream oss;
  679. oss << '+' << town->creatureGrowth(i);
  680. CSDL_Ext::printAtMiddle(oss.str(),pos.x+pomx+16,pos.y+pomy+37,GEOR13,zwykly,to);
  681. }
  682. }
  683. //print name and income
  684. CSDL_Ext::printAt(town->name,pos.x+85,pos.y+389,GEOR13,zwykly,to);
  685. char temp[10];
  686. SDL_itoa(town->dailyIncome(),temp,10);
  687. CSDL_Ext::printAtMiddle(temp,pos.x+195,pos.y+442,GEOR13,zwykly,to);
  688. //blit town icon
  689. pom = town->subID*2;
  690. if (!town->hasFort())
  691. pom += F_NUMBER*2;
  692. if(town->builded >= MAX_BUILDING_PER_TURN)
  693. pom++;
  694. blitAt(graphics->bigTownPic->ourImages[pom].bitmap,pos.x+15,pos.y+387,to);
  695. hslotup.show(to);
  696. hslotdown.show(to);
  697. show(to);
  698. if(screen->w != 800 || screen->h !=600)
  699. CMessage::drawBorder(LOCPLINT->playerID,to,828,628,pos.x-14,pos.y-15);
  700. exit->show(to);
  701. split->show(to);
  702. }
  703. void CCastleInterface::townChange()
  704. {
  705. const CGTownInstance * nt = townlist->items[townlist->selected];
  706. int tpos = townlist->selected - townlist->from;
  707. GH.popIntTotally(this);
  708. GH.pushInt(new CCastleInterface(nt, tpos));
  709. }
  710. void CCastleInterface::show(SDL_Surface * to)
  711. {
  712. count++;
  713. if(count==8)
  714. {
  715. count=0;
  716. animval++;
  717. }
  718. blitAt(cityBg,pos,to);
  719. //blit buildings
  720. for(size_t i=0;i<buildings.size();i++)
  721. {
  722. int frame = ((animval)%(buildings[i]->max - buildings[i]->offset)) + buildings[i]->offset;
  723. if(frame)
  724. {
  725. blitAt(buildings[i]->def->ourImages[0].bitmap,buildings[i]->pos.x,buildings[i]->pos.y,to);
  726. blitAt(buildings[i]->def->ourImages[frame].bitmap,buildings[i]->pos.x,buildings[i]->pos.y,to);
  727. }
  728. else
  729. blitAt(buildings[i]->def->ourImages[frame].bitmap,buildings[i]->pos.x,buildings[i]->pos.y,to);
  730. if(hBuild==buildings[i] && hBuild->border) //if this this higlighted structure and has border we'll blit it
  731. blitAt(hBuild->border,hBuild->pos,to);
  732. }
  733. }
  734. void CCastleInterface::activate()
  735. {
  736. showing = true;
  737. townlist->activate();
  738. garr->activate();
  739. LOCPLINT->statusbar = statusbar;
  740. exit->activate();
  741. split->activate();
  742. for(size_t i=0;i<buildings.size();i++) //XXX pls use iterators or at() but not []
  743. {
  744. buildings[i]->activate();
  745. }
  746. hslotdown.activate();
  747. hslotup.activate();
  748. activateKeys();
  749. }
  750. void CCastleInterface::deactivate()
  751. {
  752. showing = false;
  753. townlist->deactivate();
  754. garr->deactivate();
  755. exit->deactivate();
  756. split->deactivate();
  757. for(size_t i=0;i<buildings.size();i++) //XXX iterators
  758. {
  759. buildings[i]->deactivate();
  760. }
  761. hslotdown.deactivate();
  762. hslotup.deactivate();
  763. deactivateKeys();
  764. }
  765. void CCastleInterface::addBuilding(int bid)
  766. {
  767. //TODO: lepiej by bylo tylko dodawac co trzeba pamietajac o grupach
  768. deactivate();
  769. recreateBuildings();
  770. activate();
  771. }
  772. void CCastleInterface::removeBuilding(int bid)
  773. {
  774. //TODO: lepiej by bylo tylko usuwac co trzeba pamietajac o grupach
  775. recreateBuildings();
  776. }
  777. void CCastleInterface::recreateBuildings()
  778. {
  779. for(size_t i=0;i<buildings.size();i++)
  780. {
  781. if(showing)
  782. buildings[i]->deactivate();
  783. delete buildings[i];
  784. }
  785. buildings.clear();
  786. hBuild = NULL;
  787. std::set< std::pair<int,int> > s; //group - id
  788. for (std::set<si32>::const_iterator i=town->builtBuildings.begin();i!=town->builtBuildings.end();i++)
  789. {
  790. if(CGI->townh->structures.find(town->subID) != CGI->townh->structures.end()) //we have info about structures in this town
  791. {
  792. if(CGI->townh->structures[town->subID].find(*i)!=CGI->townh->structures[town->subID].end()) //we have info about that structure
  793. {
  794. Structure * st = CGI->townh->structures[town->subID][*i];
  795. if(st->group<0) //no group - just add it
  796. {
  797. buildings.push_back(new CBuildingRect(st));
  798. }
  799. else
  800. {
  801. std::set< std::pair<int,int> >::iterator obecny=s.end();
  802. for(std::set< std::pair<int,int> >::iterator seti = s.begin(); seti!=s.end(); seti++) //check if we have already building from same group
  803. {
  804. if(seti->first == st->group)
  805. {
  806. obecny = seti;
  807. break;
  808. }
  809. }
  810. if(obecny != s.end())
  811. {
  812. if((*(CGI->townh->structures[town->subID][obecny->second])) < (*(CGI->townh->structures[town->subID][st->ID]))) //we have to replace old building with current one
  813. {
  814. for(size_t itpb = 0; itpb<buildings.size(); itpb++)
  815. {
  816. if(buildings[itpb]->str->ID == obecny->second)
  817. {
  818. delete buildings[itpb];
  819. buildings.erase(buildings.begin() + itpb);
  820. #ifndef __GNUC__
  821. obecny->second = st->ID; //XXX look closer!
  822. #else
  823. *(const_cast<int*>(&(obecny->second))) = st->ID;
  824. #endif
  825. buildings.push_back(new CBuildingRect(st));
  826. }
  827. }
  828. }
  829. }
  830. else
  831. {
  832. buildings.push_back(new CBuildingRect(st));
  833. s.insert(std::pair<int,int>(st->group,st->ID));
  834. }
  835. }
  836. }
  837. else continue;
  838. }
  839. else
  840. break;
  841. }
  842. //ship in shipyard
  843. if(vstd::contains(town->builtBuildings,6))
  844. {
  845. std::vector <const CGObjectInstance *> vobjs = LOCPLINT->cb->getVisitableObjs(town->bestLocation());
  846. if(vobjs.size() && vobjs.front()->ID == 8) //there is visitable obj at shipyard output tile and it's a boat
  847. {
  848. Structure * st = CGI->townh->structures[town->subID][20];
  849. buildings.push_back(new CBuildingRect(st));
  850. s.insert(std::pair<int,int>(st->group,st->ID));
  851. }
  852. }
  853. std::sort(buildings.begin(),buildings.end(),srthlp);
  854. //code for Mana Vortex (there are two sets of animation frames - one without mage guild and one with
  855. if((town->subID == 5) && (town->builtBuildings.find(21)!=town->builtBuildings.end()))
  856. {
  857. CBuildingRect *vortex = NULL;
  858. for(size_t i=0;i<buildings.size();i++)
  859. {
  860. if(buildings[i]->str->ID==21)
  861. {
  862. vortex=buildings[i];
  863. break;
  864. }
  865. }
  866. if(town->builtBuildings.find(4)!=town->builtBuildings.end()) //there is mage Guild level 5
  867. {
  868. vortex->offset = 10;
  869. vortex->max = vortex->def->ourImages.size();
  870. }
  871. else
  872. {
  873. vortex->offset = 0;
  874. vortex->max = 10;
  875. }
  876. }
  877. //code for the shipyard in the Castle
  878. else if((town->subID == 0) && (town->builtBuildings.find(6)!=town->builtBuildings.end()))
  879. {
  880. CBuildingRect *shipyard = NULL;
  881. for(size_t i=0;i<buildings.size();i++)
  882. {
  883. if(buildings[i]->str->ID==6)
  884. {
  885. shipyard=buildings[i];
  886. break;
  887. }
  888. }
  889. if(town->builtBuildings.find(8)!=town->builtBuildings.end()) //there is citadel
  890. {
  891. shipyard->offset = 1;
  892. shipyard->max = shipyard->def->ourImages.size();
  893. }
  894. else
  895. {
  896. shipyard->offset = 0;
  897. shipyard->max = 1;
  898. }
  899. }
  900. if(showing)
  901. for(size_t i=0;i<buildings.size();i++)
  902. buildings[i]->activate();
  903. }
  904. CRecruitmentWindow * CCastleInterface::showRecruitmentWindow( int building )
  905. {
  906. if(building>36) //upg dwelling
  907. building-=7;
  908. int level = building-30;
  909. assert(level >= 0 && level <= 6);
  910. //std::vector<std::pair<int,int > > crs;
  911. //int amount = town->creatures[level].first;
  912. //const std::vector<ui32> &cres = town->creatures[level].second;
  913. //for(size_t i = 0; i < cres.size(); i++)
  914. // crs.push_back(std::make_pair((int)cres[i],amount));
  915. //CRecruitmentWindow *rw = new CRecruitmentWindow(crs,boost::bind(&CCallback::recruitCreatures,LOCPLINT->cb,town,_1,_2));
  916. CRecruitmentWindow *rw = new CRecruitmentWindow(town, level, town, boost::bind(&CCallback::recruitCreatures,LOCPLINT->cb,town,_1,_2));
  917. GH.pushInt(rw);
  918. return rw;
  919. }
  920. void CCastleInterface::enterMageGuild()
  921. {
  922. GH.pushInt(new CMageGuildScreen(this));
  923. }
  924. void CCastleInterface::enterTavern()
  925. {
  926. std::vector<const CGHeroInstance*> h = LOCPLINT->cb->getAvailableHeroes(town);
  927. CTavernWindow *tv = new CTavernWindow(h[0],h[1],"GOSSIP TEST");
  928. GH.pushInt(tv);
  929. }
  930. void CCastleInterface::keyPressed( const SDL_KeyboardEvent & key )
  931. {
  932. if(key.state != SDL_PRESSED) return;
  933. switch(key.keysym.sym)
  934. {
  935. case SDLK_UP:
  936. if(townlist->selected)
  937. {
  938. townlist->selected--;
  939. townlist->from--;
  940. townChange();
  941. }
  942. break;
  943. case SDLK_DOWN:
  944. if(townlist->selected < townlist->items.size() - 1)
  945. {
  946. townlist->selected++;
  947. townlist->from++;
  948. townChange();
  949. }
  950. break;
  951. case SDLK_SPACE:
  952. if(town->visitingHero && town->garrisonHero)
  953. {
  954. LOCPLINT->cb->swapGarrisonHero(town);
  955. }
  956. break;
  957. }
  958. }
  959. void CCastleInterface::splitClicked()
  960. {
  961. if(town->visitingHero && town->garrisonHero && (hslotdown.highlight || hslotup.highlight))
  962. {
  963. LOCPLINT->heroExchangeStarted(town->visitingHero->id, town->garrisonHero->id);
  964. }
  965. }
  966. void CHallInterface::CBuildingBox::hover(bool on)
  967. {
  968. //Hoverable::hover(on);
  969. if(on)
  970. {
  971. std::string toPrint;
  972. if(state==8)
  973. toPrint = CGI->generaltexth->hcommands[5];
  974. else
  975. toPrint = CGI->generaltexth->hcommands[state];
  976. std::vector<std::string> name;
  977. name.push_back(CGI->buildh->buildings[LOCPLINT->castleInt->town->subID][BID]->Name());
  978. LOCPLINT->statusbar->print(CSDL_Ext::processStr(toPrint,name));
  979. }
  980. else
  981. LOCPLINT->statusbar->clear();
  982. }
  983. void CHallInterface::CBuildingBox::clickLeft(tribool down, bool previousState)
  984. {
  985. if(previousState && (!down))
  986. {
  987. GH.pushInt(new CHallInterface::CBuildWindow(LOCPLINT->castleInt->town->subID,BID,state,0));
  988. }
  989. //ClickableL::clickLeft(down);
  990. }
  991. void CHallInterface::CBuildingBox::clickRight(tribool down, bool previousState)
  992. {
  993. if(down)
  994. {
  995. GH.pushInt(new CHallInterface::CBuildWindow(LOCPLINT->castleInt->town->subID,BID,state,1));
  996. }
  997. //ClickableR::clickRight(down);
  998. }
  999. void CHallInterface::CBuildingBox::show(SDL_Surface * to)
  1000. {
  1001. CCastleInterface *ci = LOCPLINT->castleInt;
  1002. blitAt(ci->bicons->ourImages[BID].bitmap,pos.x,pos.y,to);
  1003. int pom, pom2=-1;
  1004. switch (state)
  1005. {
  1006. case 4:
  1007. pom = 0;
  1008. pom2 = 0;
  1009. break;
  1010. case 7:
  1011. pom = 1;
  1012. break;
  1013. case 6:
  1014. pom2 = 2;
  1015. pom = 2;
  1016. break;
  1017. case 5: case 8:
  1018. pom2 = 1;
  1019. pom = 2;
  1020. break;
  1021. case 0: case 2: case 1: default:
  1022. pom = 3;
  1023. break;
  1024. }
  1025. blitAt(ci->bars->ourImages[pom].bitmap,pos.x-1,pos.y+71,to);
  1026. if(pom2>=0)
  1027. blitAt(ci->status->ourImages[pom2].bitmap,pos.x+135, pos.y+54,to);
  1028. CSDL_Ext::printAtMiddle(CGI->buildh->buildings[ci->town->subID][BID]->Name(),pos.x-1+ci->bars->ourImages[0].bitmap->w/2,pos.y+71+ci->bars->ourImages[0].bitmap->h/2, GEOR13,zwykly,to);
  1029. }
  1030. void CHallInterface::CBuildingBox::activate()
  1031. {
  1032. activateHover();
  1033. activateLClick();
  1034. activateRClick();
  1035. }
  1036. void CHallInterface::CBuildingBox::deactivate()
  1037. {
  1038. deactivateHover();
  1039. deactivateLClick();
  1040. deactivateRClick();
  1041. }
  1042. CHallInterface::CBuildingBox::~CBuildingBox()
  1043. {
  1044. }
  1045. CHallInterface::CBuildingBox::CBuildingBox(int id)
  1046. :BID(id)
  1047. {
  1048. pos.w = 150;
  1049. pos.h = 70;
  1050. }
  1051. CHallInterface::CBuildingBox::CBuildingBox(int id, int x, int y)
  1052. :BID(id)
  1053. {
  1054. pos.x = x;
  1055. pos.y = y;
  1056. pos.w = 150;
  1057. pos.h = 70;
  1058. }
  1059. CHallInterface::CHallInterface(CCastleInterface * owner)
  1060. {
  1061. resdatabar = new CMinorResDataBar;
  1062. pos = owner->pos;
  1063. resdatabar->pos.x += pos.x;
  1064. resdatabar->pos.y += pos.y;
  1065. bg = BitmapHandler::loadBitmap(CGI->buildh->hall[owner->town->subID].first);
  1066. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  1067. exit = new AdventureMapButton
  1068. (CGI->generaltexth->tcommands[8],"",boost::bind(&CHallInterface::close,this),pos.x+748,pos.y+556,"TPMAGE1.DEF",SDLK_RETURN);
  1069. exit->assignedKeys.insert(SDLK_ESCAPE);
  1070. //preparing boxes with buildings//
  1071. boxes.resize(5);
  1072. for(size_t i=0;i<5;i++) //for each row
  1073. {
  1074. std::vector< std::vector< std::vector<int> > > &boxList = CGI->buildh->hall[owner->town->subID].second;
  1075. for(size_t j=0; j<boxList[i].size();j++) //for each box
  1076. {
  1077. size_t k=0;
  1078. for(;k<boxList[i][j].size();k++)//we are looking for the first not build structure
  1079. {
  1080. int bid = boxList[i][j][k];
  1081. if(!vstd::contains(owner->town->builtBuildings,bid))
  1082. {
  1083. int x = 34 + 194*j,
  1084. y = 37 + 104*i,
  1085. ID = bid;
  1086. if(boxList[i].size() == 2) //only two boxes in this row
  1087. x+=194;
  1088. else if(boxList[i].size() == 3) //only three boxes in this row
  1089. x+=97;
  1090. boxes[i].push_back(new CBuildingBox(bid,pos.x+x,pos.y+y));
  1091. //if this is horde dwelling for upgraded creatures and we already have one for basic creatures
  1092. if((bid == 25 && vstd::contains(owner->town->builtBuildings,24))
  1093. || (bid == 19 && vstd::contains(owner->town->builtBuildings,18))
  1094. )
  1095. {
  1096. boxes[i].back()->state = 4; //already built
  1097. }
  1098. else
  1099. {
  1100. boxes[i].back()->state = LOCPLINT->cb->canBuildStructure(owner->town,ID);
  1101. }
  1102. break;
  1103. }
  1104. }
  1105. if(k == boxList[i][j].size()) //all buildings built - let's take the last one
  1106. {
  1107. int x = 34 + 194*j,
  1108. y = 37 + 104*i;
  1109. if(boxList[i].size() == 2)
  1110. x+=194;
  1111. else if(boxList[i].size() == 3)
  1112. x+=97;
  1113. boxes[i].push_back(new CBuildingBox(boxList[i][j][k-1],pos.x+x,pos.y+y));
  1114. boxes[i][boxes[i].size()-1]->state = 4; //already exists
  1115. }
  1116. }
  1117. }
  1118. }
  1119. CHallInterface::~CHallInterface()
  1120. {
  1121. SDL_FreeSurface(bg);
  1122. for(size_t i=0;i<boxes.size();i++)
  1123. for(size_t j=0;j<boxes[i].size();j++)
  1124. delete boxes[i][j]; //TODO whats wrong with smartpointers?
  1125. delete exit;
  1126. delete resdatabar;
  1127. }
  1128. void CHallInterface::close()
  1129. {
  1130. GH.popIntTotally(this);
  1131. }
  1132. void CHallInterface::show(SDL_Surface * to)
  1133. {
  1134. blitAt(bg,pos,to);
  1135. LOCPLINT->castleInt->statusbar->show(to);
  1136. resdatabar->show(to);
  1137. exit->show(to);
  1138. for(int i=0; i<5; i++)
  1139. {
  1140. for(size_t j=0;j<boxes[i].size(); ++j)
  1141. boxes[i][j]->show(to);
  1142. }
  1143. }
  1144. void CHallInterface::activate()
  1145. {
  1146. for(int i=0;i<5;i++)
  1147. {
  1148. for(size_t j=0; j < boxes[i].size(); ++j)
  1149. {
  1150. boxes[i][j]->activate();
  1151. }
  1152. }
  1153. exit->activate();
  1154. }
  1155. void CHallInterface::deactivate()
  1156. {
  1157. for(int i=0;i<5;i++)
  1158. {
  1159. for(size_t j=0;j<boxes[i].size();++j)
  1160. {
  1161. boxes[i][j]->deactivate();
  1162. }
  1163. }
  1164. exit->deactivate();
  1165. }
  1166. void CHallInterface::CBuildWindow::activate()
  1167. {
  1168. activateRClick();
  1169. if(mode)
  1170. return;
  1171. if(state==7)
  1172. buy->activate();
  1173. cancel->activate();
  1174. }
  1175. void CHallInterface::CBuildWindow::deactivate()
  1176. {
  1177. deactivateRClick();
  1178. if(mode)
  1179. return;
  1180. if(state==7)
  1181. buy->deactivate();
  1182. cancel->deactivate();
  1183. }
  1184. void CHallInterface::CBuildWindow::Buy()
  1185. {
  1186. int building = bid;
  1187. GH.popInts(2); //we - build window and hall screen
  1188. LOCPLINT->cb->buildBuilding(LOCPLINT->castleInt->town,building);
  1189. }
  1190. void CHallInterface::CBuildWindow::close()
  1191. {
  1192. GH.popIntTotally(this);
  1193. }
  1194. void CHallInterface::CBuildWindow::clickRight(tribool down, bool previousState)
  1195. {
  1196. if((!down || indeterminate(down)) && mode)
  1197. close();
  1198. }
  1199. void CHallInterface::CBuildWindow::show(SDL_Surface * to)
  1200. {
  1201. SDL_Rect pom = genRect(bitmap->h-1,bitmap->w-1,pos.x,pos.y);
  1202. SDL_Rect poms = pom; poms.x=0;poms.y=0;
  1203. SDL_BlitSurface(bitmap,&poms,to,&pom);
  1204. if(!mode)
  1205. {
  1206. buy->show(to);
  1207. cancel->show(to);
  1208. }
  1209. }
  1210. std::string CHallInterface::CBuildWindow::getTextForState(int state)
  1211. {
  1212. std::string ret;
  1213. if(state<7)
  1214. ret = CGI->generaltexth->hcommands[state];
  1215. switch (state)
  1216. {
  1217. case 4: case 5: case 6:
  1218. ret.replace(ret.find_first_of("%s"),2,CGI->buildh->buildings[tid][bid]->Name());
  1219. break;
  1220. case 7:
  1221. return CGI->generaltexth->allTexts[219]; //all prereq. are met
  1222. case 8:
  1223. {
  1224. ret = CGI->generaltexth->allTexts[52];
  1225. std::set<int> used;
  1226. used.insert(bid);
  1227. std::set<int> reqs;
  1228. for(std::set<int>::iterator i=CGI->townh->requirements[tid][bid].begin();
  1229. i!=CGI->townh->requirements[tid][bid].end();
  1230. i++
  1231. )
  1232. {
  1233. if (LOCPLINT->castleInt->town->builtBuildings.find(*i) == LOCPLINT->castleInt->town->builtBuildings.end())
  1234. reqs.insert(*i);
  1235. }
  1236. while(true)
  1237. {
  1238. size_t czystych=0;
  1239. for(std::set<int>::iterator i=reqs.begin();i!=reqs.end();i++)
  1240. {
  1241. if(used.find(*i)==used.end()) //we haven't added requirements for this building
  1242. {
  1243. used.insert(*i);
  1244. for(
  1245. std::set<int>::iterator j=CGI->townh->requirements[tid][*i].begin();
  1246. j!=CGI->townh->requirements[tid][*i].end();
  1247. j++
  1248. )
  1249. {
  1250. if(LOCPLINT->castleInt->town->builtBuildings.find(*j) == //this building is not built
  1251. LOCPLINT->castleInt->town->builtBuildings.end())
  1252. reqs.insert(*j);
  1253. }
  1254. }
  1255. else
  1256. {
  1257. czystych++;
  1258. }
  1259. }
  1260. if(czystych==reqs.size())
  1261. break;
  1262. }
  1263. bool first=true;
  1264. for(std::set<int>::iterator i=reqs.begin();i!=reqs.end();i++)
  1265. {
  1266. ret+=(((first)?(" "):(", ")) + CGI->buildh->buildings[tid][*i]->Name());
  1267. first = false;
  1268. }
  1269. }
  1270. }
  1271. return ret;
  1272. }
  1273. CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mode)
  1274. :tid(Tid), bid(Bid), state(State), mode(Mode)
  1275. {
  1276. SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPUBUILD.bmp");
  1277. graphics->blueToPlayersAdv(hhlp,LOCPLINT->playerID);
  1278. bitmap = SDL_ConvertSurface(hhlp,screen->format,0); //na 8bitowej mapie by sie psulo
  1279. SDL_SetColorKey(hhlp,SDL_SRCCOLORKEY,SDL_MapRGB(hhlp->format,0,255,255));
  1280. SDL_FreeSurface(hhlp);
  1281. pos.x = screen->w/2 - bitmap->w/2;
  1282. pos.y = screen->h/2 - bitmap->h/2;
  1283. blitAt(LOCPLINT->castleInt->bicons->ourImages[bid].bitmap,125,50,bitmap);
  1284. std::vector<std::string> pom; pom.push_back(CGI->buildh->buildings[tid][bid]->Name());
  1285. CSDL_Ext::printAtMiddleWB(CGI->buildh->buildings[tid][bid]->Description(),197,168,GEOR16,40,zwykly,bitmap);
  1286. CSDL_Ext::printAtMiddleWB(getTextForState(state),197,248,GEOR13,50,zwykly,bitmap);
  1287. CSDL_Ext::printAtMiddle(CSDL_Ext::processStr(CGI->generaltexth->hcommands[7],pom),197,30,GEOR16,tytulowy,bitmap);
  1288. int resamount=0;
  1289. for(int i=0;i<7;i++)
  1290. {
  1291. if(CGI->buildh->buildings[tid][bid]->resources[i])
  1292. {
  1293. resamount++;
  1294. }
  1295. }
  1296. int ah = (resamount>4) ? 304 : 341;
  1297. int cn=-1, it=0;
  1298. int row1w = std::min(resamount,4) * 32 + (std::min(resamount,4)-1) * 45,
  1299. row2w = (resamount-4) * 32 + (resamount-5) * 45;
  1300. char buf[15];
  1301. while(++cn<7)
  1302. {
  1303. if(!CGI->buildh->buildings[tid][bid]->resources[cn])
  1304. continue;
  1305. SDL_itoa(CGI->buildh->buildings[tid][bid]->resources[cn],buf,10);
  1306. if(it<4)
  1307. {
  1308. CSDL_Ext::printAtMiddle(buf,(bitmap->w/2-row1w/2)+77*it+16,ah+42,GEOR16,zwykly,bitmap);
  1309. blitAt(graphics->resources32->ourImages[cn].bitmap,(bitmap->w/2-row1w/2)+77*it++,ah,bitmap);
  1310. }
  1311. else
  1312. {
  1313. CSDL_Ext::printAtMiddle(buf,(bitmap->w/2-row2w/2)+77*it+16-308,ah+42,GEOR16,zwykly,bitmap);
  1314. blitAt(graphics->resources32->ourImages[cn].bitmap,(bitmap->w/2-row2w/2)+77*it++ - 308,ah,bitmap);
  1315. }
  1316. if(it==4)
  1317. ah+=75;
  1318. }
  1319. if(!mode)
  1320. {
  1321. buy = new AdventureMapButton
  1322. ("","",boost::bind(&CBuildWindow::Buy,this),pos.x+45,pos.y+446,"IBUY30.DEF",SDLK_RETURN);
  1323. cancel = new AdventureMapButton
  1324. ("","",boost::bind(&CBuildWindow::close,this),pos.x+290,pos.y+445,"ICANCEL.DEF",SDLK_ESCAPE);
  1325. if(state!=7)
  1326. buy->state=2;
  1327. }
  1328. }
  1329. CHallInterface::CBuildWindow::~CBuildWindow()
  1330. {
  1331. SDL_FreeSurface(bitmap);
  1332. if(!mode)
  1333. {
  1334. delete buy;
  1335. delete cancel;
  1336. }
  1337. }
  1338. CFortScreen::~CFortScreen()
  1339. {
  1340. for(size_t i=0;i<crePics.size();i++)
  1341. delete crePics[i];
  1342. for (size_t i=0;i<recAreas.size();i++)
  1343. delete recAreas[i];
  1344. SDL_FreeSurface(bg);
  1345. delete exit;
  1346. delete resdatabar;
  1347. }
  1348. void CFortScreen::show( SDL_Surface * to)
  1349. {
  1350. blitAt(bg,pos,to);
  1351. static unsigned char anim = 1;
  1352. for (int i=0; i<CREATURES_PER_TOWN; i++)
  1353. {
  1354. crePics[i]->blitPic(to,pos.x+positions[i].x+159,pos.y+positions[i].y+4,!(anim%4));
  1355. }
  1356. anim++;
  1357. exit->show(to);
  1358. resdatabar->show(to);
  1359. LOCPLINT->statusbar->show(to);
  1360. }
  1361. void CFortScreen::activate()
  1362. {
  1363. LOCPLINT->statusbar = LOCPLINT->castleInt->statusbar;
  1364. exit->activate();
  1365. for (size_t i=0;i<recAreas.size(); ++i)
  1366. {
  1367. recAreas[i]->activate();
  1368. }
  1369. }
  1370. void CFortScreen::deactivate()
  1371. {
  1372. exit->deactivate();
  1373. for (size_t i=0;i<recAreas.size();i++)
  1374. {
  1375. recAreas[i]->deactivate();
  1376. }
  1377. }
  1378. void CFortScreen::close()
  1379. {
  1380. GH.popIntTotally(this);
  1381. }
  1382. CFortScreen::CFortScreen( CCastleInterface * owner )
  1383. {
  1384. resdatabar = new CMinorResDataBar;
  1385. pos = owner->pos;
  1386. bg = NULL;
  1387. exit = new AdventureMapButton(CGI->generaltexth->tcommands[8],"",boost::bind(&CFortScreen::close,this),pos.x+748,pos.y+556,"TPMAGE1.DEF",SDLK_RETURN);
  1388. positions += genRect(126,386,10,22),genRect(126,386,404,22),
  1389. genRect(126,386,10,155),genRect(126,386,404,155),
  1390. genRect(126,386,10,288),genRect(126,386,404,288),
  1391. genRect(126,386,206,421);
  1392. draw(owner,true);
  1393. resdatabar->pos += pos;
  1394. }
  1395. void CFortScreen::draw( CCastleInterface * owner, bool first)
  1396. {
  1397. if(bg)
  1398. SDL_FreeSurface(bg);
  1399. char buf[20];
  1400. memset(buf,0,20);
  1401. SDL_Surface *bg2 = BitmapHandler::loadBitmap("TPCASTL7.bmp"),
  1402. *icons = BitmapHandler::loadBitmap("ZPCAINFO.bmp");
  1403. SDL_SetColorKey(icons,SDL_SRCCOLORKEY,SDL_MapRGB(icons->format,0,255,255));
  1404. graphics->blueToPlayersAdv(bg2,LOCPLINT->playerID);
  1405. bg = SDL_ConvertSurface(bg2,screen->format,0);
  1406. SDL_FreeSurface(bg2);
  1407. printAtMiddle(CGI->buildh->buildings[owner->town->subID][owner->town->fortLevel()+6]->Name(),400,13,GEORXX,zwykly,bg);
  1408. for(int i=0;i<CREATURES_PER_TOWN; i++)
  1409. {
  1410. bool upgraded = owner->town->creatureDwelling(i,true);
  1411. bool present = owner->town->creatureDwelling(i,false);
  1412. CCreature *c = &CGI->creh->creatures[upgraded ? owner->town->town->upgradedCreatures[i] : owner->town->town->basicCreatures[i]];
  1413. printAtMiddle(c->namePl,positions[i].x+79,positions[i].y+10,GEOR13,zwykly,bg); //cr. name
  1414. blitAt(owner->bicons->ourImages[30+i+upgraded*7].bitmap,positions[i].x+4,positions[i].y+21,bg); //dwelling pic
  1415. printAtMiddle(CGI->buildh->buildings[owner->town->subID][30+i+upgraded*7]->Name(),positions[i].x+79,positions[i].y+100,GEOR13,zwykly,bg); //dwelling name
  1416. if(present) //if creature is present print avail able quantity
  1417. {
  1418. SDL_itoa(owner->town->creatures[i].first,buf,10);
  1419. printAtMiddle(CGI->generaltexth->allTexts[217] + buf,positions[i].x+79,positions[i].y+118,GEOR13,zwykly,bg);
  1420. }
  1421. blitAt(icons,positions[i].x+261,positions[i].y+3,bg);
  1422. //attack
  1423. printAt(CGI->generaltexth->allTexts[190],positions[i].x+288,positions[i].y+5,GEOR13,zwykly,bg);
  1424. SDL_itoa(c->attack,buf,10);
  1425. printToWR(buf,positions[i].x+381,positions[i].y+18,GEOR13,zwykly,bg);
  1426. //defense
  1427. printAt(CGI->generaltexth->allTexts[191],positions[i].x+288,positions[i].y+25,GEOR13,zwykly,bg);
  1428. SDL_itoa(c->defence,buf,10);
  1429. printToWR(buf,positions[i].x+381,positions[i].y+38,GEOR13,zwykly,bg);
  1430. //damage
  1431. printAt(CGI->generaltexth->allTexts[199],positions[i].x+288,positions[i].y+46,GEOR13,zwykly,bg);
  1432. SDL_itoa(c->damageMin,buf,10);
  1433. int hlp;
  1434. if(c->damageMin > 0)
  1435. hlp = log10f(c->damageMin)+2;
  1436. else
  1437. hlp = 2;
  1438. buf[hlp-1]=' '; buf[hlp]='-'; buf[hlp+1]=' ';
  1439. SDL_itoa(c->damageMax,buf+hlp+2,10);
  1440. printToWR(buf,positions[i].x+381,positions[i].y+59,GEOR13,zwykly,bg);
  1441. //health
  1442. printAt(CGI->generaltexth->zelp[439].first,positions[i].x+288,positions[i].y+66,GEOR13,zwykly,bg);
  1443. SDL_itoa(c->hitPoints,buf,10);
  1444. printToWR(buf,positions[i].x+381,positions[i].y+79,GEOR13,zwykly,bg);
  1445. //speed
  1446. printAt(CGI->generaltexth->zelp[441].first,positions[i].x+288,positions[i].y+87,GEOR13,zwykly,bg);
  1447. SDL_itoa(c->speed,buf,10);
  1448. printToWR(buf,positions[i].x+381,positions[i].y+100,GEOR13,zwykly,bg);
  1449. if(present)//growth
  1450. {
  1451. printAt(CGI->generaltexth->allTexts[194],positions[i].x+288,positions[i].y+107,GEOR13,zwykly,bg);
  1452. SDL_itoa(owner->town->creatureGrowth(i),buf,10);
  1453. printToWR(buf,positions[i].x+381,positions[i].y+120,GEOR13,zwykly,bg);
  1454. }
  1455. if(first)
  1456. {
  1457. crePics.push_back(new CCreaturePic(c,false));
  1458. if(present)
  1459. {
  1460. recAreas.push_back(new RecArea(30+i+upgraded*7));
  1461. recAreas.back()->pos = positions[i] + pos;
  1462. }
  1463. }
  1464. }
  1465. SDL_FreeSurface(icons);
  1466. }
  1467. void CFortScreen::RecArea::clickLeft(tribool down, bool previousState)
  1468. {
  1469. if(!down && previousState)
  1470. {
  1471. LOCPLINT->castleInt->showRecruitmentWindow(bid);
  1472. }
  1473. //ClickableL::clickLeft(down);
  1474. }
  1475. void CFortScreen::RecArea::activate()
  1476. {
  1477. activateLClick();
  1478. activateRClick();
  1479. }
  1480. void CFortScreen::RecArea::deactivate()
  1481. {
  1482. deactivateLClick();
  1483. deactivateRClick();
  1484. }
  1485. void CFortScreen::RecArea::clickRight(tribool down, bool previousState)
  1486. {
  1487. clickLeft(down, false); //r-click does same as l-click - opens recr. window
  1488. }
  1489. CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner)
  1490. {
  1491. resdatabar = new CMinorResDataBar;
  1492. pos = owner->pos;
  1493. resdatabar->pos.x += pos.x;
  1494. resdatabar->pos.y += pos.y;
  1495. bg = BitmapHandler::loadBitmap("TPMAGE.bmp");
  1496. exit = new AdventureMapButton(CGI->generaltexth->tcommands[8],"",boost::bind(&CMageGuildScreen::close,this),pos.x+748,pos.y+556,"TPMAGE1.DEF",SDLK_RETURN);
  1497. exit->assignedKeys.insert(SDLK_ESCAPE);
  1498. scrolls2 = CDefHandler::giveDefEss("TPMAGES.DEF");
  1499. SDL_Surface *view = BitmapHandler::loadBitmap(graphics->guildBgs[owner->town->subID]);
  1500. SDL_SetColorKey(view,SDL_SRCCOLORKEY,SDL_MapRGB(view->format,0,255,255));
  1501. positions.resize(5);
  1502. positions[0] += genRect(61,83,222,445), genRect(61,83,312,445), genRect(61,83,402,445), genRect(61,83,520,445), genRect(61,83,610,445), genRect(61,83,700,445);
  1503. positions[1] += genRect(61,83,48,53), genRect(61,83,48,147), genRect(61,83,48,241), genRect(61,83,48,335), genRect(61,83,48,429);
  1504. positions[2] += genRect(61,83,570,82), genRect(61,83,672,82), genRect(61,83,570,157), genRect(61,83,672,157);
  1505. positions[3] += genRect(61,83,183,42), genRect(61,83,183,148), genRect(61,83,183,253);
  1506. positions[4] += genRect(61,83,491,325), genRect(61,83,591,325);
  1507. blitAt(view,332,76,bg);
  1508. for(size_t i=0; i<owner->town->town->mageLevel; i++)
  1509. {
  1510. size_t sp = owner->town->spellsAtLevel(i+1,false); //spell at level with -1 hmmm?
  1511. for(size_t j=0; j<sp; j++)
  1512. {
  1513. if(i<owner->town->mageGuildLevel() && owner->town->spells[i].size()>j)
  1514. {
  1515. spells.push_back(Scroll(&CGI->spellh->spells[owner->town->spells[i][j]]));
  1516. spells[spells.size()-1].pos = positions[i][j];
  1517. blitAt(graphics->spellscr->ourImages[owner->town->spells[i][j]].bitmap,positions[i][j],bg);
  1518. }
  1519. else
  1520. {
  1521. blitAt(scrolls2->ourImages[1].bitmap,positions[i][j],bg);
  1522. }
  1523. }
  1524. }
  1525. SDL_FreeSurface(view);
  1526. for(size_t i=0;i<spells.size();i++)
  1527. {
  1528. spells[i].pos.x += pos.x;
  1529. spells[i].pos.y += pos.y;
  1530. }
  1531. delete scrolls2;
  1532. }
  1533. CMageGuildScreen::~CMageGuildScreen()
  1534. {
  1535. delete exit;
  1536. SDL_FreeSurface(bg);
  1537. delete resdatabar;
  1538. }
  1539. void CMageGuildScreen::close()
  1540. {
  1541. GH.popIntTotally(this);
  1542. }
  1543. void CMageGuildScreen::show(SDL_Surface * to)
  1544. {
  1545. blitAt(bg,pos,to);
  1546. resdatabar->show(to);
  1547. LOCPLINT->statusbar->show(to);
  1548. exit->show(to);
  1549. }
  1550. void CMageGuildScreen::activate()
  1551. {
  1552. exit->activate();
  1553. for(size_t i=0;i<spells.size();i++)
  1554. {
  1555. spells[i].activate();
  1556. }
  1557. }
  1558. void CMageGuildScreen::deactivate()
  1559. {
  1560. exit->deactivate();
  1561. for(size_t i=0;i<spells.size();i++)
  1562. {
  1563. spells[i].deactivate();
  1564. }
  1565. }
  1566. void CMageGuildScreen::Scroll::clickLeft(tribool down, bool previousState)
  1567. {
  1568. if(down)
  1569. {
  1570. std::vector<SComponent*> comps(1,
  1571. new CCustomImgComponent(SComponent::spell,spell->id,0,graphics->spellscr->ourImages[spell->id].bitmap,false)
  1572. );
  1573. LOCPLINT->showInfoDialog(spell->descriptions[0],comps, soundBase::sound_todo);
  1574. }
  1575. }
  1576. void CMageGuildScreen::Scroll::clickRight(tribool down, bool previousState)
  1577. {
  1578. if(down)
  1579. {
  1580. CInfoPopup *vinya = new CInfoPopup();
  1581. vinya->free = true;
  1582. vinya->bitmap = CMessage::drawBoxTextBitmapSub
  1583. (LOCPLINT->playerID,
  1584. spell->descriptions[0],graphics->spellscr->ourImages[spell->id].bitmap,
  1585. spell->name,30,30);
  1586. vinya->pos.x = screen->w/2 - vinya->bitmap->w/2;
  1587. vinya->pos.y = screen->h/2 - vinya->bitmap->h/2;
  1588. GH.pushInt(vinya);
  1589. }
  1590. }
  1591. void CMageGuildScreen::Scroll::hover(bool on)
  1592. {
  1593. //Hoverable::hover(on);
  1594. if(on)
  1595. LOCPLINT->statusbar->print(spell->name);
  1596. else
  1597. LOCPLINT->statusbar->clear();
  1598. }
  1599. void CMageGuildScreen::Scroll::activate()
  1600. {
  1601. activateLClick();
  1602. activateRClick();
  1603. activateHover();
  1604. }
  1605. void CMageGuildScreen::Scroll::deactivate()
  1606. {
  1607. deactivateLClick();
  1608. deactivateRClick();
  1609. deactivateHover();
  1610. }
  1611. CBlacksmithDialog::CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid)
  1612. {
  1613. SDL_Surface *bg2 = BitmapHandler::loadBitmap("TPSMITH.bmp");
  1614. SDL_SetColorKey(bg2,SDL_SRCCOLORKEY,SDL_MapRGB(bg2->format,0,255,255));
  1615. graphics->blueToPlayersAdv(bg2,LOCPLINT->playerID);
  1616. bmp = SDL_ConvertSurface(bg2,screen->format,0);
  1617. SDL_FreeSurface(bg2);
  1618. bg2 = BitmapHandler::loadBitmap("TPSMITBK.bmp");
  1619. blitAt(bg2,64,50,bmp);
  1620. SDL_FreeSurface(bg2);
  1621. CCreatureAnimation cra(CGI->creh->creatures[creMachineID].animDefName);
  1622. cra.nextFrameMiddle(bmp,170,120,true,0,false);
  1623. char pom[75];
  1624. sprintf(pom,CGI->generaltexth->allTexts[274].c_str(),CGI->creh->creatures[creMachineID].nameSing.c_str()); //build a new ...
  1625. printAtMiddle(pom,165,28,GEORXX,tytulowy,bmp);
  1626. printAtMiddle(CGI->generaltexth->jktexts[43],165,218,GEOR16,zwykly,bmp); //resource cost
  1627. SDL_itoa(CGI->arth->artifacts[aid].price,pom,10);
  1628. printAtMiddle(pom,165,290,GEOR13,zwykly,bmp);
  1629. pos.w = bmp->w;
  1630. pos.h = bmp->h;
  1631. pos.x = screen->w/2 - pos.w/2;
  1632. pos.y = screen->h/2 - pos.h/2;
  1633. buy = new AdventureMapButton("","",boost::bind(&CBlacksmithDialog::close,this),pos.x + 42,pos.y + 312,"IBUY30.DEF",SDLK_RETURN);
  1634. cancel = new AdventureMapButton("","",boost::bind(&CBlacksmithDialog::close,this),pos.x + 224,pos.y + 312,"ICANCEL.DEF",SDLK_ESCAPE);
  1635. if(possible)
  1636. buy->callback += boost::bind(&CCallback::buyArtifact,LOCPLINT->cb,LOCPLINT->cb->getHeroInfo(hid,2),aid);
  1637. else
  1638. buy->bitmapOffset = 2;
  1639. blitAt(graphics->resources32->ourImages[6].bitmap,148,244,bmp);
  1640. }
  1641. void CBlacksmithDialog::show( SDL_Surface * to )
  1642. {
  1643. blitAt(bmp,pos,to);
  1644. buy->show(to);
  1645. cancel->show(to);
  1646. }
  1647. void CBlacksmithDialog::activate()
  1648. {
  1649. if(!buy->bitmapOffset)
  1650. buy->activate();
  1651. cancel->activate();
  1652. }
  1653. void CBlacksmithDialog::deactivate()
  1654. {
  1655. if(!buy->bitmapOffset)
  1656. buy->deactivate();
  1657. cancel->deactivate();
  1658. }
  1659. CBlacksmithDialog::~CBlacksmithDialog()
  1660. {
  1661. SDL_FreeSurface(bmp);
  1662. delete cancel;
  1663. delete buy;
  1664. }
  1665. void CBlacksmithDialog::close()
  1666. {
  1667. GH.popIntTotally(this);
  1668. }