CCastleInterface.cpp 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780
  1. #include "../stdafx.h"
  2. #include "CCastleInterface.h"
  3. #include "AdventureMapButton.h"
  4. #include "CAdvmapInterface.h"
  5. #include "../CCallback.h"
  6. #include "CGameInfo.h"
  7. #include "CHeroWindow.h"
  8. #include "CMessage.h"
  9. #include "SDL_Extensions.h"
  10. #include "CCreatureAnimation.h"
  11. #include "Graphics.h"
  12. #include "../hch/CArtHandler.h"
  13. #include "../hch/CBuildingHandler.h"
  14. #include "../hch/CDefHandler.h"
  15. #include "../hch/CGeneralTextHandler.h"
  16. #include "../hch/CLodHandler.h"
  17. #include "../hch/CObjectHandler.h"
  18. #include "../hch/CSpellHandler.h"
  19. #include "../hch/CTownHandler.h"
  20. #include <boost/algorithm/string.hpp>
  21. #include <boost/algorithm/string/replace.hpp>
  22. #include <boost/assign/std/vector.hpp>
  23. #include <boost/lexical_cast.hpp>
  24. #include <cmath>
  25. #include <sstream>
  26. using namespace boost::assign;
  27. using namespace CSDL_Ext;
  28. /*
  29. * CCastleInterface.cpp, part of VCMI engine
  30. *
  31. * Authors: listed in file AUTHORS in main folder
  32. *
  33. * License: GNU General Public License v2.0 or later
  34. * Full text of license available in license.txt file, in main folder
  35. *
  36. */
  37. extern TTF_Font * GEOR16;
  38. CBuildingRect::CBuildingRect(Structure *Str)
  39. :moi(false), offset(0), str(Str)
  40. {
  41. def = CDefHandler::giveDef(Str->defName);
  42. max = def->ourImages.size();
  43. if(str->ID == 33 && str->townID == 4) //little 'hack' for estate in necropolis - background color is not always the first color in the palette
  44. {
  45. for(std::vector<Cimage>::iterator i=def->ourImages.begin();i!=def->ourImages.end();i++)
  46. {
  47. SDL_SetColorKey(i->bitmap,SDL_SRCCOLORKEY,*((char*)i->bitmap->pixels));
  48. }
  49. }
  50. pos.x = str->pos.x + LOCPLINT->castleInt->pos.x;
  51. pos.y = str->pos.y + LOCPLINT->castleInt->pos.y;
  52. pos.w = def->ourImages[0].bitmap->w;
  53. pos.h = def->ourImages[0].bitmap->h;
  54. if(Str->ID<0 || (Str->ID>=27 && Str->ID<=29))
  55. {
  56. area = border = NULL;
  57. return;
  58. }
  59. if (border = BitmapHandler::loadBitmap(str->borderName)) //FIXME hmmm if '=' use () else '==' fatal mistake
  60. {
  61. SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255));
  62. }
  63. else
  64. {
  65. tlog2 << "Warning: no border for "<<Str->ID<<std::endl;
  66. }
  67. if (area = BitmapHandler::loadBitmap(str->areaName))//FIXME look up
  68. {
  69. ;//SDL_SetColorKey(area,SDL_SRCCOLORKEY,SDL_MapRGB(area->format,0,255,255));
  70. }
  71. else
  72. {
  73. tlog2 << "Warning: no area for "<<Str->ID<<std::endl;
  74. }
  75. }
  76. CBuildingRect::~CBuildingRect()
  77. {
  78. delete def;
  79. if(border)
  80. SDL_FreeSurface(border);
  81. if(area)
  82. SDL_FreeSurface(area);
  83. }
  84. void CBuildingRect::activate()
  85. {
  86. activateHover();
  87. activateLClick();
  88. activateRClick();
  89. }
  90. void CBuildingRect::deactivate()
  91. {
  92. deactivateHover();
  93. deactivateLClick();
  94. deactivateRClick();
  95. if(moi)
  96. deactivateMouseMove();
  97. moi=false;
  98. }
  99. bool CBuildingRect::operator<(const CBuildingRect & p2) const
  100. {
  101. if(str->pos.z != p2.str->pos.z)
  102. return (str->pos.z) < (p2.str->pos.z);
  103. else
  104. return (str->ID) < (p2.str->ID);
  105. }
  106. void CBuildingRect::hover(bool on)
  107. {
  108. //Hoverable::hover(on);
  109. if(on)
  110. {
  111. if(!moi)
  112. activateMouseMove();
  113. moi = true;
  114. }
  115. else
  116. {
  117. if(moi)
  118. deactivateMouseMove();
  119. moi = false;
  120. if(LOCPLINT->castleInt->hBuild == this)
  121. {
  122. LOCPLINT->castleInt->hBuild = NULL;
  123. LOCPLINT->statusbar->clear();
  124. //call mouseMoved in other buildings, cursor might have been moved while they were inactive (eg. because of r-click popup)
  125. for(size_t i = 0; i < LOCPLINT->castleInt->buildings.size(); i++)
  126. LOCPLINT->castleInt->buildings[i]->mouseMoved(GH.current->motion);
  127. }
  128. }
  129. }
  130. void CBuildingRect::clickLeft(tribool down, bool previousState)
  131. {
  132. if(area && (LOCPLINT->castleInt->hBuild==this) && !(indeterminate(down)) && (CSDL_Ext::SDL_GetPixel(area,GH.current->motion.x-pos.x,GH.current->motion.y-pos.y) != 0)) //na polu
  133. {
  134. if(previousState && !down)
  135. LOCPLINT->castleInt->buildingClicked(str->ID);
  136. //ClickableL::clickLeft(down);
  137. }
  138. }
  139. void CBuildingRect::clickRight(tribool down, bool previousState)
  140. {
  141. if((!area) || (!((bool)down)) || (this!=LOCPLINT->castleInt->hBuild))
  142. return;
  143. if((CSDL_Ext::SDL_GetPixel(area,GH.current->motion.x-pos.x,GH.current->motion.y-pos.y) != 0)) //na polu
  144. {
  145. CBuilding *bld = CGI->buildh->buildings[str->townID][str->ID];
  146. assert(bld);
  147. CInfoPopup *vinya = new CInfoPopup();
  148. vinya->free = true;
  149. vinya->bitmap = CMessage::drawBoxTextBitmapSub
  150. (LOCPLINT->playerID,
  151. bld->Description(),
  152. LOCPLINT->castleInt->bicons->ourImages[str->ID].bitmap,
  153. bld->Name());
  154. vinya->pos.x = screen->w/2 - vinya->bitmap->w/2;
  155. vinya->pos.y = screen->h/2 - vinya->bitmap->h/2;
  156. GH.pushInt(vinya);
  157. }
  158. }
  159. void CBuildingRect::mouseMoved (const SDL_MouseMotionEvent & sEvent)
  160. {
  161. if(area && isItIn(&pos,sEvent.x, sEvent.y))
  162. {
  163. if(CSDL_Ext::SDL_GetPixel(area,sEvent.x-pos.x,sEvent.y-pos.y) == 0) //hovered pixel is inside this building
  164. {
  165. if(LOCPLINT->castleInt->hBuild == this)
  166. {
  167. LOCPLINT->castleInt->hBuild = NULL;
  168. LOCPLINT->statusbar->clear();
  169. }
  170. }
  171. else //inside the area of this building
  172. {
  173. if(LOCPLINT->castleInt->hBuild) //a building is hovered
  174. {
  175. if((*LOCPLINT->castleInt->hBuild)<(*this)) //set if we are on top
  176. {
  177. LOCPLINT->castleInt->hBuild = this;
  178. if(CGI->buildh->buildings[str->townID][str->ID] && CGI->buildh->buildings[str->townID][str->ID]->Name().length())
  179. LOCPLINT->statusbar->print(CGI->buildh->buildings[str->townID][str->ID]->Name());
  180. else
  181. LOCPLINT->statusbar->print(str->name);
  182. }
  183. }
  184. else //no building hovered
  185. {
  186. LOCPLINT->castleInt->hBuild = this;
  187. if(CGI->buildh->buildings[str->townID][str->ID] && CGI->buildh->buildings[str->townID][str->ID]->Name().length())
  188. LOCPLINT->statusbar->print(CGI->buildh->buildings[str->townID][str->ID]->Name());
  189. else
  190. LOCPLINT->statusbar->print(str->name);
  191. }
  192. }
  193. }
  194. //if(border)
  195. // blitAt(border,pos.x,pos.y);
  196. }
  197. void CHeroGSlot::hover (bool on)
  198. {
  199. if(!on) return;
  200. CHeroGSlot *other = upg ? &owner->hslotup : &owner->hslotdown;
  201. std::string temp;
  202. if(hero)
  203. {
  204. if(highlight)//view NNN
  205. {
  206. temp = CGI->generaltexth->tcommands[4];
  207. boost::algorithm::replace_first(temp,"%s",hero->name);
  208. }
  209. else if(other->hero && other->highlight)//exchange
  210. {
  211. temp = CGI->generaltexth->tcommands[7];
  212. boost::algorithm::replace_first(temp,"%s",hero->name);
  213. boost::algorithm::replace_first(temp,"%s",other->hero->name);
  214. }
  215. else// select NNN (in ZZZ)
  216. {
  217. if(upg)//down - visiting
  218. {
  219. temp = CGI->generaltexth->tcommands[32];
  220. boost::algorithm::replace_first(temp,"%s",hero->name);
  221. }
  222. else //up - garrison
  223. {
  224. temp = CGI->generaltexth->tcommands[12];
  225. boost::algorithm::replace_first(temp,"%s",hero->name);
  226. }
  227. }
  228. }
  229. else //we are empty slot
  230. {
  231. if(other->highlight && other->hero) //move NNNN
  232. {
  233. temp = CGI->generaltexth->tcommands[6];
  234. boost::algorithm::replace_first(temp,"%s",other->hero->name);
  235. }
  236. else //empty
  237. {
  238. temp = CGI->generaltexth->allTexts[507];
  239. }
  240. }
  241. if(temp.size())
  242. LOCPLINT->statusbar->print(temp);
  243. }
  244. void CHeroGSlot::clickRight(tribool down, bool previousState)
  245. {
  246. }
  247. void CHeroGSlot::clickLeft(tribool down, bool previousState)
  248. {
  249. CHeroGSlot *other = upg ? &owner->hslotup : &owner->hslotdown;
  250. if(!down)
  251. {
  252. owner->garr->splitting = false;
  253. owner->garr->highlighted = NULL;
  254. if(hero && highlight)
  255. {
  256. highlight = false;
  257. LOCPLINT->openHeroWindow(hero);
  258. }
  259. else if(other->hero && other->highlight)
  260. {
  261. bool allow = true;
  262. if(upg) //moving hero out of town - check if it is allowed
  263. {
  264. if(!hero && LOCPLINT->cb->howManyHeroes(false) >= 8)
  265. {
  266. std::string tmp = CGI->generaltexth->allTexts[18]; //You already have %d adventuring heroes under your command.
  267. boost::algorithm::replace_first(tmp,"%d",boost::lexical_cast<std::string>(LOCPLINT->cb->howManyHeroes(false)));
  268. LOCPLINT->showInfoDialog(tmp,std::vector<SComponent*>(), soundBase::sound_todo);
  269. allow = false;
  270. }
  271. else if(!other->hero->army.slots.size()) //hero has no creatures - strange, but if we have appropriate error message...
  272. {
  273. LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[19],std::vector<SComponent*>(), soundBase::sound_todo); //This hero has no creatures. A hero must have creatures before he can brave the dangers of the countryside.
  274. allow = false;
  275. }
  276. }
  277. other->highlight = highlight = false;
  278. if(allow)
  279. LOCPLINT->cb->swapGarrisonHero(owner->town);
  280. }
  281. else if(hero)
  282. {
  283. highlight = true;
  284. owner->garr->highlighted = NULL;
  285. show(screen2);
  286. }
  287. hover(false);hover(true); //refresh statusbar
  288. }
  289. //if(indeterminate(down) && !isItIn(&other->pos,GH.current->motion.x,GH.current->motion.y))
  290. //{
  291. // other->highlight = highlight = false;
  292. // show(screen2);
  293. //}
  294. }
  295. void CHeroGSlot::activate()
  296. {
  297. activateLClick();
  298. activateRClick();
  299. activateHover();
  300. }
  301. void CHeroGSlot::deactivate()
  302. {
  303. highlight = false;
  304. deactivateLClick();
  305. deactivateRClick();
  306. deactivateHover();
  307. }
  308. void CHeroGSlot::show(SDL_Surface * to)
  309. {
  310. if(hero) //there is hero
  311. blitAt(graphics->portraitLarge[hero->portrait],pos,to);
  312. else if(!upg) //up garrison
  313. blitAt(graphics->flags->ourImages[LOCPLINT->castleInt->town->getOwner()].bitmap,pos,to);
  314. if(highlight)
  315. blitAt(graphics->bigImgs[-1],pos,to);
  316. }
  317. CHeroGSlot::CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h, CCastleInterface * Owner)
  318. {
  319. owner = Owner;
  320. pos.x = x;
  321. pos.y = y;
  322. pos.w = 58;
  323. pos.h = 64;
  324. hero = h;
  325. upg = updown;
  326. highlight = false;
  327. }
  328. CHeroGSlot::~CHeroGSlot()
  329. {
  330. }
  331. static std::string getBgName(int type) //TODO - co z tym zrobi�?
  332. {
  333. switch (type)
  334. {
  335. case 0:
  336. return "TBCSBACK.bmp";
  337. case 1:
  338. return "TBRMBACK.bmp";
  339. case 2:
  340. return "TBTWBACK.bmp";
  341. case 3:
  342. return "TBINBACK.bmp";
  343. case 4:
  344. return "TBNCBACK.bmp";
  345. case 5:
  346. return "TBDNBACK.bmp";
  347. case 6:
  348. return "TBSTBACK.bmp";
  349. case 7:
  350. return "TBFRBACK.bmp";
  351. case 8:
  352. return "TBELBACK.bmp";
  353. default:
  354. #ifndef __GNUC__
  355. throw new std::exception("std::string getBgName(int type): invalid type");
  356. #else
  357. throw new std::exception();
  358. #endif
  359. }
  360. }
  361. class SORTHELP
  362. {
  363. public:
  364. bool operator ()
  365. (const CBuildingRect *a ,
  366. const CBuildingRect *b)
  367. {
  368. return (*a)<(*b);
  369. }
  370. } srthlp ;
  371. CCastleInterface::CCastleInterface(const CGTownInstance * Town, int listPos)
  372. :hslotup(241,387,0,Town->garrisonHero,this),hslotdown(241,483,1,Town->visitingHero,this)
  373. {
  374. showing = false;
  375. bars = CDefHandler::giveDefEss("TPTHBAR.DEF");
  376. status = CDefHandler::giveDefEss("TPTHCHK.DEF");
  377. LOCPLINT->castleInt = this;
  378. hall = NULL;
  379. townInt = BitmapHandler::loadBitmap("TOWNSCRN.bmp");
  380. cityBg = BitmapHandler::loadBitmap(getBgName(Town->subID));
  381. pos.x = screen->w/2 - 400;
  382. pos.y = screen->h/2 - 300;
  383. hslotup.pos.x += pos.x;
  384. hslotup.pos.y += pos.y;
  385. hslotdown.pos.x += pos.x;
  386. hslotdown.pos.y += pos.y;
  387. hall = CDefHandler::giveDef("ITMTL.DEF");
  388. fort = CDefHandler::giveDef("ITMCL.DEF");
  389. hBuild = NULL;
  390. count=0;
  391. town = Town;
  392. animval = 0;
  393. //garrison
  394. garr = new CGarrisonInt(pos.x+305,pos.y+387,4,Point(0,96),townInt,Point(62,374),town,town->visitingHero);
  395. townlist = new CTownList(3,pos.x+744,pos.y+414,"IAM014.DEF","IAM015.DEF");//744,526);
  396. exit = new AdventureMapButton
  397. (CGI->generaltexth->tcommands[8],"",boost::bind(&CCastleInterface::close,this),pos.x+744,pos.y+544,"TSBTNS.DEF",SDLK_RETURN);
  398. exit->assignedKeys.insert(SDLK_ESCAPE);
  399. split = new AdventureMapButton
  400. (CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),pos.x+744,pos.y+382,"TSBTNS.DEF");
  401. statusbar = new CStatusBar(pos.x+7,pos.y+555,"TSTATBAR.bmp",732);
  402. resdatabar = new CResDataBar("ZRESBAR.bmp",pos.x+3,pos.y+575,32,2,85,85);
  403. resdatabar->pos.x = pos.x+3; resdatabar->pos.y = pos.y+575;
  404. townlist->fun = boost::bind(&CCastleInterface::townChange,this);
  405. townlist->genList();
  406. townlist->selected = vstd::findPos(townlist->items,Town);
  407. townlist->from = townlist->selected - listPos;
  408. amax(townlist->from, 0);
  409. amin(townlist->from, townlist->items.size() - townlist->SIZE);
  410. graphics->blueToPlayersAdv(townInt,LOCPLINT->playerID);
  411. exit->bitmapOffset = 4;
  412. //buildings
  413. recreateBuildings();
  414. std::string defname;
  415. switch (town->subID)
  416. {
  417. case 0:
  418. defname = "HALLCSTL.DEF";
  419. musicID = musicBase::castleTown;
  420. break;
  421. case 1:
  422. defname = "HALLRAMP.DEF";
  423. musicID = musicBase::rampartTown;
  424. break;
  425. case 2:
  426. defname = "HALLTOWR.DEF";
  427. musicID = musicBase::towerTown;
  428. break;
  429. case 3:
  430. defname = "HALLINFR.DEF";
  431. musicID = musicBase::infernoTown;
  432. break;
  433. case 4:
  434. defname = "HALLNECR.DEF";
  435. musicID = musicBase::necroTown;
  436. break;
  437. case 5:
  438. defname = "HALLDUNG.DEF";
  439. musicID = musicBase::dungeonTown;
  440. break;
  441. case 6:
  442. defname = "HALLSTRN.DEF";
  443. musicID = musicBase::strongHoldTown;
  444. break;
  445. case 7:
  446. defname = "HALLFORT.DEF";
  447. musicID = musicBase::fortressTown;
  448. break;
  449. case 8:
  450. defname = "HALLELEM.DEF";
  451. musicID = musicBase::elemTown;
  452. break;
  453. default:
  454. throw new std::string("Wrong town subID");
  455. }
  456. bicons = CDefHandler::giveDefEss(defname);
  457. CGI->musich->playMusic(musicID, -1);
  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. GH.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. GH.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. GH.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. GH.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. GH.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. GH.popIntTotally(this);
  697. GH.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. activateKeys();
  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. deactivateKeys();
  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. CRecruitmentWindow *rw = new CRecruitmentWindow(town, level, town, boost::bind(&CCallback::recruitCreatures,LOCPLINT->cb,town,_1,_2));
  906. GH.pushInt(rw);
  907. return rw;
  908. }
  909. void CCastleInterface::enterMageGuild()
  910. {
  911. GH.pushInt(new CMageGuildScreen(this));
  912. }
  913. void CCastleInterface::enterTavern()
  914. {
  915. std::vector<const CGHeroInstance*> h = LOCPLINT->cb->getAvailableHeroes(town);
  916. CTavernWindow *tv = new CTavernWindow(h[0],h[1],"GOSSIP TEST");
  917. GH.pushInt(tv);
  918. }
  919. void CCastleInterface::keyPressed( const SDL_KeyboardEvent & key )
  920. {
  921. if(key.state != SDL_RELEASED) return;
  922. switch(key.keysym.sym)
  923. {
  924. case SDLK_UP:
  925. if(townlist->selected)
  926. {
  927. townlist->selected--;
  928. townlist->from--;
  929. townChange();
  930. }
  931. break;
  932. case SDLK_DOWN:
  933. if(townlist->selected < townlist->items.size() - 1)
  934. {
  935. townlist->selected++;
  936. townlist->from++;
  937. townChange();
  938. }
  939. break;
  940. case SDLK_SPACE:
  941. if(town->visitingHero && town->garrisonHero)
  942. {
  943. LOCPLINT->cb->swapGarrisonHero(town);
  944. }
  945. break;
  946. }
  947. }
  948. void CHallInterface::CBuildingBox::hover(bool on)
  949. {
  950. //Hoverable::hover(on);
  951. if(on)
  952. {
  953. std::string toPrint;
  954. if(state==8)
  955. toPrint = CGI->generaltexth->hcommands[5];
  956. else
  957. toPrint = CGI->generaltexth->hcommands[state];
  958. std::vector<std::string> name;
  959. name.push_back(CGI->buildh->buildings[LOCPLINT->castleInt->town->subID][BID]->Name());
  960. LOCPLINT->statusbar->print(CSDL_Ext::processStr(toPrint,name));
  961. }
  962. else
  963. LOCPLINT->statusbar->clear();
  964. }
  965. void CHallInterface::CBuildingBox::clickLeft(tribool down, bool previousState)
  966. {
  967. if(previousState && (!down))
  968. {
  969. GH.pushInt(new CHallInterface::CBuildWindow(LOCPLINT->castleInt->town->subID,BID,state,0));
  970. }
  971. //ClickableL::clickLeft(down);
  972. }
  973. void CHallInterface::CBuildingBox::clickRight(tribool down, bool previousState)
  974. {
  975. if(down)
  976. {
  977. GH.pushInt(new CHallInterface::CBuildWindow(LOCPLINT->castleInt->town->subID,BID,state,1));
  978. }
  979. //ClickableR::clickRight(down);
  980. }
  981. void CHallInterface::CBuildingBox::show(SDL_Surface * to)
  982. {
  983. CCastleInterface *ci = LOCPLINT->castleInt;
  984. blitAt(ci->bicons->ourImages[BID].bitmap,pos.x,pos.y,to);
  985. int pom, pom2=-1;
  986. switch (state)
  987. {
  988. case 4:
  989. pom = 0;
  990. pom2 = 0;
  991. break;
  992. case 7:
  993. pom = 1;
  994. break;
  995. case 6:
  996. pom2 = 2;
  997. pom = 2;
  998. break;
  999. case 5: case 8:
  1000. pom2 = 1;
  1001. pom = 2;
  1002. break;
  1003. case 0: case 2: case 1: default:
  1004. pom = 3;
  1005. break;
  1006. }
  1007. blitAt(ci->bars->ourImages[pom].bitmap,pos.x-1,pos.y+71,to);
  1008. if(pom2>=0)
  1009. blitAt(ci->status->ourImages[pom2].bitmap,pos.x+135, pos.y+54,to);
  1010. 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);
  1011. }
  1012. void CHallInterface::CBuildingBox::activate()
  1013. {
  1014. activateHover();
  1015. activateLClick();
  1016. activateRClick();
  1017. }
  1018. void CHallInterface::CBuildingBox::deactivate()
  1019. {
  1020. deactivateHover();
  1021. deactivateLClick();
  1022. deactivateRClick();
  1023. }
  1024. CHallInterface::CBuildingBox::~CBuildingBox()
  1025. {
  1026. }
  1027. CHallInterface::CBuildingBox::CBuildingBox(int id)
  1028. :BID(id)
  1029. {
  1030. pos.w = 150;
  1031. pos.h = 70;
  1032. }
  1033. CHallInterface::CBuildingBox::CBuildingBox(int id, int x, int y)
  1034. :BID(id)
  1035. {
  1036. pos.x = x;
  1037. pos.y = y;
  1038. pos.w = 150;
  1039. pos.h = 70;
  1040. }
  1041. CHallInterface::CHallInterface(CCastleInterface * owner)
  1042. {
  1043. resdatabar = new CMinorResDataBar;
  1044. pos = owner->pos;
  1045. resdatabar->pos.x += pos.x;
  1046. resdatabar->pos.y += pos.y;
  1047. bg = BitmapHandler::loadBitmap(CGI->buildh->hall[owner->town->subID].first);
  1048. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  1049. exit = new AdventureMapButton
  1050. (CGI->generaltexth->tcommands[8],"",boost::bind(&CHallInterface::close,this),pos.x+748,pos.y+556,"TPMAGE1.DEF",SDLK_RETURN);
  1051. exit->assignedKeys.insert(SDLK_ESCAPE);
  1052. //preparing boxes with buildings//
  1053. boxes.resize(5);
  1054. for(size_t i=0;i<5;i++) //for each row
  1055. {
  1056. std::vector< std::vector< std::vector<int> > > &boxList = CGI->buildh->hall[owner->town->subID].second;
  1057. for(size_t j=0; j<boxList[i].size();j++) //for each box
  1058. {
  1059. size_t k=0;
  1060. for(;k<boxList[i][j].size();k++)//we are looking for the first not build structure
  1061. {
  1062. int bid = boxList[i][j][k];
  1063. if(!vstd::contains(owner->town->builtBuildings,bid))
  1064. {
  1065. int x = 34 + 194*j,
  1066. y = 37 + 104*i,
  1067. ID = bid;
  1068. if(boxList[i].size() == 2) //only two boxes in this row
  1069. x+=194;
  1070. else if(boxList[i].size() == 3) //only three boxes in this row
  1071. x+=97;
  1072. boxes[i].push_back(new CBuildingBox(bid,pos.x+x,pos.y+y));
  1073. //if this is horde dwelling for upgraded creatures and we already have one for basic creatures
  1074. if((bid == 25 && vstd::contains(owner->town->builtBuildings,24))
  1075. || (bid == 19 && vstd::contains(owner->town->builtBuildings,18))
  1076. )
  1077. {
  1078. boxes[i].back()->state = 4; //already built
  1079. }
  1080. else
  1081. {
  1082. boxes[i].back()->state = LOCPLINT->cb->canBuildStructure(owner->town,ID);
  1083. }
  1084. break;
  1085. }
  1086. }
  1087. if(k == boxList[i][j].size()) //all buildings built - let's take the last one
  1088. {
  1089. int x = 34 + 194*j,
  1090. y = 37 + 104*i;
  1091. if(boxList[i].size() == 2)
  1092. x+=194;
  1093. else if(boxList[i].size() == 3)
  1094. x+=97;
  1095. boxes[i].push_back(new CBuildingBox(boxList[i][j][k-1],pos.x+x,pos.y+y));
  1096. boxes[i][boxes[i].size()-1]->state = 4; //already exists
  1097. }
  1098. }
  1099. }
  1100. }
  1101. CHallInterface::~CHallInterface()
  1102. {
  1103. SDL_FreeSurface(bg);
  1104. for(size_t i=0;i<boxes.size();i++)
  1105. for(size_t j=0;j<boxes[i].size();j++)
  1106. delete boxes[i][j]; //TODO whats wrong with smartpointers?
  1107. delete exit;
  1108. delete resdatabar;
  1109. }
  1110. void CHallInterface::close()
  1111. {
  1112. GH.popIntTotally(this);
  1113. }
  1114. void CHallInterface::show(SDL_Surface * to)
  1115. {
  1116. blitAt(bg,pos,to);
  1117. LOCPLINT->castleInt->statusbar->show(to);
  1118. resdatabar->show(to);
  1119. exit->show(to);
  1120. for(int i=0; i<5; i++)
  1121. {
  1122. for(size_t j=0;j<boxes[i].size(); ++j)
  1123. boxes[i][j]->show(to);
  1124. }
  1125. }
  1126. void CHallInterface::activate()
  1127. {
  1128. for(int i=0;i<5;i++)
  1129. {
  1130. for(size_t j=0; j < boxes[i].size(); ++j)
  1131. {
  1132. boxes[i][j]->activate();
  1133. }
  1134. }
  1135. exit->activate();
  1136. }
  1137. void CHallInterface::deactivate()
  1138. {
  1139. for(int i=0;i<5;i++)
  1140. {
  1141. for(size_t j=0;j<boxes[i].size();++j)
  1142. {
  1143. boxes[i][j]->deactivate();
  1144. }
  1145. }
  1146. exit->deactivate();
  1147. }
  1148. void CHallInterface::CBuildWindow::activate()
  1149. {
  1150. activateRClick();
  1151. if(mode)
  1152. return;
  1153. if(state==7)
  1154. buy->activate();
  1155. cancel->activate();
  1156. }
  1157. void CHallInterface::CBuildWindow::deactivate()
  1158. {
  1159. deactivateRClick();
  1160. if(mode)
  1161. return;
  1162. if(state==7)
  1163. buy->deactivate();
  1164. cancel->deactivate();
  1165. }
  1166. void CHallInterface::CBuildWindow::Buy()
  1167. {
  1168. int building = bid;
  1169. GH.popInts(2); //we - build window and hall screen
  1170. LOCPLINT->cb->buildBuilding(LOCPLINT->castleInt->town,building);
  1171. }
  1172. void CHallInterface::CBuildWindow::close()
  1173. {
  1174. GH.popIntTotally(this);
  1175. }
  1176. void CHallInterface::CBuildWindow::clickRight(tribool down, bool previousState)
  1177. {
  1178. if((!down || indeterminate(down)) && mode)
  1179. close();
  1180. }
  1181. void CHallInterface::CBuildWindow::show(SDL_Surface * to)
  1182. {
  1183. SDL_Rect pom = genRect(bitmap->h-1,bitmap->w-1,pos.x,pos.y);
  1184. SDL_Rect poms = pom; poms.x=0;poms.y=0;
  1185. SDL_BlitSurface(bitmap,&poms,to,&pom);
  1186. if(!mode)
  1187. {
  1188. buy->show(to);
  1189. cancel->show(to);
  1190. }
  1191. }
  1192. std::string CHallInterface::CBuildWindow::getTextForState(int state)
  1193. {
  1194. std::string ret;
  1195. if(state<7)
  1196. ret = CGI->generaltexth->hcommands[state];
  1197. switch (state)
  1198. {
  1199. case 4: case 5: case 6:
  1200. ret.replace(ret.find_first_of("%s"),2,CGI->buildh->buildings[tid][bid]->Name());
  1201. break;
  1202. case 7:
  1203. return CGI->generaltexth->allTexts[219]; //all prereq. are met
  1204. case 8:
  1205. {
  1206. ret = CGI->generaltexth->allTexts[52];
  1207. std::set<int> used;
  1208. used.insert(bid);
  1209. std::set<int> reqs;
  1210. for(std::set<int>::iterator i=CGI->townh->requirements[tid][bid].begin();
  1211. i!=CGI->townh->requirements[tid][bid].end();
  1212. i++
  1213. )
  1214. {
  1215. if (LOCPLINT->castleInt->town->builtBuildings.find(*i) == LOCPLINT->castleInt->town->builtBuildings.end())
  1216. reqs.insert(*i);
  1217. }
  1218. while(true)
  1219. {
  1220. size_t czystych=0;
  1221. for(std::set<int>::iterator i=reqs.begin();i!=reqs.end();i++)
  1222. {
  1223. if(used.find(*i)==used.end()) //we haven't added requirements for this building
  1224. {
  1225. used.insert(*i);
  1226. for(
  1227. std::set<int>::iterator j=CGI->townh->requirements[tid][*i].begin();
  1228. j!=CGI->townh->requirements[tid][*i].end();
  1229. j++
  1230. )
  1231. {
  1232. if(LOCPLINT->castleInt->town->builtBuildings.find(*j) == //this building is not built
  1233. LOCPLINT->castleInt->town->builtBuildings.end())
  1234. reqs.insert(*j);
  1235. }
  1236. }
  1237. else
  1238. {
  1239. czystych++;
  1240. }
  1241. }
  1242. if(czystych==reqs.size())
  1243. break;
  1244. }
  1245. bool first=true;
  1246. for(std::set<int>::iterator i=reqs.begin();i!=reqs.end();i++)
  1247. {
  1248. ret+=(((first)?(" "):(", ")) + CGI->buildh->buildings[tid][*i]->Name());
  1249. first = false;
  1250. }
  1251. }
  1252. }
  1253. return ret;
  1254. }
  1255. CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mode)
  1256. :tid(Tid), bid(Bid), state(State), mode(Mode)
  1257. {
  1258. SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPUBUILD.bmp");
  1259. graphics->blueToPlayersAdv(hhlp,LOCPLINT->playerID);
  1260. bitmap = SDL_ConvertSurface(hhlp,screen->format,0); //na 8bitowej mapie by sie psulo
  1261. SDL_SetColorKey(hhlp,SDL_SRCCOLORKEY,SDL_MapRGB(hhlp->format,0,255,255));
  1262. SDL_FreeSurface(hhlp);
  1263. pos.x = screen->w/2 - bitmap->w/2;
  1264. pos.y = screen->h/2 - bitmap->h/2;
  1265. blitAt(LOCPLINT->castleInt->bicons->ourImages[bid].bitmap,125,50,bitmap);
  1266. std::vector<std::string> pom; pom.push_back(CGI->buildh->buildings[tid][bid]->Name());
  1267. CSDL_Ext::printAtMiddleWB(CGI->buildh->buildings[tid][bid]->Description(),197,168,GEOR16,40,zwykly,bitmap);
  1268. CSDL_Ext::printAtMiddleWB(getTextForState(state),197,248,GEOR13,50,zwykly,bitmap);
  1269. CSDL_Ext::printAtMiddle(CSDL_Ext::processStr(CGI->generaltexth->hcommands[7],pom),197,30,GEOR16,tytulowy,bitmap);
  1270. int resamount=0;
  1271. for(int i=0;i<7;i++)
  1272. {
  1273. if(CGI->buildh->buildings[tid][bid]->resources[i])
  1274. {
  1275. resamount++;
  1276. }
  1277. }
  1278. int ah = (resamount>4) ? 304 : 341;
  1279. int cn=-1, it=0;
  1280. int row1w = std::min(resamount,4) * 32 + (std::min(resamount,4)-1) * 45,
  1281. row2w = (resamount-4) * 32 + (resamount-5) * 45;
  1282. char buf[15];
  1283. while(++cn<7)
  1284. {
  1285. if(!CGI->buildh->buildings[tid][bid]->resources[cn])
  1286. continue;
  1287. SDL_itoa(CGI->buildh->buildings[tid][bid]->resources[cn],buf,10);
  1288. if(it<4)
  1289. {
  1290. CSDL_Ext::printAtMiddle(buf,(bitmap->w/2-row1w/2)+77*it+16,ah+42,GEOR16,zwykly,bitmap);
  1291. blitAt(graphics->resources32->ourImages[cn].bitmap,(bitmap->w/2-row1w/2)+77*it++,ah,bitmap);
  1292. }
  1293. else
  1294. {
  1295. CSDL_Ext::printAtMiddle(buf,(bitmap->w/2-row2w/2)+77*it+16-308,ah+42,GEOR16,zwykly,bitmap);
  1296. blitAt(graphics->resources32->ourImages[cn].bitmap,(bitmap->w/2-row2w/2)+77*it++ - 308,ah,bitmap);
  1297. }
  1298. if(it==4)
  1299. ah+=75;
  1300. }
  1301. if(!mode)
  1302. {
  1303. buy = new AdventureMapButton
  1304. ("","",boost::bind(&CBuildWindow::Buy,this),pos.x+45,pos.y+446,"IBUY30.DEF",SDLK_RETURN);
  1305. cancel = new AdventureMapButton
  1306. ("","",boost::bind(&CBuildWindow::close,this),pos.x+290,pos.y+445,"ICANCEL.DEF",SDLK_ESCAPE);
  1307. if(state!=7)
  1308. buy->state=2;
  1309. }
  1310. }
  1311. CHallInterface::CBuildWindow::~CBuildWindow()
  1312. {
  1313. SDL_FreeSurface(bitmap);
  1314. if(!mode)
  1315. {
  1316. delete buy;
  1317. delete cancel;
  1318. }
  1319. }
  1320. CFortScreen::~CFortScreen()
  1321. {
  1322. for(size_t i=0;i<crePics.size();i++)
  1323. delete crePics[i];
  1324. for (size_t i=0;i<recAreas.size();i++)
  1325. delete recAreas[i];
  1326. SDL_FreeSurface(bg);
  1327. delete exit;
  1328. delete resdatabar;
  1329. }
  1330. void CFortScreen::show( SDL_Surface * to)
  1331. {
  1332. blitAt(bg,pos,to);
  1333. static unsigned char anim = 1;
  1334. for (int i=0; i<CREATURES_PER_TOWN; i++)
  1335. {
  1336. crePics[i]->blitPic(to,pos.x+positions[i].x+159,pos.y+positions[i].y+4,!(anim%4));
  1337. }
  1338. anim++;
  1339. exit->show(to);
  1340. resdatabar->show(to);
  1341. LOCPLINT->statusbar->show(to);
  1342. }
  1343. void CFortScreen::activate()
  1344. {
  1345. LOCPLINT->statusbar = LOCPLINT->castleInt->statusbar;
  1346. exit->activate();
  1347. for (size_t i=0;i<recAreas.size(); ++i)
  1348. {
  1349. recAreas[i]->activate();
  1350. }
  1351. }
  1352. void CFortScreen::deactivate()
  1353. {
  1354. exit->deactivate();
  1355. for (size_t i=0;i<recAreas.size();i++)
  1356. {
  1357. recAreas[i]->deactivate();
  1358. }
  1359. }
  1360. void CFortScreen::close()
  1361. {
  1362. GH.popIntTotally(this);
  1363. }
  1364. CFortScreen::CFortScreen( CCastleInterface * owner )
  1365. {
  1366. resdatabar = new CMinorResDataBar;
  1367. pos = owner->pos;
  1368. bg = NULL;
  1369. exit = new AdventureMapButton(CGI->generaltexth->tcommands[8],"",boost::bind(&CFortScreen::close,this),pos.x+748,pos.y+556,"TPMAGE1.DEF",SDLK_RETURN);
  1370. positions += genRect(126,386,10,22),genRect(126,386,404,22),
  1371. genRect(126,386,10,155),genRect(126,386,404,155),
  1372. genRect(126,386,10,288),genRect(126,386,404,288),
  1373. genRect(126,386,206,421);
  1374. draw(owner,true);
  1375. resdatabar->pos += pos;
  1376. }
  1377. void CFortScreen::draw( CCastleInterface * owner, bool first)
  1378. {
  1379. if(bg)
  1380. SDL_FreeSurface(bg);
  1381. char buf[20];
  1382. memset(buf,0,20);
  1383. SDL_Surface *bg2 = BitmapHandler::loadBitmap("TPCASTL7.bmp"),
  1384. *icons = BitmapHandler::loadBitmap("ZPCAINFO.bmp");
  1385. SDL_SetColorKey(icons,SDL_SRCCOLORKEY,SDL_MapRGB(icons->format,0,255,255));
  1386. graphics->blueToPlayersAdv(bg2,LOCPLINT->playerID);
  1387. bg = SDL_ConvertSurface(bg2,screen->format,0);
  1388. SDL_FreeSurface(bg2);
  1389. printAtMiddle(CGI->buildh->buildings[owner->town->subID][owner->town->fortLevel()+6]->Name(),400,13,GEORXX,zwykly,bg);
  1390. for(int i=0;i<CREATURES_PER_TOWN; i++)
  1391. {
  1392. bool upgraded = owner->town->creatureDwelling(i,true);
  1393. bool present = owner->town->creatureDwelling(i,false);
  1394. CCreature *c = &CGI->creh->creatures[upgraded ? owner->town->town->upgradedCreatures[i] : owner->town->town->basicCreatures[i]];
  1395. printAtMiddle(c->namePl,positions[i].x+79,positions[i].y+10,GEOR13,zwykly,bg); //cr. name
  1396. blitAt(owner->bicons->ourImages[30+i+upgraded*7].bitmap,positions[i].x+4,positions[i].y+21,bg); //dwelling pic
  1397. 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
  1398. if(present) //if creature is present print avail able quantity
  1399. {
  1400. SDL_itoa(owner->town->creatures[i].first,buf,10);
  1401. printAtMiddle(CGI->generaltexth->allTexts[217] + buf,positions[i].x+79,positions[i].y+118,GEOR13,zwykly,bg);
  1402. }
  1403. blitAt(icons,positions[i].x+261,positions[i].y+3,bg);
  1404. //attack
  1405. printAt(CGI->generaltexth->allTexts[190],positions[i].x+288,positions[i].y+5,GEOR13,zwykly,bg);
  1406. SDL_itoa(c->attack,buf,10);
  1407. printToWR(buf,positions[i].x+381,positions[i].y+18,GEOR13,zwykly,bg);
  1408. //defense
  1409. printAt(CGI->generaltexth->allTexts[191],positions[i].x+288,positions[i].y+25,GEOR13,zwykly,bg);
  1410. SDL_itoa(c->defence,buf,10);
  1411. printToWR(buf,positions[i].x+381,positions[i].y+38,GEOR13,zwykly,bg);
  1412. //damage
  1413. printAt(CGI->generaltexth->allTexts[199],positions[i].x+288,positions[i].y+46,GEOR13,zwykly,bg);
  1414. SDL_itoa(c->damageMin,buf,10);
  1415. int hlp;
  1416. if(c->damageMin > 0)
  1417. hlp = log10f(c->damageMin)+2;
  1418. else
  1419. hlp = 2;
  1420. buf[hlp-1]=' '; buf[hlp]='-'; buf[hlp+1]=' ';
  1421. SDL_itoa(c->damageMax,buf+hlp+2,10);
  1422. printToWR(buf,positions[i].x+381,positions[i].y+59,GEOR13,zwykly,bg);
  1423. //health
  1424. printAt(CGI->generaltexth->zelp[439].first,positions[i].x+288,positions[i].y+66,GEOR13,zwykly,bg);
  1425. SDL_itoa(c->hitPoints,buf,10);
  1426. printToWR(buf,positions[i].x+381,positions[i].y+79,GEOR13,zwykly,bg);
  1427. //speed
  1428. printAt(CGI->generaltexth->zelp[441].first,positions[i].x+288,positions[i].y+87,GEOR13,zwykly,bg);
  1429. SDL_itoa(c->speed,buf,10);
  1430. printToWR(buf,positions[i].x+381,positions[i].y+100,GEOR13,zwykly,bg);
  1431. if(present)//growth
  1432. {
  1433. printAt(CGI->generaltexth->allTexts[194],positions[i].x+288,positions[i].y+107,GEOR13,zwykly,bg);
  1434. SDL_itoa(owner->town->creatureGrowth(i),buf,10);
  1435. printToWR(buf,positions[i].x+381,positions[i].y+120,GEOR13,zwykly,bg);
  1436. }
  1437. if(first)
  1438. {
  1439. crePics.push_back(new CCreaturePic(c,false));
  1440. if(present)
  1441. {
  1442. recAreas.push_back(new RecArea(30+i+upgraded*7));
  1443. recAreas.back()->pos = positions[i] + pos;
  1444. }
  1445. }
  1446. }
  1447. SDL_FreeSurface(icons);
  1448. }
  1449. void CFortScreen::RecArea::clickLeft(tribool down, bool previousState)
  1450. {
  1451. if(!down && previousState)
  1452. {
  1453. LOCPLINT->castleInt->showRecruitmentWindow(bid);
  1454. }
  1455. //ClickableL::clickLeft(down);
  1456. }
  1457. void CFortScreen::RecArea::activate()
  1458. {
  1459. activateLClick();
  1460. activateRClick();
  1461. }
  1462. void CFortScreen::RecArea::deactivate()
  1463. {
  1464. deactivateLClick();
  1465. deactivateRClick();
  1466. }
  1467. void CFortScreen::RecArea::clickRight(tribool down, bool previousState)
  1468. {
  1469. clickLeft(down, false); //r-click does same as l-click - opens recr. window
  1470. }
  1471. CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner)
  1472. {
  1473. resdatabar = new CMinorResDataBar;
  1474. pos = owner->pos;
  1475. resdatabar->pos.x += pos.x;
  1476. resdatabar->pos.y += pos.y;
  1477. bg = BitmapHandler::loadBitmap("TPMAGE.bmp");
  1478. exit = new AdventureMapButton(CGI->generaltexth->tcommands[8],"",boost::bind(&CMageGuildScreen::close,this),pos.x+748,pos.y+556,"TPMAGE1.DEF",SDLK_RETURN);
  1479. exit->assignedKeys.insert(SDLK_ESCAPE);
  1480. scrolls2 = CDefHandler::giveDefEss("TPMAGES.DEF");
  1481. SDL_Surface *view = BitmapHandler::loadBitmap(graphics->guildBgs[owner->town->subID]);
  1482. SDL_SetColorKey(view,SDL_SRCCOLORKEY,SDL_MapRGB(view->format,0,255,255));
  1483. positions.resize(5);
  1484. 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);
  1485. 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);
  1486. positions[2] += genRect(61,83,570,82), genRect(61,83,672,82), genRect(61,83,570,157), genRect(61,83,672,157);
  1487. positions[3] += genRect(61,83,183,42), genRect(61,83,183,148), genRect(61,83,183,253);
  1488. positions[4] += genRect(61,83,491,325), genRect(61,83,591,325);
  1489. blitAt(view,332,76,bg);
  1490. for(size_t i=0; i<owner->town->town->mageLevel; i++)
  1491. {
  1492. size_t sp = owner->town->spellsAtLevel(i+1,false); //spell at level with -1 hmmm?
  1493. for(size_t j=0; j<sp; j++)
  1494. {
  1495. if(i<owner->town->mageGuildLevel() && owner->town->spells[i].size()>j)
  1496. {
  1497. spells.push_back(Scroll(&CGI->spellh->spells[owner->town->spells[i][j]]));
  1498. spells[spells.size()-1].pos = positions[i][j];
  1499. blitAt(graphics->spellscr->ourImages[owner->town->spells[i][j]].bitmap,positions[i][j],bg);
  1500. }
  1501. else
  1502. {
  1503. blitAt(scrolls2->ourImages[1].bitmap,positions[i][j],bg);
  1504. }
  1505. }
  1506. }
  1507. SDL_FreeSurface(view);
  1508. for(size_t i=0;i<spells.size();i++)
  1509. {
  1510. spells[i].pos.x += pos.x;
  1511. spells[i].pos.y += pos.y;
  1512. }
  1513. delete scrolls2;
  1514. }
  1515. CMageGuildScreen::~CMageGuildScreen()
  1516. {
  1517. delete exit;
  1518. SDL_FreeSurface(bg);
  1519. delete resdatabar;
  1520. }
  1521. void CMageGuildScreen::close()
  1522. {
  1523. GH.popIntTotally(this);
  1524. }
  1525. void CMageGuildScreen::show(SDL_Surface * to)
  1526. {
  1527. blitAt(bg,pos,to);
  1528. resdatabar->show(to);
  1529. LOCPLINT->statusbar->show(to);
  1530. exit->show(to);
  1531. }
  1532. void CMageGuildScreen::activate()
  1533. {
  1534. exit->activate();
  1535. for(size_t i=0;i<spells.size();i++)
  1536. {
  1537. spells[i].activate();
  1538. }
  1539. }
  1540. void CMageGuildScreen::deactivate()
  1541. {
  1542. exit->deactivate();
  1543. for(size_t i=0;i<spells.size();i++)
  1544. {
  1545. spells[i].deactivate();
  1546. }
  1547. }
  1548. void CMageGuildScreen::Scroll::clickLeft(tribool down, bool previousState)
  1549. {
  1550. if(down)
  1551. {
  1552. std::vector<SComponent*> comps(1,
  1553. new CCustomImgComponent(SComponent::spell,spell->id,0,graphics->spellscr->ourImages[spell->id].bitmap,false)
  1554. );
  1555. LOCPLINT->showInfoDialog(spell->descriptions[0],comps, soundBase::sound_todo);
  1556. }
  1557. }
  1558. void CMageGuildScreen::Scroll::clickRight(tribool down, bool previousState)
  1559. {
  1560. if(down)
  1561. {
  1562. CInfoPopup *vinya = new CInfoPopup();
  1563. vinya->free = true;
  1564. vinya->bitmap = CMessage::drawBoxTextBitmapSub
  1565. (LOCPLINT->playerID,
  1566. spell->descriptions[0],graphics->spellscr->ourImages[spell->id].bitmap,
  1567. spell->name,30,30);
  1568. vinya->pos.x = screen->w/2 - vinya->bitmap->w/2;
  1569. vinya->pos.y = screen->h/2 - vinya->bitmap->h/2;
  1570. GH.pushInt(vinya);
  1571. }
  1572. }
  1573. void CMageGuildScreen::Scroll::hover(bool on)
  1574. {
  1575. //Hoverable::hover(on);
  1576. if(on)
  1577. LOCPLINT->statusbar->print(spell->name);
  1578. else
  1579. LOCPLINT->statusbar->clear();
  1580. }
  1581. void CMageGuildScreen::Scroll::activate()
  1582. {
  1583. activateLClick();
  1584. activateRClick();
  1585. activateHover();
  1586. }
  1587. void CMageGuildScreen::Scroll::deactivate()
  1588. {
  1589. deactivateLClick();
  1590. deactivateRClick();
  1591. deactivateHover();
  1592. }
  1593. CBlacksmithDialog::CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid)
  1594. {
  1595. SDL_Surface *bg2 = BitmapHandler::loadBitmap("TPSMITH.bmp");
  1596. SDL_SetColorKey(bg2,SDL_SRCCOLORKEY,SDL_MapRGB(bg2->format,0,255,255));
  1597. graphics->blueToPlayersAdv(bg2,LOCPLINT->playerID);
  1598. bmp = SDL_ConvertSurface(bg2,screen->format,0);
  1599. SDL_FreeSurface(bg2);
  1600. bg2 = BitmapHandler::loadBitmap("TPSMITBK.bmp");
  1601. blitAt(bg2,64,50,bmp);
  1602. SDL_FreeSurface(bg2);
  1603. CCreatureAnimation cra(CGI->creh->creatures[creMachineID].animDefName);
  1604. cra.nextFrameMiddle(bmp,170,120,true,0,false);
  1605. char pom[75];
  1606. sprintf(pom,CGI->generaltexth->allTexts[274].c_str(),CGI->creh->creatures[creMachineID].nameSing.c_str()); //build a new ...
  1607. printAtMiddle(pom,165,28,GEORXX,tytulowy,bmp);
  1608. printAtMiddle(CGI->generaltexth->jktexts[43],165,218,GEOR16,zwykly,bmp); //resource cost
  1609. SDL_itoa(CGI->arth->artifacts[aid].price,pom,10);
  1610. printAtMiddle(pom,165,290,GEOR13,zwykly,bmp);
  1611. pos.w = bmp->w;
  1612. pos.h = bmp->h;
  1613. pos.x = screen->w/2 - pos.w/2;
  1614. pos.y = screen->h/2 - pos.h/2;
  1615. buy = new AdventureMapButton("","",boost::bind(&CBlacksmithDialog::close,this),pos.x + 42,pos.y + 312,"IBUY30.DEF",SDLK_RETURN);
  1616. cancel = new AdventureMapButton("","",boost::bind(&CBlacksmithDialog::close,this),pos.x + 224,pos.y + 312,"ICANCEL.DEF",SDLK_ESCAPE);
  1617. if(possible)
  1618. buy->callback += boost::bind(&CCallback::buyArtifact,LOCPLINT->cb,LOCPLINT->cb->getHeroInfo(hid,2),aid);
  1619. else
  1620. buy->bitmapOffset = 2;
  1621. blitAt(graphics->resources32->ourImages[6].bitmap,148,244,bmp);
  1622. }
  1623. void CBlacksmithDialog::show( SDL_Surface * to )
  1624. {
  1625. blitAt(bmp,pos,to);
  1626. buy->show(to);
  1627. cancel->show(to);
  1628. }
  1629. void CBlacksmithDialog::activate()
  1630. {
  1631. if(!buy->bitmapOffset)
  1632. buy->activate();
  1633. cancel->activate();
  1634. }
  1635. void CBlacksmithDialog::deactivate()
  1636. {
  1637. if(!buy->bitmapOffset)
  1638. buy->deactivate();
  1639. cancel->deactivate();
  1640. }
  1641. CBlacksmithDialog::~CBlacksmithDialog()
  1642. {
  1643. SDL_FreeSurface(bmp);
  1644. delete cancel;
  1645. delete buy;
  1646. }
  1647. void CBlacksmithDialog::close()
  1648. {
  1649. GH.popIntTotally(this);
  1650. }