CPlayerInterface.cpp 127 KB

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