CPlayerInterface.cpp 91 KB

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