CPlayerInterface.cpp 124 KB

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