CPlayerInterface.cpp 125 KB

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