CPlayerInterface.cpp 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215
  1. #include "stdafx.h"
  2. #include "CPlayerInterface.h"
  3. #include "CAdvMapInterface.h"
  4. #include "CMessage.h"
  5. #include "mapHandler.h"
  6. #include "SDL_Extensions.h"
  7. #include "SDL_framerate.h"
  8. #include "CScreenHandler.h"
  9. #include "CCursorHandler.h"
  10. #include "CCallback.h"
  11. #include "SDL_Extensions.h"
  12. #include "hch/CLodHandler.h"
  13. #include "CPathfinder.h"
  14. #include <sstream>
  15. #include "hch/CHeroHandler.h"
  16. #include "hch/CTownHandler.h"
  17. #include "SDL_framerate.h"
  18. #include "hch/CGeneralTextHandler.h"
  19. #include "CCastleInterface.h"
  20. #include "CHeroWindow.h"
  21. #include "timeHandler.h"
  22. #include <boost/algorithm/string.hpp>
  23. #include <boost/algorithm/string/replace.hpp>
  24. #include "hch\CPreGameTextHandler.h"
  25. using namespace CSDL_Ext;
  26. extern TTF_Font * GEOR16;
  27. class OCM_HLP_CGIN
  28. {
  29. public:
  30. bool operator ()(const std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> & a, const std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> & b) const
  31. {
  32. return (*a.first)<(*b.first);
  33. }
  34. } ocmptwo_cgin ;
  35. void CGarrisonSlot::hover (bool on)
  36. {
  37. Hoverable::hover(on);
  38. if(on)
  39. {
  40. std::string temp;
  41. if(creature)
  42. {
  43. if(owner->highlighted)
  44. {
  45. if(owner->highlighted == this)
  46. {
  47. temp = CGI->townh->tcommands[4];
  48. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  49. }
  50. else if (owner->highlighted->creature == creature)
  51. {
  52. temp = CGI->townh->tcommands[2];
  53. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  54. }
  55. else
  56. {
  57. temp = CGI->townh->tcommands[7];
  58. boost::algorithm::replace_first(temp,"%s",owner->highlighted->creature->nameSing);
  59. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  60. }
  61. }
  62. else
  63. {
  64. if(upg)
  65. {
  66. temp = CGI->townh->tcommands[32];
  67. }
  68. else
  69. {
  70. temp = CGI->townh->tcommands[12];
  71. }
  72. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  73. };
  74. }
  75. else
  76. {
  77. if(owner->highlighted)
  78. {
  79. temp = CGI->townh->tcommands[6];
  80. boost::algorithm::replace_first(temp,"%s",owner->highlighted->creature->nameSing);
  81. }
  82. else
  83. {
  84. temp = CGI->townh->tcommands[11];
  85. }
  86. }
  87. LOCPLINT->statusbar->print(temp);
  88. }
  89. else
  90. {
  91. LOCPLINT->statusbar->clear();
  92. }
  93. }
  94. void CGarrisonSlot::clickRight (tribool down)
  95. {
  96. }
  97. void CGarrisonSlot::clickLeft(tribool down)
  98. {
  99. if(owner->ignoreEvent)
  100. {
  101. owner->ignoreEvent = false;
  102. return;
  103. }
  104. if(down)
  105. {
  106. if(owner->highlighted)
  107. {
  108. LOCPLINT->cb->swapCreatures(
  109. (!upg)?(owner->oup):(owner->odown),
  110. (!owner->highlighted->upg)?(owner->oup):(owner->odown),
  111. ID,owner->highlighted->ID);
  112. owner->highlighted = NULL;
  113. owner->recreateSlots();
  114. }
  115. else
  116. {
  117. if(creature)
  118. owner->highlighted = this;
  119. }
  120. }
  121. }
  122. void CGarrisonSlot::activate()
  123. {
  124. ClickableL::activate();
  125. ClickableR::activate();
  126. Hoverable::activate();
  127. }
  128. void CGarrisonSlot::deactivate()
  129. {
  130. ClickableL::deactivate();
  131. ClickableR::deactivate();
  132. Hoverable::deactivate();
  133. }
  134. CGarrisonSlot::CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg, const CCreature * Creature, int Count)
  135. {
  136. upg = Upg;
  137. count = Count;
  138. ID = IID;
  139. creature = Creature;
  140. pos.x = x;
  141. pos.y = y;
  142. pos.w = 58;
  143. pos.h = 64;
  144. owner = Owner;
  145. }
  146. void CGarrisonSlot::show()
  147. {
  148. if(creature)
  149. {
  150. char* buf = new char[15];
  151. itoa(count,buf,10);
  152. blitAt(CGI->creh->bigImgs[creature->idNumber],pos);
  153. printTo(buf,pos.x+56,pos.y+62,GEOR16,zwykly);
  154. if(owner->highlighted==this)
  155. blitAt(CGI->creh->bigImgs[-1],pos);
  156. if(owner->update)
  157. updateRect(&pos,ekran);
  158. delete [] buf;
  159. }
  160. else
  161. {
  162. SDL_Rect jakis1 = genRect(pos.h,pos.w,owner->offx+ID*(pos.w+owner->interx),owner->offy+upg*(pos.h+owner->intery)), jakis2 = pos;
  163. SDL_BlitSurface(owner->sur,&jakis1,ekran,&jakis2);
  164. if(owner->update)
  165. SDL_UpdateRect(ekran,pos.x,pos.y,pos.w,pos.h);
  166. }
  167. }
  168. CGarrisonInt::~CGarrisonInt()
  169. {
  170. if(sup)
  171. {
  172. for(int i=0;i<sup->size();i++)
  173. delete (*sup)[i];
  174. delete sup;
  175. }
  176. if(sdown)
  177. {
  178. for(int i=0;i<sdown->size();i++)
  179. delete (*sdown)[i];
  180. delete sdown;
  181. }
  182. }
  183. void CGarrisonInt::show()
  184. {
  185. if(sup)
  186. {
  187. for(int i = 0; i<sup->size(); i++)
  188. if((*sup)[i])
  189. (*sup)[i]->show();
  190. }
  191. if(sdown)
  192. {
  193. for(int i = 0; i<sdown->size(); i++)
  194. if((*sdown)[i])
  195. (*sdown)[i]->show();
  196. }
  197. }
  198. void CGarrisonInt::deactiveteSlots()
  199. {
  200. if(sup)
  201. {
  202. for(int i = 0; i<sup->size(); i++)
  203. {
  204. if((*sup)[i])
  205. {
  206. (*sup)[i]->deactivate();
  207. }
  208. }
  209. }
  210. if(sdown)
  211. {
  212. for(int i = 0; i<sdown->size(); i++)
  213. {
  214. if((*sdown)[i])
  215. {
  216. (*sdown)[i]->deactivate();
  217. }
  218. }
  219. }
  220. }
  221. void CGarrisonInt::activeteSlots()
  222. {
  223. if(sup)
  224. {
  225. for(int i = 0; i<sup->size(); i++)
  226. {
  227. if((*sup)[i])
  228. {
  229. (*sup)[i]->activate();
  230. }
  231. }
  232. }
  233. if(sdown)
  234. {
  235. for(int i = 0; i<sdown->size(); i++)
  236. {
  237. if((*sdown)[i])
  238. {
  239. (*sdown)[i]->activate();
  240. }
  241. }
  242. }
  243. }
  244. void CGarrisonInt::createSlots()
  245. {
  246. if(set1)
  247. {
  248. sup = new std::vector<CGarrisonSlot*>(7,(CGarrisonSlot *)(NULL));
  249. for
  250. (std::map<int,std::pair<CCreature*,int> >::const_iterator i=set1->slots.begin();
  251. i!=set1->slots.end(); i++)
  252. {
  253. (*sup)[i->first] =
  254. new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y,i->first, 0, i->second.first,i->second.second);
  255. }
  256. for(int i=0; i<sup->size(); i++)
  257. if((*sup)[i] == NULL)
  258. (*sup)[i] = new CGarrisonSlot(this, pos.x + (i*(58+interx)), pos.y,i,0,NULL, 0);
  259. }
  260. if(set2)
  261. {
  262. sdown = new std::vector<CGarrisonSlot*>(7,(CGarrisonSlot *)(NULL));
  263. for
  264. (std::map<int,std::pair<CCreature*,int> >::const_iterator i=set2->slots.begin();
  265. i!=set2->slots.end(); i++)
  266. {
  267. (*sdown)[i->first] =
  268. new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y + 64 + intery,i->first,1, i->second.first,i->second.second);
  269. }
  270. for(int i=0; i<sup->size(); i++)
  271. if((*sdown)[i] == NULL)
  272. (*sdown)[i] = new CGarrisonSlot(this, pos.x + (i*(58+interx)), pos.y + 64 + intery,i,1, NULL, 0);
  273. }
  274. }
  275. void CGarrisonInt::deleteSlots()
  276. {
  277. if(sup)
  278. {
  279. for(int i = 0; i<sup->size(); i++)
  280. {
  281. if((*sup)[i])
  282. {
  283. delete (*sup)[i];
  284. }
  285. }
  286. }
  287. if(sdown)
  288. {
  289. for(int i = 0; i<sdown->size(); i++)
  290. {
  291. if((*sdown)[i])
  292. {
  293. delete (*sdown)[i];
  294. }
  295. }
  296. }
  297. }
  298. void CGarrisonInt::recreateSlots()
  299. {
  300. deactiveteSlots();
  301. deleteSlots();
  302. createSlots();
  303. ignoreEvent = true;
  304. activeteSlots();
  305. show();
  306. }
  307. CGarrisonInt::CGarrisonInt(int x, int y, int inx, int iny, SDL_Surface *pomsur, int OX, int OY, const CGObjectInstance *s1, const CGObjectInstance *s2)
  308. :interx(inx),intery(iny),sur(pomsur),highlighted(NULL),sup(NULL),sdown(NULL),oup(s1),odown(s2),
  309. offx(OX),offy(OY)
  310. {
  311. set1 = LOCPLINT->cb->getGarrison(s1);
  312. set2 = LOCPLINT->cb->getGarrison(s2);
  313. ignoreEvent = false;
  314. update = true;
  315. pos.x=(x);
  316. pos.y=(y);
  317. pos.w=(58);
  318. pos.h=(64);
  319. createSlots();
  320. }
  321. void CGarrisonInt::activate()
  322. {
  323. if(sup)
  324. {
  325. for(int i = 0; i<sup->size(); i++)
  326. if((*sup)[i])
  327. (*sup)[i]->activate();
  328. }
  329. if(sdown)
  330. {
  331. for(int i = 0; i<sdown->size(); i++)
  332. if((*sdown)[i])
  333. (*sdown)[i]->activate();
  334. }
  335. }
  336. void CGarrisonInt::deactivate()
  337. {
  338. deactiveteSlots();
  339. }
  340. CInfoWindow::CInfoWindow()
  341. :okb(NMessage::ok,NULL,&CInfoWindow::okClicked)
  342. {
  343. okb.ourObj = this;
  344. okb.delg = this;
  345. okb.notFreeButton=true;
  346. }
  347. void CInfoWindow::okClicked(tribool down)
  348. {
  349. if (!down)
  350. close();
  351. }
  352. void CInfoWindow::close()
  353. {
  354. for (int i=0;i<components.size();i++)
  355. {
  356. components[i]->deactivate();
  357. delete components[i];
  358. }
  359. components.clear();
  360. okb.deactivate();
  361. SDL_FreeSurface(bitmap);
  362. bitmap = NULL;
  363. LOCPLINT->removeObjToBlit(this);
  364. LOCPLINT->curint->activate();
  365. delete this;
  366. }
  367. CInfoWindow::~CInfoWindow()
  368. {
  369. }
  370. SComponent::SComponent(Etype Type, int Subtype, int Val)
  371. {
  372. std::ostringstream oss;
  373. switch (Type)
  374. {
  375. case primskill:
  376. description = CGI->generaltexth->arraytxt[2+Subtype];
  377. oss << ((Val>0)?("+"):("-")) << Val << " " << CGI->heroh->pskillsn[Subtype];
  378. subtitle = oss.str();
  379. break;
  380. case resource:
  381. description = CGI->generaltexth->allTexts[242];
  382. oss << Val;
  383. subtitle = oss.str();
  384. break;
  385. case experience:
  386. description = CGI->generaltexth->allTexts[241];
  387. oss << Val ;
  388. subtitle = oss.str();
  389. break;
  390. }
  391. type = Type;
  392. subtype = Subtype;
  393. val = Val;
  394. SDL_Surface * temp = getImg();
  395. pos.w = temp->w;
  396. pos.h = temp->h;
  397. }
  398. SDL_Surface * SComponent::getImg()
  399. {
  400. switch (type)
  401. {
  402. case primskill:
  403. return CGI->heroh->pskillsb->ourImages[subtype].bitmap;
  404. break;
  405. case secskill:
  406. return CGI->abilh->abils82->ourImages[subtype*3 + 3 + val].bitmap;
  407. break;
  408. case resource:
  409. return CGI->heroh->resources->ourImages[subtype].bitmap;
  410. break;
  411. case experience:
  412. return CGI->heroh->pskillsb->ourImages[4].bitmap;
  413. break;
  414. }
  415. return NULL;
  416. }
  417. void SComponent::clickRight (tribool down)
  418. {
  419. LOCPLINT->adventureInt->handleRightClick(description,down,this);
  420. }
  421. void SComponent::activate()
  422. {
  423. ClickableR::activate();
  424. }
  425. void SComponent::deactivate()
  426. {
  427. ClickableR::deactivate();
  428. }
  429. void CSelectableComponent::clickLeft(tribool down)
  430. {
  431. if (down)
  432. {
  433. select(true);
  434. owner->selectionChange(this);
  435. }
  436. }
  437. CSelectableComponent::CSelectableComponent(Etype Type, int Sub, int Val, CSelWindow * Owner, SDL_Surface * Border)
  438. :SComponent(Type,Sub,Val),owner(Owner)
  439. {
  440. SDL_Surface * symb = SComponent::getImg();
  441. myBitmap = CSDL_Ext::newSurface(symb->w+2,symb->h+2,ekran);
  442. SDL_SetColorKey(myBitmap,SDL_SRCCOLORKEY,SDL_MapRGB(myBitmap->format,0,255,255));
  443. blitAt(symb,1,1,myBitmap);
  444. if (Border) //use custom border
  445. {
  446. border = Border;
  447. customB = true;
  448. }
  449. else //we need to draw border
  450. {
  451. customB = false;
  452. border = CSDL_Ext::newSurface(symb->w+2,symb->h+2,ekran);
  453. SDL_FillRect(border,NULL,0x00FFFF);
  454. for (int i=0;i<border->w;i++)
  455. {
  456. SDL_PutPixel(border,i,0,239,215,123);
  457. SDL_PutPixel(border,i,(border->h)-1,239,215,123);
  458. }
  459. for (int i=0;i<border->h;i++)
  460. {
  461. SDL_PutPixel(border,0,i,239,215,123);
  462. SDL_PutPixel(border,(border->w)-1,i,239,215,123);
  463. }
  464. SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255));
  465. }
  466. selected = false;
  467. }
  468. CSelectableComponent::~CSelectableComponent()
  469. {
  470. SDL_FreeSurface(myBitmap);
  471. if (!customB)
  472. SDL_FreeSurface(border);
  473. }
  474. void CSelectableComponent::activate()
  475. {
  476. SComponent::activate();
  477. ClickableL::activate();
  478. }
  479. void CSelectableComponent::deactivate()
  480. {
  481. SComponent::deactivate();
  482. ClickableL::deactivate();
  483. }
  484. SDL_Surface * CSelectableComponent::getImg()
  485. {
  486. return myBitmap;
  487. }
  488. void CSelectableComponent::select(bool on)
  489. {
  490. if(on != selected)
  491. {
  492. SDL_FillRect(myBitmap,NULL,0x000000);
  493. blitAt(SComponent::getImg(),1,1,myBitmap);
  494. if (on)
  495. {
  496. blitAt(border,0,0,myBitmap);
  497. }
  498. selected = on;
  499. return;
  500. }
  501. else
  502. {
  503. return;
  504. }
  505. }
  506. void CSimpleWindow::show(SDL_Surface * to)
  507. {
  508. if(!to)
  509. to=ekran;
  510. blitAt(bitmap,pos.x,pos.y,to);
  511. }
  512. CSimpleWindow::~CSimpleWindow()
  513. {
  514. if (bitmap)
  515. {
  516. SDL_FreeSurface(bitmap);
  517. bitmap=NULL;
  518. }
  519. }
  520. void CSelWindow::selectionChange(CSelectableComponent * to)
  521. {
  522. blitAt(to->getImg(),to->pos.x-pos.x,to->pos.y-pos.y,bitmap);
  523. for (int i=0;i<components.size();i++)
  524. {
  525. if(components[i]==to)
  526. {
  527. if (to->selected)
  528. continue;
  529. else
  530. to->select(true);
  531. }
  532. CSelectableComponent * pom = dynamic_cast<CSelectableComponent*>(components[i]);
  533. if (!pom)
  534. continue;
  535. pom->select(false);
  536. blitAt(pom->getImg(),pom->pos.x-pos.x,pom->pos.y-pos.y,bitmap);
  537. }
  538. }
  539. void CSelWindow::okClicked(tribool down)
  540. {
  541. if(!down)
  542. close();
  543. }
  544. void CSelWindow::close()
  545. {
  546. int ret = -1;
  547. for (int i=0;i<components.size();i++)
  548. {
  549. if(dynamic_cast<CSelectableComponent*>(components[i])->selected)
  550. {
  551. ret = i;
  552. }
  553. components[i]->deactivate();
  554. }
  555. components.clear();
  556. okb.deactivate();
  557. SDL_FreeSurface(bitmap);
  558. bitmap = NULL;
  559. LOCPLINT->removeObjToBlit(this);
  560. LOCPLINT->curint->activate();
  561. LOCPLINT->cb->selectionMade(ret,ID);
  562. delete this;
  563. //call owner with selection result
  564. }
  565. template <typename T>CSCButton<T>::CSCButton(CDefHandler * img, CIntObject * obj, void(T::*poin)(tribool), T* Delg)
  566. {
  567. ourObj = obj;
  568. delg = Delg;
  569. func = poin;
  570. imgs.resize(1);
  571. for (int i =0; i<img->ourImages.size();i++)
  572. {
  573. imgs[0].push_back(img->ourImages[i].bitmap);
  574. }
  575. pos.w = imgs[0][0]->w;
  576. pos.h = imgs[0][0]->h;
  577. state = 0;
  578. }
  579. template <typename T> void CSCButton<T>::clickLeft (tribool down)
  580. {
  581. if (down)
  582. {
  583. state=1;
  584. }
  585. else
  586. {
  587. state=0;
  588. }
  589. pressedL=state;
  590. show();
  591. if (delg)
  592. (delg->*func)(down);
  593. }
  594. template <typename T> void CSCButton<typename T>::activate()
  595. {
  596. ClickableL::activate();
  597. }
  598. template <typename T> void CSCButton<typename T>::deactivate()
  599. {
  600. ClickableL::deactivate();
  601. }
  602. template <typename T> void CSCButton<typename T>::show(SDL_Surface * to)
  603. {
  604. if (delg) //we blit on our owner's bitmap
  605. {
  606. blitAt(imgs[curimg][state],posr.x,posr.y,delg->bitmap);
  607. //updateRect(&genRect(pos.h,pos.w,posr.x,posr.y),delg->bitmap);
  608. }
  609. else
  610. {
  611. CButtonBase::show(to);
  612. }
  613. }
  614. CButtonBase::CButtonBase()
  615. {
  616. bitmapOffset = 0;
  617. curimg=0;
  618. type=-1;
  619. abs=false;
  620. active=false;
  621. notFreeButton = false;
  622. ourObj=NULL;
  623. state=0;
  624. }
  625. CButtonBase::~CButtonBase()
  626. {
  627. if(notFreeButton)
  628. return;
  629. for(int i =0; i<imgs.size();i++)
  630. for(int j=0;j<imgs[i].size();j++)
  631. SDL_FreeSurface(imgs[i][j]);
  632. }
  633. void CButtonBase::show(SDL_Surface * to)
  634. {
  635. if(!to)
  636. to=ekran;
  637. if (abs)
  638. {
  639. blitAt(imgs[curimg][state+bitmapOffset],pos.x,pos.y,to);
  640. //updateRect(&pos,to);
  641. }
  642. else
  643. {
  644. blitAt(imgs[curimg][state+bitmapOffset],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y,to);
  645. //updateRect(&genRect(pos.h,pos.w,pos.x+ourObj->pos.x,pos.y+ourObj->pos.y),to);
  646. }
  647. }
  648. ClickableL::ClickableL()
  649. {
  650. pressedL=false;
  651. }
  652. void ClickableL::clickLeft(tribool down)
  653. {
  654. if (down)
  655. pressedL=true;
  656. else
  657. pressedL=false;
  658. }
  659. void ClickableL::activate()
  660. {
  661. LOCPLINT->lclickable.push_back(this);
  662. }
  663. void ClickableL::deactivate()
  664. {
  665. LOCPLINT->lclickable.erase
  666. (std::find(LOCPLINT->lclickable.begin(),LOCPLINT->lclickable.end(),this));
  667. }
  668. ClickableR::ClickableR()
  669. {
  670. pressedR=false;
  671. }
  672. void ClickableR::activate()
  673. {
  674. LOCPLINT->rclickable.push_back(this);
  675. }
  676. void ClickableR::deactivate()
  677. {
  678. LOCPLINT->rclickable.erase(std::find(LOCPLINT->rclickable.begin(),LOCPLINT->rclickable.end(),this));
  679. }
  680. void Hoverable::activate()
  681. {
  682. LOCPLINT->hoverable.push_back(this);
  683. }
  684. void Hoverable::deactivate()
  685. {
  686. LOCPLINT->hoverable.erase(std::find(LOCPLINT->hoverable.begin(),LOCPLINT->hoverable.end(),this));
  687. }
  688. void Hoverable::hover(bool on)
  689. {
  690. hovered=on;
  691. }
  692. void KeyInterested::activate()
  693. {
  694. LOCPLINT->keyinterested.push_back(this);
  695. }
  696. void KeyInterested::deactivate()
  697. {
  698. LOCPLINT->
  699. keyinterested.erase(std::find(LOCPLINT->keyinterested.begin(),LOCPLINT->keyinterested.end(),this));
  700. }
  701. void MotionInterested::activate()
  702. {
  703. LOCPLINT->motioninterested.push_back(this);
  704. }
  705. void MotionInterested::deactivate()
  706. {
  707. LOCPLINT->
  708. motioninterested.erase(std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this));
  709. }
  710. void TimeInterested::activate()
  711. {
  712. LOCPLINT->timeinterested.push_back(this);
  713. }
  714. void TimeInterested::deactivate()
  715. {
  716. LOCPLINT->
  717. timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),this));
  718. }
  719. CPlayerInterface::CPlayerInterface(int Player, int serial)
  720. {
  721. playerID=Player;
  722. serialID=serial;
  723. CGI->localPlayer = playerID;
  724. human=true;
  725. hInfo = CGI->bitmaph->loadBitmap("HEROQVBK.bmp");
  726. SDL_SetColorKey(hInfo,SDL_SRCCOLORKEY,SDL_MapRGB(hInfo->format,0,255,255));
  727. slotsPos.push_back(std::pair<int,int>(44,82));
  728. slotsPos.push_back(std::pair<int,int>(80,82));
  729. slotsPos.push_back(std::pair<int,int>(116,82));
  730. slotsPos.push_back(std::pair<int,int>(26,131));
  731. slotsPos.push_back(std::pair<int,int>(62,131));
  732. slotsPos.push_back(std::pair<int,int>(98,131));
  733. slotsPos.push_back(std::pair<int,int>(134,131));
  734. luck22 = CGI->spriteh->giveDefEss("ILCK22.DEF");
  735. luck30 = CGI->spriteh->giveDefEss("ILCK30.DEF");
  736. luck42 = CGI->spriteh->giveDefEss("ILCK42.DEF");
  737. luck82 = CGI->spriteh->giveDefEss("ILCK82.DEF");
  738. morale22 = CGI->spriteh->giveDefEss("IMRL22.DEF");
  739. morale30 = CGI->spriteh->giveDefEss("IMRL30.DEF");
  740. morale42 = CGI->spriteh->giveDefEss("IMRL42.DEF");
  741. morale82 = CGI->spriteh->giveDefEss("IMRL82.DEF");
  742. }
  743. void CPlayerInterface::init(ICallback * CB)
  744. {
  745. cb = dynamic_cast<CCallback*>(CB);
  746. CGI->localPlayer = serialID;
  747. adventureInt = new CAdvMapInt(playerID);
  748. castleInt = NULL;
  749. std::vector <const CGHeroInstance *> hh = cb->getHeroesInfo(false);
  750. for(int i=0;i<hh.size();i++)
  751. {
  752. SDL_Surface * pom = infoWin(hh[i]);
  753. heroWins.insert(std::pair<int,SDL_Surface*>(hh[i]->subID,pom));
  754. }
  755. }
  756. void CPlayerInterface::yourTurn()
  757. {
  758. makingTurn = true;
  759. CGI->localPlayer = serialID;
  760. unsigned char & animVal = LOCPLINT->adventureInt->anim; //for animations handling
  761. unsigned char & heroAnimVal = LOCPLINT->adventureInt->heroAnim;
  762. adventureInt->infoBar.newDay(cb->getDate(1));
  763. adventureInt->show();
  764. //show rest of things
  765. //initializing framerate keeper
  766. mainFPSmng = new FPSmanager;
  767. SDL_initFramerate(mainFPSmng);
  768. SDL_setFramerate(mainFPSmng, 24);
  769. SDL_Event sEvent;
  770. //framerate keeper initialized
  771. timeHandler th;
  772. th.getDif();
  773. for(;makingTurn;) // main loop
  774. {
  775. CGI->screenh->updateScreen();
  776. int tv = th.getDif();
  777. for (int i=0;i<timeinterested.size();i++)
  778. {
  779. if (timeinterested[i]->toNextTick>=0)
  780. timeinterested[i]->toNextTick-=tv;
  781. if (timeinterested[i]->toNextTick<0)
  782. timeinterested[i]->tick();
  783. }
  784. LOCPLINT->adventureInt->updateScreen = false;
  785. while (SDL_PollEvent(&sEvent)) //wait for event...
  786. {
  787. handleEvent(&sEvent);
  788. }
  789. if (!castleInt) //stuff for advMapInt
  790. {
  791. ++LOCPLINT->adventureInt->animValHitCount; //for animations
  792. if(LOCPLINT->adventureInt->animValHitCount == 4)
  793. {
  794. LOCPLINT->adventureInt->animValHitCount = 0;
  795. ++animVal;
  796. LOCPLINT->adventureInt->updateScreen = true;
  797. }
  798. ++heroAnimVal;
  799. if(LOCPLINT->adventureInt->scrollingLeft)
  800. {
  801. if(LOCPLINT->adventureInt->position.x>-Woff)
  802. {
  803. LOCPLINT->adventureInt->position.x--;
  804. LOCPLINT->adventureInt->updateScreen = true;
  805. adventureInt->updateMinimap=true;
  806. }
  807. }
  808. if(LOCPLINT->adventureInt->scrollingRight)
  809. {
  810. if(LOCPLINT->adventureInt->position.x<CGI->ac->map.width-19+4)
  811. {
  812. LOCPLINT->adventureInt->position.x++;
  813. LOCPLINT->adventureInt->updateScreen = true;
  814. adventureInt->updateMinimap=true;
  815. }
  816. }
  817. if(LOCPLINT->adventureInt->scrollingUp)
  818. {
  819. if(LOCPLINT->adventureInt->position.y>-Hoff)
  820. {
  821. LOCPLINT->adventureInt->position.y--;
  822. LOCPLINT->adventureInt->updateScreen = true;
  823. adventureInt->updateMinimap=true;
  824. }
  825. }
  826. if(LOCPLINT->adventureInt->scrollingDown)
  827. {
  828. if(LOCPLINT->adventureInt->position.y<CGI->ac->map.height-18+4)
  829. {
  830. LOCPLINT->adventureInt->position.y++;
  831. LOCPLINT->adventureInt->updateScreen = true;
  832. adventureInt->updateMinimap=true;
  833. }
  834. }
  835. if(LOCPLINT->adventureInt->updateScreen)
  836. {
  837. adventureInt->update();
  838. adventureInt->updateScreen=false;
  839. }
  840. if (LOCPLINT->adventureInt->updateMinimap)
  841. {
  842. adventureInt->minimap.draw();
  843. adventureInt->updateMinimap=false;
  844. }
  845. }
  846. for(int i=0;i<objsToBlit.size();i++)
  847. objsToBlit[i]->show();
  848. //SDL_Flip(ekran);
  849. CSDL_Ext::update(ekran);
  850. SDL_Delay(5); //give time for other apps
  851. SDL_framerateDelay(mainFPSmng);
  852. }
  853. adventureInt->hide();
  854. }
  855. inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, const int & hid)
  856. {
  857. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  858. for(int h=0; h<hlp.objects.size(); ++h)
  859. if(hlp.objects[h].first->id==hid)
  860. {
  861. hlp.objects[h].second.first = r;
  862. return;
  863. }
  864. }
  865. inline void delObjRect(const int & x, const int & y, const int & z, const int & hid)
  866. {
  867. TerrainTile2 & hlp = CGI->mh->ttiles[x][y][z];
  868. for(int h=0; h<hlp.objects.size(); ++h)
  869. if(hlp.objects[h].first->id==hid)
  870. {
  871. hlp.objects.erase(hlp.objects.begin()+h);
  872. return;
  873. }
  874. }
  875. int getDir(int3 src, int3 dst)
  876. {
  877. int ret = -1;
  878. if(dst.x+1 == src.x && dst.y+1 == src.y) //tl
  879. {
  880. ret = 1;
  881. }
  882. else if(dst.x == src.x && dst.y+1 == src.y) //t
  883. {
  884. ret = 2;
  885. }
  886. else if(dst.x-1 == src.x && dst.y+1 == src.y) //tr
  887. {
  888. ret = 3;
  889. }
  890. else if(dst.x-1 == src.x && dst.y == src.y) //r
  891. {
  892. ret = 4;
  893. }
  894. else if(dst.x-1 == src.x && dst.y-1 == src.y) //br
  895. {
  896. ret = 5;
  897. }
  898. else if(dst.x == src.x && dst.y-1 == src.y) //b
  899. {
  900. ret = 6;
  901. }
  902. else if(dst.x+1 == src.x && dst.y-1 == src.y) //bl
  903. {
  904. ret = 7;
  905. }
  906. else if(dst.x+1 == src.x && dst.y == src.y) //l
  907. {
  908. ret = 8;
  909. }
  910. return ret;
  911. }
  912. void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
  913. {
  914. //initializing objects and performing first step of move
  915. CGHeroInstance * ho = details.ho; //object representing this hero
  916. int3 hp = details.src;
  917. if (!details.successful)
  918. {
  919. ho->moveDir = getDir(details.src,details.dst);
  920. ho->isStanding = true;
  921. adventureInt->heroList.draw();
  922. if (adventureInt->terrain.currentPath)
  923. {
  924. delete adventureInt->terrain.currentPath;
  925. adventureInt->terrain.currentPath = NULL;
  926. }
  927. return;
  928. }
  929. if (adventureInt->terrain.currentPath) //&& hero is moving
  930. {
  931. adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
  932. }
  933. int3 buff = details.ho->pos;
  934. buff.x-=11;
  935. buff.y-=9;
  936. buff = repairScreenPos(buff);
  937. LOCPLINT->adventureInt->position = buff; //actualizing screen pos
  938. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  939. {
  940. ho->moveDir = 1;
  941. ho->isStanding = false;
  942. CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, -31), std::vector<std::list<int3>>())));
  943. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 1, -31), std::vector<std::list<int3>>())));
  944. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 33, -31), std::vector<std::list<int3>>())));
  945. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 65, -31), std::vector<std::list<int3>>())));
  946. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 1), std::vector<std::list<int3>>())));
  947. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 1), ho->id);
  948. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 1), ho->id);
  949. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 1), ho->id);
  950. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 33), std::vector<std::list<int3>>())));
  951. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 33), ho->id);
  952. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 33), ho->id);
  953. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 33), ho->id);
  954. 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);
  955. 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);
  956. 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);
  957. 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);
  958. 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);
  959. //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);
  960. //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);
  961. //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);
  962. 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);
  963. //std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  964. //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);
  965. //std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  966. }
  967. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  968. {
  969. ho->moveDir = 2;
  970. ho->isStanding = false;
  971. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 0, -31), std::vector<std::list<int3>>())));
  972. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 32, -31), std::vector<std::list<int3>>())));
  973. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 64, -31), std::vector<std::list<int3>>())));
  974. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1), ho->id);
  975. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1), ho->id);
  976. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1), ho->id);
  977. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33), ho->id);
  978. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33), ho->id);
  979. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33), ho->id);
  980. 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);
  981. 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);
  982. 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);
  983. //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);
  984. //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);
  985. //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);
  986. //std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  987. //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);
  988. //std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  989. }
  990. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  991. {
  992. ho->moveDir = 3;
  993. ho->isStanding = false;
  994. CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -1, -31), std::vector<std::list<int3>>())));
  995. CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 31, -31), std::vector<std::list<int3>>())));
  996. CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 63, -31), std::vector<std::list<int3>>())));
  997. CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, -31), std::vector<std::list<int3>>())));
  998. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 1), ho->id);
  999. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 1), ho->id);
  1000. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 1), ho->id);
  1001. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 1), std::vector<std::list<int3>>())));
  1002. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 33), ho->id);
  1003. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 33), ho->id);
  1004. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 33), ho->id);
  1005. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 33), std::vector<std::list<int3>>())));
  1006. 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);
  1007. 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);
  1008. 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);
  1009. 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);
  1010. //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);
  1011. //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);
  1012. //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);
  1013. 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);
  1014. //std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1015. //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);
  1016. //std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1017. 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);
  1018. }
  1019. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1020. {
  1021. ho->moveDir = 4;
  1022. ho->isStanding = false;
  1023. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id);
  1024. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id);
  1025. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id);
  1026. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 0), std::vector<std::list<int3>>())));
  1027. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 32), ho->id);
  1028. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 32), ho->id);
  1029. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 32), ho->id);
  1030. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 32), std::vector<std::list<int3>>())));
  1031. //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);
  1032. //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);
  1033. //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);
  1034. 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);
  1035. //std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1036. //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);
  1037. //std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1038. 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);
  1039. }
  1040. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1041. {
  1042. ho->moveDir = 5;
  1043. ho->isStanding = false;
  1044. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, -1), ho->id);
  1045. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, -1), ho->id);
  1046. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id);
  1047. CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, -1), std::vector<std::list<int3>>())));
  1048. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 31), ho->id);
  1049. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 31), ho->id);
  1050. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 31), ho->id);
  1051. CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 31), std::vector<std::list<int3>>())));
  1052. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -1, 63), std::vector<std::list<int3>>())));
  1053. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 31, 63), std::vector<std::list<int3>>())));
  1054. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 63, 63), std::vector<std::list<int3>>())));
  1055. CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 63), std::vector<std::list<int3>>())));
  1056. //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);
  1057. //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);
  1058. //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);
  1059. 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);
  1060. //std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1061. //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);
  1062. //std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1063. 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);
  1064. 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);
  1065. 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);
  1066. 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);
  1067. 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);
  1068. }
  1069. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1070. {
  1071. ho->moveDir = 6;
  1072. ho->isStanding = false;
  1073. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1), ho->id);
  1074. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1), ho->id);
  1075. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1), ho->id);
  1076. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31), ho->id);
  1077. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31), ho->id);
  1078. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31), ho->id);
  1079. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 0, 63), std::vector<std::list<int3>>())));
  1080. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 32, 63), std::vector<std::list<int3>>())));
  1081. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 64, 63), std::vector<std::list<int3>>())));
  1082. //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);
  1083. //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);
  1084. //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);
  1085. //std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1086. //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);
  1087. //std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1088. 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);
  1089. 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);
  1090. 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);
  1091. }
  1092. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1093. {
  1094. ho->moveDir = 7;
  1095. ho->isStanding = false;
  1096. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, -1), std::vector<std::list<int3>>())));
  1097. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id);
  1098. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id);
  1099. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, -1), ho->id);
  1100. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 31), std::vector<std::list<int3>>())));
  1101. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 31), ho->id);
  1102. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 31), ho->id);
  1103. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 31), ho->id);
  1104. CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 63), std::vector<std::list<int3>>())));
  1105. CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 1, 63), std::vector<std::list<int3>>())));
  1106. CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 33, 63), std::vector<std::list<int3>>())));
  1107. CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 65, 63), std::vector<std::list<int3>>())));
  1108. 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);
  1109. //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);
  1110. //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);
  1111. //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);
  1112. 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);
  1113. //std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1114. //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);
  1115. //std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1116. 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);
  1117. 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);
  1118. 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);
  1119. 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);
  1120. }
  1121. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1122. {
  1123. ho->moveDir = 8;
  1124. ho->isStanding = false;
  1125. CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 0), std::vector<std::list<int3>>())));
  1126. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id);
  1127. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id);
  1128. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 0), ho->id);
  1129. CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 32), std::vector<std::list<int3>>())));
  1130. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 32), ho->id);
  1131. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 32), ho->id);
  1132. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 32), ho->id);
  1133. 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);
  1134. //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);
  1135. //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);
  1136. //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);
  1137. 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);
  1138. //std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1139. //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);
  1140. //std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1141. }
  1142. //first initializing done
  1143. SDL_framerateDelay(mainFPSmng); // after first move
  1144. //main moving
  1145. for(int i=1; i<32; i+=4)
  1146. {
  1147. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  1148. {
  1149. subRect(hp.x-3, hp.y-2, hp.z, genRect(32, 32, -31+i, -31+i), ho->id);
  1150. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 1+i, -31+i), ho->id);
  1151. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 33+i, -31+i), ho->id);
  1152. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 65+i, -31+i), ho->id);
  1153. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 1+i), ho->id);
  1154. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 1+i), ho->id);
  1155. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 1+i), ho->id);
  1156. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 1+i), ho->id);
  1157. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 33+i), ho->id);
  1158. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 33+i), ho->id);
  1159. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 33+i), ho->id);
  1160. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 33+i), ho->id);
  1161. /*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);
  1162. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1163. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1164. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
  1165. 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);
  1166. 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);
  1167. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1168. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1169. 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);
  1170. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1171. 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);
  1172. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);*/
  1173. }
  1174. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  1175. {
  1176. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, 0, -31+i), ho->id);
  1177. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 32, -31+i), ho->id);
  1178. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 64, -31+i), ho->id);
  1179. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1+i), ho->id);
  1180. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1+i), ho->id);
  1181. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, 1+i), ho->id);
  1182. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 33+i), ho->id);
  1183. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 33+i), ho->id);
  1184. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 33+i), ho->id);
  1185. /*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);
  1186. 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);
  1187. 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);
  1188. 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);
  1189. 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);
  1190. 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);
  1191. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1192. 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);
  1193. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);*/
  1194. }
  1195. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  1196. {
  1197. subRect(hp.x-2, hp.y-2, hp.z, genRect(32, 32, -1-i, -31+i), ho->id);
  1198. subRect(hp.x-1, hp.y-2, hp.z, genRect(32, 32, 31-i, -31+i), ho->id);
  1199. subRect(hp.x, hp.y-2, hp.z, genRect(32, 32, 63-i, -31+i), ho->id);
  1200. subRect(hp.x+1, hp.y-2, hp.z, genRect(32, 32, 95-i, -31+i), ho->id);
  1201. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 1+i), ho->id);
  1202. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 1+i), ho->id);
  1203. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 1+i), ho->id);
  1204. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 1+i), ho->id);
  1205. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 33+i), ho->id);
  1206. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 33+i), ho->id);
  1207. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 33+i), ho->id);
  1208. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 33+i), ho->id);
  1209. /*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);
  1210. 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);
  1211. 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);
  1212. 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);
  1213. 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);
  1214. 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);
  1215. 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);
  1216. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
  1217. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1218. 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);
  1219. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1220. std::stable_sort(CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.end(), ocmptwo_cgin);*/
  1221. }
  1222. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1223. {
  1224. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, 0), ho->id);
  1225. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, 0), ho->id);
  1226. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, 0), ho->id);
  1227. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, 0), ho->id);
  1228. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 32), ho->id);
  1229. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 32), ho->id);
  1230. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 32), ho->id);
  1231. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 32), ho->id);
  1232. /*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);
  1233. 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);
  1234. 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);
  1235. 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);
  1236. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1237. 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);
  1238. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1239. 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);*/
  1240. }
  1241. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1242. {
  1243. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1-i, -1-i), ho->id);
  1244. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31-i, -1-i), ho->id);
  1245. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63-i, -1-i), ho->id);
  1246. subRect(hp.x+1, hp.y-1, hp.z, genRect(32, 32, 95-i, -1-i), ho->id);
  1247. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1-i, 31-i), ho->id);
  1248. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31-i, 31-i), ho->id);
  1249. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63-i, 31-i), ho->id);
  1250. subRect(hp.x+1, hp.y, hp.z, genRect(32, 32, 95-i, 31-i), ho->id);
  1251. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, -1-i, 63-i), ho->id);
  1252. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 31-i, 63-i), ho->id);
  1253. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 63-i, 63-i), ho->id);
  1254. subRect(hp.x+1, hp.y+1, hp.z, genRect(32, 32, 95-i, 63-i), ho->id);
  1255. /*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);
  1256. 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);
  1257. 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);
  1258. 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);
  1259. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1260. 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);
  1261. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1262. 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);
  1263. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1264. std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1265. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.end(), ocmptwo_cgin);
  1266. 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);*/
  1267. }
  1268. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1269. {
  1270. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, -1-i), ho->id);
  1271. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, -1-i), ho->id);
  1272. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 64, -1-i), ho->id);
  1273. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 0, 31-i), ho->id);
  1274. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31-i), ho->id);
  1275. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31-i), ho->id);
  1276. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 0, 63-i), ho->id);
  1277. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 32, 63-i), ho->id);
  1278. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 64, 63-i), ho->id);
  1279. /*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);
  1280. 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);
  1281. 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);
  1282. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1283. 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);
  1284. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1285. 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);
  1286. 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);
  1287. 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);*/
  1288. }
  1289. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1290. {
  1291. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, -1-i), ho->id);
  1292. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, -1-i), ho->id);
  1293. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, -1-i), ho->id);
  1294. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, -1-i), ho->id);
  1295. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 31-i), ho->id);
  1296. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 31-i), ho->id);
  1297. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 31-i), ho->id);
  1298. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 31-i), ho->id);
  1299. subRect(hp.x-3, hp.y+1, hp.z, genRect(32, 32, -31+i, 63-i), ho->id);
  1300. subRect(hp.x-2, hp.y+1, hp.z, genRect(32, 32, 1+i, 63-i), ho->id);
  1301. subRect(hp.x-1, hp.y+1, hp.z, genRect(32, 32, 33+i, 63-i), ho->id);
  1302. subRect(hp.x, hp.y+1, hp.z, genRect(32, 32, 65+i, 63-i), ho->id);
  1303. /*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);
  1304. 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);
  1305. 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);
  1306. 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);
  1307. 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);
  1308. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1309. 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);
  1310. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1311. 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);
  1312. 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);
  1313. 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);
  1314. 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);*/
  1315. }
  1316. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1317. {
  1318. subRect(hp.x-3, hp.y-1, hp.z, genRect(32, 32, -31+i, 0), ho->id);
  1319. subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1+i, 0), ho->id);
  1320. subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33+i, 0), ho->id);
  1321. subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65+i, 0), ho->id);
  1322. subRect(hp.x-3, hp.y, hp.z, genRect(32, 32, -31+i, 32), ho->id);
  1323. subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1+i, 32), ho->id);
  1324. subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33+i, 32), ho->id);
  1325. subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65+i, 32), ho->id);
  1326. /*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);
  1327. 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);
  1328. 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);
  1329. 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);
  1330. 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);
  1331. std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y][hp.z].objects.end(), ocmptwo_cgin);
  1332. 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);
  1333. std::stable_sort(CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.begin(), CGI->mh->ttiles[hp.x][hp.y][hp.z].objects.end(), ocmptwo_cgin);*/
  1334. }
  1335. LOCPLINT->adventureInt->update(); //updating screen
  1336. CSDL_Ext::update(ekran);
  1337. CGI->screenh->updateScreen();
  1338. ++LOCPLINT->adventureInt->animValHitCount; //for animations
  1339. if(LOCPLINT->adventureInt->animValHitCount == 4)
  1340. {
  1341. LOCPLINT->adventureInt->animValHitCount = 0;
  1342. ++LOCPLINT->adventureInt->anim;
  1343. LOCPLINT->adventureInt->updateScreen = true;
  1344. }
  1345. ++LOCPLINT->adventureInt->heroAnim;
  1346. SDL_framerateDelay(mainFPSmng); //for animation purposes
  1347. } //for(int i=1; i<32; i+=4)
  1348. //main moving done
  1349. //finishing move
  1350. if(details.dst.x+1 == details.src.x && details.dst.y+1 == details.src.y) //tl
  1351. {
  1352. delObjRect(hp.x, hp.y-2, hp.z, ho->id);
  1353. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1354. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1355. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1356. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1357. delObjRect(hp.x-3, hp.y, hp.z, ho->id);
  1358. }
  1359. else if(details.dst.x == details.src.x && details.dst.y+1 == details.src.y) //t
  1360. {
  1361. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1362. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1363. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1364. }
  1365. else if(details.dst.x-1 == details.src.x && details.dst.y+1 == details.src.y) //tr
  1366. {
  1367. delObjRect(hp.x-2, hp.y-2, hp.z, ho->id);
  1368. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1369. delObjRect(hp.x+1, hp.y, hp.z, ho->id);
  1370. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1371. delObjRect(hp.x-1, hp.y, hp.z, ho->id);
  1372. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1373. }
  1374. else if(details.dst.x-1 == details.src.x && details.dst.y == details.src.y) //r
  1375. {
  1376. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1377. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1378. }
  1379. else if(details.dst.x-1 == details.src.x && details.dst.y-1 == details.src.y) //br
  1380. {
  1381. delObjRect(hp.x-2, hp.y+1, hp.z, ho->id);
  1382. delObjRect(hp.x-2, hp.y, hp.z, ho->id);
  1383. delObjRect(hp.x+1, hp.y-1, hp.z, ho->id);
  1384. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1385. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1386. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1387. }
  1388. else if(details.dst.x == details.src.x && details.dst.y-1 == details.src.y) //b
  1389. {
  1390. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1391. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1392. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1393. }
  1394. else if(details.dst.x+1 == details.src.x && details.dst.y-1 == details.src.y) //bl
  1395. {
  1396. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1397. delObjRect(hp.x-1, hp.y-1, hp.z, ho->id);
  1398. delObjRect(hp.x-2, hp.y-1, hp.z, ho->id);
  1399. delObjRect(hp.x-3, hp.y-1, hp.z, ho->id);
  1400. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1401. delObjRect(hp.x, hp.y+1, hp.z, ho->id);
  1402. }
  1403. else if(details.dst.x+1 == details.src.x && details.dst.y == details.src.y) //l
  1404. {
  1405. delObjRect(hp.x, hp.y-1, hp.z, ho->id);
  1406. delObjRect(hp.x, hp.y, hp.z, ho->id);
  1407. }
  1408. ho->pos = details.dst; //copy of hero's position
  1409. //ho->moveDir = 0; //move ended
  1410. ho->isStanding = true;
  1411. //move finished
  1412. CGI->mh->recalculateHideVisPosUnderObj(details.ho, true);
  1413. adventureInt->minimap.draw();
  1414. adventureInt->heroList.updateMove(ho);
  1415. }
  1416. void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
  1417. {
  1418. heroWins.erase(hero->ID);
  1419. }
  1420. void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
  1421. {
  1422. if(heroWins.find(hero->subID)==heroWins.end())
  1423. heroWins.insert(std::pair<int,SDL_Surface*>(hero->subID,infoWin(hero)));
  1424. }
  1425. SDL_Surface * CPlayerInterface::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to)
  1426. {
  1427. char * buf = new char[10];
  1428. for (int i=from;i<to;i++)
  1429. {
  1430. itoa(curh->primSkills[i],buf,10);
  1431. printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
  1432. }
  1433. delete[] buf;
  1434. return ret;
  1435. }
  1436. SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh)
  1437. {
  1438. char * buf = new char[10];
  1439. SDL_Surface * ret = copySurface(hInfo);
  1440. SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
  1441. blueToPlayersAdv(ret,playerID,1);
  1442. printAt(curh->name,75,15,GEOR13,zwykly,ret);
  1443. drawPrimarySkill(curh, ret);
  1444. for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
  1445. {
  1446. blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
  1447. itoa((*i).second.second,buf,10);
  1448. printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
  1449. }
  1450. blitAt(curh->type->portraitLarge,11,12,ret);
  1451. itoa(curh->mana,buf,10);
  1452. printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points
  1453. delete[] buf;
  1454. blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret);
  1455. blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret);
  1456. //SDL_SaveBMP(ret,"inf1.bmp");
  1457. return ret;
  1458. }
  1459. SDL_Surface * CPlayerInterface::drawTownInfoWin(const CGTownInstance * curh)
  1460. {
  1461. return NULL;
  1462. }
  1463. void CPlayerInterface::openTownWindow(const CGTownInstance * town)
  1464. {
  1465. adventureInt->hide();
  1466. timeHandler t;
  1467. t.getDif();
  1468. castleInt = new CCastleInterface(town,true);
  1469. std::cout << "Loading town screen: " << t.getDif() <<std::endl;
  1470. }
  1471. SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //specific=0 => draws info about selected town/hero
  1472. {
  1473. if (specific)
  1474. {
  1475. switch (specific->ID)
  1476. {
  1477. case 34:
  1478. return drawHeroInfoWin(dynamic_cast<const CGHeroInstance*>(specific));
  1479. break;
  1480. default:
  1481. return NULL;
  1482. break;
  1483. }
  1484. }
  1485. else
  1486. {
  1487. switch (adventureInt->selection.type)
  1488. {
  1489. case HEROI_TYPE:
  1490. {
  1491. const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection.selected;
  1492. return drawHeroInfoWin(curh);
  1493. }
  1494. case TOWNI_TYPE:
  1495. {
  1496. return drawTownInfoWin((const CGTownInstance *)adventureInt->selection.selected);
  1497. }
  1498. default:
  1499. return NULL;
  1500. }
  1501. }
  1502. return NULL;
  1503. }
  1504. void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent)
  1505. {
  1506. for (int i=0; i<hoverable.size();i++)
  1507. {
  1508. if (isItIn(&hoverable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1509. {
  1510. if (!hoverable[i]->hovered)
  1511. hoverable[i]->hover(true);
  1512. }
  1513. else if (hoverable[i]->hovered)
  1514. {
  1515. hoverable[i]->hover(false);
  1516. }
  1517. }
  1518. for(int i=0; i<motioninterested.size();i++)
  1519. {
  1520. if (isItIn(&motioninterested[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1521. {
  1522. motioninterested[i]->mouseMoved(sEvent->motion);
  1523. }
  1524. }
  1525. if(sEvent->motion.x<15)
  1526. {
  1527. LOCPLINT->adventureInt->scrollingLeft = true;
  1528. }
  1529. else
  1530. {
  1531. LOCPLINT->adventureInt->scrollingLeft = false;
  1532. }
  1533. if(sEvent->motion.x>ekran->w-15)
  1534. {
  1535. LOCPLINT->adventureInt->scrollingRight = true;
  1536. }
  1537. else
  1538. {
  1539. LOCPLINT->adventureInt->scrollingRight = false;
  1540. }
  1541. if(sEvent->motion.y<15)
  1542. {
  1543. LOCPLINT->adventureInt->scrollingUp = true;
  1544. }
  1545. else
  1546. {
  1547. LOCPLINT->adventureInt->scrollingUp = false;
  1548. }
  1549. if(sEvent->motion.y>ekran->h-15)
  1550. {
  1551. LOCPLINT->adventureInt->scrollingDown = true;
  1552. }
  1553. else
  1554. {
  1555. LOCPLINT->adventureInt->scrollingDown = false;
  1556. }
  1557. }
  1558. void CPlayerInterface::handleKeyUp(SDL_Event *sEvent)
  1559. {
  1560. switch (sEvent->key.keysym.sym)
  1561. {
  1562. case SDLK_LEFT:
  1563. {
  1564. LOCPLINT->adventureInt->scrollingLeft = false;
  1565. break;
  1566. }
  1567. case (SDLK_RIGHT):
  1568. {
  1569. LOCPLINT->adventureInt->scrollingRight = false;
  1570. break;
  1571. }
  1572. case (SDLK_UP):
  1573. {
  1574. LOCPLINT->adventureInt->scrollingUp = false;
  1575. break;
  1576. }
  1577. case (SDLK_DOWN):
  1578. {
  1579. LOCPLINT->adventureInt->scrollingDown = false;
  1580. break;
  1581. }
  1582. case (SDLK_u):
  1583. {
  1584. adventureInt->underground.clickLeft(false);
  1585. break;
  1586. }
  1587. case (SDLK_m):
  1588. {
  1589. adventureInt->moveHero.clickLeft(false);
  1590. break;
  1591. }
  1592. case (SDLK_e):
  1593. {
  1594. adventureInt->endTurn.clickLeft(false);
  1595. break;
  1596. }
  1597. }
  1598. }
  1599. void CPlayerInterface::handleKeyDown(SDL_Event *sEvent)
  1600. {
  1601. switch (sEvent->key.keysym.sym)
  1602. {
  1603. case SDLK_LEFT:
  1604. {
  1605. LOCPLINT->adventureInt->scrollingLeft = true;
  1606. break;
  1607. }
  1608. case (SDLK_RIGHT):
  1609. {
  1610. LOCPLINT->adventureInt->scrollingRight = true;
  1611. break;
  1612. }
  1613. case (SDLK_UP):
  1614. {
  1615. LOCPLINT->adventureInt->scrollingUp = true;
  1616. break;
  1617. }
  1618. case (SDLK_DOWN):
  1619. {
  1620. LOCPLINT->adventureInt->scrollingDown = true;
  1621. break;
  1622. }
  1623. case (SDLK_q):
  1624. {
  1625. exit(0);
  1626. break;
  1627. }
  1628. case (SDLK_u):
  1629. {
  1630. adventureInt->underground.clickLeft(true);
  1631. break;
  1632. }
  1633. case (SDLK_m):
  1634. {
  1635. adventureInt->moveHero.clickLeft(true);
  1636. break;
  1637. }
  1638. case (SDLK_e):
  1639. {
  1640. adventureInt->endTurn.clickLeft(true);
  1641. break;
  1642. }
  1643. }
  1644. }
  1645. void CPlayerInterface::handleEvent(SDL_Event *sEvent)
  1646. {
  1647. current = sEvent;
  1648. if(sEvent->type == SDL_MOUSEMOTION)
  1649. {
  1650. CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
  1651. }
  1652. if(sEvent->type==SDL_QUIT)
  1653. exit(0);
  1654. else if (sEvent->type==SDL_KEYDOWN)
  1655. {
  1656. handleKeyDown(sEvent);
  1657. } //keydown end
  1658. else if(sEvent->type==SDL_KEYUP)
  1659. {
  1660. handleKeyUp(sEvent);
  1661. }//keyup end
  1662. else if(sEvent->type==SDL_MOUSEMOTION)
  1663. {
  1664. handleMouseMotion(sEvent);
  1665. } //mousemotion end
  1666. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1667. {
  1668. LOGE("Left mouse button down1");
  1669. for(int i=0; i<lclickable.size();i++)
  1670. {
  1671. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1672. {
  1673. lclickable[i]->clickLeft(true);
  1674. }
  1675. }
  1676. }
  1677. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
  1678. {
  1679. for(int i=0; i<lclickable.size();i++)
  1680. {
  1681. if (isItIn(&lclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1682. {
  1683. lclickable[i]->clickLeft(false);
  1684. }
  1685. else
  1686. lclickable[i]->clickLeft(boost::logic::indeterminate);
  1687. }
  1688. }
  1689. else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1690. {
  1691. for(int i=0; i<rclickable.size();i++)
  1692. {
  1693. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1694. {
  1695. rclickable[i]->clickRight(true);
  1696. }
  1697. }
  1698. }
  1699. else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT))
  1700. {
  1701. for(int i=0; i<rclickable.size();i++)
  1702. {
  1703. if (isItIn(&rclickable[i]->pos,sEvent->motion.x,sEvent->motion.y))
  1704. {
  1705. rclickable[i]->clickRight(false);
  1706. }
  1707. else
  1708. rclickable[i]->clickRight(boost::logic::indeterminate);
  1709. }
  1710. }
  1711. current = NULL;
  1712. } //event end
  1713. int3 CPlayerInterface::repairScreenPos(int3 pos)
  1714. {
  1715. if(pos.x<=-Woff)
  1716. pos.x = -Woff+1;
  1717. if(pos.y<=-Hoff)
  1718. pos.y = -Hoff+1;
  1719. if(pos.x>CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff)
  1720. pos.x = CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff;
  1721. if(pos.y>CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff)
  1722. pos.y = CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff;
  1723. return pos;
  1724. }
  1725. void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)
  1726. {
  1727. SDL_FreeSurface(heroWins[hero->subID]);//TODO: moznaby zmieniac jedynie fragment bitmapy zwiazany z dana umiejetnoscia
  1728. heroWins[hero->subID] = infoWin(hero); //a nie przerysowywac calosc. Troche roboty, obecnie chyba nie wartej swieczki.
  1729. if (adventureInt->selection.selected == hero)
  1730. adventureInt->infoBar.draw();
  1731. return;
  1732. }
  1733. void CPlayerInterface::receivedResource(int type, int val)
  1734. {
  1735. adventureInt->resdatabar.draw();
  1736. }
  1737. void CPlayerInterface::showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID)
  1738. {
  1739. adventureInt->hide(); //dezaktywacja starego interfejsu
  1740. CSelWindow * temp = CMessage::genSelWindow(text,LOCPLINT->playerID,35,components,playerID);
  1741. LOCPLINT->objsToBlit.push_back(temp);
  1742. temp->pos.x=300-(temp->pos.w/2);
  1743. temp->pos.y=300-(temp->pos.h/2);
  1744. temp->okb.pos.x = temp->okb.posr.x + temp->pos.x;
  1745. temp->okb.pos.y = temp->okb.posr.y + temp->pos.y;
  1746. temp->okb.activate();
  1747. for (int i=0;i<temp->components.size();i++)
  1748. {
  1749. temp->components[i]->activate();
  1750. temp->components[i]->pos.x += temp->pos.x;
  1751. temp->components[i]->pos.y += temp->pos.y;
  1752. }
  1753. temp->ID = askID;
  1754. components[0]->clickLeft(true);
  1755. }
  1756. void CPlayerInterface::heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town)
  1757. {
  1758. openTownWindow(town);
  1759. }
  1760. void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj)
  1761. {
  1762. if(obj->ID == 34) //hero
  1763. {
  1764. const CGHeroInstance * hh;
  1765. if(hh = dynamic_cast<const CGHeroInstance*>(obj))
  1766. {
  1767. SDL_FreeSurface(heroWins[hh->subID]);
  1768. heroWins[hh->subID] = infoWin(hh);
  1769. }
  1770. }
  1771. else if (obj->ID == 98) //town
  1772. {
  1773. }
  1774. }
  1775. void CPlayerInterface::showComp(SComponent comp)
  1776. {
  1777. adventureInt->infoBar.showComp(&comp,4000);
  1778. }
  1779. void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*> & components)
  1780. {
  1781. curint->deactivate(); //dezaktywacja starego interfejsu
  1782. CInfoWindow * temp = CMessage::genIWindow(text,LOCPLINT->playerID,32,components);
  1783. LOCPLINT->objsToBlit.push_back(temp);
  1784. temp->pos.x=300-(temp->pos.w/2);
  1785. temp->pos.y=300-(temp->pos.h/2);
  1786. temp->okb.pos.x = temp->okb.posr.x + temp->pos.x;
  1787. temp->okb.pos.y = temp->okb.posr.y + temp->pos.y;
  1788. temp->okb.activate();
  1789. for (int i=0;i<temp->components.size();i++)
  1790. {
  1791. temp->components[i]->activate();
  1792. temp->components[i]->pos.x += temp->pos.x;
  1793. temp->components[i]->pos.y += temp->pos.y;
  1794. }
  1795. }
  1796. void CPlayerInterface::removeObjToBlit(IShowable* obj)
  1797. {
  1798. objsToBlit.erase
  1799. (std::find(objsToBlit.begin(),objsToBlit.end(),obj));
  1800. //delete obj;
  1801. }
  1802. void CPlayerInterface::tileRevealed(int3 pos)
  1803. {
  1804. adventureInt->minimap.showTile(pos);
  1805. }
  1806. void CPlayerInterface::tileHidden(int3 pos)
  1807. {
  1808. adventureInt->minimap.hideTile(pos);
  1809. }
  1810. void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero)
  1811. {
  1812. adventureInt->heroWindow->setHero(hero);
  1813. this->objsToBlit.push_back(adventureInt->heroWindow);
  1814. adventureInt->hide();
  1815. adventureInt->heroWindow->activate();
  1816. }
  1817. CStatusBar::CStatusBar(int x, int y, std::string name, int maxw)
  1818. {
  1819. bg=CGI->bitmaph->loadBitmap(name);
  1820. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  1821. pos.x=x;
  1822. pos.y=y;
  1823. if(maxw >= 0)
  1824. pos.w = std::min(bg->w,maxw);
  1825. else
  1826. pos.w=bg->w;
  1827. pos.h=bg->h;
  1828. middlex=(pos.w/2)+x;
  1829. middley=(bg->h/2)+y;
  1830. }
  1831. CStatusBar::~CStatusBar()
  1832. {
  1833. SDL_FreeSurface(bg);
  1834. }
  1835. void CStatusBar::clear()
  1836. {
  1837. current="";
  1838. SDL_Rect pom = genRect(pos.h,pos.w,pos.x,pos.y);
  1839. SDL_BlitSurface(bg,&genRect(pos.h,pos.w,0,0),ekran,&pom);
  1840. }
  1841. void CStatusBar::print(std::string text)
  1842. {
  1843. current=text;
  1844. SDL_Rect pom = genRect(pos.h,pos.w,pos.x,pos.y);
  1845. SDL_BlitSurface(bg,&genRect(pos.h,pos.w,0,0),ekran,&pom);
  1846. printAtMiddle(current,middlex,middley,GEOR13,zwykly);
  1847. }
  1848. void CStatusBar::show()
  1849. {
  1850. SDL_Rect pom = genRect(pos.h,pos.w,pos.x,pos.y);
  1851. SDL_BlitSurface(bg,&genRect(pos.h,pos.w,0,0),ekran,&pom);
  1852. printAtMiddle(current,middlex,middley,GEOR13,zwykly);
  1853. }
  1854. std::string CStatusBar::getCurrent()
  1855. {
  1856. return current;
  1857. }
  1858. void CList::activate()
  1859. {
  1860. ClickableL::activate();
  1861. ClickableR::activate();
  1862. Hoverable::activate();
  1863. KeyInterested::activate();
  1864. MotionInterested::activate();
  1865. };
  1866. void CList::deactivate()
  1867. {
  1868. ClickableL::deactivate();
  1869. ClickableR::deactivate();
  1870. Hoverable::deactivate();
  1871. KeyInterested::deactivate();
  1872. MotionInterested::deactivate();
  1873. };
  1874. void CList::clickLeft(tribool down)
  1875. {
  1876. };
  1877. CList::CList(int Size)
  1878. :SIZE(Size)
  1879. {
  1880. }
  1881. CHeroList::CHeroList(int Size)
  1882. :CList(Size)
  1883. {
  1884. pos = genRect(192,64,609,196);
  1885. arrupp = genRect(16,64,609,196);
  1886. arrdop = genRect(16,64,609,372);
  1887. //32px per hero
  1888. posmobx = 610;
  1889. posmoby = 213;
  1890. posporx = 617;
  1891. pospory = 212;
  1892. posmanx = 666;
  1893. posmany = 213;
  1894. arrup = CGI->spriteh->giveDef("IAM012.DEF");
  1895. arrdo = CGI->spriteh->giveDef("IAM013.DEF");
  1896. mobile = CGI->spriteh->giveDef("IMOBIL.DEF");
  1897. mana = CGI->spriteh->giveDef("IMANA.DEF");
  1898. empty = CGI->bitmaph->loadBitmap("HPSXXX.bmp");
  1899. selection = CGI->bitmaph->loadBitmap("HPSYYY.bmp");
  1900. SDL_SetColorKey(selection,SDL_SRCCOLORKEY,SDL_MapRGB(selection->format,0,255,255));
  1901. from = 0;
  1902. pressed = indeterminate;
  1903. }
  1904. void CHeroList::init()
  1905. {
  1906. bg = CSDL_Ext::newSurface(68,193,ekran);
  1907. SDL_BlitSurface(LOCPLINT->adventureInt->bg,&genRect(193,68,607,196),bg,&genRect(193,68,0,0));
  1908. }
  1909. void CHeroList::genList()
  1910. {
  1911. int howMany = LOCPLINT->cb->howManyHeroes();
  1912. for (int i=0;i<howMany;i++)
  1913. {
  1914. items.push_back(std::pair<const CGHeroInstance *,CPath *>(LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,i,0),NULL));
  1915. }
  1916. }
  1917. void CHeroList::select(int which)
  1918. {
  1919. selected = which;
  1920. if (which>=items.size())
  1921. return;
  1922. LOCPLINT->adventureInt->centerOn(items[which].first->pos);
  1923. LOCPLINT->adventureInt->selection.type = HEROI_TYPE;
  1924. LOCPLINT->adventureInt->selection.selected = items[which].first;
  1925. LOCPLINT->adventureInt->terrain.currentPath = items[which].second;
  1926. draw();
  1927. LOCPLINT->adventureInt->townList.draw();
  1928. LOCPLINT->adventureInt->infoBar.draw(NULL);
  1929. }
  1930. void CHeroList::clickLeft(tribool down)
  1931. {
  1932. if (down)
  1933. {
  1934. /***************************ARROWS*****************************************/
  1935. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  1936. {
  1937. blitAt(arrup->ourImages[1].bitmap,arrupp.x,arrupp.y);
  1938. pressed = true;
  1939. return;
  1940. }
  1941. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  1942. {
  1943. blitAt(arrdo->ourImages[1].bitmap,arrdop.x,arrdop.y);
  1944. pressed = false;
  1945. return;
  1946. }
  1947. /***************************HEROES*****************************************/
  1948. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  1949. hx-=pos.x;
  1950. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  1951. float ny = (float)hy/(float)32;
  1952. if (ny>=5 || ny<0)
  1953. return;
  1954. if (((int)(ny+from))==selected && (LOCPLINT->adventureInt->selection.type == HEROI_TYPE))
  1955. LOCPLINT->openHeroWindow(items[selected].first);//print hero screen
  1956. select(ny+from);
  1957. }
  1958. else
  1959. {
  1960. if (indeterminate(pressed))
  1961. return;
  1962. if (pressed) //up
  1963. {
  1964. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  1965. pressed = indeterminate;
  1966. if (!down)
  1967. {
  1968. from--;
  1969. if (from<0)
  1970. from=0;
  1971. draw();
  1972. }
  1973. }
  1974. else if (!pressed) //down
  1975. {
  1976. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  1977. pressed = indeterminate;
  1978. if (!down)
  1979. {
  1980. from++;
  1981. //if (from<items.size()-5)
  1982. // from=items.size()-5;
  1983. draw();
  1984. }
  1985. }
  1986. else
  1987. throw 0;
  1988. }
  1989. }
  1990. void CHeroList::mouseMoved (SDL_MouseMotionEvent & sEvent)
  1991. {
  1992. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  1993. {
  1994. if (from>0)
  1995. LOCPLINT->adventureInt->statusbar.print(CGI->preth->advHListUp.first);
  1996. else
  1997. LOCPLINT->adventureInt->statusbar.clear();
  1998. return;
  1999. }
  2000. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  2001. {
  2002. if ((items.size()-from) > 5)
  2003. LOCPLINT->adventureInt->statusbar.print(CGI->preth->advHListDown.first);
  2004. else
  2005. LOCPLINT->adventureInt->statusbar.clear();
  2006. return;
  2007. }
  2008. //if not buttons then heroes
  2009. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  2010. hx-=pos.x;
  2011. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  2012. float ny = (float)hy/(float)32;
  2013. if ((ny>5 || ny<0) || (from+ny>=items.size()))
  2014. {
  2015. LOCPLINT->adventureInt->statusbar.clear();
  2016. return;
  2017. }
  2018. std::vector<std::string> temp;
  2019. temp.push_back(items[from+ny].first->name);
  2020. temp.push_back(items[from+ny].first->type->heroClass->name);
  2021. LOCPLINT->adventureInt->statusbar.print( processStr(CGI->generaltexth->allTexts[15],temp) );
  2022. //select(ny+from);
  2023. }
  2024. void CHeroList::clickRight(tribool down)
  2025. {
  2026. if (down)
  2027. {
  2028. /***************************ARROWS*****************************************/
  2029. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  2030. {
  2031. LOCPLINT->adventureInt->handleRightClick(CGI->preth->advHListUp.second,down,this);
  2032. }
  2033. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  2034. {
  2035. LOCPLINT->adventureInt->handleRightClick(CGI->preth->advHListDown.second,down,this);
  2036. }
  2037. }
  2038. else
  2039. {
  2040. LOCPLINT->adventureInt->handleRightClick(CGI->preth->advHListUp.second,down,this);
  2041. LOCPLINT->adventureInt->handleRightClick(CGI->preth->advHListDown.second,down,this);
  2042. }
  2043. }
  2044. void CHeroList::hover (bool on)
  2045. {
  2046. }
  2047. void CHeroList::keyPressed (SDL_KeyboardEvent & key)
  2048. {
  2049. }
  2050. void CHeroList::updateHList()
  2051. {
  2052. items.clear();
  2053. genList();
  2054. }
  2055. void CHeroList::updateMove(const CGHeroInstance* which) //draws move points bar
  2056. {
  2057. int ser = LOCPLINT->cb->getHeroSerial(which);
  2058. ser -= from;
  2059. int pom = (which->movement)/100;
  2060. blitAt(mobile->ourImages[pom].bitmap,posmobx,posmoby+ser*32); //move point
  2061. }
  2062. void CHeroList::draw()
  2063. {
  2064. for (int iT=0+from;iT<5+from;iT++)
  2065. {
  2066. int i = iT-from;
  2067. if (iT>=items.size())
  2068. {
  2069. blitAt(mobile->ourImages[0].bitmap,posmobx,posmoby+i*32);
  2070. blitAt(mana->ourImages[0].bitmap,posmanx,posmany+i*32);
  2071. blitAt(empty,posporx,pospory+i*32);
  2072. continue;
  2073. }
  2074. int pom = (LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->movement)/100;
  2075. if (pom>25) pom=25;
  2076. if (pom<0) pom=0;
  2077. blitAt(mobile->ourImages[pom].bitmap,posmobx,posmoby+i*32); //move point
  2078. pom = (LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->mana)/5; //bylo: .../10;
  2079. if (pom>25) pom=25;
  2080. if (pom<0) pom=0;
  2081. blitAt(mana->ourImages[pom].bitmap,posmanx,posmany+i*32); //mana
  2082. SDL_Surface * temp = LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,iT,0)->type->portraitSmall;
  2083. blitAt(temp,posporx,pospory+i*32);
  2084. if ((selected == iT) && (LOCPLINT->adventureInt->selection.type == HEROI_TYPE))
  2085. {
  2086. blitAt(selection,posporx,pospory+i*32);
  2087. }
  2088. //TODO: support for custom portraits
  2089. }
  2090. if (from>0)
  2091. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  2092. else
  2093. blitAt(arrup->ourImages[2].bitmap,arrupp.x,arrupp.y);
  2094. if (items.size()-from>5)
  2095. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  2096. else
  2097. blitAt(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y);
  2098. }