CKingdomInterface.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  1. #include "CKingdomInterface.h"
  2. #include "AdventureMapButton.h"
  3. #include "CAdvmapInterface.h"
  4. #include "../CCallback.h"
  5. #include "../global.h"
  6. #include "CConfigHandler.h"
  7. #include "CGameInfo.h"
  8. #include "CHeroWindow.h"
  9. #include "CSpellWindow.h"
  10. #include "CMessage.h"
  11. #include "SDL_Extensions.h"
  12. #include "Graphics.h"
  13. #include "../hch/CArtHandler.h"
  14. #include "../hch/CBuildingHandler.h"
  15. #include "../hch/CDefHandler.h"
  16. #include "../hch/CHeroHandler.h"
  17. #include "../hch/CGeneralTextHandler.h"
  18. #include "../hch/CObjectHandler.h"
  19. #include "../hch/CTownHandler.h"
  20. #include "../hch/CHeroHandler.h"
  21. #include "../lib/map.h"
  22. #include "../lib/NetPacks.h"
  23. #include <boost/algorithm/string/replace.hpp>
  24. #include <boost/assign/std/vector.hpp>
  25. #include <boost/assign/list_of.hpp>
  26. #include <boost/lexical_cast.hpp>
  27. #include <boost/format.hpp>
  28. #include <sstream>
  29. #include <SDL.h>
  30. using namespace boost::assign;
  31. using namespace CSDL_Ext;
  32. /*
  33. * CKingdomInterface.cpp, part of VCMI engine
  34. *
  35. * Authors: listed in file AUTHORS in main folder
  36. *
  37. * License: GNU General Public License v2.0 or later
  38. * Full text of license available in license.txt file, in main folder
  39. *
  40. */
  41. #define ADVOPT (conf.go()->ac)
  42. CDefEssential* CKingdomInterface::slots;
  43. CDefEssential* CKingdomInterface::fort;
  44. CDefEssential* CKingdomInterface::hall;
  45. CKingdomInterface::CKingdomInterface()
  46. {
  47. OBJ_CONSTRUCTION_CAPTURING_ALL;
  48. defActions = SHARE_POS | DISPOSE;
  49. PicCount = ADVOPT.overviewPics;
  50. size = ADVOPT.overviewSize;
  51. pos.x = screen->w/2 - 400;
  52. pos.y = screen->h/2 - (68+58*size);
  53. showHarrisoned = false;//set to true if you want to see garrisoned heroes
  54. heroPos = townPos = objPos = state = 0;
  55. bg = BitmapHandler::loadBitmap(ADVOPT.overviewBg);
  56. graphics->blueToPlayersAdv(bg, LOCPLINT->playerID);
  57. mines = CDefHandler::giveDefEss("OVMINES.DEF");
  58. title = CDefHandler::giveDefEss("OVTITLE.DEF");
  59. hall = CDefHandler::giveDefEss("ITMTL.DEF");
  60. fort = CDefHandler::giveDefEss("ITMCL.DEF");
  61. objPics = CDefHandler::giveDefEss("FLAGPORT.DEF");
  62. slots = CDefHandler::giveDefEss("OVSLOT.DEF");
  63. toHeroes = new AdventureMapButton (CGI->generaltexth->overview[11],"",
  64. boost::bind(&CKingdomInterface::listToHeroes,this),748,28+size*116,"OVBUTN1.DEF", SDLK_h);
  65. toHeroes->block(2);
  66. toTowns = new AdventureMapButton (CGI->generaltexth->overview[12],"",
  67. boost::bind(&CKingdomInterface::listToTowns,this),748,64+size*116,"OVBUTN6.DEF", SDLK_t);
  68. toTowns->block(0);
  69. exit = new AdventureMapButton (CGI->generaltexth->allTexts[600],"",
  70. boost::bind(&CKingdomInterface::close,this),748,99+size*116,"OVBUTN1.DEF", SDLK_RETURN);
  71. exit->bitmapOffset = 3;
  72. statusbar = new CStatusBar(7, 91+size*116,"TSTATBAR.bmp",732);
  73. resdatabar = new CResDataBar("KRESBAR.bmp",pos.x+3,pos.y+111+size*116,32,2,76,76);
  74. for(size_t i=0;i<size;i++)//creating empty hero/town lists for input
  75. {
  76. heroes.push_back( new CHeroItem(i,this));
  77. towns.push_back( new CTownItem(i,this));
  78. }
  79. slider = new CSlider(4, 4, size*116+19, boost::bind (&CKingdomInterface::sliderMoved, this, _1),
  80. size, LOCPLINT->cb->howManyHeroes(showHarrisoned), 0, false, 0);
  81. //creating objects list
  82. ObjTop = new AdventureMapButton ("","", boost::bind(&CKingdomInterface::moveObjectList,this,0),
  83. 733,4,"OVBUTN4.DEF");
  84. ObjUp = new AdventureMapButton ("","", boost::bind(&CKingdomInterface::moveObjectList,this,1),
  85. 733,24,"OVBUTN4.DEF");
  86. ObjUp->bitmapOffset = 4;
  87. ObjDown = new AdventureMapButton ("","", boost::bind(&CKingdomInterface::moveObjectList,this,2),
  88. 733,size*116-18,"OVBUTN4.DEF");
  89. ObjDown->bitmapOffset = 6;
  90. ObjBottom = new AdventureMapButton ("","", boost::bind(&CKingdomInterface::moveObjectList,this,3),
  91. 733,size*116+2,"OVBUTN4.DEF");
  92. ObjBottom->bitmapOffset = 2;
  93. for (size_t i=0; i<8; i++)
  94. {
  95. incomes.push_back(new HoverableArea());//bottom panel with mines
  96. incomes[i]->pos = genRect(57,68,pos.x+20+i*80,pos.y+31+size*116);
  97. incomes[i]->hoverText = CGI->generaltexth->mines[i].first;
  98. }
  99. incomes[7]->pos.w = 136;
  100. incomes[7]->hoverText = CGI->generaltexth->allTexts[255];
  101. incomesVal+=0,0,0,0,0,0,0,0;//for mines images
  102. std::map<std::pair<int,int>,int> addObjects;//objects to print, except 17th dwelling
  103. //format: (id,subID),image index
  104. #define INSERT_MAP addObjects.insert(std::pair<std::pair<int,int>,int>(std::pair<int,int>
  105. INSERT_MAP (20,1) ,81));//Golem factory
  106. INSERT_MAP (42,0) ,82));//Lighthouse
  107. INSERT_MAP (33,0) ,83));//Garrison
  108. INSERT_MAP (219,0),83));//Garrison
  109. INSERT_MAP (33,1) ,84));//Anti-magic Garrison
  110. INSERT_MAP (219,1),84));//Anti-magic Garrison
  111. INSERT_MAP (53,7) ,85));//Abandoned mine
  112. INSERT_MAP (20,0) ,86));//Conflux
  113. INSERT_MAP (87,0) ,87));//Harbor
  114. #undef INSERT_MAP
  115. for(size_t i = 0; i<CGI->state->map->objects.size(); i++)//getting mines and dwelling (in one pass to make it faster)
  116. {
  117. CGObjectInstance* obj = CGI->state->map->objects[i];//current object
  118. if (obj)
  119. {
  120. if (obj->tempOwner == CGI->state->currentPlayer)//if object is our
  121. {
  122. std::pair<int,int > curElm = std::pair<int,int >(obj->ID, obj->subID);
  123. if ( obj->ID == 17 )//dwelling, text is a plural name of a creature
  124. {
  125. objList[obj->subID].first += 1;
  126. objList[obj->subID].second = & CGI->creh->creatures[CGI->objh->cregens[obj->subID]].namePl;
  127. }
  128. else if (addObjects.find(curElm) != addObjects.end())
  129. {//object from addObjects map, text is name of the object
  130. objList[addObjects[curElm]].first += 1;
  131. objList[addObjects[curElm]].second = & obj->hoverName;
  132. }
  133. else if ( obj->ID == 53 )//TODO: abandoned mines
  134. incomesVal[obj->subID]+=1;
  135. }
  136. }
  137. }
  138. addObjects.clear();
  139. objSize = (size*116-64)/57; //in object list will fit (height of panel)/(height of one element) items
  140. ObjList.resize(objSize);
  141. for(size_t i=0;i<objSize;i++)
  142. {
  143. ObjList[i] = new HoverableArea();
  144. ObjList[i]->pos = genRect(50,50,pos.x+740,pos.y+44+i*57);
  145. }
  146. incomesVal[7] = incomesVal[6]*1000;//gold mines -> total income
  147. std::vector<const CGHeroInstance*> heroes = LOCPLINT->cb->getHeroesInfo(true);
  148. for(size_t i=0; i<heroes.size();i++)
  149. switch(heroes[i]->getSecSkillLevel(13))//some heroes may have estates
  150. {
  151. case 1: //basic
  152. incomesVal[7] += 125;
  153. break;
  154. case 2: //advanced
  155. incomesVal[7] += 250;
  156. break;
  157. case 3: //expert
  158. incomesVal[7] += 500;
  159. break;
  160. }
  161. std::vector<const CGTownInstance*> towns = LOCPLINT->cb->getTownsInfo(true);
  162. for(size_t i=0; i<towns.size();i++)
  163. incomesVal[7] += towns[i]->dailyIncome();
  164. }
  165. void CKingdomInterface::moveObjectList(int newPos)
  166. {
  167. int top = objList.size() > objSize ? 0 : objList.size() - objSize ;
  168. int bottom = objList.size() > objSize ? objList.size() - objSize : 0 ;
  169. switch (newPos)//checking what button was pressed
  170. {
  171. /* Top */ case 0: objPos = top;
  172. break;
  173. /* Up */ case 1: objPos = objPos==top?top:(objPos-1);
  174. break;
  175. /* Down */ case 2: objPos = objPos==bottom?bottom:(objPos+1);
  176. break;
  177. /*Bottom*/ case 3: objPos = bottom;
  178. break;
  179. }
  180. showAll(screen2);
  181. }
  182. CKingdomInterface::~CKingdomInterface()
  183. {
  184. SDL_FreeSurface(bg);
  185. delete title;//deleting .def
  186. delete slots;
  187. delete fort;
  188. delete hall;
  189. delete objPics;
  190. delete mines;
  191. towns.clear();//deleting lists
  192. heroes.clear();
  193. incomes.clear();
  194. ObjList.clear();
  195. objList.clear();
  196. }
  197. void CKingdomInterface::close()
  198. {
  199. GH.popIntTotally(this);
  200. }
  201. void CKingdomInterface::updateAllGarrisons()
  202. {
  203. for (int i = 0; i<towns.size(); i++)
  204. {
  205. if (towns[i] && towns[i]->garr)
  206. towns[i]->garr->recreateSlots();
  207. }
  208. for (int i = 0; i<heroes.size(); i++)
  209. {
  210. if (heroes[i] && heroes[i]->garr)
  211. heroes[i]->garr->recreateSlots();
  212. }
  213. }
  214. void CKingdomInterface::showAll( SDL_Surface * to/*=NULL*/)
  215. {
  216. LOCPLINT->adventureInt->resdatabar.draw(to);
  217. blitAt(bg,pos,to);
  218. resdatabar->draw(to);
  219. toTowns->show(to);
  220. toHeroes->show(to);
  221. exit->show(to);
  222. ObjTop->show(to);
  223. ObjUp->show(to);
  224. ObjDown->show(to);
  225. ObjBottom->show(to);
  226. for (size_t i=0; i<ObjList.size(); i++)//list may be moved, recreate hover text
  227. ObjList[i]->hoverText = "";
  228. int skipCount=0, curPos=objPos<0?(-objPos):0;
  229. for (std::map<int,std::pair<int, std::string*> >::iterator it=objList.begin(); it!= objList.end(); it++)
  230. {
  231. if (skipCount<objPos)//we will show only objects from objPos
  232. {
  233. skipCount++;
  234. continue;
  235. }
  236. blitAt(objPics->ourImages[(*it).first].bitmap,pos.x+740,pos.y+44+curPos*57,to);
  237. std::ostringstream ostrs;//objects count
  238. ostrs << (*it).second.first;
  239. CSDL_Ext::printTo(ostrs.str(),pos.x+790,pos.y+94+curPos*57,FONT_SMALL,zwykly,to);
  240. ObjList[curPos]->hoverText = * (*it).second.second;
  241. curPos++;
  242. if (curPos == objSize)
  243. break;
  244. }
  245. if (state == 1)
  246. {//printing text "Town", "Harrisoned hero", "Visiting hero"
  247. CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[3],pos.x+144,pos.y+14,FONT_MEDIUM,zwykly,to);
  248. CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[4],pos.x+373,pos.y+14,FONT_MEDIUM,zwykly,to);
  249. CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[5],pos.x+606,pos.y+14,FONT_MEDIUM,zwykly,to);
  250. for (size_t i=0; i<size; i++)
  251. towns[i]->showAll(to);//show town list
  252. }
  253. else
  254. {//text "Hero/stats" and "Skills"
  255. CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[0],pos.x+150,pos.y+14,FONT_MEDIUM,zwykly,to);
  256. CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[1],pos.x+500,pos.y+14,FONT_MEDIUM,zwykly,to);
  257. for (size_t i=0; i<size; i++)
  258. heroes[i]->showAll(to);//show hero list
  259. }
  260. for (int i = 0; i<7; i++)
  261. blitAt(mines->ourImages[i].bitmap,pos.x + 20 + i*80,pos.y + 31+size*116,to);
  262. for(size_t i=0;i<incomes.size();i++)
  263. {
  264. std::ostringstream oss;
  265. oss << incomesVal[i];
  266. CSDL_Ext::printAtMiddle(oss.str(),incomes[i]->pos.x+incomes[i]->pos.w/2,incomes[i]->pos.y+50,FONT_SMALL,zwykly,to);
  267. }
  268. slider->showAll(to);
  269. if(screen->w != 800 || screen->h !=600)
  270. CMessage::drawBorder(LOCPLINT->playerID,to,828,136+116*size+29,pos.x-14,pos.y-15);
  271. show(to);
  272. }
  273. void CKingdomInterface::show(SDL_Surface * to)
  274. {
  275. statusbar->show(to);
  276. }
  277. void CKingdomInterface::activate()
  278. {
  279. GH.statusbar = statusbar;
  280. exit->activate();
  281. toTowns->activate();
  282. toHeroes->activate();
  283. ObjTop->activate();
  284. ObjUp->activate();
  285. ObjDown->activate();
  286. ObjBottom->activate();
  287. for (size_t i=0; i<ObjList.size(); i++)
  288. ObjList[i]->activate();
  289. for (size_t i=0; i<incomes.size(); i++)
  290. incomes[i]->activate();
  291. if (state == 1)
  292. for (size_t i=0; i<size; i++)
  293. towns[i]->activate();
  294. else
  295. for (size_t i=0; i<size; i++)
  296. heroes[i]->activate();
  297. slider->activate();
  298. }
  299. void CKingdomInterface::deactivate()
  300. {
  301. exit->deactivate();
  302. toTowns->deactivate();
  303. toHeroes->deactivate();
  304. ObjTop->deactivate();
  305. ObjUp->deactivate();
  306. ObjDown->deactivate();
  307. ObjBottom->deactivate();
  308. for (size_t i=0; i<ObjList.size(); i++)
  309. ObjList[i]->deactivate();
  310. for (size_t i=0; i<incomes.size(); i++)
  311. incomes[i]->deactivate();
  312. if (state == 1)
  313. for (size_t i=0; i<size; i++)
  314. towns[i]->deactivate();
  315. else
  316. for (size_t i=0; i<size; i++)
  317. heroes[i]->deactivate();
  318. slider->deactivate();
  319. }
  320. void CKingdomInterface::recreateHeroList(int pos)
  321. {
  322. std::vector<const CGHeroInstance*> Heroes = LOCPLINT->cb->getHeroesInfo(true);
  323. int i=0, cnt=0;
  324. for (size_t j = 0; ((j<Heroes.size()) && (i<size));j++)
  325. {
  326. if (Heroes[j]->inTownGarrison && (!showHarrisoned))//if hero in garrison and we don't show them
  327. continue;
  328. if (cnt<pos)//skipping heroes
  329. {
  330. cnt++;
  331. continue;
  332. }//this hero will be added
  333. heroes[i]->setHero(Heroes[j]);
  334. i++;
  335. }
  336. for (i;i<size;i++)//if we still have empty pieces
  337. heroes[i]->setHero(NULL);//empty pic
  338. }
  339. void CKingdomInterface::recreateTownList(int pos)
  340. {
  341. std::vector<const CGTownInstance*> Towns = LOCPLINT->cb->getTownsInfo(false);
  342. for(size_t i=0;i<size;i++)
  343. {
  344. if (i+pos<LOCPLINT->cb->howManyTowns())
  345. towns[i]->setTown(Towns[i+pos]);//replace town
  346. else
  347. towns[i]->setTown(NULL);//only empty pic
  348. }
  349. }
  350. void CKingdomInterface::listToTowns()
  351. {
  352. state = 1;
  353. toHeroes->block(0);
  354. toTowns->block(2);
  355. heroPos = slider->value;
  356. slider->setAmount(LOCPLINT->cb->howManyTowns());
  357. slider->value=townPos;//moving slider
  358. recreateTownList(townPos);
  359. for (size_t i=0;i<size;i++)
  360. {
  361. heroes[i]->deactivate();
  362. towns[i]->activate();
  363. }
  364. showAll(screen2);
  365. }
  366. void CKingdomInterface::listToHeroes()
  367. {
  368. state = 2;
  369. toHeroes->block(2);
  370. toTowns->block(0);
  371. townPos = slider->value;
  372. slider->setAmount(LOCPLINT->cb->howManyHeroes(showHarrisoned));
  373. slider->value=heroPos;//moving slider
  374. recreateHeroList(heroPos);
  375. for (size_t i=0;i<size;i++)
  376. {
  377. towns[i]->deactivate();
  378. heroes[i]->activate();
  379. }
  380. showAll(screen2);
  381. }
  382. void CKingdomInterface::sliderMoved(int newpos)
  383. {
  384. if (state == 0)
  385. {
  386. townPos = newpos;
  387. recreateHeroList(newpos);
  388. state = 2;
  389. }
  390. else if ( state == 1 )//towns
  391. {
  392. for (size_t i=0; i<size; i++)
  393. towns[i]->deactivate();
  394. townPos = newpos;
  395. recreateTownList(newpos);
  396. for (size_t i=0; i<size; i++)
  397. towns[i]->activate();
  398. showAll(screen2);
  399. }
  400. else//heroes
  401. {
  402. for (size_t i=0; i<size; i++)
  403. heroes[i]->deactivate();
  404. heroPos = newpos;
  405. recreateHeroList(newpos);
  406. for (size_t i=0; i<size; i++)
  407. heroes[i]->activate();
  408. showAll(screen2);
  409. }
  410. }
  411. CKingdomInterface::CTownItem::CTownItem(int num, CKingdomInterface * Owner)
  412. {
  413. recActions = DISPOSE | SHARE_POS;
  414. owner = Owner;
  415. numb = num;
  416. pos.x += 23;
  417. pos.y += 25+num*116;
  418. pos.w = 702;
  419. pos.h = 114;
  420. town = NULL;
  421. garr = NULL;
  422. garrHero = new LRClickableAreaOpenHero();
  423. garrHero->pos = genRect(64, 58, pos.x+244, pos.y + 6);
  424. visitHero = new LRClickableAreaOpenHero();
  425. visitHero->pos = genRect(64, 58, pos.x+476, pos.y + 6);
  426. for (int i=0; i<CREATURES_PER_TOWN;i++)
  427. {//creatures info
  428. creaGrowth.push_back(new HoverableArea());
  429. creaGrowth[i]->pos = genRect(32, 32, pos.x+56+i*37, pos.y + 78);
  430. creaCount.push_back(new CCreaPlace());
  431. creaCount[i]->pos = genRect(32, 32, pos.x+409+i*37, pos.y + 78);
  432. creaCount[i]->type = i;
  433. }
  434. hallArea = new HoverableArea();
  435. hallArea->pos = genRect(38, 38, pos.x+69, pos.y + 31);
  436. fortArea = new HoverableArea();
  437. fortArea->pos = genRect(38, 38, pos.x+111, pos.y + 31);
  438. townImage = new LRClickableAreaOpenTown();
  439. townImage->pos = genRect(64, 58, pos.x+5, pos.y + 6);
  440. incomeArea = new HoverableArea();
  441. incomeArea->pos = genRect(42, 64, pos.x+154, pos.y + 31);
  442. incomeArea->hoverText = CGI->generaltexth->allTexts[255];
  443. }
  444. CKingdomInterface::CTownItem::~CTownItem()
  445. {
  446. creaGrowth.clear();
  447. creaCount.clear();
  448. delete garr;
  449. }
  450. void CKingdomInterface::CTownItem::setTown(const CGTownInstance * newTown)
  451. {
  452. BLOCK_CAPTURING;
  453. delete garr;
  454. town = newTown;
  455. if (!town)
  456. {
  457. return;
  458. garr = NULL;
  459. }
  460. garr = new CGarrisonInt(pos.x+313,pos.y+3,4,Point(232,0),slots->ourImages[owner->PicCount+2].bitmap,Point(313,2),town,town->visitingHero,true,true, 4,Point(-126,37));
  461. garr->update = true;
  462. char buf[400];
  463. if (town->garrisonHero)
  464. {
  465. garrHero->hero = town->garrisonHero;
  466. sprintf(buf, CGI->generaltexth->allTexts[15].c_str(), town->garrisonHero->name.c_str(), town->garrisonHero->type->heroClass->name.c_str());
  467. garrHero->hoverText = buf;
  468. }
  469. if (town->visitingHero)
  470. {
  471. visitHero->hero = town->visitingHero;
  472. sprintf(buf, CGI->generaltexth->allTexts[15].c_str(), town->visitingHero->name.c_str(), town->visitingHero->type->heroClass->name.c_str());
  473. visitHero->hoverText = buf;
  474. }
  475. for (int i=0; i<CREATURES_PER_TOWN;i++)
  476. {
  477. creaCount[i]->town = NULL;
  478. int crid = -1;
  479. if (vstd::contains(town->builtBuildings,30+i+CREATURES_PER_TOWN))
  480. crid = town->town->upgradedCreatures[i];
  481. else
  482. crid = town->town->basicCreatures[i];
  483. std::string descr=CGI->generaltexth->allTexts[588];
  484. boost::algorithm::replace_first(descr,"%s",CGI->creh->creatures[crid].namePl);
  485. creaGrowth[i]->hoverText = descr;
  486. descr=CGI->generaltexth->heroscrn[1];
  487. boost::algorithm::replace_first(descr,"%s",CGI->creh->creatures[crid].namePl);
  488. creaCount[i]->hoverText = descr;
  489. creaCount[i]->town = town;
  490. }
  491. townImage->hoverText = town->name;
  492. townImage->town = town;
  493. hallArea->hoverText = CGI->buildh->buildings[town->subID][10+town->hallLevel()]->Name();
  494. if (town->hasFort())
  495. fortArea->hoverText = CGI->buildh->buildings[town->subID][6+town->fortLevel()]->Name();
  496. else
  497. fortArea->hoverText = "";
  498. }
  499. void CKingdomInterface::CTownItem::activate()
  500. {
  501. if (!town)
  502. return;
  503. setTown(town);
  504. hallArea->activate();
  505. fortArea->activate();
  506. incomeArea->activate();
  507. townImage->activate();
  508. if (town->garrisonHero)
  509. garrHero->activate();
  510. if (town->visitingHero)
  511. visitHero->activate();
  512. for (int i=0; i<CREATURES_PER_TOWN;i++)
  513. if (vstd::contains(town->builtBuildings,30+i))
  514. {
  515. creaGrowth[i]->activate();
  516. creaCount [i]->activate();
  517. }
  518. garr->activate();
  519. }
  520. void CKingdomInterface::CTownItem::deactivate()
  521. {
  522. if (!town)
  523. return;
  524. hallArea->deactivate();
  525. fortArea->deactivate();
  526. incomeArea->deactivate();
  527. townImage->deactivate();
  528. if (town->garrisonHero)
  529. garrHero->deactivate();
  530. if (town->visitingHero)
  531. visitHero->deactivate();
  532. for (int i=0; i<CREATURES_PER_TOWN;i++)
  533. if (vstd::contains(town->builtBuildings,30+i))
  534. {
  535. creaGrowth[i]->deactivate();
  536. creaCount [i]->deactivate();
  537. } garr->deactivate();
  538. }
  539. void CKingdomInterface::CTownItem::showAll(SDL_Surface * to)
  540. {
  541. if (!town)
  542. {//if NULL - print background & exit
  543. blitAt(slots->ourImages[numb % owner->PicCount].bitmap,pos.x,pos.y,to);
  544. return;
  545. }//background
  546. blitAt(slots->ourImages[owner->PicCount+2].bitmap,pos.x,pos.y,to); garr->show(to);
  547. //town pic/name
  548. int townPic = town->subID*2;
  549. if (!town->hasFort())
  550. townPic += F_NUMBER*2;
  551. if(town->builded >= MAX_BUILDING_PER_TURN)
  552. townPic++;
  553. blitAt(graphics->bigTownPic->ourImages[townPic].bitmap,pos.x+5,pos.y+6,to);
  554. CSDL_Ext::printAt(town->name,pos.x+73,pos.y+8,FONT_SMALL,zwykly,to);
  555. //fort pic
  556. townPic = town->fortLevel()-1;
  557. if (townPic==-1) townPic = 3;
  558. blitAt(fort->ourImages[townPic].bitmap,pos.x+111,pos.y+31,to);
  559. //hall pic
  560. townPic = town->hallLevel();
  561. blitAt(hall->ourImages[townPic].bitmap,pos.x+69,pos.y+31,to);
  562. //income pic
  563. std::ostringstream oss;
  564. oss << town->dailyIncome();
  565. CSDL_Ext::printAtMiddle(oss.str(),pos.x+189,pos.y+61,FONT_SMALL,zwykly,to);
  566. std::vector<std::string> * toPrin = CMessage::breakText(CGI->generaltexth->allTexts[265]);
  567. CSDL_Ext::printAt((*toPrin)[0], pos.x+4, pos.y+76, FONT_SMALL, tytulowy, to);
  568. if(toPrin->size()!=1)
  569. CSDL_Ext::printAt((*toPrin)[1], pos.x+4, pos.y+92, FONT_SMALL, tytulowy, to);
  570. delete toPrin;
  571. toPrin = CMessage::breakText(CGI->generaltexth->allTexts[266]);
  572. CSDL_Ext::printAt((*toPrin)[0], pos.x+351, pos.y+76, FONT_SMALL, tytulowy, to);
  573. if(toPrin->size()!=1)
  574. CSDL_Ext::printAt((*toPrin)[1], pos.x+351, pos.y+92, FONT_SMALL, tytulowy, to);
  575. delete toPrin;
  576. for (int i=0; i<CREATURES_PER_TOWN;i++)
  577. {//creatures info
  578. int crid = -1;
  579. int bid = 30+i;
  580. if (!vstd::contains(town->builtBuildings,bid))
  581. continue;
  582. if (vstd::contains(town->builtBuildings,bid+CREATURES_PER_TOWN))
  583. {
  584. crid = town->town->upgradedCreatures[i];
  585. bid += CREATURES_PER_TOWN;
  586. }
  587. else
  588. crid = town->town->basicCreatures[i];
  589. //creature growth
  590. blitAt(graphics->smallImgs[crid],pos.x+56+i*37,pos.y+78,to);
  591. std::ostringstream oss;
  592. oss << '+' << town->creatureGrowth(i);
  593. CSDL_Ext::printTo(oss.str(),pos.x+87+i*37,pos.y+110,FONT_TINY,zwykly,to);
  594. //creature available
  595. blitAt(graphics->smallImgs[crid],pos.x+409+i*37,pos.y+78,to);
  596. std::ostringstream ostrs;
  597. ostrs << town->creatures[i].first;
  598. CSDL_Ext::printTo(ostrs.str(),pos.x+440+i*37,pos.y+110,FONT_TINY,zwykly,to);
  599. }
  600. if (town->garrisonHero)
  601. blitAt(graphics->portraitLarge[town->garrisonHero->portrait],pos.x+244,pos.y+6,to);
  602. if (town->visitingHero)
  603. blitAt(graphics->portraitLarge[town->visitingHero->portrait],pos.x+476,pos.y+6,to);
  604. }
  605. CKingdomInterface::CHeroItem::CHeroItem(int num, CKingdomInterface * Owner)
  606. {
  607. OBJ_CONSTRUCTION_CAPTURING_ALL;
  608. recActions = DISPOSE | SHARE_POS;
  609. defActions = SHARE_POS;
  610. owner = Owner;
  611. numb = num;
  612. pos.x += 23;
  613. pos.y += 25+num*116;
  614. pos.w = 702;
  615. pos.h = 114;
  616. hero = NULL;
  617. garr = NULL;
  618. artGroup = 0;
  619. backpackPos = 0;
  620. artButtons = new CHighlightableButtonsGroup(0);
  621. for (size_t it = 0; it<3; it++)
  622. {
  623. artButtons->addButton(boost::assign::map_list_of(0,CGI->generaltexth->overview[13+it]),
  624. CGI->generaltexth->overview[8+it], "OVBUTN3.DEF",364+it*112, 46, it);
  625. std::string str = CGI->generaltexth->overview[8+it];
  626. str = str.substr(str.find_first_of("{")+1, str.find_first_of("}")-str.find_first_of("{"));
  627. artButtons->buttons[it]->addTextOverlay(str, FONT_SMALL, tytulowy);
  628. }
  629. artButtons->onChange = boost::bind(&CKingdomInterface::CHeroItem::onArtChange, this, _1);
  630. artButtons->select(0,0);
  631. artLeft = new AdventureMapButton("", "", boost::bind
  632. (&CKingdomInterface::CHeroItem::scrollArts,this,-1), 269, 66, "hsbtns3.def", SDLK_LEFT);
  633. artRight = new AdventureMapButton("", "", boost::bind
  634. (&CKingdomInterface::CHeroItem::scrollArts,this,+1), 675, 66, "hsbtns5.def", SDLK_RIGHT);
  635. portrait = new LRClickableAreaOpenHero();
  636. portrait->pos = genRect(64, 58, pos.x+5, pos.y + 5);
  637. char bufor[400];
  638. for(int i=0; i<PRIMARY_SKILLS; i++)
  639. {
  640. primarySkills.push_back(new LRClickableAreaWTextComp());
  641. primarySkills[i]->pos = genRect(45, 32, pos.x+77 + 36*i, pos.y+26);
  642. primarySkills[i]->text = CGI->generaltexth->arraytxt[2+i];
  643. primarySkills[i]->type = i;
  644. primarySkills[i]->baseType = 0;
  645. sprintf(bufor, CGI->generaltexth->heroscrn[1].c_str(), CGI->generaltexth->primarySkillNames[i].c_str());
  646. primarySkills[i]->hoverText = std::string(bufor);
  647. };
  648. experience = new LRClickableAreaWText();
  649. experience->pos = genRect(33, 49, pos.x+322, pos.y+5);
  650. experience->hoverText = CGI->generaltexth->heroscrn[9];
  651. morale = new LRClickableAreaWTextComp();
  652. morale->pos = genRect(20,32,pos.x+221,pos.y+52);
  653. luck = new LRClickableAreaWTextComp();
  654. luck->pos = genRect(20,32,pos.x+221,pos.y+28);
  655. spellPoints = new LRClickableAreaWText();
  656. spellPoints->pos = genRect(33, 49, pos.x+270, pos.y+5);
  657. spellPoints->hoverText = CGI->generaltexth->heroscrn[22];
  658. speciality = new LRClickableAreaWText();
  659. speciality->pos = genRect(32, 32, pos.x+374, pos.y+5);
  660. speciality->hoverText = CGI->generaltexth->heroscrn[27];
  661. for(int i=0; i<SKILL_PER_HERO; ++i)
  662. {
  663. secondarySkills.push_back(new LRClickableAreaWTextComp());
  664. secondarySkills[i]->pos = genRect(32, 32, pos.x+410+i*37, pos.y+5);
  665. secondarySkills[i]->baseType = 1;
  666. };
  667. for (int i=0; i<18;i++)
  668. {
  669. artifacts.push_back(new CArtPlace(this));
  670. artifacts[i]->pos = genRect(44, 44, pos.x+268+(i%9)*48, pos.y+66);
  671. artifacts[i]->baseType = SComponent::artifact;
  672. };
  673. for (int i=0; i<8;i++)
  674. {
  675. backpack.push_back(new CArtPlace(this));
  676. backpack[i]->pos = genRect(44, 44, pos.x+293+(i%9)*48, pos.y+66);
  677. backpack[i]->baseType = SComponent::artifact;
  678. };
  679. }
  680. CKingdomInterface::CHeroItem::~CHeroItem()
  681. {
  682. delete garr;
  683. delete artButtons;
  684. primarySkills.clear();
  685. secondarySkills.clear();
  686. artifacts.clear();
  687. backpack.clear();
  688. }
  689. void CKingdomInterface::CHeroItem::setHero(const CGHeroInstance * newHero)
  690. {
  691. BLOCK_CAPTURING;
  692. delete garr;
  693. hero = newHero;
  694. if (!hero)
  695. {
  696. return;
  697. garr = NULL;
  698. }
  699. char bufor[4000];
  700. artLeft->block(hero->artifacts.size() <= 8);
  701. artRight->block(hero->artifacts.size() <= 8);
  702. garr = new CGarrisonInt(pos.x+6, pos.y+78, 4, Point(), slots->ourImages[owner->PicCount].bitmap,
  703. Point(6,78), hero, NULL, true, true);
  704. for (int i=0; i<artifacts.size(); i++)
  705. {
  706. artifacts[i]->type = hero->getArtAtPos(i);
  707. if (artifacts[i]->type<0)
  708. artifacts[i]->hoverText = CGI->generaltexth->heroscrn[11];
  709. else
  710. {
  711. artifacts[i]->text = CGI->generaltexth->artifDescriptions[artifacts[i]->type];
  712. artifacts[i]->hoverText = boost::str(boost::format(CGI->generaltexth->heroscrn[1].c_str()) % CGI->arth->artifacts[artifacts[i]->type].Name());
  713. }
  714. }
  715. for (int i=0; i<backpack.size(); i++)
  716. {
  717. backpack[i]->type = hero->getArtAtPos(19+i);
  718. if (backpack[i]->type<0)
  719. backpack[i]->hoverText ="";
  720. else
  721. {
  722. backpack[i]->text = CGI->generaltexth->artifDescriptions[backpack[i]->type];
  723. backpack[i]->hoverText = boost::str(boost::format(CGI->generaltexth->heroscrn[1].c_str()) % CGI->arth->artifacts[backpack[i]->type].Name());
  724. }
  725. }
  726. sprintf(bufor, CGI->generaltexth->allTexts[15].c_str(), hero->name.c_str(), hero->type->heroClass->name.c_str());
  727. portrait->hoverText = std::string(bufor);
  728. portrait->hero = hero;
  729. speciality->text = CGI->generaltexth->hTxts[hero->subID].longBonus;
  730. //primary skills
  731. for(size_t g=0; g<primarySkills.size(); ++g)
  732. primarySkills[g]->bonus = hero->getPrimSkillLevel(g);
  733. //secondary skills
  734. for(size_t g=0; g<std::min(secondarySkills.size(),hero->secSkills.size()); ++g)
  735. {
  736. int skill = hero->secSkills[g].first,
  737. level = hero->secSkills[g].second;
  738. secondarySkills[g]->type = skill;
  739. secondarySkills[g]->bonus = level;
  740. secondarySkills[g]->text = CGI->generaltexth->skillInfoTexts[skill][level-1];
  741. sprintf(bufor, CGI->generaltexth->heroscrn[21].c_str(), CGI->generaltexth->levels[level-1].c_str(), CGI->generaltexth->skillName[skill].c_str());
  742. secondarySkills[g]->hoverText = std::string(bufor);
  743. }
  744. //experience
  745. experience->text = CGI->generaltexth->allTexts[2].c_str();
  746. boost::replace_first(experience->text, "%d", boost::lexical_cast<std::string>(hero->level));
  747. boost::replace_first(experience->text, "%d", boost::lexical_cast<std::string>(CGI->heroh->reqExp(hero->level+1)));
  748. boost::replace_first(experience->text, "%d", boost::lexical_cast<std::string>(hero->exp));
  749. //spell points
  750. sprintf(bufor, CGI->generaltexth->allTexts[205].c_str(), hero->name.c_str(), hero->mana, hero->manaLimit());
  751. spellPoints->text = std::string(bufor);
  752. //setting morale
  753. std::vector<std::pair<int,std::string> > mrl = hero->getCurrentMoraleModifiers();
  754. int mrlv = hero->getCurrentMorale();
  755. int mrlt = (mrlv>0)-(mrlv<0); //signum: -1 - bad morale, 0 - neutral, 1 - good
  756. morale->hoverText = CGI->generaltexth->heroscrn[4 - mrlt];
  757. morale->baseType = SComponent::morale;
  758. morale->bonus = mrlv;
  759. morale->text = CGI->generaltexth->arraytxt[88];
  760. boost::algorithm::replace_first(morale->text,"%s",CGI->generaltexth->arraytxt[86-mrlt]);
  761. if (!mrl.size())
  762. morale->text += CGI->generaltexth->arraytxt[108];
  763. else
  764. for(int it=0; it < mrl.size(); it++)
  765. morale->text += "\n" + mrl[it].second;
  766. //setting luck
  767. mrl = hero->getCurrentLuckModifiers();
  768. mrlv = hero->getCurrentLuck();
  769. mrlt = (mrlv>0)-(mrlv<0); //signum: -1 - bad luck, 0 - neutral, 1 - good
  770. luck->hoverText = CGI->generaltexth->heroscrn[7 - mrlt];
  771. luck->baseType = SComponent::luck;
  772. luck->bonus = mrlv;
  773. luck->text = CGI->generaltexth->arraytxt[62];
  774. boost::algorithm::replace_first(luck->text,"%s",CGI->generaltexth->arraytxt[60-mrlt]);
  775. if (!mrl.size())
  776. luck->text += CGI->generaltexth->arraytxt[77];
  777. else
  778. for(int it=0; it < mrl.size(); it++)
  779. luck->text += "\n" + mrl[it].second;
  780. }
  781. void CKingdomInterface::CHeroItem::scrollArts(int move)
  782. {
  783. backpackPos = ( backpackPos + move + hero->artifacts.size()) % hero->artifacts.size();
  784. for (int i=0; i<backpack.size(); i++)
  785. {
  786. backpack[i]->type = hero->getArtAtPos(19+(backpackPos + i)%hero->artifacts.size());
  787. if (backpack[i]->type<0)
  788. backpack[i]->hoverText ="";
  789. else
  790. {
  791. backpack[i]->text = CGI->generaltexth->artifDescriptions[backpack[i]->type];
  792. backpack[i]->hoverText = boost::str(boost::format(CGI->generaltexth->heroscrn[1].c_str()) % CGI->arth->artifacts[backpack[i]->type].Name());
  793. }
  794. }
  795. showAll(screen2);
  796. }
  797. void CKingdomInterface::CHeroItem::showAll(SDL_Surface * to)
  798. {
  799. if (!hero)
  800. {//if we have no hero for this slot - print background & exit
  801. blitAt(slots->ourImages[numb % owner->PicCount].bitmap,pos.x,pos.y,to);
  802. return;
  803. }//print background, different for arts view/backpack mode
  804. blitAt(slots->ourImages[(artGroup!=2)?owner->PicCount:(owner->PicCount+1)].bitmap,pos.x,pos.y,to);
  805. //text "Artifacts"
  806. CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[2],pos.x+320,pos.y+55,FONT_SMALL,zwykly,to);
  807. blitAt(graphics->portraitLarge[hero->portrait],pos.x+5,pos.y+6,to);
  808. garr->show(to);
  809. //hero name
  810. CSDL_Ext::printAt(hero->name,pos.x+73,pos.y+7,FONT_SMALL,zwykly,to);
  811. for (int i = 0; i<6; i++)
  812. {//primary skills, mana and exp. pics
  813. blitAt(graphics->pskillst->ourImages[i].bitmap,(i<4)?(pos.x+78+36*i):(pos.x+539-52*i),
  814. (i<4)?(pos.y+26):(pos.y+6),to);
  815. if (i>3) continue;//primary skills text
  816. std::ostringstream str;
  817. str << (hero->primSkills[i]);
  818. CSDL_Ext::printAtMiddle(str.str(),pos.x+94+36*i,pos.y+66,FONT_SMALL,zwykly,to);
  819. }
  820. {//luck and morale pics, experience and mana text
  821. blitAt(graphics->luck30->ourImages[hero->getCurrentLuck()+3].bitmap,pos.x+222,pos.y+30,to);
  822. blitAt(graphics->morale30->ourImages[hero->getCurrentMorale()+3].bitmap,pos.x+222,pos.y+54,to);
  823. std::ostringstream str;
  824. str << (hero->exp);
  825. CSDL_Ext::printAtMiddle(str.str(),(pos.x+348),(pos.y+31),FONT_TINY,zwykly,to);
  826. std::ostringstream strnew;
  827. strnew << (hero->mana)<<"/"<<(hero->manaLimit());
  828. CSDL_Ext::printAtMiddle(strnew.str(),(pos.x+295),(pos.y+30),FONT_TINY,zwykly,to);
  829. }
  830. //hero speciality
  831. blitAt(graphics->un32->ourImages[hero->subID].bitmap, pos.x+375, pos.y+6, to);
  832. for(int i=0; i<hero->secSkills.size(); i++)
  833. {//secondary skills
  834. int skill = hero->secSkills[i].first,
  835. level = hero->secSkills[i].second;
  836. blitAt(graphics->abils32->ourImages[skill*3+level+2].bitmap,pos.x+411+i*36,pos.y+6,to);
  837. }
  838. artButtons->show(to);
  839. int iter=0;
  840. switch (artGroup)
  841. {//arts
  842. case 1:iter = 9;//misc. arts, spellbook, war machines
  843. case 0://equipped arts
  844. for (int i = iter ; i<iter+9;i++)
  845. {
  846. int artID = hero->getArtAtPos(i);
  847. if (artID>=0)
  848. blitAt(graphics->artDefs->ourImages[artID].bitmap,pos.x+268+48*(i%9),pos.y+66,to);
  849. }
  850. break;
  851. case 2:
  852. artLeft->show(to);
  853. artRight->show(to);
  854. int max = hero->artifacts.size();
  855. iter = std::min(8, max);
  856. for (size_t it = 0 ; it<iter;it++)
  857. blitAt(graphics->artDefs->ourImages[hero->artifacts[(it+backpackPos)%max]].bitmap,pos.x+293+48*it,pos.y+66,to);
  858. break;
  859. }
  860. show(to);
  861. }
  862. void CKingdomInterface::CHeroItem::onArtChange(int newstate)
  863. {
  864. if (!hero)
  865. return;
  866. deactivate();
  867. artGroup = newstate;
  868. activate();
  869. showAll(screen2);
  870. }
  871. void CKingdomInterface::CHeroItem::activate()
  872. {
  873. setHero(hero);
  874. if (!hero)
  875. return;
  876. artButtons->activate();
  877. garr->activate();
  878. if ( artGroup == 2 )
  879. {
  880. artLeft->activate();
  881. artRight->activate();
  882. for (size_t i=0; i<8;i++)
  883. backpack[i]->activate();
  884. }
  885. else
  886. {
  887. for (size_t i=artGroup*9; i<9+artGroup*9;i++)
  888. artifacts[i]->activate();
  889. }
  890. portrait->activate();
  891. experience->activate();
  892. morale->activate();
  893. luck->activate();
  894. spellPoints->activate();
  895. speciality->activate();
  896. for (size_t i=0; i<primarySkills.size();i++)
  897. primarySkills[i]->activate();
  898. for (size_t i=0; i<std::min(secondarySkills.size(),hero->secSkills.size());i++)
  899. secondarySkills[i]->activate();
  900. }
  901. void CKingdomInterface::CHeroItem::deactivate()
  902. {
  903. if (!hero)
  904. return;
  905. artButtons->deactivate();
  906. garr->deactivate();
  907. if ( artGroup == 2 )
  908. {
  909. artLeft->deactivate();
  910. artRight->deactivate();
  911. for (size_t i=0; i<8;i++)
  912. backpack[i]->deactivate();
  913. }
  914. else
  915. {
  916. for (size_t i=artGroup*9; i<9+artGroup*9;i++)
  917. artifacts[i]->deactivate();
  918. }
  919. portrait->deactivate();
  920. experience->deactivate();
  921. morale->deactivate();
  922. luck->deactivate();
  923. spellPoints->deactivate();
  924. speciality->deactivate();
  925. for (size_t i=0; i<primarySkills.size();i++)
  926. primarySkills[i]->deactivate();
  927. for (size_t i=0; i<std::min(secondarySkills.size(),hero->secSkills.size());i++)
  928. secondarySkills[i]->deactivate();
  929. }
  930. CKingdomInterface::CHeroItem::CArtPlace::CArtPlace(CHeroItem * owner)
  931. {
  932. hero = owner;
  933. used = LCLICK | RCLICK | HOVER;
  934. }
  935. void CKingdomInterface::CHeroItem::CArtPlace::activate()
  936. {
  937. LRClickableAreaWTextComp::activate();
  938. }
  939. void CKingdomInterface::CHeroItem::CArtPlace::clickLeft(tribool down, bool previousState)
  940. {
  941. if (!down && previousState && type>=0)
  942. {
  943. if(type == 0)
  944. {
  945. CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (screen->w - 620)/2, (screen->h - 595)/2), hero->hero);
  946. GH.pushInt(spellWindow);
  947. }
  948. else
  949. LRClickableAreaWTextComp::clickLeft(down,previousState);
  950. }
  951. }
  952. void CKingdomInterface::CHeroItem::CArtPlace::clickRight(tribool down, bool previousState)
  953. {
  954. if (type>=0)
  955. LRClickableAreaWTextComp::clickRight(down, previousState);
  956. }
  957. void CKingdomInterface::CHeroItem::CArtPlace::deactivate()
  958. {
  959. LRClickableAreaWTextComp::deactivate();
  960. }
  961. CKingdomInterface::CTownItem::CCreaPlace::CCreaPlace()
  962. {
  963. town = NULL;
  964. used = LCLICK | RCLICK | HOVER;
  965. }
  966. void CKingdomInterface::CTownItem::CCreaPlace::activate()
  967. {
  968. LRClickableAreaWTextComp::activate();
  969. }
  970. void CKingdomInterface::CTownItem::CCreaPlace::clickLeft(tribool down, bool previousState)
  971. {
  972. if (!down && previousState && town)
  973. {
  974. GH.pushInt (new CRecruitmentWindow(town, type, town, boost::bind
  975. (&CCallback::recruitCreatures,LOCPLINT->cb,town,_1,_2)));
  976. }
  977. }
  978. void CKingdomInterface::CTownItem::CCreaPlace::clickRight(tribool down, bool previousState)
  979. {
  980. if (down && town)
  981. {
  982. int crid;
  983. if (town->builtBuildings.find(30+type+CREATURES_PER_TOWN)!=town->builtBuildings.end())
  984. crid = town->town->upgradedCreatures[type];
  985. else
  986. crid = town->town->basicCreatures[type];
  987. GH.pushInt(new CCreInfoWindow(crid, 0, town->creatures[type].first, NULL, 0, 0, NULL));
  988. }
  989. }
  990. void CKingdomInterface::CTownItem::CCreaPlace::deactivate()
  991. {
  992. LRClickableAreaWTextComp::deactivate();
  993. }