CCastleInterface.cpp 48 KB

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