CPlayerInterface.cpp 91 KB

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