2
0

CPlayerInterface.cpp 89 KB

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