CPlayerInterface.cpp 89 KB

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