CPlayerInterface.cpp 93 KB

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