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/CHeroHandler.h"
  16. #include "hch/CTownHandler.h"
  17. #include "SDL_framerate.h"
  18. #include "hch/CGeneralTextHandler.h"
  19. #include "CCastleInterface.h"
  20. #include "CHeroWindow.h"
  21. #include "timeHandler.h"
  22. #include <boost/algorithm/string.hpp>
  23. #include <boost/algorithm/string/replace.hpp>
  24. #include "hch\CPreGameTextHandler.h"
  25. #include "CBattleInterface.h"
  26. #include "CLua.h"
  27. #include <cmath>
  28. using namespace CSDL_Ext;
  29. extern TTF_Font * GEOR16;
  30. extern bool continueReadingConsole;
  31. class OCM_HLP_CGIN
  32. {
  33. public:
  34. bool operator ()(const std::pair<CGObjectInstance*,SDL_Rect> & a, const std::pair<CGObjectInstance*,SDL_Rect> & b) const
  35. {
  36. return (*a.first)<(*b.first);
  37. }
  38. } ocmptwo_cgin ;
  39. void CGarrisonSlot::hover (bool on)
  40. {
  41. Hoverable::hover(on);
  42. if(on)
  43. {
  44. std::string temp;
  45. if(creature)
  46. {
  47. if(owner->highlighted)
  48. {
  49. if(owner->highlighted == this)
  50. {
  51. temp = CGI->townh->tcommands[4];
  52. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  53. }
  54. else if (owner->highlighted->creature == creature)
  55. {
  56. temp = CGI->townh->tcommands[2];
  57. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  58. }
  59. else if (owner->highlighted->creature)
  60. {
  61. temp = CGI->townh->tcommands[7];
  62. boost::algorithm::replace_first(temp,"%s",owner->highlighted->creature->nameSing);
  63. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  64. }
  65. else
  66. {
  67. std::cout << "Warning - shouldn't be - highlighted void slot "<<owner->highlighted<<std::endl;
  68. std::cout << "Highlighted set to NULL"<<std::endl;
  69. owner->highlighted = NULL;
  70. }
  71. }
  72. else
  73. {
  74. if(upg)
  75. {
  76. temp = CGI->townh->tcommands[32];
  77. }
  78. else
  79. {
  80. temp = CGI->townh->tcommands[12];
  81. }
  82. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  83. };
  84. }
  85. else
  86. {
  87. if(owner->highlighted)
  88. {
  89. temp = CGI->townh->tcommands[6];
  90. boost::algorithm::replace_first(temp,"%s",owner->highlighted->creature->nameSing);
  91. }
  92. else
  93. {
  94. temp = CGI->townh->tcommands[11];
  95. }
  96. }
  97. LOCPLINT->statusbar->print(temp);
  98. }
  99. else
  100. {
  101. LOCPLINT->statusbar->clear();
  102. }
  103. }
  104. const CArmedInstance * CGarrisonSlot::getObj()
  105. {
  106. return (!upg)?(owner->oup):(owner->odown);
  107. }
  108. void CGarrisonSlot::clickRight (tribool down)
  109. {
  110. StackState *pom = NULL;
  111. if(down && creature)
  112. {
  113. if(getObj()->ID == 34)
  114. {
  115. pom = new StackState();
  116. const CGHeroInstance *h = static_cast<const CGHeroInstance *>(getObj());
  117. pom->attackBonus = h->primSkills[0];
  118. pom->defenseBonus = h->primSkills[1];
  119. pom->luck = h->getCurrentLuck();
  120. pom->morale = h->getCurrentMorale();
  121. }
  122. (new CCreInfoWindow(creature->idNumber,0,pom,boost::function<void()>(),boost::function<void()>()))
  123. ->activate();
  124. }
  125. delete pom;
  126. }
  127. void CGarrisonSlot::clickLeft(tribool down)
  128. {
  129. if(owner->ignoreEvent)
  130. {
  131. owner->ignoreEvent = false;
  132. return;
  133. }
  134. if(down)
  135. {
  136. bool refr = false;
  137. if(owner->highlighted)
  138. {
  139. if(owner->highlighted == this) //view info
  140. {
  141. UpgradeInfo pom = LOCPLINT->cb->getUpgradeInfo(getObj(),ID);
  142. (new CCreInfoWindow
  143. (creature->idNumber,1,NULL,
  144. (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
  145. boost::bind(&CCallback::dismissCreature,LOCPLINT->cb,getObj(),ID)))
  146. ->activate();
  147. owner->highlighted = NULL;
  148. show();
  149. refr = true;
  150. }
  151. else if( !creature && owner->splitting)//split
  152. {
  153. owner->p2 = ID;
  154. owner->pb = upg;
  155. owner->splitting = false;
  156. LOCPLINT->curint->deactivate();
  157. CSplitWindow * spw = new CSplitWindow(owner->highlighted->creature->idNumber,owner->highlighted->count, owner);
  158. spw->activate();
  159. refr = true;
  160. }
  161. else if(creature != owner->highlighted->creature) //swap
  162. {
  163. LOCPLINT->cb->swapCreatures(
  164. (!upg)?(owner->oup):(owner->odown),
  165. (!owner->highlighted->upg)?(owner->oup):(owner->odown),
  166. ID,owner->highlighted->ID);
  167. }
  168. else //merge
  169. {
  170. LOCPLINT->cb->mergeStacks(
  171. (!owner->highlighted->upg)?(owner->oup):(owner->odown),
  172. (!upg)?(owner->oup):(owner->odown),
  173. owner->highlighted->ID,ID);
  174. }
  175. }
  176. else //highlight
  177. {
  178. if(creature)
  179. owner->highlighted = this;
  180. show();
  181. refr = true;
  182. }
  183. if(refr) {hover(false); hover(true); } //to refresh statusbar
  184. }
  185. }
  186. void CGarrisonSlot::activate()
  187. {
  188. if(!active) active=true;
  189. else return;
  190. ClickableL::activate();
  191. ClickableR::activate();
  192. Hoverable::activate();
  193. }
  194. void CGarrisonSlot::deactivate()
  195. {
  196. if(active) active=false;
  197. else return;
  198. ClickableL::deactivate();
  199. ClickableR::deactivate();
  200. Hoverable::deactivate();
  201. }
  202. CGarrisonSlot::CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg, const CCreature * Creature, int Count)
  203. {
  204. active = false;
  205. upg = Upg;
  206. count = Count;
  207. ID = IID;
  208. creature = Creature;
  209. pos.x = x;
  210. pos.y = y;
  211. pos.w = 58;
  212. pos.h = 64;
  213. owner = Owner;
  214. }
  215. CGarrisonSlot::~CGarrisonSlot()
  216. {
  217. if(active)
  218. deactivate();
  219. }
  220. void CGarrisonSlot::show()
  221. {
  222. if(creature)
  223. {
  224. char* buf = new char[15];
  225. itoa(count,buf,10);
  226. blitAt(CGI->creh->bigImgs[creature->idNumber],pos);
  227. printTo(buf,pos.x+56,pos.y+62,GEOR16,zwykly);
  228. if(owner->highlighted==this)
  229. blitAt(CGI->creh->bigImgs[-1],pos);
  230. if(owner->update)
  231. updateRect(&pos,screen);
  232. delete [] buf;
  233. }
  234. else
  235. {
  236. SDL_Rect jakis1 = genRect(pos.h,pos.w,owner->offx+ID*(pos.w+owner->interx),owner->offy+upg*(pos.h+owner->intery)), jakis2 = pos;
  237. SDL_BlitSurface(owner->sur,&jakis1,screen,&jakis2);
  238. if(owner->splitting)
  239. blitAt(CGI->creh->bigImgs[-1],pos);
  240. if(owner->update)
  241. SDL_UpdateRect(screen,pos.x,pos.y,pos.w,pos.h);
  242. }
  243. }
  244. CGarrisonInt::~CGarrisonInt()
  245. {
  246. if(sup)
  247. {
  248. for(int i=0;i<sup->size();i++)
  249. delete (*sup)[i];
  250. delete sup;
  251. }
  252. if(sdown)
  253. {
  254. for(int i=0;i<sdown->size();i++)
  255. delete (*sdown)[i];
  256. delete sdown;
  257. }
  258. }
  259. void CGarrisonInt::show()
  260. {
  261. if(sup)
  262. {
  263. for(int i = 0; i<sup->size(); i++)
  264. if((*sup)[i])
  265. (*sup)[i]->show();
  266. }
  267. if(sdown)
  268. {
  269. for(int i = 0; i<sdown->size(); i++)
  270. if((*sdown)[i])
  271. (*sdown)[i]->show();
  272. }
  273. }
  274. void CGarrisonInt::deactiveteSlots()
  275. {
  276. if(sup)
  277. {
  278. for(int i = 0; i<sup->size(); i++)
  279. {
  280. if((*sup)[i])
  281. {
  282. (*sup)[i]->deactivate();
  283. }
  284. }
  285. }
  286. if(sdown)
  287. {
  288. for(int i = 0; i<sdown->size(); i++)
  289. {
  290. if((*sdown)[i])
  291. {
  292. (*sdown)[i]->deactivate();
  293. }
  294. }
  295. }
  296. }
  297. void CGarrisonInt::activeteSlots()
  298. {
  299. if(sup)
  300. {
  301. for(int i = 0; i<sup->size(); i++)
  302. {
  303. if((*sup)[i])
  304. {
  305. (*sup)[i]->activate();
  306. }
  307. }
  308. }
  309. if(sdown)
  310. {
  311. for(int i = 0; i<sdown->size(); i++)
  312. {
  313. if((*sdown)[i])
  314. {
  315. (*sdown)[i]->activate();
  316. }
  317. }
  318. }
  319. }
  320. void CGarrisonInt::createSlots()
  321. {
  322. if(set1)
  323. {
  324. sup = new std::vector<CGarrisonSlot*>(7,(CGarrisonSlot *)(NULL));
  325. for
  326. (std::map<int,std::pair<CCreature*,int> >::const_iterator i=set1->slots.begin();
  327. i!=set1->slots.end(); i++)
  328. {
  329. (*sup)[i->first] =
  330. new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y,i->first, 0, i->second.first,i->second.second);
  331. }
  332. for(int i=0; i<sup->size(); i++)
  333. if((*sup)[i] == NULL)
  334. (*sup)[i] = new CGarrisonSlot(this, pos.x + (i*(58+interx)), pos.y,i,0,NULL, 0);
  335. }
  336. if(set2)
  337. {
  338. sdown = new std::vector<CGarrisonSlot*>(7,(CGarrisonSlot *)(NULL));
  339. for
  340. (std::map<int,std::pair<CCreature*,int> >::const_iterator i=set2->slots.begin();
  341. i!=set2->slots.end(); i++)
  342. {
  343. (*sdown)[i->first] =
  344. new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y + 64 + intery,i->first,1, i->second.first,i->second.second);
  345. }
  346. for(int i=0; i<sup->size(); i++)
  347. if((*sdown)[i] == NULL)
  348. (*sdown)[i] = new CGarrisonSlot(this, pos.x + (i*(58+interx)), pos.y + 64 + intery,i,1, NULL, 0);
  349. }
  350. }
  351. void CGarrisonInt::deleteSlots()
  352. {
  353. if(sup)
  354. {
  355. for(int i = 0; i<sup->size(); i++)
  356. {
  357. if((*sup)[i])
  358. {
  359. delete (*sup)[i];
  360. }
  361. }
  362. }
  363. if(sdown)
  364. {
  365. for(int i = 0; i<sdown->size(); i++)
  366. {
  367. if((*sdown)[i])
  368. {
  369. delete (*sdown)[i];
  370. }
  371. }
  372. }
  373. }
  374. void CGarrisonInt::recreateSlots()
  375. {
  376. splitting = false;
  377. highlighted = NULL;
  378. deactiveteSlots();
  379. deleteSlots();
  380. createSlots();
  381. ignoreEvent = true;
  382. activeteSlots();
  383. show();
  384. }
  385. void CGarrisonInt::splitClick()
  386. {
  387. if(!highlighted)
  388. return;
  389. splitting = !splitting;
  390. show();
  391. }
  392. void CGarrisonInt::splitStacks(int am2)
  393. {
  394. LOCPLINT->cb->splitStack(
  395. (highlighted->upg)?(odown):(oup),
  396. (pb)?(odown):(oup),
  397. highlighted->ID,
  398. p2,
  399. am2);
  400. }
  401. CGarrisonInt::CGarrisonInt(int x, int y, int inx, int iny, SDL_Surface *pomsur, int OX, int OY, const CArmedInstance *s1, const CArmedInstance *s2)
  402. :interx(inx),intery(iny),sur(pomsur),highlighted(NULL),sup(NULL),sdown(NULL),oup(s1),odown(s2),
  403. offx(OX),offy(OY)
  404. {
  405. splitting = false;
  406. set1 = LOCPLINT->cb->getGarrison(s1);
  407. set2 = LOCPLINT->cb->getGarrison(s2);
  408. ignoreEvent = false;
  409. update = true;
  410. pos.x=(x);
  411. pos.y=(y);
  412. pos.w=(58);
  413. pos.h=(64);
  414. createSlots();
  415. }
  416. void CGarrisonInt::activate()
  417. {
  418. if(sup)
  419. {
  420. for(int i = 0; i<sup->size(); i++)
  421. if((*sup)[i])
  422. (*sup)[i]->activate();
  423. }
  424. if(sdown)
  425. {
  426. for(int i = 0; i<sdown->size(); i++)
  427. if((*sdown)[i])
  428. (*sdown)[i]->activate();
  429. }
  430. }
  431. void CGarrisonInt::deactivate()
  432. {
  433. deactiveteSlots();
  434. }
  435. CInfoWindow::CInfoWindow()
  436. :okb(NMessage::ok,NULL,&CInfoWindow::okClicked)
  437. {
  438. okb.ourObj = this;
  439. okb.delg = this;
  440. okb.notFreeButton=true;
  441. }
  442. void CInfoWindow::okClicked(tribool down)
  443. {
  444. if (!down)
  445. close();
  446. }
  447. void CInfoWindow::close()
  448. {
  449. for (int i=0;i<components.size();i++)
  450. {
  451. components[i]->deactivate();
  452. delete components[i];
  453. }
  454. components.clear();
  455. okb.deactivate();
  456. SDL_FreeSurface(bitmap);
  457. bitmap = NULL;
  458. LOCPLINT->removeObjToBlit(this);
  459. LOCPLINT->curint->activate();
  460. delete this;
  461. }
  462. CInfoWindow::~CInfoWindow()
  463. {
  464. }
  465. void CRClickPopup::clickRight (tribool down)
  466. {
  467. if(down)
  468. return;
  469. close();
  470. }
  471. void CRClickPopup::activate()
  472. {
  473. ClickableR::activate();
  474. LOCPLINT->objsToBlit.push_back(this);
  475. }
  476. void CRClickPopup::deactivate()
  477. {
  478. ClickableR::deactivate();
  479. LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
  480. }
  481. CInfoPopup::CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free)
  482. :bitmap(Bitmap),free(Free)
  483. {
  484. pos.x = x;
  485. pos.y = y;
  486. pos.h = bitmap->h;
  487. pos.w = bitmap->w;
  488. }
  489. void CInfoPopup::close()
  490. {
  491. deactivate();
  492. if(free)
  493. SDL_FreeSurface(bitmap);
  494. delete this;
  495. if(LOCPLINT->curint == LOCPLINT->adventureInt)
  496. LOCPLINT->adventureInt->show();
  497. else if(LOCPLINT->curint == LOCPLINT->castleInt)
  498. LOCPLINT->castleInt->showAll();
  499. }
  500. void CInfoPopup::show(SDL_Surface * to)
  501. {
  502. blitAt(bitmap,pos.x,pos.y,(to)?(to):(screen));
  503. }
  504. SComponent::SComponent(Etype Type, int Subtype, int Val)
  505. {
  506. std::ostringstream oss;
  507. switch (Type)
  508. {
  509. case primskill:
  510. description = CGI->generaltexth->arraytxt[2+Subtype];
  511. oss << ((Val>0)?("+"):("-")) << Val << " " << CGI->heroh->pskillsn[Subtype];
  512. subtitle = oss.str();
  513. break;
  514. case resource:
  515. description = CGI->generaltexth->allTexts[242];
  516. oss << Val;
  517. subtitle = oss.str();
  518. break;
  519. case experience:
  520. description = CGI->generaltexth->allTexts[241];
  521. oss << Val ;
  522. subtitle = oss.str();
  523. break;
  524. }
  525. type = Type;
  526. subtype = Subtype;
  527. val = Val;
  528. SDL_Surface * temp = getImg();
  529. pos.w = temp->w;
  530. pos.h = temp->h;
  531. }
  532. SDL_Surface * SComponent::getImg()
  533. {
  534. switch (type)
  535. {
  536. case primskill:
  537. return CGI->heroh->pskillsb->ourImages[subtype].bitmap;
  538. break;
  539. case secskill:
  540. return CGI->abilh->abils82->ourImages[subtype*3 + 3 + val].bitmap;
  541. break;
  542. case resource:
  543. return CGI->heroh->resources->ourImages[subtype].bitmap;
  544. break;
  545. case experience:
  546. return CGI->heroh->pskillsb->ourImages[4].bitmap;
  547. break;
  548. }
  549. return NULL;
  550. }
  551. void SComponent::clickRight (tribool down)
  552. {
  553. LOCPLINT->adventureInt->handleRightClick(description,down,this);
  554. }
  555. void SComponent::activate()
  556. {
  557. ClickableR::activate();
  558. }
  559. void SComponent::deactivate()
  560. {
  561. ClickableR::deactivate();
  562. }
  563. void CSelectableComponent::clickLeft(tribool down)
  564. {
  565. if (down)
  566. {
  567. select(true);
  568. owner->selectionChange(this);
  569. }
  570. }
  571. CSelectableComponent::CSelectableComponent(Etype Type, int Sub, int Val, CSelWindow * Owner, SDL_Surface * Border)
  572. :SComponent(Type,Sub,Val),owner(Owner)
  573. {
  574. SDL_Surface * symb = SComponent::getImg();
  575. myBitmap = CSDL_Ext::newSurface(symb->w+2,symb->h+2,screen);
  576. SDL_SetColorKey(myBitmap,SDL_SRCCOLORKEY,SDL_MapRGB(myBitmap->format,0,255,255));
  577. blitAt(symb,1,1,myBitmap);
  578. if (Border) //use custom border
  579. {
  580. border = Border;
  581. customB = true;
  582. }
  583. else //we need to draw border
  584. {
  585. customB = false;
  586. border = CSDL_Ext::newSurface(symb->w+2,symb->h+2,screen);
  587. SDL_FillRect(border,NULL,0x00FFFF);
  588. for (int i=0;i<border->w;i++)
  589. {
  590. SDL_PutPixel(border,i,0,239,215,123);
  591. SDL_PutPixel(border,i,(border->h)-1,239,215,123);
  592. }
  593. for (int i=0;i<border->h;i++)
  594. {
  595. SDL_PutPixel(border,0,i,239,215,123);
  596. SDL_PutPixel(border,(border->w)-1,i,239,215,123);
  597. }
  598. SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255));
  599. }
  600. selected = false;
  601. }
  602. CSelectableComponent::~CSelectableComponent()
  603. {
  604. SDL_FreeSurface(myBitmap);
  605. if (!customB)
  606. SDL_FreeSurface(border);
  607. }
  608. void CSelectableComponent::activate()
  609. {
  610. SComponent::activate();
  611. ClickableL::activate();
  612. }
  613. void CSelectableComponent::deactivate()
  614. {
  615. SComponent::deactivate();
  616. ClickableL::deactivate();
  617. }
  618. SDL_Surface * CSelectableComponent::getImg()
  619. {
  620. return myBitmap;
  621. }
  622. void CSelectableComponent::select(bool on)
  623. {
  624. if(on != selected)
  625. {
  626. SDL_FillRect(myBitmap,NULL,0x000000);
  627. blitAt(SComponent::getImg(),1,1,myBitmap);
  628. if (on)
  629. {
  630. blitAt(border,0,0,myBitmap);
  631. }
  632. selected = on;
  633. return;
  634. }
  635. else
  636. {
  637. return;
  638. }
  639. }
  640. void CSimpleWindow::show(SDL_Surface * to)
  641. {
  642. if(!to)
  643. to=screen;
  644. blitAt(bitmap,pos.x,pos.y,to);
  645. }
  646. CSimpleWindow::~CSimpleWindow()
  647. {
  648. if (bitmap)
  649. {
  650. SDL_FreeSurface(bitmap);
  651. bitmap=NULL;
  652. }
  653. }
  654. void CSelWindow::selectionChange(CSelectableComponent * to)
  655. {
  656. blitAt(to->getImg(),to->pos.x-pos.x,to->pos.y-pos.y,bitmap);
  657. for (int i=0;i<components.size();i++)
  658. {
  659. if(components[i]==to)
  660. {
  661. if (to->selected)
  662. continue;
  663. else
  664. to->select(true);
  665. }
  666. CSelectableComponent * pom = dynamic_cast<CSelectableComponent*>(components[i]);
  667. if (!pom)
  668. continue;
  669. pom->select(false);
  670. blitAt(pom->getImg(),pom->pos.x-pos.x,pom->pos.y-pos.y,bitmap);
  671. }
  672. }
  673. void CSelWindow::okClicked(tribool down)
  674. {
  675. if(!down)
  676. close();
  677. }
  678. void CSelWindow::close()
  679. {
  680. int ret = -1;
  681. for (int i=0;i<components.size();i++)
  682. {
  683. if(dynamic_cast<CSelectableComponent*>(components[i])->selected)
  684. {
  685. ret = i;
  686. }
  687. components[i]->deactivate();
  688. }
  689. components.clear();
  690. okb.deactivate();
  691. SDL_FreeSurface(bitmap);
  692. bitmap = NULL;
  693. LOCPLINT->removeObjToBlit(this);
  694. LOCPLINT->curint->activate();
  695. LOCPLINT->cb->selectionMade(ret,ID);
  696. delete this;
  697. //call owner with selection result
  698. }
  699. template <typename T>CSCButton<T>::CSCButton(CDefHandler * img, CIntObject * obj, void(T::*poin)(tribool), T* Delg)
  700. {
  701. ourObj = obj;
  702. delg = Delg;
  703. func = poin;
  704. imgs.resize(1);
  705. for (int i =0; i<img->ourImages.size();i++)
  706. {
  707. imgs[0].push_back(img->ourImages[i].bitmap);
  708. }
  709. pos.w = imgs[0][0]->w;
  710. pos.h = imgs[0][0]->h;
  711. state = 0;
  712. }
  713. template <typename T> void CSCButton<T>::clickLeft (tribool down)
  714. {
  715. if (down)
  716. {
  717. state=1;
  718. }
  719. else
  720. {
  721. state=0;
  722. }
  723. pressedL=state;
  724. show();
  725. if (delg)
  726. (delg->*func)(down);
  727. }
  728. template <typename T> void CSCButton<typename T>::activate()
  729. {
  730. ClickableL::activate();
  731. }
  732. template <typename T> void CSCButton<typename T>::deactivate()
  733. {
  734. ClickableL::deactivate();
  735. }
  736. template <typename T> void CSCButton<typename T>::show(SDL_Surface * to)
  737. {
  738. if (delg) //we blit on our owner's bitmap
  739. {
  740. blitAt(imgs[curimg][state],posr.x,posr.y,delg->bitmap);
  741. //updateRect(&genRect(pos.h,pos.w,posr.x,posr.y),delg->bitmap);
  742. }
  743. else
  744. {
  745. CButtonBase::show(to);
  746. }
  747. }
  748. CButtonBase::CButtonBase()
  749. {
  750. bitmapOffset = 0;
  751. curimg=0;
  752. type=-1;
  753. abs=false;
  754. active=false;
  755. notFreeButton = false;
  756. ourObj=NULL;
  757. state=0;
  758. }
  759. CButtonBase::~CButtonBase()
  760. {
  761. if(notFreeButton)
  762. return;
  763. for(int i =0; i<imgs.size();i++)
  764. for(int j=0;j<imgs[i].size();j++)
  765. SDL_FreeSurface(imgs[i][j]);
  766. }
  767. void CButtonBase::show(SDL_Surface * to)
  768. {
  769. if(!to)
  770. to=screen;
  771. if (abs)
  772. {
  773. blitAt(imgs[curimg]
  774. [( (state+bitmapOffset) < (imgs[curimg].size()) ) ?
  775. (state+bitmapOffset) :
  776. (imgs[curimg].size()-1) ]
  777. ,pos.x,pos.y,to);
  778. //updateRect(&pos,to);
  779. }
  780. else
  781. {
  782. blitAt(imgs[curimg]
  783. [( (state+bitmapOffset) < (imgs[curimg].size()) ) ?
  784. (state+bitmapOffset) :
  785. (imgs[curimg].size()-1) ],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y,to);
  786. //updateRect(&genRect(pos.h,pos.w,pos.x+ourObj->pos.x,pos.y+ourObj->pos.y),to);
  787. }
  788. }
  789. ClickableL::ClickableL()
  790. {
  791. pressedL=false;
  792. }
  793. void ClickableL::clickLeft(tribool down)
  794. {
  795. if (down)
  796. pressedL=true;
  797. else
  798. pressedL=false;
  799. }
  800. void ClickableL::activate()
  801. {
  802. LOCPLINT->lclickable.push_back(this);
  803. }
  804. void ClickableL::deactivate()
  805. {
  806. LOCPLINT->lclickable.erase
  807. (std::find(LOCPLINT->lclickable.begin(),LOCPLINT->lclickable.end(),this));
  808. }
  809. ClickableR::ClickableR()
  810. {
  811. pressedR=false;
  812. }
  813. void ClickableR::clickRight(tribool down)
  814. {
  815. if (down)
  816. pressedR=true;
  817. else
  818. pressedR=false;
  819. }
  820. void ClickableR::activate()
  821. {
  822. LOCPLINT->rclickable.push_back(this);
  823. }
  824. void ClickableR::deactivate()
  825. {
  826. LOCPLINT->rclickable.erase(std::find(LOCPLINT->rclickable.begin(),LOCPLINT->rclickable.end(),this));
  827. }
  828. void Hoverable::activate()
  829. {
  830. LOCPLINT->hoverable.push_back(this);
  831. }
  832. void Hoverable::deactivate()
  833. {
  834. LOCPLINT->hoverable.erase(std::find(LOCPLINT->hoverable.begin(),LOCPLINT->hoverable.end(),this));
  835. }
  836. void Hoverable::hover(bool on)
  837. {
  838. hovered=on;
  839. }
  840. void KeyInterested::activate()
  841. {
  842. LOCPLINT->keyinterested.push_back(this);
  843. }
  844. void KeyInterested::deactivate()
  845. {
  846. LOCPLINT->
  847. keyinterested.erase(std::find(LOCPLINT->keyinterested.begin(),LOCPLINT->keyinterested.end(),this));
  848. }
  849. void MotionInterested::activate()
  850. {
  851. LOCPLINT->motioninterested.push_back(this);
  852. }
  853. void MotionInterested::deactivate()
  854. {
  855. LOCPLINT->
  856. motioninterested.erase(std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this));
  857. }
  858. void TimeInterested::activate()
  859. {
  860. LOCPLINT->timeinterested.push_back(this);
  861. }
  862. void TimeInterested::deactivate()
  863. {
  864. LOCPLINT->
  865. timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),this));
  866. }
  867. CPlayerInterface::CPlayerInterface(int Player, int serial)
  868. {
  869. playerID=Player;
  870. serialID=serial;
  871. CGI->localPlayer = playerID;
  872. human=true;
  873. hInfo = CGI->bitmaph->loadBitmap("HEROQVBK.bmp");
  874. SDL_SetColorKey(hInfo,SDL_SRCCOLORKEY,SDL_MapRGB(hInfo->format,0,255,255));
  875. tInfo = CGI->bitmaph->loadBitmap("TOWNQVBK.bmp");
  876. SDL_SetColorKey(tInfo,SDL_SRCCOLORKEY,SDL_MapRGB(tInfo->format,0,255,255));
  877. slotsPos.push_back(std::pair<int,int>(44,82));
  878. slotsPos.push_back(std::pair<int,int>(80,82));
  879. slotsPos.push_back(std::pair<int,int>(116,82));
  880. slotsPos.push_back(std::pair<int,int>(26,131));
  881. slotsPos.push_back(std::pair<int,int>(62,131));
  882. slotsPos.push_back(std::pair<int,int>(98,131));
  883. slotsPos.push_back(std::pair<int,int>(134,131));
  884. luck22 = CGI->spriteh->giveDefEss("ILCK22.DEF");
  885. luck30 = CGI->spriteh->giveDefEss("ILCK30.DEF");
  886. luck42 = CGI->spriteh->giveDefEss("ILCK42.DEF");
  887. luck82 = CGI->spriteh->giveDefEss("ILCK82.DEF");
  888. morale22 = CGI->spriteh->giveDefEss("IMRL22.DEF");
  889. morale30 = CGI->spriteh->giveDefEss("IMRL30.DEF");
  890. morale42 = CGI->spriteh->giveDefEss("IMRL42.DEF");
  891. morale82 = CGI->spriteh->giveDefEss("IMRL82.DEF");
  892. halls = CGI->spriteh->giveDefEss("ITMTLS.DEF");
  893. forts = CGI->spriteh->giveDefEss("ITMCLS.DEF");
  894. bigTownPic = CGI->spriteh->giveDefEss("ITPT.DEF");
  895. }
  896. void CPlayerInterface::init(ICallback * CB)
  897. {
  898. cb = dynamic_cast<CCallback*>(CB);
  899. CGI->localPlayer = serialID;
  900. adventureInt = new CAdvMapInt(playerID);
  901. castleInt = NULL;
  902. std::vector <const CGHeroInstance *> hh = cb->getHeroesInfo(false);
  903. for(int i=0;i<hh.size();i++)
  904. {
  905. SDL_Surface * pom = infoWin(hh[i]);
  906. heroWins.insert(std::pair<int,SDL_Surface*>(hh[i]->subID,pom));
  907. }
  908. std::vector<const CGTownInstance*> tt = cb->getTownsInfo(false);
  909. for(int i=0;i<tt.size();i++)
  910. {
  911. SDL_Surface * pom = infoWin(tt[i]);
  912. townWins.insert(std::pair<int,SDL_Surface*>(tt[i]->identifier,pom));
  913. }
  914. }
  915. void CPlayerInterface::yourTurn()
  916. {
  917. makingTurn = true;
  918. CGI->localPlayer = serialID;
  919. unsigned char & animVal = LOCPLINT->adventureInt->anim; //for animations handling
  920. unsigned char & heroAnimVal = LOCPLINT->adventureInt->heroAnim;
  921. adventureInt->infoBar.newDay(cb->getDate(1));
  922. adventureInt->activate();
  923. //show rest of things
  924. //initializing framerate keeper
  925. mainFPSmng = new FPSmanager;
  926. SDL_initFramerate(mainFPSmng);
  927. SDL_setFramerate(mainFPSmng, 24);
  928. SDL_Event sEvent;
  929. //framerate keeper initialized
  930. timeHandler th;
  931. th.getDif();
  932. for(;makingTurn;) // main loop
  933. {
  934. //updating water tiles
  935. //int wnumber = -1;
  936. //for(int s=0; s<CGI->mh->reader->defs.size(); ++s)
  937. //{
  938. // if(CGI->mh->reader->defs[s]->defName==std::string("WATRTL.DEF"))
  939. // {
  940. // wnumber = s;
  941. // break;
  942. // }
  943. //}
  944. //if(wnumber>=0)
  945. //{
  946. // for(int g=0; g<CGI->mh->reader->defs[wnumber]->ourImages.size(); ++g)
  947. // {
  948. // SDL_Color tab[32];
  949. // for(int i=0; i<32; ++i)
  950. // {
  951. // tab[i] = CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap->format->palette->colors[160 + (i+1)%32];
  952. // }
  953. // //SDL_SaveBMP(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap,"t1.bmp");
  954. // for(int i=0; i<32; ++i)
  955. // {
  956. // CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap->format->palette->colors[160 + i] = tab[i];
  957. // }
  958. // //SDL_SaveBMP(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap,"t2.bmp");
  959. // CSDL_Ext::update(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap);
  960. // }
  961. //}
  962. //water tiles updated
  963. CGI->screenh->updateScreen();
  964. int tv = th.getDif();
  965. for (int i=0;i<timeinterested.size();i++)
  966. {
  967. if (timeinterested[i]->toNextTick>=0)
  968. timeinterested[i]->toNextTick-=tv;
  969. if (timeinterested[i]->toNextTick<0)
  970. timeinterested[i]->tick();
  971. }
  972. LOCPLINT->adventureInt->updateScreen = false;
  973. while (SDL_PollEvent(&sEvent)) //wait for event...
  974. {
  975. handleEvent(&sEvent);
  976. }
  977. if (!castleInt) //stuff for advMapInt
  978. {
  979. ++LOCPLINT->adventureInt->animValHitCount; //for animations
  980. if(LOCPLINT->adventureInt->animValHitCount == 4)
  981. {
  982. LOCPLINT->adventureInt->animValHitCount = 0;
  983. ++animVal;
  984. LOCPLINT->adventureInt->updateScreen = true;
  985. }
  986. ++heroAnimVal;
  987. if(LOCPLINT->adventureInt->scrollingLeft)
  988. {
  989. if(LOCPLINT->adventureInt->position.x>-Woff)
  990. {
  991. LOCPLINT->adventureInt->position.x--;
  992. LOCPLINT->adventureInt->updateScreen = true;
  993. adventureInt->updateMinimap=true;
  994. }
  995. }
  996. if(LOCPLINT->adventureInt->scrollingRight)
  997. {
  998. if(LOCPLINT->adventureInt->position.x<CGI->ac->map.width-19+4)
  999. {
  1000. LOCPLINT->adventureInt->position.x++;
  1001. LOCPLINT->adventureInt->updateScreen = true;
  1002. adventureInt->updateMinimap=true;
  1003. }
  1004. }
  1005. if(LOCPLINT->adventureInt->scrollingUp)
  1006. {
  1007. if(LOCPLINT->adventureInt->position.y>-Hoff)
  1008. {
  1009. LOCPLINT->adventureInt->position.y--;
  1010. LOCPLINT->adventureInt->updateScreen = true;
  1011. adventureInt->updateMinimap=true;
  1012. }
  1013. }
  1014. if(LOCPLINT->adventureInt->scrollingDown)
  1015. {
  1016. if(LOCPLINT->adventureInt->position.y<CGI->ac->map.height-18+4)
  1017. {
  1018. LOCPLINT->adventureInt->position.y++;
  1019. LOCPLINT->adventureInt->updateScreen = true;
  1020. adventureInt->updateMinimap=true;
  1021. }
  1022. }
  1023. if(LOCPLINT->adventureInt->updateScreen)
  1024. {
  1025. adventureInt->update();
  1026. adventureInt->updateScreen=false;
  1027. }
  1028. if (LOCPLINT->adventureInt->updateMinimap)
  1029. {
  1030. adventureInt->minimap.draw();
  1031. adventureInt->updateMinimap=false;
  1032. }
  1033. }
  1034. for(int i=0;i<objsToBlit.size();i++)
  1035. objsToBlit[i]->show();
  1036. //SDL_Flip(screen);
  1037. CSDL_Ext::update(screen);
  1038. SDL_Delay(5); //give time for other apps
  1039. SDL_framerateDelay(mainFPSmng);
  1040. }
  1041. adventureInt->hide();
  1042. }
  1043. inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, const int & hid)
  1044. {
  1045. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  1046. for(int h=0; h<hlp.objects.size(); ++h)
  1047. if(hlp.objects[h].first->id==hid)
  1048. {
  1049. hlp.objects[h].second = r;
  1050. return;
  1051. }
  1052. }
  1053. inline void delObjRect(const int & x, const int & y, const int & z, const int & hid)
  1054. {
  1055. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  1056. for(int h=0; h<hlp.objects.size(); ++h)
  1057. if(hlp.objects[h].first->id==hid)
  1058. {
  1059. hlp.objects.erase(hlp.objects.begin()+h);
  1060. return;
  1061. }
  1062. }
  1063. int getDir(int3 src, int3 dst)
  1064. {
  1065. int ret = -1;
  1066. if(dst.x+1 == src.x && dst.y+1 == src.y) //tl
  1067. {
  1068. ret = 1;
  1069. }
  1070. else if(dst.x == src.x && dst.y+1 == src.y) //t
  1071. {
  1072. ret = 2;
  1073. }
  1074. else if(dst.x-1 == src.x && dst.y+1 == src.y) //tr
  1075. {
  1076. ret = 3;
  1077. }
  1078. else if(dst.x-1 == src.x && dst.y == src.y) //r
  1079. {
  1080. ret = 4;
  1081. }
  1082. else if(dst.x-1 == src.x && dst.y-1 == src.y) //br
  1083. {
  1084. ret = 5;
  1085. }
  1086. else if(dst.x == src.x && dst.y-1 == src.y) //b
  1087. {
  1088. ret = 6;
  1089. }
  1090. else if(dst.x+1 == src.x && dst.y-1 == src.y) //bl
  1091. {
  1092. ret = 7;
  1093. }
  1094. else if(dst.x+1 == src.x && dst.y == src.y) //l
  1095. {
  1096. ret = 8;
  1097. }
  1098. return ret;
  1099. }
  1100. void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
  1101. {
  1102. //initializing objects and performing first step of move
  1103. CGHeroInstance * ho = details.ho; //object representing this hero
  1104. int3 hp = details.src;
  1105. if (!details.successful)
  1106. {
  1107. ho->moveDir = getDir(details.src,details.dst);
  1108. ho->isStanding = true;
  1109. adventureInt->heroList.draw();
  1110. if (adventureInt->terrain.currentPath)
  1111. {
  1112. delete adventureInt->terrain.currentPath;
  1113. adventureInt->terrain.currentPath = NULL;
  1114. }
  1115. return;
  1116. }
  1117. if (adventureInt->terrain.currentPath) //&& hero is moving
  1118. {
  1119. adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
  1120. }
  1121. int3 buff = details.ho->pos;
  1122. buff.x-=11;
  1123. buff.y-=9;
  1124. buff = repairScreenPos(buff);
  1125. LOCPLINT->adventureInt->position = buff; //actualizing screen pos
  1126. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  1127. {
  1128. ho->moveDir = 1;
  1129. ho->isStanding = false;
  1130. CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -31)));
  1131. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, -31)));
  1132. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, -31)));
  1133. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, -31)));
  1134. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 1)));
  1135. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 1), ho->id);
  1136. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 1), ho->id);
  1137. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 1), ho->id);
  1138. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 33)));
  1139. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 33), ho->id);
  1140. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 33), ho->id);
  1141. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 33), ho->id);
  1142. 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);
  1143. 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);
  1144. 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);
  1145. 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);
  1146. 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);
  1147. 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);
  1148. }
  1149. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  1150. {
  1151. ho->moveDir = 2;
  1152. ho->isStanding = false;
  1153. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, -31)));
  1154. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, -31)));
  1155. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, -31)));
  1156. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1), ho->id);
  1157. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1), ho->id);
  1158. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1), ho->id);
  1159. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33), ho->id);
  1160. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33), ho->id);
  1161. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33), ho->id);
  1162. 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);
  1163. 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);
  1164. 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);
  1165. }
  1166. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  1167. {
  1168. ho->moveDir = 3;
  1169. ho->isStanding = false;
  1170. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, -31)));
  1171. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, -31)));
  1172. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, -31)));
  1173. CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -31)));
  1174. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 1), ho->id);
  1175. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 1), ho->id);
  1176. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 1), ho->id);
  1177. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 1)));
  1178. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 33), ho->id);
  1179. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 33), ho->id);
  1180. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 33), ho->id);
  1181. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 33)));
  1182. 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);
  1183. 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);
  1184. 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);
  1185. 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);
  1186. 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);
  1187. 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);
  1188. }
  1189. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1190. {
  1191. ho->moveDir = 4;
  1192. ho->isStanding = false;
  1193. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id);
  1194. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id);
  1195. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id);
  1196. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 0)));
  1197. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 32), ho->id);
  1198. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 32), ho->id);
  1199. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 32), ho->id);
  1200. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 32)));
  1201. 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);
  1202. 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);
  1203. }
  1204. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1205. {
  1206. ho->moveDir = 5;
  1207. ho->isStanding = false;
  1208. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, -1), ho->id);
  1209. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, -1), ho->id);
  1210. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id);
  1211. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -1)));
  1212. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 31), ho->id);
  1213. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 31), ho->id);
  1214. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 31), ho->id);
  1215. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 31)));
  1216. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, 63)));
  1217. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, 63)));
  1218. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, 63)));
  1219. CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 63)));
  1220. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1221. 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);
  1222. 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);
  1223. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1224. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1225. 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);
  1226. }
  1227. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1228. {
  1229. ho->moveDir = 6;
  1230. ho->isStanding = false;
  1231. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1), ho->id);
  1232. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1), ho->id);
  1233. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1), ho->id);
  1234. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31), ho->id);
  1235. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31), ho->id);
  1236. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31), ho->id);
  1237. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, 63)));
  1238. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, 63)));
  1239. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, 63)));
  1240. 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);
  1241. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1242. 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);
  1243. }
  1244. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1245. {
  1246. ho->moveDir = 7;
  1247. ho->isStanding = false;
  1248. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -1)));
  1249. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id);
  1250. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id);
  1251. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, -1), ho->id);
  1252. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 31)));
  1253. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 31), ho->id);
  1254. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 31), ho->id);
  1255. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 31), ho->id);
  1256. CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 63)));
  1257. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, 63)));
  1258. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, 63)));
  1259. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, 63)));
  1260. 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);
  1261. 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);
  1262. 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);
  1263. 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);
  1264. 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);
  1265. 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);
  1266. }
  1267. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1268. {
  1269. ho->moveDir = 8;
  1270. ho->isStanding = false;
  1271. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 0)));
  1272. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id);
  1273. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id);
  1274. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 0), ho->id);
  1275. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 32)));
  1276. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 32), ho->id);
  1277. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 32), ho->id);
  1278. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 32), ho->id);
  1279. 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);
  1280. 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);
  1281. }
  1282. //first initializing done
  1283. SDL_framerateDelay(mainFPSmng); // after first move
  1284. //main moving
  1285. for(int i=1; i<32; i+=4)
  1286. {
  1287. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  1288. {
  1289. subRect(hp.x-3, hp.y-2, hp.z, genRect(32, 32, -31+i, -31+i), ho->id);
  1290. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 1+i, -31+i), ho->id);
  1291. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 33+i, -31+i), ho->id);
  1292. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 65+i, -31+i), ho->id);
  1293. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 1+i), ho->id);
  1294. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 1+i), ho->id);
  1295. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 1+i), ho->id);
  1296. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 1+i), ho->id);
  1297. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 33+i), ho->id);
  1298. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 33+i), ho->id);
  1299. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 33+i), ho->id);
  1300. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 33+i), ho->id);
  1301. }
  1302. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  1303. {
  1304. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 0, -31+i), ho->id);
  1305. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 32, -31+i), ho->id);
  1306. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 64, -31+i), ho->id);
  1307. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1+i), ho->id);
  1308. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1+i), ho->id);
  1309. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1+i), ho->id);
  1310. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33+i), ho->id);
  1311. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33+i), ho->id);
  1312. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33+i), ho->id);
  1313. }
  1314. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  1315. {
  1316. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, -1-i, -31+i), ho->id);
  1317. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 31-i, -31+i), ho->id);
  1318. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 63-i, -31+i), ho->id);
  1319. subRect(hp.x+1, hp.y-2, hp.z, genRect(32, 32, 95-i, -31+i), ho->id);
  1320. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 1+i), ho->id);
  1321. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 1+i), ho->id);
  1322. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 1+i), ho->id);
  1323. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 1+i), ho->id);
  1324. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 33+i), ho->id);
  1325. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 33+i), ho->id);
  1326. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 33+i), ho->id);
  1327. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 33+i), ho->id);
  1328. }
  1329. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1330. {
  1331. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 0), ho->id);
  1332. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 0), ho->id);
  1333. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 0), ho->id);
  1334. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 0), ho->id);
  1335. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 32), ho->id);
  1336. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 32), ho->id);
  1337. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 32), ho->id);
  1338. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 32), ho->id);
  1339. }
  1340. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1341. {
  1342. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, -1-i), ho->id);
  1343. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, -1-i), ho->id);
  1344. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, -1-i), ho->id);
  1345. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, -1-i), ho->id);
  1346. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 31-i), ho->id);
  1347. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 31-i), ho->id);
  1348. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 31-i), ho->id);
  1349. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 31-i), ho->id);
  1350. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, -1-i, 63-i), ho->id);
  1351. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 31-i, 63-i), ho->id);
  1352. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 63-i, 63-i), ho->id);
  1353. subRect(hp.x+1, hp.y+1, hp.z, genRect(32, 32, 95-i, 63-i), ho->id);
  1354. }
  1355. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1356. {
  1357. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1-i), ho->id);
  1358. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1-i), ho->id);
  1359. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1-i), ho->id);
  1360. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31-i), ho->id);
  1361. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31-i), ho->id);
  1362. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31-i), ho->id);
  1363. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 0, 63-i), ho->id);
  1364. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 32, 63-i), ho->id);
  1365. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 64, 63-i), ho->id);
  1366. }
  1367. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1368. {
  1369. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, -1-i), ho->id);
  1370. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, -1-i), ho->id);
  1371. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, -1-i), ho->id);
  1372. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, -1-i), ho->id);
  1373. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 31-i), ho->id);
  1374. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 31-i), ho->id);
  1375. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 31-i), ho->id);
  1376. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 31-i), ho->id);
  1377. subRect(hp.x-3, hp.y+1, hp.z, genRect(32, 32, -31+i, 63-i), ho->id);
  1378. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 1+i, 63-i), ho->id);
  1379. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 33+i, 63-i), ho->id);
  1380. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 65+i, 63-i), ho->id);
  1381. }
  1382. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1383. {
  1384. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 0), ho->id);
  1385. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 0), ho->id);
  1386. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 0), ho->id);
  1387. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 0), ho->id);
  1388. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 32), ho->id);
  1389. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 32), ho->id);
  1390. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 32), ho->id);
  1391. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 32), ho->id);
  1392. }
  1393. LOCPLINT->adventureInt->update(); //updating screen
  1394. CSDL_Ext::update(screen);
  1395. CGI->screenh->updateScreen();
  1396. ++LOCPLINT->adventureInt->animValHitCount; //for animations
  1397. if(LOCPLINT->adventureInt->animValHitCount == 4)
  1398. {
  1399. LOCPLINT->adventureInt->animValHitCount = 0;
  1400. ++LOCPLINT->adventureInt->anim;
  1401. LOCPLINT->adventureInt->updateScreen = true;
  1402. }
  1403. ++LOCPLINT->adventureInt->heroAnim;
  1404. SDL_Delay(5);
  1405. SDL_framerateDelay(mainFPSmng); //for animation purposes
  1406. } //for(int i=1; i<32; i+=4)
  1407. //main moving done
  1408. //finishing move
  1409. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  1410. {
  1411. delObjRect(hp.x, hp.y-2, hp.z, ho->id);
  1412. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1413. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1414. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1415. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1416. delObjRect(hp.x-3, hp.y, hp.z, ho->id);
  1417. }
  1418. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  1419. {
  1420. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1421. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1422. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1423. }
  1424. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  1425. {
  1426. delObjRect(hp.x-2, hp.y-2, hp.z, ho->id);
  1427. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1428. delObjRect(hp.x+1, hp.y, hp.z, ho->id);
  1429. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1430. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1431. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1432. }
  1433. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1434. {
  1435. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1436. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1437. }
  1438. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1439. {
  1440. delObjRect(hp.x-2, hp.y+1, hp.z, ho->id);
  1441. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1442. delObjRect(hp.x+1, hp.y-1, hp.z, ho->id);
  1443. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1444. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1445. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1446. }
  1447. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1448. {
  1449. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1450. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1451. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1452. }
  1453. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1454. {
  1455. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1456. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1457. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1458. delObjRect(hp.x-3, hp.y-1, hp.z, ho->id);
  1459. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1460. delObjRect(hp.x, hp.y+1, hp.z, ho->id);
  1461. }
  1462. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1463. {
  1464. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1465. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1466. }
  1467. ho->pos = details.dst; //copy of hero's position
  1468. //ho->moveDir = 0; //move ended
  1469. ho->isStanding = true;
  1470. //move finished
  1471. CGI->mh->recalculateHideVisPosUnderObj(details.ho, true);
  1472. adventureInt->minimap.draw();
  1473. adventureInt->heroList.updateMove(ho);
  1474. }
  1475. void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
  1476. {
  1477. heroWins.erase(hero->ID);
  1478. }
  1479. void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
  1480. {
  1481. if(heroWins.find(hero->subID)==heroWins.end())
  1482. heroWins.insert(std::pair<int,SDL_Surface*>(hero->subID,infoWin(hero)));
  1483. }
  1484. SDL_Surface * CPlayerInterface::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to)
  1485. {
  1486. char * buf = new char[10];
  1487. for (int i=from;i<to;i++)
  1488. {
  1489. itoa(curh->primSkills[i],buf,10);
  1490. printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
  1491. }
  1492. delete[] buf;
  1493. return ret;
  1494. }
  1495. SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh)
  1496. {
  1497. char * buf = new char[10];
  1498. blueToPlayersAdv(hInfo,playerID,1);
  1499. SDL_Surface * ret = SDL_DisplayFormat(hInfo);
  1500. SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
  1501. printAt(curh->name,75,15,GEOR13,zwykly,ret);
  1502. drawPrimarySkill(curh, ret);
  1503. for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
  1504. {
  1505. blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
  1506. itoa((*i).second.second,buf,10);
  1507. printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
  1508. }
  1509. blitAt(curh->type->portraitLarge,11,12,ret);
  1510. itoa(curh->mana,buf,10);
  1511. printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points
  1512. delete[] buf;
  1513. blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret);
  1514. blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret);
  1515. //SDL_SaveBMP(ret,"inf1.bmp");
  1516. return ret;
  1517. }
  1518. SDL_Surface * CPlayerInterface::drawTownInfoWin(const CGTownInstance * curh)
  1519. {
  1520. char * buf = new char[10];
  1521. blueToPlayersAdv(tInfo,playerID,1);
  1522. SDL_Surface * ret = SDL_DisplayFormat(tInfo);
  1523. SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
  1524. printAt(curh->name,75,15,GEOR13,zwykly,ret);
  1525. int pom = curh->fortLevel() - 1; if(pom<0) pom = 3;
  1526. blitAt(forts->ourImages[pom].bitmap,115,42,ret);
  1527. if((pom=curh->hallLevel())>=0)
  1528. blitAt(halls->ourImages[pom].bitmap,77,42,ret);
  1529. itoa(curh->dailyIncome(),buf,10);
  1530. printAtMiddle(buf,167,70,GEORM,zwykly,ret);
  1531. for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
  1532. {
  1533. if(!i->second.first)
  1534. continue;
  1535. blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
  1536. itoa((*i).second.second,buf,10);
  1537. printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
  1538. }
  1539. //blit town icon
  1540. pom = curh->subID*2;
  1541. if (!curh->hasFort())
  1542. pom += F_NUMBER*2;
  1543. if(curh->builded >= MAX_BUILDING_PER_TURN)
  1544. pom++;
  1545. blitAt(bigTownPic->ourImages[pom].bitmap,13,13,ret);
  1546. delete[] buf;
  1547. return ret;
  1548. }
  1549. void CPlayerInterface::openTownWindow(const CGTownInstance * town)
  1550. {
  1551. adventureInt->hide();
  1552. //timeHandler t;
  1553. //t.getDif();
  1554. castleInt = new CCastleInterface(town,true);
  1555. //std::cout << "Loading town screen: " << t.getDif() <<std::endl;
  1556. }
  1557. SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //specific=0 => draws info about selected town/hero
  1558. {
  1559. if (specific)
  1560. {
  1561. switch (specific->ID)
  1562. {
  1563. case 34:
  1564. return drawHeroInfoWin(dynamic_cast<const CGHeroInstance*>(specific));
  1565. break;
  1566. case 98:
  1567. return drawTownInfoWin(dynamic_cast<const CGTownInstance*>(specific));
  1568. break;
  1569. default:
  1570. return NULL;
  1571. break;
  1572. }
  1573. }
  1574. else
  1575. {
  1576. switch (adventureInt->selection.type)
  1577. {
  1578. case HEROI_TYPE:
  1579. {
  1580. const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection.selected;
  1581. return drawHeroInfoWin(curh);
  1582. }
  1583. case TOWNI_TYPE:
  1584. {
  1585. return drawTownInfoWin((const CGTownInstance *)adventureInt->selection.selected);
  1586. }
  1587. default:
  1588. return NULL;
  1589. }
  1590. }
  1591. return NULL;
  1592. }
  1593. void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent)
  1594. {
  1595. for (int i=0; i<hoverable.size();i++)
  1596. {
  1597. if (isItIn(&hoverable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1598. {
  1599. if (!hoverable[i]->hovered)
  1600. hoverable[i]->hover(true);
  1601. }
  1602. else if (hoverable[i]->hovered)
  1603. {
  1604. hoverable[i]->hover(false);
  1605. }
  1606. }
  1607. for(int i=0; i<motioninterested.size();i++)
  1608. {
  1609. if (motioninterested[i]->strongInterest || isItIn(&motioninterested[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1610. {
  1611. motioninterested[i]->mouseMoved(sEvent->motion);
  1612. }
  1613. }
  1614. if(sEvent->motion.x<15)
  1615. {
  1616. LOCPLINT->adventureInt->scrollingLeft = true;
  1617. }
  1618. else
  1619. {
  1620. LOCPLINT->adventureInt->scrollingLeft = false;
  1621. }
  1622. if(sEvent->motion.x>screen->w-15)
  1623. {
  1624. LOCPLINT->adventureInt->scrollingRight = true;
  1625. }
  1626. else
  1627. {
  1628. LOCPLINT->adventureInt->scrollingRight = false;
  1629. }
  1630. if(sEvent->motion.y<15)
  1631. {
  1632. LOCPLINT->adventureInt->scrollingUp = true;
  1633. }
  1634. else
  1635. {
  1636. LOCPLINT->adventureInt->scrollingUp = false;
  1637. }
  1638. if(sEvent->motion.y>screen->h-15)
  1639. {
  1640. LOCPLINT->adventureInt->scrollingDown = true;
  1641. }
  1642. else
  1643. {
  1644. LOCPLINT->adventureInt->scrollingDown = false;
  1645. }
  1646. }
  1647. void CPlayerInterface::handleKeyUp(SDL_Event *sEvent)
  1648. {
  1649. switch (sEvent->key.keysym.sym)
  1650. {
  1651. case SDLK_LEFT:
  1652. {
  1653. LOCPLINT->adventureInt->scrollingLeft = false;
  1654. break;
  1655. }
  1656. case (SDLK_RIGHT):
  1657. {
  1658. LOCPLINT->adventureInt->scrollingRight = false;
  1659. break;
  1660. }
  1661. case (SDLK_UP):
  1662. {
  1663. LOCPLINT->adventureInt->scrollingUp = false;
  1664. break;
  1665. }
  1666. case (SDLK_DOWN):
  1667. {
  1668. LOCPLINT->adventureInt->scrollingDown = false;
  1669. break;
  1670. }
  1671. case (SDLK_u):
  1672. {
  1673. adventureInt->underground.clickLeft(false);
  1674. break;
  1675. }
  1676. case (SDLK_m):
  1677. {
  1678. adventureInt->moveHero.clickLeft(false);
  1679. break;
  1680. }
  1681. case (SDLK_e):
  1682. {
  1683. adventureInt->endTurn.clickLeft(false);
  1684. break;
  1685. }
  1686. }
  1687. }
  1688. void CPlayerInterface::handleKeyDown(SDL_Event *sEvent)
  1689. {
  1690. switch (sEvent->key.keysym.sym)
  1691. {
  1692. case SDLK_LEFT:
  1693. {
  1694. LOCPLINT->adventureInt->scrollingLeft = true;
  1695. break;
  1696. }
  1697. case (SDLK_RIGHT):
  1698. {
  1699. LOCPLINT->adventureInt->scrollingRight = true;
  1700. break;
  1701. }
  1702. case (SDLK_UP):
  1703. {
  1704. LOCPLINT->adventureInt->scrollingUp = true;
  1705. break;
  1706. }
  1707. case (SDLK_DOWN):
  1708. {
  1709. LOCPLINT->adventureInt->scrollingDown = true;
  1710. break;
  1711. }
  1712. case (SDLK_q):
  1713. {
  1714. continueReadingConsole = false;
  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->reader->map.width - this->adventureInt->terrain.tilesw + Woff)
  1810. pos.x = CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff;
  1811. if(pos.y>CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff)
  1812. pos.y = CGI->mh->reader->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. }