CPlayerInterface.cpp 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084
  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. pim = new boost::mutex;
  901. }
  902. CPlayerInterface::~CPlayerInterface()
  903. {
  904. delete pim;
  905. }
  906. void CPlayerInterface::init(ICallback * CB)
  907. {
  908. cb = dynamic_cast<CCallback*>(CB);
  909. adventureInt = new CAdvMapInt(playerID);
  910. castleInt = NULL;
  911. std::vector <const CGHeroInstance *> hh = cb->getHeroesInfo(false);
  912. for(int i=0;i<hh.size();i++)
  913. {
  914. SDL_Surface * pom = infoWin(hh[i]);
  915. graphics->heroWins.insert(std::pair<int,SDL_Surface*>(hh[i]->subID,pom));
  916. }
  917. std::vector<const CGTownInstance*> tt = cb->getTownsInfo(false);
  918. for(int i=0;i<tt.size();i++)
  919. {
  920. SDL_Surface * pom = infoWin(tt[i]);
  921. graphics->townWins.insert(std::pair<int,SDL_Surface*>(tt[i]->identifier,pom));
  922. }
  923. }
  924. void CPlayerInterface::yourTurn()
  925. {
  926. LOCPLINT = this;
  927. makingTurn = true;
  928. unsigned char & animVal = LOCPLINT->adventureInt->anim; //for animations handling
  929. unsigned char & heroAnimVal = LOCPLINT->adventureInt->heroAnim;
  930. adventureInt->infoBar.newDay(cb->getDate(1));
  931. adventureInt->activate();
  932. //show rest of things
  933. //initializing framerate keeper
  934. mainFPSmng = new FPSmanager;
  935. SDL_initFramerate(mainFPSmng);
  936. SDL_setFramerate(mainFPSmng, 24);
  937. SDL_Event sEvent;
  938. //framerate keeper initialized
  939. timeHandler th;
  940. th.getDif();
  941. for(;makingTurn;) // main loop
  942. {
  943. //updating water tiles
  944. //int wnumber = -1;
  945. //for(int s=0; s<CGI->mh->reader->defs.size(); ++s)
  946. //{
  947. // if(CGI->mh->reader->defs[s]->defName==std::string("WATRTL.DEF"))
  948. // {
  949. // wnumber = s;
  950. // break;
  951. // }
  952. //}
  953. //if(wnumber>=0)
  954. //{
  955. // for(int g=0; g<CGI->mh->reader->defs[wnumber]->ourImages.size(); ++g)
  956. // {
  957. // SDL_Color tab[32];
  958. // for(int i=0; i<32; ++i)
  959. // {
  960. // tab[i] = CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap->format->palette->colors[160 + (i+1)%32];
  961. // }
  962. // //SDL_SaveBMP(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap,"t1.bmp");
  963. // for(int i=0; i<32; ++i)
  964. // {
  965. // CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap->format->palette->colors[160 + i] = tab[i];
  966. // }
  967. // //SDL_SaveBMP(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap,"t2.bmp");
  968. // CSDL_Ext::update(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap);
  969. // }
  970. //}
  971. //water tiles updated
  972. CGI->screenh->updateScreen();
  973. pim->lock();
  974. int tv = th.getDif();
  975. for (int i=0;i<timeinterested.size();i++)
  976. {
  977. if (timeinterested[i]->toNextTick>=0)
  978. timeinterested[i]->toNextTick-=tv;
  979. if (timeinterested[i]->toNextTick<0)
  980. timeinterested[i]->tick();
  981. }
  982. LOCPLINT->adventureInt->updateScreen = false;
  983. eventsM.lock();
  984. while(!events.empty())
  985. {
  986. handleEvent(&events.front());
  987. events.pop();
  988. }
  989. eventsM.unlock();
  990. if (!castleInt) //stuff for advMapInt
  991. {
  992. ++LOCPLINT->adventureInt->animValHitCount; //for animations
  993. if(LOCPLINT->adventureInt->animValHitCount == 4)
  994. {
  995. LOCPLINT->adventureInt->animValHitCount = 0;
  996. ++animVal;
  997. LOCPLINT->adventureInt->updateScreen = true;
  998. }
  999. ++heroAnimVal;
  1000. if(LOCPLINT->adventureInt->scrollingLeft)
  1001. {
  1002. if(LOCPLINT->adventureInt->position.x>-Woff)
  1003. {
  1004. LOCPLINT->adventureInt->position.x--;
  1005. LOCPLINT->adventureInt->updateScreen = true;
  1006. adventureInt->updateMinimap=true;
  1007. }
  1008. }
  1009. if(LOCPLINT->adventureInt->scrollingRight)
  1010. {
  1011. if(LOCPLINT->adventureInt->position.x<CGI->mh->map->width-19+4)
  1012. {
  1013. LOCPLINT->adventureInt->position.x++;
  1014. LOCPLINT->adventureInt->updateScreen = true;
  1015. adventureInt->updateMinimap=true;
  1016. }
  1017. }
  1018. if(LOCPLINT->adventureInt->scrollingUp)
  1019. {
  1020. if(LOCPLINT->adventureInt->position.y>-Hoff)
  1021. {
  1022. LOCPLINT->adventureInt->position.y--;
  1023. LOCPLINT->adventureInt->updateScreen = true;
  1024. adventureInt->updateMinimap=true;
  1025. }
  1026. }
  1027. if(LOCPLINT->adventureInt->scrollingDown)
  1028. {
  1029. if(LOCPLINT->adventureInt->position.y<CGI->mh->map->height-18+4)
  1030. {
  1031. LOCPLINT->adventureInt->position.y++;
  1032. LOCPLINT->adventureInt->updateScreen = true;
  1033. adventureInt->updateMinimap=true;
  1034. }
  1035. }
  1036. if(LOCPLINT->adventureInt->updateScreen)
  1037. {
  1038. adventureInt->update();
  1039. adventureInt->updateScreen=false;
  1040. }
  1041. if (LOCPLINT->adventureInt->updateMinimap)
  1042. {
  1043. adventureInt->minimap.draw();
  1044. adventureInt->updateMinimap=false;
  1045. }
  1046. }
  1047. for(int i=0;i<objsToBlit.size();i++)
  1048. objsToBlit[i]->show();
  1049. pim->unlock();
  1050. //SDL_Flip(screen);
  1051. CSDL_Ext::update(screen);
  1052. SDL_Delay(5); //give time for other apps
  1053. SDL_framerateDelay(mainFPSmng);
  1054. }
  1055. adventureInt->hide();
  1056. cb->endTurn();
  1057. }
  1058. inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, const int & hid)
  1059. {
  1060. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  1061. for(int h=0; h<hlp.objects.size(); ++h)
  1062. if(hlp.objects[h].first->id==hid)
  1063. {
  1064. hlp.objects[h].second = r;
  1065. return;
  1066. }
  1067. }
  1068. inline void delObjRect(const int & x, const int & y, const int & z, const int & hid)
  1069. {
  1070. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  1071. for(int h=0; h<hlp.objects.size(); ++h)
  1072. if(hlp.objects[h].first->id==hid)
  1073. {
  1074. hlp.objects.erase(hlp.objects.begin()+h);
  1075. return;
  1076. }
  1077. }
  1078. int getDir(int3 src, int3 dst)
  1079. {
  1080. int ret = -1;
  1081. if(dst.x+1 == src.x && dst.y+1 == src.y) //tl
  1082. {
  1083. ret = 1;
  1084. }
  1085. else if(dst.x == src.x && dst.y+1 == src.y) //t
  1086. {
  1087. ret = 2;
  1088. }
  1089. else if(dst.x-1 == src.x && dst.y+1 == src.y) //tr
  1090. {
  1091. ret = 3;
  1092. }
  1093. else if(dst.x-1 == src.x && dst.y == src.y) //r
  1094. {
  1095. ret = 4;
  1096. }
  1097. else if(dst.x-1 == src.x && dst.y-1 == src.y) //br
  1098. {
  1099. ret = 5;
  1100. }
  1101. else if(dst.x == src.x && dst.y-1 == src.y) //b
  1102. {
  1103. ret = 6;
  1104. }
  1105. else if(dst.x+1 == src.x && dst.y-1 == src.y) //bl
  1106. {
  1107. ret = 7;
  1108. }
  1109. else if(dst.x+1 == src.x && dst.y == src.y) //l
  1110. {
  1111. ret = 8;
  1112. }
  1113. return ret;
  1114. }
  1115. void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
  1116. {
  1117. //initializing objects and performing first step of move
  1118. CGHeroInstance * ho = details.ho; //object representing this hero
  1119. int3 hp = details.src;
  1120. boost::unique_lock<boost::mutex> un(*pim);
  1121. if (!details.successful)
  1122. {
  1123. ho->moveDir = getDir(details.src,details.dst);
  1124. ho->isStanding = true;
  1125. adventureInt->heroList.draw();
  1126. if (adventureInt->terrain.currentPath)
  1127. {
  1128. delete adventureInt->terrain.currentPath;
  1129. adventureInt->terrain.currentPath = NULL;
  1130. }
  1131. return;
  1132. }
  1133. if (adventureInt->terrain.currentPath) //&& hero is moving
  1134. {
  1135. adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
  1136. }
  1137. int3 buff = details.ho->pos;
  1138. buff.x-=11;
  1139. buff.y-=9;
  1140. buff = repairScreenPos(buff);
  1141. LOCPLINT->adventureInt->position = buff; //actualizing screen pos
  1142. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  1143. {
  1144. ho->moveDir = 1;
  1145. ho->isStanding = false;
  1146. CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -31)));
  1147. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, -31)));
  1148. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, -31)));
  1149. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, -31)));
  1150. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 1)));
  1151. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 1), ho->id);
  1152. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 1), ho->id);
  1153. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 1), ho->id);
  1154. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 33)));
  1155. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 33), ho->id);
  1156. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 33), ho->id);
  1157. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 33), ho->id);
  1158. 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);
  1159. 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);
  1160. 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);
  1161. 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);
  1162. 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);
  1163. 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);
  1164. }
  1165. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  1166. {
  1167. ho->moveDir = 2;
  1168. ho->isStanding = false;
  1169. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, -31)));
  1170. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, -31)));
  1171. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, -31)));
  1172. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1), ho->id);
  1173. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1), ho->id);
  1174. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1), ho->id);
  1175. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33), ho->id);
  1176. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33), ho->id);
  1177. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33), ho->id);
  1178. 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);
  1179. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1180. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1181. }
  1182. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  1183. {
  1184. ho->moveDir = 3;
  1185. ho->isStanding = false;
  1186. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, -31)));
  1187. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, -31)));
  1188. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, -31)));
  1189. CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -31)));
  1190. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 1), ho->id);
  1191. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 1), ho->id);
  1192. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 1), ho->id);
  1193. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 1)));
  1194. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 33), ho->id);
  1195. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 33), ho->id);
  1196. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 33), ho->id);
  1197. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 33)));
  1198. 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);
  1199. 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);
  1200. 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);
  1201. 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);
  1202. 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);
  1203. 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);
  1204. }
  1205. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1206. {
  1207. ho->moveDir = 4;
  1208. ho->isStanding = false;
  1209. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id);
  1210. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id);
  1211. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id);
  1212. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 0)));
  1213. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 32), ho->id);
  1214. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 32), ho->id);
  1215. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 32), ho->id);
  1216. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 32)));
  1217. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1218. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1219. }
  1220. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1221. {
  1222. ho->moveDir = 5;
  1223. ho->isStanding = false;
  1224. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, -1), ho->id);
  1225. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, -1), ho->id);
  1226. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id);
  1227. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -1)));
  1228. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 31), ho->id);
  1229. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 31), ho->id);
  1230. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 31), ho->id);
  1231. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 31)));
  1232. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, 63)));
  1233. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, 63)));
  1234. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, 63)));
  1235. CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 63)));
  1236. 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);
  1237. 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);
  1238. 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);
  1239. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1240. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1241. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1242. }
  1243. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1244. {
  1245. ho->moveDir = 6;
  1246. ho->isStanding = false;
  1247. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1), ho->id);
  1248. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1), ho->id);
  1249. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1), ho->id);
  1250. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31), ho->id);
  1251. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31), ho->id);
  1252. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31), ho->id);
  1253. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, 63)));
  1254. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, 63)));
  1255. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, 63)));
  1256. 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);
  1257. 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);
  1258. 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);
  1259. }
  1260. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1261. {
  1262. ho->moveDir = 7;
  1263. ho->isStanding = false;
  1264. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -1)));
  1265. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id);
  1266. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id);
  1267. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, -1), ho->id);
  1268. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 31)));
  1269. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 31), ho->id);
  1270. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 31), ho->id);
  1271. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 31), ho->id);
  1272. CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 63)));
  1273. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, 63)));
  1274. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, 63)));
  1275. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, 63)));
  1276. 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);
  1277. 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);
  1278. 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);
  1279. 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);
  1280. 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);
  1281. 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);
  1282. }
  1283. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1284. {
  1285. ho->moveDir = 8;
  1286. ho->isStanding = false;
  1287. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 0)));
  1288. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id);
  1289. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id);
  1290. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 0), ho->id);
  1291. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 32)));
  1292. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 32), ho->id);
  1293. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 32), ho->id);
  1294. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 32), ho->id);
  1295. 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);
  1296. 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);
  1297. }
  1298. //first initializing done
  1299. SDL_framerateDelay(mainFPSmng); // after first move
  1300. //main moving
  1301. for(int i=1; i<32; i+=4)
  1302. {
  1303. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  1304. {
  1305. subRect(hp.x-3, hp.y-2, hp.z, genRect(32, 32, -31+i, -31+i), ho->id);
  1306. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 1+i, -31+i), ho->id);
  1307. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 33+i, -31+i), ho->id);
  1308. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 65+i, -31+i), ho->id);
  1309. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 1+i), ho->id);
  1310. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 1+i), ho->id);
  1311. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 1+i), ho->id);
  1312. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 1+i), ho->id);
  1313. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 33+i), ho->id);
  1314. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 33+i), ho->id);
  1315. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 33+i), ho->id);
  1316. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 33+i), ho->id);
  1317. }
  1318. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  1319. {
  1320. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 0, -31+i), ho->id);
  1321. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 32, -31+i), ho->id);
  1322. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 64, -31+i), ho->id);
  1323. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1+i), ho->id);
  1324. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1+i), ho->id);
  1325. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1+i), ho->id);
  1326. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33+i), ho->id);
  1327. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33+i), ho->id);
  1328. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33+i), ho->id);
  1329. }
  1330. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  1331. {
  1332. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, -1-i, -31+i), ho->id);
  1333. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 31-i, -31+i), ho->id);
  1334. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 63-i, -31+i), ho->id);
  1335. subRect(hp.x+1, hp.y-2, hp.z, genRect(32, 32, 95-i, -31+i), ho->id);
  1336. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 1+i), ho->id);
  1337. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 1+i), ho->id);
  1338. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 1+i), ho->id);
  1339. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 1+i), ho->id);
  1340. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 33+i), ho->id);
  1341. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 33+i), ho->id);
  1342. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 33+i), ho->id);
  1343. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 33+i), ho->id);
  1344. }
  1345. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1346. {
  1347. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 0), ho->id);
  1348. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 0), ho->id);
  1349. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 0), ho->id);
  1350. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 0), ho->id);
  1351. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 32), ho->id);
  1352. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 32), ho->id);
  1353. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 32), ho->id);
  1354. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 32), ho->id);
  1355. }
  1356. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1357. {
  1358. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, -1-i), ho->id);
  1359. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, -1-i), ho->id);
  1360. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, -1-i), ho->id);
  1361. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, -1-i), ho->id);
  1362. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 31-i), ho->id);
  1363. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 31-i), ho->id);
  1364. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 31-i), ho->id);
  1365. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 31-i), ho->id);
  1366. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, -1-i, 63-i), ho->id);
  1367. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 31-i, 63-i), ho->id);
  1368. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 63-i, 63-i), ho->id);
  1369. subRect(hp.x+1, hp.y+1, hp.z, genRect(32, 32, 95-i, 63-i), ho->id);
  1370. }
  1371. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1372. {
  1373. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1-i), ho->id);
  1374. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1-i), ho->id);
  1375. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1-i), ho->id);
  1376. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31-i), ho->id);
  1377. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31-i), ho->id);
  1378. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31-i), ho->id);
  1379. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 0, 63-i), ho->id);
  1380. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 32, 63-i), ho->id);
  1381. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 64, 63-i), ho->id);
  1382. }
  1383. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1384. {
  1385. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, -1-i), ho->id);
  1386. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, -1-i), ho->id);
  1387. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, -1-i), ho->id);
  1388. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, -1-i), ho->id);
  1389. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 31-i), ho->id);
  1390. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 31-i), ho->id);
  1391. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 31-i), ho->id);
  1392. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 31-i), ho->id);
  1393. subRect(hp.x-3, hp.y+1, hp.z, genRect(32, 32, -31+i, 63-i), ho->id);
  1394. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 1+i, 63-i), ho->id);
  1395. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 33+i, 63-i), ho->id);
  1396. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 65+i, 63-i), ho->id);
  1397. }
  1398. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1399. {
  1400. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 0), ho->id);
  1401. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 0), ho->id);
  1402. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 0), ho->id);
  1403. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 0), ho->id);
  1404. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 32), ho->id);
  1405. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 32), ho->id);
  1406. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 32), ho->id);
  1407. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 32), ho->id);
  1408. }
  1409. LOCPLINT->adventureInt->update(); //updating screen
  1410. CSDL_Ext::update(screen);
  1411. CGI->screenh->updateScreen();
  1412. ++LOCPLINT->adventureInt->animValHitCount; //for animations
  1413. if(LOCPLINT->adventureInt->animValHitCount == 4)
  1414. {
  1415. LOCPLINT->adventureInt->animValHitCount = 0;
  1416. ++LOCPLINT->adventureInt->anim;
  1417. LOCPLINT->adventureInt->updateScreen = true;
  1418. }
  1419. ++LOCPLINT->adventureInt->heroAnim;
  1420. SDL_Delay(5);
  1421. SDL_framerateDelay(mainFPSmng); //for animation purposes
  1422. } //for(int i=1; i<32; i+=4)
  1423. //main moving done
  1424. //finishing move
  1425. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  1426. {
  1427. delObjRect(hp.x, hp.y-2, hp.z, ho->id);
  1428. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1429. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1430. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1431. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1432. delObjRect(hp.x-3, hp.y, hp.z, ho->id);
  1433. }
  1434. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  1435. {
  1436. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1437. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1438. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1439. }
  1440. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  1441. {
  1442. delObjRect(hp.x-2, hp.y-2, hp.z, ho->id);
  1443. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1444. delObjRect(hp.x+1, hp.y, hp.z, ho->id);
  1445. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1446. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1447. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1448. }
  1449. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1450. {
  1451. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1452. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1453. }
  1454. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1455. {
  1456. delObjRect(hp.x-2, hp.y+1, hp.z, ho->id);
  1457. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1458. delObjRect(hp.x+1, hp.y-1, hp.z, ho->id);
  1459. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1460. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1461. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1462. }
  1463. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1464. {
  1465. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1466. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1467. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1468. }
  1469. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1470. {
  1471. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1472. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1473. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1474. delObjRect(hp.x-3, hp.y-1, hp.z, ho->id);
  1475. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1476. delObjRect(hp.x, hp.y+1, hp.z, ho->id);
  1477. }
  1478. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1479. {
  1480. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1481. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1482. }
  1483. ho->pos = details.dst; //copy of hero's position
  1484. //ho->moveDir = 0; //move ended
  1485. ho->isStanding = true;
  1486. //move finished
  1487. CGI->mh->recalculateHideVisPosUnderObj(details.ho, true);
  1488. adventureInt->minimap.draw();
  1489. adventureInt->heroList.updateMove(ho);
  1490. }
  1491. void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
  1492. {
  1493. graphics->heroWins.erase(hero->ID);
  1494. }
  1495. void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
  1496. {
  1497. if(graphics->heroWins.find(hero->subID)==graphics->heroWins.end())
  1498. graphics->heroWins.insert(std::pair<int,SDL_Surface*>(hero->subID,infoWin(hero)));
  1499. }
  1500. void CPlayerInterface::openTownWindow(const CGTownInstance * town)
  1501. {
  1502. adventureInt->hide();
  1503. //timeHandler t;
  1504. //t.getDif();
  1505. castleInt = new CCastleInterface(town,true);
  1506. //std::cout << "Loading town screen: " << t.getDif() <<std::endl;
  1507. }
  1508. SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //specific=0 => draws info about selected town/hero
  1509. {
  1510. if (specific)
  1511. {
  1512. switch (specific->ID)
  1513. {
  1514. case 34:
  1515. return graphics->drawHeroInfoWin(dynamic_cast<const CGHeroInstance*>(specific));
  1516. break;
  1517. case 98:
  1518. return graphics->drawTownInfoWin(dynamic_cast<const CGTownInstance*>(specific));
  1519. break;
  1520. default:
  1521. return NULL;
  1522. break;
  1523. }
  1524. }
  1525. else
  1526. {
  1527. switch (adventureInt->selection.type)
  1528. {
  1529. case HEROI_TYPE:
  1530. {
  1531. const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection.selected;
  1532. return graphics->drawHeroInfoWin(curh);
  1533. }
  1534. case TOWNI_TYPE:
  1535. {
  1536. return graphics->drawTownInfoWin((const CGTownInstance *)adventureInt->selection.selected);
  1537. }
  1538. default:
  1539. return NULL;
  1540. }
  1541. }
  1542. return NULL;
  1543. }
  1544. void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent)
  1545. {
  1546. for (int i=0; i<hoverable.size();i++)
  1547. {
  1548. if (isItIn(&hoverable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1549. {
  1550. if (!hoverable[i]->hovered)
  1551. hoverable[i]->hover(true);
  1552. }
  1553. else if (hoverable[i]->hovered)
  1554. {
  1555. hoverable[i]->hover(false);
  1556. }
  1557. }
  1558. for(int i=0; i<motioninterested.size();i++)
  1559. {
  1560. if (motioninterested[i]->strongInterest || isItIn(&motioninterested[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1561. {
  1562. motioninterested[i]->mouseMoved(sEvent->motion);
  1563. }
  1564. }
  1565. if(sEvent->motion.x<15)
  1566. {
  1567. LOCPLINT->adventureInt->scrollingLeft = true;
  1568. }
  1569. else
  1570. {
  1571. LOCPLINT->adventureInt->scrollingLeft = false;
  1572. }
  1573. if(sEvent->motion.x>screen->w-15)
  1574. {
  1575. LOCPLINT->adventureInt->scrollingRight = true;
  1576. }
  1577. else
  1578. {
  1579. LOCPLINT->adventureInt->scrollingRight = false;
  1580. }
  1581. if(sEvent->motion.y<15)
  1582. {
  1583. LOCPLINT->adventureInt->scrollingUp = true;
  1584. }
  1585. else
  1586. {
  1587. LOCPLINT->adventureInt->scrollingUp = false;
  1588. }
  1589. if(sEvent->motion.y>screen->h-15)
  1590. {
  1591. LOCPLINT->adventureInt->scrollingDown = true;
  1592. }
  1593. else
  1594. {
  1595. LOCPLINT->adventureInt->scrollingDown = false;
  1596. }
  1597. }
  1598. void CPlayerInterface::handleKeyUp(SDL_Event *sEvent)
  1599. {
  1600. switch (sEvent->key.keysym.sym)
  1601. {
  1602. case SDLK_LEFT:
  1603. {
  1604. LOCPLINT->adventureInt->scrollingLeft = false;
  1605. break;
  1606. }
  1607. case (SDLK_RIGHT):
  1608. {
  1609. LOCPLINT->adventureInt->scrollingRight = false;
  1610. break;
  1611. }
  1612. case (SDLK_UP):
  1613. {
  1614. LOCPLINT->adventureInt->scrollingUp = false;
  1615. break;
  1616. }
  1617. case (SDLK_DOWN):
  1618. {
  1619. LOCPLINT->adventureInt->scrollingDown = false;
  1620. break;
  1621. }
  1622. case (SDLK_u):
  1623. {
  1624. adventureInt->underground.clickLeft(false);
  1625. break;
  1626. }
  1627. case (SDLK_m):
  1628. {
  1629. adventureInt->moveHero.clickLeft(false);
  1630. break;
  1631. }
  1632. case (SDLK_e):
  1633. {
  1634. adventureInt->endTurn.clickLeft(false);
  1635. break;
  1636. }
  1637. }
  1638. }
  1639. void CPlayerInterface::handleKeyDown(SDL_Event *sEvent)
  1640. {
  1641. switch (sEvent->key.keysym.sym)
  1642. {
  1643. case SDLK_LEFT:
  1644. {
  1645. LOCPLINT->adventureInt->scrollingLeft = true;
  1646. break;
  1647. }
  1648. case (SDLK_RIGHT):
  1649. {
  1650. LOCPLINT->adventureInt->scrollingRight = true;
  1651. break;
  1652. }
  1653. case (SDLK_UP):
  1654. {
  1655. LOCPLINT->adventureInt->scrollingUp = true;
  1656. break;
  1657. }
  1658. case (SDLK_DOWN):
  1659. {
  1660. LOCPLINT->adventureInt->scrollingDown = true;
  1661. break;
  1662. }
  1663. case (SDLK_q):
  1664. {
  1665. continueReadingConsole = false;
  1666. exit(0);
  1667. break;
  1668. }
  1669. case (SDLK_u):
  1670. {
  1671. adventureInt->underground.clickLeft(true);
  1672. break;
  1673. }
  1674. case (SDLK_m):
  1675. {
  1676. adventureInt->moveHero.clickLeft(true);
  1677. break;
  1678. }
  1679. case (SDLK_e):
  1680. {
  1681. adventureInt->endTurn.clickLeft(true);
  1682. break;
  1683. }
  1684. }
  1685. }
  1686. void CPlayerInterface::handleEvent(SDL_Event *sEvent)
  1687. {
  1688. current = sEvent;
  1689. if(sEvent->type == SDL_MOUSEMOTION)
  1690. {
  1691. CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
  1692. }
  1693. if(sEvent->type==SDL_QUIT)
  1694. exit(0);
  1695. else if (sEvent->type==SDL_KEYDOWN)
  1696. {
  1697. handleKeyDown(sEvent);
  1698. } //keydown end
  1699. else if(sEvent->type==SDL_KEYUP)
  1700. {
  1701. handleKeyUp(sEvent);
  1702. }//keyup end
  1703. else if(sEvent->type==SDL_MOUSEMOTION)
  1704. {
  1705. handleMouseMotion(sEvent);
  1706. } //mousemotion end
  1707. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1708. {
  1709. for(int i=0; i<lclickable.size();i++)
  1710. {
  1711. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1712. {
  1713. lclickable[i]->clickLeft(true);
  1714. }
  1715. }
  1716. }
  1717. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1718. {
  1719. for(int i=0; i<lclickable.size();i++)
  1720. {
  1721. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1722. {
  1723. lclickable[i]->clickLeft(false);
  1724. }
  1725. else
  1726. lclickable[i]->clickLeft(boost::logic::indeterminate);
  1727. }
  1728. }
  1729. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1730. {
  1731. for(int i=0; i<rclickable.size();i++)
  1732. {
  1733. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1734. {
  1735. rclickable[i]->clickRight(true);
  1736. }
  1737. }
  1738. }
  1739. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1740. {
  1741. for(int i=0; i<rclickable.size();i++)
  1742. {
  1743. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1744. {
  1745. rclickable[i]->clickRight(false);
  1746. }
  1747. else
  1748. rclickable[i]->clickRight(boost::logic::indeterminate);
  1749. }
  1750. }
  1751. current = NULL;
  1752. } //event end
  1753. int3 CPlayerInterface::repairScreenPos(int3 pos)
  1754. {
  1755. if(pos.x<=-Woff)
  1756. pos.x = -Woff+1;
  1757. if(pos.y<=-Hoff)
  1758. pos.y = -Hoff+1;
  1759. if(pos.x>CGI->mh->map->width - this->adventureInt->terrain.tilesw + Woff)
  1760. pos.x = CGI->mh->map->width - this->adventureInt->terrain.tilesw + Woff;
  1761. if(pos.y>CGI->mh->map->height - this->adventureInt->terrain.tilesh + Hoff)
  1762. pos.y = CGI->mh->map->height - this->adventureInt->terrain.tilesh + Hoff;
  1763. return pos;
  1764. }
  1765. void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)
  1766. {
  1767. SDL_FreeSurface(graphics->heroWins[hero->subID]);//TODO: moznaby zmieniac jedynie fragment bitmapy zwiazany z dana umiejetnoscia
  1768. graphics->heroWins[hero->subID] = infoWin(hero); //a nie przerysowywac calosc. Troche roboty, obecnie chyba nie wartej swieczki.
  1769. if (adventureInt->selection.selected == hero)
  1770. adventureInt->infoBar.draw();
  1771. return;
  1772. }
  1773. void CPlayerInterface::receivedResource(int type, int val)
  1774. {
  1775. adventureInt->resdatabar.draw();
  1776. }
  1777. void CPlayerInterface::showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID)
  1778. {
  1779. adventureInt->hide(); //dezaktywacja starego interfejsu
  1780. CSelWindow * temp = CMessage::genSelWindow(text,LOCPLINT->playerID,35,components,playerID);
  1781. LOCPLINT->objsToBlit.push_back(temp);
  1782. temp->pos.x=300-(temp->pos.w/2);
  1783. temp->pos.y=300-(temp->pos.h/2);
  1784. temp->okb.pos.x = temp->okb.posr.x + temp->pos.x;
  1785. temp->okb.pos.y = temp->okb.posr.y + temp->pos.y;
  1786. temp->okb.activate();
  1787. for (int i=0;i<temp->components.size();i++)
  1788. {
  1789. temp->components[i]->activate();
  1790. temp->components[i]->pos.x += temp->pos.x;
  1791. temp->components[i]->pos.y += temp->pos.y;
  1792. }
  1793. temp->ID = askID;
  1794. components[0]->clickLeft(true);
  1795. }
  1796. void CPlayerInterface::heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town)
  1797. {
  1798. openTownWindow(town);
  1799. }
  1800. void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj)
  1801. {
  1802. boost::unique_lock<boost::mutex> un(*pim);
  1803. if(obj->ID == 34) //hero
  1804. {
  1805. const CGHeroInstance * hh;
  1806. if(hh = dynamic_cast<const CGHeroInstance*>(obj))
  1807. {
  1808. SDL_FreeSurface(graphics->heroWins[hh->subID]);
  1809. graphics->heroWins[hh->subID] = infoWin(hh);
  1810. }
  1811. CHeroWindow * hw = dynamic_cast<CHeroWindow *>(curint);
  1812. if(hw)
  1813. {
  1814. hw->garInt->recreateSlots();
  1815. hw->garInt->show();
  1816. }
  1817. else if(castleInt == curint) //opened town window - redraw town garrsion slots (change is within hero garr)
  1818. {
  1819. castleInt->garr->highlighted = NULL;
  1820. castleInt->garr->recreateSlots();
  1821. }
  1822. }
  1823. else if (obj->ID == 98) //town
  1824. {
  1825. const CGTownInstance * tt;
  1826. if(tt = dynamic_cast<const CGTownInstance*>(obj))
  1827. {
  1828. SDL_FreeSurface(graphics->townWins[tt->identifier]);
  1829. graphics->townWins[tt->identifier] = infoWin(tt);
  1830. }
  1831. const CCastleInterface *ci = dynamic_cast<CCastleInterface*>(curint);
  1832. if(ci)
  1833. {
  1834. ci->garr->highlighted = NULL;
  1835. ci->garr->recreateSlots();
  1836. }
  1837. }
  1838. }
  1839. void CPlayerInterface::buildChanged(const CGTownInstance *town, int buildingID, int what) //what: 1 - built, 2 - demolished
  1840. {
  1841. if(curint!=castleInt)
  1842. return;
  1843. if(castleInt->town!=town)
  1844. return;
  1845. boost::unique_lock<boost::mutex> un(*pim);
  1846. switch(what)
  1847. {
  1848. case 1:
  1849. castleInt->addBuilding(buildingID);
  1850. break;
  1851. case 2:
  1852. castleInt->removeBuilding(buildingID);
  1853. break;
  1854. }
  1855. }
  1856. 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
  1857. {
  1858. curint->deactivate();
  1859. curint = new CBattleInterface(army1,army2,hero1,hero2);
  1860. curint->activate();
  1861. LOCPLINT->objsToBlit.push_back(dynamic_cast<IShowable*>(curint));
  1862. }
  1863. void CPlayerInterface::battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles) //called when battlefield is prepared, prior the battle beginning
  1864. {
  1865. }
  1866. 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
  1867. {
  1868. dynamic_cast<CBattleInterface*>(curint)->newRound(round);
  1869. }
  1870. void CPlayerInterface::actionStarted(BattleAction action)//occurs BEFORE every action taken by any stack or by the hero
  1871. {
  1872. }
  1873. void CPlayerInterface::actionFinished(BattleAction action)//occurs AFTER every action taken by any stack or by the hero
  1874. {
  1875. //dynamic_cast<CBattleInterface*>(curint)->givenCommand = -1;
  1876. }
  1877. BattleAction CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack
  1878. {
  1879. unsigned char showCount = 0;
  1880. dynamic_cast<CBattleInterface*>(curint)->stackActivated(stackID);
  1881. while(!dynamic_cast<CBattleInterface*>(curint)->givenCommand) //while current unit can perform an action
  1882. {
  1883. ++showCount;
  1884. SDL_Event sEvent;
  1885. while (SDL_PollEvent(&sEvent)) //wait for event...
  1886. {
  1887. LOCPLINT->handleEvent(&sEvent);
  1888. }
  1889. if(showCount%2==0)
  1890. for(int i=0;i<objsToBlit.size();i++)
  1891. objsToBlit[i]->show();
  1892. //SDL_Flip(screen);
  1893. CSDL_Ext::update(screen);
  1894. /*timeHandler th;
  1895. th.getDif();
  1896. int tv = th.getDif();
  1897. for (int i=0;i<((CBattleInterface*)this->curint)->timeinterested.size();i++)
  1898. {
  1899. if (timeinterested[i]->toNextTick>=0)
  1900. timeinterested[i]->toNextTick-=tv;
  1901. if (timeinterested[i]->toNextTick<0)
  1902. timeinterested[i]->tick();
  1903. }*/
  1904. SDL_Delay(1); //give time for other apps
  1905. SDL_framerateDelay(mainFPSmng);
  1906. }
  1907. BattleAction ret = *(dynamic_cast<CBattleInterface*>(curint)->givenCommand);
  1908. delete dynamic_cast<CBattleInterface*>(curint)->givenCommand;
  1909. dynamic_cast<CBattleInterface*>(curint)->givenCommand = NULL;
  1910. return ret;
  1911. }
  1912. void CPlayerInterface::battleEnd(CCreatureSet * army1, CCreatureSet * army2, CArmedInstance *hero1, CArmedInstance *hero2, std::vector<int> capturedArtifacts, int expForWinner, bool winner)
  1913. {
  1914. dynamic_cast<CBattleInterface*>(curint)->deactivate();
  1915. LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),dynamic_cast<IShowable*>(curint)));
  1916. delete dynamic_cast<CBattleInterface*>(curint);
  1917. curint = adventureInt;
  1918. adventureInt->activate();
  1919. }
  1920. void CPlayerInterface::battleStackMoved(int ID, int dest, bool startMoving, bool endMoving)
  1921. {
  1922. dynamic_cast<CBattleInterface*>(curint)->stackMoved(ID, dest, startMoving, endMoving);
  1923. }
  1924. void CPlayerInterface::battleStackAttacking(int ID, int dest)
  1925. {
  1926. dynamic_cast<CBattleInterface*>(curint)->stackAttacking(ID, dest);
  1927. }
  1928. void CPlayerInterface::battleStackIsAttacked(int ID, int dmg, int killed, int IDby)
  1929. {
  1930. dynamic_cast<CBattleInterface*>(curint)->stackIsAttacked(ID, dmg, killed, IDby);
  1931. }
  1932. void CPlayerInterface::battleStackKilled(int ID, int dmg, int killed, int IDby)
  1933. {
  1934. dynamic_cast<CBattleInterface*>(curint)->stackKilled(ID, dmg, killed, IDby);
  1935. }
  1936. void CPlayerInterface::showComp(SComponent comp)
  1937. {
  1938. adventureInt->infoBar.showComp(&comp,4000);
  1939. }
  1940. void CPlayerInterface::showInfoDialog(std::string text, std::vector<Component*> &components)
  1941. {
  1942. curint->deactivate(); //dezaktywacja starego interfejsu
  1943. std::vector<SComponent*> intComps;
  1944. for(int i=0;i<components.size();i++)
  1945. intComps.push_back(new SComponent(*components[i]));
  1946. CInfoWindow * temp = CMessage::genIWindow(text,LOCPLINT->playerID,32,intComps);
  1947. LOCPLINT->objsToBlit.push_back(temp);
  1948. temp->pos.x=300-(temp->pos.w/2);
  1949. temp->pos.y=300-(temp->pos.h/2);
  1950. temp->okb.pos.x = temp->okb.posr.x + temp->pos.x;
  1951. temp->okb.pos.y = temp->okb.posr.y + temp->pos.y;
  1952. temp->okb.activate();
  1953. for (int i=0;i<temp->components.size();i++)
  1954. {
  1955. temp->components[i]->activate();
  1956. temp->components[i]->pos.x += temp->pos.x;
  1957. temp->components[i]->pos.y += temp->pos.y;
  1958. }
  1959. }
  1960. void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*> & components)
  1961. {
  1962. curint->deactivate(); //dezaktywacja starego interfejsu
  1963. CInfoWindow * temp = CMessage::genIWindow(text,LOCPLINT->playerID,32,components);
  1964. LOCPLINT->objsToBlit.push_back(temp);
  1965. temp->pos.x=300-(temp->pos.w/2);
  1966. temp->pos.y=300-(temp->pos.h/2);
  1967. temp->okb.pos.x = temp->okb.posr.x + temp->pos.x;
  1968. temp->okb.pos.y = temp->okb.posr.y + temp->pos.y;
  1969. temp->okb.activate();
  1970. for (int i=0;i<temp->components.size();i++)
  1971. {
  1972. temp->components[i]->activate();
  1973. temp->components[i]->pos.x += temp->pos.x;
  1974. temp->components[i]->pos.y += temp->pos.y;
  1975. }
  1976. }
  1977. void CPlayerInterface::removeObjToBlit(IShowable* obj)
  1978. {
  1979. objsToBlit.erase
  1980. (std::find(objsToBlit.begin(),objsToBlit.end(),obj));
  1981. //delete obj;
  1982. }
  1983. void CPlayerInterface::tileRevealed(int3 pos)
  1984. {
  1985. adventureInt->minimap.showTile(pos);
  1986. }
  1987. void CPlayerInterface::tileHidden(int3 pos)
  1988. {
  1989. adventureInt->minimap.hideTile(pos);
  1990. }
  1991. void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero)
  1992. {
  1993. adventureInt->heroWindow->setHero(hero);
  1994. this->objsToBlit.push_back(adventureInt->heroWindow);
  1995. adventureInt->hide();
  1996. adventureInt->heroWindow->activate();
  1997. }
  1998. CStatusBar::CStatusBar(int x, int y, std::string name, int maxw)
  1999. {
  2000. bg=BitmapHandler::loadBitmap(name);
  2001. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  2002. pos.x=x;
  2003. pos.y=y;
  2004. if(maxw >= 0)
  2005. pos.w = min(bg->w,maxw);
  2006. else
  2007. pos.w=bg->w;
  2008. pos.h=bg->h;
  2009. middlex=(pos.w/2)+x;
  2010. middley=(bg->h/2)+y;
  2011. }
  2012. CStatusBar::~CStatusBar()
  2013. {
  2014. SDL_FreeSurface(bg);
  2015. }
  2016. void CStatusBar::clear()
  2017. {
  2018. current="";
  2019. SDL_Rect pom = genRect(pos.h,pos.w,pos.x,pos.y);
  2020. SDL_BlitSurface(bg,&genRect(pos.h,pos.w,0,0),screen,&pom);
  2021. }
  2022. void CStatusBar::print(std::string text)
  2023. {
  2024. current=text;
  2025. SDL_Rect pom = genRect(pos.h,pos.w,pos.x,pos.y);
  2026. SDL_BlitSurface(bg,&genRect(pos.h,pos.w,0,0),screen,&pom);
  2027. printAtMiddle(current,middlex,middley,GEOR13,zwykly);
  2028. }
  2029. void CStatusBar::show()
  2030. {
  2031. SDL_Rect pom = genRect(pos.h,pos.w,pos.x,pos.y);
  2032. SDL_BlitSurface(bg,&genRect(pos.h,pos.w,0,0),screen,&pom);
  2033. printAtMiddle(current,middlex,middley,GEOR13,zwykly);
  2034. }
  2035. std::string CStatusBar::getCurrent()
  2036. {
  2037. return current;
  2038. }
  2039. void CList::activate()
  2040. {
  2041. ClickableL::activate();
  2042. ClickableR::activate();
  2043. Hoverable::activate();
  2044. KeyInterested::activate();
  2045. MotionInterested::activate();
  2046. };
  2047. void CList::deactivate()
  2048. {
  2049. ClickableL::deactivate();
  2050. ClickableR::deactivate();
  2051. Hoverable::deactivate();
  2052. KeyInterested::deactivate();
  2053. MotionInterested::deactivate();
  2054. };
  2055. void CList::clickLeft(tribool down)
  2056. {
  2057. };
  2058. CList::CList(int Size)
  2059. :SIZE(Size)
  2060. {
  2061. }
  2062. CHeroList::CHeroList(int Size)
  2063. :CList(Size)
  2064. {
  2065. pos = genRect(192,64,609,196);
  2066. arrupp = genRect(16,64,609,196);
  2067. arrdop = genRect(16,64,609,372);
  2068. //32px per hero
  2069. posmobx = 610;
  2070. posmoby = 213;
  2071. posporx = 617;
  2072. pospory = 212;
  2073. posmanx = 666;
  2074. posmany = 213;
  2075. arrup = CDefHandler::giveDef("IAM012.DEF");
  2076. arrdo = CDefHandler::giveDef("IAM013.DEF");
  2077. mobile = CDefHandler::giveDef("IMOBIL.DEF");
  2078. mana = CDefHandler::giveDef("IMANA.DEF");
  2079. empty = BitmapHandler::loadBitmap("HPSXXX.bmp");
  2080. selection = BitmapHandler::loadBitmap("HPSYYY.bmp");
  2081. SDL_SetColorKey(selection,SDL_SRCCOLORKEY,SDL_MapRGB(selection->format,0,255,255));
  2082. from = 0;
  2083. pressed = indeterminate;
  2084. }
  2085. void CHeroList::init()
  2086. {
  2087. bg = CSDL_Ext::newSurface(68,193,screen);
  2088. SDL_BlitSurface(LOCPLINT->adventureInt->bg,&genRect(193,68,607,196),bg,&genRect(193,68,0,0));
  2089. }
  2090. void CHeroList::genList()
  2091. {
  2092. int howMany = LOCPLINT->cb->howManyHeroes();
  2093. for (int i=0;i<howMany;i++)
  2094. {
  2095. items.push_back(std::pair<const CGHeroInstance *,CPath *>(LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,i,0),NULL));
  2096. }
  2097. }
  2098. void CHeroList::select(int which)
  2099. {
  2100. if (which<0)
  2101. {
  2102. selected = which;
  2103. LOCPLINT->adventureInt->selection.selected = LOCPLINT->adventureInt->terrain.currentPath = NULL;
  2104. draw();
  2105. LOCPLINT->adventureInt->infoBar.draw(NULL);
  2106. }
  2107. if (which>=items.size())
  2108. return;
  2109. selected = which;
  2110. LOCPLINT->adventureInt->centerOn(items[which].first->pos);
  2111. LOCPLINT->adventureInt->selection.type = HEROI_TYPE;
  2112. LOCPLINT->adventureInt->selection.selected = items[which].first;
  2113. LOCPLINT->adventureInt->terrain.currentPath = items[which].second;
  2114. draw();
  2115. LOCPLINT->adventureInt->townList.draw();
  2116. LOCPLINT->adventureInt->infoBar.draw(NULL);
  2117. }
  2118. void CHeroList::clickLeft(tribool down)
  2119. {
  2120. if (down)
  2121. {
  2122. /***************************ARROWS*****************************************/
  2123. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  2124. {
  2125. blitAt(arrup->ourImages[1].bitmap,arrupp.x,arrupp.y);
  2126. pressed = true;
  2127. return;
  2128. }
  2129. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  2130. {
  2131. blitAt(arrdo->ourImages[1].bitmap,arrdop.x,arrdop.y);
  2132. pressed = false;
  2133. return;
  2134. }
  2135. /***************************HEROES*****************************************/
  2136. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2137. hx-=pos.x;
  2138. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2139. int ny = hy/32;
  2140. if (ny>=5 || ny<0)
  2141. return;
  2142. if ( (ny+from)==selected && (LOCPLINT->adventureInt->selection.type == HEROI_TYPE))
  2143. LOCPLINT->openHeroWindow(items[selected].first);//print hero screen
  2144. select(ny+from);
  2145. }
  2146. else
  2147. {
  2148. if (indeterminate(pressed))
  2149. return;
  2150. if (pressed) //up
  2151. {
  2152. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  2153. pressed = indeterminate;
  2154. if (!down)
  2155. {
  2156. from--;
  2157. if (from<0)
  2158. from=0;
  2159. draw();
  2160. }
  2161. }
  2162. else if (!pressed) //down
  2163. {
  2164. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  2165. pressed = indeterminate;
  2166. if (!down)
  2167. {
  2168. from++;
  2169. //if (from<items.size()-5)
  2170. // from=items.size()-5;
  2171. draw();
  2172. }
  2173. }
  2174. else
  2175. throw 0;
  2176. }
  2177. }
  2178. void CHeroList::mouseMoved (SDL_MouseMotionEvent & sEvent)
  2179. {
  2180. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  2181. {
  2182. if (from>0)
  2183. LOCPLINT->adventureInt->statusbar.print(CGI->preth->zelp[303].first);
  2184. else
  2185. LOCPLINT->adventureInt->statusbar.clear();
  2186. return;
  2187. }
  2188. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  2189. {
  2190. if ((items.size()-from) > 5)
  2191. LOCPLINT->adventureInt->statusbar.print(CGI->preth->zelp[304].first);
  2192. else
  2193. LOCPLINT->adventureInt->statusbar.clear();
  2194. return;
  2195. }
  2196. //if not buttons then heroes
  2197. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2198. hx-=pos.x;
  2199. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2200. int ny = hy/32;
  2201. if ((ny>5 || ny<0) || (from+ny>=items.size()))
  2202. {
  2203. LOCPLINT->adventureInt->statusbar.clear();
  2204. return;
  2205. }
  2206. std::vector<std::string> temp;
  2207. temp.push_back(items[from+ny].first->name);
  2208. temp.push_back(items[from+ny].first->type->heroClass->name);
  2209. LOCPLINT->adventureInt->statusbar.print( processStr(CGI->generaltexth->allTexts[15],temp) );
  2210. //select(ny+from);
  2211. }
  2212. void CHeroList::clickRight(tribool down)
  2213. {
  2214. if (down)
  2215. {
  2216. /***************************ARROWS*****************************************/
  2217. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  2218. {
  2219. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[303].second,down,this);
  2220. }
  2221. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  2222. {
  2223. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[304].second,down,this);
  2224. }
  2225. //if not buttons then heroes
  2226. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2227. hx-=pos.x;
  2228. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2229. int ny = hy/32;
  2230. if ((ny>5 || ny<0) || (from+ny>=items.size()))
  2231. {
  2232. return;
  2233. }
  2234. //show popup
  2235. 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);
  2236. ip->activate();
  2237. }
  2238. else
  2239. {
  2240. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[303].second,down,this);
  2241. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[304].second,down,this);
  2242. }
  2243. }
  2244. void CHeroList::hover (bool on)
  2245. {
  2246. }
  2247. void CHeroList::keyPressed (SDL_KeyboardEvent & key)
  2248. {
  2249. }
  2250. void CHeroList::updateHList()
  2251. {
  2252. items.clear();
  2253. genList();
  2254. if(selected>=items.size())
  2255. select(items.size()-1);
  2256. if(items.size()==0)
  2257. LOCPLINT->adventureInt->townList.select(0);
  2258. else
  2259. select(selected);
  2260. }
  2261. void CHeroList::updateMove(const CGHeroInstance* which) //draws move points bar
  2262. {
  2263. int ser = LOCPLINT->cb->getHeroSerial(which);
  2264. ser -= from;
  2265. int pom = (which->movement)/100;
  2266. blitAt(mobile->ourImages[pom].bitmap,posmobx,posmoby+ser*32); //move point
  2267. }
  2268. void CHeroList::draw()
  2269. {
  2270. for (int iT=0+from;iT<5+from;iT++)
  2271. {
  2272. int i = iT-from;
  2273. if (iT>=items.size())
  2274. {
  2275. blitAt(mobile->ourImages[0].bitmap,posmobx,posmoby+i*32);
  2276. blitAt(mana->ourImages[0].bitmap,posmanx,posmany+i*32);
  2277. blitAt(empty,posporx,pospory+i*32);
  2278. continue;
  2279. }
  2280. int pom = (LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->movement)/100;
  2281. if (pom>25) pom=25;
  2282. if (pom<0) pom=0;
  2283. blitAt(mobile->ourImages[pom].bitmap,posmobx,posmoby+i*32); //move point
  2284. pom = (LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->mana)/5; //bylo: .../10;
  2285. if (pom>25) pom=25;
  2286. if (pom<0) pom=0;
  2287. blitAt(mana->ourImages[pom].bitmap,posmanx,posmany+i*32); //mana
  2288. SDL_Surface * temp = graphics->portraitSmall[LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->subID];
  2289. blitAt(temp,posporx,pospory+i*32);
  2290. if ((selected == iT) && (LOCPLINT->adventureInt->selection.type == HEROI_TYPE))
  2291. {
  2292. blitAt(selection,posporx,pospory+i*32);
  2293. }
  2294. //TODO: support for custom portraits
  2295. }
  2296. if (from>0)
  2297. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  2298. else
  2299. blitAt(arrup->ourImages[2].bitmap,arrupp.x,arrupp.y);
  2300. if (items.size()-from>5)
  2301. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  2302. else
  2303. blitAt(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y);
  2304. }
  2305. CTownList::~CTownList()
  2306. {
  2307. delete arrup;
  2308. delete arrdo;
  2309. }
  2310. CTownList::CTownList(int Size, SDL_Rect * Pos, int arupx, int arupy, int ardox, int ardoy)
  2311. :CList(Size)
  2312. {
  2313. pos = *Pos;
  2314. arrup = CDefHandler::giveDef("IAM014.DEF");
  2315. arrdo = CDefHandler::giveDef("IAM015.DEF");
  2316. arrupp.x=arupx;
  2317. arrupp.y=arupy;
  2318. arrupp.w=arrup->ourImages[0].bitmap->w;
  2319. arrupp.h=arrup->ourImages[0].bitmap->h;
  2320. arrdop.x=ardox;
  2321. arrdop.y=ardoy;
  2322. arrdop.w=arrdo->ourImages[0].bitmap->w;
  2323. arrdop.h=arrdo->ourImages[0].bitmap->h;
  2324. posporx = arrdop.x;
  2325. pospory = arrupp.y + arrupp.h;
  2326. pressed = indeterminate;
  2327. from = 0;
  2328. }
  2329. void CTownList::genList()
  2330. {
  2331. int howMany = LOCPLINT->cb->howManyTowns();
  2332. for (int i=0;i<howMany;i++)
  2333. {
  2334. items.push_back(LOCPLINT->cb->getTownInfo(i,0));
  2335. }
  2336. }
  2337. void CTownList::select(int which)
  2338. {
  2339. if (which>=items.size())
  2340. return;
  2341. selected = which;
  2342. if(!fun.empty())
  2343. fun();
  2344. }
  2345. void CTownList::mouseMoved (SDL_MouseMotionEvent & sEvent)
  2346. {
  2347. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  2348. {
  2349. if (from>0)
  2350. LOCPLINT->statusbar->print(CGI->preth->zelp[306].first);
  2351. else
  2352. LOCPLINT->statusbar->clear();
  2353. return;
  2354. }
  2355. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  2356. {
  2357. if ((items.size()-from) > SIZE)
  2358. LOCPLINT->statusbar->print(CGI->preth->zelp[307].first);
  2359. else
  2360. LOCPLINT->statusbar->clear();
  2361. return;
  2362. }
  2363. //if not buttons then towns
  2364. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2365. hx-=pos.x;
  2366. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2367. int ny = hy/32;
  2368. if ((ny>SIZE || ny<0) || (from+ny>=items.size()))
  2369. {
  2370. LOCPLINT->statusbar->clear();
  2371. return;
  2372. };
  2373. LOCPLINT->statusbar->print(items[from+ny]->name);
  2374. }
  2375. void CTownList::clickLeft(tribool down)
  2376. {
  2377. if (down)
  2378. {
  2379. /***************************ARROWS*****************************************/
  2380. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  2381. {
  2382. blitAt(arrup->ourImages[1].bitmap,arrupp.x,arrupp.y);
  2383. pressed = true;
  2384. return;
  2385. }
  2386. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>SIZE))
  2387. {
  2388. blitAt(arrdo->ourImages[1].bitmap,arrdop.x,arrdop.y);
  2389. pressed = false;
  2390. return;
  2391. }
  2392. /***************************TOWNS*****************************************/
  2393. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2394. hx-=pos.x;
  2395. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2396. int ny = hy/32;
  2397. if (ny>SIZE || ny<0)
  2398. return;
  2399. if (SIZE==5 && (ny+from)==selected && (LOCPLINT->adventureInt->selection.type == TOWNI_TYPE))
  2400. LOCPLINT->openTownWindow(items[selected]);//print town screen
  2401. else
  2402. select(ny+from);
  2403. }
  2404. else
  2405. {
  2406. if (indeterminate(pressed))
  2407. return;
  2408. if (pressed) //up
  2409. {
  2410. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  2411. pressed = indeterminate;
  2412. if (!down)
  2413. {
  2414. from--;
  2415. if (from<0)
  2416. from=0;
  2417. draw();
  2418. }
  2419. }
  2420. else if (!pressed) //down
  2421. {
  2422. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  2423. pressed = indeterminate;
  2424. if (!down)
  2425. {
  2426. from++;
  2427. //if (from<items.size()-5)
  2428. // from=items.size()-5;
  2429. draw();
  2430. }
  2431. }
  2432. else
  2433. throw 0;
  2434. }
  2435. }
  2436. void CTownList::clickRight(tribool down)
  2437. {
  2438. if (down)
  2439. {
  2440. /***************************ARROWS*****************************************/
  2441. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  2442. {
  2443. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[306].second,down,this);
  2444. }
  2445. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  2446. {
  2447. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[307].second,down,this);
  2448. }
  2449. //if not buttons then towns
  2450. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2451. hx-=pos.x;
  2452. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2453. int ny = hy/32;
  2454. if ((ny>5 || ny<0) || (from+ny>=items.size()))
  2455. {
  2456. return;
  2457. }
  2458. //show popup
  2459. 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);
  2460. ip->activate();
  2461. }
  2462. else
  2463. {
  2464. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[306].second,down,this);
  2465. LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[307].second,down,this);
  2466. }
  2467. }
  2468. void CTownList::hover (bool on)
  2469. {
  2470. }
  2471. void CTownList::keyPressed (SDL_KeyboardEvent & key)
  2472. {
  2473. }
  2474. void CTownList::draw()
  2475. {
  2476. for (int iT=0+from;iT<SIZE+from;iT++)
  2477. {
  2478. int i = iT-from;
  2479. if (iT>=items.size())
  2480. {
  2481. blitAt(graphics->getPic(-1),posporx,pospory+i*32);
  2482. continue;
  2483. }
  2484. blitAt(graphics->getPic(items[iT]->subID,items[iT]->hasFort(),items[iT]->builded),posporx,pospory+i*32);
  2485. if ((selected == iT) && (LOCPLINT->adventureInt->selection.type == TOWNI_TYPE))
  2486. {
  2487. blitAt(graphics->getPic(-2),posporx,pospory+i*32);
  2488. }
  2489. }
  2490. if (from>0)
  2491. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  2492. else
  2493. blitAt(arrup->ourImages[2].bitmap,arrupp.x,arrupp.y);
  2494. if (items.size()-from>SIZE)
  2495. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  2496. else
  2497. blitAt(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y);
  2498. }
  2499. CCreaturePic::CCreaturePic(CCreature *cre)
  2500. :c(cre)
  2501. {
  2502. anim = new CCreatureAnimation(cre->animDefName);
  2503. }
  2504. CCreaturePic::~CCreaturePic()
  2505. {
  2506. delete anim;
  2507. }
  2508. int CCreaturePic::blitPic(SDL_Surface *to, int x, int y, bool nextFrame)
  2509. {
  2510. blitAt(graphics->backgrounds[c->faction],x,y);//curx-50,pos.y+130-65);
  2511. SDL_Rect dst = genRect(130,100,x,y);
  2512. if(c->isDoubleWide())
  2513. x-=15;
  2514. return anim->nextFrameMiddle(to,x+70,y+45,true,nextFrame,false,&dst);
  2515. }
  2516. SDL_Surface * CCreaturePic::getPic(bool nextFrame)
  2517. {
  2518. //TODO: write
  2519. return NULL;
  2520. }
  2521. void CRecrutationWindow::close()
  2522. {
  2523. deactivate();
  2524. delete this;
  2525. LOCPLINT->curint->activate();
  2526. CCastleInterface *pom;
  2527. if(pom=dynamic_cast<CCastleInterface*>(LOCPLINT->curint))
  2528. pom->showAll();
  2529. }
  2530. void CRecrutationWindow::Max()
  2531. {
  2532. slider->moveTo(slider->amount);
  2533. }
  2534. void CRecrutationWindow::Buy()
  2535. {
  2536. recruit(creatures[which].ID,slider->value);
  2537. close();
  2538. }
  2539. void CRecrutationWindow::Cancel()
  2540. {
  2541. close();
  2542. }
  2543. void CRecrutationWindow::sliderMoved(int to)
  2544. {
  2545. }
  2546. void CRecrutationWindow::clickLeft(tribool down)
  2547. {
  2548. int curx = 192 + 51 - (102*creatures.size()/2) - (18*(creatures.size()-1)/2);
  2549. for(int i=0;i<creatures.size();i++)
  2550. {
  2551. if(isItIn(&genRect(132,102,pos.x+curx,pos.y+64),LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  2552. {
  2553. which = i;
  2554. int newAmount = min(amounts[i],creatures[i].amount);
  2555. slider->amount = newAmount;
  2556. if(slider->value > newAmount)
  2557. slider->moveTo(newAmount);
  2558. else
  2559. slider->moveTo(slider->value);
  2560. curx = 192 + 51 - (102*creatures.size()/2) - (18*(creatures.size()-1)/2);
  2561. for(int j=0;j<creatures.size();j++)
  2562. {
  2563. if(which==j)
  2564. drawBorder(bitmap,curx,64,102,132,int3(255,0,0));
  2565. else
  2566. drawBorder(bitmap,curx,64,102,132,int3(239,215,123));
  2567. curx += 120;
  2568. }
  2569. break;
  2570. }
  2571. curx += 120;
  2572. }
  2573. }
  2574. void CRecrutationWindow::activate()
  2575. {
  2576. LOCPLINT->objsToBlit.push_back(this);
  2577. ClickableL::activate();
  2578. buy->activate();
  2579. max->activate();
  2580. cancel->activate();
  2581. slider->activate();
  2582. }
  2583. void CRecrutationWindow::deactivate()
  2584. {
  2585. LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
  2586. ClickableL::deactivate();
  2587. buy->deactivate();
  2588. max->deactivate();
  2589. cancel->deactivate();
  2590. slider->deactivate();
  2591. }
  2592. void CRecrutationWindow::show(SDL_Surface * to)
  2593. {
  2594. static char c=0;
  2595. blitAt(bitmap,pos.x,pos.y,to?to:screen);
  2596. buy->show();
  2597. max->show();
  2598. cancel->show();
  2599. slider->show();
  2600. char pom[15];
  2601. itoa(creatures[which].amount,pom,10); //available
  2602. printAtMiddle(pom,pos.x+205,pos.y+252,GEOR13,zwykly,screen);
  2603. itoa(slider->value,pom,10); //recruit
  2604. printAtMiddle(pom,pos.x+279,pos.y+252,GEOR13,zwykly,screen);
  2605. 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"
  2606. int curx = pos.x+115-creatures[which].res.size()*16;
  2607. for(int i=0;i<creatures[which].res.size();i++)
  2608. {
  2609. blitAt(graphics->resources32->ourImages[creatures[which].res[i].first].bitmap,curx,pos.y+243,screen);
  2610. blitAt(graphics->resources32->ourImages[creatures[which].res[i].first].bitmap,curx+258,pos.y+243,screen);
  2611. itoa(creatures[which].res[i].second,pom,10);
  2612. printAtMiddle(pom,curx+12,pos.y+286,GEOR13,zwykly,screen);
  2613. itoa(creatures[which].res[i].second * slider->value,pom,10);
  2614. printAtMiddle(pom,curx+12+258,pos.y+286,GEOR13,zwykly,screen);
  2615. curx+=32;
  2616. }
  2617. curx = pos.x + 192 + 102 - (102*creatures.size()/2) - (18*(creatures.size()-1)/2);
  2618. for(int i=0;i<creatures.size();i++)
  2619. {
  2620. creatures[i].pic->blitPic(screen,curx-50,pos.y+130-65,!(c%2));
  2621. curx += 120;
  2622. }
  2623. c++;
  2624. }
  2625. CRecrutationWindow::CRecrutationWindow(const std::vector<std::pair<int,int> > &Creatures, const boost::function<void(int,int)> &Recruit) //creatures - pairs<creature_ID,amount>
  2626. :recruit(Recruit)
  2627. {
  2628. which = 0;
  2629. creatures.resize(Creatures.size());
  2630. amounts.resize(Creatures.size());
  2631. for(int i=0;i<creatures.size();i++)
  2632. {
  2633. creatures[i].amount = Creatures[i].second;
  2634. creatures[i].ID = Creatures[i].first;
  2635. for(int j=0;j<CGI->creh->creatures[Creatures[i].first].cost.size();j++)
  2636. if(CGI->creh->creatures[Creatures[i].first].cost[j])
  2637. creatures[i].res.push_back(std::make_pair(j,CGI->creh->creatures[Creatures[i].first].cost[j]));
  2638. creatures[i].pic = new CCreaturePic(&CGI->creh->creatures[Creatures[i].first]);
  2639. amounts[i] = CGI->creh->creatures[Creatures[i].first].maxAmount(LOCPLINT->cb->getResourceAmount());
  2640. }
  2641. SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPRCRT.bmp");
  2642. graphics->blueToPlayersAdv(hhlp,LOCPLINT->playerID);
  2643. bitmap = SDL_ConvertSurface(hhlp,screen->format,0); //na 8bitowej mapie by sie psulo
  2644. SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
  2645. SDL_FreeSurface(hhlp);
  2646. pos.x = screen->w/2 - bitmap->w/2;
  2647. pos.y = screen->h/2 - bitmap->h/2;
  2648. pos.w = bitmap->w;
  2649. pos.h = bitmap->h;
  2650. 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);
  2651. std::string pom;
  2652. printAtMiddle(CGI->generaltexth->allTexts[346],113,231,GEOR13,zwykly,bitmap); //cost per troop t
  2653. printAtMiddle(CGI->generaltexth->allTexts[465],205,231,GEOR13,zwykly,bitmap); //available t
  2654. printAtMiddle(CGI->generaltexth->allTexts[16],279,231,GEOR13,zwykly,bitmap); //recruit t
  2655. printAtMiddle(CGI->generaltexth->allTexts[466],373,231,GEOR13,zwykly,bitmap); //total cost t
  2656. drawBorder(bitmap,172,222,67,42,int3(239,215,123));
  2657. drawBorder(bitmap,246,222,67,42,int3(239,215,123));
  2658. drawBorder(bitmap,64,222,99,76,int3(239,215,123));
  2659. drawBorder(bitmap,322,222,99,76,int3(239,215,123));
  2660. drawBorder(bitmap,133,312,66,34,int3(173,142,66));
  2661. drawBorder(bitmap,211,312,66,34,int3(173,142,66));
  2662. drawBorder(bitmap,289,312,66,34,int3(173,142,66));
  2663. //border for creatures
  2664. int curx = 192 + 51 - (102*creatures.size()/2) - (18*(creatures.size()-1)/2);
  2665. for(int i=0;i<creatures.size();i++)
  2666. {
  2667. creatures[i].pos.x = curx+1;
  2668. creatures[i].pos.y = 65;
  2669. creatures[i].pos.w = 100;
  2670. creatures[i].pos.h = 130;
  2671. if(which==i)
  2672. drawBorder(bitmap,curx,64,102,132,int3(255,0,0));
  2673. else
  2674. drawBorder(bitmap,curx,64,102,132,int3(239,215,123));
  2675. curx += 120;
  2676. }
  2677. max = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Max,this),pos.x+134,pos.y+313,"IRCBTNS.DEF");
  2678. buy = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Buy,this),pos.x+212,pos.y+313,"IBY6432.DEF");
  2679. cancel = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Cancel,this),pos.x+290,pos.y+313,"ICN6432.DEF");
  2680. LOCPLINT->curint->deactivate();
  2681. //AdventureMapButton( std::string Name, std::string HelpBox, void(T::*Function)(),
  2682. //int x, int y, std::string defName, T* Owner, bool activ=false, std::vector<std::string> * add = NULL, bool playerColoredButton = true );//c-tor
  2683. }//(int x, int y, int totalw, T*Owner,void(T::*Moved)(int to), int Capacity, int Amount, int Value, bool Horizontal)
  2684. CRecrutationWindow::~CRecrutationWindow()
  2685. {
  2686. for(int i=0;i<creatures.size();i++)
  2687. {
  2688. delete creatures[i].pic;
  2689. }
  2690. delete max;
  2691. delete buy;
  2692. delete cancel;
  2693. SDL_FreeSurface(bitmap);
  2694. delete slider;
  2695. }
  2696. CSplitWindow::CSplitWindow(int cid, int max, CGarrisonInt *Owner)
  2697. {
  2698. c=cid;
  2699. slider = NULL;
  2700. gar = Owner;
  2701. bitmap = BitmapHandler::loadBitmap("GPUCRDIV.bmp");
  2702. SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
  2703. pos.x = screen->w/2 - bitmap->w/2;
  2704. pos.y = screen->h/2 - bitmap->h/2;
  2705. pos.w = bitmap->w;
  2706. pos.h = bitmap->h;
  2707. ok = new AdventureMapButton("","",boost::bind(&CSplitWindow::split,this),pos.x+20,pos.y+263,"IOK6432.DEF");
  2708. cancel = new AdventureMapButton("","",boost::bind(&CSplitWindow::close,this),pos.x+214,pos.y+263,"ICN6432.DEF");
  2709. slider = new CSlider(pos.x+21,pos.y+194,257,boost::bind(&CSplitWindow::sliderMoved,this,_1),1,max,0,true);
  2710. a1 = max;
  2711. a2 = 0;
  2712. anim = new CCreaturePic(&CGI->creh->creatures[cid]);
  2713. anim->anim->setType(1);
  2714. std::string title = CGI->generaltexth->allTexts[256];
  2715. boost::algorithm::replace_first(title,"%s",CGI->creh->creatures[cid].namePl);
  2716. printAtMiddle(title,150,34,GEOR16,tytulowy,bitmap);
  2717. }
  2718. CSplitWindow::~CSplitWindow()
  2719. {
  2720. SDL_FreeSurface(bitmap);
  2721. delete ok;
  2722. delete cancel;
  2723. delete slider;
  2724. delete anim;
  2725. }
  2726. void CSplitWindow::activate()
  2727. {
  2728. LOCPLINT->objsToBlit.push_back(this);
  2729. KeyInterested::activate();
  2730. ok->activate();
  2731. cancel->activate();
  2732. slider->activate();
  2733. }
  2734. void CSplitWindow::deactivate()
  2735. {
  2736. LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
  2737. KeyInterested::deactivate();
  2738. ok->deactivate();
  2739. cancel->deactivate();
  2740. slider->deactivate();
  2741. }
  2742. void CSplitWindow::split()
  2743. {
  2744. gar->splitStacks(a2);
  2745. close();
  2746. }
  2747. void CSplitWindow::close()
  2748. {
  2749. deactivate();
  2750. delete this;
  2751. LOCPLINT->curint->activate();
  2752. CCastleInterface *c = dynamic_cast<CCastleInterface*>(LOCPLINT->curint);
  2753. if(c) c->showAll();
  2754. }
  2755. void CSplitWindow::sliderMoved(int to)
  2756. {
  2757. a2 = to;
  2758. if(slider)
  2759. a1 = slider->amount - to;
  2760. }
  2761. void CSplitWindow::show(SDL_Surface * to)
  2762. {
  2763. char pom[15];
  2764. blitAt(bitmap,pos.x,pos.y,screen);
  2765. ok->show();
  2766. cancel->show();
  2767. slider->show();
  2768. itoa(a1,pom,10);
  2769. printAtMiddle(pom,pos.x+70,pos.y+237,GEOR16,zwykly,screen);
  2770. itoa(a2,pom,10);
  2771. printAtMiddle(pom,pos.x+233,pos.y+237,GEOR16,zwykly,screen);
  2772. anim->blitPic(screen,pos.x+20,pos.y+54,false);
  2773. anim->blitPic(screen,pos.x+177,pos.y+54,false);
  2774. }
  2775. void CSplitWindow::keyPressed (SDL_KeyboardEvent & key)
  2776. {
  2777. //TODO: make manual typing possible
  2778. }
  2779. void CCreInfoWindow::show(SDL_Surface * to)
  2780. {
  2781. char pom[15];
  2782. blitAt(bitmap,pos.x,pos.y,screen);
  2783. anim->blitPic(screen,pos.x+21,pos.y+48,(type) && anf);
  2784. anf=!anf;
  2785. if(upgrade)
  2786. upgrade->show();
  2787. if(dismiss)
  2788. dismiss->show();
  2789. if(ok)
  2790. ok->show();
  2791. }
  2792. CCreInfoWindow::CCreInfoWindow
  2793. (int Cid, int Type, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm)
  2794. :ok(0),dismiss(0),upgrade(0),type(Type),dsm(Dsm)
  2795. {
  2796. c = &CGI->creh->creatures[Cid];
  2797. bitmap = BitmapHandler::loadBitmap("CRSTKPU.bmp");
  2798. pos.x = screen->w/2 - bitmap->w/2;
  2799. pos.y = screen->h/2 - bitmap->h/2;
  2800. pos.w = bitmap->w;
  2801. pos.h = bitmap->h;
  2802. graphics->blueToPlayersAdv(bitmap,LOCPLINT->playerID);
  2803. SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
  2804. anim = new CCreaturePic(c);
  2805. if(!type) anim->anim->setType(1);
  2806. char pom[25];int hlp=0;
  2807. printAtMiddle(c->namePl,149,30,GEOR13,zwykly,bitmap); //creature name
  2808. //atttack
  2809. printAt(CGI->preth->zelp[435].first,155,48,GEOR13,zwykly,bitmap);
  2810. itoa(c->attack,pom,10);
  2811. if(State && State->attackBonus)
  2812. {
  2813. int hlp = log10f(c->attack)+2;
  2814. pom[hlp-1] = ' '; pom[hlp] = '(';
  2815. itoa(c->attack+State->attackBonus,pom+hlp+1,10);
  2816. hlp += 2+(int)log10f(State->attackBonus+c->attack);
  2817. pom[hlp] = ')'; pom[hlp+1] = '\0';
  2818. }
  2819. printToWR(pom,276,61,GEOR13,zwykly,bitmap);
  2820. //defense
  2821. printAt(CGI->preth->zelp[436].first,155,67,GEOR13,zwykly,bitmap);
  2822. itoa(c->defence,pom,10);
  2823. if(State && State->defenseBonus)
  2824. {
  2825. int hlp = log10f(c->defence)+2;
  2826. pom[hlp-1] = ' '; pom[hlp] = '(';
  2827. itoa(c->defence+State->defenseBonus,pom+hlp+1,10);
  2828. pom[hlp+2+(int)log10f(State->defenseBonus+c->defence)] = ')';
  2829. }
  2830. printToWR(pom,276,80,GEOR13,zwykly,bitmap);
  2831. //shots
  2832. if(c->shots)
  2833. {
  2834. printAt(CGI->generaltexth->allTexts[198],155,86,GEOR13,zwykly,bitmap);
  2835. itoa(c->shots,pom,10);
  2836. printToWR(pom,276,99,GEOR13,zwykly,bitmap);
  2837. }
  2838. //damage
  2839. printAt(CGI->generaltexth->allTexts[199],155,105,GEOR13,zwykly,bitmap);
  2840. itoa(c->damageMin,pom,10);
  2841. hlp=log10f(c->damageMin)+2;
  2842. pom[hlp-1]=' '; pom[hlp]='-'; pom[hlp+1]=' ';
  2843. itoa(c->damageMax,pom+hlp+2,10);
  2844. printToWR(pom,276,118,GEOR13,zwykly,bitmap);
  2845. //health
  2846. printAt(CGI->preth->zelp[439].first,155,124,GEOR13,zwykly,bitmap);
  2847. itoa(c->hitPoints,pom,10);
  2848. printToWR(pom,276,137,GEOR13,zwykly,bitmap);
  2849. //remaining health - TODO: show during the battles
  2850. //printAt(CGI->preth->zelp[440].first,155,143,GEOR13,zwykly,bitmap);
  2851. //speed
  2852. printAt(CGI->preth->zelp[441].first,155,162,GEOR13,zwykly,bitmap);
  2853. itoa(c->speed,pom,10);
  2854. printToWR(pom,276,175,GEOR13,zwykly,bitmap);
  2855. //luck and morale
  2856. blitAt(graphics->morale42->ourImages[(State)?(State->morale+3):(3)].bitmap,24,189,bitmap);
  2857. blitAt(graphics->luck42->ourImages[(State)?(State->luck+3):(3)].bitmap,77,189,bitmap);
  2858. //print abilities text - if r-click popup
  2859. if(type)
  2860. {
  2861. if(Upg)
  2862. upgrade = new AdventureMapButton("",CGI->preth->zelp[446].second,Upg,pos.x+76,pos.y+237,"IVIEWCR.DEF");
  2863. if(Dsm)
  2864. dismiss = new AdventureMapButton("",CGI->preth->zelp[445].second,boost::bind(&CCreInfoWindow::dismissF,this),pos.x+21,pos.y+237,"IVIEWCR2.DEF");
  2865. ok = new AdventureMapButton("",CGI->preth->zelp[445].second,boost::bind(&CCreInfoWindow::close,this),pos.x+216,pos.y+237,"IOKAY.DEF");
  2866. }
  2867. else
  2868. {
  2869. printAtWB(c->abilityText,17,231,GEOR13,35,zwykly,bitmap);
  2870. }
  2871. }
  2872. CCreInfoWindow::~CCreInfoWindow()
  2873. {
  2874. SDL_FreeSurface(bitmap);
  2875. delete anim;
  2876. delete upgrade;
  2877. delete ok;
  2878. delete dismiss;
  2879. }
  2880. void CCreInfoWindow::activate()
  2881. {
  2882. if(!type)
  2883. ClickableR::activate();
  2884. LOCPLINT->objsToBlit.push_back(this);
  2885. if(ok)
  2886. ok->activate();
  2887. if(dismiss)
  2888. dismiss->activate();
  2889. if(upgrade)
  2890. upgrade->activate();
  2891. if(type)
  2892. LOCPLINT->curint->deactivate();
  2893. }
  2894. void CCreInfoWindow::close()
  2895. {
  2896. deactivate();
  2897. CCastleInterface *c = dynamic_cast<CCastleInterface*>(LOCPLINT->curint);
  2898. if(c) c->showAll();
  2899. if(type)
  2900. LOCPLINT->curint->activate();
  2901. delete this;
  2902. }
  2903. void CCreInfoWindow::clickRight(boost::logic::tribool down)
  2904. {
  2905. if(down)
  2906. return;
  2907. close();
  2908. }
  2909. void CCreInfoWindow::dismissF()
  2910. {
  2911. dsm();
  2912. close();
  2913. }
  2914. void CCreInfoWindow::keyPressed (SDL_KeyboardEvent & key)
  2915. {
  2916. }
  2917. void CCreInfoWindow::deactivate()
  2918. {
  2919. if(!type)
  2920. ClickableR::deactivate();
  2921. LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
  2922. if(ok)
  2923. ok->deactivate();
  2924. if(dismiss)
  2925. dismiss->deactivate();
  2926. if(upgrade)
  2927. upgrade->deactivate();
  2928. }