CPlayerInterface.cpp 125 KB

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