CPlayerInterface.cpp 89 KB

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