CCastleInterface.cpp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340
  1. #include "stdafx.h"
  2. #include "CCastleInterface.h"
  3. #include "hch/CObjectHandler.h"
  4. #include "CGameInfo.h"
  5. #include "hch/CLodHandler.h"
  6. #include "SDL_Extensions.h"
  7. #include "CAdvmapInterface.h"
  8. #include "hch/CTownHandler.h"
  9. #include "AdventureMapButton.h"
  10. #include "hch/CBuildingHandler.h"
  11. #include "hch/CDefHandler.h"
  12. #include <sstream>
  13. #include "CMessage.h"
  14. #include "hch/CGeneralTextHandler.h"
  15. #include "CCallback.h"
  16. #include "client/Graphics.h"
  17. #include "client/CCreatureAnimation.h"
  18. #include "CHeroWindow.h"
  19. #include <boost/algorithm/string.hpp>
  20. #include <boost/algorithm/string/replace.hpp>
  21. #include <boost/assign/std/vector.hpp>
  22. using namespace boost::assign;
  23. using namespace CSDL_Ext;
  24. extern TTF_Font * GEOR16;
  25. CBuildingRect::CBuildingRect(Structure *Str)
  26. :str(Str), moi(false), offset(0)
  27. {
  28. def = CDefHandler::giveDef(Str->defName);
  29. max = def->ourImages.size();
  30. if(str->ID == 33 && str->townID == 4) //little 'hack' for estate in necropolis - background color is not always the first color in the palette
  31. {
  32. for(std::vector<Cimage>::iterator i=def->ourImages.begin();i!=def->ourImages.end();i++)
  33. {
  34. SDL_SetColorKey(i->bitmap,SDL_SRCCOLORKEY,*((char*)i->bitmap->pixels));
  35. }
  36. }
  37. pos.x = str->pos.x;
  38. pos.y = str->pos.y;
  39. pos.w = def->ourImages[0].bitmap->w;
  40. pos.h = def->ourImages[0].bitmap->h;
  41. if(Str->ID<0 || (Str->ID>=27 && Str->ID<=29))
  42. {
  43. area = border = NULL;
  44. return;
  45. }
  46. if (border = BitmapHandler::loadBitmap(str->borderName))
  47. SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255));
  48. else
  49. std::cout << "Warning: no border for "<<Str->ID<<std::endl;
  50. if (area = BitmapHandler::loadBitmap(str->areaName))
  51. ;//SDL_SetColorKey(area,SDL_SRCCOLORKEY,SDL_MapRGB(area->format,0,255,255));
  52. else
  53. std::cout << "Warning: no area for "<<Str->ID<<std::endl;
  54. }
  55. CBuildingRect::~CBuildingRect()
  56. {
  57. delete def;
  58. if(border)
  59. SDL_FreeSurface(border);
  60. if(area)
  61. SDL_FreeSurface(area);
  62. }
  63. void CBuildingRect::activate()
  64. {
  65. Hoverable::activate();
  66. ClickableL::activate();
  67. ClickableR::activate();
  68. }
  69. void CBuildingRect::deactivate()
  70. {
  71. Hoverable::deactivate();
  72. ClickableL::deactivate();
  73. ClickableR::deactivate();
  74. if(moi)
  75. MotionInterested::deactivate();
  76. moi=false;
  77. }
  78. bool CBuildingRect::operator<(const CBuildingRect & p2) const
  79. {
  80. if(str->pos.z != p2.str->pos.z)
  81. return (str->pos.z) < (p2.str->pos.z);
  82. else
  83. return (str->ID) < (p2.str->ID);
  84. }
  85. void CBuildingRect::hover(bool on)
  86. {
  87. Hoverable::hover(on);
  88. if(on)
  89. {
  90. if(!moi)
  91. MotionInterested::activate();
  92. moi = true;
  93. }
  94. else
  95. {
  96. if(moi)
  97. MotionInterested::deactivate();
  98. moi = false;
  99. if(LOCPLINT->castleInt->hBuild == this)
  100. {
  101. LOCPLINT->castleInt->hBuild = NULL;
  102. LOCPLINT->statusbar->clear();
  103. }
  104. }
  105. }
  106. void CBuildingRect::clickLeft (tribool down)
  107. {
  108. if(area && (LOCPLINT->castleInt->hBuild==this) && !(indeterminate(down)) && (CSDL_Ext::SDL_GetPixel(area,LOCPLINT->current->motion.x-pos.x,LOCPLINT->current->motion.y-pos.y) != 0)) //na polu
  109. {
  110. if(pressedL && !down)
  111. LOCPLINT->castleInt->buildingClicked(str->ID);
  112. ClickableL::clickLeft(down);
  113. }
  114. //todo - handle
  115. }
  116. void CBuildingRect::clickRight (tribool down)
  117. {
  118. if((!area) || (!((bool)down)) || (this!=LOCPLINT->castleInt->hBuild))
  119. return;
  120. if((CSDL_Ext::SDL_GetPixel(area,LOCPLINT->current->motion.x-pos.x,LOCPLINT->current->motion.y-pos.y) != 0)) //na polu
  121. {
  122. CInfoPopup *vinya = new CInfoPopup();
  123. vinya->free = true;
  124. vinya->bitmap = CMessage::drawBoxTextBitmapSub
  125. (LOCPLINT->playerID,
  126. CGI->buildh->buildings[str->townID][str->ID]->description,
  127. LOCPLINT->castleInt->bicons->ourImages[str->ID].bitmap,
  128. CGI->buildh->buildings[str->townID][str->ID]->name);
  129. vinya->pos.x = screen->w/2 - vinya->bitmap->w/2;
  130. vinya->pos.y = screen->h/2 - vinya->bitmap->h/2;
  131. vinya->activate();
  132. }
  133. }
  134. void CBuildingRect::mouseMoved (SDL_MouseMotionEvent & sEvent)
  135. {
  136. if(area)
  137. {
  138. if(CSDL_Ext::SDL_GetPixel(area,sEvent.x-pos.x,sEvent.y-pos.y) == 0) //hovered pixel is inside this building
  139. {
  140. if(LOCPLINT->castleInt->hBuild == this)
  141. {
  142. LOCPLINT->castleInt->hBuild = NULL;
  143. LOCPLINT->statusbar->clear();
  144. }
  145. }
  146. else //inside the area of this building
  147. {
  148. if(LOCPLINT->castleInt->hBuild) //a building is hovered
  149. {
  150. if((*LOCPLINT->castleInt->hBuild)<(*this)) //set if we are on top
  151. {
  152. LOCPLINT->castleInt->hBuild = this;
  153. if(CGI->buildh->buildings[str->townID][str->ID] && CGI->buildh->buildings[str->townID][str->ID]->name.length())
  154. LOCPLINT->statusbar->print(CGI->buildh->buildings[str->townID][str->ID]->name);
  155. else
  156. LOCPLINT->statusbar->print(str->name);
  157. }
  158. }
  159. else //no building hovered
  160. {
  161. LOCPLINT->castleInt->hBuild = this;
  162. if(CGI->buildh->buildings[str->townID][str->ID] && CGI->buildh->buildings[str->townID][str->ID]->name.length())
  163. LOCPLINT->statusbar->print(CGI->buildh->buildings[str->townID][str->ID]->name);
  164. else
  165. LOCPLINT->statusbar->print(str->name);
  166. }
  167. }
  168. }
  169. //if(border)
  170. // blitAt(border,pos.x,pos.y);
  171. }
  172. void CHeroGSlot::hover (bool on)
  173. {
  174. if(!on) return;
  175. CHeroGSlot *other = upg ? &owner->hslotup : &owner->hslotdown;
  176. std::string temp;
  177. if(hero)
  178. {
  179. if(highlight)//view NNN
  180. {
  181. temp = CGI->townh->tcommands[4];
  182. boost::algorithm::replace_first(temp,"%s",hero->name);
  183. }
  184. else if(other->hero && other->highlight)//exchange
  185. {
  186. temp = CGI->townh->tcommands[7];
  187. boost::algorithm::replace_first(temp,"%s",hero->name);
  188. boost::algorithm::replace_first(temp,"%s",other->hero->name);
  189. }
  190. else// select NNN (in ZZZ)
  191. {
  192. if(upg)//down - visiting
  193. {
  194. temp = CGI->townh->tcommands[32];
  195. boost::algorithm::replace_first(temp,"%s",hero->name);
  196. }
  197. else //up - garrison
  198. {
  199. temp = CGI->townh->tcommands[12];
  200. boost::algorithm::replace_first(temp,"%s",hero->name);
  201. }
  202. }
  203. }
  204. else //we are empty slot
  205. {
  206. if(other->highlight && other->hero) //move NNNN
  207. {
  208. temp = CGI->townh->tcommands[6];
  209. boost::algorithm::replace_first(temp,"%s",other->hero->name);
  210. }
  211. else //empty
  212. {
  213. temp = CGI->generaltexth->allTexts[507];
  214. }
  215. }
  216. if(temp.size())
  217. LOCPLINT->statusbar->print(temp);
  218. }
  219. void CHeroGSlot::clickRight (boost::logic::tribool down)
  220. {
  221. }
  222. void CHeroGSlot::clickLeft(boost::logic::tribool down)
  223. {
  224. if(!down)
  225. {
  226. CHeroGSlot *other = upg ? &owner->hslotup : &owner->hslotdown;
  227. if(hero && highlight)
  228. {
  229. highlight = false;
  230. LOCPLINT->openHeroWindow(hero);
  231. LOCPLINT->adventureInt->heroWindow->quitButton->callback += boost::bind(&CCastleInterface::showAll,owner,screen,true);
  232. }
  233. else if(hero)
  234. {
  235. highlight = true;
  236. owner->showAll();
  237. }
  238. else if(other->hero, other->highlight)
  239. {
  240. other->highlight = highlight = false;
  241. LOCPLINT->cb->swapGarrisonHero(owner->town);
  242. }
  243. hover(false);hover(true); //refresh statusbar
  244. }
  245. }
  246. void CHeroGSlot::activate()
  247. {
  248. ClickableL::activate();
  249. ClickableR::activate();
  250. Hoverable::activate();
  251. }
  252. void CHeroGSlot::deactivate()
  253. {
  254. ClickableL::deactivate();
  255. ClickableR::deactivate();
  256. Hoverable::deactivate();
  257. }
  258. void CHeroGSlot::show()
  259. {
  260. if(hero) //there is hero
  261. blitAt(graphics->portraitLarge[hero->portrait],pos);
  262. else if(!upg) //up garrison
  263. blitAt((static_cast<CCastleInterface*>(LOCPLINT->curint))->flag->ourImages[(static_cast<CCastleInterface*>(LOCPLINT->curint))->town->getOwner()].bitmap,pos);
  264. if(highlight)
  265. blitAt(graphics->bigImgs[-1],pos);
  266. }
  267. CHeroGSlot::CHeroGSlot(int x, int y, int updown, const CGHeroInstance *h, CCastleInterface * Owner)
  268. {
  269. owner = Owner;
  270. pos.x = x;
  271. pos.y = y;
  272. pos.w = 58;
  273. pos.h = 64;
  274. hero = h;
  275. upg = updown;
  276. highlight = false;
  277. }
  278. CHeroGSlot::~CHeroGSlot()
  279. {
  280. }
  281. std::string getBgName(int type) //TODO - co z tym zrobiæ?
  282. {
  283. switch (type)
  284. {
  285. case 0:
  286. return "TBCSBACK.bmp";
  287. case 1:
  288. return "TBRMBACK.bmp";
  289. case 2:
  290. return "TBTWBACK.bmp";
  291. case 3:
  292. return "TBINBACK.bmp";
  293. case 4:
  294. return "TBNCBACK.bmp";
  295. case 5:
  296. return "TBDNBACK.bmp";
  297. case 6:
  298. return "TBSTBACK.bmp";
  299. case 7:
  300. return "TBFRBACK.bmp";
  301. case 8:
  302. return "TBELBACK.bmp";
  303. default:
  304. #ifndef __GNUC__
  305. throw new std::exception("std::string getBgName(int type): invalid type");
  306. #else
  307. throw new std::exception();
  308. #endif
  309. }
  310. }
  311. class SORTHELP
  312. {
  313. public:
  314. bool operator ()
  315. (const CBuildingRect *a ,
  316. const CBuildingRect *b)
  317. {
  318. return (*a)<(*b);
  319. }
  320. } srthlp ;
  321. CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
  322. :hslotup(241,387,0,Town->garrisonHero,this),hslotdown(241,483,1,Town->visitingHero,this)
  323. {
  324. hall = NULL;
  325. townInt = BitmapHandler::loadBitmap("TOWNSCRN.bmp");
  326. cityBg = BitmapHandler::loadBitmap(getBgName(Town->subID));
  327. hall = CDefHandler::giveDef("ITMTL.DEF");
  328. fort = CDefHandler::giveDef("ITMCL.DEF");
  329. flag = CDefHandler::giveDef("CREST58.DEF");
  330. hBuild = NULL;
  331. count=0;
  332. town = Town;
  333. //garrison
  334. garr = new CGarrisonInt(305,387,4,32,townInt,243,13,town,town->visitingHero);
  335. townlist = new CTownList(3,&genRect(128,48,744,414),744,414,744,526);
  336. exit = new AdventureMapButton
  337. (CGI->townh->tcommands[8],"",boost::bind(&CCastleInterface::close,this),744,544,"TSBTNS.DEF",false,NULL,false);
  338. split = new AdventureMapButton
  339. (CGI->townh->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),744,382,"TSBTNS.DEF",false,NULL,false);
  340. statusbar = new CStatusBar(8,555,"TSTATBAR.bmp",732);
  341. townlist->fun = boost::bind(&CCastleInterface::townChange,this);
  342. townlist->genList();
  343. townlist->selected = getIndexOf(townlist->items,Town);
  344. if((townlist->selected+1) > townlist->SIZE)
  345. townlist->from = townlist->selected - townlist->SIZE + 2;
  346. graphics->blueToPlayersAdv(townInt,LOCPLINT->playerID);
  347. exit->bitmapOffset = 4;
  348. //buildings
  349. recreateBuildings();
  350. if(Activate)
  351. {
  352. LOCPLINT->objsToBlit.push_back(this);
  353. activate();
  354. showAll();
  355. }
  356. std::string defname;
  357. switch (town->subID)
  358. {
  359. case 0:
  360. defname = "HALLCSTL.DEF";
  361. break;
  362. case 1:
  363. defname = "HALLRAMP.DEF";
  364. break;
  365. case 2:
  366. defname = "HALLTOWR.DEF";
  367. break;
  368. case 3:
  369. defname = "HALLINFR.DEF";
  370. break;
  371. case 4:
  372. defname = "HALLNECR.DEF";
  373. break;
  374. case 5:
  375. defname = "HALLDUNG.DEF";
  376. break;
  377. case 6:
  378. defname = "HALLSTRN.DEF";
  379. break;
  380. case 7:
  381. defname = "HALLFORT.DEF";
  382. break;
  383. case 8:
  384. defname = "HALLELEM.DEF";
  385. break;
  386. default:
  387. #ifndef __GNUC__
  388. throw new std::exception("Bad town subID");
  389. #else
  390. throw new std::exception();
  391. #endif
  392. }
  393. bicons = CDefHandler::giveDefEss(defname);
  394. //blit buildings on bg
  395. //for(int i=0;i<buildings.size();i++)
  396. //{
  397. // blitAt(buildings[i]->def->ourImages[0].bitmap,buildings[i]->pos.x,buildings[i]->pos.y,cityBg);
  398. //}
  399. }
  400. CCastleInterface::~CCastleInterface()
  401. {
  402. SDL_FreeSurface(townInt);
  403. SDL_FreeSurface(cityBg);
  404. delete exit;
  405. delete split;
  406. delete hall;
  407. delete fort;
  408. delete flag;
  409. delete garr;
  410. delete townlist;
  411. delete statusbar;
  412. for(int i=0;i<buildings.size();i++)
  413. {
  414. delete buildings[i];
  415. }
  416. delete bicons;
  417. }
  418. void CCastleInterface::close()
  419. {
  420. LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
  421. deactivate();
  422. LOCPLINT->castleInt = NULL;
  423. LOCPLINT->adventureInt->activate();
  424. delete this;
  425. }
  426. void CCastleInterface::splitF()
  427. {
  428. }
  429. void CCastleInterface::buildingClicked(int building)
  430. {
  431. std::cout<<"You've clicked on "<<building<<std::endl;
  432. if(building==19 || building==18)
  433. {
  434. building = town->town->hordeLvl[0] + 30;
  435. }
  436. else if(building==24 || building==25)
  437. {
  438. building = town->town->hordeLvl[1] + 30;
  439. }
  440. if(building >= 30)
  441. {
  442. LOCPLINT->curint->deactivate();
  443. showRecruitmentWindow(building);
  444. }
  445. else
  446. {
  447. switch(building)
  448. {
  449. case 7: case 8: case 9:
  450. {
  451. CFortScreen *fs = new CFortScreen(this);
  452. deactivate();
  453. fs->activate();
  454. fs->show();
  455. break;
  456. }
  457. case 10: case 11: case 12: case 13:
  458. enterHall();
  459. break;
  460. default:
  461. std::cout<<"This building isn't handled...\n";
  462. }
  463. }
  464. }
  465. void CCastleInterface::enterHall()
  466. {
  467. deactivate();
  468. CHallInterface *h = new CHallInterface(this);
  469. subInt = h;
  470. h->activate();
  471. h->show();
  472. }
  473. void CCastleInterface::showAll( SDL_Surface * to/*=NULL*/, bool forceTotalRedraw /*= false*/)
  474. {
  475. if (!to)
  476. to=screen;
  477. blitAt(cityBg,0,0,to);
  478. blitAt(townInt,0,374,to);
  479. LOCPLINT->adventureInt->resdatabar.draw();
  480. townlist->draw();
  481. statusbar->show();
  482. garr->show();
  483. int pom;
  484. //draw fort icon
  485. if(town->builtBuildings.find(9)!=town->builtBuildings.end())
  486. pom = 2;
  487. else if(town->builtBuildings.find(8)!=town->builtBuildings.end())
  488. pom = 1;
  489. else if(town->builtBuildings.find(7)!=town->builtBuildings.end())
  490. pom = 0;
  491. else pom = 3;
  492. blitAt(fort->ourImages[pom].bitmap,122,413,to);
  493. //draw ((village/town/city) hall)/capitol icon
  494. if(town->builtBuildings.find(13)!=town->builtBuildings.end())
  495. pom = 3;
  496. else if(town->builtBuildings.find(12)!=town->builtBuildings.end())
  497. pom = 2;
  498. else if(town->builtBuildings.find(11)!=town->builtBuildings.end())
  499. pom = 1;
  500. else pom = 0;
  501. blitAt(hall->ourImages[pom].bitmap,80,413,to);
  502. //draw creatures icons and their growths
  503. for(int i=0;i<CREATURES_PER_TOWN;i++)
  504. {
  505. int cid = -1;
  506. if (town->builtBuildings.find(30+i)!=town->builtBuildings.end())
  507. {
  508. if (town->builtBuildings.find(30+CREATURES_PER_TOWN+i)!=town->builtBuildings.end())
  509. cid = town->town->upgradedCreatures[i];
  510. else
  511. cid = town->town->basicCreatures[i];
  512. }
  513. if (cid>=0)
  514. {
  515. int pomx, pomy;
  516. pomx = 22 + (55*((i>3)?(i-4):i));
  517. pomy = (i>3)?(507):(459);
  518. blitAt(graphics->smallImgs[cid],pomx,pomy,to);
  519. std::ostringstream oss;
  520. oss << '+' << town->creatureGrowth(i);
  521. CSDL_Ext::printAtMiddle(oss.str(),pomx+16,pomy+37,GEOR13,zwykly,to);
  522. }
  523. }
  524. //print name and income
  525. CSDL_Ext::printAt(town->name,85,389,GEOR13,zwykly,to);
  526. char temp[10];
  527. SDL_itoa(town->dailyIncome(),temp,10);
  528. CSDL_Ext::printAtMiddle(temp,195,442,GEOR13,zwykly,to);
  529. //blit town icon
  530. pom = town->subID*2;
  531. if (!town->hasFort())
  532. pom += F_NUMBER*2;
  533. if(town->builded >= MAX_BUILDING_PER_TURN)
  534. pom++;
  535. blitAt(graphics->bigTownPic->ourImages[pom].bitmap,15,387,to);
  536. hslotup.show();
  537. hslotdown.show();
  538. pom=false;
  539. if(forceTotalRedraw && !showing)
  540. pom = showing = true;
  541. show();
  542. if(pom)
  543. showing = false;
  544. }
  545. void CCastleInterface::townChange()
  546. {
  547. const CGTownInstance * nt = townlist->items[townlist->selected];
  548. deactivate();
  549. LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
  550. delete this;
  551. LOCPLINT->castleInt = new CCastleInterface(nt,true);
  552. }
  553. void CCastleInterface::show(SDL_Surface * to)
  554. {
  555. if(!showing)
  556. return;
  557. if (!to)
  558. to=screen;
  559. count++;
  560. if(count==8)
  561. {
  562. count=0;
  563. animval++;
  564. }
  565. blitAt(cityBg,0,0,to);
  566. //blit buildings
  567. for(int i=0;i<buildings.size();i++)
  568. {
  569. int frame = ((animval)%(buildings[i]->max - buildings[i]->offset)) + buildings[i]->offset;
  570. if(frame)
  571. {
  572. blitAt(buildings[i]->def->ourImages[0].bitmap,buildings[i]->pos.x,buildings[i]->pos.y,to);
  573. blitAt(buildings[i]->def->ourImages[frame].bitmap,buildings[i]->pos.x,buildings[i]->pos.y,to);
  574. }
  575. else
  576. blitAt(buildings[i]->def->ourImages[frame].bitmap,buildings[i]->pos.x,buildings[i]->pos.y,to);
  577. if(hBuild==buildings[i] && hBuild->border) //if this this higlighted structure and has border we'll blit it
  578. blitAt(hBuild->border,hBuild->pos,to);
  579. }
  580. }
  581. void CCastleInterface::activate()
  582. {
  583. showing = true;
  584. townlist->activate();
  585. garr->activate();
  586. LOCPLINT->curint = this;
  587. LOCPLINT->statusbar = statusbar;
  588. exit->activate();
  589. split->activate();
  590. for(int i=0;i<buildings.size();i++)
  591. buildings[i]->activate();
  592. hslotdown.activate();
  593. hslotup.activate();
  594. }
  595. void CCastleInterface::deactivate()
  596. {
  597. showing = false;
  598. townlist->deactivate();
  599. garr->deactivate();
  600. exit->deactivate();
  601. split->deactivate();
  602. for(int i=0;i<buildings.size();i++)
  603. buildings[i]->deactivate();
  604. hslotdown.deactivate();
  605. hslotup.deactivate();
  606. }
  607. void CCastleInterface::addBuilding(int bid)
  608. {
  609. //TODO: lepiej by bylo tylko dodawac co trzeba pamietajac o grupach
  610. deactivate();
  611. recreateBuildings();
  612. activate();
  613. }
  614. void CCastleInterface::removeBuilding(int bid)
  615. {
  616. //TODO: lepiej by bylo tylko usuwac co trzeba pamietajac o grupach
  617. recreateBuildings();
  618. }
  619. void CCastleInterface::recreateBuildings()
  620. {
  621. for(int i=0;i<buildings.size();i++)
  622. {
  623. if(showing)
  624. buildings[i]->deactivate();
  625. delete buildings[i];
  626. }
  627. buildings.clear();
  628. hBuild = NULL;
  629. std::set< std::pair<int,int> > s; //group - id
  630. for (std::set<si32>::const_iterator i=town->builtBuildings.begin();i!=town->builtBuildings.end();i++)
  631. {
  632. if(CGI->townh->structures.find(town->subID) != CGI->townh->structures.end()) //we have info about structures in this town
  633. {
  634. if(CGI->townh->structures[town->subID].find(*i)!=CGI->townh->structures[town->subID].end()) //we have info about that structure
  635. {
  636. Structure * st = CGI->townh->structures[town->subID][*i];
  637. if(st->group<0) //no group - just add it
  638. {
  639. buildings.push_back(new CBuildingRect(st));
  640. }
  641. else
  642. {
  643. std::set< std::pair<int,int> >::iterator obecny=s.end();
  644. for(std::set< std::pair<int,int> >::iterator seti = s.begin(); seti!=s.end(); seti++) //check if we have already building from same group
  645. {
  646. if(seti->first == st->group)
  647. {
  648. obecny = seti;
  649. break;
  650. }
  651. }
  652. if(obecny != s.end())
  653. {
  654. if((*(CGI->townh->structures[town->subID][obecny->second])) < (*(CGI->townh->structures[town->subID][st->ID]))) //we have to replace old building with current one
  655. {
  656. for(int itpb = 0; itpb<buildings.size(); itpb++)
  657. {
  658. if(buildings[itpb]->str->ID == obecny->second)
  659. {
  660. delete buildings[itpb];
  661. buildings.erase(buildings.begin() + itpb);
  662. #ifndef __GNUC__
  663. obecny->second = st->ID;
  664. #else
  665. *(const_cast<int*>(&(obecny->second))) = st->ID;
  666. #endif
  667. buildings.push_back(new CBuildingRect(st));
  668. }
  669. }
  670. }
  671. }
  672. else
  673. {
  674. buildings.push_back(new CBuildingRect(st));
  675. s.insert(std::pair<int,int>(st->group,st->ID));
  676. }
  677. }
  678. }
  679. else continue;
  680. }
  681. else
  682. break;
  683. }
  684. std::sort(buildings.begin(),buildings.end(),srthlp);
  685. //code for Mana Vortex (there are two sets of animation frames - one without mage guild and one with
  686. if((town->subID == 5) && (town->builtBuildings.find(21)!=town->builtBuildings.end()))
  687. {
  688. CBuildingRect *vortex = NULL;
  689. for(int i=0;i<buildings.size();i++)
  690. {
  691. if(buildings[i]->str->ID==21)
  692. {
  693. vortex=buildings[i];
  694. break;
  695. }
  696. }
  697. if(town->builtBuildings.find(4)!=town->builtBuildings.end()) //there is mage Guild level 5
  698. {
  699. vortex->offset = 10;
  700. vortex->max = vortex->def->ourImages.size();
  701. }
  702. else
  703. {
  704. vortex->offset = 0;
  705. vortex->max = 10;
  706. }
  707. }
  708. //code for the shipyard in the Castle
  709. else if((town->subID == 0) && (town->builtBuildings.find(6)!=town->builtBuildings.end()))
  710. {
  711. CBuildingRect *shipyard = NULL;
  712. for(int i=0;i<buildings.size();i++)
  713. {
  714. if(buildings[i]->str->ID==6)
  715. {
  716. shipyard=buildings[i];
  717. break;
  718. }
  719. }
  720. if(town->builtBuildings.find(8)!=town->builtBuildings.end()) //there is citadel
  721. {
  722. shipyard->offset = 1;
  723. shipyard->max = shipyard->def->ourImages.size();
  724. }
  725. else
  726. {
  727. shipyard->offset = 0;
  728. shipyard->max = 1;
  729. }
  730. }
  731. }
  732. CRecrutationWindow * CCastleInterface::showRecruitmentWindow( int building )
  733. {
  734. if(building>36)
  735. building-=7;
  736. std::vector<std::pair<int,int > > crs;
  737. int amount = (const_cast<CGTownInstance*>(town))->strInfo.creatures[building-30]; //trzeba odconstowac, bo inaczej operator [] by sypal :(
  738. if(town->builtBuildings.find(building+7) != town->builtBuildings.end()) //check if there is an upgraded building
  739. crs.push_back(std::make_pair(town->town->upgradedCreatures[building-30],amount));
  740. crs.push_back(std::make_pair(town->town->basicCreatures[building-30],amount));
  741. CRecrutationWindow *rw = new CRecrutationWindow(crs,boost::bind(&CCallback::recruitCreatures,LOCPLINT->cb,town,_1,_2));
  742. rw->activate();
  743. return rw;
  744. }
  745. void CHallInterface::CBuildingBox::hover(bool on)
  746. {
  747. Hoverable::hover(on);
  748. if(on)
  749. {
  750. std::string toPrint;
  751. if(state==8)
  752. toPrint = CGI->townh->hcommands[5];
  753. else
  754. toPrint = CGI->townh->hcommands[state];
  755. std::vector<std::string> name;
  756. name.push_back(CGI->buildh->buildings[LOCPLINT->castleInt->town->subID][BID]->name);
  757. LOCPLINT->statusbar->print(CSDL_Ext::processStr(toPrint,name));
  758. }
  759. else
  760. LOCPLINT->statusbar->clear();
  761. }
  762. void CHallInterface::CBuildingBox::clickLeft (tribool down)
  763. {
  764. if(pressedL && (!down))
  765. {
  766. LOCPLINT->castleInt->subInt->deactivate();
  767. new CHallInterface::CBuildWindow(LOCPLINT->castleInt->town->subID,BID,state,0);
  768. }
  769. ClickableL::clickLeft(down);
  770. }
  771. void CHallInterface::CBuildingBox::clickRight (tribool down)
  772. {
  773. if(down)
  774. {
  775. LOCPLINT->castleInt->subInt->deactivate();
  776. new CHallInterface::CBuildWindow(LOCPLINT->castleInt->town->subID,BID,state,1);
  777. }
  778. ClickableR::clickRight(down);
  779. }
  780. void CHallInterface::CBuildingBox::show(SDL_Surface * to)
  781. {
  782. CHallInterface *hi = static_cast<CHallInterface*>(LOCPLINT->castleInt->subInt);
  783. blitAt(LOCPLINT->castleInt->bicons->ourImages[BID].bitmap,pos.x,pos.y);
  784. int pom, pom2=-1;
  785. switch (state)
  786. {
  787. case 4:
  788. pom = 0;
  789. pom2 = 0;
  790. break;
  791. case 7:
  792. pom = 1;
  793. break;
  794. case 6:
  795. pom2 = 2;
  796. pom = 2;
  797. break;
  798. case 0: case 5: case 8:
  799. pom2 = 1;
  800. pom = 2;
  801. break;
  802. case 2: case 1: default:
  803. pom = 3;
  804. break;
  805. }
  806. blitAt(hi->bars->ourImages[pom].bitmap,pos.x-1,pos.y+71);
  807. if(pom2>=0)
  808. blitAt(hi->status->ourImages[pom2].bitmap,pos.x+135, pos.y+54);
  809. CSDL_Ext::printAtMiddle(CGI->buildh->buildings[LOCPLINT->castleInt->town->subID][BID]->name,pos.x-1+hi->bars->ourImages[0].bitmap->w/2,pos.y+71+hi->bars->ourImages[0].bitmap->h/2, GEOR13,zwykly);
  810. }
  811. void CHallInterface::CBuildingBox::activate()
  812. {
  813. Hoverable::activate();
  814. ClickableL::activate();
  815. ClickableR::activate();
  816. }
  817. void CHallInterface::CBuildingBox::deactivate()
  818. {
  819. Hoverable::deactivate();
  820. ClickableL::deactivate();
  821. ClickableR::deactivate();
  822. }
  823. CHallInterface::CBuildingBox::~CBuildingBox()
  824. {
  825. }
  826. CHallInterface::CBuildingBox::CBuildingBox(int id)
  827. :BID(id)
  828. {
  829. pos.w = 150;
  830. pos.h = 70;
  831. }
  832. CHallInterface::CBuildingBox::CBuildingBox(int id, int x, int y)
  833. :BID(id)
  834. {
  835. pos.x = x;
  836. pos.y = y;
  837. pos.w = 150;
  838. pos.h = 70;
  839. }
  840. CHallInterface::CHallInterface(CCastleInterface * owner)
  841. {
  842. bg = BitmapHandler::loadBitmap(CGI->buildh->hall[owner->town->subID].first);
  843. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  844. bars = CDefHandler::giveDefEss("TPTHBAR.DEF");
  845. status = CDefHandler::giveDefEss("TPTHCHK.DEF");
  846. exit = new AdventureMapButton
  847. (CGI->townh->tcommands[8],"",boost::bind(&CHallInterface::close,this),748,556,"TPMAGE1.DEF",false,NULL,false);
  848. //preparing boxes with buildings//
  849. boxes.resize(5);
  850. for(int i=0;i<5;i++) //for each row
  851. {
  852. for(int j=0; j<CGI->buildh->hall[owner->town->subID].second[i].size();j++) //for each box
  853. {
  854. int k=0;
  855. for(;k<CGI->buildh->hall[owner->town->subID].second[i][j].size();k++)//we are looking for the first not build structure
  856. {
  857. if(
  858. (owner->town->builtBuildings.find(CGI->buildh->hall[owner->town->subID].second[i][j][k]))
  859. ==
  860. (owner->town->builtBuildings.end()) )
  861. {
  862. int x = 34 + 194*j,
  863. y = 37 + 104*i,
  864. ID = CGI->buildh->hall[owner->town->subID].second[i][j][k];
  865. if(CGI->buildh->hall[owner->town->subID].second[i].size() == 2) //only two boxes in this row
  866. x+=194;
  867. else if(CGI->buildh->hall[owner->town->subID].second[i].size() == 3) //only three boxes in this row
  868. x+=97;
  869. boxes[i].push_back(new CBuildingBox(CGI->buildh->hall[owner->town->subID].second[i][j][k],x,y));
  870. boxes[i][boxes[i].size()-1]->state = 7; //allowed by default
  871. //can we build it?
  872. if(owner->town->forbiddenBuildings.find(CGI->buildh->hall[owner->town->subID].second[i][j][k])!=owner->town->forbiddenBuildings.end())
  873. boxes[i][boxes[i].size()-1]->state = 2; //forbidden
  874. else if(owner->town->builded >= MAX_BUILDING_PER_TURN)
  875. boxes[i][boxes[i].size()-1]->state = 5; //building limit
  876. //checking resources
  877. CBuilding * pom = CGI->buildh->buildings[owner->town->subID][CGI->buildh->hall[owner->town->subID].second[i][j][k]];
  878. for(int res=0;res<7;res++) //TODO: support custom amount of resources
  879. {
  880. if(pom->resources[res]>LOCPLINT->cb->getResourceAmount(res))
  881. boxes[i][boxes[i].size()-1]->state = 6; //lack of res
  882. }
  883. //checking for requirements
  884. for( std::set<int>::iterator ri = CGI->townh->requirements[owner->town->subID][ID].begin();
  885. ri != CGI->townh->requirements[owner->town->subID][ID].end();
  886. ri++ )
  887. {
  888. if(owner->town->builtBuildings.find(*ri)==owner->town->builtBuildings.end())
  889. boxes[i][boxes[i].size()-1]->state = 8; //lack of requirements - cannot build
  890. }
  891. //TODO: check if capital is already built, check if there is water for shipyard
  892. break;
  893. }
  894. }
  895. if(k==CGI->buildh->hall[owner->town->subID].second[i][j].size()) //all buildings built - let's take the last one
  896. {
  897. int x = 34 + 194*j,
  898. y = 37 + 104*i;
  899. if(CGI->buildh->hall[owner->town->subID].second[i].size() == 2)
  900. x+=194;
  901. else if(CGI->buildh->hall[owner->town->subID].second[i].size() == 3)
  902. x+=97;
  903. boxes[i].push_back(new CBuildingBox(CGI->buildh->hall[owner->town->subID].second[i][j][k-1],x,y));
  904. boxes[i][boxes[i].size()-1]->state = 4; //already exists
  905. }
  906. }
  907. }
  908. }
  909. CHallInterface::~CHallInterface()
  910. {
  911. delete bars;
  912. delete status;
  913. SDL_FreeSurface(bg);
  914. for(int i=0;i<boxes.size();i++)
  915. for(int j=0;j<boxes[i].size();j++)
  916. delete boxes[i][j];
  917. delete exit;
  918. }
  919. void CHallInterface::close()
  920. {
  921. deactivate();
  922. delete this;
  923. LOCPLINT->castleInt->activate();
  924. LOCPLINT->castleInt->showAll();
  925. }
  926. void CHallInterface::show(SDL_Surface * to)
  927. {
  928. blitAt(bg,0,0);
  929. resdatabar.show();
  930. exit->show();
  931. for(int i=0; i<5; i++)
  932. {
  933. for(int j=0;j<boxes[i].size();j++)
  934. boxes[i][j]->show();
  935. }
  936. }
  937. void CHallInterface::activate()
  938. {
  939. for(int i=0;i<5;i++)
  940. for(int j=0;j<boxes[i].size();j++)
  941. boxes[i][j]->activate();
  942. exit->activate();
  943. }
  944. void CHallInterface::deactivate()
  945. {
  946. for(int i=0;i<5;i++)
  947. {
  948. for(int j=0;j<boxes[i].size();j++)
  949. {
  950. boxes[i][j]->deactivate();
  951. }
  952. }
  953. exit->deactivate();
  954. }
  955. void CHallInterface::CBuildWindow::activate()
  956. {
  957. LOCPLINT->objsToBlit.push_back(this);
  958. ClickableR::activate();
  959. if(mode)
  960. return;
  961. if(state==7)
  962. buy->activate();
  963. cancel->activate();
  964. }
  965. void CHallInterface::CBuildWindow::deactivate()
  966. {
  967. LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
  968. ClickableR::deactivate();
  969. if(mode)
  970. return;
  971. if(state==7)
  972. buy->deactivate();
  973. cancel->deactivate();
  974. }
  975. void CHallInterface::CBuildWindow::Buy()
  976. {
  977. deactivate();
  978. LOCPLINT->castleInt->subInt = NULL;
  979. LOCPLINT->castleInt->activate();
  980. LOCPLINT->cb->buildBuilding(LOCPLINT->castleInt->town,bid);
  981. delete this;
  982. delete LOCPLINT->castleInt->subInt;
  983. LOCPLINT->castleInt->showAll();
  984. }
  985. void CHallInterface::CBuildWindow::close()
  986. {
  987. deactivate();
  988. delete this;
  989. LOCPLINT->castleInt->subInt->activate();
  990. LOCPLINT->castleInt->subInt->show();
  991. }
  992. void CHallInterface::CBuildWindow::clickRight (tribool down)
  993. {
  994. if((!down || indeterminate(down)) && mode)
  995. close();
  996. }
  997. void CHallInterface::CBuildWindow::show(SDL_Surface * to)
  998. {
  999. SDL_Rect pom = genRect(bitmap->h-1,bitmap->w-1,pos.x,pos.y);
  1000. SDL_Rect poms = pom; poms.x=0;poms.y=0;
  1001. SDL_BlitSurface(bitmap,&poms,to?to:screen,&pom);
  1002. if(!mode)
  1003. {
  1004. buy->show();
  1005. cancel->show();
  1006. }
  1007. }
  1008. std::string CHallInterface::CBuildWindow::getTextForState(int state)
  1009. {
  1010. std::string ret;
  1011. if(state<7)
  1012. ret = CGI->townh->hcommands[state];
  1013. switch (state)
  1014. {
  1015. case 4: case 5: case 6:
  1016. ret.replace(ret.find_first_of("%s"),2,CGI->buildh->buildings[tid][bid]->name);
  1017. break;
  1018. case 7:
  1019. return CGI->generaltexth->allTexts[219]; //all prereq. are met
  1020. case 8:
  1021. {
  1022. ret = CGI->generaltexth->allTexts[52];
  1023. std::set<int> used;
  1024. used.insert(bid);
  1025. std::set<int> reqs;
  1026. for(std::set<int>::iterator i=CGI->townh->requirements[tid][bid].begin();i!=CGI->townh->requirements[tid][bid].end();i++)
  1027. if (LOCPLINT->castleInt->town->builtBuildings.find(*i) == LOCPLINT->castleInt->town->builtBuildings.end())
  1028. reqs.insert(*i);
  1029. while(true)
  1030. {
  1031. int czystych=0;
  1032. for(std::set<int>::iterator i=reqs.begin();i!=reqs.end();i++)
  1033. {
  1034. if(used.find(*i)==used.end()) //we haven't added requirements for this building
  1035. {
  1036. used.insert(*i);
  1037. for(
  1038. std::set<int>::iterator j=CGI->townh->requirements[tid][*i].begin();
  1039. j!=CGI->townh->requirements[tid][*i].end();
  1040. j++
  1041. )
  1042. {
  1043. if(LOCPLINT->castleInt->town->builtBuildings.find(*j) == //this building is not built
  1044. LOCPLINT->castleInt->town->builtBuildings.end())
  1045. reqs.insert(*j);
  1046. }
  1047. }
  1048. else
  1049. {
  1050. czystych++;
  1051. }
  1052. }
  1053. if(czystych==reqs.size())
  1054. break;
  1055. }
  1056. bool first=true;
  1057. for(std::set<int>::iterator i=reqs.begin();i!=reqs.end();i++)
  1058. {
  1059. ret+=(((first)?(" "):(", ")) + CGI->buildh->buildings[tid][*i]->name);
  1060. first = false;
  1061. }
  1062. }
  1063. }
  1064. return ret;
  1065. }
  1066. CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mode)
  1067. :tid(Tid),bid(Bid),mode(Mode), state(State)
  1068. {
  1069. SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPUBUILD.bmp");
  1070. graphics->blueToPlayersAdv(hhlp,LOCPLINT->playerID);
  1071. bitmap = SDL_ConvertSurface(hhlp,screen->format,0); //na 8bitowej mapie by sie psulo
  1072. SDL_SetColorKey(hhlp,SDL_SRCCOLORKEY,SDL_MapRGB(hhlp->format,0,255,255));
  1073. SDL_FreeSurface(hhlp);
  1074. pos.x = screen->w/2 - bitmap->w/2;
  1075. pos.y = screen->h/2 - bitmap->h/2;
  1076. blitAt(LOCPLINT->castleInt->bicons->ourImages[bid].bitmap,125,50,bitmap);
  1077. std::vector<std::string> pom; pom.push_back(CGI->buildh->buildings[tid][bid]->name);
  1078. CSDL_Ext::printAtMiddleWB(CGI->buildh->buildings[tid][bid]->description,197,168,GEOR16,40,zwykly,bitmap);
  1079. CSDL_Ext::printAtMiddleWB(getTextForState(state),197,248,GEOR13,50,zwykly,bitmap);
  1080. CSDL_Ext::printAtMiddle(CSDL_Ext::processStr(CGI->townh->hcommands[7],pom),197,30,GEOR16,tytulowy,bitmap);
  1081. int resamount=0; for(int i=0;i<7;i++) if(CGI->buildh->buildings[tid][bid]->resources[i]) resamount++;
  1082. int ah = (resamount>4) ? 304 : 341;
  1083. int cn=-1, it=0;
  1084. int row1w = std::min(resamount,4) * 32 + (std::min(resamount,4)-1) * 45,
  1085. row2w = (resamount-4) * 32 + (resamount-5) * 45;
  1086. char buf[15];
  1087. while(++cn<7)
  1088. {
  1089. if(!CGI->buildh->buildings[tid][bid]->resources[cn])
  1090. continue;
  1091. SDL_itoa(CGI->buildh->buildings[tid][bid]->resources[cn],buf,10);
  1092. if(it<4)
  1093. {
  1094. CSDL_Ext::printAtMiddle(buf,(bitmap->w/2-row1w/2)+77*it+16,ah+42,GEOR16,zwykly,bitmap);
  1095. blitAt(graphics->resources32->ourImages[cn].bitmap,(bitmap->w/2-row1w/2)+77*it++,ah,bitmap);
  1096. }
  1097. else
  1098. {
  1099. CSDL_Ext::printAtMiddle(buf,(bitmap->w/2-row2w/2)+77*it+16-308,ah+42,GEOR16,zwykly,bitmap);
  1100. blitAt(graphics->resources32->ourImages[cn].bitmap,(bitmap->w/2-row2w/2)+77*it++ - 308,ah,bitmap);
  1101. }
  1102. if(it==4)
  1103. ah+=75;
  1104. }
  1105. if(!mode)
  1106. {
  1107. buy = new AdventureMapButton
  1108. ("","",boost::bind(&CBuildWindow::Buy,this),pos.x+45,pos.y+446,"IBUY30.DEF",false,NULL,false);
  1109. cancel = new AdventureMapButton
  1110. ("","",boost::bind(&CBuildWindow::close,this),pos.x+290,pos.y+445,"ICANCEL.DEF",false,NULL,false);
  1111. if(state!=7)
  1112. buy->state=2;
  1113. }
  1114. activate();
  1115. }
  1116. CHallInterface::CBuildWindow::~CBuildWindow()
  1117. {
  1118. SDL_FreeSurface(bitmap);
  1119. if(!mode)
  1120. {
  1121. delete buy;
  1122. delete cancel;
  1123. }
  1124. }
  1125. CFortScreen::~CFortScreen()
  1126. {
  1127. for(int i=0;i<crePics.size();i++)
  1128. delete crePics[i];
  1129. for (int i=0;i<recAreas.size();i++)
  1130. delete recAreas[i];
  1131. SDL_FreeSurface(bg);
  1132. delete exit;
  1133. }
  1134. void CFortScreen::show( SDL_Surface * to)
  1135. {
  1136. blitAt(bg,0,0);
  1137. static unsigned char anim = 1;
  1138. for (int i=0; i<CREATURES_PER_TOWN; i++)
  1139. {
  1140. crePics[i]->blitPic(screen,positions[i].x+159,positions[i].y+4,!(anim%4));
  1141. }
  1142. anim++;
  1143. exit->show();
  1144. }
  1145. void CFortScreen::activate()
  1146. {
  1147. LOCPLINT->curint = this;
  1148. exit->activate();
  1149. for (int i=0;i<recAreas.size();i++)
  1150. {
  1151. recAreas[i]->activate();
  1152. }
  1153. LOCPLINT->objsToBlit -= LOCPLINT->castleInt;
  1154. LOCPLINT->objsToBlit += this;
  1155. }
  1156. void CFortScreen::deactivate()
  1157. {
  1158. exit->deactivate();
  1159. for (int i=0;i<recAreas.size();i++)
  1160. {
  1161. recAreas[i]->deactivate();
  1162. }
  1163. LOCPLINT->objsToBlit -= this;
  1164. LOCPLINT->objsToBlit += LOCPLINT->castleInt;
  1165. }
  1166. void CFortScreen::close()
  1167. {
  1168. deactivate();
  1169. delete this;
  1170. LOCPLINT->castleInt->activate();
  1171. LOCPLINT->castleInt->showAll();
  1172. }
  1173. CFortScreen::CFortScreen( CCastleInterface * owner )
  1174. {
  1175. bg = NULL;
  1176. exit = new AdventureMapButton(CGI->townh->tcommands[8],"",boost::bind(&CFortScreen::close,this),748,556,"TPMAGE1.DEF",false,NULL,false);
  1177. positions += genRect(126,386,10,22),genRect(126,386,404,22),
  1178. genRect(126,386,10,155),genRect(126,386,404,155),
  1179. genRect(126,386,10,288),genRect(126,386,404,288),
  1180. genRect(126,386,206,421);//genRect(126,386,10,421),genRect(126,386,404,421);
  1181. draw(owner,true);
  1182. }
  1183. void CFortScreen::draw( CCastleInterface * owner, bool first)
  1184. {
  1185. if(bg)
  1186. SDL_FreeSurface(bg);
  1187. char buf[20];
  1188. memset(buf,0,20);
  1189. SDL_Surface *bg2 = BitmapHandler::loadBitmap("TPCASTL7.bmp"),
  1190. *icons = BitmapHandler::loadBitmap("ZPCAINFO.bmp");
  1191. SDL_SetColorKey(icons,SDL_SRCCOLORKEY,SDL_MapRGB(icons->format,0,255,255));
  1192. graphics->blueToPlayersAdv(bg2,LOCPLINT->playerID);
  1193. bg = SDL_ConvertSurface(bg2,screen->format,0);
  1194. SDL_FreeSurface(bg2);
  1195. printAtMiddle(CGI->buildh->buildings[owner->town->subID][owner->town->fortLevel()+6]->name,400,13,GEORXX,zwykly,bg);
  1196. for(int i=0;i<CREATURES_PER_TOWN; i++)
  1197. {
  1198. bool upgraded = owner->town->creatureDwelling(i,true);
  1199. bool present = owner->town->creatureDwelling(i,false);
  1200. CCreature *c = &CGI->creh->creatures[upgraded ? owner->town->town->upgradedCreatures[i] : owner->town->town->basicCreatures[i]];
  1201. printAtMiddle(c->namePl,positions[i].x+79,positions[i].y+10,GEOR13,zwykly,bg); //cr. name
  1202. blitAt(owner->bicons->ourImages[30+i+upgraded*7].bitmap,positions[i].x+4,positions[i].y+21,bg); //dwelling pic
  1203. printAtMiddle(CGI->buildh->buildings[owner->town->subID][30+i+upgraded*7]->name,positions[i].x+79,positions[i].y+100,GEOR13,zwykly,bg); //dwelling name
  1204. if(present) //if creature is present print avail able quantity
  1205. {
  1206. SDL_itoa(owner->town->strInfo.creatures.find(i)->second,buf,10);
  1207. printAtMiddle(CGI->generaltexth->allTexts[217] + buf,positions[i].x+79,positions[i].y+118,GEOR13,zwykly,bg);
  1208. }
  1209. blitAt(icons,positions[i].x+261,positions[i].y+3,bg);
  1210. //atttack
  1211. printAt(CGI->generaltexth->allTexts[190],positions[i].x+288,positions[i].y+5,GEOR13,zwykly,bg);
  1212. SDL_itoa(c->attack,buf,10);
  1213. printToWR(buf,positions[i].x+381,positions[i].y+18,GEOR13,zwykly,bg);
  1214. //defense
  1215. printAt(CGI->generaltexth->allTexts[191],positions[i].x+288,positions[i].y+25,GEOR13,zwykly,bg);
  1216. SDL_itoa(c->defence,buf,10);
  1217. printToWR(buf,positions[i].x+381,positions[i].y+38,GEOR13,zwykly,bg);
  1218. //damage
  1219. printAt(CGI->generaltexth->allTexts[199],positions[i].x+288,positions[i].y+46,GEOR13,zwykly,bg);
  1220. SDL_itoa(c->damageMin,buf,10);
  1221. int hlp=log10f(c->damageMin)+2;
  1222. buf[hlp-1]=' '; buf[hlp]='-'; buf[hlp+1]=' ';
  1223. SDL_itoa(c->damageMax,buf+hlp+2,10);
  1224. printToWR(buf,positions[i].x+381,positions[i].y+59,GEOR13,zwykly,bg);
  1225. //health
  1226. printAt(CGI->preth->zelp[439].first,positions[i].x+288,positions[i].y+66,GEOR13,zwykly,bg);
  1227. SDL_itoa(c->hitPoints,buf,10);
  1228. printToWR(buf,positions[i].x+381,positions[i].y+79,GEOR13,zwykly,bg);
  1229. //speed
  1230. printAt(CGI->preth->zelp[441].first,positions[i].x+288,positions[i].y+87,GEOR13,zwykly,bg);
  1231. SDL_itoa(c->speed,buf,10);
  1232. printToWR(buf,positions[i].x+381,positions[i].y+100,GEOR13,zwykly,bg);
  1233. if(present)//growth
  1234. {
  1235. printAt(CGI->generaltexth->allTexts[194],positions[i].x+288,positions[i].y+107,GEOR13,zwykly,bg);
  1236. SDL_itoa(owner->town->creatureGrowth(i),buf,10);
  1237. printToWR(buf,positions[i].x+381,positions[i].y+120,GEOR13,zwykly,bg);
  1238. }
  1239. if(first)
  1240. {
  1241. crePics.push_back(new CCreaturePic(c,false));
  1242. if(present)
  1243. {
  1244. recAreas.push_back(new RecArea(30+i+upgraded*7));
  1245. recAreas[recAreas.size()-1]->pos = positions[i];
  1246. }
  1247. }
  1248. }
  1249. SDL_FreeSurface(icons);
  1250. }
  1251. void CFortScreen::RecArea::clickLeft (tribool down)
  1252. {
  1253. if(!down)
  1254. {
  1255. LOCPLINT->curint->deactivate();
  1256. CRecrutationWindow *rw = LOCPLINT->castleInt->showRecruitmentWindow(bid);
  1257. rw->buy->callback += boost::bind(&CFortScreen::draw, static_cast<CFortScreen*>(LOCPLINT->curint), LOCPLINT->castleInt, false);
  1258. }
  1259. }
  1260. void CFortScreen::RecArea::activate()
  1261. {
  1262. ClickableL::activate();
  1263. }
  1264. void CFortScreen::RecArea::deactivate()
  1265. {
  1266. ClickableL::deactivate();
  1267. }