CPlayerInterface.cpp 128 KB

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