CPlayerInterface.cpp 124 KB

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