CPlayerInterface.cpp 124 KB

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