CPlayerInterface.cpp 124 KB

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