2
0

CPlayerInterface.cpp 124 KB

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