CPlayerInterface.cpp 91 KB

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