CPlayerInterface.cpp 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116
  1. #include "stdafx.h"
  2. #include "CPlayerInterface.h"
  3. #include "CAdvmapInterface.h"
  4. #include "CMessage.h"
  5. #include "mapHandler.h"
  6. #include "SDL_Extensions.h"
  7. #include "SDL_framerate.h"
  8. #include "CScreenHandler.h"
  9. #include "CCursorHandler.h"
  10. #include "CCallback.h"
  11. #include "SDL_Extensions.h"
  12. #include "hch/CLodHandler.h"
  13. #include "CPathfinder.h"
  14. #include <sstream>
  15. #include "hch/CAbilityHandler.h"
  16. #include "hch/CHeroHandler.h"
  17. #include "hch/CTownHandler.h"
  18. #include "SDL_framerate.h"
  19. #include "hch/CGeneralTextHandler.h"
  20. #include "CCastleInterface.h"
  21. #include "CHeroWindow.h"
  22. #include "timeHandler.h"
  23. #include <boost/algorithm/string.hpp>
  24. #include <boost/algorithm/string/replace.hpp>
  25. #include "hch\CPreGameTextHandler.h"
  26. #include "CBattleInterface.h"
  27. #include "CLua.h"
  28. #include <cmath>
  29. #include "client/CCreatureAnimation.h"
  30. using namespace CSDL_Ext;
  31. extern TTF_Font * GEOR16;
  32. class OCM_HLP_CGIN
  33. {
  34. public:
  35. bool operator ()(const std::pair<CGObjectInstance*,SDL_Rect> & a, const std::pair<CGObjectInstance*,SDL_Rect> & b) const
  36. {
  37. return (*a.first)<(*b.first);
  38. }
  39. } ocmptwo_cgin ;
  40. void CGarrisonSlot::hover (bool on)
  41. {
  42. Hoverable::hover(on);
  43. if(on)
  44. {
  45. std::string temp;
  46. if(creature)
  47. {
  48. if(owner->highlighted)
  49. {
  50. if(owner->highlighted == this)
  51. {
  52. temp = CGI->townh->tcommands[4];
  53. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  54. }
  55. else if (owner->highlighted->creature == creature)
  56. {
  57. temp = CGI->townh->tcommands[2];
  58. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  59. }
  60. else if (owner->highlighted->creature)
  61. {
  62. temp = CGI->townh->tcommands[7];
  63. boost::algorithm::replace_first(temp,"%s",owner->highlighted->creature->nameSing);
  64. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  65. }
  66. else
  67. {
  68. std::cout << "Warning - shouldn't be - highlighted void slot "<<owner->highlighted<<std::endl;
  69. std::cout << "Highlighted set to NULL"<<std::endl;
  70. owner->highlighted = NULL;
  71. }
  72. }
  73. else
  74. {
  75. if(upg)
  76. {
  77. temp = CGI->townh->tcommands[32];
  78. }
  79. else
  80. {
  81. temp = CGI->townh->tcommands[12];
  82. }
  83. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  84. };
  85. }
  86. else
  87. {
  88. if(owner->highlighted)
  89. {
  90. temp = CGI->townh->tcommands[6];
  91. boost::algorithm::replace_first(temp,"%s",owner->highlighted->creature->nameSing);
  92. }
  93. else
  94. {
  95. temp = CGI->townh->tcommands[11];
  96. }
  97. }
  98. LOCPLINT->statusbar->print(temp);
  99. }
  100. else
  101. {
  102. LOCPLINT->statusbar->clear();
  103. }
  104. }
  105. const CArmedInstance * CGarrisonSlot::getObj()
  106. {
  107. return (!upg)?(owner->oup):(owner->odown);
  108. }
  109. void CGarrisonSlot::clickRight (tribool down)
  110. {
  111. StackState *pom = NULL;
  112. if(down && creature)
  113. {
  114. if(getObj()->ID == 34)
  115. {
  116. pom = new StackState();
  117. const CGHeroInstance *h = static_cast<const CGHeroInstance *>(getObj());
  118. pom->attackBonus = h->primSkills[0];
  119. pom->defenseBonus = h->primSkills[1];
  120. pom->luck = h->getCurrentLuck();
  121. pom->morale = h->getCurrentMorale();
  122. }
  123. (new CCreInfoWindow(creature->idNumber,0,pom,boost::function<void()>(),boost::function<void()>()))
  124. ->activate();
  125. }
  126. delete pom;
  127. }
  128. void CGarrisonSlot::clickLeft(tribool down)
  129. {
  130. if(owner->ignoreEvent)
  131. {
  132. owner->ignoreEvent = false;
  133. return;
  134. }
  135. if(down)
  136. {
  137. bool refr = false;
  138. if(owner->highlighted)
  139. {
  140. if(owner->highlighted == this) //view info
  141. {
  142. UpgradeInfo pom = LOCPLINT->cb->getUpgradeInfo(getObj(),ID);
  143. (new CCreInfoWindow
  144. (creature->idNumber,1,NULL,
  145. (pom.oldID>=0)?(boost::bind(&CCallback::upgradeCreature,LOCPLINT->cb,getObj(),ID,-1)):(boost::function<void()>()), //if upgrade is possible we'll bind proper function in callback
  146. boost::bind(&CCallback::dismissCreature,LOCPLINT->cb,getObj(),ID)))
  147. ->activate();
  148. owner->highlighted = NULL;
  149. show();
  150. refr = true;
  151. }
  152. else if( !creature && owner->splitting)//split
  153. {
  154. owner->p2 = ID;
  155. owner->pb = upg;
  156. owner->splitting = false;
  157. LOCPLINT->curint->deactivate();
  158. CSplitWindow * spw = new CSplitWindow(owner->highlighted->creature->idNumber,owner->highlighted->count, owner);
  159. spw->activate();
  160. refr = true;
  161. }
  162. else if(creature != owner->highlighted->creature) //swap
  163. {
  164. LOCPLINT->cb->swapCreatures(
  165. (!upg)?(owner->oup):(owner->odown),
  166. (!owner->highlighted->upg)?(owner->oup):(owner->odown),
  167. ID,owner->highlighted->ID);
  168. }
  169. else //merge
  170. {
  171. LOCPLINT->cb->mergeStacks(
  172. (!owner->highlighted->upg)?(owner->oup):(owner->odown),
  173. (!upg)?(owner->oup):(owner->odown),
  174. owner->highlighted->ID,ID);
  175. }
  176. }
  177. else //highlight
  178. {
  179. if(creature)
  180. owner->highlighted = this;
  181. show();
  182. refr = true;
  183. }
  184. if(refr) {hover(false); hover(true); } //to refresh statusbar
  185. }
  186. }
  187. void CGarrisonSlot::activate()
  188. {
  189. if(!active) active=true;
  190. else return;
  191. ClickableL::activate();
  192. ClickableR::activate();
  193. Hoverable::activate();
  194. }
  195. void CGarrisonSlot::deactivate()
  196. {
  197. if(active) active=false;
  198. else return;
  199. ClickableL::deactivate();
  200. ClickableR::deactivate();
  201. Hoverable::deactivate();
  202. }
  203. CGarrisonSlot::CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg, const CCreature * Creature, int Count)
  204. {
  205. active = false;
  206. upg = Upg;
  207. count = Count;
  208. ID = IID;
  209. creature = Creature;
  210. pos.x = x;
  211. pos.y = y;
  212. pos.w = 58;
  213. pos.h = 64;
  214. owner = Owner;
  215. }
  216. CGarrisonSlot::~CGarrisonSlot()
  217. {
  218. if(active)
  219. deactivate();
  220. }
  221. void CGarrisonSlot::show()
  222. {
  223. if(creature)
  224. {
  225. char* buf = new char[15];
  226. itoa(count,buf,10);
  227. blitAt(CGI->creh->bigImgs[creature->idNumber],pos);
  228. printTo(buf,pos.x+56,pos.y+62,GEOR16,zwykly);
  229. if(owner->highlighted==this)
  230. blitAt(CGI->creh->bigImgs[-1],pos);
  231. if(owner->update)
  232. updateRect(&pos,screen);
  233. delete [] buf;
  234. }
  235. else
  236. {
  237. SDL_Rect jakis1 = genRect(pos.h,pos.w,owner->offx+ID*(pos.w+owner->interx),owner->offy+upg*(pos.h+owner->intery)), jakis2 = pos;
  238. SDL_BlitSurface(owner->sur,&jakis1,screen,&jakis2);
  239. if(owner->splitting)
  240. blitAt(CGI->creh->bigImgs[-1],pos);
  241. if(owner->update)
  242. SDL_UpdateRect(screen,pos.x,pos.y,pos.w,pos.h);
  243. }
  244. }
  245. CGarrisonInt::~CGarrisonInt()
  246. {
  247. if(sup)
  248. {
  249. for(int i=0;i<sup->size();i++)
  250. delete (*sup)[i];
  251. delete sup;
  252. }
  253. if(sdown)
  254. {
  255. for(int i=0;i<sdown->size();i++)
  256. delete (*sdown)[i];
  257. delete sdown;
  258. }
  259. }
  260. void CGarrisonInt::show()
  261. {
  262. if(sup)
  263. {
  264. for(int i = 0; i<sup->size(); i++)
  265. if((*sup)[i])
  266. (*sup)[i]->show();
  267. }
  268. if(sdown)
  269. {
  270. for(int i = 0; i<sdown->size(); i++)
  271. if((*sdown)[i])
  272. (*sdown)[i]->show();
  273. }
  274. }
  275. void CGarrisonInt::deactiveteSlots()
  276. {
  277. if(sup)
  278. {
  279. for(int i = 0; i<sup->size(); i++)
  280. {
  281. if((*sup)[i])
  282. {
  283. (*sup)[i]->deactivate();
  284. }
  285. }
  286. }
  287. if(sdown)
  288. {
  289. for(int i = 0; i<sdown->size(); i++)
  290. {
  291. if((*sdown)[i])
  292. {
  293. (*sdown)[i]->deactivate();
  294. }
  295. }
  296. }
  297. }
  298. void CGarrisonInt::activeteSlots()
  299. {
  300. if(sup)
  301. {
  302. for(int i = 0; i<sup->size(); i++)
  303. {
  304. if((*sup)[i])
  305. {
  306. (*sup)[i]->activate();
  307. }
  308. }
  309. }
  310. if(sdown)
  311. {
  312. for(int i = 0; i<sdown->size(); i++)
  313. {
  314. if((*sdown)[i])
  315. {
  316. (*sdown)[i]->activate();
  317. }
  318. }
  319. }
  320. }
  321. void CGarrisonInt::createSlots()
  322. {
  323. if(set1)
  324. {
  325. sup = new std::vector<CGarrisonSlot*>(7,(CGarrisonSlot *)(NULL));
  326. for
  327. (std::map<int,std::pair<CCreature*,int> >::const_iterator i=set1->slots.begin();
  328. i!=set1->slots.end(); i++)
  329. {
  330. (*sup)[i->first] =
  331. new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y,i->first, 0, i->second.first,i->second.second);
  332. }
  333. for(int i=0; i<sup->size(); i++)
  334. if((*sup)[i] == NULL)
  335. (*sup)[i] = new CGarrisonSlot(this, pos.x + (i*(58+interx)), pos.y,i,0,NULL, 0);
  336. }
  337. if(set2)
  338. {
  339. sdown = new std::vector<CGarrisonSlot*>(7,(CGarrisonSlot *)(NULL));
  340. for
  341. (std::map<int,std::pair<CCreature*,int> >::const_iterator i=set2->slots.begin();
  342. i!=set2->slots.end(); i++)
  343. {
  344. (*sdown)[i->first] =
  345. new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y + 64 + intery,i->first,1, i->second.first,i->second.second);
  346. }
  347. for(int i=0; i<sup->size(); i++)
  348. if((*sdown)[i] == NULL)
  349. (*sdown)[i] = new CGarrisonSlot(this, pos.x + (i*(58+interx)), pos.y + 64 + intery,i,1, NULL, 0);
  350. }
  351. }
  352. void CGarrisonInt::deleteSlots()
  353. {
  354. if(sup)
  355. {
  356. for(int i = 0; i<sup->size(); i++)
  357. {
  358. if((*sup)[i])
  359. {
  360. delete (*sup)[i];
  361. }
  362. }
  363. }
  364. if(sdown)
  365. {
  366. for(int i = 0; i<sdown->size(); i++)
  367. {
  368. if((*sdown)[i])
  369. {
  370. delete (*sdown)[i];
  371. }
  372. }
  373. }
  374. }
  375. void CGarrisonInt::recreateSlots()
  376. {
  377. splitting = false;
  378. highlighted = NULL;
  379. deactiveteSlots();
  380. deleteSlots();
  381. createSlots();
  382. ignoreEvent = true;
  383. activeteSlots();
  384. show();
  385. }
  386. void CGarrisonInt::splitClick()
  387. {
  388. if(!highlighted)
  389. return;
  390. splitting = !splitting;
  391. show();
  392. }
  393. void CGarrisonInt::splitStacks(int am2)
  394. {
  395. LOCPLINT->cb->splitStack(
  396. (highlighted->upg)?(odown):(oup),
  397. (pb)?(odown):(oup),
  398. highlighted->ID,
  399. p2,
  400. am2);
  401. }
  402. CGarrisonInt::CGarrisonInt(int x, int y, int inx, int iny, SDL_Surface *pomsur, int OX, int OY, const CArmedInstance *s1, const CArmedInstance *s2)
  403. :interx(inx),intery(iny),sur(pomsur),highlighted(NULL),sup(NULL),sdown(NULL),oup(s1),odown(s2),
  404. offx(OX),offy(OY)
  405. {
  406. splitting = false;
  407. set1 = LOCPLINT->cb->getGarrison(s1);
  408. set2 = LOCPLINT->cb->getGarrison(s2);
  409. ignoreEvent = false;
  410. update = true;
  411. pos.x=(x);
  412. pos.y=(y);
  413. pos.w=(58);
  414. pos.h=(64);
  415. createSlots();
  416. }
  417. void CGarrisonInt::activate()
  418. {
  419. if(sup)
  420. {
  421. for(int i = 0; i<sup->size(); i++)
  422. if((*sup)[i])
  423. (*sup)[i]->activate();
  424. }
  425. if(sdown)
  426. {
  427. for(int i = 0; i<sdown->size(); i++)
  428. if((*sdown)[i])
  429. (*sdown)[i]->activate();
  430. }
  431. }
  432. void CGarrisonInt::deactivate()
  433. {
  434. deactiveteSlots();
  435. }
  436. CInfoWindow::CInfoWindow()
  437. :okb(NMessage::ok,NULL,&CInfoWindow::okClicked)
  438. {
  439. okb.ourObj = this;
  440. okb.delg = this;
  441. okb.notFreeButton=true;
  442. }
  443. void CInfoWindow::okClicked(tribool down)
  444. {
  445. if (!down)
  446. close();
  447. }
  448. void CInfoWindow::close()
  449. {
  450. for (int i=0;i<components.size();i++)
  451. {
  452. components[i]->deactivate();
  453. delete components[i];
  454. }
  455. components.clear();
  456. okb.deactivate();
  457. SDL_FreeSurface(bitmap);
  458. bitmap = NULL;
  459. LOCPLINT->removeObjToBlit(this);
  460. LOCPLINT->curint->activate();
  461. delete this;
  462. }
  463. CInfoWindow::~CInfoWindow()
  464. {
  465. }
  466. void CRClickPopup::clickRight (tribool down)
  467. {
  468. if(down)
  469. return;
  470. close();
  471. }
  472. void CRClickPopup::activate()
  473. {
  474. ClickableR::activate();
  475. LOCPLINT->objsToBlit.push_back(this);
  476. }
  477. void CRClickPopup::deactivate()
  478. {
  479. ClickableR::deactivate();
  480. LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
  481. }
  482. CInfoPopup::CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free)
  483. :bitmap(Bitmap),free(Free)
  484. {
  485. pos.x = x;
  486. pos.y = y;
  487. pos.h = bitmap->h;
  488. pos.w = bitmap->w;
  489. }
  490. void CInfoPopup::close()
  491. {
  492. deactivate();
  493. if(free)
  494. SDL_FreeSurface(bitmap);
  495. delete this;
  496. if(LOCPLINT->curint == LOCPLINT->adventureInt)
  497. LOCPLINT->adventureInt->show();
  498. else if(LOCPLINT->curint == LOCPLINT->castleInt)
  499. LOCPLINT->castleInt->showAll();
  500. }
  501. void CInfoPopup::show(SDL_Surface * to)
  502. {
  503. blitAt(bitmap,pos.x,pos.y,(to)?(to):(screen));
  504. }
  505. SComponent::SComponent(Etype Type, int Subtype, int Val)
  506. {
  507. std::ostringstream oss;
  508. switch (Type)
  509. {
  510. case primskill:
  511. description = CGI->generaltexth->arraytxt[2+Subtype];
  512. oss << ((Val>0)?("+"):("-")) << Val << " " << CGI->heroh->pskillsn[Subtype];
  513. subtitle = oss.str();
  514. break;
  515. case resource:
  516. description = CGI->generaltexth->allTexts[242];
  517. oss << Val;
  518. subtitle = oss.str();
  519. break;
  520. case experience:
  521. description = CGI->generaltexth->allTexts[241];
  522. oss << Val ;
  523. subtitle = oss.str();
  524. break;
  525. }
  526. type = Type;
  527. subtype = Subtype;
  528. val = Val;
  529. SDL_Surface * temp = getImg();
  530. pos.w = temp->w;
  531. pos.h = temp->h;
  532. }
  533. SDL_Surface * SComponent::getImg()
  534. {
  535. switch (type)
  536. {
  537. case primskill:
  538. return CGI->heroh->pskillsb->ourImages[subtype].bitmap;
  539. break;
  540. case secskill:
  541. return CGI->abilh->abils82->ourImages[subtype*3 + 3 + val].bitmap;
  542. break;
  543. case resource:
  544. return CGI->heroh->resources->ourImages[subtype].bitmap;
  545. break;
  546. case experience:
  547. return CGI->heroh->pskillsb->ourImages[4].bitmap;
  548. break;
  549. }
  550. return NULL;
  551. }
  552. void SComponent::clickRight (tribool down)
  553. {
  554. LOCPLINT->adventureInt->handleRightClick(description,down,this);
  555. }
  556. void SComponent::activate()
  557. {
  558. ClickableR::activate();
  559. }
  560. void SComponent::deactivate()
  561. {
  562. ClickableR::deactivate();
  563. }
  564. void CSelectableComponent::clickLeft(tribool down)
  565. {
  566. if (down)
  567. {
  568. select(true);
  569. owner->selectionChange(this);
  570. }
  571. }
  572. CSelectableComponent::CSelectableComponent(Etype Type, int Sub, int Val, CSelWindow * Owner, SDL_Surface * Border)
  573. :SComponent(Type,Sub,Val),owner(Owner)
  574. {
  575. SDL_Surface * symb = SComponent::getImg();
  576. myBitmap = CSDL_Ext::newSurface(symb->w+2,symb->h+2,screen);
  577. SDL_SetColorKey(myBitmap,SDL_SRCCOLORKEY,SDL_MapRGB(myBitmap->format,0,255,255));
  578. blitAt(symb,1,1,myBitmap);
  579. if (Border) //use custom border
  580. {
  581. border = Border;
  582. customB = true;
  583. }
  584. else //we need to draw border
  585. {
  586. customB = false;
  587. border = CSDL_Ext::newSurface(symb->w+2,symb->h+2,screen);
  588. SDL_FillRect(border,NULL,0x00FFFF);
  589. for (int i=0;i<border->w;i++)
  590. {
  591. SDL_PutPixel(border,i,0,239,215,123);
  592. SDL_PutPixel(border,i,(border->h)-1,239,215,123);
  593. }
  594. for (int i=0;i<border->h;i++)
  595. {
  596. SDL_PutPixel(border,0,i,239,215,123);
  597. SDL_PutPixel(border,(border->w)-1,i,239,215,123);
  598. }
  599. SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255));
  600. }
  601. selected = false;
  602. }
  603. CSelectableComponent::~CSelectableComponent()
  604. {
  605. SDL_FreeSurface(myBitmap);
  606. if (!customB)
  607. SDL_FreeSurface(border);
  608. }
  609. void CSelectableComponent::activate()
  610. {
  611. SComponent::activate();
  612. ClickableL::activate();
  613. }
  614. void CSelectableComponent::deactivate()
  615. {
  616. SComponent::deactivate();
  617. ClickableL::deactivate();
  618. }
  619. SDL_Surface * CSelectableComponent::getImg()
  620. {
  621. return myBitmap;
  622. }
  623. void CSelectableComponent::select(bool on)
  624. {
  625. if(on != selected)
  626. {
  627. SDL_FillRect(myBitmap,NULL,0x000000);
  628. blitAt(SComponent::getImg(),1,1,myBitmap);
  629. if (on)
  630. {
  631. blitAt(border,0,0,myBitmap);
  632. }
  633. selected = on;
  634. return;
  635. }
  636. else
  637. {
  638. return;
  639. }
  640. }
  641. void CSimpleWindow::show(SDL_Surface * to)
  642. {
  643. if(!to)
  644. to=screen;
  645. blitAt(bitmap,pos.x,pos.y,to);
  646. }
  647. CSimpleWindow::~CSimpleWindow()
  648. {
  649. if (bitmap)
  650. {
  651. SDL_FreeSurface(bitmap);
  652. bitmap=NULL;
  653. }
  654. }
  655. void CSelWindow::selectionChange(CSelectableComponent * to)
  656. {
  657. blitAt(to->getImg(),to->pos.x-pos.x,to->pos.y-pos.y,bitmap);
  658. for (int i=0;i<components.size();i++)
  659. {
  660. if(components[i]==to)
  661. {
  662. if (to->selected)
  663. continue;
  664. else
  665. to->select(true);
  666. }
  667. CSelectableComponent * pom = dynamic_cast<CSelectableComponent*>(components[i]);
  668. if (!pom)
  669. continue;
  670. pom->select(false);
  671. blitAt(pom->getImg(),pom->pos.x-pos.x,pom->pos.y-pos.y,bitmap);
  672. }
  673. }
  674. void CSelWindow::okClicked(tribool down)
  675. {
  676. if(!down)
  677. close();
  678. }
  679. void CSelWindow::close()
  680. {
  681. int ret = -1;
  682. for (int i=0;i<components.size();i++)
  683. {
  684. if(dynamic_cast<CSelectableComponent*>(components[i])->selected)
  685. {
  686. ret = i;
  687. }
  688. components[i]->deactivate();
  689. }
  690. components.clear();
  691. okb.deactivate();
  692. SDL_FreeSurface(bitmap);
  693. bitmap = NULL;
  694. LOCPLINT->removeObjToBlit(this);
  695. LOCPLINT->curint->activate();
  696. LOCPLINT->cb->selectionMade(ret,ID);
  697. delete this;
  698. //call owner with selection result
  699. }
  700. template <typename T>CSCButton<T>::CSCButton(CDefHandler * img, CIntObject * obj, void(T::*poin)(tribool), T* Delg)
  701. {
  702. ourObj = obj;
  703. delg = Delg;
  704. func = poin;
  705. imgs.resize(1);
  706. for (int i =0; i<img->ourImages.size();i++)
  707. {
  708. imgs[0].push_back(img->ourImages[i].bitmap);
  709. }
  710. pos.w = imgs[0][0]->w;
  711. pos.h = imgs[0][0]->h;
  712. state = 0;
  713. }
  714. template <typename T> void CSCButton<T>::clickLeft (tribool down)
  715. {
  716. if (down)
  717. {
  718. state=1;
  719. }
  720. else
  721. {
  722. state=0;
  723. }
  724. pressedL=state;
  725. show();
  726. if (delg)
  727. (delg->*func)(down);
  728. }
  729. template <typename T> void CSCButton<typename T>::activate()
  730. {
  731. ClickableL::activate();
  732. }
  733. template <typename T> void CSCButton<typename T>::deactivate()
  734. {
  735. ClickableL::deactivate();
  736. }
  737. template <typename T> void CSCButton<typename T>::show(SDL_Surface * to)
  738. {
  739. if (delg) //we blit on our owner's bitmap
  740. {
  741. blitAt(imgs[curimg][state],posr.x,posr.y,delg->bitmap);
  742. //updateRect(&genRect(pos.h,pos.w,posr.x,posr.y),delg->bitmap);
  743. }
  744. else
  745. {
  746. CButtonBase::show(to);
  747. }
  748. }
  749. CButtonBase::CButtonBase()
  750. {
  751. bitmapOffset = 0;
  752. curimg=0;
  753. type=-1;
  754. abs=false;
  755. active=false;
  756. notFreeButton = false;
  757. ourObj=NULL;
  758. state=0;
  759. }
  760. CButtonBase::~CButtonBase()
  761. {
  762. if(notFreeButton)
  763. return;
  764. for(int i =0; i<imgs.size();i++)
  765. for(int j=0;j<imgs[i].size();j++)
  766. SDL_FreeSurface(imgs[i][j]);
  767. }
  768. void CButtonBase::show(SDL_Surface * to)
  769. {
  770. if(!to)
  771. to=screen;
  772. if (abs)
  773. {
  774. blitAt(imgs[curimg]
  775. [( (state+bitmapOffset) < (imgs[curimg].size()) ) ?
  776. (state+bitmapOffset) :
  777. (imgs[curimg].size()-1) ]
  778. ,pos.x,pos.y,to);
  779. //updateRect(&pos,to);
  780. }
  781. else
  782. {
  783. blitAt(imgs[curimg]
  784. [( (state+bitmapOffset) < (imgs[curimg].size()) ) ?
  785. (state+bitmapOffset) :
  786. (imgs[curimg].size()-1) ],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y,to);
  787. //updateRect(&genRect(pos.h,pos.w,pos.x+ourObj->pos.x,pos.y+ourObj->pos.y),to);
  788. }
  789. }
  790. ClickableL::ClickableL()
  791. {
  792. pressedL=false;
  793. }
  794. void ClickableL::clickLeft(tribool down)
  795. {
  796. if (down)
  797. pressedL=true;
  798. else
  799. pressedL=false;
  800. }
  801. void ClickableL::activate()
  802. {
  803. LOCPLINT->lclickable.push_back(this);
  804. }
  805. void ClickableL::deactivate()
  806. {
  807. LOCPLINT->lclickable.erase
  808. (std::find(LOCPLINT->lclickable.begin(),LOCPLINT->lclickable.end(),this));
  809. }
  810. ClickableR::ClickableR()
  811. {
  812. pressedR=false;
  813. }
  814. void ClickableR::clickRight(tribool down)
  815. {
  816. if (down)
  817. pressedR=true;
  818. else
  819. pressedR=false;
  820. }
  821. void ClickableR::activate()
  822. {
  823. LOCPLINT->rclickable.push_back(this);
  824. }
  825. void ClickableR::deactivate()
  826. {
  827. LOCPLINT->rclickable.erase(std::find(LOCPLINT->rclickable.begin(),LOCPLINT->rclickable.end(),this));
  828. }
  829. void Hoverable::activate()
  830. {
  831. LOCPLINT->hoverable.push_back(this);
  832. }
  833. void Hoverable::deactivate()
  834. {
  835. LOCPLINT->hoverable.erase(std::find(LOCPLINT->hoverable.begin(),LOCPLINT->hoverable.end(),this));
  836. }
  837. void Hoverable::hover(bool on)
  838. {
  839. hovered=on;
  840. }
  841. void KeyInterested::activate()
  842. {
  843. LOCPLINT->keyinterested.push_back(this);
  844. }
  845. void KeyInterested::deactivate()
  846. {
  847. LOCPLINT->
  848. keyinterested.erase(std::find(LOCPLINT->keyinterested.begin(),LOCPLINT->keyinterested.end(),this));
  849. }
  850. void MotionInterested::activate()
  851. {
  852. LOCPLINT->motioninterested.push_back(this);
  853. }
  854. void MotionInterested::deactivate()
  855. {
  856. LOCPLINT->
  857. motioninterested.erase(std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this));
  858. }
  859. void TimeInterested::activate()
  860. {
  861. LOCPLINT->timeinterested.push_back(this);
  862. }
  863. void TimeInterested::deactivate()
  864. {
  865. LOCPLINT->
  866. timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),this));
  867. }
  868. CPlayerInterface::CPlayerInterface(int Player, int serial)
  869. {
  870. playerID=Player;
  871. serialID=serial;
  872. CGI->localPlayer = playerID;
  873. human=true;
  874. hInfo = CGI->bitmaph->loadBitmap("HEROQVBK.bmp");
  875. SDL_SetColorKey(hInfo,SDL_SRCCOLORKEY,SDL_MapRGB(hInfo->format,0,255,255));
  876. tInfo = CGI->bitmaph->loadBitmap("TOWNQVBK.bmp");
  877. SDL_SetColorKey(tInfo,SDL_SRCCOLORKEY,SDL_MapRGB(tInfo->format,0,255,255));
  878. slotsPos.push_back(std::pair<int,int>(44,82));
  879. slotsPos.push_back(std::pair<int,int>(80,82));
  880. slotsPos.push_back(std::pair<int,int>(116,82));
  881. slotsPos.push_back(std::pair<int,int>(26,131));
  882. slotsPos.push_back(std::pair<int,int>(62,131));
  883. slotsPos.push_back(std::pair<int,int>(98,131));
  884. slotsPos.push_back(std::pair<int,int>(134,131));
  885. luck22 = CGI->spriteh->giveDefEss("ILCK22.DEF");
  886. luck30 = CGI->spriteh->giveDefEss("ILCK30.DEF");
  887. luck42 = CGI->spriteh->giveDefEss("ILCK42.DEF");
  888. luck82 = CGI->spriteh->giveDefEss("ILCK82.DEF");
  889. morale22 = CGI->spriteh->giveDefEss("IMRL22.DEF");
  890. morale30 = CGI->spriteh->giveDefEss("IMRL30.DEF");
  891. morale42 = CGI->spriteh->giveDefEss("IMRL42.DEF");
  892. morale82 = CGI->spriteh->giveDefEss("IMRL82.DEF");
  893. halls = CGI->spriteh->giveDefEss("ITMTLS.DEF");
  894. forts = CGI->spriteh->giveDefEss("ITMCLS.DEF");
  895. bigTownPic = CGI->spriteh->giveDefEss("ITPT.DEF");
  896. }
  897. void CPlayerInterface::init(ICallback * CB)
  898. {
  899. cb = dynamic_cast<CCallback*>(CB);
  900. CGI->localPlayer = serialID;
  901. adventureInt = new CAdvMapInt(playerID);
  902. castleInt = NULL;
  903. std::vector <const CGHeroInstance *> hh = cb->getHeroesInfo(false);
  904. for(int i=0;i<hh.size();i++)
  905. {
  906. SDL_Surface * pom = infoWin(hh[i]);
  907. heroWins.insert(std::pair<int,SDL_Surface*>(hh[i]->subID,pom));
  908. }
  909. std::vector<const CGTownInstance*> tt = cb->getTownsInfo(false);
  910. for(int i=0;i<tt.size();i++)
  911. {
  912. SDL_Surface * pom = infoWin(tt[i]);
  913. townWins.insert(std::pair<int,SDL_Surface*>(tt[i]->identifier,pom));
  914. }
  915. }
  916. void CPlayerInterface::yourTurn()
  917. {
  918. makingTurn = true;
  919. CGI->localPlayer = serialID;
  920. unsigned char & animVal = LOCPLINT->adventureInt->anim; //for animations handling
  921. unsigned char & heroAnimVal = LOCPLINT->adventureInt->heroAnim;
  922. adventureInt->infoBar.newDay(cb->getDate(1));
  923. adventureInt->activate();
  924. //show rest of things
  925. //initializing framerate keeper
  926. mainFPSmng = new FPSmanager;
  927. SDL_initFramerate(mainFPSmng);
  928. SDL_setFramerate(mainFPSmng, 24);
  929. SDL_Event sEvent;
  930. //framerate keeper initialized
  931. timeHandler th;
  932. th.getDif();
  933. for(;makingTurn;) // main loop
  934. {
  935. //updating water tiles
  936. //int wnumber = -1;
  937. //for(int s=0; s<CGI->mh->reader->defs.size(); ++s)
  938. //{
  939. // if(CGI->mh->reader->defs[s]->defName==std::string("WATRTL.DEF"))
  940. // {
  941. // wnumber = s;
  942. // break;
  943. // }
  944. //}
  945. //if(wnumber>=0)
  946. //{
  947. // for(int g=0; g<CGI->mh->reader->defs[wnumber]->ourImages.size(); ++g)
  948. // {
  949. // SDL_Color tab[32];
  950. // for(int i=0; i<32; ++i)
  951. // {
  952. // tab[i] = CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap->format->palette->colors[160 + (i+1)%32];
  953. // }
  954. // //SDL_SaveBMP(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap,"t1.bmp");
  955. // for(int i=0; i<32; ++i)
  956. // {
  957. // CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap->format->palette->colors[160 + i] = tab[i];
  958. // }
  959. // //SDL_SaveBMP(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap,"t2.bmp");
  960. // CSDL_Ext::update(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap);
  961. // }
  962. //}
  963. //water tiles updated
  964. CGI->screenh->updateScreen();
  965. int tv = th.getDif();
  966. for (int i=0;i<timeinterested.size();i++)
  967. {
  968. if (timeinterested[i]->toNextTick>=0)
  969. timeinterested[i]->toNextTick-=tv;
  970. if (timeinterested[i]->toNextTick<0)
  971. timeinterested[i]->tick();
  972. }
  973. LOCPLINT->adventureInt->updateScreen = false;
  974. while (SDL_PollEvent(&sEvent)) //wait for event...
  975. {
  976. handleEvent(&sEvent);
  977. }
  978. if (!castleInt) //stuff for advMapInt
  979. {
  980. ++LOCPLINT->adventureInt->animValHitCount; //for animations
  981. if(LOCPLINT->adventureInt->animValHitCount == 4)
  982. {
  983. LOCPLINT->adventureInt->animValHitCount = 0;
  984. ++animVal;
  985. LOCPLINT->adventureInt->updateScreen = true;
  986. }
  987. ++heroAnimVal;
  988. if(LOCPLINT->adventureInt->scrollingLeft)
  989. {
  990. if(LOCPLINT->adventureInt->position.x>-Woff)
  991. {
  992. LOCPLINT->adventureInt->position.x--;
  993. LOCPLINT->adventureInt->updateScreen = true;
  994. adventureInt->updateMinimap=true;
  995. }
  996. }
  997. if(LOCPLINT->adventureInt->scrollingRight)
  998. {
  999. if(LOCPLINT->adventureInt->position.x<CGI->ac->map.width-19+4)
  1000. {
  1001. LOCPLINT->adventureInt->position.x++;
  1002. LOCPLINT->adventureInt->updateScreen = true;
  1003. adventureInt->updateMinimap=true;
  1004. }
  1005. }
  1006. if(LOCPLINT->adventureInt->scrollingUp)
  1007. {
  1008. if(LOCPLINT->adventureInt->position.y>-Hoff)
  1009. {
  1010. LOCPLINT->adventureInt->position.y--;
  1011. LOCPLINT->adventureInt->updateScreen = true;
  1012. adventureInt->updateMinimap=true;
  1013. }
  1014. }
  1015. if(LOCPLINT->adventureInt->scrollingDown)
  1016. {
  1017. if(LOCPLINT->adventureInt->position.y<CGI->ac->map.height-18+4)
  1018. {
  1019. LOCPLINT->adventureInt->position.y++;
  1020. LOCPLINT->adventureInt->updateScreen = true;
  1021. adventureInt->updateMinimap=true;
  1022. }
  1023. }
  1024. if(LOCPLINT->adventureInt->updateScreen)
  1025. {
  1026. adventureInt->update();
  1027. adventureInt->updateScreen=false;
  1028. }
  1029. if (LOCPLINT->adventureInt->updateMinimap)
  1030. {
  1031. adventureInt->minimap.draw();
  1032. adventureInt->updateMinimap=false;
  1033. }
  1034. }
  1035. for(int i=0;i<objsToBlit.size();i++)
  1036. objsToBlit[i]->show();
  1037. //SDL_Flip(screen);
  1038. CSDL_Ext::update(screen);
  1039. SDL_Delay(5); //give time for other apps
  1040. SDL_framerateDelay(mainFPSmng);
  1041. }
  1042. adventureInt->hide();
  1043. }
  1044. inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, const int & hid)
  1045. {
  1046. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  1047. for(int h=0; h<hlp.objects.size(); ++h)
  1048. if(hlp.objects[h].first->id==hid)
  1049. {
  1050. hlp.objects[h].second = r;
  1051. return;
  1052. }
  1053. }
  1054. inline void delObjRect(const int & x, const int & y, const int & z, const int & hid)
  1055. {
  1056. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  1057. for(int h=0; h<hlp.objects.size(); ++h)
  1058. if(hlp.objects[h].first->id==hid)
  1059. {
  1060. hlp.objects.erase(hlp.objects.begin()+h);
  1061. return;
  1062. }
  1063. }
  1064. int getDir(int3 src, int3 dst)
  1065. {
  1066. int ret = -1;
  1067. if(dst.x+1 == src.x && dst.y+1 == src.y) //tl
  1068. {
  1069. ret = 1;
  1070. }
  1071. else if(dst.x == src.x && dst.y+1 == src.y) //t
  1072. {
  1073. ret = 2;
  1074. }
  1075. else if(dst.x-1 == src.x && dst.y+1 == src.y) //tr
  1076. {
  1077. ret = 3;
  1078. }
  1079. else if(dst.x-1 == src.x && dst.y == src.y) //r
  1080. {
  1081. ret = 4;
  1082. }
  1083. else if(dst.x-1 == src.x && dst.y-1 == src.y) //br
  1084. {
  1085. ret = 5;
  1086. }
  1087. else if(dst.x == src.x && dst.y-1 == src.y) //b
  1088. {
  1089. ret = 6;
  1090. }
  1091. else if(dst.x+1 == src.x && dst.y-1 == src.y) //bl
  1092. {
  1093. ret = 7;
  1094. }
  1095. else if(dst.x+1 == src.x && dst.y == src.y) //l
  1096. {
  1097. ret = 8;
  1098. }
  1099. return ret;
  1100. }
  1101. void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
  1102. {
  1103. //initializing objects and performing first step of move
  1104. CGHeroInstance * ho = details.ho; //object representing this hero
  1105. int3 hp = details.src;
  1106. if (!details.successful)
  1107. {
  1108. ho->moveDir = getDir(details.src,details.dst);
  1109. ho->isStanding = true;
  1110. adventureInt->heroList.draw();
  1111. if (adventureInt->terrain.currentPath)
  1112. {
  1113. delete adventureInt->terrain.currentPath;
  1114. adventureInt->terrain.currentPath = NULL;
  1115. }
  1116. return;
  1117. }
  1118. if (adventureInt->terrain.currentPath) //&& hero is moving
  1119. {
  1120. adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
  1121. }
  1122. int3 buff = details.ho->pos;
  1123. buff.x-=11;
  1124. buff.y-=9;
  1125. buff = repairScreenPos(buff);
  1126. LOCPLINT->adventureInt->position = buff; //actualizing screen pos
  1127. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  1128. {
  1129. ho->moveDir = 1;
  1130. ho->isStanding = false;
  1131. CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -31)));
  1132. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, -31)));
  1133. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, -31)));
  1134. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, -31)));
  1135. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 1)));
  1136. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 1), ho->id);
  1137. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 1), ho->id);
  1138. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 1), ho->id);
  1139. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 33)));
  1140. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 33), ho->id);
  1141. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 33), ho->id);
  1142. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 33), ho->id);
  1143. 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);
  1144. 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);
  1145. 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);
  1146. 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);
  1147. 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);
  1148. 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);
  1149. }
  1150. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  1151. {
  1152. ho->moveDir = 2;
  1153. ho->isStanding = false;
  1154. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, -31)));
  1155. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, -31)));
  1156. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, -31)));
  1157. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1), ho->id);
  1158. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1), ho->id);
  1159. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1), ho->id);
  1160. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33), ho->id);
  1161. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33), ho->id);
  1162. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33), ho->id);
  1163. 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);
  1164. 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);
  1165. 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);
  1166. }
  1167. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  1168. {
  1169. ho->moveDir = 3;
  1170. ho->isStanding = false;
  1171. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, -31)));
  1172. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, -31)));
  1173. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, -31)));
  1174. CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -31)));
  1175. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 1), ho->id);
  1176. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 1), ho->id);
  1177. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 1), ho->id);
  1178. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 1)));
  1179. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 33), ho->id);
  1180. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 33), ho->id);
  1181. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 33), ho->id);
  1182. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 33)));
  1183. 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);
  1184. 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);
  1185. 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);
  1186. 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);
  1187. 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);
  1188. 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);
  1189. }
  1190. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1191. {
  1192. ho->moveDir = 4;
  1193. ho->isStanding = false;
  1194. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id);
  1195. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id);
  1196. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id);
  1197. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 0)));
  1198. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 32), ho->id);
  1199. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 32), ho->id);
  1200. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 32), ho->id);
  1201. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 32)));
  1202. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1203. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1204. }
  1205. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1206. {
  1207. ho->moveDir = 5;
  1208. ho->isStanding = false;
  1209. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, -1), ho->id);
  1210. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, -1), ho->id);
  1211. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id);
  1212. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -1)));
  1213. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 31), ho->id);
  1214. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 31), ho->id);
  1215. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 31), ho->id);
  1216. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 31)));
  1217. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, 63)));
  1218. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, 63)));
  1219. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, 63)));
  1220. CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 63)));
  1221. 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);
  1222. 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);
  1223. 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);
  1224. 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);
  1225. 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);
  1226. 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);
  1227. }
  1228. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1229. {
  1230. ho->moveDir = 6;
  1231. ho->isStanding = false;
  1232. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1), ho->id);
  1233. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1), ho->id);
  1234. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1), ho->id);
  1235. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31), ho->id);
  1236. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31), ho->id);
  1237. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31), ho->id);
  1238. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, 63)));
  1239. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, 63)));
  1240. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, 63)));
  1241. 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);
  1242. 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);
  1243. 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);
  1244. }
  1245. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1246. {
  1247. ho->moveDir = 7;
  1248. ho->isStanding = false;
  1249. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -1)));
  1250. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id);
  1251. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id);
  1252. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, -1), ho->id);
  1253. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 31)));
  1254. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 31), ho->id);
  1255. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 31), ho->id);
  1256. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 31), ho->id);
  1257. CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 63)));
  1258. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, 63)));
  1259. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, 63)));
  1260. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, 63)));
  1261. 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);
  1262. 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);
  1263. 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);
  1264. 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);
  1265. 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);
  1266. 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);
  1267. }
  1268. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1269. {
  1270. ho->moveDir = 8;
  1271. ho->isStanding = false;
  1272. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 0)));
  1273. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id);
  1274. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id);
  1275. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 0), ho->id);
  1276. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 32)));
  1277. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 32), ho->id);
  1278. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 32), ho->id);
  1279. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 32), ho->id);
  1280. 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);
  1281. 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);
  1282. }
  1283. //first initializing done
  1284. SDL_framerateDelay(mainFPSmng); // after first move
  1285. //main moving
  1286. for(int i=1; i<32; i+=4)
  1287. {
  1288. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  1289. {
  1290. subRect(hp.x-3, hp.y-2, hp.z, genRect(32, 32, -31+i, -31+i), ho->id);
  1291. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 1+i, -31+i), ho->id);
  1292. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 33+i, -31+i), ho->id);
  1293. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 65+i, -31+i), ho->id);
  1294. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 1+i), ho->id);
  1295. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 1+i), ho->id);
  1296. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 1+i), ho->id);
  1297. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 1+i), ho->id);
  1298. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 33+i), ho->id);
  1299. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 33+i), ho->id);
  1300. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 33+i), ho->id);
  1301. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 33+i), ho->id);
  1302. }
  1303. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  1304. {
  1305. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 0, -31+i), ho->id);
  1306. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 32, -31+i), ho->id);
  1307. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 64, -31+i), ho->id);
  1308. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1+i), ho->id);
  1309. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1+i), ho->id);
  1310. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1+i), ho->id);
  1311. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33+i), ho->id);
  1312. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33+i), ho->id);
  1313. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33+i), ho->id);
  1314. }
  1315. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  1316. {
  1317. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, -1-i, -31+i), ho->id);
  1318. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 31-i, -31+i), ho->id);
  1319. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 63-i, -31+i), ho->id);
  1320. subRect(hp.x+1, hp.y-2, hp.z, genRect(32, 32, 95-i, -31+i), ho->id);
  1321. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 1+i), ho->id);
  1322. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 1+i), ho->id);
  1323. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 1+i), ho->id);
  1324. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 1+i), ho->id);
  1325. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 33+i), ho->id);
  1326. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 33+i), ho->id);
  1327. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 33+i), ho->id);
  1328. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 33+i), ho->id);
  1329. }
  1330. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1331. {
  1332. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 0), ho->id);
  1333. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 0), ho->id);
  1334. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 0), ho->id);
  1335. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 0), ho->id);
  1336. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 32), ho->id);
  1337. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 32), ho->id);
  1338. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 32), ho->id);
  1339. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 32), ho->id);
  1340. }
  1341. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1342. {
  1343. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, -1-i), ho->id);
  1344. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, -1-i), ho->id);
  1345. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, -1-i), ho->id);
  1346. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, -1-i), ho->id);
  1347. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 31-i), ho->id);
  1348. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 31-i), ho->id);
  1349. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 31-i), ho->id);
  1350. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 31-i), ho->id);
  1351. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, -1-i, 63-i), ho->id);
  1352. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 31-i, 63-i), ho->id);
  1353. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 63-i, 63-i), ho->id);
  1354. subRect(hp.x+1, hp.y+1, hp.z, genRect(32, 32, 95-i, 63-i), ho->id);
  1355. }
  1356. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1357. {
  1358. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1-i), ho->id);
  1359. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1-i), ho->id);
  1360. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1-i), ho->id);
  1361. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31-i), ho->id);
  1362. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31-i), ho->id);
  1363. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31-i), ho->id);
  1364. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 0, 63-i), ho->id);
  1365. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 32, 63-i), ho->id);
  1366. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 64, 63-i), ho->id);
  1367. }
  1368. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1369. {
  1370. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, -1-i), ho->id);
  1371. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, -1-i), ho->id);
  1372. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, -1-i), ho->id);
  1373. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, -1-i), ho->id);
  1374. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 31-i), ho->id);
  1375. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 31-i), ho->id);
  1376. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 31-i), ho->id);
  1377. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 31-i), ho->id);
  1378. subRect(hp.x-3, hp.y+1, hp.z, genRect(32, 32, -31+i, 63-i), ho->id);
  1379. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 1+i, 63-i), ho->id);
  1380. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 33+i, 63-i), ho->id);
  1381. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 65+i, 63-i), ho->id);
  1382. }
  1383. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1384. {
  1385. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 0), ho->id);
  1386. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 0), ho->id);
  1387. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 0), ho->id);
  1388. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 0), ho->id);
  1389. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 32), ho->id);
  1390. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 32), ho->id);
  1391. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 32), ho->id);
  1392. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 32), ho->id);
  1393. }
  1394. LOCPLINT->adventureInt->update(); //updating screen
  1395. CSDL_Ext::update(screen);
  1396. CGI->screenh->updateScreen();
  1397. ++LOCPLINT->adventureInt->animValHitCount; //for animations
  1398. if(LOCPLINT->adventureInt->animValHitCount == 4)
  1399. {
  1400. LOCPLINT->adventureInt->animValHitCount = 0;
  1401. ++LOCPLINT->adventureInt->anim;
  1402. LOCPLINT->adventureInt->updateScreen = true;
  1403. }
  1404. ++LOCPLINT->adventureInt->heroAnim;
  1405. SDL_Delay(5);
  1406. SDL_framerateDelay(mainFPSmng); //for animation purposes
  1407. } //for(int i=1; i<32; i+=4)
  1408. //main moving done
  1409. //finishing move
  1410. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  1411. {
  1412. delObjRect(hp.x, hp.y-2, hp.z, ho->id);
  1413. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1414. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1415. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1416. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1417. delObjRect(hp.x-3, hp.y, hp.z, ho->id);
  1418. }
  1419. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  1420. {
  1421. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1422. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1423. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1424. }
  1425. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  1426. {
  1427. delObjRect(hp.x-2, hp.y-2, hp.z, ho->id);
  1428. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1429. delObjRect(hp.x+1, hp.y, hp.z, ho->id);
  1430. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1431. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1432. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1433. }
  1434. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1435. {
  1436. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1437. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1438. }
  1439. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1440. {
  1441. delObjRect(hp.x-2, hp.y+1, hp.z, ho->id);
  1442. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1443. delObjRect(hp.x+1, hp.y-1, hp.z, ho->id);
  1444. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1445. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1446. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1447. }
  1448. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1449. {
  1450. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1451. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1452. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1453. }
  1454. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1455. {
  1456. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1457. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1458. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1459. delObjRect(hp.x-3, hp.y-1, hp.z, ho->id);
  1460. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1461. delObjRect(hp.x, hp.y+1, hp.z, ho->id);
  1462. }
  1463. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1464. {
  1465. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1466. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1467. }
  1468. ho->pos = details.dst; //copy of hero's position
  1469. //ho->moveDir = 0; //move ended
  1470. ho->isStanding = true;
  1471. //move finished
  1472. CGI->mh->recalculateHideVisPosUnderObj(details.ho, true);
  1473. adventureInt->minimap.draw();
  1474. adventureInt->heroList.updateMove(ho);
  1475. }
  1476. void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
  1477. {
  1478. heroWins.erase(hero->ID);
  1479. }
  1480. void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
  1481. {
  1482. if(heroWins.find(hero->subID)==heroWins.end())
  1483. heroWins.insert(std::pair<int,SDL_Surface*>(hero->subID,infoWin(hero)));
  1484. }
  1485. SDL_Surface * CPlayerInterface::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to)
  1486. {
  1487. char * buf = new char[10];
  1488. for (int i=from;i<to;i++)
  1489. {
  1490. itoa(curh->primSkills[i],buf,10);
  1491. printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
  1492. }
  1493. delete[] buf;
  1494. return ret;
  1495. }
  1496. SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh)
  1497. {
  1498. char * buf = new char[10];
  1499. blueToPlayersAdv(hInfo,playerID,1);
  1500. SDL_Surface * ret = SDL_DisplayFormat(hInfo);
  1501. SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
  1502. printAt(curh->name,75,15,GEOR13,zwykly,ret);
  1503. drawPrimarySkill(curh, ret);
  1504. for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
  1505. {
  1506. blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
  1507. itoa((*i).second.second,buf,10);
  1508. printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
  1509. }
  1510. blitAt(curh->type->portraitLarge,11,12,ret);
  1511. itoa(curh->mana,buf,10);
  1512. printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points
  1513. delete[] buf;
  1514. blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret);
  1515. blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret);
  1516. //SDL_SaveBMP(ret,"inf1.bmp");
  1517. return ret;
  1518. }
  1519. SDL_Surface * CPlayerInterface::drawTownInfoWin(const CGTownInstance * curh)
  1520. {
  1521. char * buf = new char[10];
  1522. blueToPlayersAdv(tInfo,playerID,1);
  1523. SDL_Surface * ret = SDL_DisplayFormat(tInfo);
  1524. SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
  1525. printAt(curh->name,75,15,GEOR13,zwykly,ret);
  1526. int pom = curh->fortLevel() - 1; if(pom<0) pom = 3;
  1527. blitAt(forts->ourImages[pom].bitmap,115,42,ret);
  1528. if((pom=curh->hallLevel())>=0)
  1529. blitAt(halls->ourImages[pom].bitmap,77,42,ret);
  1530. itoa(curh->dailyIncome(),buf,10);
  1531. printAtMiddle(buf,167,70,GEORM,zwykly,ret);
  1532. for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
  1533. {
  1534. if(!i->second.first)
  1535. continue;
  1536. blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
  1537. itoa((*i).second.second,buf,10);
  1538. printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
  1539. }
  1540. //blit town icon
  1541. pom = curh->subID*2;
  1542. if (!curh->hasFort())
  1543. pom += F_NUMBER*2;
  1544. if(curh->builded >= MAX_BUILDING_PER_TURN)
  1545. pom++;
  1546. blitAt(bigTownPic->ourImages[pom].bitmap,13,13,ret);
  1547. delete[] buf;
  1548. return ret;
  1549. }
  1550. void CPlayerInterface::openTownWindow(const CGTownInstance * town)
  1551. {
  1552. adventureInt->hide();
  1553. //timeHandler t;
  1554. //t.getDif();
  1555. castleInt = new CCastleInterface(town,true);
  1556. //std::cout << "Loading town screen: " << t.getDif() <<std::endl;
  1557. }
  1558. SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //specific=0 => draws info about selected town/hero
  1559. {
  1560. if (specific)
  1561. {
  1562. switch (specific->ID)
  1563. {
  1564. case 34:
  1565. return drawHeroInfoWin(dynamic_cast<const CGHeroInstance*>(specific));
  1566. break;
  1567. case 98:
  1568. return drawTownInfoWin(dynamic_cast<const CGTownInstance*>(specific));
  1569. break;
  1570. default:
  1571. return NULL;
  1572. break;
  1573. }
  1574. }
  1575. else
  1576. {
  1577. switch (adventureInt->selection.type)
  1578. {
  1579. case HEROI_TYPE:
  1580. {
  1581. const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection.selected;
  1582. return drawHeroInfoWin(curh);
  1583. }
  1584. case TOWNI_TYPE:
  1585. {
  1586. return drawTownInfoWin((const CGTownInstance *)adventureInt->selection.selected);
  1587. }
  1588. default:
  1589. return NULL;
  1590. }
  1591. }
  1592. return NULL;
  1593. }
  1594. void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent)
  1595. {
  1596. for (int i=0; i<hoverable.size();i++)
  1597. {
  1598. if (isItIn(&hoverable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1599. {
  1600. if (!hoverable[i]->hovered)
  1601. hoverable[i]->hover(true);
  1602. }
  1603. else if (hoverable[i]->hovered)
  1604. {
  1605. hoverable[i]->hover(false);
  1606. }
  1607. }
  1608. for(int i=0; i<motioninterested.size();i++)
  1609. {
  1610. if (motioninterested[i]->strongInterest || isItIn(&motioninterested[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1611. {
  1612. motioninterested[i]->mouseMoved(sEvent->motion);
  1613. }
  1614. }
  1615. if(sEvent->motion.x<15)
  1616. {
  1617. LOCPLINT->adventureInt->scrollingLeft = true;
  1618. }
  1619. else
  1620. {
  1621. LOCPLINT->adventureInt->scrollingLeft = false;
  1622. }
  1623. if(sEvent->motion.x>screen->w-15)
  1624. {
  1625. LOCPLINT->adventureInt->scrollingRight = true;
  1626. }
  1627. else
  1628. {
  1629. LOCPLINT->adventureInt->scrollingRight = false;
  1630. }
  1631. if(sEvent->motion.y<15)
  1632. {
  1633. LOCPLINT->adventureInt->scrollingUp = true;
  1634. }
  1635. else
  1636. {
  1637. LOCPLINT->adventureInt->scrollingUp = false;
  1638. }
  1639. if(sEvent->motion.y>screen->h-15)
  1640. {
  1641. LOCPLINT->adventureInt->scrollingDown = true;
  1642. }
  1643. else
  1644. {
  1645. LOCPLINT->adventureInt->scrollingDown = false;
  1646. }
  1647. }
  1648. void CPlayerInterface::handleKeyUp(SDL_Event *sEvent)
  1649. {
  1650. switch (sEvent->key.keysym.sym)
  1651. {
  1652. case SDLK_LEFT:
  1653. {
  1654. LOCPLINT->adventureInt->scrollingLeft = false;
  1655. break;
  1656. }
  1657. case (SDLK_RIGHT):
  1658. {
  1659. LOCPLINT->adventureInt->scrollingRight = false;
  1660. break;
  1661. }
  1662. case (SDLK_UP):
  1663. {
  1664. LOCPLINT->adventureInt->scrollingUp = false;
  1665. break;
  1666. }
  1667. case (SDLK_DOWN):
  1668. {
  1669. LOCPLINT->adventureInt->scrollingDown = false;
  1670. break;
  1671. }
  1672. case (SDLK_u):
  1673. {
  1674. adventureInt->underground.clickLeft(false);
  1675. break;
  1676. }
  1677. case (SDLK_m):
  1678. {
  1679. adventureInt->moveHero.clickLeft(false);
  1680. break;
  1681. }
  1682. case (SDLK_e):
  1683. {
  1684. adventureInt->endTurn.clickLeft(false);
  1685. break;
  1686. }
  1687. }
  1688. }
  1689. void CPlayerInterface::handleKeyDown(SDL_Event *sEvent)
  1690. {
  1691. switch (sEvent->key.keysym.sym)
  1692. {
  1693. case SDLK_LEFT:
  1694. {
  1695. LOCPLINT->adventureInt->scrollingLeft = true;
  1696. break;
  1697. }
  1698. case (SDLK_RIGHT):
  1699. {
  1700. LOCPLINT->adventureInt->scrollingRight = true;
  1701. break;
  1702. }
  1703. case (SDLK_UP):
  1704. {
  1705. LOCPLINT->adventureInt->scrollingUp = true;
  1706. break;
  1707. }
  1708. case (SDLK_DOWN):
  1709. {
  1710. LOCPLINT->adventureInt->scrollingDown = true;
  1711. break;
  1712. }
  1713. case (SDLK_q):
  1714. {
  1715. exit(0);
  1716. break;
  1717. }
  1718. case (SDLK_u):
  1719. {
  1720. adventureInt->underground.clickLeft(true);
  1721. break;
  1722. }
  1723. case (SDLK_m):
  1724. {
  1725. adventureInt->moveHero.clickLeft(true);
  1726. break;
  1727. }
  1728. case (SDLK_e):
  1729. {
  1730. adventureInt->endTurn.clickLeft(true);
  1731. break;
  1732. }
  1733. }
  1734. }
  1735. void CPlayerInterface::handleEvent(SDL_Event *sEvent)
  1736. {
  1737. current = sEvent;
  1738. if(sEvent->type == SDL_MOUSEMOTION)
  1739. {
  1740. CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
  1741. }
  1742. if(sEvent->type==SDL_QUIT)
  1743. exit(0);
  1744. else if (sEvent->type==SDL_KEYDOWN)
  1745. {
  1746. handleKeyDown(sEvent);
  1747. } //keydown end
  1748. else if(sEvent->type==SDL_KEYUP)
  1749. {
  1750. handleKeyUp(sEvent);
  1751. }//keyup end
  1752. else if(sEvent->type==SDL_MOUSEMOTION)
  1753. {
  1754. handleMouseMotion(sEvent);
  1755. } //mousemotion end
  1756. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1757. {
  1758. LOGE("Left mouse button down1");
  1759. for(int i=0; i<lclickable.size();i++)
  1760. {
  1761. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1762. {
  1763. lclickable[i]->clickLeft(true);
  1764. }
  1765. }
  1766. }
  1767. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1768. {
  1769. for(int i=0; i<lclickable.size();i++)
  1770. {
  1771. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1772. {
  1773. lclickable[i]->clickLeft(false);
  1774. }
  1775. else
  1776. lclickable[i]->clickLeft(boost::logic::indeterminate);
  1777. }
  1778. }
  1779. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1780. {
  1781. for(int i=0; i<rclickable.size();i++)
  1782. {
  1783. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1784. {
  1785. rclickable[i]->clickRight(true);
  1786. }
  1787. }
  1788. }
  1789. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1790. {
  1791. for(int i=0; i<rclickable.size();i++)
  1792. {
  1793. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1794. {
  1795. rclickable[i]->clickRight(false);
  1796. }
  1797. else
  1798. rclickable[i]->clickRight(boost::logic::indeterminate);
  1799. }
  1800. }
  1801. current = NULL;
  1802. } //event end
  1803. int3 CPlayerInterface::repairScreenPos(int3 pos)
  1804. {
  1805. if(pos.x<=-Woff)
  1806. pos.x = -Woff+1;
  1807. if(pos.y<=-Hoff)
  1808. pos.y = -Hoff+1;
  1809. if(pos.x>CGI->mh->map->width - this->adventureInt->terrain.tilesw + Woff)
  1810. pos.x = CGI->mh->map->width - this->adventureInt->terrain.tilesw + Woff;
  1811. if(pos.y>CGI->mh->map->height - this->adventureInt->terrain.tilesh + Hoff)
  1812. pos.y = CGI->mh->map->height - this->adventureInt->terrain.tilesh + Hoff;
  1813. return pos;
  1814. }
  1815. void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)
  1816. {
  1817. SDL_FreeSurface(heroWins[hero->subID]);//TODO: moznaby zmieniac jedynie fragment bitmapy zwiazany z dana umiejetnoscia
  1818. heroWins[hero->subID] = infoWin(hero); //a nie przerysowywac calosc. Troche roboty, obecnie chyba nie wartej swieczki.
  1819. if (adventureInt->selection.selected == hero)
  1820. adventureInt->infoBar.draw();
  1821. return;
  1822. }
  1823. void CPlayerInterface::receivedResource(int type, int val)
  1824. {
  1825. adventureInt->resdatabar.draw();
  1826. }
  1827. void CPlayerInterface::showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID)
  1828. {
  1829. adventureInt->hide(); //dezaktywacja starego interfejsu
  1830. CSelWindow * temp = CMessage::genSelWindow(text,LOCPLINT->playerID,35,components,playerID);
  1831. LOCPLINT->objsToBlit.push_back(temp);
  1832. temp->pos.x=300-(temp->pos.w/2);
  1833. temp->pos.y=300-(temp->pos.h/2);
  1834. temp->okb.pos.x = temp->okb.posr.x + temp->pos.x;
  1835. temp->okb.pos.y = temp->okb.posr.y + temp->pos.y;
  1836. temp->okb.activate();
  1837. for (int i=0;i<temp->components.size();i++)
  1838. {
  1839. temp->components[i]->activate();
  1840. temp->components[i]->pos.x += temp->pos.x;
  1841. temp->components[i]->pos.y += temp->pos.y;
  1842. }
  1843. temp->ID = askID;
  1844. components[0]->clickLeft(true);
  1845. }
  1846. void CPlayerInterface::heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town)
  1847. {
  1848. openTownWindow(town);
  1849. }
  1850. void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj)
  1851. {
  1852. if(obj->ID == 34) //hero
  1853. {
  1854. const CGHeroInstance * hh;
  1855. if(hh = dynamic_cast<const CGHeroInstance*>(obj))
  1856. {
  1857. SDL_FreeSurface(heroWins[hh->subID]);
  1858. heroWins[hh->subID] = infoWin(hh);
  1859. }
  1860. CHeroWindow * hw = dynamic_cast<CHeroWindow *>(curint);
  1861. if(hw)
  1862. {
  1863. hw->garInt->recreateSlots();
  1864. hw->garInt->show();
  1865. }
  1866. else if(castleInt == curint) //opened town window - redraw town garrsion slots (change is within hero garr)
  1867. {
  1868. castleInt->garr->highlighted = NULL;
  1869. castleInt->garr->recreateSlots();
  1870. }
  1871. }
  1872. else if (obj->ID == 98) //town
  1873. {
  1874. const CGTownInstance * tt;
  1875. if(tt = dynamic_cast<const CGTownInstance*>(obj))
  1876. {
  1877. SDL_FreeSurface(townWins[tt->identifier]);
  1878. townWins[tt->identifier] = infoWin(tt);
  1879. }
  1880. const CCastleInterface *ci = dynamic_cast<CCastleInterface*>(curint);
  1881. if(ci)
  1882. {
  1883. ci->garr->highlighted = NULL;
  1884. ci->garr->recreateSlots();
  1885. }
  1886. }
  1887. }
  1888. void CPlayerInterface::buildChanged(const CGTownInstance *town, int buildingID, int what) //what: 1 - built, 2 - demolished
  1889. {
  1890. if(curint!=castleInt)
  1891. return;
  1892. if(castleInt->town!=town)
  1893. return;
  1894. switch(what)
  1895. {
  1896. case 1:
  1897. castleInt->addBuilding(buildingID);
  1898. break;
  1899. case 2:
  1900. castleInt->removeBuilding(buildingID);
  1901. break;
  1902. }
  1903. }
  1904. void CPlayerInterface::battleStart(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, tribool side) //called by engine when battle starts; side=0 - left, side=1 - right
  1905. {
  1906. curint->deactivate();
  1907. curint = new CBattleInterface(army1,army2,hero1,hero2);
  1908. curint->activate();
  1909. LOCPLINT->objsToBlit.push_back(dynamic_cast<IShowable*>(curint));
  1910. }
  1911. void CPlayerInterface::battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles) //called when battlefield is prepared, prior the battle beginning
  1912. {
  1913. }
  1914. 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
  1915. {
  1916. dynamic_cast<CBattleInterface*>(curint)->newRound(round);
  1917. }
  1918. void CPlayerInterface::actionStarted(BattleAction action)//occurs BEFORE every action taken by any stack or by the hero
  1919. {
  1920. }
  1921. void CPlayerInterface::actionFinished(BattleAction action)//occurs AFTER every action taken by any stack or by the hero
  1922. {
  1923. //dynamic_cast<CBattleInterface*>(curint)->givenCommand = -1;
  1924. }
  1925. BattleAction CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack
  1926. {
  1927. unsigned char showCount = 0;
  1928. dynamic_cast<CBattleInterface*>(curint)->stackActivated(stackID);
  1929. while(!dynamic_cast<CBattleInterface*>(curint)->givenCommand) //while current unit can perform an action
  1930. {
  1931. ++showCount;
  1932. SDL_Event sEvent;
  1933. while (SDL_PollEvent(&sEvent)) //wait for event...
  1934. {
  1935. LOCPLINT->handleEvent(&sEvent);
  1936. }
  1937. if(showCount%2==0)
  1938. for(int i=0;i<objsToBlit.size();i++)
  1939. objsToBlit[i]->show();
  1940. //SDL_Flip(screen);
  1941. CSDL_Ext::update(screen);
  1942. /*timeHandler th;
  1943. th.getDif();
  1944. int tv = th.getDif();
  1945. for (int i=0;i<((CBattleInterface*)this->curint)->timeinterested.size();i++)
  1946. {
  1947. if (timeinterested[i]->toNextTick>=0)
  1948. timeinterested[i]->toNextTick-=tv;
  1949. if (timeinterested[i]->toNextTick<0)
  1950. timeinterested[i]->tick();
  1951. }*/
  1952. SDL_Delay(1); //give time for other apps
  1953. SDL_framerateDelay(mainFPSmng);
  1954. }
  1955. BattleAction ret = *(dynamic_cast<CBattleInterface*>(curint)->givenCommand);
  1956. delete dynamic_cast<CBattleInterface*>(curint)->givenCommand;
  1957. dynamic_cast<CBattleInterface*>(curint)->givenCommand = NULL;
  1958. return ret;
  1959. }
  1960. void CPlayerInterface::battleEnd(CCreatureSet * army1, CCreatureSet * army2, CArmedInstance *hero1, CArmedInstance *hero2, std::vector<int> capturedArtifacts, int expForWinner, bool winner)
  1961. {
  1962. dynamic_cast<CBattleInterface*>(curint)->deactivate();
  1963. LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),dynamic_cast<IShowable*>(curint)));
  1964. delete dynamic_cast<CBattleInterface*>(curint);
  1965. curint = adventureInt;
  1966. adventureInt->activate();
  1967. }
  1968. void CPlayerInterface::battleStackMoved(int ID, int dest, bool startMoving, bool endMoving)
  1969. {
  1970. dynamic_cast<CBattleInterface*>(curint)->stackMoved(ID, dest, startMoving, endMoving);
  1971. }
  1972. void CPlayerInterface::battleStackAttacking(int ID, int dest)
  1973. {
  1974. dynamic_cast<CBattleInterface*>(curint)->stackAttacking(ID, dest);
  1975. }
  1976. void CPlayerInterface::battleStackIsAttacked(int ID, int dmg, int killed, int IDby)
  1977. {
  1978. dynamic_cast<CBattleInterface*>(curint)->stackIsAttacked(ID, dmg, killed, IDby);
  1979. }
  1980. void CPlayerInterface::battleStackKilled(int ID, int dmg, int killed, int IDby)
  1981. {
  1982. dynamic_cast<CBattleInterface*>(curint)->stackKilled(ID, dmg, killed, IDby);
  1983. }
  1984. void CPlayerInterface::showComp(SComponent comp)
  1985. {
  1986. adventureInt->infoBar.showComp(&comp,4000);
  1987. }
  1988. void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*> & components)
  1989. {
  1990. curint->deactivate(); //dezaktywacja starego interfejsu
  1991. CInfoWindow * temp = CMessage::genIWindow(text,LOCPLINT->playerID,32,components);
  1992. LOCPLINT->objsToBlit.push_back(temp);
  1993. temp->pos.x=300-(temp->pos.w/2);
  1994. temp->pos.y=300-(temp->pos.h/2);
  1995. temp->okb.pos.x = temp->okb.posr.x + temp->pos.x;
  1996. temp->okb.pos.y = temp->okb.posr.y + temp->pos.y;
  1997. temp->okb.activate();
  1998. for (int i=0;i<temp->components.size();i++)
  1999. {
  2000. temp->components[i]->activate();
  2001. temp->components[i]->pos.x += temp->pos.x;
  2002. temp->components[i]->pos.y += temp->pos.y;
  2003. }
  2004. }
  2005. void CPlayerInterface::removeObjToBlit(IShowable* obj)
  2006. {
  2007. objsToBlit.erase
  2008. (std::find(objsToBlit.begin(),objsToBlit.end(),obj));
  2009. //delete obj;
  2010. }
  2011. void CPlayerInterface::tileRevealed(int3 pos)
  2012. {
  2013. adventureInt->minimap.showTile(pos);
  2014. }
  2015. void CPlayerInterface::tileHidden(int3 pos)
  2016. {
  2017. adventureInt->minimap.hideTile(pos);
  2018. }
  2019. void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero)
  2020. {
  2021. adventureInt->heroWindow->setHero(hero);
  2022. this->objsToBlit.push_back(adventureInt->heroWindow);
  2023. adventureInt->hide();
  2024. adventureInt->heroWindow->activate();
  2025. }
  2026. CStatusBar::CStatusBar(int x, int y, std::string name, int maxw)
  2027. {
  2028. bg=CGI->bitmaph->loadBitmap(name);
  2029. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  2030. pos.x=x;
  2031. pos.y=y;
  2032. if(maxw >= 0)
  2033. pos.w = std::min(bg->w,maxw);
  2034. else
  2035. pos.w=bg->w;
  2036. pos.h=bg->h;
  2037. middlex=(pos.w/2)+x;
  2038. middley=(bg->h/2)+y;
  2039. }
  2040. CStatusBar::~CStatusBar()
  2041. {
  2042. SDL_FreeSurface(bg);
  2043. }
  2044. void CStatusBar::clear()
  2045. {
  2046. current="";
  2047. SDL_Rect pom = genRect(pos.h,pos.w,pos.x,pos.y);
  2048. SDL_BlitSurface(bg,&genRect(pos.h,pos.w,0,0),screen,&pom);
  2049. }
  2050. void CStatusBar::print(std::string text)
  2051. {
  2052. current=text;
  2053. SDL_Rect pom = genRect(pos.h,pos.w,pos.x,pos.y);
  2054. SDL_BlitSurface(bg,&genRect(pos.h,pos.w,0,0),screen,&pom);
  2055. printAtMiddle(current,middlex,middley,GEOR13,zwykly);
  2056. }
  2057. void CStatusBar::show()
  2058. {
  2059. SDL_Rect pom = genRect(pos.h,pos.w,pos.x,pos.y);
  2060. SDL_BlitSurface(bg,&genRect(pos.h,pos.w,0,0),screen,&pom);
  2061. printAtMiddle(current,middlex,middley,GEOR13,zwykly);
  2062. }
  2063. std::string CStatusBar::getCurrent()
  2064. {
  2065. return current;
  2066. }
  2067. void CList::activate()
  2068. {
  2069. ClickableL::activate();
  2070. ClickableR::activate();
  2071. Hoverable::activate();
  2072. KeyInterested::activate();
  2073. MotionInterested::activate();
  2074. };
  2075. void CList::deactivate()
  2076. {
  2077. ClickableL::deactivate();
  2078. ClickableR::deactivate();
  2079. Hoverable::deactivate();
  2080. KeyInterested::deactivate();
  2081. MotionInterested::deactivate();
  2082. };
  2083. void CList::clickLeft(tribool down)
  2084. {
  2085. };
  2086. CList::CList(int Size)
  2087. :SIZE(Size)
  2088. {
  2089. }
  2090. CHeroList::CHeroList(int Size)
  2091. :CList(Size)
  2092. {
  2093. pos = genRect(192,64,609,196);
  2094. arrupp = genRect(16,64,609,196);
  2095. arrdop = genRect(16,64,609,372);
  2096. //32px per hero
  2097. posmobx = 610;
  2098. posmoby = 213;
  2099. posporx = 617;
  2100. pospory = 212;
  2101. posmanx = 666;
  2102. posmany = 213;
  2103. arrup = CGI->spriteh->giveDef("IAM012.DEF");
  2104. arrdo = CGI->spriteh->giveDef("IAM013.DEF");
  2105. mobile = CGI->spriteh->giveDef("IMOBIL.DEF");
  2106. mana = CGI->spriteh->giveDef("IMANA.DEF");
  2107. empty = CGI->bitmaph->loadBitmap("HPSXXX.bmp");
  2108. selection = CGI->bitmaph->loadBitmap("HPSYYY.bmp");
  2109. SDL_SetColorKey(selection,SDL_SRCCOLORKEY,SDL_MapRGB(selection->format,0,255,255));
  2110. from = 0;
  2111. pressed = indeterminate;
  2112. }
  2113. void CHeroList::init()
  2114. {
  2115. bg = CSDL_Ext::newSurface(68,193,screen);
  2116. SDL_BlitSurface(LOCPLINT->adventureInt->bg,&genRect(193,68,607,196),bg,&genRect(193,68,0,0));
  2117. }
  2118. void CHeroList::genList()
  2119. {
  2120. int howMany = LOCPLINT->cb->howManyHeroes();
  2121. for (int i=0;i<howMany;i++)
  2122. {
  2123. items.push_back(std::pair<const CGHeroInstance *,CPath *>(LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,i,0),NULL));
  2124. }
  2125. }
  2126. void CHeroList::select(int which)
  2127. {
  2128. if (which<0)
  2129. {
  2130. selected = which;
  2131. LOCPLINT->adventureInt->selection.selected = LOCPLINT->adventureInt->terrain.currentPath = NULL;
  2132. draw();
  2133. LOCPLINT->adventureInt->infoBar.draw(NULL);
  2134. }
  2135. if (which>=items.size())
  2136. return;
  2137. selected = which;
  2138. LOCPLINT->adventureInt->centerOn(items[which].first->pos);
  2139. LOCPLINT->adventureInt->selection.type = HEROI_TYPE;
  2140. LOCPLINT->adventureInt->selection.selected = items[which].first;
  2141. LOCPLINT->adventureInt->terrain.currentPath = items[which].second;
  2142. draw();
  2143. LOCPLINT->adventureInt->townList.draw();
  2144. LOCPLINT->adventureInt->infoBar.draw(NULL);
  2145. }
  2146. void CHeroList::clickLeft(tribool down)
  2147. {
  2148. if (down)
  2149. {
  2150. /***************************ARROWS*****************************************/
  2151. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  2152. {
  2153. blitAt(arrup->ourImages[1].bitmap,arrupp.x,arrupp.y);
  2154. pressed = true;
  2155. return;
  2156. }
  2157. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  2158. {
  2159. blitAt(arrdo->ourImages[1].bitmap,arrdop.x,arrdop.y);
  2160. pressed = false;
  2161. return;
  2162. }
  2163. /***************************HEROES*****************************************/
  2164. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2165. hx-=pos.x;
  2166. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2167. int ny = hy/32;
  2168. if (ny>=5 || ny<0)
  2169. return;
  2170. if ( (ny+from)==selected && (LOCPLINT->adventureInt->selection.type == HEROI_TYPE))
  2171. LOCPLINT->openHeroWindow(items[selected].first);//print hero screen
  2172. select(ny+from);
  2173. }
  2174. else
  2175. {
  2176. if (indeterminate(pressed))
  2177. return;
  2178. if (pressed) //up
  2179. {
  2180. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  2181. pressed = indeterminate;
  2182. if (!down)
  2183. {
  2184. from--;
  2185. if (from<0)
  2186. from=0;
  2187. draw();
  2188. }
  2189. }
  2190. else if (!pressed) //down
  2191. {
  2192. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  2193. pressed = indeterminate;
  2194. if (!down)
  2195. {
  2196. from++;
  2197. //if (from<items.size()-5)
  2198. // from=items.size()-5;
  2199. draw();
  2200. }
  2201. }
  2202. else
  2203. throw 0;
  2204. }
  2205. }
  2206. void CHeroList::mouseMoved (SDL_MouseMotionEvent & sEvent)
  2207. {
  2208. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  2209. {
  2210. if (from>0)
  2211. LOCPLINT->adventureInt->statusbar.print(CGI->preth->zelp[303].first);
  2212. else
  2213. LOCPLINT->adventureInt->statusbar.clear();
  2214. return;
  2215. }
  2216. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  2217. {
  2218. if ((items.size()-from) > 5)
  2219. LOCPLINT->adventureInt->statusbar.print(CGI->preth->zelp[304].first);
  2220. else
  2221. LOCPLINT->adventureInt->statusbar.clear();
  2222. return;
  2223. }
  2224. //if not buttons then heroes
  2225. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2226. hx-=pos.x;
  2227. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2228. int ny = hy/32;
  2229. if ((ny>5 || ny<0) || (from+ny>=items.size()))
  2230. {
  2231. LOCPLINT->adventureInt->statusbar.clear();
  2232. return;
  2233. }
  2234. std::vector<std::string> temp;
  2235. temp.push_back(items[from+ny].first->name);
  2236. temp.push_back(items[from+ny].first->type->heroClass->name);
  2237. LOCPLINT->adventureInt->statusbar.print( processStr(CGI->generaltexth->allTexts[15],temp) );
  2238. //select(ny+from);
  2239. }
  2240. void CHeroList::clickRight(tribool down)
  2241. {
  2242. if (down)
  2243. {
  2244. /***************************ARROWS*****************************************/
  2245. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  2246. {
  2247. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[303].second,down,this);
  2248. }
  2249. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  2250. {
  2251. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[304].second,down,this);
  2252. }
  2253. //if not buttons then heroes
  2254. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2255. hx-=pos.x;
  2256. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2257. int ny = hy/32;
  2258. if ((ny>5 || ny<0) || (from+ny>=items.size()))
  2259. {
  2260. return;
  2261. }
  2262. //show popup
  2263. CInfoPopup * ip = new CInfoPopup(LOCPLINT->heroWins[items[from+ny].first->subID],LOCPLINT->current->motion.x-LOCPLINT->heroWins[items[from+ny].first->subID]->w,LOCPLINT->current->motion.y-LOCPLINT->heroWins[items[from+ny].first->subID]->h,false);
  2264. ip->activate();
  2265. }
  2266. else
  2267. {
  2268. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[303].second,down,this);
  2269. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[304].second,down,this);
  2270. }
  2271. }
  2272. void CHeroList::hover (bool on)
  2273. {
  2274. }
  2275. void CHeroList::keyPressed (SDL_KeyboardEvent & key)
  2276. {
  2277. }
  2278. void CHeroList::updateHList()
  2279. {
  2280. items.clear();
  2281. genList();
  2282. if(selected>=items.size())
  2283. select(items.size()-1);
  2284. if(items.size()==0)
  2285. LOCPLINT->adventureInt->townList.select(0);
  2286. else
  2287. select(selected);
  2288. }
  2289. void CHeroList::updateMove(const CGHeroInstance* which) //draws move points bar
  2290. {
  2291. int ser = LOCPLINT->cb->getHeroSerial(which);
  2292. ser -= from;
  2293. int pom = (which->movement)/100;
  2294. blitAt(mobile->ourImages[pom].bitmap,posmobx,posmoby+ser*32); //move point
  2295. }
  2296. void CHeroList::draw()
  2297. {
  2298. for (int iT=0+from;iT<5+from;iT++)
  2299. {
  2300. int i = iT-from;
  2301. if (iT>=items.size())
  2302. {
  2303. blitAt(mobile->ourImages[0].bitmap,posmobx,posmoby+i*32);
  2304. blitAt(mana->ourImages[0].bitmap,posmanx,posmany+i*32);
  2305. blitAt(empty,posporx,pospory+i*32);
  2306. continue;
  2307. }
  2308. int pom = (LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->movement)/100;
  2309. if (pom>25) pom=25;
  2310. if (pom<0) pom=0;
  2311. blitAt(mobile->ourImages[pom].bitmap,posmobx,posmoby+i*32); //move point
  2312. pom = (LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->mana)/5; //bylo: .../10;
  2313. if (pom>25) pom=25;
  2314. if (pom<0) pom=0;
  2315. blitAt(mana->ourImages[pom].bitmap,posmanx,posmany+i*32); //mana
  2316. SDL_Surface * temp = LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->type->portraitSmall;
  2317. blitAt(temp,posporx,pospory+i*32);
  2318. if ((selected == iT) && (LOCPLINT->adventureInt->selection.type == HEROI_TYPE))
  2319. {
  2320. blitAt(selection,posporx,pospory+i*32);
  2321. }
  2322. //TODO: support for custom portraits
  2323. }
  2324. if (from>0)
  2325. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  2326. else
  2327. blitAt(arrup->ourImages[2].bitmap,arrupp.x,arrupp.y);
  2328. if (items.size()-from>5)
  2329. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  2330. else
  2331. blitAt(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y);
  2332. }
  2333. CTownList::~CTownList()
  2334. {
  2335. delete arrup;
  2336. delete arrdo;
  2337. }
  2338. CTownList::CTownList(int Size, SDL_Rect * Pos, int arupx, int arupy, int ardox, int ardoy)
  2339. :CList(Size)
  2340. {
  2341. pos = *Pos;
  2342. arrup = CGI->spriteh->giveDef("IAM014.DEF");
  2343. arrdo = CGI->spriteh->giveDef("IAM015.DEF");
  2344. arrupp.x=arupx;
  2345. arrupp.y=arupy;
  2346. arrupp.w=arrup->ourImages[0].bitmap->w;
  2347. arrupp.h=arrup->ourImages[0].bitmap->h;
  2348. arrdop.x=ardox;
  2349. arrdop.y=ardoy;
  2350. arrdop.w=arrdo->ourImages[0].bitmap->w;
  2351. arrdop.h=arrdo->ourImages[0].bitmap->h;
  2352. posporx = arrdop.x;
  2353. pospory = arrupp.y + arrupp.h;
  2354. pressed = indeterminate;
  2355. from = 0;
  2356. }
  2357. void CTownList::genList()
  2358. {
  2359. int howMany = LOCPLINT->cb->howManyTowns();
  2360. for (int i=0;i<howMany;i++)
  2361. {
  2362. items.push_back(LOCPLINT->cb->getTownInfo(i,0));
  2363. }
  2364. }
  2365. void CTownList::select(int which)
  2366. {
  2367. if (which>=items.size())
  2368. return;
  2369. selected = which;
  2370. if(!fun.empty())
  2371. fun();
  2372. }
  2373. void CTownList::mouseMoved (SDL_MouseMotionEvent & sEvent)
  2374. {
  2375. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  2376. {
  2377. if (from>0)
  2378. LOCPLINT->statusbar->print(CGI->preth->zelp[306].first);
  2379. else
  2380. LOCPLINT->statusbar->clear();
  2381. return;
  2382. }
  2383. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  2384. {
  2385. if ((items.size()-from) > SIZE)
  2386. LOCPLINT->statusbar->print(CGI->preth->zelp[307].first);
  2387. else
  2388. LOCPLINT->statusbar->clear();
  2389. return;
  2390. }
  2391. //if not buttons then towns
  2392. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2393. hx-=pos.x;
  2394. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2395. int ny = hy/32;
  2396. if ((ny>SIZE || ny<0) || (from+ny>=items.size()))
  2397. {
  2398. LOCPLINT->statusbar->clear();
  2399. return;
  2400. };
  2401. LOCPLINT->statusbar->print(items[from+ny]->state->hoverText(const_cast<CGTownInstance*>(items[from+ny])));
  2402. }
  2403. void CTownList::clickLeft(tribool down)
  2404. {
  2405. if (down)
  2406. {
  2407. /***************************ARROWS*****************************************/
  2408. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  2409. {
  2410. blitAt(arrup->ourImages[1].bitmap,arrupp.x,arrupp.y);
  2411. pressed = true;
  2412. return;
  2413. }
  2414. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>SIZE))
  2415. {
  2416. blitAt(arrdo->ourImages[1].bitmap,arrdop.x,arrdop.y);
  2417. pressed = false;
  2418. return;
  2419. }
  2420. /***************************TOWNS*****************************************/
  2421. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2422. hx-=pos.x;
  2423. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2424. int ny = hy/32;
  2425. if (ny>SIZE || ny<0)
  2426. return;
  2427. if (SIZE==5 && (ny+from)==selected && (LOCPLINT->adventureInt->selection.type == TOWNI_TYPE))
  2428. LOCPLINT->openTownWindow(items[selected]);//print town screen
  2429. else
  2430. select(ny+from);
  2431. }
  2432. else
  2433. {
  2434. if (indeterminate(pressed))
  2435. return;
  2436. if (pressed) //up
  2437. {
  2438. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  2439. pressed = indeterminate;
  2440. if (!down)
  2441. {
  2442. from--;
  2443. if (from<0)
  2444. from=0;
  2445. draw();
  2446. }
  2447. }
  2448. else if (!pressed) //down
  2449. {
  2450. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  2451. pressed = indeterminate;
  2452. if (!down)
  2453. {
  2454. from++;
  2455. //if (from<items.size()-5)
  2456. // from=items.size()-5;
  2457. draw();
  2458. }
  2459. }
  2460. else
  2461. throw 0;
  2462. }
  2463. }
  2464. void CTownList::clickRight(tribool down)
  2465. {
  2466. if (down)
  2467. {
  2468. /***************************ARROWS*****************************************/
  2469. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  2470. {
  2471. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[306].second,down,this);
  2472. }
  2473. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  2474. {
  2475. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[307].second,down,this);
  2476. }
  2477. //if not buttons then towns
  2478. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2479. hx-=pos.x;
  2480. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2481. int ny = hy/32;
  2482. if ((ny>5 || ny<0) || (from+ny>=items.size()))
  2483. {
  2484. return;
  2485. }
  2486. //show popup
  2487. CInfoPopup * ip = new CInfoPopup(LOCPLINT->townWins[items[from+ny]->identifier],LOCPLINT->current->motion.x-LOCPLINT->townWins[items[from+ny]->identifier]->w,LOCPLINT->current->motion.y-LOCPLINT->townWins[items[from+ny]->identifier]->h,false);
  2488. ip->activate();
  2489. }
  2490. else
  2491. {
  2492. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[306].second,down,this);
  2493. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[307].second,down,this);
  2494. }
  2495. }
  2496. void CTownList::hover (bool on)
  2497. {
  2498. }
  2499. void CTownList::keyPressed (SDL_KeyboardEvent & key)
  2500. {
  2501. }
  2502. void CTownList::draw()
  2503. {
  2504. for (int iT=0+from;iT<SIZE+from;iT++)
  2505. {
  2506. int i = iT-from;
  2507. if (iT>=items.size())
  2508. {
  2509. blitAt(CGI->townh->getPic(-1),posporx,pospory+i*32);
  2510. continue;
  2511. }
  2512. blitAt(CGI->townh->getPic(items[iT]->subID,items[iT]->hasFort(),items[iT]->builded),posporx,pospory+i*32);
  2513. if ((selected == iT) && (LOCPLINT->adventureInt->selection.type == TOWNI_TYPE))
  2514. {
  2515. blitAt(CGI->townh->getPic(-2),posporx,pospory+i*32);
  2516. }
  2517. }
  2518. if (from>0)
  2519. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  2520. else
  2521. blitAt(arrup->ourImages[2].bitmap,arrupp.x,arrupp.y);
  2522. if (items.size()-from>SIZE)
  2523. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  2524. else
  2525. blitAt(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y);
  2526. }
  2527. CCreaturePic::CCreaturePic(CCreature *cre)
  2528. :c(cre)
  2529. {
  2530. anim = new CCreatureAnimation(cre->animDefName);
  2531. }
  2532. CCreaturePic::~CCreaturePic()
  2533. {
  2534. delete anim;
  2535. }
  2536. int CCreaturePic::blitPic(SDL_Surface *to, int x, int y, bool nextFrame)
  2537. {
  2538. blitAt(CGI->creh->backgrounds[c->faction],x,y);//curx-50,pos.y+130-65);
  2539. SDL_Rect dst = genRect(130,100,x,y);
  2540. if(c->isDoubleWide())
  2541. x-=15;
  2542. return anim->nextFrameMiddle(to,x+70,y+45,true,nextFrame,false,&dst);
  2543. }
  2544. SDL_Surface * CCreaturePic::getPic(bool nextFrame)
  2545. {
  2546. //TODO: write
  2547. return NULL;
  2548. }
  2549. void CRecrutationWindow::close()
  2550. {
  2551. deactivate();
  2552. delete this;
  2553. LOCPLINT->curint->activate();
  2554. CCastleInterface *pom;
  2555. if(pom=dynamic_cast<CCastleInterface*>(LOCPLINT->curint))
  2556. pom->showAll();
  2557. }
  2558. void CRecrutationWindow::Max()
  2559. {
  2560. slider->moveTo(slider->amount);
  2561. }
  2562. void CRecrutationWindow::Buy()
  2563. {
  2564. recruit(creatures[which].ID,slider->value);
  2565. close();
  2566. }
  2567. void CRecrutationWindow::Cancel()
  2568. {
  2569. close();
  2570. }
  2571. void CRecrutationWindow::sliderMoved(int to)
  2572. {
  2573. }
  2574. void CRecrutationWindow::clickLeft(tribool down)
  2575. {
  2576. int curx = 192 + 51 - (102*creatures.size()/2) - (18*(creatures.size()-1)/2);
  2577. for(int i=0;i<creatures.size();i++)
  2578. {
  2579. if(isItIn(&genRect(132,102,pos.x+curx,pos.y+64),LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  2580. {
  2581. which = i;
  2582. int newAmount = std::min(amounts[i],creatures[i].amount);
  2583. slider->amount = newAmount;
  2584. if(slider->value > newAmount)
  2585. slider->moveTo(newAmount);
  2586. else
  2587. slider->moveTo(slider->value);
  2588. curx = 192 + 51 - (102*creatures.size()/2) - (18*(creatures.size()-1)/2);
  2589. for(int j=0;j<creatures.size();j++)
  2590. {
  2591. if(which==j)
  2592. drawBorder(bitmap,curx,64,102,132,int3(255,0,0));
  2593. else
  2594. drawBorder(bitmap,curx,64,102,132,int3(239,215,123));
  2595. curx += 120;
  2596. }
  2597. break;
  2598. }
  2599. curx += 120;
  2600. }
  2601. }
  2602. void CRecrutationWindow::activate()
  2603. {
  2604. LOCPLINT->objsToBlit.push_back(this);
  2605. ClickableL::activate();
  2606. buy->activate();
  2607. max->activate();
  2608. cancel->activate();
  2609. slider->activate();
  2610. }
  2611. void CRecrutationWindow::deactivate()
  2612. {
  2613. LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
  2614. ClickableL::deactivate();
  2615. buy->deactivate();
  2616. max->deactivate();
  2617. cancel->deactivate();
  2618. slider->deactivate();
  2619. }
  2620. void CRecrutationWindow::show(SDL_Surface * to)
  2621. {
  2622. static char c=0;
  2623. blitAt(bitmap,pos.x,pos.y,to?to:screen);
  2624. buy->show();
  2625. max->show();
  2626. cancel->show();
  2627. slider->show();
  2628. char pom[15];
  2629. itoa(creatures[which].amount,pom,10); //available
  2630. printAtMiddle(pom,pos.x+205,pos.y+252,GEOR13,zwykly,screen);
  2631. itoa(slider->value,pom,10); //recruit
  2632. printAtMiddle(pom,pos.x+279,pos.y+252,GEOR13,zwykly,screen);
  2633. 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"
  2634. int curx = pos.x+115-creatures[which].res.size()*16;
  2635. for(int i=0;i<creatures[which].res.size();i++)
  2636. {
  2637. blitAt(CGI->townh->resources->ourImages[creatures[which].res[i].first].bitmap,curx,pos.y+243,screen);
  2638. blitAt(CGI->townh->resources->ourImages[creatures[which].res[i].first].bitmap,curx+258,pos.y+243,screen);
  2639. itoa(creatures[which].res[i].second,pom,10);
  2640. printAtMiddle(pom,curx+12,pos.y+286,GEOR13,zwykly,screen);
  2641. itoa(creatures[which].res[i].second * slider->value,pom,10);
  2642. printAtMiddle(pom,curx+12+258,pos.y+286,GEOR13,zwykly,screen);
  2643. curx+=32;
  2644. }
  2645. curx = pos.x + 192 + 102 - (102*creatures.size()/2) - (18*(creatures.size()-1)/2);
  2646. for(int i=0;i<creatures.size();i++)
  2647. {
  2648. creatures[i].pic->blitPic(screen,curx-50,pos.y+130-65,!(c%2));
  2649. curx += 120;
  2650. }
  2651. c++;
  2652. }
  2653. CRecrutationWindow::CRecrutationWindow(const std::vector<std::pair<int,int> > &Creatures, const boost::function<void(int,int)> &Recruit) //creatures - pairs<creature_ID,amount>
  2654. :recruit(Recruit)
  2655. {
  2656. which = 0;
  2657. creatures.resize(Creatures.size());
  2658. amounts.resize(Creatures.size());
  2659. for(int i=0;i<creatures.size();i++)
  2660. {
  2661. creatures[i].amount = Creatures[i].second;
  2662. creatures[i].ID = Creatures[i].first;
  2663. for(int j=0;j<CGI->creh->creatures[Creatures[i].first].cost.size();j++)
  2664. if(CGI->creh->creatures[Creatures[i].first].cost[j])
  2665. creatures[i].res.push_back(std::make_pair(j,CGI->creh->creatures[Creatures[i].first].cost[j]));
  2666. creatures[i].pic = new CCreaturePic(&CGI->creh->creatures[Creatures[i].first]);
  2667. amounts[i] = CGI->creh->creatures[Creatures[i].first].maxAmount(LOCPLINT->cb->getResourceAmount());
  2668. }
  2669. SDL_Surface *hhlp = CGI->bitmaph->loadBitmap("TPRCRT.bmp");
  2670. blueToPlayersAdv(hhlp,LOCPLINT->playerID);
  2671. bitmap = SDL_ConvertSurface(hhlp,screen->format,0); //na 8bitowej mapie by sie psulo
  2672. SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
  2673. SDL_FreeSurface(hhlp);
  2674. pos.x = screen->w/2 - bitmap->w/2;
  2675. pos.y = screen->h/2 - bitmap->h/2;
  2676. pos.w = bitmap->w;
  2677. pos.h = bitmap->h;
  2678. slider = new CSlider(pos.x+176,pos.y+279,135,boost::bind(&CRecrutationWindow::sliderMoved,this, _1),1,std::min(amounts[0],creatures[0].amount),0,true);
  2679. std::string pom;
  2680. printAtMiddle(CGI->generaltexth->allTexts[346],113,231,GEOR13,zwykly,bitmap); //cost per troop t
  2681. printAtMiddle(CGI->generaltexth->allTexts[465],205,231,GEOR13,zwykly,bitmap); //available t
  2682. printAtMiddle(CGI->generaltexth->allTexts[16],279,231,GEOR13,zwykly,bitmap); //recruit t
  2683. printAtMiddle(CGI->generaltexth->allTexts[466],373,231,GEOR13,zwykly,bitmap); //total cost t
  2684. drawBorder(bitmap,172,222,67,42,int3(239,215,123));
  2685. drawBorder(bitmap,246,222,67,42,int3(239,215,123));
  2686. drawBorder(bitmap,64,222,99,76,int3(239,215,123));
  2687. drawBorder(bitmap,322,222,99,76,int3(239,215,123));
  2688. drawBorder(bitmap,133,312,66,34,int3(173,142,66));
  2689. drawBorder(bitmap,211,312,66,34,int3(173,142,66));
  2690. drawBorder(bitmap,289,312,66,34,int3(173,142,66));
  2691. //border for creatures
  2692. int curx = 192 + 51 - (102*creatures.size()/2) - (18*(creatures.size()-1)/2);
  2693. for(int i=0;i<creatures.size();i++)
  2694. {
  2695. creatures[i].pos.x = curx+1;
  2696. creatures[i].pos.y = 65;
  2697. creatures[i].pos.w = 100;
  2698. creatures[i].pos.h = 130;
  2699. if(which==i)
  2700. drawBorder(bitmap,curx,64,102,132,int3(255,0,0));
  2701. else
  2702. drawBorder(bitmap,curx,64,102,132,int3(239,215,123));
  2703. curx += 120;
  2704. }
  2705. max = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Max,this),pos.x+134,pos.y+313,"IRCBTNS.DEF");
  2706. buy = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Buy,this),pos.x+212,pos.y+313,"IBY6432.DEF");
  2707. cancel = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Cancel,this),pos.x+290,pos.y+313,"ICN6432.DEF");
  2708. LOCPLINT->curint->deactivate();
  2709. //AdventureMapButton( std::string Name, std::string HelpBox, void(T::*Function)(),
  2710. //int x, int y, std::string defName, T* Owner, bool activ=false, std::vector<std::string> * add = NULL, bool playerColoredButton = true );//c-tor
  2711. }//(int x, int y, int totalw, T*Owner,void(T::*Moved)(int to), int Capacity, int Amount, int Value, bool Horizontal)
  2712. CRecrutationWindow::~CRecrutationWindow()
  2713. {
  2714. for(int i=0;i<creatures.size();i++)
  2715. {
  2716. delete creatures[i].pic;
  2717. }
  2718. delete max;
  2719. delete buy;
  2720. delete cancel;
  2721. SDL_FreeSurface(bitmap);
  2722. delete slider;
  2723. }
  2724. CSplitWindow::CSplitWindow(int cid, int max, CGarrisonInt *Owner)
  2725. {
  2726. c=cid;
  2727. slider = NULL;
  2728. gar = Owner;
  2729. bitmap = CGI->bitmaph->loadBitmap("GPUCRDIV.bmp");
  2730. SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
  2731. pos.x = screen->w/2 - bitmap->w/2;
  2732. pos.y = screen->h/2 - bitmap->h/2;
  2733. pos.w = bitmap->w;
  2734. pos.h = bitmap->h;
  2735. ok = new AdventureMapButton("","",boost::bind(&CSplitWindow::split,this),pos.x+20,pos.y+263,"IOK6432.DEF");
  2736. cancel = new AdventureMapButton("","",boost::bind(&CSplitWindow::close,this),pos.x+214,pos.y+263,"ICN6432.DEF");
  2737. slider = new CSlider(pos.x+21,pos.y+194,257,boost::bind(&CSplitWindow::sliderMoved,this,_1),1,max,0,true);
  2738. a1 = max;
  2739. a2 = 0;
  2740. anim = new CCreaturePic(&CGI->creh->creatures[cid]);
  2741. anim->anim->setType(1);
  2742. std::string title = CGI->generaltexth->allTexts[256];
  2743. boost::algorithm::replace_first(title,"%s",CGI->creh->creatures[cid].namePl);
  2744. printAtMiddle(title,150,34,GEOR16,tytulowy,bitmap);
  2745. }
  2746. CSplitWindow::~CSplitWindow()
  2747. {
  2748. SDL_FreeSurface(bitmap);
  2749. delete ok;
  2750. delete cancel;
  2751. delete slider;
  2752. delete anim;
  2753. }
  2754. void CSplitWindow::activate()
  2755. {
  2756. LOCPLINT->objsToBlit.push_back(this);
  2757. KeyInterested::activate();
  2758. ok->activate();
  2759. cancel->activate();
  2760. slider->activate();
  2761. }
  2762. void CSplitWindow::deactivate()
  2763. {
  2764. LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
  2765. KeyInterested::deactivate();
  2766. ok->deactivate();
  2767. cancel->deactivate();
  2768. slider->deactivate();
  2769. }
  2770. void CSplitWindow::split()
  2771. {
  2772. gar->splitStacks(a2);
  2773. close();
  2774. }
  2775. void CSplitWindow::close()
  2776. {
  2777. deactivate();
  2778. delete this;
  2779. LOCPLINT->curint->activate();
  2780. CCastleInterface *c = dynamic_cast<CCastleInterface*>(LOCPLINT->curint);
  2781. if(c) c->showAll();
  2782. }
  2783. void CSplitWindow::sliderMoved(int to)
  2784. {
  2785. a2 = to;
  2786. if(slider)
  2787. a1 = slider->amount - to;
  2788. }
  2789. void CSplitWindow::show(SDL_Surface * to)
  2790. {
  2791. char pom[15];
  2792. blitAt(bitmap,pos.x,pos.y,screen);
  2793. ok->show();
  2794. cancel->show();
  2795. slider->show();
  2796. itoa(a1,pom,10);
  2797. printAtMiddle(pom,pos.x+70,pos.y+237,GEOR16,zwykly,screen);
  2798. itoa(a2,pom,10);
  2799. printAtMiddle(pom,pos.x+233,pos.y+237,GEOR16,zwykly,screen);
  2800. anim->blitPic(screen,pos.x+20,pos.y+54,false);
  2801. anim->blitPic(screen,pos.x+177,pos.y+54,false);
  2802. }
  2803. void CSplitWindow::keyPressed (SDL_KeyboardEvent & key)
  2804. {
  2805. //TODO: make manual typing possible
  2806. }
  2807. void CCreInfoWindow::show(SDL_Surface * to)
  2808. {
  2809. char pom[15];
  2810. blitAt(bitmap,pos.x,pos.y,screen);
  2811. anim->blitPic(screen,pos.x+21,pos.y+48,(type) && anf);
  2812. anf=!anf;
  2813. if(upgrade)
  2814. upgrade->show();
  2815. if(dismiss)
  2816. dismiss->show();
  2817. if(ok)
  2818. ok->show();
  2819. }
  2820. CCreInfoWindow::CCreInfoWindow
  2821. (int Cid, int Type, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm)
  2822. :ok(0),dismiss(0),upgrade(0),type(Type),dsm(Dsm)
  2823. {
  2824. c = &CGI->creh->creatures[Cid];
  2825. bitmap = CGI->bitmaph->loadBitmap("CRSTKPU.bmp");
  2826. pos.x = screen->w/2 - bitmap->w/2;
  2827. pos.y = screen->h/2 - bitmap->h/2;
  2828. pos.w = bitmap->w;
  2829. pos.h = bitmap->h;
  2830. blueToPlayersAdv(bitmap,LOCPLINT->playerID);
  2831. SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
  2832. anim = new CCreaturePic(c);
  2833. if(!type) anim->anim->setType(1);
  2834. char pom[25];int hlp=0;
  2835. printAtMiddle(c->namePl,149,30,GEOR13,zwykly,bitmap); //creature name
  2836. //atttack
  2837. printAt(CGI->preth->zelp[435].first,155,48,GEOR13,zwykly,bitmap);
  2838. itoa(c->attack,pom,10);
  2839. if(State && State->attackBonus)
  2840. {
  2841. int hlp = log10f(c->attack)+2;
  2842. pom[hlp-1] = ' '; pom[hlp] = '(';
  2843. itoa(c->attack+State->attackBonus,pom+hlp+1,10);
  2844. hlp += 2+(int)log10f(State->attackBonus+c->attack);
  2845. pom[hlp] = ')'; pom[hlp+1] = '\0';
  2846. }
  2847. printToWR(pom,276,61,GEOR13,zwykly,bitmap);
  2848. //defense
  2849. printAt(CGI->preth->zelp[436].first,155,67,GEOR13,zwykly,bitmap);
  2850. itoa(c->defence,pom,10);
  2851. if(State && State->defenseBonus)
  2852. {
  2853. int hlp = log10f(c->defence)+2;
  2854. pom[hlp-1] = ' '; pom[hlp] = '(';
  2855. itoa(c->defence+State->defenseBonus,pom+hlp+1,10);
  2856. pom[hlp+2+(int)log10f(State->defenseBonus+c->defence)] = ')';
  2857. }
  2858. printToWR(pom,276,80,GEOR13,zwykly,bitmap);
  2859. //shots
  2860. if(c->shots)
  2861. {
  2862. printAt(CGI->generaltexth->allTexts[198],155,86,GEOR13,zwykly,bitmap);
  2863. itoa(c->shots,pom,10);
  2864. printToWR(pom,276,99,GEOR13,zwykly,bitmap);
  2865. }
  2866. //damage
  2867. printAt(CGI->generaltexth->allTexts[199],155,105,GEOR13,zwykly,bitmap);
  2868. itoa(c->damageMin,pom,10);
  2869. hlp=log10f(c->damageMin)+2;
  2870. pom[hlp-1]=' '; pom[hlp]='-'; pom[hlp+1]=' ';
  2871. itoa(c->damageMax,pom+hlp+2,10);
  2872. printToWR(pom,276,118,GEOR13,zwykly,bitmap);
  2873. //health
  2874. printAt(CGI->preth->zelp[439].first,155,124,GEOR13,zwykly,bitmap);
  2875. itoa(c->hitPoints,pom,10);
  2876. printToWR(pom,276,137,GEOR13,zwykly,bitmap);
  2877. //remaining health - TODO: show during the battles
  2878. //printAt(CGI->preth->zelp[440].first,155,143,GEOR13,zwykly,bitmap);
  2879. //speed
  2880. printAt(CGI->preth->zelp[441].first,155,162,GEOR13,zwykly,bitmap);
  2881. itoa(c->speed,pom,10);
  2882. printToWR(pom,276,175,GEOR13,zwykly,bitmap);
  2883. //luck and morale
  2884. blitAt(LOCPLINT->morale42->ourImages[(State)?(State->morale+3):(3)].bitmap,24,189,bitmap);
  2885. blitAt(LOCPLINT->luck42->ourImages[(State)?(State->luck+3):(3)].bitmap,77,189,bitmap);
  2886. //print abilities text - if r-click popup
  2887. if(type)
  2888. {
  2889. if(Upg)
  2890. upgrade = new AdventureMapButton("",CGI->preth->zelp[446].second,Upg,pos.x+76,pos.y+237,"IVIEWCR.DEF");
  2891. if(Dsm)
  2892. dismiss = new AdventureMapButton("",CGI->preth->zelp[445].second,boost::bind(&CCreInfoWindow::dismissF,this),pos.x+21,pos.y+237,"IVIEWCR2.DEF");
  2893. ok = new AdventureMapButton("",CGI->preth->zelp[445].second,boost::bind(&CCreInfoWindow::close,this),pos.x+216,pos.y+237,"IOKAY.DEF");
  2894. }
  2895. else
  2896. {
  2897. printAtWB(c->abilityText,17,231,GEOR13,35,zwykly,bitmap);
  2898. }
  2899. }
  2900. CCreInfoWindow::~CCreInfoWindow()
  2901. {
  2902. SDL_FreeSurface(bitmap);
  2903. delete anim;
  2904. delete upgrade;
  2905. delete ok;
  2906. delete dismiss;
  2907. }
  2908. void CCreInfoWindow::activate()
  2909. {
  2910. if(!type)
  2911. ClickableR::activate();
  2912. LOCPLINT->objsToBlit.push_back(this);
  2913. if(ok)
  2914. ok->activate();
  2915. if(dismiss)
  2916. dismiss->activate();
  2917. if(upgrade)
  2918. upgrade->activate();
  2919. if(type)
  2920. LOCPLINT->curint->deactivate();
  2921. }
  2922. void CCreInfoWindow::close()
  2923. {
  2924. deactivate();
  2925. CCastleInterface *c = dynamic_cast<CCastleInterface*>(LOCPLINT->curint);
  2926. if(c) c->showAll();
  2927. if(type)
  2928. LOCPLINT->curint->activate();
  2929. delete this;
  2930. }
  2931. void CCreInfoWindow::clickRight(boost::logic::tribool down)
  2932. {
  2933. if(down)
  2934. return;
  2935. close();
  2936. }
  2937. void CCreInfoWindow::dismissF()
  2938. {
  2939. dsm();
  2940. close();
  2941. }
  2942. void CCreInfoWindow::keyPressed (SDL_KeyboardEvent & key)
  2943. {
  2944. }
  2945. void CCreInfoWindow::deactivate()
  2946. {
  2947. if(!type)
  2948. ClickableR::deactivate();
  2949. LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
  2950. if(ok)
  2951. ok->deactivate();
  2952. if(dismiss)
  2953. dismiss->deactivate();
  2954. if(upgrade)
  2955. upgrade->deactivate();
  2956. }