CCastleInterface.cpp 48 KB

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