CPlayerInterface.cpp 123 KB

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