CPlayerInterface.cpp 135 KB

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