CPlayerInterface.cpp 92 KB

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