CPlayerInterface.cpp 125 KB

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