CCastleInterface.cpp 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746
  1. #include "StdInc.h"
  2. #include "CCastleInterface.h"
  3. #include "../CCallback.h"
  4. #include "../lib/CArtHandler.h"
  5. #include "../lib/CBuildingHandler.h"
  6. #include "../lib/CCreatureHandler.h"
  7. #include "../lib/CGeneralTextHandler.h"
  8. #include "../lib/CModHandler.h"
  9. #include "../lib/CObjectHandler.h"
  10. #include "../lib/CSpellHandler.h"
  11. #include "../lib/CTownHandler.h"
  12. #include "CAdvmapInterface.h"
  13. #include "CAnimation.h"
  14. #include "CBitmapHandler.h"
  15. #include "CDefHandler.h"
  16. #include "CGameInfo.h"
  17. #include "CHeroWindow.h"
  18. #include "CMessage.h"
  19. #include "CMusicHandler.h"
  20. #include "CPlayerInterface.h"
  21. #include "Graphics.h"
  22. #include "gui/SDL_Extensions.h"
  23. #include "../lib/GameConstants.h"
  24. #include "gui/CGuiHandler.h"
  25. #include "gui/CIntObjectClasses.h"
  26. using namespace boost::assign;
  27. /*
  28. * CCastleInterface.cpp, part of VCMI engine
  29. *
  30. * Authors: listed in file AUTHORS in main folder
  31. *
  32. * License: GNU General Public License v2.0 or later
  33. * Full text of license available in license.txt file, in main folder
  34. *
  35. */
  36. const CBuilding * CBuildingRect::getBuilding()
  37. {
  38. if (!str->building)
  39. return nullptr;
  40. if (str->hiddenUpgrade) // hidden upgrades, e.g. hordes - return base (dwelling for hordes)
  41. return town->town->buildings.at(str->building->getBase());
  42. return str->building;
  43. }
  44. CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance *Town, const CStructure *Str)
  45. :CShowableAnim(0, 0, Str->defName, CShowableAnim::BASE | CShowableAnim::USE_RLE),
  46. parent(Par),
  47. town(Town),
  48. str(Str),
  49. stateCounter(80)
  50. {
  51. recActions = ACTIVATE | DEACTIVATE | DISPOSE | SHARE_POS;
  52. addUsedEvents(LCLICK | RCLICK | HOVER);
  53. pos.x += str->pos.x;
  54. pos.y += str->pos.y;
  55. if (!str->borderName.empty())
  56. border = BitmapHandler::loadBitmap(str->borderName, true);
  57. else
  58. border = nullptr;
  59. if (!str->areaName.empty())
  60. area = BitmapHandler::loadBitmap(str->areaName);
  61. else
  62. area = nullptr;
  63. }
  64. CBuildingRect::~CBuildingRect()
  65. {
  66. SDL_FreeSurface(border);
  67. SDL_FreeSurface(area);
  68. }
  69. bool CBuildingRect::operator<(const CBuildingRect & p2) const
  70. {
  71. return (str->pos.z) < (p2.str->pos.z);
  72. }
  73. void CBuildingRect::hover(bool on)
  74. {
  75. if(on)
  76. {
  77. if(!(active & MOVE))
  78. addUsedEvents(MOVE);
  79. }
  80. else
  81. {
  82. if(active & MOVE)
  83. removeUsedEvents(MOVE);
  84. if(parent->selectedBuilding == this)
  85. {
  86. parent->selectedBuilding = nullptr;
  87. GH.statusbar->clear();
  88. }
  89. }
  90. }
  91. void CBuildingRect::clickLeft(tribool down, bool previousState)
  92. {
  93. if( previousState && !down && area && (parent->selectedBuilding==this) && getBuilding() )
  94. if (!CSDL_Ext::isTransparent(area, GH.current->motion.x-pos.x, GH.current->motion.y-pos.y) ) //inside building image
  95. parent->buildingClicked(getBuilding()->bid);
  96. }
  97. void CBuildingRect::clickRight(tribool down, bool previousState)
  98. {
  99. if((!area) || (!((bool)down)) || (this!=parent->selectedBuilding) || getBuilding() == nullptr)
  100. return;
  101. if( !CSDL_Ext::isTransparent(area, GH.current->motion.x-pos.x, GH.current->motion.y-pos.y) ) //inside building image
  102. {
  103. BuildingID bid = getBuilding()->bid;
  104. const CBuilding *bld = town->town->buildings.at(bid);
  105. if (bid < BuildingID::DWELL_FIRST)
  106. {
  107. CRClickPopup::createAndPush(CInfoWindow::genText(bld->Name(), bld->Description()),
  108. new CComponent(CComponent::building, bld->town->faction->index, bld->bid));
  109. }
  110. else
  111. {
  112. int level = ( bid - BuildingID::DWELL_FIRST ) % GameConstants::CREATURES_PER_TOWN;
  113. GH.pushInt(new CDwellingInfoBox(parent->pos.x+parent->pos.w/2, parent->pos.y+parent->pos.h/2, town, level));
  114. }
  115. }
  116. }
  117. SDL_Color multiplyColors (const SDL_Color &b, const SDL_Color &a, double f)
  118. {
  119. SDL_Color ret;
  120. ret.r = a.r*f + b.r*(1-f);
  121. ret.g = a.g*f + b.g*(1-f);
  122. ret.b = a.b*f + b.b*(1-f);
  123. return ret;
  124. }
  125. void CBuildingRect::show(SDL_Surface * to)
  126. {
  127. const ui32 stageDelay = 16;
  128. const ui32 S1_TRANSP = 16; //0.5 sec building appear 0->100 transparency
  129. const ui32 S2_WHITE_B = 32; //0.5 sec border glows from white to yellow
  130. const ui32 S3_YELLOW_B= 48; //0.5 sec border glows from yellow to normal
  131. const ui32 BUILDED = 80; // 1 sec delay, nothing happens
  132. if (stateCounter < S1_TRANSP)
  133. {
  134. setAlpha(255*stateCounter/stageDelay);
  135. CShowableAnim::show(to);
  136. }
  137. else
  138. {
  139. setAlpha(255);
  140. CShowableAnim::show(to);
  141. }
  142. if (border && stateCounter > S1_TRANSP)
  143. {
  144. if (stateCounter == BUILDED)
  145. {
  146. if (parent->selectedBuilding == this)
  147. blitAtLoc(border,0,0,to);
  148. return;
  149. }
  150. if (border->format->palette != nullptr)
  151. {
  152. // key colors in glowing border
  153. SDL_Color c1 = {200, 200, 200, 255};
  154. SDL_Color c2 = {120, 100, 60, 255};
  155. SDL_Color c3 = {200, 180, 110, 255};
  156. ui32 colorID = SDL_MapRGB(border->format, c3.r, c3.g, c3.b);
  157. SDL_Color oldColor = border->format->palette->colors[colorID];
  158. SDL_Color newColor;
  159. if (stateCounter < S2_WHITE_B)
  160. newColor = multiplyColors(c1, c2, static_cast<double>(stateCounter % stageDelay) / stageDelay);
  161. else
  162. if (stateCounter < S3_YELLOW_B)
  163. newColor = multiplyColors(c2, c3, static_cast<double>(stateCounter % stageDelay) / stageDelay);
  164. else
  165. newColor = oldColor;
  166. SDL_SetColors(border, &newColor, colorID, 1);
  167. blitAtLoc(border,0,0,to);
  168. SDL_SetColors(border, &oldColor, colorID, 1);
  169. }
  170. }
  171. if (stateCounter < BUILDED)
  172. stateCounter++;
  173. }
  174. void CBuildingRect::showAll(SDL_Surface * to)
  175. {
  176. if (stateCounter == 0)
  177. return;
  178. CShowableAnim::showAll(to);
  179. if(!active && parent->selectedBuilding == this && border)
  180. blitAtLoc(border,0,0,to);
  181. }
  182. std::string CBuildingRect::getSubtitle()//hover text for building
  183. {
  184. if (!getBuilding())
  185. return "";
  186. int bid = getBuilding()->bid;
  187. if (bid<30)//non-dwellings - only buiding name
  188. return town->town->buildings.at(getBuilding()->bid)->Name();
  189. else//dwellings - recruit %creature%
  190. {
  191. auto & availableCreatures = town->creatures[(bid-30)%GameConstants::CREATURES_PER_TOWN].second;
  192. if(availableCreatures.size())
  193. {
  194. int creaID = availableCreatures.back();//taking last of available creatures
  195. return CGI->generaltexth->allTexts[16] + " " + CGI->creh->creatures.at(creaID)->namePl;
  196. }
  197. else
  198. {
  199. logGlobal->warnStream() << "Problem: dwelling with id " << bid << " offers no creatures!";
  200. return "#ERROR#";
  201. }
  202. }
  203. }
  204. void CBuildingRect::mouseMoved (const SDL_MouseMotionEvent & sEvent)
  205. {
  206. if(area && isItIn(&pos,sEvent.x, sEvent.y))
  207. {
  208. if(CSDL_Ext::isTransparent(area, GH.current->motion.x-pos.x, GH.current->motion.y-pos.y)) //hovered pixel is inside this building
  209. {
  210. if(parent->selectedBuilding == this)
  211. {
  212. parent->selectedBuilding = nullptr;
  213. GH.statusbar->clear();
  214. }
  215. }
  216. else //inside the area of this building
  217. {
  218. if(! parent->selectedBuilding //no building hovered
  219. || (*parent->selectedBuilding)<(*this)) //or we are on top
  220. {
  221. parent->selectedBuilding = this;
  222. GH.statusbar->setText(getSubtitle());
  223. }
  224. }
  225. }
  226. }
  227. CDwellingInfoBox::CDwellingInfoBox(int centerX, int centerY, const CGTownInstance *Town, int level):
  228. CWindowObject(RCLICK_POPUP | PLAYER_COLORED, "CRTOINFO", Point(centerX, centerY))
  229. {
  230. OBJ_CONSTRUCTION_CAPTURING_ALL;
  231. const CCreature * creature = CGI->creh->creatures.at(Town->creatures.at(level).second.back());
  232. title = new CLabel(80, 30, FONT_SMALL, CENTER, Colors::WHITE, creature->namePl);
  233. animation = new CCreaturePic(30, 44, creature, true, true);
  234. std::string text = boost::lexical_cast<std::string>(Town->creatures.at(level).first);
  235. available = new CLabel(80,190, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[217] + text);
  236. costPerTroop = new CLabel(80, 227, FONT_SMALL, CENTER, Colors::WHITE, CGI->generaltexth->allTexts[346]);
  237. for(int i = 0; i<GameConstants::RESOURCE_QUANTITY; i++)
  238. {
  239. if(creature->cost[i])
  240. {
  241. resPicture.push_back(new CAnimImage("RESOURCE", i, 0, 0, 0));
  242. resAmount.push_back(new CLabel(0,0, FONT_SMALL, CENTER, Colors::WHITE, boost::lexical_cast<std::string>(creature->cost[i])));
  243. }
  244. }
  245. int posY = 238;
  246. int posX = pos.w/2 - resAmount.size() * 25 + 5;
  247. for (size_t i=0; i<resAmount.size(); i++)
  248. {
  249. resPicture[i]->moveBy(Point(posX, posY));
  250. resAmount[i]->moveBy(Point(posX+16, posY+43));
  251. posX += 50;
  252. }
  253. }
  254. void CHeroGSlot::hover (bool on)
  255. {
  256. if(!on)
  257. {
  258. GH.statusbar->clear();
  259. return;
  260. }
  261. CHeroGSlot *other = upg ? owner->garrisonedHero : owner->visitingHero;
  262. std::string temp;
  263. if(hero)
  264. {
  265. if(selection)//view NNN
  266. {
  267. temp = CGI->generaltexth->tcommands[4];
  268. boost::algorithm::replace_first(temp,"%s",hero->name);
  269. }
  270. else if(other->hero && other->selection)//exchange
  271. {
  272. temp = CGI->generaltexth->tcommands[7];
  273. boost::algorithm::replace_first(temp,"%s",hero->name);
  274. boost::algorithm::replace_first(temp,"%s",other->hero->name);
  275. }
  276. else// select NNN (in ZZZ)
  277. {
  278. if(upg)//down - visiting
  279. {
  280. temp = CGI->generaltexth->tcommands[32];
  281. boost::algorithm::replace_first(temp,"%s",hero->name);
  282. }
  283. else //up - garrison
  284. {
  285. temp = CGI->generaltexth->tcommands[12];
  286. boost::algorithm::replace_first(temp,"%s",hero->name);
  287. }
  288. }
  289. }
  290. else //we are empty slot
  291. {
  292. if(other->selection && other->hero) //move NNNN
  293. {
  294. temp = CGI->generaltexth->tcommands[6];
  295. boost::algorithm::replace_first(temp,"%s",other->hero->name);
  296. }
  297. else //empty
  298. {
  299. temp = CGI->generaltexth->allTexts[507];
  300. }
  301. }
  302. if(temp.size())
  303. GH.statusbar->setText(temp);
  304. }
  305. void CHeroGSlot::clickLeft(tribool down, bool previousState)
  306. {
  307. CHeroGSlot *other = upg ? owner->garrisonedHero : owner->visitingHero;
  308. if(!down)
  309. {
  310. owner->garr->setSplittingMode(false);
  311. owner->garr->selectSlot(nullptr);
  312. if(hero && selection)
  313. {
  314. setHighlight(false);
  315. LOCPLINT->openHeroWindow(hero);
  316. }
  317. else if(other->hero && other->selection)
  318. {
  319. bool allow = true;
  320. if(upg) //moving hero out of town - check if it is allowed
  321. {
  322. if(!hero && LOCPLINT->cb->howManyHeroes(false) >= VLC->modh->settings.MAX_HEROES_ON_MAP_PER_PLAYER)
  323. {
  324. std::string tmp = CGI->generaltexth->allTexts[18]; //You already have %d adventuring heroes under your command.
  325. boost::algorithm::replace_first(tmp,"%d",boost::lexical_cast<std::string>(LOCPLINT->cb->howManyHeroes(false)));
  326. LOCPLINT->showInfoDialog(tmp,std::vector<CComponent*>(), soundBase::sound_todo);
  327. allow = false;
  328. }
  329. else if(!other->hero->stacksCount()) //hero has no creatures - strange, but if we have appropriate error message...
  330. {
  331. LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[19],std::vector<CComponent*>(), soundBase::sound_todo); //This hero has no creatures. A hero must have creatures before he can brave the dangers of the countryside.
  332. allow = false;
  333. }
  334. }
  335. setHighlight(false);
  336. other->setHighlight(false);
  337. if(allow)
  338. owner->swapArmies();
  339. }
  340. else if(hero)
  341. {
  342. setHighlight(true);
  343. owner->garr->selectSlot(nullptr);
  344. showAll(screen2);
  345. }
  346. hover(false);hover(true); //refresh statusbar
  347. }
  348. }
  349. void CHeroGSlot::deactivate()
  350. {
  351. vstd::clear_pointer(selection);
  352. CIntObject::deactivate();
  353. }
  354. CHeroGSlot::CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h, HeroSlots * Owner)
  355. {
  356. owner = Owner;
  357. pos.x += x;
  358. pos.y += y;
  359. pos.w = 58;
  360. pos.h = 64;
  361. upg = updown;
  362. selection = nullptr;
  363. image = nullptr;
  364. set(h);
  365. addUsedEvents(LCLICK | HOVER);
  366. }
  367. CHeroGSlot::~CHeroGSlot()
  368. {
  369. }
  370. void CHeroGSlot::setHighlight( bool on )
  371. {
  372. OBJ_CONSTRUCTION_CAPTURING_ALL;
  373. vstd::clear_pointer(selection);
  374. if (on)
  375. selection = new CAnimImage("TWCRPORT", 1, 0);
  376. if(owner->garrisonedHero->hero && owner->visitingHero->hero) //two heroes in town
  377. {
  378. for(auto & elem : owner->garr->splitButtons) //splitting enabled when slot higlighted
  379. elem->block(!on);
  380. }
  381. }
  382. void CHeroGSlot::set(const CGHeroInstance *newHero)
  383. {
  384. OBJ_CONSTRUCTION_CAPTURING_ALL;
  385. if (image)
  386. delete image;
  387. hero = newHero;
  388. if (newHero)
  389. image = new CAnimImage("PortraitsLarge", newHero->portrait, 0, 0, 0);
  390. else if(!upg && owner->showEmpty) //up garrison
  391. image = new CAnimImage("CREST58", LOCPLINT->castleInt->town->getOwner().getNum(), 0, 0, 0);
  392. else
  393. image = nullptr;
  394. }
  395. template <class ptr>
  396. class SORTHELP
  397. {
  398. public:
  399. bool operator ()
  400. (const ptr *a ,
  401. const ptr *b)
  402. {
  403. return (*a)<(*b);
  404. }
  405. };
  406. SORTHELP<CBuildingRect> buildSorter;
  407. SORTHELP<CStructure> structSorter;
  408. CCastleBuildings::CCastleBuildings(const CGTownInstance* Town):
  409. town(Town),
  410. selectedBuilding(nullptr)
  411. {
  412. OBJ_CONSTRUCTION_CAPTURING_ALL;
  413. background = new CPicture(town->town->clientInfo.townBackground);
  414. pos.w = background->pos.w;
  415. pos.h = background->pos.h;
  416. recreate();
  417. }
  418. void CCastleBuildings::recreate()
  419. {
  420. selectedBuilding = nullptr;
  421. OBJ_CONSTRUCTION_CAPTURING_ALL;
  422. //clear existing buildings
  423. for(auto build : buildings)
  424. delete build;
  425. buildings.clear();
  426. groups.clear();
  427. //Generate buildings list
  428. auto buildingsCopy = town->builtBuildings;// a bit modified copy of built buildings
  429. if(vstd::contains(town->builtBuildings, BuildingID::SHIPYARD))
  430. {
  431. std::vector <const CGObjectInstance *> vobjs = LOCPLINT->cb->getVisitableObjs(town->bestLocation());
  432. //there is visitable obj at shipyard output tile and it's a boat or hero (on boat)
  433. if(!vobjs.empty() && (vobjs.front()->ID == Obj::BOAT || vobjs.front()->ID == Obj::HERO))
  434. {
  435. buildingsCopy.insert(BuildingID::SHIP);
  436. }
  437. }
  438. for(const CStructure * structure : town->town->clientInfo.structures)
  439. {
  440. if (!structure->building)
  441. {
  442. buildings.push_back(new CBuildingRect(this, town, structure));
  443. continue;
  444. }
  445. if (vstd::contains(buildingsCopy, structure->building->bid))
  446. {
  447. groups[structure->building->getBase()].push_back(structure);
  448. }
  449. }
  450. for(auto & entry : groups)
  451. {
  452. const CBuilding * build = town->town->buildings.at(entry.first);
  453. const CStructure * toAdd = *boost::max_element(entry.second, [=](const CStructure * a, const CStructure * b)
  454. {
  455. return build->getDistance(a->building->bid)
  456. < build->getDistance(b->building->bid);
  457. });
  458. buildings.push_back(new CBuildingRect(this, town, toAdd));
  459. }
  460. boost::sort(buildings, [] (const CBuildingRect * a, const CBuildingRect * b)
  461. {
  462. return *a < *b;
  463. });
  464. }
  465. CCastleBuildings::~CCastleBuildings()
  466. {
  467. }
  468. void CCastleBuildings::addBuilding(BuildingID building)
  469. {
  470. //FIXME: implement faster method without complete recreation of town
  471. BuildingID base = town->town->buildings.at(building)->getBase();
  472. recreate();
  473. auto & structures = groups.at(base);
  474. for(CBuildingRect * rect : buildings)
  475. {
  476. if (vstd::contains(structures, rect->str))
  477. {
  478. //reset animation
  479. if (structures.size() == 1)
  480. rect->stateCounter = 0; // transparency -> fully visible stage
  481. else
  482. rect->stateCounter = 16; // already in fully visible stage
  483. break;
  484. }
  485. }
  486. }
  487. void CCastleBuildings::removeBuilding(BuildingID building)
  488. {
  489. //FIXME: implement faster method without complete recreation of town
  490. recreate();
  491. }
  492. void CCastleBuildings::show(SDL_Surface * to)
  493. {
  494. CIntObject::show(to);
  495. for(CBuildingRect * str : buildings)
  496. str->show(to);
  497. }
  498. void CCastleBuildings::showAll(SDL_Surface * to)
  499. {
  500. CIntObject::showAll(to);
  501. for(CBuildingRect * str : buildings)
  502. str->showAll(to);
  503. }
  504. const CGHeroInstance* CCastleBuildings::getHero()
  505. {
  506. if (town->visitingHero)
  507. return town->visitingHero;
  508. if (town->garrisonHero)
  509. return town->garrisonHero;
  510. return nullptr;
  511. }
  512. void CCastleBuildings::buildingClicked(BuildingID building)
  513. {
  514. logGlobal->traceStream()<<"You've clicked on "<<building;
  515. const CBuilding *b = town->town->buildings.find(building)->second;
  516. if(building >= BuildingID::DWELL_FIRST)
  517. {
  518. enterDwelling((building-BuildingID::DWELL_FIRST)%GameConstants::CREATURES_PER_TOWN);
  519. }
  520. else
  521. {
  522. switch(building)
  523. {
  524. case BuildingID::MAGES_GUILD_1:
  525. case BuildingID::MAGES_GUILD_2:
  526. case BuildingID::MAGES_GUILD_3:
  527. case BuildingID::MAGES_GUILD_4:
  528. case BuildingID::MAGES_GUILD_5:
  529. enterMagesGuild();
  530. break;
  531. case BuildingID::TAVERN:
  532. LOCPLINT->showTavernWindow(town);
  533. break;
  534. case BuildingID::SHIPYARD:
  535. if(town->shipyardStatus() == IBoatGenerator::GOOD)
  536. LOCPLINT->showShipyardDialog(town);
  537. break;
  538. case BuildingID::FORT:
  539. case BuildingID::CITADEL:
  540. case BuildingID::CASTLE:
  541. GH.pushInt(new CFortScreen(town));
  542. break;
  543. case BuildingID::VILLAGE_HALL:
  544. case BuildingID::CITY_HALL:
  545. case BuildingID::TOWN_HALL:
  546. case BuildingID::CAPITOL:
  547. enterTownHall();
  548. break;
  549. case BuildingID::MARKETPLACE:
  550. GH.pushInt(new CMarketplaceWindow(town, town->visitingHero));
  551. break;
  552. case BuildingID::BLACKSMITH:
  553. enterBlacksmith(town->town->warMachine);
  554. break;
  555. case BuildingID::SPECIAL_1:
  556. switch(town->subID)
  557. {
  558. case ETownType::RAMPART://Mystic Pond
  559. enterFountain(building);
  560. break;
  561. case ETownType::TOWER:
  562. case ETownType::DUNGEON://Artifact Merchant
  563. case ETownType::CONFLUX:
  564. if(town->visitingHero)
  565. GH.pushInt(new CMarketplaceWindow(town, town->visitingHero, EMarketMode::RESOURCE_ARTIFACT));
  566. else
  567. LOCPLINT->showInfoDialog(boost::str(boost::format(CGI->generaltexth->allTexts[273]) % b->Name())); //Only visiting heroes may use the %s.
  568. break;
  569. default:
  570. enterBuilding(building);
  571. break;
  572. }
  573. break;
  574. case BuildingID::SHIP:
  575. LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[51]); //Cannot build another boat
  576. break;
  577. case BuildingID::SPECIAL_2:
  578. switch(town->subID)
  579. {
  580. case ETownType::RAMPART: //Fountain of Fortune
  581. enterFountain(building);
  582. break;
  583. case ETownType::STRONGHOLD: //Freelancer's Guild
  584. if(getHero())
  585. GH.pushInt(new CMarketplaceWindow(town, getHero(), EMarketMode::CREATURE_RESOURCE));
  586. else
  587. LOCPLINT->showInfoDialog(boost::str(boost::format(CGI->generaltexth->allTexts[273]) % b->Name())); //Only visiting heroes may use the %s.
  588. break;
  589. case ETownType::CONFLUX: //Magic University
  590. if (getHero())
  591. GH.pushInt(new CUniversityWindow(getHero(), town));
  592. else
  593. enterBuilding(building);
  594. break;
  595. default:
  596. enterBuilding(building);
  597. break;
  598. }
  599. break;
  600. case BuildingID::SPECIAL_3:
  601. switch(town->subID)
  602. {
  603. case ETownType::CASTLE: //Brotherhood of sword
  604. LOCPLINT->showTavernWindow(town);
  605. break;
  606. case ETownType::INFERNO: //Castle Gate
  607. enterCastleGate();
  608. break;
  609. case ETownType::NECROPOLIS: //Skeleton Transformer
  610. GH.pushInt( new CTransformerWindow(getHero(), town) );
  611. break;
  612. case ETownType::DUNGEON: //Portal of Summoning
  613. if (town->creatures[GameConstants::CREATURES_PER_TOWN].second.empty())//No creatures
  614. LOCPLINT->showInfoDialog(CGI->generaltexth->tcommands[30]);
  615. else
  616. enterDwelling(GameConstants::CREATURES_PER_TOWN);
  617. break;
  618. case ETownType::STRONGHOLD: //Ballista Yard
  619. enterBlacksmith(ArtifactID::BALLISTA);
  620. break;
  621. default:
  622. enterBuilding(building);
  623. break;
  624. }
  625. break;
  626. default:
  627. enterBuilding(building);
  628. break;
  629. }
  630. }
  631. }
  632. void CCastleBuildings::enterBlacksmith(ArtifactID artifactID)
  633. {
  634. const CGHeroInstance *hero = town->visitingHero;
  635. if(!hero)
  636. {
  637. LOCPLINT->showInfoDialog(boost::str(boost::format(CGI->generaltexth->allTexts[273]) % town->town->buildings.find(BuildingID::BLACKSMITH)->second->Name()));
  638. return;
  639. }
  640. int price = CGI->arth->artifacts[artifactID]->price;
  641. bool possible = LOCPLINT->cb->getResourceAmount(Res::GOLD) >= price && !hero->hasArt(artifactID);
  642. GH.pushInt(new CBlacksmithDialog(possible, CArtHandler::machineIDToCreature(artifactID), artifactID, hero->id));
  643. }
  644. void CCastleBuildings::enterBuilding(BuildingID building)
  645. {
  646. std::vector<CComponent*> comps(1, new CComponent(CComponent::building, town->subID, building));
  647. LOCPLINT->showInfoDialog(
  648. town->town->buildings.find(building)->second->Description(),comps);
  649. }
  650. void CCastleBuildings::enterCastleGate()
  651. {
  652. if (!town->visitingHero)
  653. {
  654. LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[126]);
  655. return;//only visiting hero can use castle gates
  656. }
  657. std::vector <int> availableTowns;
  658. std::vector <const CGTownInstance*> Towns = LOCPLINT->cb->getTownsInfo(false);
  659. for(auto & Town : Towns)
  660. {
  661. const CGTownInstance *t = Town;
  662. if (t->id != this->town->id && t->visitingHero == nullptr && //another town, empty and this is
  663. t->hasBuilt(BuildingID::CASTLE_GATE, ETownType::INFERNO))
  664. {
  665. availableTowns.push_back(t->id.getNum());//add to the list
  666. }
  667. }
  668. auto titlePic = new CPicture (LOCPLINT->castleInt->bicons->ourImages[BuildingID::CASTLE_GATE].bitmap, 0,0, false);//will be deleted by selection window
  669. GH.pushInt (new CObjectListWindow(availableTowns, titlePic, CGI->generaltexth->jktexts[40],
  670. CGI->generaltexth->jktexts[41], boost::bind (&CCastleInterface::castleTeleport, LOCPLINT->castleInt, _1)));
  671. }
  672. void CCastleBuildings::enterDwelling(int level)
  673. {
  674. assert(level >= 0 && level < town->creatures.size());
  675. auto recruitCb = [=](CreatureID id, int count){ LOCPLINT->cb->recruitCreatures(town, id, count, level); };
  676. GH.pushInt(new CRecruitmentWindow(town, level, town, recruitCb, -87));
  677. }
  678. void CCastleBuildings::enterFountain(BuildingID building)
  679. {
  680. std::vector<CComponent*> comps(1, new CComponent(CComponent::building,town->subID,building));
  681. std::string descr = town->town->buildings.find(building)->second->Description();
  682. if ( building == BuildingID::FOUNTAIN_OF_FORTUNE)
  683. descr += "\n\n"+town->town->buildings.find(BuildingID::MYSTIC_POND)->second->Description();
  684. if (town->bonusValue.first == 0)//fountain was builded this week
  685. descr += "\n\n"+ CGI->generaltexth->allTexts[677];
  686. else//fountain produced something;
  687. {
  688. descr+= "\n\n"+ CGI->generaltexth->allTexts[678];
  689. boost::algorithm::replace_first(descr,"%s",CGI->generaltexth->restypes[town->bonusValue.first]);
  690. boost::algorithm::replace_first(descr,"%d",boost::lexical_cast<std::string>(town->bonusValue.second));
  691. }
  692. LOCPLINT->showInfoDialog(descr, comps);
  693. }
  694. void CCastleBuildings::enterMagesGuild()
  695. {
  696. const CGHeroInstance *hero = getHero();
  697. if(hero && !hero->hasSpellbook()) //hero doesn't have spellbok
  698. {
  699. if(LOCPLINT->cb->getResourceAmount(Res::GOLD) < 500) //not enough gold to buy spellbook
  700. {
  701. openMagesGuild();
  702. LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[213]);
  703. }
  704. else
  705. {
  706. CFunctionList<void()> onYes = [this]{ openMagesGuild(); };
  707. CFunctionList<void()> onNo = onYes;
  708. onYes += [hero]{ LOCPLINT->cb->buyArtifact(hero, ArtifactID::SPELLBOOK); };
  709. std::vector<CComponent*> components(1, new CComponent(CComponent::artifact,0,0));
  710. LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[214], onYes, onNo, true, components);
  711. }
  712. }
  713. else
  714. {
  715. openMagesGuild();
  716. }
  717. }
  718. void CCastleBuildings::enterTownHall()
  719. {
  720. if(town->visitingHero && town->visitingHero->hasArt(2) &&
  721. !vstd::contains(town->builtBuildings, BuildingID::GRAIL)) //hero has grail, but town does not have it
  722. {
  723. if(!vstd::contains(town->forbiddenBuildings, BuildingID::GRAIL))
  724. {
  725. LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[597], //Do you wish this to be the permanent home of the Grail?
  726. [&]{ LOCPLINT->cb->buildBuilding(town, BuildingID::GRAIL); },
  727. [&]{ openTownHall(); },
  728. true);
  729. }
  730. else
  731. {
  732. LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[673]);
  733. (dynamic_cast<CInfoWindow*>(GH.topInt()))->buttons[0]->callback += boost::bind(&CCastleBuildings::openTownHall, this);
  734. }
  735. }
  736. else
  737. {
  738. openTownHall();
  739. }
  740. }
  741. void CCastleBuildings::openMagesGuild()
  742. {
  743. std::string mageGuildBackground;
  744. mageGuildBackground = LOCPLINT->castleInt->town->town->clientInfo.guildBackground;
  745. GH.pushInt(new CMageGuildScreen(LOCPLINT->castleInt,mageGuildBackground));
  746. }
  747. void CCastleBuildings::openTownHall()
  748. {
  749. GH.pushInt(new CHallInterface(town));
  750. }
  751. CCastleInterface::CCastleInterface(const CGTownInstance * Town, const CGTownInstance * from):
  752. CWindowObject(PLAYER_COLORED | BORDERED),
  753. hall(nullptr),
  754. fort(nullptr),
  755. town(Town)
  756. {
  757. OBJ_CONSTRUCTION_CAPTURING_ALL;
  758. LOCPLINT->castleInt = this;
  759. addUsedEvents(KEYBOARD);
  760. builds = new CCastleBuildings(town);
  761. panel = new CPicture("TOWNSCRN", 0, builds->pos.h);
  762. panel->colorize(LOCPLINT->playerID);
  763. pos.w = panel->pos.w;
  764. pos.h = builds->pos.h + panel->pos.h;
  765. center();
  766. updateShadow();
  767. garr = new CGarrisonInt(305, 387, 4, Point(0,96), panel->bg, Point(62,374), town->getUpperArmy(), town->visitingHero);
  768. heroes = new HeroSlots(town, Point(241, 387), Point(241, 483), garr, true);
  769. title = new CLabel(85, 387, FONT_MEDIUM, TOPLEFT, Colors::WHITE, town->name);
  770. income = new CLabel(195, 443, FONT_SMALL, CENTER);
  771. icon = new CAnimImage("ITPT", 0, 0, 15, 387);
  772. exit = new CAdventureMapButton(CGI->generaltexth->tcommands[8], "", boost::bind(&CCastleInterface::close,this), 744, 544, "TSBTNS", SDLK_RETURN);
  773. exit->assignedKeys.insert(SDLK_ESCAPE);
  774. exit->setOffset(4);
  775. split = new CAdventureMapButton(CGI->generaltexth->tcommands[3], "", boost::bind(&CGarrisonInt::splitClick,garr), 744, 382, "TSBTNS.DEF");
  776. split->callback += boost::bind(&HeroSlots::splitClicked, heroes);
  777. garr->addSplitBtn(split);
  778. Rect barRect(9, 182, 732, 18);
  779. statusbar = new CGStatusBar(new CPicture(*panel, barRect, 9, 555, false));
  780. resdatabar = new CResDataBar("ARESBAR", 3, 575, 32, 2, 85, 85);
  781. townlist = new CTownList(3, Point(744, 414), "IAM014", "IAM015");
  782. if (from)
  783. townlist->select(from);
  784. townlist->select(town); //this will scroll list to select current town
  785. townlist->onSelect = boost::bind(&CCastleInterface::townChange, this);
  786. recreateIcons();
  787. CCS->musich->playMusic(town->town->clientInfo.musicTheme, true);
  788. bicons = CDefHandler::giveDefEss(town->town->clientInfo.buildingsIcons);
  789. }
  790. CCastleInterface::~CCastleInterface()
  791. {
  792. LOCPLINT->castleInt = nullptr;
  793. delete bicons;
  794. }
  795. void CCastleInterface::close()
  796. {
  797. if(town->tempOwner == LOCPLINT->playerID) //we may have opened window for an allied town
  798. {
  799. if(town->visitingHero && town->visitingHero->tempOwner == LOCPLINT->playerID)
  800. adventureInt->select(town->visitingHero);
  801. else
  802. adventureInt->select(town);
  803. }
  804. CWindowObject::close();
  805. }
  806. void CCastleInterface::castleTeleport(int where)
  807. {
  808. const CGTownInstance * dest = LOCPLINT->cb->getTown(ObjectInstanceID(where));
  809. LOCPLINT->cb->teleportHero(town->visitingHero, dest);
  810. LOCPLINT->eraseCurrentPathOf(town->visitingHero, false);
  811. }
  812. void CCastleInterface::townChange()
  813. {
  814. const CGTownInstance * dest = LOCPLINT->towns[townlist->getSelectedIndex()];
  815. const CGTownInstance * town = this->town;// "this" is going to be deleted
  816. if ( dest == town )
  817. return;
  818. close();
  819. GH.pushInt(new CCastleInterface(dest, town));
  820. }
  821. void CCastleInterface::addBuilding(BuildingID bid)
  822. {
  823. deactivate();
  824. builds->addBuilding(bid);
  825. recreateIcons();
  826. activate();
  827. }
  828. void CCastleInterface::removeBuilding(BuildingID bid)
  829. {
  830. deactivate();
  831. builds->removeBuilding(bid);
  832. recreateIcons();
  833. activate();
  834. }
  835. void CCastleInterface::recreateIcons()
  836. {
  837. OBJ_CONSTRUCTION_CAPTURING_ALL;
  838. delete fort;
  839. delete hall;
  840. size_t iconIndex = town->town->clientInfo.icons[town->hasFort()][town->builded >= CGI->modh->settings.MAX_BUILDING_PER_TURN];
  841. icon->setFrame(iconIndex);
  842. TResources townIncome = town->dailyIncome();
  843. income->setText(boost::lexical_cast<std::string>(townIncome[Res::GOLD]));
  844. hall = new CTownInfo( 80, 413, town, true);
  845. fort = new CTownInfo(122, 413, town, false);
  846. for (auto & elem : creainfo)
  847. delete elem;
  848. creainfo.clear();
  849. for (size_t i=0; i<4; i++)
  850. creainfo.push_back(new CCreaInfo(Point(14+55*i, 459), town, i));
  851. for (size_t i=0; i<4; i++)
  852. creainfo.push_back(new CCreaInfo(Point(14+55*i, 507), town, i+4));
  853. }
  854. CCreaInfo::CCreaInfo(Point position, const CGTownInstance *Town, int Level, bool compact, bool ShowAvailable):
  855. town(Town),
  856. level(Level),
  857. showAvailable(ShowAvailable)
  858. {
  859. OBJ_CONSTRUCTION_CAPTURING_ALL;
  860. pos += position;
  861. if ( town->creatures.size() <= level || town->creatures[level].second.empty())
  862. {
  863. level = -1;
  864. label = nullptr;
  865. picture = nullptr;
  866. return;//No creature
  867. }
  868. addUsedEvents(LCLICK | RCLICK | HOVER);
  869. ui32 creatureID = town->creatures[level].second.back();
  870. creature = CGI->creh->creatures[creatureID];
  871. picture = new CAnimImage("CPRSMALL", creature->iconIndex, 0, 8, 0);
  872. std::string value;
  873. if (showAvailable)
  874. value = boost::lexical_cast<std::string>(town->creatures[level].first);
  875. else
  876. value = boost::lexical_cast<std::string>(town->creatureGrowth(level));
  877. if (compact)
  878. {
  879. label = new CLabel(40, 32, FONT_TINY, BOTTOMRIGHT, Colors::WHITE, value);
  880. pos.x += 8;
  881. pos.w = 32;
  882. pos.h = 32;
  883. }
  884. else
  885. {
  886. label = new CLabel(24, 40, FONT_SMALL, CENTER, Colors::WHITE, value);
  887. pos.w = 48;
  888. pos.h = 48;
  889. }
  890. }
  891. void CCreaInfo::update()
  892. {
  893. if (label)
  894. {
  895. std::string value;
  896. if (showAvailable)
  897. value = boost::lexical_cast<std::string>(town->creatures[level].first);
  898. else
  899. value = boost::lexical_cast<std::string>(town->creatureGrowth(level));
  900. if (value != label->text)
  901. label->setText(value);
  902. }
  903. }
  904. void CCreaInfo::hover(bool on)
  905. {
  906. std::string message = CGI->generaltexth->allTexts[588];
  907. boost::algorithm::replace_first(message,"%s",creature->namePl);
  908. if(on)
  909. {
  910. GH.statusbar->setText(message);
  911. }
  912. else if (message == GH.statusbar->getText())
  913. GH.statusbar->clear();
  914. }
  915. void CCreaInfo::clickLeft(tribool down, bool previousState)
  916. {
  917. if(previousState && (!down))
  918. {
  919. int offset = LOCPLINT->castleInt? (-87) : 0;
  920. auto recruitCb = [=](CreatureID id, int count) { LOCPLINT->cb->recruitCreatures(town, id, count, level); };
  921. GH.pushInt(new CRecruitmentWindow(town, level, town, recruitCb, offset));
  922. }
  923. }
  924. int CCreaInfo::AddToString(std::string from, std::string & to, int numb)
  925. {
  926. if (numb == 0)
  927. return 0;
  928. boost::algorithm::replace_first(from,"%+d", (numb > 0 ? "+" : "")+boost::lexical_cast<std::string>(numb)); //negative values don't need "+"
  929. to+="\n"+from;
  930. return numb;
  931. }
  932. std::string CCreaInfo::genGrowthText()
  933. {
  934. GrowthInfo gi = town->getGrowthInfo(level);
  935. std::string descr = boost::str(boost::format(CGI->generaltexth->allTexts[589]) % creature->nameSing % gi.totalGrowth());
  936. for(const GrowthInfo::Entry &entry : gi.entries)
  937. {
  938. descr +="\n" + entry.description;
  939. }
  940. return descr;
  941. }
  942. void CCreaInfo::clickRight(tribool down, bool previousState)
  943. {
  944. if(down)
  945. {
  946. if (showAvailable)
  947. GH.pushInt(new CDwellingInfoBox(screen->w/2, screen->h/2, town, level));
  948. else
  949. CRClickPopup::createAndPush(genGrowthText(), new CComponent(CComponent::creature, creature->idNumber));
  950. }
  951. }
  952. CTownInfo::CTownInfo(int posX, int posY, const CGTownInstance* Town, bool townHall):
  953. town(Town),
  954. building(nullptr)
  955. {
  956. OBJ_CONSTRUCTION_CAPTURING_ALL;
  957. addUsedEvents(RCLICK | HOVER);
  958. pos.x += posX;
  959. pos.y += posY;
  960. int buildID;
  961. if (townHall)
  962. {
  963. buildID = 10 + town->hallLevel();
  964. picture = new CAnimImage("ITMTL.DEF", town->hallLevel());
  965. }
  966. else
  967. {
  968. buildID = 6 + town->fortLevel();
  969. if (buildID == 6)
  970. return;
  971. picture = new CAnimImage("ITMCL.DEF", town->fortLevel()-1);
  972. }
  973. building = town->town->buildings.at(BuildingID(buildID));
  974. pos = picture->pos;
  975. }
  976. void CTownInfo::hover(bool on)
  977. {
  978. if(on)
  979. {
  980. if ( building )
  981. GH.statusbar->setText(building->Name());
  982. }
  983. else
  984. GH.statusbar->clear();
  985. }
  986. void CTownInfo::clickRight(tribool down, bool previousState)
  987. {
  988. if(down && building)
  989. CRClickPopup::createAndPush(CInfoWindow::genText(building->Name(), building->Description()),
  990. new CComponent(CComponent::building, building->town->faction->index, building->bid));
  991. }
  992. void CCastleInterface::keyPressed( const SDL_KeyboardEvent & key )
  993. {
  994. if(key.state != SDL_PRESSED) return;
  995. switch(key.keysym.sym)
  996. {
  997. #if 0 // code that can be used to fix blit order in towns using +/- keys. Quite ugly but works
  998. case SDLK_KP_PLUS :
  999. if (builds->selectedBuilding)
  1000. {
  1001. OBJ_CONSTRUCTION_CAPTURING_ALL;
  1002. CStructure * str = const_cast<CStructure *>(builds->selectedBuilding->str);
  1003. str->pos.z++;
  1004. delete builds;
  1005. builds = new CCastleBuildings(town);
  1006. for(const CStructure * str : town->town->clientInfo.structures)
  1007. {
  1008. if (str->building)
  1009. logGlobal->errorStream() << int(str->building->bid) << " -> " << int(str->pos.z);
  1010. }
  1011. }
  1012. break;
  1013. case SDLK_KP_MINUS:
  1014. if (builds->selectedBuilding)
  1015. {
  1016. OBJ_CONSTRUCTION_CAPTURING_ALL;
  1017. CStructure * str = const_cast<CStructure *>(builds->selectedBuilding->str);
  1018. str->pos.z--;
  1019. delete builds;
  1020. builds = new CCastleBuildings(town);
  1021. for(const CStructure * str : town->town->clientInfo.structures)
  1022. {
  1023. if (str->building)
  1024. logGlobal->errorStream() << int(str->building->bid) << " -> " << int(str->pos.z);
  1025. }
  1026. }
  1027. break;
  1028. #endif
  1029. case SDLK_UP:
  1030. townlist->selectPrev();
  1031. break;
  1032. case SDLK_DOWN:
  1033. townlist->selectNext();
  1034. break;
  1035. case SDLK_SPACE:
  1036. heroes->swapArmies();
  1037. break;
  1038. case SDLK_t:
  1039. if(town->hasBuilt(BuildingID::TAVERN))
  1040. LOCPLINT->showTavernWindow(town);
  1041. break;
  1042. default:
  1043. break;
  1044. }
  1045. }
  1046. HeroSlots::HeroSlots(const CGTownInstance * Town, Point garrPos, Point visitPos, CGarrisonInt *Garrison, bool ShowEmpty):
  1047. showEmpty(ShowEmpty),
  1048. town(Town),
  1049. garr(Garrison)
  1050. {
  1051. OBJ_CONSTRUCTION_CAPTURING_ALL;
  1052. garrisonedHero = new CHeroGSlot(garrPos.x, garrPos.y, 0, town->garrisonHero, this);
  1053. visitingHero = new CHeroGSlot(visitPos.x, visitPos.y, 1, town->visitingHero, this);
  1054. }
  1055. void HeroSlots::update()
  1056. {
  1057. garrisonedHero->set(town->garrisonHero);
  1058. visitingHero->set(town->visitingHero);
  1059. }
  1060. void HeroSlots::splitClicked()
  1061. {
  1062. if(!!town->visitingHero && town->garrisonHero && (visitingHero->selection || garrisonedHero->selection))
  1063. {
  1064. LOCPLINT->heroExchangeStarted(town->visitingHero->id, town->garrisonHero->id, QueryID(-1));
  1065. }
  1066. }
  1067. void HeroSlots::swapArmies()
  1068. {
  1069. if(!town->garrisonHero && town->visitingHero) //visiting => garrison, merge armies: town army => hero army
  1070. {
  1071. if(!town->visitingHero->canBeMergedWith(*town))
  1072. {
  1073. LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[275], std::vector<CComponent*>(), soundBase::sound_todo);
  1074. return;
  1075. }
  1076. }
  1077. LOCPLINT->cb->swapGarrisonHero(town);
  1078. }
  1079. void CHallInterface::CBuildingBox::hover(bool on)
  1080. {
  1081. if(on)
  1082. {
  1083. std::string toPrint;
  1084. if(state==EBuildingState::PREREQUIRES || state == EBuildingState::MISSING_BASE)
  1085. toPrint = CGI->generaltexth->hcommands[5];
  1086. else if(state==EBuildingState::CANT_BUILD_TODAY)
  1087. toPrint = CGI->generaltexth->allTexts[223];
  1088. else
  1089. toPrint = CGI->generaltexth->hcommands[state];
  1090. boost::algorithm::replace_first(toPrint,"%s",building->Name());
  1091. GH.statusbar->setText(toPrint);
  1092. }
  1093. else
  1094. GH.statusbar->clear();
  1095. }
  1096. void CHallInterface::CBuildingBox::clickLeft(tribool down, bool previousState)
  1097. {
  1098. if(previousState && (!down))
  1099. GH.pushInt(new CBuildWindow(town,building,state,0));
  1100. }
  1101. void CHallInterface::CBuildingBox::clickRight(tribool down, bool previousState)
  1102. {
  1103. if(down)
  1104. GH.pushInt(new CBuildWindow(town,building,state,1));
  1105. }
  1106. CHallInterface::CBuildingBox::CBuildingBox(int x, int y, const CGTownInstance * Town, const CBuilding * Building):
  1107. town(Town),
  1108. building(Building)
  1109. {
  1110. OBJ_CONSTRUCTION_CAPTURING_ALL;
  1111. addUsedEvents(LCLICK | RCLICK | HOVER);
  1112. pos.x += x;
  1113. pos.y += y;
  1114. pos.w = 154;
  1115. pos.h = 92;
  1116. state = LOCPLINT->cb->canBuildStructure(town,building->bid);
  1117. assert(state < EBuildingState::BUILDING_ERROR);
  1118. static int panelIndex[10] = { 3, 3, 3, 0, 0, 2, 2, 1, 2, 2};
  1119. static int iconIndex[10] = {-1, -1, -1, 0, 0, 1, 2, -1, 1, 1};
  1120. picture = new CAnimImage(town->town->clientInfo.buildingsIcons, building->bid, 0, 2, 2);
  1121. panel = new CAnimImage("TPTHBAR", panelIndex[state], 0, 1, 73);
  1122. if ( iconIndex[state] >=0 )
  1123. icon = new CAnimImage("TPTHCHK", iconIndex[state], 0, 136, 56);
  1124. label = new CLabel(75, 81, FONT_SMALL, CENTER, Colors::WHITE, building->Name());
  1125. }
  1126. CHallInterface::CHallInterface(const CGTownInstance *Town):
  1127. CWindowObject(PLAYER_COLORED | BORDERED, Town->town->clientInfo.hallBackground),
  1128. town(Town)
  1129. {
  1130. OBJ_CONSTRUCTION_CAPTURING_ALL;
  1131. resdatabar = new CMinorResDataBar;
  1132. resdatabar->pos.x += pos.x;
  1133. resdatabar->pos.y += pos.y;
  1134. Rect barRect(5, 556, 740, 18);
  1135. statusBar = new CGStatusBar(new CPicture(*background, barRect, 5, 556, false));
  1136. title = new CLabel(399, 12, FONT_MEDIUM, CENTER, Colors::WHITE, town->town->buildings.at(BuildingID(town->hallLevel()+BuildingID::VILLAGE_HALL))->Name());
  1137. exit = new CAdventureMapButton(CGI->generaltexth->hcommands[8], "",
  1138. boost::bind(&CHallInterface::close,this), 748, 556, "TPMAGE1.DEF", SDLK_RETURN);
  1139. exit->assignedKeys.insert(SDLK_ESCAPE);
  1140. auto & boxList = town->town->clientInfo.hallSlots;
  1141. boxes.resize(boxList.size());
  1142. for(size_t row=0; row<boxList.size(); row++) //for each row
  1143. {
  1144. for(size_t col=0; col<boxList[row].size(); col++) //for each box
  1145. {
  1146. const CBuilding *building = nullptr;
  1147. for(auto & elem : boxList[row][col])//we are looking for the first not build structure
  1148. {
  1149. auto buildingID = elem;
  1150. building = town->town->buildings.at(buildingID);
  1151. if(!vstd::contains(town->builtBuildings,buildingID))
  1152. break;
  1153. }
  1154. int posX = pos.w/2 - boxList[row].size()*154/2 - (boxList[row].size()-1)*20 + 194*col,
  1155. posY = 35 + 104*row;
  1156. if (building)
  1157. boxes[row].push_back(new CBuildingBox(posX, posY, town, building));
  1158. }
  1159. }
  1160. }
  1161. void CBuildWindow::buyFunc()
  1162. {
  1163. LOCPLINT->cb->buildBuilding(town,building->bid);
  1164. GH.popInts(2); //we - build window and hall screen
  1165. }
  1166. std::string CBuildWindow::getTextForState(int state)
  1167. {
  1168. std::string ret;
  1169. if(state < EBuildingState::ALLOWED)
  1170. ret = CGI->generaltexth->hcommands[state];
  1171. switch (state)
  1172. {
  1173. case EBuildingState::ALREADY_PRESENT:
  1174. case EBuildingState::CANT_BUILD_TODAY:
  1175. case EBuildingState::NO_RESOURCES:
  1176. ret.replace(ret.find_first_of("%s"), 2, building->Name());
  1177. break;
  1178. case EBuildingState::ALLOWED:
  1179. return CGI->generaltexth->allTexts[219]; //all prereq. are met
  1180. case EBuildingState::PREREQUIRES:
  1181. {
  1182. auto toStr = [&](const BuildingID build) -> std::string
  1183. {
  1184. return town->town->buildings.at(build)->Name();
  1185. };
  1186. /*auto toBool = [&](const BuildingID build)
  1187. {
  1188. return town->hasBuilt(build);
  1189. };*/
  1190. ret = CGI->generaltexth->allTexts[52];
  1191. ret += "\n" + building->requirements.toString(toStr);
  1192. break;
  1193. }
  1194. case EBuildingState::MISSING_BASE:
  1195. {
  1196. std::string msg = CGI->generaltexth->localizedTexts["townHall"]["missingBase"].String();
  1197. ret = boost::str(boost::format(msg) % town->town->buildings.at(building->upgrade)->Name());
  1198. break;
  1199. }
  1200. }
  1201. return ret;
  1202. }
  1203. CBuildWindow::CBuildWindow(const CGTownInstance *Town, const CBuilding * Building, int state, bool rightClick):
  1204. CWindowObject(PLAYER_COLORED | (rightClick ? RCLICK_POPUP : 0), "TPUBUILD"),
  1205. town(Town),
  1206. building(Building)
  1207. {
  1208. OBJ_CONSTRUCTION_CAPTURING_ALL;
  1209. new CAnimImage(town->town->clientInfo.buildingsIcons, building->bid, 0, 125, 50);
  1210. new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
  1211. new CLabel(197, 30, FONT_MEDIUM, CENTER, Colors::WHITE,
  1212. boost::str(boost::format(CGI->generaltexth->hcommands[7]) % building->Name()));
  1213. new CTextBox(building->Description(), Rect(33, 135, 329, 67), 0, FONT_MEDIUM, CENTER);
  1214. new CTextBox(getTextForState(state), Rect(33, 216, 329, 67), 0, FONT_SMALL, CENTER);
  1215. //Create components for all required resources
  1216. std::vector<CComponent *> components;
  1217. for(int i = 0; i<GameConstants::RESOURCE_QUANTITY; i++)
  1218. {
  1219. if(building->resources[i])
  1220. {
  1221. components.push_back(new CComponent(CComponent::resource, i, building->resources[i], CComponent::small));
  1222. }
  1223. }
  1224. new CComponentBox(components, Rect(25, 300, pos.w - 50, 130));
  1225. if(!rightClick)
  1226. { //normal window
  1227. buy = new CAdventureMapButton(boost::str(boost::format(CGI->generaltexth->allTexts[595]) % building->Name()),
  1228. "", boost::bind(&CBuildWindow::buyFunc,this), 45, 446,"IBUY30", SDLK_RETURN);
  1229. buy->borderColor = Colors::METALLIC_GOLD;
  1230. buy->borderEnabled = true;
  1231. cancel = new CAdventureMapButton(boost::str(boost::format(CGI->generaltexth->allTexts[596]) % building->Name()),
  1232. "", boost::bind(&CBuildWindow::close,this), 290, 445, "ICANCEL", SDLK_ESCAPE);
  1233. cancel->borderColor = Colors::METALLIC_GOLD;
  1234. cancel->borderEnabled = true;
  1235. buy->block(state!=7 || LOCPLINT->playerID != town->tempOwner);
  1236. }
  1237. }
  1238. std::string CFortScreen::getBgName(const CGTownInstance *town)
  1239. {
  1240. ui32 fortSize = town->creatures.size();
  1241. if (fortSize > GameConstants::CREATURES_PER_TOWN && town->creatures.back().second.empty())
  1242. fortSize--;
  1243. if (fortSize == GameConstants::CREATURES_PER_TOWN)
  1244. return "TPCASTL7";
  1245. else
  1246. return "TPCASTL8";
  1247. }
  1248. CFortScreen::CFortScreen(const CGTownInstance * town):
  1249. CWindowObject(PLAYER_COLORED | BORDERED, getBgName(town))
  1250. {
  1251. OBJ_CONSTRUCTION_CAPTURING_ALL;
  1252. ui32 fortSize = town->creatures.size();
  1253. if (fortSize > GameConstants::CREATURES_PER_TOWN && town->creatures.back().second.empty())
  1254. fortSize--;
  1255. const CBuilding *fortBuilding = town->town->buildings.at(BuildingID(town->fortLevel()+6));
  1256. title = new CLabel(400, 12, FONT_BIG, CENTER, Colors::WHITE, fortBuilding->Name());
  1257. std::string text = boost::str(boost::format(CGI->generaltexth->fcommands[6]) % fortBuilding->Name());
  1258. exit = new CAdventureMapButton(text, "", boost::bind(&CFortScreen::close,this) ,748, 556, "TPMAGE1", SDLK_RETURN);
  1259. exit->assignedKeys.insert(SDLK_ESCAPE);
  1260. std::vector<Point> positions;
  1261. positions += Point(10, 22), Point(404, 22),
  1262. Point(10, 155), Point(404,155),
  1263. Point(10, 288), Point(404,288);
  1264. if (fortSize == GameConstants::CREATURES_PER_TOWN)
  1265. positions += Point(206,421);
  1266. else
  1267. positions += Point(10, 421), Point(404,421);
  1268. for (ui32 i=0; i<fortSize; i++)
  1269. {
  1270. BuildingID buildingID;
  1271. if (fortSize == GameConstants::CREATURES_PER_TOWN)
  1272. {
  1273. if (vstd::contains(town->builtBuildings, BuildingID::DWELL_UP_FIRST+i))
  1274. buildingID = BuildingID(BuildingID::DWELL_UP_FIRST+i);
  1275. else
  1276. buildingID = BuildingID(BuildingID::DWELL_FIRST+i);
  1277. }
  1278. else
  1279. buildingID = BuildingID::SPECIAL_3;
  1280. recAreas.push_back(new RecruitArea(positions[i].x, positions[i].y, town, i));
  1281. }
  1282. resdatabar = new CMinorResDataBar;
  1283. resdatabar->pos.x += pos.x;
  1284. resdatabar->pos.y += pos.y;
  1285. Rect barRect(4, 554, 740, 18);
  1286. statusBar = new CGStatusBar(new CPicture(*background, barRect, 4, 554, false));
  1287. }
  1288. void CFortScreen::creaturesChanged()
  1289. {
  1290. for (auto & elem : recAreas)
  1291. elem->creaturesChanged();
  1292. }
  1293. LabeledValue::LabeledValue(Rect size, std::string name, std::string descr, int min, int max)
  1294. {
  1295. pos.x+=size.x;
  1296. pos.y+=size.y;
  1297. pos.w = size.w;
  1298. pos.h = size.h;
  1299. init(name, descr, min, max);
  1300. }
  1301. LabeledValue::LabeledValue(Rect size, std::string name, std::string descr, int val)
  1302. {
  1303. pos.x+=size.x;
  1304. pos.y+=size.y;
  1305. pos.w = size.w;
  1306. pos.h = size.h;
  1307. init(name, descr, val, val);
  1308. }
  1309. void LabeledValue::init(std::string nameText, std::string descr, int min, int max)
  1310. {
  1311. OBJ_CONSTRUCTION_CAPTURING_ALL;
  1312. addUsedEvents(HOVER);
  1313. hoverText = descr;
  1314. std::string valueText;
  1315. if (min && max)
  1316. {
  1317. valueText = boost::lexical_cast<std::string>(min);
  1318. if (min != max)
  1319. valueText += '-' + boost::lexical_cast<std::string>(max);
  1320. }
  1321. name = new CLabel(3, 0, FONT_SMALL, TOPLEFT, Colors::WHITE, nameText);
  1322. value = new CLabel(pos.w-3, pos.h-2, FONT_SMALL, BOTTOMRIGHT, Colors::WHITE, valueText);
  1323. }
  1324. void LabeledValue::hover(bool on)
  1325. {
  1326. if(on)
  1327. GH.statusbar->setText(hoverText);
  1328. else
  1329. {
  1330. GH.statusbar->clear();
  1331. parent->hovered = false;
  1332. }
  1333. }
  1334. const CCreature * CFortScreen::RecruitArea::getMyCreature()
  1335. {
  1336. if (!town->creatures.at(level).second.empty()) // built
  1337. return VLC->creh->creatures[town->creatures.at(level).second.back()];
  1338. if (!town->town->creatures.at(level).empty()) // there are creatures on this level
  1339. return VLC->creh->creatures[town->town->creatures.at(level).front()];
  1340. return nullptr;
  1341. }
  1342. const CBuilding * CFortScreen::RecruitArea::getMyBuilding()
  1343. {
  1344. BuildingID myID = BuildingID(BuildingID::DWELL_FIRST).advance(level);
  1345. if (level == GameConstants::CREATURES_PER_TOWN)
  1346. return town->town->buildings.at(BuildingID::PORTAL_OF_SUMMON);
  1347. if (!town->town->buildings.count(myID))
  1348. return nullptr;
  1349. const CBuilding * build = town->town->buildings.at(myID);
  1350. while (town->town->buildings.count(myID))
  1351. {
  1352. if (town->hasBuilt(myID))
  1353. build = town->town->buildings.at(myID);
  1354. myID.advance(GameConstants::CREATURES_PER_TOWN);
  1355. }
  1356. return build;
  1357. }
  1358. CFortScreen::RecruitArea::RecruitArea(int posX, int posY, const CGTownInstance *Town, int Level):
  1359. town(Town),
  1360. level(Level),
  1361. availableCount(nullptr)
  1362. {
  1363. OBJ_CONSTRUCTION_CAPTURING_ALL;
  1364. pos.x +=posX;
  1365. pos.y +=posY;
  1366. pos.w = 386;
  1367. pos.h = 126;
  1368. if (!town->creatures[level].second.empty())
  1369. addUsedEvents(LCLICK | RCLICK | HOVER);//Activate only if dwelling is present
  1370. icons = new CPicture("TPCAINFO", 261, 3);
  1371. if (getMyBuilding() != nullptr)
  1372. {
  1373. buildingPic = new CAnimImage(town->town->clientInfo.buildingsIcons, getMyBuilding()->bid, 0, 4, 21);
  1374. dwellingName = new CLabel(78, 101, FONT_SMALL, CENTER, Colors::WHITE, getMyBuilding()->Name());
  1375. if (vstd::contains(town->builtBuildings, getMyBuilding()->bid))
  1376. {
  1377. ui32 available = town->creatures[level].first;
  1378. std::string availableText = CGI->generaltexth->allTexts[217]+ boost::lexical_cast<std::string>(available);
  1379. availableCount = new CLabel(78, 119, FONT_SMALL, CENTER, Colors::WHITE, availableText);
  1380. }
  1381. }
  1382. if (getMyCreature() != nullptr)
  1383. {
  1384. hoverText = boost::str(boost::format(CGI->generaltexth->tcommands[21]) % getMyCreature()->namePl);
  1385. creatureAnim = new CCreaturePic(159, 4, getMyCreature(), false);
  1386. creatureName = new CLabel(78, 11, FONT_SMALL, CENTER, Colors::WHITE, getMyCreature()->namePl);
  1387. Rect sizes(287, 4, 96, 18);
  1388. values.push_back(new LabeledValue(sizes, CGI->generaltexth->allTexts[190], CGI->generaltexth->fcommands[0], getMyCreature()->Attack()));
  1389. sizes.y+=20;
  1390. values.push_back(new LabeledValue(sizes, CGI->generaltexth->allTexts[191], CGI->generaltexth->fcommands[1], getMyCreature()->Defense()));
  1391. sizes.y+=21;
  1392. values.push_back(new LabeledValue(sizes, CGI->generaltexth->allTexts[199], CGI->generaltexth->fcommands[2], getMyCreature()->getMinDamage(), getMyCreature()->getMaxDamage()));
  1393. sizes.y+=20;
  1394. values.push_back(new LabeledValue(sizes, CGI->generaltexth->allTexts[388], CGI->generaltexth->fcommands[3], getMyCreature()->MaxHealth()));
  1395. sizes.y+=21;
  1396. values.push_back(new LabeledValue(sizes, CGI->generaltexth->allTexts[193], CGI->generaltexth->fcommands[4], getMyCreature()->valOfBonuses(Bonus::STACKS_SPEED)));
  1397. sizes.y+=20;
  1398. values.push_back(new LabeledValue(sizes, CGI->generaltexth->allTexts[194], CGI->generaltexth->fcommands[5], town->creatureGrowth(level)));
  1399. }
  1400. }
  1401. void CFortScreen::RecruitArea::hover(bool on)
  1402. {
  1403. if(on)
  1404. GH.statusbar->setText(hoverText);
  1405. else
  1406. GH.statusbar->clear();
  1407. }
  1408. void CFortScreen::RecruitArea::creaturesChanged()
  1409. {
  1410. if (availableCount)
  1411. {
  1412. std::string availableText = CGI->generaltexth->allTexts[217] +
  1413. boost::lexical_cast<std::string>(town->creatures[level].first);
  1414. availableCount->setText(availableText);
  1415. }
  1416. }
  1417. void CFortScreen::RecruitArea::clickLeft(tribool down, bool previousState)
  1418. {
  1419. if(!down && previousState)
  1420. LOCPLINT->castleInt->builds->enterDwelling(level);
  1421. }
  1422. void CFortScreen::RecruitArea::clickRight(tribool down, bool previousState)
  1423. {
  1424. clickLeft(down, false); //r-click does same as l-click - opens recr. window
  1425. }
  1426. CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner,std::string imagem) :CWindowObject(BORDERED,imagem)
  1427. {
  1428. OBJ_CONSTRUCTION_CAPTURING_ALL;
  1429. window = new CPicture(owner->town->town->clientInfo.guildWindow , 332, 76);
  1430. resdatabar = new CMinorResDataBar;
  1431. resdatabar->pos.x += pos.x;
  1432. resdatabar->pos.y += pos.y;
  1433. Rect barRect(7, 556, 737, 18);
  1434. statusBar = new CGStatusBar(new CPicture(*background, barRect, 7, 556, false));
  1435. exit = new CAdventureMapButton(CGI->generaltexth->allTexts[593],"",boost::bind(&CMageGuildScreen::close,this), 748, 556,"TPMAGE1.DEF",SDLK_RETURN);
  1436. exit->assignedKeys.insert(SDLK_ESCAPE);
  1437. std::vector<std::vector<Point> > positions;
  1438. positions.resize(5);
  1439. positions[0] += Point(222,445), Point(312,445), Point(402,445), Point(520,445), Point(610,445), Point(700,445);
  1440. positions[1] += Point(48,53), Point(48,147), Point(48,241), Point(48,335), Point(48,429);
  1441. positions[2] += Point(570,82), Point(672,82), Point(570,157), Point(672,157);
  1442. positions[3] += Point(183,42), Point(183,148), Point(183,253);
  1443. positions[4] += Point(491,325), Point(591,325);
  1444. for(size_t i=0; i<owner->town->town->mageLevel; i++)
  1445. {
  1446. size_t spellCount = owner->town->spellsAtLevel(i+1,false); //spell at level with -1 hmmm?
  1447. for(size_t j=0; j<spellCount; j++)
  1448. {
  1449. if(i<owner->town->mageGuildLevel() && owner->town->spells[i].size()>j)
  1450. spells.push_back( new Scroll(positions[i][j], CGI->spellh->objects[owner->town->spells[i][j]]));
  1451. else
  1452. new CAnimImage("TPMAGES.DEF", 1, 0, positions[i][j].x, positions[i][j].y);//closed scroll
  1453. }
  1454. }
  1455. }
  1456. CMageGuildScreen::Scroll::Scroll(Point position, const CSpell *Spell)
  1457. :spell(Spell)
  1458. {
  1459. OBJ_CONSTRUCTION_CAPTURING_ALL;
  1460. addUsedEvents(LCLICK | RCLICK | HOVER);
  1461. pos += position;
  1462. image = new CAnimImage("SPELLSCR", spell->id);
  1463. pos = image->pos;
  1464. }
  1465. void CMageGuildScreen::Scroll::clickLeft(tribool down, bool previousState)
  1466. {
  1467. if(down)
  1468. LOCPLINT->showInfoDialog(spell->getLevelInfo(0).description, new CComponent(CComponent::spell,spell->id));
  1469. }
  1470. void CMageGuildScreen::Scroll::clickRight(tribool down, bool previousState)
  1471. {
  1472. if(down)
  1473. CRClickPopup::createAndPush(spell->getLevelInfo(0).description, new CComponent(CComponent::spell, spell->id));
  1474. }
  1475. void CMageGuildScreen::Scroll::hover(bool on)
  1476. {
  1477. if(on)
  1478. GH.statusbar->setText(spell->name);
  1479. else
  1480. GH.statusbar->clear();
  1481. }
  1482. CBlacksmithDialog::CBlacksmithDialog(bool possible, CreatureID creMachineID, ArtifactID aid, ObjectInstanceID hid):
  1483. CWindowObject(PLAYER_COLORED, "TPSMITH")
  1484. {
  1485. OBJ_CONSTRUCTION_CAPTURING_ALL;
  1486. statusBar = new CGStatusBar(new CPicture(*background, Rect(8, pos.h - 26, pos.w - 16, 19), 8, pos.h - 26));
  1487. animBG = new CPicture("TPSMITBK", 64, 50);
  1488. animBG->needRefresh = true;
  1489. const CCreature *creature = CGI->creh->creatures[creMachineID];
  1490. anim = new CCreatureAnim(64, 50, creature->animDefName, Rect());
  1491. anim->clipRect(113,125,200,150);
  1492. title = new CLabel(165, 28, FONT_BIG, CENTER, Colors::YELLOW,
  1493. boost::str(boost::format(CGI->generaltexth->allTexts[274]) % creature->nameSing));
  1494. costText = new CLabel(165, 218, FONT_MEDIUM, CENTER, Colors::WHITE, CGI->generaltexth->jktexts[43]);
  1495. costValue = new CLabel(165, 290, FONT_MEDIUM, CENTER, Colors::WHITE,
  1496. boost::lexical_cast<std::string>(CGI->arth->artifacts[aid]->price));
  1497. std::string text = boost::str(boost::format(CGI->generaltexth->allTexts[595]) % creature->nameSing);
  1498. buy = new CAdventureMapButton(text,"",boost::bind(&CBlacksmithDialog::close, this), 42, 312,"IBUY30.DEF",SDLK_RETURN);
  1499. text = boost::str(boost::format(CGI->generaltexth->allTexts[596]) % creature->nameSing);
  1500. cancel = new CAdventureMapButton(text,"",boost::bind(&CBlacksmithDialog::close, this), 224, 312,"ICANCEL.DEF",SDLK_ESCAPE);
  1501. if(possible)
  1502. buy->callback += [=]{ LOCPLINT->cb->buyArtifact(LOCPLINT->cb->getHero(hid),aid); };
  1503. else
  1504. buy->block(true);
  1505. new CAnimImage("RESOURCE", 6, 0, 148, 244);
  1506. }