CPlayerInterface.cpp 125 KB

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