CPlayerInterface.cpp 91 KB

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