CPlayerInterface.cpp 127 KB

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