CCastleInterface.cpp 48 KB

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