CPlayerInterface.cpp 127 KB

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