CPlayerInterface.cpp 123 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992
  1. #include "stdafx.h"
  2. #include "CAdvmapInterface.h"
  3. #include "CBattleInterface.h"
  4. #include "CCallback.h"
  5. #include "CCastleInterface.h"
  6. #include "CCursorHandler.h"
  7. #include "CGameInfo.h"
  8. #include "CHeroWindow.h"
  9. #include "CMessage.h"
  10. #include "CPathfinder.h"
  11. #include "CPlayerInterface.h"
  12. #include "SDL_Extensions.h"
  13. #include "SDL_Extensions.h"
  14. #include "SDL_framerate.h"
  15. #include "SDL_framerate.h"
  16. #include "client/CCreatureAnimation.h"
  17. #include "client/Graphics.h"
  18. #include "hch/CAbilityHandler.h"
  19. #include "hch/CArtHandler.h"
  20. #include "hch/CGeneralTextHandler.h"
  21. #include "hch/CHeroHandler.h"
  22. #include "hch/CLodHandler.h"
  23. #include "hch/CObjectHandler.h"
  24. #include "hch/CPreGameTextHandler.h"
  25. #include "hch/CSpellHandler.h"
  26. #include "hch/CTownHandler.h"
  27. #include "lib/CondSh.h"
  28. #include "lib/NetPacks.h"
  29. #include "map.h"
  30. #include "mapHandler.h"
  31. #include "timeHandler.h"
  32. #include <boost/algorithm/string.hpp>
  33. #include <boost/algorithm/string/replace.hpp>
  34. #include <boost/assign/std/vector.hpp>
  35. #include <boost/assign/list_of.hpp>
  36. #include <boost/thread.hpp>
  37. #include <cmath>
  38. #include <queue>
  39. #include <sstream>
  40. #ifdef min
  41. #undef min
  42. #endif
  43. #ifdef max
  44. #undef max
  45. #endif
  46. using namespace boost::assign;
  47. using namespace CSDL_Ext;
  48. extern TTF_Font * GEOR16;
  49. CPlayerInterface * LOCPLINT;
  50. extern std::queue<SDL_Event> events;
  51. extern boost::mutex eventsM;
  52. class OCM_HLP_CGIN
  53. {
  54. public:
  55. bool operator ()(const std::pair<const CGObjectInstance*,SDL_Rect> & a, const std::pair<const CGObjectInstance*,SDL_Rect> & b) const
  56. {
  57. return (*a.first)<(*b.first);
  58. }
  59. } ocmptwo_cgin ;
  60. void CGarrisonSlot::hover (bool on)
  61. {
  62. Hoverable::hover(on);
  63. if(on)
  64. {
  65. std::string temp;
  66. if(creature)
  67. {
  68. if(owner->highlighted)
  69. {
  70. if(owner->highlighted == this)
  71. {
  72. temp = CGI->townh->tcommands[4];
  73. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  74. }
  75. else if (owner->highlighted->creature == creature)
  76. {
  77. temp = CGI->townh->tcommands[2];
  78. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  79. }
  80. else if (owner->highlighted->creature)
  81. {
  82. temp = CGI->townh->tcommands[7];
  83. boost::algorithm::replace_first(temp,"%s",owner->highlighted->creature->nameSing);
  84. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  85. }
  86. else
  87. {
  88. tlog2 << "Warning - shouldn't be - highlighted void slot "<<owner->highlighted<<std::endl;
  89. tlog2 << "Highlighted set to NULL"<<std::endl;
  90. owner->highlighted = NULL;
  91. }
  92. }
  93. else
  94. {
  95. if(upg)
  96. {
  97. temp = CGI->townh->tcommands[32];
  98. }
  99. else
  100. {
  101. temp = CGI->townh->tcommands[12];
  102. }
  103. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  104. };
  105. }
  106. else
  107. {
  108. if(owner->highlighted)
  109. {
  110. temp = CGI->townh->tcommands[6];
  111. boost::algorithm::replace_first(temp,"%s",owner->highlighted->creature->nameSing);
  112. }
  113. else
  114. {
  115. temp = CGI->townh->tcommands[11];
  116. }
  117. }
  118. LOCPLINT->statusbar->print(temp);
  119. }
  120. else
  121. {
  122. LOCPLINT->statusbar->clear();
  123. }
  124. }
  125. const CArmedInstance * CGarrisonSlot::getObj()
  126. {
  127. return (!upg)?(owner->oup):(owner->odown);
  128. }
  129. void CGarrisonSlot::clickRight (tribool down)
  130. {
  131. StackState *pom = NULL;
  132. if(down && creature)
  133. {
  134. if(getObj()->ID == 34)
  135. {
  136. pom = new StackState();
  137. const CGHeroInstance *h = static_cast<const CGHeroInstance *>(getObj());
  138. pom->currentHealth = 0;
  139. pom->attackBonus = h->getPrimSkillLevel(0);
  140. pom->defenseBonus = h->getPrimSkillLevel(1);
  141. pom->luck = h->getCurrentLuck();
  142. pom->morale = h->getCurrentMorale();
  143. }
  144. (new CCreInfoWindow(creature->idNumber,0,count,pom,boost::function<void()>(),boost::function<void()>(),NULL))
  145. ->activate();
  146. //LOCPLINT->curint->deactivate();
  147. }
  148. delete pom;
  149. }
  150. void CGarrisonSlot::clickLeft(tribool down)
  151. {
  152. if(owner->ignoreEvent)
  153. {
  154. owner->ignoreEvent = false;
  155. return;
  156. }
  157. if(down)
  158. {
  159. bool refr = false;
  160. if(owner->highlighted)
  161. {
  162. if(owner->highlighted == this) //view info
  163. {
  164. UpgradeInfo pom = LOCPLINT->cb->getUpgradeInfo(getObj(),ID);
  165. if(pom.oldID>=0)
  166. {
  167. (new CCreInfoWindow
  168. (creature->idNumber,1,count,NULL,
  169. boost::bind(&CCallback::upgradeCreature,LOCPLINT->cb,getObj(),ID,pom.newID[0]), //if upgrade is possible we'll bind proper function in callback
  170. boost::bind(&CCallback::dismissCreature,LOCPLINT->cb,getObj(),ID),&pom))
  171. ->activate();
  172. }
  173. else
  174. {
  175. (new CCreInfoWindow
  176. (creature->idNumber,1,count,NULL,0, boost::bind(&CCallback::dismissCreature,LOCPLINT->cb,getObj(),ID),NULL) )
  177. ->activate();
  178. }
  179. if(LOCPLINT->curint->subInt)
  180. LOCPLINT->curint->subInt->deactivate();
  181. else
  182. LOCPLINT->curint->deactivate();
  183. owner->highlighted = NULL;
  184. show();
  185. refr = true;
  186. }
  187. else if( !creature && owner->splitting)//split
  188. {
  189. owner->p2 = ID;
  190. owner->pb = upg;
  191. owner->splitting = false;
  192. LOCPLINT->curint->deactivate();
  193. CSplitWindow * spw = new CSplitWindow(owner->highlighted->creature->idNumber,owner->highlighted->count, owner);
  194. spw->activate();
  195. refr = true;
  196. }
  197. else if(creature != owner->highlighted->creature) //swap
  198. {
  199. LOCPLINT->cb->swapCreatures(
  200. (!upg)?(owner->oup):(owner->odown),
  201. (!owner->highlighted->upg)?(owner->oup):(owner->odown),
  202. ID,owner->highlighted->ID);
  203. }
  204. else //merge
  205. {
  206. LOCPLINT->cb->mergeStacks(
  207. (!owner->highlighted->upg)?(owner->oup):(owner->odown),
  208. (!upg)?(owner->oup):(owner->odown),
  209. owner->highlighted->ID,ID);
  210. }
  211. }
  212. else //highlight
  213. {
  214. if(creature)
  215. owner->highlighted = this;
  216. show();
  217. refr = true;
  218. }
  219. if(refr) {hover(false); hover(true); } //to refresh statusbar
  220. }
  221. }
  222. void CGarrisonSlot::activate()
  223. {
  224. if(!active) active=true;
  225. else return;
  226. ClickableL::activate();
  227. ClickableR::activate();
  228. Hoverable::activate();
  229. }
  230. void CGarrisonSlot::deactivate()
  231. {
  232. if(active) active=false;
  233. else return;
  234. ClickableL::deactivate();
  235. ClickableR::deactivate();
  236. Hoverable::deactivate();
  237. }
  238. CGarrisonSlot::CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg, const CCreature * Creature, int Count)
  239. {
  240. active = false;
  241. upg = Upg;
  242. count = Count;
  243. ID = IID;
  244. creature = Creature;
  245. pos.x = x;
  246. pos.y = y;
  247. pos.w = 58;
  248. pos.h = 64;
  249. owner = Owner;
  250. }
  251. CGarrisonSlot::~CGarrisonSlot()
  252. {
  253. if(active)
  254. deactivate();
  255. }
  256. void CGarrisonSlot::show()
  257. {
  258. if(creature)
  259. {
  260. char* buf = new char[15];
  261. SDL_itoa(count,buf,10);
  262. blitAt(graphics->bigImgs[creature->idNumber],pos);
  263. printToWR(buf,pos.x+56,pos.y+62,GEOR16,zwykly);
  264. if(owner->highlighted==this)
  265. blitAt(graphics->bigImgs[-1],pos);
  266. //if(owner->update)
  267. // updateRect(&pos,screen);
  268. delete [] buf;
  269. }
  270. else
  271. {
  272. SDL_Rect jakis1 = genRect(pos.h,pos.w,owner->offx+ID*(pos.w+owner->interx),owner->offy+upg*(pos.h+owner->intery)), jakis2 = pos;
  273. SDL_BlitSurface(owner->sur,&jakis1,screen,&jakis2);
  274. if(owner->splitting)
  275. blitAt(graphics->bigImgs[-1],pos);
  276. //if(owner->update)
  277. // SDL_UpdateRect(screen,pos.x,pos.y,pos.w,pos.h);
  278. }
  279. }
  280. CGarrisonInt::~CGarrisonInt()
  281. {
  282. if(sup)
  283. {
  284. for(int i=0;i<sup->size();i++)
  285. delete (*sup)[i];
  286. delete sup;
  287. }
  288. if(sdown)
  289. {
  290. for(int i=0;i<sdown->size();i++)
  291. delete (*sdown)[i];
  292. delete sdown;
  293. }
  294. }
  295. void CGarrisonInt::show()
  296. {
  297. if(sup)
  298. {
  299. for(int i = 0; i<sup->size(); i++)
  300. if((*sup)[i])
  301. (*sup)[i]->show();
  302. }
  303. if(sdown)
  304. {
  305. for(int i = 0; i<sdown->size(); i++)
  306. if((*sdown)[i])
  307. (*sdown)[i]->show();
  308. }
  309. }
  310. void CGarrisonInt::deactiveteSlots()
  311. {
  312. if(sup)
  313. {
  314. for(int i = 0; i<sup->size(); i++)
  315. {
  316. if((*sup)[i])
  317. {
  318. (*sup)[i]->deactivate();
  319. }
  320. }
  321. }
  322. if(sdown)
  323. {
  324. for(int i = 0; i<sdown->size(); i++)
  325. {
  326. if((*sdown)[i])
  327. {
  328. (*sdown)[i]->deactivate();
  329. }
  330. }
  331. }
  332. }
  333. void CGarrisonInt::activeteSlots()
  334. {
  335. if(sup)
  336. {
  337. for(int i = 0; i<sup->size(); i++)
  338. {
  339. if((*sup)[i])
  340. {
  341. (*sup)[i]->activate();
  342. }
  343. }
  344. }
  345. if(sdown)
  346. {
  347. for(int i = 0; i<sdown->size(); i++)
  348. {
  349. if((*sdown)[i])
  350. {
  351. (*sdown)[i]->activate();
  352. }
  353. }
  354. }
  355. }
  356. void CGarrisonInt::createSlots()
  357. {
  358. if(set1)
  359. {
  360. sup = new std::vector<CGarrisonSlot*>(7,(CGarrisonSlot *)(NULL));
  361. for
  362. (std::map<si32,std::pair<ui32,si32> >::const_iterator i=set1->slots.begin();
  363. i!=set1->slots.end(); i++)
  364. {
  365. (*sup)[i->first] =
  366. new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y,i->first, 0, &CGI->creh->creatures[i->second.first],i->second.second);
  367. }
  368. for(int i=0; i<sup->size(); i++)
  369. if((*sup)[i] == NULL)
  370. (*sup)[i] = new CGarrisonSlot(this, pos.x + (i*(58+interx)), pos.y,i,0,NULL, 0);
  371. }
  372. if(set2)
  373. {
  374. sdown = new std::vector<CGarrisonSlot*>(7,(CGarrisonSlot *)(NULL));
  375. for
  376. (std::map<si32,std::pair<ui32,si32> >::const_iterator i=set2->slots.begin();
  377. i!=set2->slots.end(); i++)
  378. {
  379. (*sdown)[i->first] =
  380. new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y + 64 + intery,i->first,1, &CGI->creh->creatures[i->second.first],i->second.second);
  381. }
  382. for(int i=0; i<sup->size(); i++)
  383. if((*sdown)[i] == NULL)
  384. (*sdown)[i] = new CGarrisonSlot(this, pos.x + (i*(58+interx)), pos.y + 64 + intery,i,1, NULL, 0);
  385. }
  386. }
  387. void CGarrisonInt::deleteSlots()
  388. {
  389. if(sup)
  390. {
  391. for(int i = 0; i<sup->size(); i++)
  392. {
  393. if((*sup)[i])
  394. {
  395. delete (*sup)[i];
  396. }
  397. }
  398. delete sup;
  399. sup = NULL;
  400. }
  401. if(sdown)
  402. {
  403. for(int i = 0; i<sdown->size(); i++)
  404. {
  405. if((*sdown)[i])
  406. {
  407. delete (*sdown)[i];
  408. }
  409. }
  410. delete sdown;
  411. sdown = NULL;
  412. }
  413. }
  414. void CGarrisonInt::recreateSlots()
  415. {
  416. splitting = false;
  417. highlighted = NULL;
  418. if(active)
  419. {
  420. deactiveteSlots();
  421. }
  422. deleteSlots();
  423. createSlots();
  424. if(active)
  425. {
  426. //ignoreEvent = true;
  427. activeteSlots();
  428. show();
  429. }
  430. }
  431. void CGarrisonInt::splitClick()
  432. {
  433. if(!highlighted)
  434. return;
  435. splitting = !splitting;
  436. show();
  437. }
  438. void CGarrisonInt::splitStacks(int am2)
  439. {
  440. LOCPLINT->cb->splitStack(
  441. (highlighted->upg)?(odown):(oup),
  442. (pb)?(odown):(oup),
  443. highlighted->ID,
  444. p2,
  445. am2);
  446. }
  447. CGarrisonInt::CGarrisonInt(int x, int y, int inx, int iny, SDL_Surface *pomsur, int OX, int OY, const CArmedInstance *s1, const CArmedInstance *s2)
  448. :interx(inx),intery(iny),sur(pomsur),highlighted(NULL),sup(NULL),sdown(NULL),oup(s1),odown(s2),
  449. offx(OX),offy(OY)
  450. {
  451. active = false;
  452. splitting = false;
  453. set1 = LOCPLINT->cb->getGarrison(s1);
  454. set2 = LOCPLINT->cb->getGarrison(s2);
  455. ignoreEvent = false;
  456. update = true;
  457. pos.x=(x);
  458. pos.y=(y);
  459. pos.w=(58);
  460. pos.h=(64);
  461. createSlots();
  462. }
  463. void CGarrisonInt::activate()
  464. {
  465. active = true;
  466. if(sup)
  467. {
  468. for(int i = 0; i<sup->size(); i++)
  469. if((*sup)[i])
  470. (*sup)[i]->activate();
  471. }
  472. if(sdown)
  473. {
  474. for(int i = 0; i<sdown->size(); i++)
  475. if((*sdown)[i])
  476. (*sdown)[i]->activate();
  477. }
  478. }
  479. void CGarrisonInt::deactivate()
  480. {
  481. active = false;
  482. deactiveteSlots();
  483. }
  484. CInfoWindow::CInfoWindow(std::string text, int player, int charperline, const std::vector<SComponent*> &comps, std::vector<std::pair<std::string,CFunctionList<void()> > > &Buttons)
  485. {
  486. for(int i=0;i<Buttons.size();i++)
  487. {
  488. buttons.push_back(new AdventureMapButton("","",Buttons[i].second,0,0,Buttons[i].first));
  489. if(!Buttons[i].second) //if no function, then by default we'll set it to close
  490. {
  491. buttons[i]->ourKey = SDLK_RETURN;
  492. buttons[i]->callback += boost::bind(&CInfoWindow::close,this);
  493. }
  494. }
  495. for(int i=0;i<comps.size();i++)
  496. {
  497. components.push_back(comps[i]);
  498. }
  499. CMessage::drawIWindow(this,text,player,charperline);
  500. }
  501. CInfoWindow::CInfoWindow()
  502. {
  503. }
  504. void CInfoWindow::close()
  505. {
  506. deactivate();
  507. delete this;
  508. LOCPLINT->showingDialog->setn(false);
  509. }
  510. void CInfoWindow::show(SDL_Surface * to)
  511. {
  512. CSimpleWindow::show();
  513. for(int i=0;i<buttons.size();i++)
  514. buttons[i]->show();
  515. }
  516. CInfoWindow::~CInfoWindow()
  517. {
  518. if(delComps)
  519. {
  520. for (int i=0;i<components.size();i++)
  521. delete components[i];
  522. }
  523. for(int i=0;i<buttons.size();i++)
  524. delete buttons[i];
  525. }
  526. void CInfoWindow::activate()
  527. {
  528. for (int i=0;i<components.size();i++)
  529. components[i]->activate();
  530. for(int i=0;i<buttons.size();i++)
  531. buttons[i]->activate();
  532. }
  533. void CInfoWindow::deactivate()
  534. {
  535. for (int i=0;i<components.size();i++)
  536. components[i]->deactivate();
  537. for(int i=0;i<buttons.size();i++)
  538. buttons[i]->deactivate();
  539. LOCPLINT->removeObjToBlit(this);
  540. }
  541. void CRClickPopup::clickRight (tribool down)
  542. {
  543. if(down)
  544. return;
  545. close();
  546. }
  547. void CRClickPopup::activate()
  548. {
  549. ClickableR::activate();
  550. LOCPLINT->objsToBlit.push_back(this);
  551. }
  552. void CRClickPopup::deactivate()
  553. {
  554. ClickableR::deactivate();
  555. LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
  556. }
  557. CInfoPopup::CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free)
  558. :bitmap(Bitmap),free(Free)
  559. {
  560. pos.x = x;
  561. pos.y = y;
  562. pos.h = bitmap->h;
  563. pos.w = bitmap->w;
  564. }
  565. void CInfoPopup::close()
  566. {
  567. deactivate();
  568. if(free)
  569. SDL_FreeSurface(bitmap);
  570. delete this;
  571. if(LOCPLINT->curint == LOCPLINT->adventureInt)
  572. LOCPLINT->adventureInt->show();
  573. else if((LOCPLINT->curint == LOCPLINT->castleInt) && !LOCPLINT->castleInt->subInt)
  574. LOCPLINT->castleInt->showAll();
  575. }
  576. void CInfoPopup::show(SDL_Surface * to)
  577. {
  578. blitAt(bitmap,pos.x,pos.y,(to)?(to):(screen));
  579. }
  580. void SComponent::init(Etype Type, int Subtype, int Val)
  581. {
  582. std::ostringstream oss;
  583. switch (Type)
  584. {
  585. case artifact:
  586. description = CGI->arth->artifacts[Subtype].description;
  587. subtitle = CGI->arth->artifacts[Subtype].name;
  588. break;
  589. case primskill:
  590. description = CGI->generaltexth->arraytxt[2+Subtype];
  591. oss << ((Val>0)?("+"):("-")) << Val << " " << CGI->heroh->pskillsn[Subtype];
  592. subtitle = oss.str();
  593. break;
  594. case secskill44:
  595. subtitle += CGI->abilh->levels[Val-1] + " " + CGI->abilh->abilities[Subtype]->name;
  596. description = CGI->abilh->abilities[Subtype]->infoTexts[Val-1];
  597. break;
  598. case resource:
  599. description = CGI->generaltexth->allTexts[242];
  600. oss << Val;
  601. subtitle = oss.str();
  602. break;
  603. case spell:
  604. description = CGI->spellh->spells[Subtype].descriptions[Val];
  605. subtitle = CGI->spellh->spells[Subtype].name;
  606. break;
  607. case experience:
  608. description = CGI->generaltexth->allTexts[241];
  609. oss << Val ;
  610. if(Subtype && Val==1)
  611. {
  612. subtitle = CGI->generaltexth->allTexts[442];
  613. }
  614. else
  615. {
  616. subtitle = oss.str();
  617. }
  618. break;
  619. }
  620. type = Type;
  621. subtype = Subtype;
  622. val = Val;
  623. SDL_Surface * temp = this->getImg();
  624. pos.w = temp->w;
  625. pos.h = temp->h;
  626. }
  627. SComponent::SComponent(Etype Type, int Subtype, int Val)
  628. {
  629. init(Type,Subtype,Val);
  630. }
  631. SComponent::SComponent(const Component &c)
  632. {
  633. if(c.id==5)
  634. init(experience,c.subtype,c.val);
  635. else
  636. init((Etype)c.id,c.subtype,c.val);
  637. if(c.id==2 && c.when==-1)
  638. subtitle += CGI->generaltexth->allTexts[3].substr(2,CGI->generaltexth->allTexts[3].length()-2);
  639. }
  640. void SComponent::show(SDL_Surface * to)
  641. {
  642. blitAt(getImg(),pos.x,pos.y,to);
  643. }
  644. SDL_Surface * SComponent::getImg()
  645. {
  646. switch (type)
  647. {
  648. case artifact:
  649. return graphics->artDefs->ourImages[subtype].bitmap;
  650. break;
  651. case primskill:
  652. return graphics->pskillsb->ourImages[subtype].bitmap;
  653. break;
  654. case secskill44:
  655. return CGI->abilh->abils44->ourImages[subtype*3 + 3 + val - 1].bitmap;
  656. break;
  657. case secskill:
  658. return CGI->abilh->abils82->ourImages[subtype*3 + 3 + val - 1].bitmap;
  659. break;
  660. case resource:
  661. return graphics->resources->ourImages[subtype].bitmap;
  662. break;
  663. case experience:
  664. return graphics->pskillsb->ourImages[4].bitmap;
  665. break;
  666. }
  667. return NULL;
  668. }
  669. void SComponent::clickRight (tribool down)
  670. {
  671. LOCPLINT->adventureInt->handleRightClick(description,down,this);
  672. }
  673. void SComponent::activate()
  674. {
  675. ClickableR::activate();
  676. }
  677. void SComponent::deactivate()
  678. {
  679. ClickableR::deactivate();
  680. }
  681. void CSelectableComponent::clickLeft(tribool down)
  682. {
  683. if (down)
  684. {
  685. if(onSelect)
  686. onSelect();
  687. }
  688. }
  689. void CSelectableComponent::init(SDL_Surface * Border)
  690. {
  691. SDL_Surface * symb = SComponent::getImg();
  692. myBitmap = CSDL_Ext::newSurface(symb->w+2,symb->h+2,screen);
  693. SDL_SetColorKey(myBitmap,SDL_SRCCOLORKEY,SDL_MapRGB(myBitmap->format,0,255,255));
  694. blitAt(symb,1,1,myBitmap);
  695. if (Border) //use custom border
  696. {
  697. border = Border;
  698. customB = true;
  699. }
  700. else //we need to draw border
  701. {
  702. customB = false;
  703. border = CSDL_Ext::newSurface(symb->w+2,symb->h+2,screen);
  704. SDL_FillRect(border,NULL,0x00FFFF);
  705. for (int i=0;i<border->w;i++)
  706. {
  707. SDL_PutPixel(border,i,0,239,215,123);
  708. SDL_PutPixel(border,i,(border->h)-1,239,215,123);
  709. }
  710. for (int i=0;i<border->h;i++)
  711. {
  712. SDL_PutPixel(border,0,i,239,215,123);
  713. SDL_PutPixel(border,(border->w)-1,i,239,215,123);
  714. }
  715. SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255));
  716. }
  717. selected = false;
  718. }
  719. CSelectableComponent::CSelectableComponent(const Component &c, boost::function<void()> OnSelect, SDL_Surface * Border)
  720. :SComponent(c),onSelect(OnSelect)
  721. {
  722. init(Border);
  723. }
  724. CSelectableComponent::CSelectableComponent(Etype Type, int Sub, int Val, boost::function<void()> OnSelect, SDL_Surface * Border)
  725. :SComponent(Type,Sub,Val),onSelect(OnSelect)
  726. {
  727. init(Border);
  728. }
  729. CSelectableComponent::~CSelectableComponent()
  730. {
  731. SDL_FreeSurface(myBitmap);
  732. if (!customB)
  733. SDL_FreeSurface(border);
  734. }
  735. void CSelectableComponent::activate()
  736. {
  737. SComponent::activate();
  738. ClickableL::activate();
  739. }
  740. void CSelectableComponent::deactivate()
  741. {
  742. SComponent::deactivate();
  743. ClickableL::deactivate();
  744. }
  745. SDL_Surface * CSelectableComponent::getImg()
  746. {
  747. return myBitmap;
  748. }
  749. void CSelectableComponent::select(bool on)
  750. {
  751. if(on != selected)
  752. {
  753. SDL_FillRect(myBitmap,NULL,0x000000);
  754. blitAt(SComponent::getImg(),1,1,myBitmap);
  755. if (on)
  756. {
  757. blitAt(border,0,0,myBitmap);
  758. }
  759. selected = on;
  760. return;
  761. }
  762. else
  763. {
  764. return;
  765. }
  766. }
  767. void CSelectableComponent::show(SDL_Surface * to)
  768. {
  769. blitAt(myBitmap,pos.x,pos.y,to);
  770. printAtMiddleWB(subtitle,pos.x+pos.w/2,pos.y+pos.h+14,GEOR13,12,zwykly,to);
  771. }
  772. void CSimpleWindow::show(SDL_Surface * to)
  773. {
  774. if(!to)
  775. to=screen;
  776. blitAt(bitmap,pos.x,pos.y,to);
  777. }
  778. CSimpleWindow::~CSimpleWindow()
  779. {
  780. if (bitmap)
  781. {
  782. SDL_FreeSurface(bitmap);
  783. bitmap=NULL;
  784. }
  785. }
  786. void CSelWindow::selectionChange(unsigned to)
  787. {
  788. for (unsigned i=0;i<components.size();i++)
  789. {
  790. CSelectableComponent * pom = dynamic_cast<CSelectableComponent*>(components[i]);
  791. if (!pom)
  792. continue;
  793. pom->select(i==to);
  794. blitAt(pom->getImg(),pom->pos.x-pos.x,pom->pos.y-pos.y,bitmap);
  795. }
  796. }
  797. CSelWindow::CSelWindow(std::string text, int player, int charperline, std::vector<CSelectableComponent*> &comps, std::vector<std::pair<std::string,boost::function<void()> > > &Buttons)
  798. {
  799. for(int i=0;i<Buttons.size();i++)
  800. {
  801. buttons.push_back(new AdventureMapButton("","",(Buttons[i].second)?(Buttons[i].second):(boost::bind(&CInfoWindow::close,this)),0,0,Buttons[i].first));
  802. }
  803. for(int i=0;i<comps.size();i++)
  804. {
  805. components.push_back(comps[i]);
  806. comps[i]->onSelect = boost::bind(&CSelWindow::selectionChange,this,i);
  807. }
  808. CMessage::drawIWindow(this,text,player,charperline);
  809. }
  810. void CSelWindow::close()
  811. {
  812. deactivate();
  813. int ret = -1;
  814. for (int i=0;i<components.size();i++)
  815. {
  816. if(dynamic_cast<CSelectableComponent*>(components[i])->selected)
  817. {
  818. ret = i;
  819. }
  820. }
  821. LOCPLINT->curint->activate();
  822. LOCPLINT->cb->selectionMade(ret,ID);
  823. delete this;
  824. //call owner with selection result
  825. }
  826. CButtonBase::CButtonBase()
  827. {
  828. bitmapOffset = 0;
  829. curimg=0;
  830. type=-1;
  831. abs=false;
  832. active=false;
  833. notFreeButton = false;
  834. ourObj=NULL;
  835. state=0;
  836. }
  837. CButtonBase::~CButtonBase()
  838. {
  839. if(notFreeButton)
  840. return;
  841. for(int i =0; i<imgs.size();i++)
  842. for(int j=0;j<imgs[i].size();j++)
  843. SDL_FreeSurface(imgs[i][j]);
  844. }
  845. void CButtonBase::show(SDL_Surface * to)
  846. {
  847. if(!to)
  848. to=screen;
  849. if (abs)
  850. {
  851. blitAt(imgs[curimg]
  852. [( (state+bitmapOffset) < (imgs[curimg].size()) ) ?
  853. (state+bitmapOffset) :
  854. (imgs[curimg].size()-1) ]
  855. ,pos.x,pos.y,to);
  856. //updateRect(&pos,to);
  857. }
  858. else
  859. {
  860. blitAt(imgs[curimg]
  861. [( (state+bitmapOffset) < (imgs[curimg].size()) ) ?
  862. (state+bitmapOffset) :
  863. (imgs[curimg].size()-1) ],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y,to);
  864. //updateRect(&genRect(pos.h,pos.w,pos.x+ourObj->pos.x,pos.y+ourObj->pos.y),to);
  865. }
  866. }
  867. ClickableL::ClickableL()
  868. {
  869. pressedL=false;
  870. }
  871. void ClickableL::clickLeft(tribool down)
  872. {
  873. if (down)
  874. pressedL=true;
  875. else
  876. pressedL=false;
  877. }
  878. void ClickableL::activate()
  879. {
  880. LOCPLINT->lclickable.push_front(this);
  881. }
  882. void ClickableL::deactivate()
  883. {
  884. LOCPLINT->lclickable.erase
  885. (std::find(LOCPLINT->lclickable.begin(),LOCPLINT->lclickable.end(),this));
  886. }
  887. ClickableR::ClickableR()
  888. {
  889. pressedR=false;
  890. }
  891. void ClickableR::clickRight(tribool down)
  892. {
  893. if (down)
  894. pressedR=true;
  895. else
  896. pressedR=false;
  897. }
  898. void ClickableR::activate()
  899. {
  900. LOCPLINT->rclickable.push_front(this);
  901. }
  902. void ClickableR::deactivate()
  903. {
  904. LOCPLINT->rclickable.erase(std::find(LOCPLINT->rclickable.begin(),LOCPLINT->rclickable.end(),this));
  905. }
  906. void Hoverable::activate()
  907. {
  908. LOCPLINT->hoverable.push_front(this);
  909. }
  910. void Hoverable::deactivate()
  911. {
  912. LOCPLINT->hoverable.erase(std::find(LOCPLINT->hoverable.begin(),LOCPLINT->hoverable.end(),this));
  913. }
  914. void Hoverable::hover(bool on)
  915. {
  916. hovered=on;
  917. }
  918. void KeyInterested::activate()
  919. {
  920. LOCPLINT->keyinterested.push_front(this);
  921. }
  922. void KeyInterested::deactivate()
  923. {
  924. LOCPLINT->
  925. keyinterested.erase(std::find(LOCPLINT->keyinterested.begin(),LOCPLINT->keyinterested.end(),this));
  926. }
  927. void MotionInterested::activate()
  928. {
  929. LOCPLINT->motioninterested.push_front(this);
  930. }
  931. void MotionInterested::deactivate()
  932. {
  933. LOCPLINT->
  934. motioninterested.erase(std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this));
  935. }
  936. void TimeInterested::activate()
  937. {
  938. LOCPLINT->timeinterested.push_back(this);
  939. }
  940. void TimeInterested::deactivate()
  941. {
  942. LOCPLINT->
  943. timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),this));
  944. }
  945. CPlayerInterface::CPlayerInterface(int Player, int serial)
  946. {
  947. LOCPLINT = this;
  948. playerID=Player;
  949. serialID=serial;
  950. human=true;
  951. pim = new boost::recursive_mutex;
  952. showingDialog = new CondSh<bool>(false);
  953. heroMoveSpeed = 2;
  954. //initializing framerate keeper
  955. mainFPSmng = new FPSmanager;
  956. SDL_initFramerate(mainFPSmng);
  957. SDL_setFramerate(mainFPSmng, 48);
  958. //framerate keeper initialized
  959. }
  960. CPlayerInterface::~CPlayerInterface()
  961. {
  962. delete pim;
  963. delete showingDialog;
  964. }
  965. void CPlayerInterface::init(ICallback * CB)
  966. {
  967. cb = dynamic_cast<CCallback*>(CB);
  968. adventureInt = new CAdvMapInt(playerID);
  969. castleInt = NULL;
  970. std::vector<const CGTownInstance*> tt = cb->getTownsInfo(false);
  971. for(int i=0;i<tt.size();i++)
  972. {
  973. SDL_Surface * pom = infoWin(tt[i]);
  974. graphics->townWins.insert(std::pair<int,SDL_Surface*>(tt[i]->id,pom));
  975. }
  976. }
  977. void CPlayerInterface::yourTurn()
  978. {
  979. LOCPLINT = this;
  980. makingTurn = true;
  981. for(std::map<int,SDL_Surface*>::iterator i=graphics->heroWins.begin(); i!=graphics->heroWins.end();i++) //redraw hero infoboxes
  982. SDL_FreeSurface(i->second);
  983. graphics->heroWins.clear();
  984. std::vector <const CGHeroInstance *> hh = cb->getHeroesInfo(false);
  985. for(int i=0;i<hh.size();i++)
  986. {
  987. SDL_Surface * pom = infoWin(hh[i]);
  988. graphics->heroWins.insert(std::pair<int,SDL_Surface*>(hh[i]->subID,pom));
  989. }
  990. adventureInt->infoBar.newDay(cb->getDate(1));
  991. if(adventureInt->heroList.items.size())
  992. adventureInt->select(adventureInt->heroList.items[0].first);
  993. else
  994. adventureInt->select(adventureInt->townList.items[0]);
  995. adventureInt->activate();
  996. timeHandler th;
  997. th.getDif();
  998. for(;makingTurn;) // main loop
  999. {
  1000. updateWater();
  1001. pim->lock();
  1002. int tv = th.getDif();
  1003. std::list<TimeInterested*> hlp = timeinterested;
  1004. for (std::list<TimeInterested*>::iterator i=hlp.begin(); i != hlp.end();i++)
  1005. {
  1006. if(!vstd::contains(timeinterested,*i)) continue;
  1007. if ((*i)->toNextTick>=0)
  1008. (*i)->toNextTick-=tv;
  1009. if ((*i)->toNextTick<0)
  1010. (*i)->tick();
  1011. }
  1012. LOCPLINT->adventureInt->updateScreen = false;
  1013. eventsM.lock();
  1014. while(!events.empty())
  1015. {
  1016. handleEvent(&events.front());
  1017. events.pop();
  1018. }
  1019. eventsM.unlock();
  1020. if (curint == adventureInt) //stuff for advMapInt
  1021. {
  1022. adventureInt->update();
  1023. }
  1024. for(int i=0;i<objsToBlit.size();i++)
  1025. objsToBlit[i]->show();
  1026. CGI->curh->draw1();
  1027. CSDL_Ext::update(screen);
  1028. CGI->curh->draw2();
  1029. pim->unlock();
  1030. SDL_framerateDelay(mainFPSmng);
  1031. }
  1032. adventureInt->hide();
  1033. cb->endTurn();
  1034. }
  1035. inline void subRect(const int & x, const int & y, const int & z, const SDL_Rect & r, const int & hid)
  1036. {
  1037. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  1038. for(int h=0; h<hlp.objects.size(); ++h)
  1039. if(hlp.objects[h].first->id==hid)
  1040. {
  1041. hlp.objects[h].second = r;
  1042. return;
  1043. }
  1044. }
  1045. inline void delObjRect(const int & x, const int & y, const int & z, const int & hid)
  1046. {
  1047. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  1048. for(int h=0; h<hlp.objects.size(); ++h)
  1049. if(hlp.objects[h].first->id==hid)
  1050. {
  1051. hlp.objects.erase(hlp.objects.begin()+h);
  1052. return;
  1053. }
  1054. }
  1055. int getDir(int3 src, int3 dst)
  1056. {
  1057. int ret = -1;
  1058. if(dst.x+1 == src.x && dst.y+1 == src.y) //tl
  1059. {
  1060. ret = 1;
  1061. }
  1062. else if(dst.x == src.x && dst.y+1 == src.y) //t
  1063. {
  1064. ret = 2;
  1065. }
  1066. else if(dst.x-1 == src.x && dst.y+1 == src.y) //tr
  1067. {
  1068. ret = 3;
  1069. }
  1070. else if(dst.x-1 == src.x && dst.y == src.y) //r
  1071. {
  1072. ret = 4;
  1073. }
  1074. else if(dst.x-1 == src.x && dst.y-1 == src.y) //br
  1075. {
  1076. ret = 5;
  1077. }
  1078. else if(dst.x == src.x && dst.y-1 == src.y) //b
  1079. {
  1080. ret = 6;
  1081. }
  1082. else if(dst.x+1 == src.x && dst.y-1 == src.y) //bl
  1083. {
  1084. ret = 7;
  1085. }
  1086. else if(dst.x+1 == src.x && dst.y == src.y) //l
  1087. {
  1088. ret = 8;
  1089. }
  1090. return ret;
  1091. }
  1092. void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
  1093. {
  1094. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1095. int3 buff = details.ho->pos;
  1096. buff.x-=11;
  1097. buff.y-=9;
  1098. buff = repairScreenPos(buff);
  1099. LOCPLINT->adventureInt->position = buff; //actualizing screen pos
  1100. if(adventureInt == curint)
  1101. adventureInt->minimap.draw();
  1102. if(details.style)
  1103. return;
  1104. //initializing objects and performing first step of move
  1105. const CGHeroInstance * ho = details.ho; //object representing this hero
  1106. int3 hp = details.src;
  1107. if (!details.successful) //hero failed to move
  1108. {
  1109. ho->moveDir = getDir(details.src,details.dst);
  1110. ho->isStanding = true;
  1111. adventureInt->heroList.draw();
  1112. if (adventureInt->terrain.currentPath && ho->movement>145) //TODO: better condition on movement - check cost of endtile
  1113. {
  1114. delete adventureInt->terrain.currentPath;
  1115. adventureInt->terrain.currentPath = NULL;
  1116. adventureInt->heroList.items[adventureInt->heroList.getPosOfHero(ho)].second = NULL;
  1117. }
  1118. return;
  1119. }
  1120. if (adventureInt->terrain.currentPath) //&& hero is moving
  1121. {
  1122. adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
  1123. }
  1124. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  1125. {
  1126. ho->moveDir = 1;
  1127. ho->isStanding = false;
  1128. CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -31)));
  1129. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, -31)));
  1130. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, -31)));
  1131. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, -31)));
  1132. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 1)));
  1133. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 1), ho->id);
  1134. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 1), ho->id);
  1135. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 1), ho->id);
  1136. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 33)));
  1137. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 33), ho->id);
  1138. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 33), ho->id);
  1139. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 33), ho->id);
  1140. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1141. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1142. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1143. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1144. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1145. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1146. }
  1147. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  1148. {
  1149. ho->moveDir = 2;
  1150. ho->isStanding = false;
  1151. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, -31)));
  1152. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, -31)));
  1153. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, -31)));
  1154. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1), ho->id);
  1155. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1), ho->id);
  1156. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1), ho->id);
  1157. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33), ho->id);
  1158. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33), ho->id);
  1159. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33), ho->id);
  1160. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1161. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1162. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1163. }
  1164. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  1165. {
  1166. ho->moveDir = 3;
  1167. ho->isStanding = false;
  1168. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, -31)));
  1169. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, -31)));
  1170. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, -31)));
  1171. CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -31)));
  1172. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 1), ho->id);
  1173. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 1), ho->id);
  1174. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 1), ho->id);
  1175. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 1)));
  1176. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 33), ho->id);
  1177. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 33), ho->id);
  1178. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 33), ho->id);
  1179. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 33)));
  1180. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1181. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1182. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1183. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1184. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1185. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1186. }
  1187. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1188. {
  1189. ho->moveDir = 4;
  1190. ho->isStanding = false;
  1191. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id);
  1192. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id);
  1193. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id);
  1194. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 0)));
  1195. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 32), ho->id);
  1196. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 32), ho->id);
  1197. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 32), ho->id);
  1198. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 32)));
  1199. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1200. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1201. }
  1202. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1203. {
  1204. ho->moveDir = 5;
  1205. ho->isStanding = false;
  1206. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, -1), ho->id);
  1207. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, -1), ho->id);
  1208. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id);
  1209. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -1)));
  1210. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 31), ho->id);
  1211. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 31), ho->id);
  1212. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 31), ho->id);
  1213. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 31)));
  1214. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, 63)));
  1215. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, 63)));
  1216. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, 63)));
  1217. CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 63)));
  1218. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1219. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1220. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1221. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1222. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1223. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1224. }
  1225. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1226. {
  1227. ho->moveDir = 6;
  1228. ho->isStanding = false;
  1229. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1), ho->id);
  1230. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1), ho->id);
  1231. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1), ho->id);
  1232. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31), ho->id);
  1233. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31), ho->id);
  1234. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31), ho->id);
  1235. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, 63)));
  1236. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, 63)));
  1237. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, 63)));
  1238. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1239. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1240. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1241. }
  1242. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1243. {
  1244. ho->moveDir = 7;
  1245. ho->isStanding = false;
  1246. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -1)));
  1247. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id);
  1248. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id);
  1249. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, -1), ho->id);
  1250. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 31)));
  1251. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 31), ho->id);
  1252. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 31), ho->id);
  1253. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 31), ho->id);
  1254. CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 63)));
  1255. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, 63)));
  1256. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, 63)));
  1257. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, 63)));
  1258. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1259. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1260. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1261. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1262. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1263. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1264. }
  1265. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1266. {
  1267. ho->moveDir = 8;
  1268. ho->isStanding = false;
  1269. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 0)));
  1270. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id);
  1271. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id);
  1272. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 0), ho->id);
  1273. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 32)));
  1274. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 32), ho->id);
  1275. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 32), ho->id);
  1276. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 32), ho->id);
  1277. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1278. std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1279. }
  1280. //first initializing done
  1281. SDL_framerateDelay(mainFPSmng); // after first move
  1282. //main moving
  1283. for(int i=1; i<32; i+=2*heroMoveSpeed)
  1284. {
  1285. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  1286. {
  1287. //seting advmap shift
  1288. adventureInt->terrain.moveX = i-32;
  1289. adventureInt->terrain.moveY = i-32;
  1290. subRect(hp.x-3, hp.y-2, hp.z, genRect(32, 32, -31+i, -31+i), ho->id);
  1291. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 1+i, -31+i), ho->id);
  1292. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 33+i, -31+i), ho->id);
  1293. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 65+i, -31+i), ho->id);
  1294. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 1+i), ho->id);
  1295. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 1+i), ho->id);
  1296. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 1+i), ho->id);
  1297. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 1+i), ho->id);
  1298. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 33+i), ho->id);
  1299. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 33+i), ho->id);
  1300. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 33+i), ho->id);
  1301. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 33+i), ho->id);
  1302. }
  1303. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  1304. {
  1305. //seting advmap shift
  1306. adventureInt->terrain.moveY = i-32;
  1307. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 0, -31+i), ho->id);
  1308. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 32, -31+i), ho->id);
  1309. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 64, -31+i), ho->id);
  1310. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1+i), ho->id);
  1311. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1+i), ho->id);
  1312. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1+i), ho->id);
  1313. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33+i), ho->id);
  1314. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33+i), ho->id);
  1315. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33+i), ho->id);
  1316. }
  1317. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  1318. {
  1319. //seting advmap shift
  1320. adventureInt->terrain.moveX = -i+32;
  1321. adventureInt->terrain.moveY = i-32;
  1322. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, -1-i, -31+i), ho->id);
  1323. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 31-i, -31+i), ho->id);
  1324. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 63-i, -31+i), ho->id);
  1325. subRect(hp.x+1, hp.y-2, hp.z, genRect(32, 32, 95-i, -31+i), ho->id);
  1326. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 1+i), ho->id);
  1327. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 1+i), ho->id);
  1328. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 1+i), ho->id);
  1329. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 1+i), ho->id);
  1330. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 33+i), ho->id);
  1331. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 33+i), ho->id);
  1332. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 33+i), ho->id);
  1333. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 33+i), ho->id);
  1334. }
  1335. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1336. {
  1337. //seting advmap shift
  1338. adventureInt->terrain.moveX = -i+32;
  1339. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 0), ho->id);
  1340. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 0), ho->id);
  1341. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 0), ho->id);
  1342. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 0), ho->id);
  1343. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 32), ho->id);
  1344. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 32), ho->id);
  1345. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 32), ho->id);
  1346. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 32), ho->id);
  1347. }
  1348. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1349. {
  1350. //seting advmap shift
  1351. adventureInt->terrain.moveX = -i+32;
  1352. adventureInt->terrain.moveY = -i+32;
  1353. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, -1-i), ho->id);
  1354. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, -1-i), ho->id);
  1355. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, -1-i), ho->id);
  1356. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, -1-i), ho->id);
  1357. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 31-i), ho->id);
  1358. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 31-i), ho->id);
  1359. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 31-i), ho->id);
  1360. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 31-i), ho->id);
  1361. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, -1-i, 63-i), ho->id);
  1362. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 31-i, 63-i), ho->id);
  1363. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 63-i, 63-i), ho->id);
  1364. subRect(hp.x+1, hp.y+1, hp.z, genRect(32, 32, 95-i, 63-i), ho->id);
  1365. }
  1366. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1367. {
  1368. //seting advmap shift
  1369. adventureInt->terrain.moveY = -i+32;
  1370. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1-i), ho->id);
  1371. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1-i), ho->id);
  1372. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1-i), ho->id);
  1373. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31-i), ho->id);
  1374. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31-i), ho->id);
  1375. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31-i), ho->id);
  1376. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 0, 63-i), ho->id);
  1377. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 32, 63-i), ho->id);
  1378. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 64, 63-i), ho->id);
  1379. }
  1380. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1381. {
  1382. //seting advmap shift
  1383. adventureInt->terrain.moveX = i-32;
  1384. adventureInt->terrain.moveY = -i+32;
  1385. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, -1-i), ho->id);
  1386. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, -1-i), ho->id);
  1387. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, -1-i), ho->id);
  1388. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, -1-i), ho->id);
  1389. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 31-i), ho->id);
  1390. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 31-i), ho->id);
  1391. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 31-i), ho->id);
  1392. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 31-i), ho->id);
  1393. subRect(hp.x-3, hp.y+1, hp.z, genRect(32, 32, -31+i, 63-i), ho->id);
  1394. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 1+i, 63-i), ho->id);
  1395. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 33+i, 63-i), ho->id);
  1396. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 65+i, 63-i), ho->id);
  1397. }
  1398. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1399. {
  1400. //seting advmap shift
  1401. adventureInt->terrain.moveX = i-32;
  1402. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 0), ho->id);
  1403. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 0), ho->id);
  1404. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 0), ho->id);
  1405. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 0), ho->id);
  1406. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 32), ho->id);
  1407. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 32), ho->id);
  1408. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 32), ho->id);
  1409. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 32), ho->id);
  1410. }
  1411. adventureInt->updateScreen = true;
  1412. LOCPLINT->adventureInt->update(); //updating screen
  1413. CSDL_Ext::update(screen);
  1414. //CGI->screenh->updateScreen();
  1415. ++LOCPLINT->adventureInt->animValHitCount; //for animations
  1416. if(LOCPLINT->adventureInt->animValHitCount == 8)
  1417. {
  1418. LOCPLINT->adventureInt->animValHitCount = 0;
  1419. ++LOCPLINT->adventureInt->anim;
  1420. LOCPLINT->adventureInt->updateScreen = true;
  1421. }
  1422. ++LOCPLINT->adventureInt->heroAnim;
  1423. SDL_Delay(5);
  1424. SDL_framerateDelay(mainFPSmng); //for animation purposes
  1425. } //for(int i=1; i<32; i+=4)
  1426. //main moving done
  1427. //finishing move
  1428. //restoring adventureInt->terrain.move*
  1429. adventureInt->terrain.moveX = adventureInt->terrain.moveY = 0;
  1430. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  1431. {
  1432. delObjRect(hp.x, hp.y-2, hp.z, ho->id);
  1433. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1434. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1435. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1436. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1437. delObjRect(hp.x-3, hp.y, hp.z, ho->id);
  1438. }
  1439. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  1440. {
  1441. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1442. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1443. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1444. }
  1445. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  1446. {
  1447. delObjRect(hp.x-2, hp.y-2, hp.z, ho->id);
  1448. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1449. delObjRect(hp.x+1, hp.y, hp.z, ho->id);
  1450. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1451. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1452. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1453. }
  1454. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1455. {
  1456. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1457. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1458. }
  1459. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1460. {
  1461. delObjRect(hp.x-2, hp.y+1, hp.z, ho->id);
  1462. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1463. delObjRect(hp.x+1, hp.y-1, hp.z, ho->id);
  1464. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1465. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1466. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1467. }
  1468. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1469. {
  1470. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1471. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1472. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1473. }
  1474. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1475. {
  1476. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1477. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1478. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1479. delObjRect(hp.x-3, hp.y-1, hp.z, ho->id);
  1480. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1481. delObjRect(hp.x, hp.y+1, hp.z, ho->id);
  1482. }
  1483. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1484. {
  1485. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1486. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1487. }
  1488. //restoring good rects
  1489. subRect(details.dst.x-2, details.dst.y-1, details.dst.z, genRect(32, 32, 0, 0), ho->id);
  1490. subRect(details.dst.x-1, details.dst.y-1, details.dst.z, genRect(32, 32, 32, 0), ho->id);
  1491. subRect(details.dst.x, details.dst.y-1, details.dst.z, genRect(32, 32, 64, 0), ho->id);
  1492. subRect(details.dst.x-2, details.dst.y, details.dst.z, genRect(32, 32, 0, 32), ho->id);
  1493. subRect(details.dst.x-1, details.dst.y, details.dst.z, genRect(32, 32, 32, 32), ho->id);
  1494. subRect(details.dst.x, details.dst.y, details.dst.z, genRect(32, 32, 64, 32), ho->id);
  1495. //restoring good order of objects
  1496. std::stable_sort(CGI->mh->ttiles[details.dst.x-2][details.dst.y-1][details.dst.z].objects.begin(), CGI->mh->ttiles[details.dst.x-2][details.dst.y-1][details.dst.z].objects.end(), ocmptwo_cgin);
  1497. std::stable_sort(CGI->mh->ttiles[details.dst.x-1][details.dst.y-1][details.dst.z].objects.begin(), CGI->mh->ttiles[details.dst.x-1][details.dst.y-1][details.dst.z].objects.end(), ocmptwo_cgin);
  1498. std::stable_sort(CGI->mh->ttiles[details.dst.x][details.dst.y-1][details.dst.z].objects.begin(), CGI->mh->ttiles[details.dst.x][details.dst.y-1][details.dst.z].objects.end(), ocmptwo_cgin);
  1499. std::stable_sort(CGI->mh->ttiles[details.dst.x-2][details.dst.y][details.dst.z].objects.begin(), CGI->mh->ttiles[details.dst.x-2][details.dst.y][details.dst.z].objects.end(), ocmptwo_cgin);
  1500. std::stable_sort(CGI->mh->ttiles[details.dst.x-1][details.dst.y][details.dst.z].objects.begin(), CGI->mh->ttiles[details.dst.x-1][details.dst.y][details.dst.z].objects.end(), ocmptwo_cgin);
  1501. std::stable_sort(CGI->mh->ttiles[details.dst.x][details.dst.y][details.dst.z].objects.begin(), CGI->mh->ttiles[details.dst.x][details.dst.y][details.dst.z].objects.end(), ocmptwo_cgin);
  1502. ho->isStanding = true;
  1503. //move finished
  1504. adventureInt->minimap.draw();
  1505. adventureInt->heroList.updateMove(ho);
  1506. }
  1507. void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
  1508. {
  1509. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1510. graphics->heroWins.erase(hero->ID);
  1511. adventureInt->heroList.updateHList();
  1512. }
  1513. void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
  1514. {
  1515. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1516. if(graphics->heroWins.find(hero->subID)==graphics->heroWins.end())
  1517. graphics->heroWins.insert(std::pair<int,SDL_Surface*>(hero->subID,infoWin(hero)));
  1518. adventureInt->heroList.updateHList();
  1519. }
  1520. void CPlayerInterface::openTownWindow(const CGTownInstance * town)
  1521. {
  1522. adventureInt->hide();
  1523. //timeHandler t;
  1524. //t.getDif();
  1525. castleInt = new CCastleInterface(town,true);
  1526. //std::cout << "Loading town screen: " << t.getDif() <<std::endl;
  1527. }
  1528. SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //specific=0 => draws info about selected town/hero
  1529. {
  1530. if (specific)
  1531. {
  1532. switch (specific->ID)
  1533. {
  1534. case 34:
  1535. return graphics->drawHeroInfoWin(dynamic_cast<const CGHeroInstance*>(specific));
  1536. break;
  1537. case 98:
  1538. return graphics->drawTownInfoWin(dynamic_cast<const CGTownInstance*>(specific));
  1539. break;
  1540. default:
  1541. return NULL;
  1542. break;
  1543. }
  1544. }
  1545. else
  1546. {
  1547. switch (adventureInt->selection->ID)
  1548. {
  1549. case HEROI_TYPE:
  1550. {
  1551. const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection;
  1552. return graphics->drawHeroInfoWin(curh);
  1553. }
  1554. case TOWNI_TYPE:
  1555. {
  1556. return graphics->drawTownInfoWin((const CGTownInstance *)adventureInt->selection);
  1557. }
  1558. default:
  1559. return NULL;
  1560. }
  1561. }
  1562. return NULL;
  1563. }
  1564. void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent)
  1565. {
  1566. std::vector<Hoverable*> hlp;
  1567. for(std::list<Hoverable*>::iterator i=hoverable.begin(); i != hoverable.end();i++)
  1568. {
  1569. if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  1570. {
  1571. if (!(*i)->hovered)
  1572. hlp.push_back((*i));
  1573. }
  1574. else if ((*i)->hovered)
  1575. {
  1576. (*i)->hover(false);
  1577. }
  1578. }
  1579. for(int i=0; i<hlp.size();i++)
  1580. hlp[i]->hover(true);
  1581. std::list<MotionInterested*> miCopy = motioninterested;
  1582. for(std::list<MotionInterested*>::iterator i=miCopy.begin(); i != miCopy.end();i++)
  1583. {
  1584. if ((*i)->strongInterest || isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  1585. {
  1586. (*i)->mouseMoved(sEvent->motion);
  1587. }
  1588. }
  1589. if(!SDL_GetKeyState(NULL)[SDLK_LCTRL])
  1590. {
  1591. if(sEvent->motion.x<15)
  1592. {
  1593. LOCPLINT->adventureInt->scrollingLeft = true;
  1594. }
  1595. else
  1596. {
  1597. LOCPLINT->adventureInt->scrollingLeft = false;
  1598. }
  1599. if(sEvent->motion.x>screen->w-15)
  1600. {
  1601. LOCPLINT->adventureInt->scrollingRight = true;
  1602. }
  1603. else
  1604. {
  1605. LOCPLINT->adventureInt->scrollingRight = false;
  1606. }
  1607. if(sEvent->motion.y<15)
  1608. {
  1609. LOCPLINT->adventureInt->scrollingUp = true;
  1610. }
  1611. else
  1612. {
  1613. LOCPLINT->adventureInt->scrollingUp = false;
  1614. }
  1615. if(sEvent->motion.y>screen->h-15)
  1616. {
  1617. LOCPLINT->adventureInt->scrollingDown = true;
  1618. }
  1619. else
  1620. {
  1621. LOCPLINT->adventureInt->scrollingDown = false;
  1622. }
  1623. }
  1624. }
  1625. void CPlayerInterface::handleEvent(SDL_Event *sEvent)
  1626. {
  1627. current = sEvent;
  1628. if (sEvent->type==SDL_KEYDOWN || sEvent->type==SDL_KEYUP)
  1629. {
  1630. std::list<KeyInterested*> miCopy = keyinterested;
  1631. for(std::list<KeyInterested*>::iterator i=miCopy.begin(); i != miCopy.end();i++)
  1632. if(vstd::contains(keyinterested,*i))
  1633. (**i).keyPressed(sEvent->key);
  1634. }
  1635. else if(sEvent->type==SDL_MOUSEMOTION)
  1636. {
  1637. CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
  1638. handleMouseMotion(sEvent);
  1639. }
  1640. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1641. {
  1642. std::list<ClickableL*> hlp = lclickable;
  1643. for(std::list<ClickableL*>::iterator i=hlp.begin(); i != hlp.end();i++)
  1644. {
  1645. if(!vstd::contains(lclickable,*i)) continue;
  1646. if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  1647. {
  1648. (*i)->clickLeft(true);
  1649. }
  1650. }
  1651. }
  1652. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1653. {
  1654. std::list<ClickableL*> hlp = lclickable;
  1655. for(std::list<ClickableL*>::iterator i=hlp.begin(); i != hlp.end();i++)
  1656. {
  1657. if(!vstd::contains(lclickable,*i)) continue;
  1658. if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  1659. {
  1660. (*i)->clickLeft(false);
  1661. }
  1662. else
  1663. (*i)->clickLeft(boost::logic::indeterminate);
  1664. }
  1665. }
  1666. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1667. {
  1668. std::list<ClickableR*> hlp = rclickable;
  1669. for(std::list<ClickableR*>::iterator i=hlp.begin(); i != hlp.end();i++)
  1670. {
  1671. if(!vstd::contains(rclickable,*i)) continue;
  1672. if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  1673. {
  1674. (*i)->clickRight(true);
  1675. }
  1676. }
  1677. }
  1678. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1679. {
  1680. std::list<ClickableR*> hlp = rclickable;
  1681. for(std::list<ClickableR*>::iterator i=hlp.begin(); i != hlp.end();i++)
  1682. {
  1683. if(!vstd::contains(rclickable,*i)) continue;
  1684. if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
  1685. {
  1686. (*i)->clickRight(false);
  1687. }
  1688. else
  1689. (*i)->clickRight(boost::logic::indeterminate);
  1690. }
  1691. }
  1692. current = NULL;
  1693. } //event end
  1694. int3 CPlayerInterface::repairScreenPos(int3 pos)
  1695. {
  1696. if(pos.x<=-Woff)
  1697. pos.x = -Woff+1;
  1698. if(pos.y<=-Hoff)
  1699. pos.y = -Hoff+1;
  1700. if(pos.x>CGI->mh->map->width - this->adventureInt->terrain.tilesw + Woff)
  1701. pos.x = CGI->mh->map->width - this->adventureInt->terrain.tilesw + Woff;
  1702. if(pos.y>CGI->mh->map->height - this->adventureInt->terrain.tilesh + Hoff)
  1703. pos.y = CGI->mh->map->height - this->adventureInt->terrain.tilesh + Hoff;
  1704. return pos;
  1705. }
  1706. void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)
  1707. {
  1708. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1709. SDL_FreeSurface(graphics->heroWins[hero->subID]);//TODO: moznaby zmieniac jedynie fragment bitmapy zwiazany z dana umiejetnoscia
  1710. graphics->heroWins[hero->subID] = infoWin(hero); //a nie przerysowywac calosc. Troche roboty, obecnie chyba nie wartej swieczki.
  1711. if (adventureInt->selection == hero)
  1712. adventureInt->infoBar.draw();
  1713. return;
  1714. }
  1715. void CPlayerInterface::heroManaPointsChanged(const CGHeroInstance * hero)
  1716. {
  1717. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1718. SDL_FreeSurface(graphics->heroWins[hero->subID]);//TODO: moznaby zmieniac jedynie fragment bitmapy zwiazany z dana umiejetnoscia
  1719. graphics->heroWins[hero->subID] = infoWin(hero); //a nie przerysowywac calosc. Troche roboty, obecnie chyba nie wartej swieczki.
  1720. if (adventureInt->selection == hero)
  1721. adventureInt->infoBar.draw();
  1722. }
  1723. void CPlayerInterface::heroMovePointsChanged(const CGHeroInstance * hero)
  1724. {
  1725. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1726. if(adventureInt == curint)
  1727. adventureInt->heroList.draw();
  1728. }
  1729. void CPlayerInterface::receivedResource(int type, int val)
  1730. {
  1731. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1732. if(curint==adventureInt || curint==castleInt)
  1733. adventureInt->resdatabar.draw();
  1734. }
  1735. void CPlayerInterface::showSelDialog(std::string &text, const std::vector<Component*> &components, ui32 askID)
  1736. //void CPlayerInterface::showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID)
  1737. {
  1738. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1739. adventureInt->hide(); //dezaktywacja starego interfejsu
  1740. std::vector<CSelectableComponent*> intComps;
  1741. for(int i=0;i<components.size();i++)
  1742. intComps.push_back(new CSelectableComponent(*components[i])); //will be deleted by CSelWindow::close
  1743. std::vector<std::pair<std::string,boost::function<void()> > > pom;
  1744. pom.push_back(std::pair<std::string,boost::function<void()> >("IOKAY.DEF",0));
  1745. CSelWindow * temp = new CSelWindow(text,playerID,35,intComps,pom);
  1746. LOCPLINT->objsToBlit.push_back(temp);
  1747. temp->activate();
  1748. temp->ID = askID;
  1749. intComps[0]->clickLeft(true);
  1750. }
  1751. void CPlayerInterface::heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16>& skills, boost::function<void(ui32)> &callback)
  1752. {
  1753. {
  1754. boost::unique_lock<boost::mutex> un(showingDialog->mx);
  1755. while(showingDialog->data)
  1756. showingDialog->cond.wait(un);
  1757. }
  1758. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1759. CLevelWindow *lw = new CLevelWindow(hero,pskill,skills,callback);
  1760. curint->deactivate();
  1761. lw->activate();
  1762. }
  1763. void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town)
  1764. {
  1765. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1766. //redraw infowindow
  1767. SDL_FreeSurface(graphics->townWins[town->id]);
  1768. graphics->townWins[town->id] = infoWin(town);
  1769. if(town->garrisonHero)
  1770. {
  1771. CGI->mh->hideObject(town->garrisonHero);
  1772. }
  1773. if(town->visitingHero)
  1774. {
  1775. CGI->mh->printObject(town->visitingHero);
  1776. }
  1777. adventureInt->heroList.updateHList();
  1778. CCastleInterface *c = dynamic_cast<CCastleInterface*>(curint);
  1779. if(c)
  1780. {
  1781. c->garr->highlighted = NULL;
  1782. c->hslotup.hero = town->garrisonHero;
  1783. c->garr->odown = c->hslotdown.hero = town->visitingHero;
  1784. c->garr->set2 = town->visitingHero ? &town->visitingHero->army : NULL;
  1785. c->garr->recreateSlots();
  1786. c->showAll();
  1787. }
  1788. }
  1789. void CPlayerInterface::heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town)
  1790. {
  1791. if(hero->tempOwner != town->tempOwner)
  1792. return;
  1793. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1794. openTownWindow(town);
  1795. }
  1796. void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj)
  1797. {
  1798. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1799. if(obj->ID == 34) //hero
  1800. {
  1801. const CGHeroInstance * hh;
  1802. if(hh = dynamic_cast<const CGHeroInstance*>(obj))
  1803. {
  1804. SDL_FreeSurface(graphics->heroWins[hh->subID]);
  1805. graphics->heroWins[hh->subID] = infoWin(hh);
  1806. }
  1807. CHeroWindow * hw = adventureInt->heroWindow;
  1808. if(hw == curint->subInt)
  1809. {
  1810. hw->garInt->recreateSlots();
  1811. hw->garInt->show();
  1812. }
  1813. if(castleInt) //opened town window - redraw town garrsion slots (change is within hero garr)
  1814. {
  1815. castleInt->garr->highlighted = NULL;
  1816. castleInt->garr->recreateSlots();
  1817. }
  1818. }
  1819. else if (obj->ID == 98) //town
  1820. {
  1821. const CGTownInstance * tt;
  1822. if(tt = static_cast<const CGTownInstance*>(obj))
  1823. {
  1824. SDL_FreeSurface(graphics->townWins[tt->id]);
  1825. graphics->townWins[tt->id] = infoWin(tt);
  1826. }
  1827. if(tt->visitingHero)
  1828. {
  1829. SDL_FreeSurface(graphics->heroWins[tt->visitingHero->subID]);
  1830. graphics->heroWins[tt->visitingHero->subID] = infoWin(tt->visitingHero);
  1831. }
  1832. if(LOCPLINT->castleInt)
  1833. {
  1834. LOCPLINT->castleInt->garr->highlighted = NULL;
  1835. LOCPLINT->castleInt->garr->recreateSlots();
  1836. }
  1837. }
  1838. if(curint == adventureInt)
  1839. adventureInt->infoBar.draw();
  1840. }
  1841. void CPlayerInterface::buildChanged(const CGTownInstance *town, int buildingID, int what) //what: 1 - built, 2 - demolished
  1842. {
  1843. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1844. switch (buildingID)
  1845. {
  1846. case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 15:
  1847. {
  1848. SDL_FreeSurface(graphics->townWins[town->id]);
  1849. graphics->townWins[town->id] = infoWin(town);
  1850. break;
  1851. }
  1852. }
  1853. if(curint!=castleInt)
  1854. return;
  1855. if(castleInt->town!=town)
  1856. return;
  1857. switch(what)
  1858. {
  1859. case 1:
  1860. castleInt->addBuilding(buildingID);
  1861. break;
  1862. case 2:
  1863. castleInt->removeBuilding(buildingID);
  1864. break;
  1865. }
  1866. }
  1867. void CPlayerInterface::battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side) //called by engine when battle starts; side=0 - left, side=1 - right
  1868. {
  1869. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1870. curint->deactivate();
  1871. curint = battleInt = new CBattleInterface(army1,army2,hero1,hero2);
  1872. curint->activate();
  1873. LOCPLINT->objsToBlit.push_back(dynamic_cast<IShowable*>(curint));
  1874. }
  1875. void CPlayerInterface::battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles) //called when battlefield is prepared, prior the battle beginning
  1876. {
  1877. }
  1878. void CPlayerInterface::battleNewRound(int round) //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
  1879. {
  1880. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1881. battleInt->newRound(round);
  1882. }
  1883. void CPlayerInterface::actionStarted(const BattleAction* action)
  1884. {
  1885. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1886. curAction = action;
  1887. if((action->actionType==2 || (action->actionType==6 && action->destinationTile!=cb->battleGetPos(action->stackNumber)))
  1888. && battleInt->creAnims[action->stackNumber]->framesInGroup(20)
  1889. )
  1890. {
  1891. battleInt->creAnims[action->stackNumber]->setType(20);
  1892. }
  1893. //if((action->actionType==2 || (action->actionType==6 && action->destinationTile!=cb->battleGetPos(action->stackNumber)))) //deactivating interface when move is started
  1894. {
  1895. battleInt->deactivate();
  1896. }
  1897. if(action->actionType == 1)
  1898. {
  1899. if(action->side)
  1900. battleInt->defendingHero->setPhase(4);
  1901. else
  1902. battleInt->attackingHero->setPhase(4);
  1903. }
  1904. }
  1905. void CPlayerInterface::actionFinished(const BattleAction* action)
  1906. {
  1907. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1908. curAction = NULL;
  1909. //if((action->actionType==2 || (action->actionType==6 && action->destinationTile!=cb->battleGetPos(action->stackNumber)))) //activating interface when move is finished
  1910. {
  1911. battleInt->activate();
  1912. }
  1913. if(action->actionType == 1)
  1914. {
  1915. if(action->side)
  1916. battleInt->defendingHero->setPhase(0);
  1917. else
  1918. battleInt->attackingHero->setPhase(0);
  1919. }
  1920. }
  1921. BattleAction CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack
  1922. {
  1923. CBattleInterface *b = battleInt;
  1924. {
  1925. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1926. b->stackActivated(stackID);
  1927. }
  1928. //wait till BattleInterface sets its command
  1929. boost::unique_lock<boost::mutex> lock(b->givenCommand->mx);
  1930. while(!b->givenCommand->data)
  1931. b->givenCommand->cond.wait(lock);
  1932. //tidy up
  1933. BattleAction ret = *(b->givenCommand->data);
  1934. delete b->givenCommand->data;
  1935. b->givenCommand->data = NULL;
  1936. //return command
  1937. return ret;
  1938. }
  1939. void CPlayerInterface::battleEnd(BattleResult *br)
  1940. {
  1941. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1942. ((CBattleInterface*)curint)->battleFinished(*br);
  1943. }
  1944. void CPlayerInterface::battleResultQuited()
  1945. {
  1946. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1947. ((CBattleInterface*)curint)->resWindow->deactivate();
  1948. objsToBlit -= curint;
  1949. delete battleInt;
  1950. battleInt = 0;
  1951. curint = adventureInt;
  1952. adventureInt->activate();
  1953. LOCPLINT->showingDialog->setn(false);
  1954. }
  1955. void CPlayerInterface::battleStackMoved(int ID, int dest)
  1956. {
  1957. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1958. battleInt->stackMoved(ID, dest, dest==curAction->destinationTile);
  1959. }
  1960. void CPlayerInterface::battleSpellCasted(SpellCasted *sc)
  1961. {
  1962. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1963. battleInt->spellCasted(sc);
  1964. }
  1965. void CPlayerInterface::battleStackAttacked(BattleStackAttacked * bsa)
  1966. {
  1967. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1968. if(bsa->isEffect())
  1969. {
  1970. battleInt->displayEffect(bsa->effect, cb->battleGetStackByID(bsa->stackAttacked)->position, cb->battleGetStackByID(bsa->stackAttacked)->attackerOwned);
  1971. }
  1972. if(bsa->killed())
  1973. battleInt->stackKilled(bsa->stackAttacked, bsa->damageAmount, bsa->killedAmount, LOCPLINT->curAction->stackNumber, LOCPLINT->curAction->actionType==7 );
  1974. else
  1975. battleInt->stackIsAttacked(bsa->stackAttacked, bsa->damageAmount, bsa->killedAmount, LOCPLINT->curAction->stackNumber, LOCPLINT->curAction->actionType==7);
  1976. }
  1977. void CPlayerInterface::battleAttack(BattleAttack *ba)
  1978. {
  1979. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1980. if(ba->shot())
  1981. battleInt->stackIsShooting(ba->stackAttacking,cb->battleGetPos(ba->bsa.stackAttacked));
  1982. else
  1983. battleInt->stackAttacking( ba->stackAttacking, ba->counter() ? curAction->destinationTile : curAction->additionalInfo );
  1984. /*if(ba->killed())
  1985. battleInt->stackKilled(ba->bsa.stackAttacked, ba->bsa.damageAmount, ba->bsa.killedAmount, ba->stackAttacking, ba->shot());
  1986. else
  1987. battleInt->stackIsAttacked(ba->bsa.stackAttacked, ba->bsa.damageAmount, ba->bsa.killedAmount, ba->stackAttacking, ba->shot());*/
  1988. }
  1989. void CPlayerInterface::showComp(SComponent comp)
  1990. {
  1991. boost::unique_lock<boost::recursive_mutex> un(*pim);
  1992. adventureInt->infoBar.showComp(&comp,4000);
  1993. }
  1994. void CPlayerInterface::showInfoDialog(std::string &text, const std::vector<Component*> &components)
  1995. {
  1996. std::vector<SComponent*> intComps;
  1997. for(int i=0;i<components.size();i++)
  1998. intComps.push_back(new SComponent(*components[i]));
  1999. showInfoDialog(text,intComps);
  2000. }
  2001. void CPlayerInterface::showInfoDialog(std::string &text, const std::vector<SComponent*> & components)
  2002. {
  2003. showingDialog->set(true);
  2004. boost::unique_lock<boost::recursive_mutex> un(*pim);
  2005. curint->deactivate(); //dezaktywacja starego interfejsu
  2006. std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
  2007. pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",0));
  2008. CInfoWindow * temp = new CInfoWindow(text,playerID,32,components,pom);
  2009. temp->buttons[0]->callback += boost::bind(&IActivable::activate,LOCPLINT->curint);
  2010. temp->activate();
  2011. LOCPLINT->objsToBlit.push_back(temp);
  2012. }
  2013. void CPlayerInterface::showYesNoDialog(std::string &text, const std::vector<SComponent*> & components, CFunctionList<void()> onYes, CFunctionList<void()> onNo, bool deactivateCur, bool DelComps)
  2014. {
  2015. boost::unique_lock<boost::recursive_mutex> un(*pim);
  2016. if(deactivateCur)
  2017. curint->deactivate(); //dezaktywacja starego interfejsu
  2018. std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
  2019. pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",0));
  2020. pom.push_back(std::pair<std::string,CFunctionList<void()> >("ICANCEL.DEF",0));
  2021. CInfoWindow * temp = new CInfoWindow(text,playerID,32,components,pom);
  2022. temp->delComps = DelComps;
  2023. for(int i=0;i<onYes.funcs.size();i++)
  2024. temp->buttons[0]->callback += onYes.funcs[i];
  2025. for(int i=0;i<onNo.funcs.size();i++)
  2026. temp->buttons[1]->callback += onNo.funcs[i];
  2027. //if(onYes)
  2028. // temp->buttons[0]->callback += boost::bind(&CInfoWindow::close,temp);
  2029. //if(onNo)
  2030. // temp->buttons[1]->callback += boost::bind(&CInfoWindow::close,temp);
  2031. temp->activate();
  2032. LOCPLINT->objsToBlit.push_back(temp);
  2033. }
  2034. void CPlayerInterface::showYesNoDialog( std::string &text, const std::vector<Component*> &components, ui32 askID )
  2035. {
  2036. boost::unique_lock<boost::recursive_mutex> un(*pim);
  2037. curint->deactivate(); //dezaktywacja starego interfejsu
  2038. std::vector<SComponent*> intComps;
  2039. for(int i=0;i<components.size();i++)
  2040. intComps.push_back(new SComponent(*components[i])); //will be deleted by CSelWindow::close
  2041. std::vector<std::pair<std::string,CFunctionList<void()> > > pom;
  2042. pom.push_back(std::pair<std::string,CFunctionList<void()> >("IOKAY.DEF",0));
  2043. pom.push_back(std::pair<std::string,CFunctionList<void()> >("ICANCEL.DEF",0));
  2044. CInfoWindow * temp = new CInfoWindow(text,playerID,32,intComps,pom);
  2045. temp->buttons[0]->callback += boost::bind(&IActivable::activate,curint);
  2046. temp->buttons[1]->callback += boost::bind(&IActivable::activate,curint);
  2047. temp->buttons[0]->callback += boost::bind(&CCallback::selectionMade,cb,0,askID);
  2048. temp->buttons[1]->callback += boost::bind(&CCallback::selectionMade,cb,1,askID);
  2049. temp->delComps = true;
  2050. temp->activate();
  2051. LOCPLINT->objsToBlit.push_back(temp);
  2052. }
  2053. void CPlayerInterface::removeObjToBlit(IShowable* obj)
  2054. {
  2055. boost::unique_lock<boost::recursive_mutex> un(*pim);
  2056. objsToBlit.erase
  2057. (std::find(objsToBlit.begin(),objsToBlit.end(),obj));
  2058. //delete obj;
  2059. }
  2060. void CPlayerInterface::tileRevealed(const std::set<int3> &pos)
  2061. {
  2062. boost::unique_lock<boost::recursive_mutex> un(*pim);
  2063. for(std::set<int3>::const_iterator i=pos.begin(); i!=pos.end();i++)
  2064. adventureInt->minimap.showTile(*i);
  2065. if(curint == adventureInt)
  2066. adventureInt->minimap.draw();
  2067. }
  2068. void CPlayerInterface::tileHidden(const std::set<int3> &pos)
  2069. {
  2070. boost::unique_lock<boost::recursive_mutex> un(*pim);
  2071. for(std::set<int3>::const_iterator i=pos.begin(); i!=pos.end();i++)
  2072. adventureInt->minimap.hideTile(*i);
  2073. if(curint == adventureInt)
  2074. adventureInt->minimap.draw();
  2075. }
  2076. void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero)
  2077. {
  2078. boost::unique_lock<boost::recursive_mutex> un(*pim);
  2079. adventureInt->heroWindow->setHero(hero);
  2080. this->objsToBlit.push_back(adventureInt->heroWindow);
  2081. curint->deactivate();
  2082. if(curint == castleInt)
  2083. castleInt->subInt = adventureInt->heroWindow;
  2084. adventureInt->heroWindow->quitButton->callback.funcs.clear();
  2085. adventureInt->heroWindow->quitButton->callback += boost::bind(&CHeroWindow::deactivate,adventureInt->heroWindow);
  2086. adventureInt->heroWindow->quitButton->callback += boost::bind(&CHeroWindow::quit,adventureInt->heroWindow);
  2087. adventureInt->heroWindow->activate();
  2088. }
  2089. void CPlayerInterface::heroArtifactSetChanged(const CGHeroInstance*hero)
  2090. {
  2091. boost::unique_lock<boost::recursive_mutex> un(*pim);
  2092. if(curint->subInt == adventureInt->heroWindow)
  2093. {
  2094. adventureInt->heroWindow->deactivate();
  2095. adventureInt->heroWindow->setHero(adventureInt->heroWindow->curHero);
  2096. adventureInt->heroWindow->activate();
  2097. }
  2098. }
  2099. void CPlayerInterface::updateWater()
  2100. {
  2101. //updating water tiles
  2102. //int wnumber = -1;
  2103. //for(int s=0; s<CGI->mh->reader->defs.size(); ++s)
  2104. //{
  2105. // if(CGI->mh->reader->defs[s]->defName==std::string("WATRTL.DEF"))
  2106. // {
  2107. // wnumber = s;
  2108. // break;
  2109. // }
  2110. //}
  2111. //if(wnumber>=0)
  2112. //{
  2113. // for(int g=0; g<CGI->mh->reader->defs[wnumber]->ourImages.size(); ++g)
  2114. // {
  2115. // SDL_Color tab[32];
  2116. // for(int i=0; i<32; ++i)
  2117. // {
  2118. // tab[i] = CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap->format->palette->colors[160 + (i+1)%32];
  2119. // }
  2120. // //SDL_SaveBMP(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap,"t1.bmp");
  2121. // for(int i=0; i<32; ++i)
  2122. // {
  2123. // CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap->format->palette->colors[160 + i] = tab[i];
  2124. // }
  2125. // //SDL_SaveBMP(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap,"t2.bmp");
  2126. // CSDL_Ext::update(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap);
  2127. // }
  2128. //}
  2129. //water tiles updated
  2130. //CGI->screenh->updateScreen();
  2131. }
  2132. void CPlayerInterface::availableCreaturesChanged( const CGTownInstance *town )
  2133. {
  2134. boost::unique_lock<boost::recursive_mutex> un(*pim);
  2135. if(curint == castleInt)
  2136. {
  2137. CFortScreen *fs = dynamic_cast<CFortScreen*>(curint->subInt);
  2138. if(fs)
  2139. fs->draw(castleInt,false);
  2140. }
  2141. }
  2142. CStatusBar::CStatusBar(int x, int y, std::string name, int maxw)
  2143. {
  2144. bg=BitmapHandler::loadBitmap(name);
  2145. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  2146. pos.x=x;
  2147. pos.y=y;
  2148. if(maxw >= 0)
  2149. pos.w = min(bg->w,maxw);
  2150. else
  2151. pos.w=bg->w;
  2152. pos.h=bg->h;
  2153. middlex=(pos.w/2)+x;
  2154. middley=(bg->h/2)+y;
  2155. }
  2156. CStatusBar::~CStatusBar()
  2157. {
  2158. SDL_FreeSurface(bg);
  2159. }
  2160. void CStatusBar::clear()
  2161. {
  2162. current="";
  2163. SDL_Rect pom = genRect(pos.h,pos.w,pos.x,pos.y);
  2164. SDL_BlitSurface(bg,&genRect(pos.h,pos.w,0,0),screen,&pom);
  2165. }
  2166. void CStatusBar::print(const std::string & text)
  2167. {
  2168. current=text;
  2169. SDL_Rect pom = genRect(pos.h,pos.w,pos.x,pos.y);
  2170. SDL_BlitSurface(bg,&genRect(pos.h,pos.w,0,0),screen,&pom);
  2171. printAtMiddle(current,middlex,middley,GEOR13,zwykly);
  2172. }
  2173. void CStatusBar::show()
  2174. {
  2175. SDL_Rect pom = genRect(pos.h,pos.w,pos.x,pos.y);
  2176. SDL_BlitSurface(bg,&genRect(pos.h,pos.w,0,0),screen,&pom);
  2177. printAtMiddle(current,middlex,middley,GEOR13,zwykly);
  2178. }
  2179. std::string CStatusBar::getCurrent()
  2180. {
  2181. return current;
  2182. }
  2183. void CList::activate()
  2184. {
  2185. ClickableL::activate();
  2186. ClickableR::activate();
  2187. Hoverable::activate();
  2188. KeyInterested::activate();
  2189. MotionInterested::activate();
  2190. };
  2191. void CList::deactivate()
  2192. {
  2193. ClickableL::deactivate();
  2194. ClickableR::deactivate();
  2195. Hoverable::deactivate();
  2196. KeyInterested::deactivate();
  2197. MotionInterested::deactivate();
  2198. };
  2199. void CList::clickLeft(tribool down)
  2200. {
  2201. };
  2202. CList::CList(int Size)
  2203. :SIZE(Size)
  2204. {
  2205. }
  2206. CHeroList::CHeroList(int Size)
  2207. :CList(Size)
  2208. {
  2209. pos = genRect(192,64,609,196);
  2210. arrupp = genRect(16,64,609,196);
  2211. arrdop = genRect(16,64,609,372);
  2212. //32px per hero
  2213. posmobx = 610;
  2214. posmoby = 213;
  2215. posporx = 617;
  2216. pospory = 212;
  2217. posmanx = 666;
  2218. posmany = 213;
  2219. arrup = CDefHandler::giveDef("IAM012.DEF");
  2220. arrdo = CDefHandler::giveDef("IAM013.DEF");
  2221. mobile = CDefHandler::giveDef("IMOBIL.DEF");
  2222. mana = CDefHandler::giveDef("IMANA.DEF");
  2223. empty = BitmapHandler::loadBitmap("HPSXXX.bmp");
  2224. selection = BitmapHandler::loadBitmap("HPSYYY.bmp");
  2225. SDL_SetColorKey(selection,SDL_SRCCOLORKEY,SDL_MapRGB(selection->format,0,255,255));
  2226. from = 0;
  2227. pressed = indeterminate;
  2228. }
  2229. void CHeroList::init()
  2230. {
  2231. bg = CSDL_Ext::newSurface(68,193,screen);
  2232. SDL_BlitSurface(LOCPLINT->adventureInt->bg,&genRect(193,68,607,196),bg,&genRect(193,68,0,0));
  2233. }
  2234. void CHeroList::genList()
  2235. {
  2236. int howMany = LOCPLINT->cb->howManyHeroes();
  2237. for (int i=0;i<howMany;i++)
  2238. {
  2239. const CGHeroInstance * h = LOCPLINT->cb->getHeroInfo(i,0);
  2240. if(!h->inTownGarrison)
  2241. items.push_back(std::pair<const CGHeroInstance *,CPath *>(h,NULL));
  2242. }
  2243. }
  2244. void CHeroList::select(int which)
  2245. {
  2246. if (which<0)
  2247. {
  2248. selected = which;
  2249. LOCPLINT->adventureInt->selection = NULL;
  2250. LOCPLINT->adventureInt->terrain.currentPath = NULL;
  2251. draw();
  2252. LOCPLINT->adventureInt->infoBar.draw(NULL);
  2253. }
  2254. if (which>=items.size())
  2255. return;
  2256. selected = which;
  2257. LOCPLINT->adventureInt->centerOn(items[which].first->pos);
  2258. LOCPLINT->adventureInt->selection = items[which].first;
  2259. LOCPLINT->adventureInt->terrain.currentPath = items[which].second;
  2260. draw();
  2261. LOCPLINT->adventureInt->townList.draw();
  2262. LOCPLINT->adventureInt->infoBar.draw(NULL);
  2263. LOCPLINT->cb->setSelection(items[which].first);
  2264. }
  2265. void CHeroList::clickLeft(tribool down)
  2266. {
  2267. if (down)
  2268. {
  2269. /***************************ARROWS*****************************************/
  2270. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  2271. {
  2272. blitAt(arrup->ourImages[1].bitmap,arrupp.x,arrupp.y);
  2273. pressed = true;
  2274. return;
  2275. }
  2276. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  2277. {
  2278. blitAt(arrdo->ourImages[1].bitmap,arrdop.x,arrdop.y);
  2279. pressed = false;
  2280. return;
  2281. }
  2282. /***************************HEROES*****************************************/
  2283. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2284. hx-=pos.x;
  2285. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2286. int ny = hy/32;
  2287. if (ny>=5 || ny<0)
  2288. return;
  2289. if ( (ny+from)==selected && (LOCPLINT->adventureInt->selection->ID == HEROI_TYPE))
  2290. LOCPLINT->openHeroWindow(items[selected].first);//print hero screen
  2291. select(ny+from);
  2292. }
  2293. else
  2294. {
  2295. if (indeterminate(pressed))
  2296. return;
  2297. if (pressed) //up
  2298. {
  2299. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  2300. pressed = indeterminate;
  2301. if (!down)
  2302. {
  2303. from--;
  2304. if (from<0)
  2305. from=0;
  2306. draw();
  2307. }
  2308. }
  2309. else if (!pressed) //down
  2310. {
  2311. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  2312. pressed = indeterminate;
  2313. if (!down)
  2314. {
  2315. from++;
  2316. //if (from<items.size()-5)
  2317. // from=items.size()-5;
  2318. draw();
  2319. }
  2320. }
  2321. else
  2322. throw 0;
  2323. }
  2324. }
  2325. void CHeroList::mouseMoved (const SDL_MouseMotionEvent & sEvent)
  2326. {
  2327. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  2328. {
  2329. if (from>0)
  2330. LOCPLINT->adventureInt->statusbar.print(CGI->preth->zelp[303].first);
  2331. else
  2332. LOCPLINT->adventureInt->statusbar.clear();
  2333. return;
  2334. }
  2335. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  2336. {
  2337. if ((items.size()-from) > 5)
  2338. LOCPLINT->adventureInt->statusbar.print(CGI->preth->zelp[304].first);
  2339. else
  2340. LOCPLINT->adventureInt->statusbar.clear();
  2341. return;
  2342. }
  2343. //if not buttons then heroes
  2344. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2345. hx-=pos.x;
  2346. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2347. int ny = hy/32;
  2348. if ((ny>5 || ny<0) || (from+ny>=items.size()))
  2349. {
  2350. LOCPLINT->adventureInt->statusbar.clear();
  2351. return;
  2352. }
  2353. std::vector<std::string> temp;
  2354. temp.push_back(items[from+ny].first->name);
  2355. temp.push_back(items[from+ny].first->type->heroClass->name);
  2356. LOCPLINT->adventureInt->statusbar.print( processStr(CGI->generaltexth->allTexts[15],temp) );
  2357. //select(ny+from);
  2358. }
  2359. void CHeroList::clickRight(tribool down)
  2360. {
  2361. if (down)
  2362. {
  2363. /***************************ARROWS*****************************************/
  2364. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  2365. {
  2366. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[303].second,down,this);
  2367. }
  2368. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  2369. {
  2370. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[304].second,down,this);
  2371. }
  2372. //if not buttons then heroes
  2373. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2374. hx-=pos.x;
  2375. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2376. int ny = hy/32;
  2377. if ((ny>5 || ny<0) || (from+ny>=items.size()))
  2378. {
  2379. return;
  2380. }
  2381. //show popup
  2382. CInfoPopup * ip = new CInfoPopup(graphics->heroWins[items[from+ny].first->subID],LOCPLINT->current->motion.x-graphics->heroWins[items[from+ny].first->subID]->w,LOCPLINT->current->motion.y-graphics->heroWins[items[from+ny].first->subID]->h,false);
  2383. ip->activate();
  2384. }
  2385. else
  2386. {
  2387. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[303].second,down,this);
  2388. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[304].second,down,this);
  2389. }
  2390. }
  2391. void CHeroList::hover (bool on)
  2392. {
  2393. }
  2394. void CHeroList::keyPressed (const SDL_KeyboardEvent & key)
  2395. {
  2396. }
  2397. void CHeroList::updateHList()
  2398. {
  2399. items.clear();
  2400. genList();
  2401. if(selected>=items.size())
  2402. select(items.size()-1);
  2403. if(items.size()==0)
  2404. LOCPLINT->adventureInt->townList.select(0);
  2405. else
  2406. select(selected);
  2407. }
  2408. void CHeroList::updateMove(const CGHeroInstance* which) //draws move points bar
  2409. {
  2410. int ser = LOCPLINT->cb->getHeroSerial(which);
  2411. ser -= from;
  2412. int pom = std::min((which->movement)/100,(int)mobile->ourImages.size()-1);
  2413. blitAt(mobile->ourImages[pom].bitmap,posmobx,posmoby+ser*32); //move point
  2414. }
  2415. void CHeroList::draw()
  2416. {
  2417. for (int iT=0+from;iT<5+from;iT++)
  2418. {
  2419. int i = iT-from;
  2420. if (iT>=items.size())
  2421. {
  2422. blitAt(mobile->ourImages[0].bitmap,posmobx,posmoby+i*32);
  2423. blitAt(mana->ourImages[0].bitmap,posmanx,posmany+i*32);
  2424. blitAt(empty,posporx,pospory+i*32);
  2425. continue;
  2426. }
  2427. const CGHeroInstance *cur = items[iT].first;
  2428. int pom = cur->movement / 100;
  2429. if (pom>25) pom=25;
  2430. if (pom<0) pom=0;
  2431. blitAt(mobile->ourImages[pom].bitmap,posmobx,posmoby+i*32); //move point
  2432. pom = cur->mana / 5; //bylo: .../10;
  2433. if (pom>25) pom=25;
  2434. if (pom<0) pom=0;
  2435. blitAt(mana->ourImages[pom].bitmap,posmanx,posmany+i*32); //mana
  2436. SDL_Surface * temp = graphics->portraitSmall[cur->portrait];
  2437. blitAt(temp,posporx,pospory+i*32);
  2438. if ((selected == iT) && (LOCPLINT->adventureInt->selection->ID == HEROI_TYPE))
  2439. {
  2440. blitAt(selection,posporx,pospory+i*32);
  2441. }
  2442. //TODO: support for custom portraits
  2443. }
  2444. if (from>0)
  2445. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  2446. else
  2447. blitAt(arrup->ourImages[2].bitmap,arrupp.x,arrupp.y);
  2448. if (items.size()-from>5)
  2449. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  2450. else
  2451. blitAt(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y);
  2452. }
  2453. int CHeroList::getPosOfHero(const CArmedInstance* h)
  2454. {
  2455. return vstd::findPos(items,h,boost::bind(vstd::equal<std::pair<const CGHeroInstance*, CPath *>,const CArmedInstance *,const CGHeroInstance*>,_1,&std::pair<const CGHeroInstance*, CPath *>::first,_2));
  2456. }
  2457. CTownList::~CTownList()
  2458. {
  2459. delete arrup;
  2460. delete arrdo;
  2461. }
  2462. CTownList::CTownList(int Size, SDL_Rect * Pos, int arupx, int arupy, int ardox, int ardoy)
  2463. :CList(Size)
  2464. {
  2465. pos = *Pos;
  2466. arrup = CDefHandler::giveDef("IAM014.DEF");
  2467. arrdo = CDefHandler::giveDef("IAM015.DEF");
  2468. arrupp.x=arupx;
  2469. arrupp.y=arupy;
  2470. arrupp.w=arrup->ourImages[0].bitmap->w;
  2471. arrupp.h=arrup->ourImages[0].bitmap->h;
  2472. arrdop.x=ardox;
  2473. arrdop.y=ardoy;
  2474. arrdop.w=arrdo->ourImages[0].bitmap->w;
  2475. arrdop.h=arrdo->ourImages[0].bitmap->h;
  2476. posporx = arrdop.x;
  2477. pospory = arrupp.y + arrupp.h;
  2478. pressed = indeterminate;
  2479. from = 0;
  2480. }
  2481. void CTownList::genList()
  2482. {
  2483. int howMany = LOCPLINT->cb->howManyTowns();
  2484. for (int i=0;i<howMany;i++)
  2485. {
  2486. items.push_back(LOCPLINT->cb->getTownInfo(i,0));
  2487. }
  2488. }
  2489. void CTownList::select(int which)
  2490. {
  2491. if (which>=items.size())
  2492. return;
  2493. selected = which;
  2494. if(!fun.empty())
  2495. fun();
  2496. }
  2497. void CTownList::mouseMoved (const SDL_MouseMotionEvent & sEvent)
  2498. {
  2499. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  2500. {
  2501. if (from>0)
  2502. LOCPLINT->statusbar->print(CGI->preth->zelp[306].first);
  2503. else
  2504. LOCPLINT->statusbar->clear();
  2505. return;
  2506. }
  2507. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  2508. {
  2509. if ((items.size()-from) > SIZE)
  2510. LOCPLINT->statusbar->print(CGI->preth->zelp[307].first);
  2511. else
  2512. LOCPLINT->statusbar->clear();
  2513. return;
  2514. }
  2515. //if not buttons then towns
  2516. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2517. hx-=pos.x;
  2518. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2519. int ny = hy/32;
  2520. if ((ny>SIZE || ny<0) || (from+ny>=items.size()))
  2521. {
  2522. LOCPLINT->statusbar->clear();
  2523. return;
  2524. };
  2525. LOCPLINT->statusbar->print(items[from+ny]->name);
  2526. }
  2527. void CTownList::clickLeft(tribool down)
  2528. {
  2529. if (down)
  2530. {
  2531. /***************************ARROWS*****************************************/
  2532. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  2533. {
  2534. blitAt(arrup->ourImages[1].bitmap,arrupp.x,arrupp.y);
  2535. pressed = true;
  2536. return;
  2537. }
  2538. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>SIZE))
  2539. {
  2540. blitAt(arrdo->ourImages[1].bitmap,arrdop.x,arrdop.y);
  2541. pressed = false;
  2542. return;
  2543. }
  2544. /***************************TOWNS*****************************************/
  2545. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2546. hx-=pos.x;
  2547. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2548. int ny = hy/32;
  2549. if (ny>SIZE || ny<0)
  2550. return;
  2551. if (SIZE==5 && (ny+from)==selected && (LOCPLINT->adventureInt->selection->ID == TOWNI_TYPE))
  2552. LOCPLINT->openTownWindow(items[selected]);//print town screen
  2553. else
  2554. select(ny+from);
  2555. }
  2556. else
  2557. {
  2558. if (indeterminate(pressed))
  2559. return;
  2560. if (pressed) //up
  2561. {
  2562. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  2563. pressed = indeterminate;
  2564. if (!down)
  2565. {
  2566. from--;
  2567. if (from<0)
  2568. from=0;
  2569. draw();
  2570. }
  2571. }
  2572. else if (!pressed) //down
  2573. {
  2574. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  2575. pressed = indeterminate;
  2576. if (!down)
  2577. {
  2578. from++;
  2579. //if (from<items.size()-5)
  2580. // from=items.size()-5;
  2581. draw();
  2582. }
  2583. }
  2584. else
  2585. throw 0;
  2586. }
  2587. }
  2588. void CTownList::clickRight(tribool down)
  2589. {
  2590. if (down)
  2591. {
  2592. /***************************ARROWS*****************************************/
  2593. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  2594. {
  2595. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[306].second,down,this);
  2596. }
  2597. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  2598. {
  2599. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[307].second,down,this);
  2600. }
  2601. //if not buttons then towns
  2602. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2603. hx-=pos.x;
  2604. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2605. int ny = hy/32;
  2606. if ((ny>5 || ny<0) || (from+ny>=items.size()))
  2607. {
  2608. return;
  2609. }
  2610. //show popup
  2611. CInfoPopup * ip = new CInfoPopup(graphics->townWins[items[from+ny]->id],LOCPLINT->current->motion.x-graphics->townWins[items[from+ny]->id]->w,LOCPLINT->current->motion.y-graphics->townWins[items[from+ny]->id]->h,false);
  2612. ip->activate();
  2613. }
  2614. else
  2615. {
  2616. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[306].second,down,this);
  2617. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[307].second,down,this);
  2618. }
  2619. }
  2620. void CTownList::hover (bool on)
  2621. {
  2622. }
  2623. void CTownList::keyPressed (const SDL_KeyboardEvent & key)
  2624. {
  2625. }
  2626. void CTownList::draw()
  2627. {
  2628. for (int iT=0+from;iT<SIZE+from;iT++)
  2629. {
  2630. int i = iT-from;
  2631. if (iT>=items.size())
  2632. {
  2633. blitAt(graphics->getPic(-1),posporx,pospory+i*32);
  2634. continue;
  2635. }
  2636. blitAt(graphics->getPic(items[iT]->subID,items[iT]->hasFort(),items[iT]->builded),posporx,pospory+i*32);
  2637. if ((selected == iT) && (LOCPLINT->adventureInt->selection->ID == TOWNI_TYPE))
  2638. {
  2639. blitAt(graphics->getPic(-2),posporx,pospory+i*32);
  2640. }
  2641. }
  2642. if (from>0)
  2643. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  2644. else
  2645. blitAt(arrup->ourImages[2].bitmap,arrupp.x,arrupp.y);
  2646. if (items.size()-from>SIZE)
  2647. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  2648. else
  2649. blitAt(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y);
  2650. }
  2651. CCreaturePic::CCreaturePic(CCreature *cre, bool Big)
  2652. :c(cre),big(Big)
  2653. {
  2654. anim = new CCreatureAnimation(cre->animDefName);
  2655. }
  2656. CCreaturePic::~CCreaturePic()
  2657. {
  2658. delete anim;
  2659. }
  2660. int CCreaturePic::blitPic(SDL_Surface *to, int x, int y, bool nextFrame)
  2661. {
  2662. SDL_Rect dst;
  2663. if(big)
  2664. {
  2665. blitAt(graphics->backgrounds[c->faction],x,y);//curx-50,pos.y+130-65);
  2666. dst = genRect(130,100,x,y);
  2667. }
  2668. else
  2669. {
  2670. blitAt(graphics->backgroundsm[c->faction],x,y);//curx-50,pos.y+130-65);
  2671. dst = genRect(120,100,x,y);
  2672. }
  2673. if(c->isDoubleWide())
  2674. x-=15;
  2675. return anim->nextFrameMiddle(to,x+70,y+45,true,nextFrame,false,&dst);
  2676. }
  2677. SDL_Surface * CCreaturePic::getPic(bool nextFrame)
  2678. {
  2679. //TODO: write
  2680. return NULL;
  2681. }
  2682. void CRecrutationWindow::close()
  2683. {
  2684. deactivate();
  2685. delete this;
  2686. LOCPLINT->curint->activate();
  2687. }
  2688. void CRecrutationWindow::Max()
  2689. {
  2690. slider->moveTo(slider->amount);
  2691. }
  2692. void CRecrutationWindow::Buy()
  2693. {
  2694. recruit(creatures[which].ID,slider->value);
  2695. close();
  2696. }
  2697. void CRecrutationWindow::Cancel()
  2698. {
  2699. close();
  2700. }
  2701. void CRecrutationWindow::sliderMoved(int to)
  2702. {
  2703. }
  2704. void CRecrutationWindow::clickLeft(tribool down)
  2705. {
  2706. int curx = 192 + 51 - (102*creatures.size()/2) - (18*(creatures.size()-1)/2);
  2707. for(int i=0;i<creatures.size();i++)
  2708. {
  2709. if(isItIn(&genRect(132,102,pos.x+curx,pos.y+64),LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  2710. {
  2711. which = i;
  2712. int newAmount = min(amounts[i],creatures[i].amount);
  2713. slider->amount = newAmount;
  2714. if(slider->value > newAmount)
  2715. slider->moveTo(newAmount);
  2716. else
  2717. slider->moveTo(slider->value);
  2718. curx = 192 + 51 - (102*creatures.size()/2) - (18*(creatures.size()-1)/2);
  2719. for(int j=0;j<creatures.size();j++)
  2720. {
  2721. if(which==j)
  2722. drawBorder(bitmap,curx,64,102,132,int3(255,0,0));
  2723. else
  2724. drawBorder(bitmap,curx,64,102,132,int3(239,215,123));
  2725. curx += 120;
  2726. }
  2727. break;
  2728. }
  2729. curx += 120;
  2730. }
  2731. }
  2732. void CRecrutationWindow::activate()
  2733. {
  2734. LOCPLINT->objsToBlit.push_back(this);
  2735. ClickableL::activate();
  2736. buy->activate();
  2737. max->activate();
  2738. cancel->activate();
  2739. slider->activate();
  2740. }
  2741. void CRecrutationWindow::deactivate()
  2742. {
  2743. LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
  2744. ClickableL::deactivate();
  2745. buy->deactivate();
  2746. max->deactivate();
  2747. cancel->deactivate();
  2748. slider->deactivate();
  2749. }
  2750. void CRecrutationWindow::show(SDL_Surface * to)
  2751. {
  2752. static char c=0;
  2753. blitAt(bitmap,pos.x,pos.y,to?to:screen);
  2754. buy->show();
  2755. max->show();
  2756. cancel->show();
  2757. slider->show();
  2758. char pom[15];
  2759. SDL_itoa(creatures[which].amount-slider->value,pom,10); //available
  2760. printAtMiddle(pom,pos.x+205,pos.y+252,GEOR13,zwykly,screen);
  2761. SDL_itoa(slider->value,pom,10); //recruit
  2762. printAtMiddle(pom,pos.x+279,pos.y+252,GEOR13,zwykly,screen);
  2763. printAtMiddle(CGI->generaltexth->allTexts[16] + " " + CGI->creh->creatures[creatures[which].ID].namePl,pos.x+243,pos.y+32,GEOR16,tytulowy,screen); //eg "Recruit Dragon flies"
  2764. int curx = pos.x+115-creatures[which].res.size()*16;
  2765. for(int i=0;i<creatures[which].res.size();i++)
  2766. {
  2767. blitAt(graphics->resources32->ourImages[creatures[which].res[i].first].bitmap,curx,pos.y+243,screen);
  2768. blitAt(graphics->resources32->ourImages[creatures[which].res[i].first].bitmap,curx+258,pos.y+243,screen);
  2769. SDL_itoa(creatures[which].res[i].second,pom,10);
  2770. printAtMiddle(pom,curx+12,pos.y+286,GEOR13,zwykly,screen);
  2771. SDL_itoa(creatures[which].res[i].second * slider->value,pom,10);
  2772. printAtMiddle(pom,curx+12+258,pos.y+286,GEOR13,zwykly,screen);
  2773. curx+=32;
  2774. }
  2775. curx = pos.x + 192 + 102 - (102*creatures.size()/2) - (18*(creatures.size()-1)/2);
  2776. for(int i=0;i<creatures.size();i++)
  2777. {
  2778. creatures[i].pic->blitPic(screen,curx-50,pos.y+130-65,!(c%4));
  2779. curx += 120;
  2780. }
  2781. c++;
  2782. }
  2783. CRecrutationWindow::CRecrutationWindow(const std::vector<std::pair<int,int> > &Creatures, const boost::function<void(int,int)> &Recruit) //creatures - pairs<creature_ID,amount>
  2784. :recruit(Recruit)
  2785. {
  2786. which = 0;
  2787. creatures.resize(Creatures.size());
  2788. amounts.resize(Creatures.size());
  2789. for(int i=0;i<creatures.size();i++)
  2790. {
  2791. creatures[i].amount = Creatures[i].second;
  2792. creatures[i].ID = Creatures[i].first;
  2793. for(int j=0;j<CGI->creh->creatures[Creatures[i].first].cost.size();j++)
  2794. if(CGI->creh->creatures[Creatures[i].first].cost[j])
  2795. creatures[i].res.push_back(std::make_pair(j,CGI->creh->creatures[Creatures[i].first].cost[j]));
  2796. creatures[i].pic = new CCreaturePic(&CGI->creh->creatures[Creatures[i].first]);
  2797. amounts[i] = CGI->creh->creatures[Creatures[i].first].maxAmount(LOCPLINT->cb->getResourceAmount());
  2798. }
  2799. SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPRCRT.bmp");
  2800. graphics->blueToPlayersAdv(hhlp,LOCPLINT->playerID);
  2801. bitmap = SDL_ConvertSurface(hhlp,screen->format,0); //na 8bitowej mapie by sie psulo
  2802. SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
  2803. SDL_FreeSurface(hhlp);
  2804. pos.x = screen->w/2 - bitmap->w/2;
  2805. pos.y = screen->h/2 - bitmap->h/2;
  2806. pos.w = bitmap->w;
  2807. pos.h = bitmap->h;
  2808. slider = new CSlider(pos.x+176,pos.y+279,135,boost::bind(&CRecrutationWindow::sliderMoved,this, _1),1,min(amounts[0],creatures[0].amount),0,true);
  2809. std::string pom;
  2810. printAtMiddle(CGI->generaltexth->allTexts[346],113,231,GEOR13,zwykly,bitmap); //cost per troop t
  2811. printAtMiddle(CGI->generaltexth->allTexts[465],205,231,GEOR13,zwykly,bitmap); //available t
  2812. printAtMiddle(CGI->generaltexth->allTexts[16],279,231,GEOR13,zwykly,bitmap); //recruit t
  2813. printAtMiddle(CGI->generaltexth->allTexts[466],373,231,GEOR13,zwykly,bitmap); //total cost t
  2814. drawBorder(bitmap,172,222,67,42,int3(239,215,123));
  2815. drawBorder(bitmap,246,222,67,42,int3(239,215,123));
  2816. drawBorder(bitmap,64,222,99,76,int3(239,215,123));
  2817. drawBorder(bitmap,322,222,99,76,int3(239,215,123));
  2818. drawBorder(bitmap,133,312,66,34,int3(173,142,66));
  2819. drawBorder(bitmap,211,312,66,34,int3(173,142,66));
  2820. drawBorder(bitmap,289,312,66,34,int3(173,142,66));
  2821. //border for creatures
  2822. int curx = 192 + 51 - (102*creatures.size()/2) - (18*(creatures.size()-1)/2);
  2823. for(int i=0;i<creatures.size();i++)
  2824. {
  2825. creatures[i].pos.x = curx+1;
  2826. creatures[i].pos.y = 65;
  2827. creatures[i].pos.w = 100;
  2828. creatures[i].pos.h = 130;
  2829. if(which==i)
  2830. drawBorder(bitmap,curx,64,102,132,int3(255,0,0));
  2831. else
  2832. drawBorder(bitmap,curx,64,102,132,int3(239,215,123));
  2833. curx += 120;
  2834. }
  2835. max = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Max,this),pos.x+134,pos.y+313,"IRCBTNS.DEF",SDLK_m);
  2836. buy = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Buy,this),pos.x+212,pos.y+313,"IBY6432.DEF",SDLK_RETURN);
  2837. cancel = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Cancel,this),pos.x+290,pos.y+313,"ICN6432.DEF",SDLK_ESCAPE);
  2838. if(!creatures[0].amount)
  2839. {
  2840. max->block(true);
  2841. buy->block(true);
  2842. }
  2843. }
  2844. CRecrutationWindow::~CRecrutationWindow()
  2845. {
  2846. for(int i=0;i<creatures.size();i++)
  2847. {
  2848. delete creatures[i].pic;
  2849. }
  2850. delete max;
  2851. delete buy;
  2852. delete cancel;
  2853. SDL_FreeSurface(bitmap);
  2854. delete slider;
  2855. }
  2856. CSplitWindow::CSplitWindow(int cid, int max, CGarrisonInt *Owner)
  2857. {
  2858. c=cid;
  2859. slider = NULL;
  2860. gar = Owner;
  2861. bitmap = BitmapHandler::loadBitmap("GPUCRDIV.bmp");
  2862. SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
  2863. pos.x = screen->w/2 - bitmap->w/2;
  2864. pos.y = screen->h/2 - bitmap->h/2;
  2865. pos.w = bitmap->w;
  2866. pos.h = bitmap->h;
  2867. ok = new AdventureMapButton("","",boost::bind(&CSplitWindow::split,this),pos.x+20,pos.y+263,"IOK6432.DEF",SDLK_RETURN);
  2868. cancel = new AdventureMapButton("","",boost::bind(&CSplitWindow::close,this),pos.x+214,pos.y+263,"ICN6432.DEF",SDLK_ESCAPE);
  2869. slider = new CSlider(pos.x+21,pos.y+194,257,boost::bind(&CSplitWindow::sliderMoved,this,_1),1,max,0,true);
  2870. a1 = max;
  2871. a2 = 0;
  2872. anim = new CCreaturePic(&CGI->creh->creatures[cid]);
  2873. anim->anim->setType(1);
  2874. std::string title = CGI->generaltexth->allTexts[256];
  2875. boost::algorithm::replace_first(title,"%s",CGI->creh->creatures[cid].namePl);
  2876. printAtMiddle(title,150,34,GEOR16,tytulowy,bitmap);
  2877. }
  2878. CSplitWindow::~CSplitWindow()
  2879. {
  2880. SDL_FreeSurface(bitmap);
  2881. delete ok;
  2882. delete cancel;
  2883. delete slider;
  2884. delete anim;
  2885. }
  2886. void CSplitWindow::activate()
  2887. {
  2888. LOCPLINT->objsToBlit.push_back(this);
  2889. KeyInterested::activate();
  2890. ok->activate();
  2891. cancel->activate();
  2892. slider->activate();
  2893. }
  2894. void CSplitWindow::deactivate()
  2895. {
  2896. LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
  2897. KeyInterested::deactivate();
  2898. ok->deactivate();
  2899. cancel->deactivate();
  2900. slider->deactivate();
  2901. }
  2902. void CSplitWindow::split()
  2903. {
  2904. gar->splitStacks(a2);
  2905. close();
  2906. }
  2907. void CSplitWindow::close()
  2908. {
  2909. deactivate();
  2910. delete this;
  2911. LOCPLINT->curint->activate();
  2912. }
  2913. void CSplitWindow::sliderMoved(int to)
  2914. {
  2915. a2 = to;
  2916. if(slider)
  2917. a1 = slider->amount - to;
  2918. }
  2919. void CSplitWindow::show(SDL_Surface * to)
  2920. {
  2921. char pom[15];
  2922. blitAt(bitmap,pos.x,pos.y,screen);
  2923. ok->show();
  2924. cancel->show();
  2925. slider->show();
  2926. SDL_itoa(a1,pom,10);
  2927. printAtMiddle(pom,pos.x+70,pos.y+237,GEOR16,zwykly,screen);
  2928. SDL_itoa(a2,pom,10);
  2929. printAtMiddle(pom,pos.x+233,pos.y+237,GEOR16,zwykly,screen);
  2930. anim->blitPic(screen,pos.x+20,pos.y+54,false);
  2931. anim->blitPic(screen,pos.x+177,pos.y+54,false);
  2932. }
  2933. void CSplitWindow::keyPressed (const SDL_KeyboardEvent & key)
  2934. {
  2935. //TODO: make manual typing possible
  2936. }
  2937. void CCreInfoWindow::show(SDL_Surface * to)
  2938. {
  2939. char pom[15];
  2940. blitAt(bitmap,pos.x,pos.y,screen);
  2941. anim->blitPic(screen,pos.x+21,pos.y+48,(type) && !(anf%4));
  2942. if(++anf==4)
  2943. anf=0;
  2944. if(count.size())
  2945. printTo(count.c_str(),pos.x+114,pos.y+174,GEOR16,zwykly);
  2946. if(upgrade)
  2947. upgrade->show();
  2948. if(dismiss)
  2949. dismiss->show();
  2950. if(ok)
  2951. ok->show();
  2952. }
  2953. CCreInfoWindow::CCreInfoWindow(int Cid, int Type, int creatureCount, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm, UpgradeInfo *ui)
  2954. :ok(0),dismiss(0),upgrade(0),type(Type),dsm(Dsm),dependant(0)
  2955. {
  2956. active = false;
  2957. anf = 0;
  2958. c = &CGI->creh->creatures[Cid];
  2959. bitmap = BitmapHandler::loadBitmap("CRSTKPU.bmp");
  2960. pos.x = screen->w/2 - bitmap->w/2;
  2961. pos.y = screen->h/2 - bitmap->h/2;
  2962. pos.w = bitmap->w;
  2963. pos.h = bitmap->h;
  2964. graphics->blueToPlayersAdv(bitmap,LOCPLINT->playerID);
  2965. SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
  2966. anim = new CCreaturePic(c);
  2967. if(!type) anim->anim->setType(1);
  2968. char pom[75];int hlp=0;
  2969. if(creatureCount)
  2970. {
  2971. SDL_itoa(creatureCount,pom,10);
  2972. count = pom;
  2973. }
  2974. printAtMiddle(c->namePl,149,30,GEOR13,zwykly,bitmap); //creature name
  2975. //atttack
  2976. printAt(CGI->preth->zelp[435].first,155,48,GEOR13,zwykly,bitmap);
  2977. SDL_itoa(c->attack,pom,10);
  2978. if(State && State->attackBonus)
  2979. {
  2980. int hlp = log10f(c->attack)+2;
  2981. pom[hlp-1] = ' '; pom[hlp] = '(';
  2982. SDL_itoa(c->attack+State->attackBonus,pom+hlp+1,10);
  2983. hlp += 2+(int)log10f(State->attackBonus+c->attack);
  2984. pom[hlp] = ')'; pom[hlp+1] = '\0';
  2985. }
  2986. printToWR(pom,276,61,GEOR13,zwykly,bitmap);
  2987. //defense
  2988. printAt(CGI->preth->zelp[436].first,155,67,GEOR13,zwykly,bitmap);
  2989. SDL_itoa(c->defence,pom,10);
  2990. if(State && State->defenseBonus)
  2991. {
  2992. int hlp = log10f(c->defence)+2;
  2993. pom[hlp-1] = ' '; pom[hlp] = '(';
  2994. SDL_itoa(c->defence+State->defenseBonus,pom+hlp+1,10);
  2995. hlp += 2+(int)log10f(State->defenseBonus+c->defence);
  2996. pom[hlp] = ')'; pom[hlp+1] = '\0';
  2997. }
  2998. printToWR(pom,276,80,GEOR13,zwykly,bitmap);
  2999. //shots
  3000. if(c->shots)
  3001. {
  3002. printAt(CGI->generaltexth->allTexts[198],155,86,GEOR13,zwykly,bitmap);
  3003. if(State)
  3004. sprintf(pom,"%d(%d)",c->shots,State->shotsLeft);
  3005. else
  3006. SDL_itoa(c->shots,pom,10);
  3007. printToWR(pom,276,99,GEOR13,zwykly,bitmap);
  3008. }
  3009. //damage
  3010. printAt(CGI->generaltexth->allTexts[199],155,105,GEOR13,zwykly,bitmap);
  3011. SDL_itoa(c->damageMin,pom,10);
  3012. hlp=log10f(c->damageMin)+2;
  3013. pom[hlp-1]=' '; pom[hlp]='-'; pom[hlp+1]=' ';
  3014. SDL_itoa(c->damageMax,pom+hlp+2,10);
  3015. printToWR(pom,276,118,GEOR13,zwykly,bitmap);
  3016. //health
  3017. printAt(CGI->preth->zelp[439].first,155,124,GEOR13,zwykly,bitmap);
  3018. SDL_itoa(c->hitPoints,pom,10);
  3019. printToWR(pom,276,137,GEOR13,zwykly,bitmap);
  3020. //remaining health
  3021. if(State && State->currentHealth)
  3022. {
  3023. printAt(CGI->preth->zelp[440].first,155,143,GEOR13,zwykly,bitmap);
  3024. SDL_itoa(State->currentHealth,pom,10);
  3025. printToWR(pom,276,156,GEOR13,zwykly,bitmap);
  3026. }
  3027. //speed
  3028. printAt(CGI->preth->zelp[441].first,155,162,GEOR13,zwykly,bitmap);
  3029. SDL_itoa(c->speed,pom,10);
  3030. printToWR(pom,276,175,GEOR13,zwykly,bitmap);
  3031. //luck and morale
  3032. blitAt(graphics->morale42->ourImages[(State)?(State->morale+3):(3)].bitmap,24,189,bitmap);
  3033. blitAt(graphics->luck42->ourImages[(State)?(State->luck+3):(3)].bitmap,77,189,bitmap);
  3034. //print abilities text - if r-click popup
  3035. if(type)
  3036. {
  3037. if(Upg && ui)
  3038. {
  3039. bool enough = true;
  3040. for(std::set<std::pair<int,int> >::iterator i=ui->cost[0].begin(); i!=ui->cost[0].end(); i++) //calculate upgrade cost
  3041. {
  3042. if(LOCPLINT->cb->getResourceAmount(i->first) < i->second*creatureCount)
  3043. enough = false;
  3044. upgResCost.push_back(new SComponent(SComponent::resource,i->first,i->second*creatureCount));
  3045. }
  3046. if(enough)
  3047. {
  3048. CFunctionList<void()> fs[2];
  3049. fs[0] += Upg;
  3050. fs[0] += boost::bind(&CCreInfoWindow::close,this);
  3051. fs[1] += boost::bind(&CCreInfoWindow::activate,this);
  3052. CFunctionList<void()> cfl;
  3053. cfl = boost::bind(&CCreInfoWindow::deactivate,this);
  3054. cfl += boost::bind(&CPlayerInterface::showYesNoDialog,LOCPLINT,CGI->generaltexth->allTexts[207],boost::ref(upgResCost),fs[0],fs[1],false,false);
  3055. upgrade = new AdventureMapButton("",CGI->preth->zelp[446].second,cfl,pos.x+76,pos.y+237,"IVIEWCR.DEF",SDLK_u);
  3056. }
  3057. else
  3058. {
  3059. upgrade = new AdventureMapButton("",CGI->preth->zelp[446].second,boost::function<void()>(),pos.x+76,pos.y+237,"IVIEWCR.DEF");
  3060. upgrade->callback.funcs.clear();
  3061. upgrade->bitmapOffset = 2;
  3062. }
  3063. }
  3064. if(Dsm)
  3065. {
  3066. CFunctionList<void()> fs[2];
  3067. //on dismiss confirmed
  3068. fs[0] += Dsm; //dismiss
  3069. fs[0] += boost::bind(&CCreInfoWindow::close,this);//close this window
  3070. fs[1] += boost::bind(&CCreInfoWindow::activate,this);
  3071. CFunctionList<void()> cfl;
  3072. cfl = boost::bind(&CCreInfoWindow::deactivate,this);
  3073. cfl += boost::bind(&CPlayerInterface::showYesNoDialog,LOCPLINT,CGI->generaltexth->allTexts[12],std::vector<SComponent*>(),fs[0],fs[1],false,false);
  3074. dismiss = new AdventureMapButton("",CGI->preth->zelp[445].second,cfl,pos.x+21,pos.y+237,"IVIEWCR2.DEF",SDLK_d);
  3075. }
  3076. ok = new AdventureMapButton("",CGI->preth->zelp[445].second,boost::bind(&CCreInfoWindow::close,this),pos.x+216,pos.y+237,"IOKAY.DEF",SDLK_RETURN);
  3077. }
  3078. else
  3079. {
  3080. printAtWB(c->abilityText,17,231,GEOR13,35,zwykly,bitmap);
  3081. }
  3082. }
  3083. CCreInfoWindow::~CCreInfoWindow()
  3084. {
  3085. SDL_FreeSurface(bitmap);
  3086. delete anim;
  3087. delete upgrade;
  3088. delete ok;
  3089. delete dismiss;
  3090. for(int i=0; i<upgResCost.size();i++)
  3091. delete upgResCost[i];
  3092. }
  3093. void CCreInfoWindow::activate()
  3094. {
  3095. if(active) return;
  3096. active = true;
  3097. if(!type)
  3098. ClickableR::activate();
  3099. LOCPLINT->objsToBlit.push_back(this);
  3100. if(ok)
  3101. ok->activate();
  3102. if(dismiss)
  3103. dismiss->activate();
  3104. if(upgrade)
  3105. upgrade->activate();
  3106. }
  3107. void CCreInfoWindow::close()
  3108. {
  3109. deactivate();
  3110. if(dynamic_cast<CHeroWindow*>(LOCPLINT->curint->subInt))
  3111. {
  3112. if(type)
  3113. LOCPLINT->curint->subInt->activate();
  3114. }
  3115. else
  3116. {
  3117. CCastleInterface *c = dynamic_cast<CCastleInterface*>(LOCPLINT->curint);
  3118. if(c)
  3119. c->showAll();
  3120. if(type)
  3121. LOCPLINT->curint->activate();
  3122. }
  3123. delete this;
  3124. }
  3125. void CCreInfoWindow::clickRight(boost::logic::tribool down)
  3126. {
  3127. if(down)
  3128. return;
  3129. close();
  3130. }
  3131. void CCreInfoWindow::dismissF()
  3132. {
  3133. dsm();
  3134. close();
  3135. }
  3136. void CCreInfoWindow::keyPressed (const SDL_KeyboardEvent & key)
  3137. {
  3138. }
  3139. void CCreInfoWindow::deactivate()
  3140. {
  3141. if(!active) return;
  3142. active = false;
  3143. if(!type)
  3144. ClickableR::deactivate();
  3145. LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
  3146. if(ok)
  3147. ok->deactivate();
  3148. if(dismiss)
  3149. dismiss->deactivate();
  3150. if(upgrade)
  3151. upgrade->deactivate();
  3152. }
  3153. void CCreInfoWindow::onUpgradeYes()
  3154. {
  3155. dependant->close();
  3156. dependant->deactivate();
  3157. delete dependant;
  3158. LOCPLINT->curint->activate();
  3159. }
  3160. void CCreInfoWindow::onUpgradeNo()
  3161. {
  3162. }
  3163. void CLevelWindow::close()
  3164. {
  3165. deactivate();
  3166. for(int i=0;i<comps.size();i++)
  3167. {
  3168. if(comps[i]->selected)
  3169. {
  3170. cb(i);
  3171. break;
  3172. }
  3173. }
  3174. delete this;
  3175. LOCPLINT->curint->activate();
  3176. }
  3177. CLevelWindow::CLevelWindow(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback)
  3178. {
  3179. heroType = hero->subID;
  3180. cb = callback;
  3181. for(int i=0;i<skills.size();i++)
  3182. comps.push_back(new CSelectableComponent(SComponent::secskill44,skills[i],hero->getSecSkillLevel(skills[i])+1,boost::bind(&CLevelWindow::selectionChanged,this,i)));
  3183. bitmap = BitmapHandler::loadBitmap("LVLUPBKG.bmp");
  3184. graphics->blueToPlayersAdv(bitmap,hero->tempOwner);
  3185. SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
  3186. pos.x = screen->w/2 - bitmap->w/2;
  3187. pos.y = screen->h/2 - bitmap->h/2;
  3188. pos.w = bitmap->w;
  3189. pos.h = bitmap->h;
  3190. ok = new AdventureMapButton("","",boost::bind(&CLevelWindow::close,this),pos.x+297,pos.y+413,"IOKAY.DEF",SDLK_RETURN);
  3191. //draw window
  3192. char buf[100], buf2[100];
  3193. strcpy(buf2,CGI->generaltexth->allTexts[444].c_str()); //%s has gained a level.
  3194. sprintf(buf,buf2,hero->name.c_str());
  3195. printAtMiddle(buf,192,35,GEOR16,zwykly,bitmap);
  3196. strcpy(buf2,CGI->generaltexth->allTexts[445].c_str()); //%s is now a level %d %s.
  3197. sprintf(buf,buf2,hero->name.c_str(),hero->level,hero->type->heroClass->name.c_str());
  3198. printAtMiddle(buf,192,162,GEOR16,zwykly,bitmap);
  3199. blitAt(graphics->pskillsm->ourImages[pskill].bitmap,174,190,bitmap);
  3200. printAtMiddle((CGI->generaltexth->primarySkillNames[pskill] + " +1"),192,252,GEOR16,zwykly,bitmap);
  3201. SDL_Surface * ort = TTF_RenderText_Blended(GEOR16,CGI->generaltexth->allTexts[4].c_str(),zwykly);
  3202. int curx = bitmap->w/2 - ( skills.size()*44 + (skills.size()-1)*(36+ort->w) )/2;
  3203. for(int i=0;i<comps.size();i++)
  3204. {
  3205. comps[i]->pos.x = curx+pos.x;
  3206. comps[i]->pos.y = 326+pos.y;
  3207. if( i < (comps.size()-1) )
  3208. {
  3209. curx += 44 + 18; //skill width + margin to "or"
  3210. blitAt(ort,curx,346,bitmap);
  3211. curx += ort->w + 18;
  3212. }
  3213. }
  3214. SDL_FreeSurface(ort);
  3215. }
  3216. void CLevelWindow::selectionChanged(unsigned to)
  3217. {
  3218. for(int i=0;i<comps.size();i++)
  3219. if(i==to)
  3220. comps[i]->select(true);
  3221. else
  3222. comps[i]->select(false);
  3223. }
  3224. CLevelWindow::~CLevelWindow()
  3225. {
  3226. delete ok;
  3227. for(int i=0;i<comps.size();i++)
  3228. delete comps[i];
  3229. SDL_FreeSurface(bitmap);
  3230. }
  3231. void CLevelWindow::activate()
  3232. {
  3233. LOCPLINT->objsToBlit.push_back(this);
  3234. ok->activate();
  3235. for(int i=0;i<comps.size();i++)
  3236. comps[i]->activate();
  3237. }
  3238. void CLevelWindow::deactivate()
  3239. {
  3240. LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
  3241. ok->deactivate();
  3242. for(int i=0;i<comps.size();i++)
  3243. comps[i]->deactivate();
  3244. }
  3245. void CLevelWindow::show(SDL_Surface * to)
  3246. {
  3247. blitAt(bitmap,pos.x,pos.y,screen);
  3248. blitAt(graphics->portraitLarge[heroType],170+pos.x,66+pos.y);
  3249. ok->show();
  3250. for(int i=0;i<comps.size();i++)
  3251. comps[i]->show();
  3252. }
  3253. void CMinorResDataBar::show(SDL_Surface * to)
  3254. {
  3255. blitAt(bg,pos.x,pos.y);
  3256. char * buf = new char[15];
  3257. for (int i=0;i<7;i++)
  3258. {
  3259. SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
  3260. CSDL_Ext::printAtMiddle(buf,pos.x + 50 + 76*i,pos.y+pos.h/2,GEOR13,zwykly);
  3261. }
  3262. std::vector<std::string> temp;
  3263. SDL_itoa(LOCPLINT->cb->getDate(3),buf,10); temp.push_back(std::string(buf));
  3264. SDL_itoa(LOCPLINT->cb->getDate(2),buf,10); temp.push_back(buf);
  3265. SDL_itoa(LOCPLINT->cb->getDate(1),buf,10); temp.push_back(buf);
  3266. CSDL_Ext::printAtMiddle(CSDL_Ext::processStr(
  3267. CGI->generaltexth->allTexts[62]
  3268. +": %s, "
  3269. + CGI->generaltexth->allTexts[63]
  3270. + ": %s, "
  3271. + CGI->generaltexth->allTexts[64]
  3272. + ": %s",temp)
  3273. ,pos.x+545+(pos.w-545)/2,pos.y+pos.h/2,GEOR13,zwykly);
  3274. temp.clear();
  3275. //updateRect(&pos,screen);
  3276. delete[] buf;
  3277. }
  3278. CMinorResDataBar::CMinorResDataBar()
  3279. {
  3280. bg = BitmapHandler::loadBitmap("Z2ESBAR.bmp");
  3281. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  3282. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  3283. pos.x = 7;
  3284. pos.y = 575;
  3285. pos.w = bg->w;
  3286. pos.h = bg->h;
  3287. }
  3288. CMinorResDataBar::~CMinorResDataBar()
  3289. {
  3290. SDL_FreeSurface(bg);
  3291. }
  3292. SDL_Surface * CCustomImgComponent::getImg()
  3293. {
  3294. return bmp;
  3295. }
  3296. CCustomImgComponent::CCustomImgComponent( Etype Type, int Subtype, int Val, SDL_Surface *sur, bool freeSur )
  3297. :bmp(sur), free(freeSur)
  3298. {
  3299. init(Type,Subtype,Val);
  3300. }
  3301. CCustomImgComponent::~CCustomImgComponent()
  3302. {
  3303. if(free)
  3304. SDL_FreeSurface(bmp);
  3305. }
  3306. CMarketplaceWindow::CTradeableItem::CTradeableItem( int Type, int ID, bool Left)
  3307. {
  3308. left = Left;
  3309. type = Type;
  3310. id = ID;
  3311. }
  3312. void CMarketplaceWindow::CTradeableItem::show( SDL_Surface * to/*=NULL*/ )
  3313. {
  3314. SDL_Surface *hlp = getSurface();
  3315. blitAt(hlp,pos.x+19,pos.y+9,to);
  3316. }
  3317. void CMarketplaceWindow::CTradeableItem::clickLeft( boost::logic::tribool down )
  3318. {
  3319. CMarketplaceWindow *mw = static_cast<CMarketplaceWindow *>(LOCPLINT->curint->subInt);
  3320. if(down)
  3321. {
  3322. if(left)
  3323. {
  3324. if(mw->hLeft != this)
  3325. mw->hLeft = this;
  3326. else
  3327. return;
  3328. }
  3329. else
  3330. {
  3331. if(mw->hRight != this)
  3332. mw->hRight = this;
  3333. else
  3334. return;
  3335. }
  3336. mw->selectionChanged(left);
  3337. }
  3338. }
  3339. void CMarketplaceWindow::CTradeableItem::activate()
  3340. {
  3341. ClickableL::activate();
  3342. }
  3343. void CMarketplaceWindow::CTradeableItem::deactivate()
  3344. {
  3345. ClickableL::deactivate();
  3346. }
  3347. SDL_Surface * CMarketplaceWindow::CTradeableItem::getSurface()
  3348. {
  3349. switch(type)
  3350. {
  3351. case 0:
  3352. return graphics->resources32->ourImages[id].bitmap;
  3353. case 1:
  3354. return graphics->artDefs->ourImages[id].bitmap;
  3355. default:
  3356. return NULL;
  3357. }
  3358. }
  3359. void initItems( std::vector<CMarketplaceWindow::CTradeableItem*> &i, std::vector<SDL_Rect> &p, int type, int amount, bool left, std::vector<int> *ids/*=NULL*/ )
  3360. {
  3361. i.resize(amount);
  3362. for(int j=0;j<amount;j++)
  3363. {
  3364. i[j] = new CMarketplaceWindow::CTradeableItem(type,(ids && ids->size()>j) ? (*ids)[j] : j, left);
  3365. i[j]->pos = p[j];
  3366. }
  3367. }
  3368. void CMarketplaceWindow::setMode( int mode )
  3369. {
  3370. std::vector<SDL_Rect> lpos, rpos;
  3371. clear();
  3372. switch(mode)
  3373. {
  3374. case 0:
  3375. {
  3376. SDL_Surface *bg2 = BitmapHandler::loadBitmap("TPMRKRES.bmp");
  3377. SDL_SetColorKey(bg2,SDL_SRCCOLORKEY,SDL_MapRGB(bg2->format,0,255,255));
  3378. graphics->blueToPlayersAdv(bg2,LOCPLINT->playerID);
  3379. bg = SDL_ConvertSurface(bg2,screen->format,0);
  3380. SDL_FreeSurface(bg2);
  3381. lpos += genRect(66,69,39,180), genRect(66,69,122,180), genRect(66,69,204,180),
  3382. genRect(66,69,39,259), genRect(66,69,122,259), genRect(66,69,204,259),
  3383. genRect(66,69,122,338);
  3384. for(int i=0;i<lpos.size();i++)
  3385. {
  3386. lpos[i].x += pos.x;
  3387. lpos[i].y += pos.y;
  3388. rpos.push_back(lpos[i]);
  3389. rpos[rpos.size()-1].x += 288;
  3390. }
  3391. initItems(left,lpos,0,7,true,NULL);
  3392. initItems(right,rpos,0,7,false,NULL);
  3393. printAtMiddle(CGI->generaltexth->allTexts[158],303,28,GEORXX,tytulowy,bg); //title
  3394. printAtMiddle(CGI->generaltexth->allTexts[270],158,148,GEOR13,zwykly,bg); //kingdom res.
  3395. printAtMiddle(CGI->generaltexth->allTexts[168],450,148,GEOR13,zwykly,bg); //available for trade
  3396. }
  3397. }
  3398. }
  3399. void CMarketplaceWindow::clear()
  3400. {
  3401. for(int i=0;i<left.size();i++)
  3402. delete left[i];
  3403. for(int i=0;i<right.size();i++)
  3404. delete right[i];
  3405. left.clear();
  3406. right.clear();
  3407. SDL_FreeSurface(bg);
  3408. }
  3409. CMarketplaceWindow::CMarketplaceWindow(int Mode)
  3410. {
  3411. mode = Mode;
  3412. bg = NULL;
  3413. ok = max = deal = NULL;
  3414. pos.x = screen->w/2 - 300;
  3415. pos.y = screen->h/2 - 296;
  3416. slider = new CSlider(pos.x+231,pos.y+490,137,boost::bind(&CMarketplaceWindow::sliderMoved,this,_1),0,0);
  3417. setMode(mode);
  3418. hLeft = hRight = NULL;
  3419. ok = new AdventureMapButton("","",boost::bind(&CMarketplaceWindow::deactivate,this),pos.x+516,pos.y+520,"IOK6432.DEF",SDLK_RETURN);
  3420. ok->callback += boost::bind(&CMarketplaceWindow::clear,this); //clear
  3421. ok->callback += boost::bind(vstd::delObj<CMarketplaceWindow>,this); //will delete
  3422. ok->callback += boost::bind(&CMainInterface::activate,LOCPLINT->curint);
  3423. deal = new AdventureMapButton("","",boost::bind(&CMarketplaceWindow::makeDeal,this),pos.x+307,pos.y+520,"TPMRKB.DEF");
  3424. max = new AdventureMapButton("","",boost::bind(&CMarketplaceWindow::setMax,this),pos.x+229,pos.y+520,"IRCBTNS.DEF");
  3425. max->block(true);
  3426. deal->block(true);
  3427. }
  3428. CMarketplaceWindow::~CMarketplaceWindow()
  3429. {
  3430. delete slider;
  3431. }
  3432. void CMarketplaceWindow::show( SDL_Surface * to/*=NULL*/ )
  3433. {
  3434. blitAt(bg,pos);
  3435. if(hRight)
  3436. CSDL_Ext::drawBorder(screen,hRight->pos.x-1,hRight->pos.y-1,hRight->pos.w+2,hRight->pos.h+2,int3(255,231,148));
  3437. if(hLeft)
  3438. CSDL_Ext::drawBorder(screen,hLeft->pos.x-1,hLeft->pos.y-1,hLeft->pos.w+2,hLeft->pos.h+2,int3(255,231,148));
  3439. ok->show();
  3440. deal->show();
  3441. max->show();
  3442. slider->show();
  3443. for(int i=0;i<left.size();i++)
  3444. left[i]->show();
  3445. for(int i=0;i<right.size();i++)
  3446. right[i]->show();
  3447. if(mode==0)
  3448. {
  3449. char buf[15];
  3450. for(int i=0;i<left.size();i++)
  3451. {
  3452. SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
  3453. printAtMiddle(buf,left[i]->pos.x+35,left[i]->pos.y+56,GEOR13,zwykly);
  3454. }
  3455. if(hLeft) //print prices
  3456. {
  3457. for(int i=0; i<right.size();i++)
  3458. {
  3459. if(right[i]->id != hLeft->id)
  3460. printAtMiddle(rSubs[i],right[i]->pos.x+35,right[i]->pos.y+56,GEOR13,zwykly);
  3461. else
  3462. printAtMiddle(CGI->generaltexth->allTexts[164],right[i]->pos.x+35,right[i]->pos.y+56,GEOR13,zwykly);
  3463. }
  3464. }
  3465. if(hLeft && hRight && hLeft->id!= hRight->id)
  3466. {
  3467. blitAt(hLeft->getSurface(),pos.x+142,pos.y+457,screen);
  3468. blitAt(hRight->getSurface(),pos.x+430,pos.y+457,screen);
  3469. SDL_itoa(slider->value * r1,buf,10);
  3470. printAtMiddle(buf,pos.x+158,pos.y+504,GEOR13,zwykly);
  3471. SDL_itoa(slider->value * r2,buf,10);
  3472. printAtMiddle(buf,pos.x+446,pos.y+504,GEOR13,zwykly);
  3473. }
  3474. }
  3475. }
  3476. void CMarketplaceWindow::activate()
  3477. {
  3478. LOCPLINT->objsToBlit += this;
  3479. LOCPLINT->curint->subInt = this;
  3480. for(int i=0;i<left.size();i++)
  3481. left[i]->activate();
  3482. for(int i=0;i<right.size();i++)
  3483. right[i]->activate();
  3484. ok->activate();
  3485. max->activate();
  3486. deal->activate();
  3487. slider->activate();
  3488. }
  3489. void CMarketplaceWindow::deactivate()
  3490. {
  3491. LOCPLINT->objsToBlit -= this;
  3492. LOCPLINT->curint->subInt = NULL;
  3493. for(int i=0;i<left.size();i++)
  3494. left[i]->deactivate();
  3495. for(int i=0;i<right.size();i++)
  3496. right[i]->deactivate();
  3497. ok->deactivate();
  3498. max->deactivate();
  3499. deal->deactivate();
  3500. slider->deactivate();
  3501. }
  3502. void CMarketplaceWindow::setMax()
  3503. {
  3504. slider->moveTo(slider->amount);
  3505. }
  3506. void CMarketplaceWindow::makeDeal()
  3507. {
  3508. LOCPLINT->cb->trade(mode,hLeft->id,hRight->id,slider->value*r1);
  3509. slider->moveTo(0);
  3510. hLeft = NULL;
  3511. selectionChanged(true);
  3512. }
  3513. void CMarketplaceWindow::sliderMoved( int to )
  3514. {
  3515. }
  3516. void CMarketplaceWindow::selectionChanged(bool side)
  3517. {
  3518. if(hLeft && hRight && hLeft->id!= hRight->id)
  3519. {
  3520. LOCPLINT->cb->getMarketOffer(hLeft->id,hRight->id,r1,r2,0);
  3521. slider->amount = LOCPLINT->cb->getResourceAmount(hLeft->id) / r1;
  3522. slider->moveTo(0);
  3523. max->block(false);
  3524. deal->block(false);
  3525. }
  3526. else
  3527. {
  3528. max->block(true);
  3529. deal->block(true);
  3530. slider->amount = 0;
  3531. slider->moveTo(0);
  3532. }
  3533. if(side && hLeft) //left selection changed, recalculate offers
  3534. {
  3535. rSubs.clear();
  3536. rSubs.resize(right.size());
  3537. int h1, h2;
  3538. for(int i=0;i<right.size();i++)
  3539. {
  3540. std::ostringstream oss;
  3541. LOCPLINT->cb->getMarketOffer(hLeft->id,i,h1,h2,0);
  3542. oss << h2;
  3543. if(h1!=1)
  3544. oss << "/" << h1;
  3545. rSubs[i] = oss.str();
  3546. }
  3547. }
  3548. }
  3549. CSystemOptionsWindow::CSystemOptionsWindow(const SDL_Rect &pos, CPlayerInterface * owner)
  3550. {
  3551. this->pos = pos;
  3552. background = BitmapHandler::loadBitmap("SysOpbck.bmp", true);
  3553. graphics->blueToPlayersAdv(background, LOCPLINT->playerID);
  3554. //printing texts
  3555. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[568], 240, 32, GEOR16, tytulowy, background); //window title
  3556. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[569], 122, 65, GEOR16, tytulowy, background); //hero speed
  3557. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[570], 122, 131, GEOR16, tytulowy, background); //enemy speed
  3558. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[571], 122, 197, GEOR16, tytulowy, background); //map scroll speed
  3559. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[20], 122, 263, GEOR16, tytulowy, background); //video quality
  3560. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[394], 122, 348, GEOR16, tytulowy, background); //music volume
  3561. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[395], 122, 414, GEOR16, tytulowy, background); //effects volume
  3562. CSDL_Ext::printAt(CGI->generaltexth->allTexts[572], 283, 57, GEOR16, zwykly, background); //show move path
  3563. CSDL_Ext::printAt(CGI->generaltexth->allTexts[573], 283, 89, GEOR16, zwykly, background); //show hero reminder
  3564. CSDL_Ext::printAt(CGI->generaltexth->allTexts[574], 283, 121, GEOR16, zwykly, background); //quick combat
  3565. CSDL_Ext::printAt(CGI->generaltexth->allTexts[575], 283, 153, GEOR16, zwykly, background); //video subtitles
  3566. CSDL_Ext::printAt(CGI->generaltexth->allTexts[576], 283, 185, GEOR16, zwykly, background); //town building outlines
  3567. CSDL_Ext::printAt(CGI->generaltexth->allTexts[577], 283, 217, GEOR16, zwykly, background); //spell book animation
  3568. //setting up buttons
  3569. quitGame = new AdventureMapButton (CGI->preth->zelp[324].first, CGI->preth->zelp[324].second, boost::bind(&CSystemOptionsWindow::bquitf, this), 405, 471, "soquit.def", SDLK_q);
  3570. std::swap(quitGame->imgs[0][0], quitGame->imgs[0][1]);
  3571. backToMap = new AdventureMapButton (CGI->preth->zelp[325].first, CGI->preth->zelp[325].second, boost::bind(&CSystemOptionsWindow::breturnf, this), 516, 471, "soretrn.def", SDLK_RETURN);
  3572. std::swap(backToMap->imgs[0][0], backToMap->imgs[0][1]);
  3573. heroMoveSpeed = new CHighlightableButtonsGroup(0);
  3574. heroMoveSpeed->addButton(boost::assign::map_list_of(0,CGI->preth->zelp[349].first),CGI->preth->zelp[349].second, "sysopb1.def", 187, 134, 1);
  3575. heroMoveSpeed->addButton(boost::assign::map_list_of(0,CGI->preth->zelp[350].first),CGI->preth->zelp[350].second, "sysopb2.def", 235, 134, 2);
  3576. heroMoveSpeed->addButton(boost::assign::map_list_of(0,CGI->preth->zelp[351].first),CGI->preth->zelp[351].second, "sysopb3.def", 283, 134, 4);
  3577. heroMoveSpeed->addButton(boost::assign::map_list_of(0,CGI->preth->zelp[352].first),CGI->preth->zelp[352].second, "sysopb4.def", 331, 134, 8);
  3578. heroMoveSpeed->select(owner->heroMoveSpeed, 1);
  3579. heroMoveSpeed->onChange = boost::bind(&CPlayerInterface::setHeroMoveSpeed, owner, _1);
  3580. }
  3581. CSystemOptionsWindow::~CSystemOptionsWindow()
  3582. {
  3583. SDL_FreeSurface(background);
  3584. delete quitGame;
  3585. delete backToMap;
  3586. delete heroMoveSpeed;
  3587. }
  3588. void CSystemOptionsWindow::bquitf()
  3589. {
  3590. this->deactivate();
  3591. LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], std::vector<SComponent*>(), boost::bind(exit, 0), boost::bind(&CSystemOptionsWindow::activate, this), false, false);
  3592. }
  3593. void CSystemOptionsWindow::breturnf()
  3594. {
  3595. deactivate();
  3596. for(int g=0; g<LOCPLINT->objsToBlit.size(); ++g)
  3597. {
  3598. if(dynamic_cast<CSystemOptionsWindow*>(LOCPLINT->objsToBlit[g]))
  3599. {
  3600. LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+g);
  3601. break;
  3602. }
  3603. }
  3604. delete this;
  3605. LOCPLINT->curint->activate();
  3606. }
  3607. void CSystemOptionsWindow::activate()
  3608. {
  3609. quitGame->activate();
  3610. backToMap->activate();
  3611. heroMoveSpeed->activate();
  3612. }
  3613. void CSystemOptionsWindow::deactivate()
  3614. {
  3615. quitGame->deactivate();
  3616. backToMap->deactivate();
  3617. heroMoveSpeed->deactivate();
  3618. }
  3619. void CSystemOptionsWindow::show(SDL_Surface *to)
  3620. {
  3621. //evaluating to
  3622. if(!to)
  3623. to = screen;
  3624. SDL_BlitSurface(background, NULL, to, &pos);
  3625. quitGame->show(to);
  3626. backToMap->show(to);
  3627. heroMoveSpeed->show(to);
  3628. }
  3629. CTavernWindow::CTavernWindow(const CGHeroInstance *H1, const CGHeroInstance *H2, const std::string &gossip)
  3630. :h1(selected,0,72,299,H1),h2(selected,1,162,299,H2)
  3631. {
  3632. selected = 0;
  3633. bg = BitmapHandler::loadBitmap("TPTAVERN.bmp");
  3634. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  3635. printAtMiddle(CGI->generaltexth->jktexts[37],200,35,GEOR16,tytulowy,bg);
  3636. printAtMiddle("2500",320,328,GEOR13,zwykly,bg);
  3637. printAtMiddle(CGI->generaltexth->jktexts[38],146,283,GEOR16,tytulowy,bg);
  3638. printAtMiddleWB(gossip,200,220,GEOR13,50,zwykly,bg);
  3639. pos.w = bg->w;
  3640. pos.h = bg->h;
  3641. pos.x = (screen->w-bg->w)/2;
  3642. pos.y = (screen->h-bg->h)/2;
  3643. h1.pos.x += pos.x;
  3644. h2.pos.x += pos.x;
  3645. h1.pos.y += pos.y;
  3646. h2.pos.y += pos.y;
  3647. cancel = new AdventureMapButton("","",boost::bind(&CTavernWindow::close,this),pos.x+310,pos.y+428,"ICANCEL.DEF",SDLK_ESCAPE);
  3648. recruit = new AdventureMapButton("","",boost::bind(&CTavernWindow::recruitb,this),pos.x+272,pos.y+355,"TPTAV01.DEF",SDLK_RETURN);
  3649. thiefGuild = new AdventureMapButton("","",0,pos.x+22,pos.y+428,"TPTAV02.DEF",SDLK_t);
  3650. }
  3651. void CTavernWindow::recruitb()
  3652. {
  3653. const CGHeroInstance *toBuy = (selected ? h2 : h1).h;
  3654. close();
  3655. LOCPLINT->cb->recruitHero(LOCPLINT->castleInt->town,toBuy);
  3656. }
  3657. CTavernWindow::~CTavernWindow()
  3658. {
  3659. SDL_FreeSurface(bg);
  3660. delete cancel;
  3661. delete thiefGuild;
  3662. delete recruit;
  3663. }
  3664. void CTavernWindow::activate()
  3665. {
  3666. LOCPLINT->objsToBlit += this;
  3667. LOCPLINT->curint->subInt = this;
  3668. thiefGuild->activate();
  3669. cancel->activate();
  3670. h1.activate();
  3671. h2.activate();
  3672. recruit->activate();
  3673. }
  3674. void CTavernWindow::deactivate()
  3675. {
  3676. LOCPLINT->objsToBlit -= this;
  3677. thiefGuild->deactivate();
  3678. cancel->deactivate();
  3679. h1.deactivate();
  3680. h2.deactivate();
  3681. recruit->deactivate();
  3682. }
  3683. void CTavernWindow::close()
  3684. {
  3685. LOCPLINT->curint->subInt = NULL;
  3686. deactivate();
  3687. delete this;
  3688. LOCPLINT->curint->activate();
  3689. }
  3690. void CTavernWindow::show(SDL_Surface * to)
  3691. {
  3692. blitAt(bg,pos.x,pos.y,screen);
  3693. h1.show();
  3694. h2.show();
  3695. thiefGuild->show();
  3696. cancel->show();
  3697. recruit->show();
  3698. HeroPortrait *sel = selected ? &h2 : &h1;
  3699. char descr[300];
  3700. int artifs = sel->h->artifWorn.size()+sel->h->artifacts.size();
  3701. for(int i=13; i<=17; i++) //war machines and spellbook doesn't count
  3702. if(vstd::contains(sel->h->artifWorn,i))
  3703. artifs--;
  3704. sprintf_s(descr,300,CGI->generaltexth->allTexts[215].c_str(),
  3705. sel->h->name.c_str(),sel->h->level,sel->h->type->heroClass->name.c_str(),artifs);
  3706. printAtMiddleWB(descr,pos.x+146,pos.y+389,GEOR13,40,zwykly,screen);
  3707. CSDL_Ext::drawBorder(screen,sel->pos.x-2,sel->pos.y-2,sel->pos.w+4,sel->pos.h+4,int3(247,223,123));
  3708. }
  3709. void CTavernWindow::HeroPortrait::clickLeft(boost::logic::tribool down)
  3710. {
  3711. if(pressedL && !down)
  3712. as();
  3713. ClickableL::clickLeft(down);
  3714. }
  3715. void CTavernWindow::HeroPortrait::activate()
  3716. {
  3717. ClickableL::activate();
  3718. ClickableR::activate();
  3719. }
  3720. void CTavernWindow::HeroPortrait::deactivate()
  3721. {
  3722. ClickableL::deactivate();
  3723. ClickableR::deactivate();
  3724. }
  3725. void CTavernWindow::HeroPortrait::clickRight(boost::logic::tribool down)
  3726. {
  3727. if(down)
  3728. {
  3729. LOCPLINT->adventureInt->heroWindow->setHero(h);
  3730. LOCPLINT->objsToBlit += LOCPLINT->adventureInt->heroWindow;
  3731. LOCPLINT->curint->deactivate();
  3732. ClickableR::activate();
  3733. }
  3734. else if(vstd::contains(LOCPLINT->objsToBlit,LOCPLINT->adventureInt->heroWindow))
  3735. {
  3736. LOCPLINT->objsToBlit -= LOCPLINT->adventureInt->heroWindow;
  3737. ClickableR::deactivate();
  3738. LOCPLINT->castleInt->showAll(0,true);
  3739. LOCPLINT->curint->subInt->activate();
  3740. }
  3741. }
  3742. CTavernWindow::HeroPortrait::HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H)
  3743. :as(sel,id)
  3744. {
  3745. h = H;
  3746. pos.x = x;
  3747. pos.y = y;
  3748. pos.w = 58;
  3749. pos.h = 64;
  3750. }
  3751. void CTavernWindow::HeroPortrait::show(SDL_Surface * to)
  3752. {
  3753. blitAt(graphics->portraitLarge[h->subID],pos);
  3754. }