CPlayerInterface.cpp 89 KB

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