CCastleInterface.cpp 52 KB

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