CPlayerInterface.cpp 124 KB

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