CPlayerInterface.cpp 120 KB

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