CAdvmapInterface.cpp 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. #include "stdafx.h"
  2. #include "CAdvmapInterface.h"
  3. #include "client/CBitmapHandler.h"
  4. #include "CPlayerInterface.h"
  5. #include "hch/CPreGameTextHandler.h"
  6. #include "hch/CGeneralTextHandler.h"
  7. #include "hch/CDefHandler.h"
  8. #include "hch/CTownHandler.h"
  9. #include "CPathfinder.h"
  10. #include "CGameInfo.h"
  11. #include "SDL_Extensions.h"
  12. #include "CCallback.h"
  13. #include <boost/assign/std/vector.hpp>
  14. #include "mapHandler.h"
  15. #include "CMessage.h"
  16. #include <boost/algorithm/string.hpp>
  17. #include <boost/algorithm/string/replace.hpp>
  18. #include "hch/CHeroHandler.h"
  19. #include <sstream>
  20. #include "AdventureMapButton.h"
  21. #include "CHeroWindow.h"
  22. #include "client/Graphics.h"
  23. #include "hch/CObjectHandler.h"
  24. #include <boost/thread.hpp>
  25. #include "map.h"
  26. #pragma warning (disable : 4355)
  27. extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
  28. using namespace boost::logic;
  29. using namespace boost::assign;
  30. using namespace CSDL_Ext;
  31. CAdvMapInt::~CAdvMapInt()
  32. {
  33. SDL_FreeSurface(bg);
  34. delete heroWindow;
  35. }
  36. CMinimap::CMinimap(bool draw)
  37. {
  38. statusbarTxt = CGI->preth->zelp[291].first;
  39. rcText = CGI->preth->zelp[291].second;
  40. pos.x=630;
  41. pos.y=26;
  42. pos.h=pos.w=144;
  43. int rx = (((float)19)/(CGI->mh->sizes.x))*((float)pos.w),
  44. ry = (((float)18)/(CGI->mh->sizes.y))*((float)pos.h);
  45. radar = newSurface(rx,ry);
  46. temps = newSurface(144,144);
  47. SDL_FillRect(radar,NULL,0x00FFFF);
  48. for (int i=0; i<radar->w; i++)
  49. {
  50. if (i%4 || (i==0))
  51. {
  52. SDL_PutPixel(radar,i,0,255,75,125);
  53. SDL_PutPixel(radar,i,radar->h-1,255,75,125);
  54. }
  55. }
  56. for (int i=0; i<radar->h; i++)
  57. {
  58. if ((i%4) || (i==0))
  59. {
  60. SDL_PutPixel(radar,0,i,255,75,125);
  61. SDL_PutPixel(radar,radar->w-1,i,255,75,125);
  62. }
  63. }
  64. SDL_SetColorKey(radar,SDL_SRCCOLORKEY,SDL_MapRGB(radar->format,0,255,255));
  65. //radar = CDefHandler::giveDef("RADAR.DEF");
  66. std::ifstream is("config/minimap.txt",std::ifstream::in);
  67. for (int i=0;i<TERRAIN_TYPES;i++)
  68. {
  69. std::pair<int,SDL_Color> vinya;
  70. std::pair<int,SDL_Color> vinya2;
  71. int pom;
  72. is >> pom;
  73. vinya2.first=vinya.first=pom;
  74. is >> pom;
  75. vinya.second.r=pom;
  76. is >> pom;
  77. vinya.second.g=pom;
  78. is >> pom;
  79. vinya.second.b=pom;
  80. is >> pom;
  81. vinya2.second.r=pom;
  82. is >> pom;
  83. vinya2.second.g=pom;
  84. is >> pom;
  85. vinya2.second.b=pom;
  86. vinya.second.unused=vinya2.second.unused=255;
  87. colors.insert(vinya);
  88. colorsBlocked.insert(vinya2);
  89. }
  90. is.close();
  91. if (draw)
  92. redraw();
  93. }
  94. void CMinimap::draw()
  95. {
  96. //draw terrain
  97. blitAt(map[LOCPLINT->adventureInt->position.z],0,0,temps);
  98. //draw heroes
  99. std::vector <const CGHeroInstance *> hh = LOCPLINT->cb->getHeroesInfo(false);
  100. int mw = map[0]->w, mh = map[0]->h,
  101. wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y;
  102. for (int i=0; i<hh.size();i++)
  103. {
  104. int3 hpos = hh[i]->getPosition(false);
  105. if(hpos.z!=LOCPLINT->adventureInt->position.z)
  106. continue;
  107. //float zawx = ((float)hpos.x/CGI->mh->sizes.x), zawy = ((float)hpos.y/CGI->mh->sizes.y);
  108. int3 maplgp ( (hpos.x*mw)/CGI->mh->sizes.x, (hpos.y*mh)/CGI->mh->sizes.y, hpos.z );
  109. for (int ii=0; ii<wo; ii++)
  110. {
  111. for (int jj=0; jj<ho; jj++)
  112. {
  113. SDL_PutPixel(temps,maplgp.x+ii,maplgp.y+jj,graphics->playerColors[hh[i]->getOwner()].r,graphics->playerColors[hh[i]->getOwner()].g,graphics->playerColors[hh[i]->getOwner()].b);
  114. }
  115. }
  116. }
  117. blitAt(FoW[LOCPLINT->adventureInt->position.z],0,0,temps);
  118. //draw radar
  119. int bx = (((float)LOCPLINT->adventureInt->position.x)/(((float)CGI->mh->sizes.x)))*pos.w,
  120. by = (((float)LOCPLINT->adventureInt->position.y)/(((float)CGI->mh->sizes.y)))*pos.h;
  121. blitAt(radar,bx,by,temps);
  122. blitAt(temps,pos.x,pos.y);
  123. //SDL_UpdateRect(screen,pos.x,pos.y,pos.w,pos.h);
  124. }
  125. void CMinimap::redraw(int level)// (level==-1) => redraw all levels
  126. {
  127. (CGI);
  128. for (int i=0; i<CGI->mh->sizes.z; i++)
  129. {
  130. SDL_Surface * pom ;
  131. if ((level>=0) && (i!=level))
  132. continue;
  133. if (map.size()<i+1)
  134. pom = CSDL_Ext::newSurface(pos.w,pos.h,screen);
  135. else pom = map[i];
  136. for (int x=0;x<pos.w;x++)
  137. {
  138. for (int y=0;y<pos.h;y++)
  139. {
  140. int mx=(CGI->mh->sizes.x*x)/pos.w;
  141. int my=(CGI->mh->sizes.y*y)/pos.h;
  142. if (CGI->mh->ttiles[mx][my][i].tileInfo->blocked && (!CGI->mh->ttiles[mx][my][i].tileInfo->visitable))
  143. SDL_PutPixel(pom,x,y,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].r,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].g,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].b);
  144. else SDL_PutPixel(pom,x,y,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].r,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].g,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].b);
  145. }
  146. }
  147. map.push_back(pom);
  148. }
  149. //FoW
  150. int mw = map[0]->w, mh = map[0]->h,
  151. wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y;
  152. for(int d=0; d<CGI->mh->map->twoLevel+1; ++d)
  153. {
  154. if(level>=0 && d!=level)
  155. continue;
  156. SDL_Surface * pt = CSDL_Ext::newSurface(pos.w, pos.h, CSDL_Ext::std32bppSurface);
  157. for (int i=0; i<mw; i++)
  158. {
  159. for (int j=0; j<mh; j++)
  160. {
  161. int3 pp( ((i*CGI->mh->sizes.x)/mw), ((j*CGI->mh->sizes.y)/mh), d );
  162. if ( !LOCPLINT->cb->isVisible(pp) )
  163. {
  164. CSDL_Ext::SDL_PutPixelWithoutRefresh(pt,i,j,0,0,0);
  165. }
  166. }
  167. }
  168. CSDL_Ext::update(pt);
  169. FoW.push_back(pt);
  170. }
  171. //FoW end
  172. }
  173. void CMinimap::updateRadar()
  174. {}
  175. void CMinimap::clickRight (tribool down)
  176. {
  177. LOCPLINT->adventureInt->handleRightClick(rcText,down,this);
  178. }
  179. void CMinimap::clickLeft (tribool down)
  180. {
  181. if (down && (!pressedL))
  182. MotionInterested::activate();
  183. else if (!down)
  184. {
  185. if (std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this)!=LOCPLINT->motioninterested.end())
  186. MotionInterested::deactivate();
  187. }
  188. ClickableL::clickLeft(down);
  189. if (!((bool)down))
  190. return;
  191. float dx=((float)(LOCPLINT->current->motion.x-pos.x))/((float)pos.w),
  192. dy=((float)(LOCPLINT->current->motion.y-pos.y))/((float)pos.h);
  193. int3 newCPos;
  194. newCPos.x = (CGI->mh->sizes.x*dx);
  195. newCPos.y = (CGI->mh->sizes.y*dy);
  196. newCPos.z = LOCPLINT->adventureInt->position.z;
  197. LOCPLINT->adventureInt->centerOn(newCPos);
  198. }
  199. void CMinimap::hover (bool on)
  200. {
  201. Hoverable::hover(on);
  202. if (on)
  203. LOCPLINT->adventureInt->statusbar.print(statusbarTxt);
  204. else if (LOCPLINT->adventureInt->statusbar.current==statusbarTxt)
  205. LOCPLINT->adventureInt->statusbar.clear();
  206. }
  207. void CMinimap::mouseMoved (SDL_MouseMotionEvent & sEvent)
  208. {
  209. if (pressedL)
  210. {
  211. clickLeft(true);
  212. }
  213. }
  214. void CMinimap::activate()
  215. {
  216. ClickableL::activate();
  217. ClickableR::activate();
  218. Hoverable::activate();
  219. if (pressedL)
  220. MotionInterested::activate();
  221. }
  222. void CMinimap::deactivate()
  223. {
  224. if (pressedL)
  225. MotionInterested::deactivate();
  226. ClickableL::deactivate();
  227. ClickableR::deactivate();
  228. Hoverable::deactivate();
  229. }
  230. void CMinimap::showTile(int3 pos)
  231. {
  232. int mw = map[0]->w, mh = map[0]->h;
  233. double wo = ((double)mw)/CGI->mh->sizes.x, ho = ((double)mh)/CGI->mh->sizes.y;
  234. for (int ii=0; ii<wo; ii++)
  235. {
  236. for (int jj=0; jj<ho; jj++)
  237. {
  238. if ((pos.x*wo+ii<this->pos.w) && (pos.y*ho+jj<this->pos.h))
  239. CSDL_Ext::SDL_PutPixel(FoW[pos.z],pos.x*wo+ii,pos.y*ho+jj,0,0,0,0,0);
  240. }
  241. }
  242. }
  243. void CMinimap::hideTile(int3 pos)
  244. {
  245. }
  246. CTerrainRect::CTerrainRect():currentPath(NULL)
  247. {
  248. tilesw=19;
  249. tilesh=18;
  250. pos.x=7;
  251. pos.y=6;
  252. pos.w=593;
  253. pos.h=547;
  254. arrows = CDefHandler::giveDef("ADAG.DEF");
  255. for(int y=0; y<arrows->ourImages.size(); ++y)
  256. {
  257. arrows->ourImages[y].bitmap = CSDL_Ext::alphaTransform(arrows->ourImages[y].bitmap);
  258. }
  259. }
  260. void CTerrainRect::activate()
  261. {
  262. ClickableL::activate();
  263. ClickableR::activate();
  264. Hoverable::activate();
  265. KeyInterested::activate();
  266. MotionInterested::activate();
  267. };
  268. void CTerrainRect::deactivate()
  269. {
  270. ClickableL::deactivate();
  271. ClickableR::deactivate();
  272. Hoverable::deactivate();
  273. KeyInterested::deactivate();
  274. MotionInterested::deactivate();
  275. };
  276. void CTerrainRect::clickLeft(tribool down)
  277. {
  278. if ((down==false) || indeterminate(down))
  279. return;
  280. if (LOCPLINT->adventureInt->selection.type != HEROI_TYPE)
  281. {
  282. if (currentPath)
  283. {
  284. delete currentPath;
  285. currentPath = NULL;
  286. }
  287. return;
  288. }
  289. int3 mp = whichTileIsIt();
  290. if ((mp.x<0) || (mp.y<0))
  291. return;
  292. bool mres =true;
  293. if (currentPath)
  294. {
  295. if ( (currentPath->endPos()) == mp)
  296. { //move
  297. CPath sended(*currentPath); //temporary path - engine will operate on it
  298. LOCPLINT->pim->unlock();
  299. mres = LOCPLINT->cb->moveHero( ((const CGHeroInstance*)LOCPLINT->adventureInt->selection.selected)->type->ID,&sended,1,0);
  300. LOCPLINT->pim->lock();
  301. if(!mres)
  302. {
  303. delete currentPath;
  304. currentPath = NULL;
  305. int i=0;
  306. for(;i<LOCPLINT->adventureInt->heroList.items.size();i++)
  307. {
  308. if(LOCPLINT->adventureInt->heroList.items[i].first->subID == ((const CGHeroInstance*)LOCPLINT->adventureInt->selection.selected)->type->ID)
  309. {
  310. LOCPLINT->adventureInt->heroList.items[i].second = NULL;
  311. break;
  312. }
  313. }
  314. }
  315. }
  316. else
  317. {
  318. delete currentPath;
  319. currentPath=NULL;
  320. }
  321. }
  322. const CGHeroInstance * currentHero = (LOCPLINT->adventureInt->heroList.items.size())?(LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].first):(NULL);
  323. if(!currentHero)
  324. return;
  325. int3 bufpos = currentHero->getPosition(false);
  326. //bufpos.x-=1;
  327. if (mres)
  328. {
  329. vector<Coordinate>* p;
  330. p = CGI->pathf->GetPath(Coordinate(bufpos),Coordinate(mp),currentHero);
  331. //Convert to old format.
  332. currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->ConvertToOldFormat(p);
  333. delete p;
  334. //currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->getPath(bufpos,mp,currentHero,1);
  335. }
  336. }
  337. void CTerrainRect::clickRight(tribool down)
  338. {
  339. }
  340. void CTerrainRect::mouseMoved (SDL_MouseMotionEvent & sEvent)
  341. {
  342. int3 pom=LOCPLINT->adventureInt->verifyPos(whichTileIsIt(sEvent.x,sEvent.y));
  343. if (pom!=curHoveredTile)
  344. curHoveredTile=pom;
  345. else
  346. return;
  347. std::vector<std::string> temp = LOCPLINT->cb->getObjDescriptions(pom);
  348. if (temp.size())
  349. {
  350. LOCPLINT->adventureInt->statusbar.print((*((temp.end())-1)));
  351. }
  352. else
  353. {
  354. LOCPLINT->adventureInt->statusbar.clear();
  355. }
  356. }
  357. void CTerrainRect::keyPressed (SDL_KeyboardEvent & key){}
  358. void CTerrainRect::hover(bool on)
  359. {
  360. if (!on)
  361. LOCPLINT->adventureInt->statusbar.clear();
  362. }
  363. void CTerrainRect::showPath()
  364. {
  365. for (int i=0;i<currentPath->nodes.size()-1;i++)
  366. {
  367. int pn=-1;//number of picture
  368. if (i==0) //last tile
  369. {
  370. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  371. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  372. if (x<0 || y<0 || x>pos.w || y>pos.h)
  373. continue;
  374. pn=0;
  375. }
  376. else
  377. {
  378. std::vector<CPathNode> & cv = currentPath->nodes;
  379. if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1)
  380. {
  381. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  382. {
  383. pn = 3;
  384. }
  385. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  386. {
  387. pn = 12;
  388. }
  389. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  390. {
  391. pn = 21;
  392. }
  393. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  394. {
  395. pn = 22;
  396. }
  397. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  398. {
  399. pn = 2;
  400. }
  401. }
  402. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1)
  403. {
  404. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  405. {
  406. pn = 4;
  407. }
  408. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  409. {
  410. pn = 13;
  411. }
  412. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  413. {
  414. pn = 22;
  415. }
  416. }
  417. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1)
  418. {
  419. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
  420. {
  421. pn = 5;
  422. }
  423. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  424. {
  425. pn = 14;
  426. }
  427. else if(cv[i-1].coord.x+1 == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y)
  428. {
  429. pn = 23;
  430. }
  431. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  432. {
  433. pn = 24;
  434. }
  435. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  436. {
  437. pn = 4;
  438. }
  439. }
  440. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y)
  441. {
  442. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  443. {
  444. pn = 6;
  445. }
  446. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
  447. {
  448. pn = 15;
  449. }
  450. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  451. {
  452. pn = 24;
  453. }
  454. }
  455. else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1)
  456. {
  457. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
  458. {
  459. pn = 7;
  460. }
  461. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  462. {
  463. pn = 16;
  464. }
  465. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  466. {
  467. pn = 17;
  468. }
  469. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
  470. {
  471. pn = 6;
  472. }
  473. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  474. {
  475. pn = 18;
  476. }
  477. }
  478. else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1)
  479. {
  480. if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  481. {
  482. pn = 8;
  483. }
  484. else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  485. {
  486. pn = 9;
  487. }
  488. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  489. {
  490. pn = 18;
  491. }
  492. }
  493. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1)
  494. {
  495. if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
  496. {
  497. pn = 1;
  498. }
  499. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  500. {
  501. pn = 10;
  502. }
  503. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  504. {
  505. pn = 19;
  506. }
  507. else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
  508. {
  509. pn = 8;
  510. }
  511. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  512. {
  513. pn = 20;
  514. }
  515. }
  516. else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y)
  517. {
  518. if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
  519. {
  520. pn = 2;
  521. }
  522. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
  523. {
  524. pn = 11;
  525. }
  526. else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
  527. {
  528. pn = 20;
  529. }
  530. }
  531. }
  532. if ( ((currentPath->nodes[i].dist)-(*(currentPath->nodes.end()-1)).dist) > ((const CGHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->movement)
  533. pn+=25;
  534. if (pn>=0)
  535. {
  536. int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
  537. y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
  538. if (x<0 || y<0 || x>pos.w || y>pos.h)
  539. continue;
  540. int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
  541. hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
  542. if (hvx<0 && hvy<0)
  543. {
  544. CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, screen, &genRect(32, 32, x, y));
  545. }
  546. else if(hvx<0)
  547. {
  548. CSDL_Ext::blit8bppAlphaTo24bpp
  549. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,0,0),
  550. screen,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,x,y));
  551. }
  552. else if (hvy<0)
  553. {
  554. CSDL_Ext::blit8bppAlphaTo24bpp
  555. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  556. screen,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  557. }
  558. else
  559. {
  560. CSDL_Ext::blit8bppAlphaTo24bpp
  561. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  562. screen,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  563. }
  564. }
  565. } //for (int i=0;i<currentPath->nodes.size()-1;i++)
  566. }
  567. void CTerrainRect::show()
  568. {
  569. SDL_Surface * teren = CGI->mh->terrainRect
  570. (LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
  571. tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim,
  572. &LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim,
  573. screen,&genRect(547,594,7,6)
  574. );
  575. //SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));
  576. //SDL_FreeSurface(teren);
  577. if (currentPath && LOCPLINT->adventureInt->position.z==currentPath->startPos().z) //drawing path
  578. {
  579. showPath();
  580. }
  581. }
  582. int3 CTerrainRect::whichTileIsIt(int x, int y)
  583. {
  584. int3 ret;
  585. ret.x = LOCPLINT->adventureInt->position.x + ((LOCPLINT->current->motion.x-pos.x)/32);
  586. ret.y = LOCPLINT->adventureInt->position.y + ((LOCPLINT->current->motion.y-pos.y)/32);
  587. ret.z = LOCPLINT->adventureInt->position.z;
  588. return ret;
  589. }
  590. int3 CTerrainRect::whichTileIsIt()
  591. {
  592. return whichTileIsIt(LOCPLINT->current->motion.x,LOCPLINT->current->motion.y);
  593. }
  594. void CResDataBar::clickRight (tribool down)
  595. {
  596. }
  597. void CResDataBar::activate()
  598. {
  599. ClickableR::activate();
  600. }
  601. void CResDataBar::deactivate()
  602. {
  603. ClickableR::deactivate();
  604. }
  605. CResDataBar::CResDataBar()
  606. {
  607. bg = BitmapHandler::loadBitmap("ZRESBAR.bmp");
  608. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  609. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  610. pos = genRect(bg->h,bg->w,3,575);
  611. txtpos += (std::pair<int,int>(35,577)),(std::pair<int,int>(120,577)),(std::pair<int,int>(205,577)),
  612. (std::pair<int,int>(290,577)),(std::pair<int,int>(375,577)),(std::pair<int,int>(460,577)),
  613. (std::pair<int,int>(545,577)),(std::pair<int,int>(620,577));
  614. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63] + ": %s, " +
  615. CGI->generaltexth->allTexts[64] + ": %s";
  616. }
  617. CResDataBar::~CResDataBar()
  618. {
  619. SDL_FreeSurface(bg);
  620. }
  621. void CResDataBar::draw()
  622. {
  623. blitAt(bg,pos.x,pos.y);
  624. char * buf = new char[15];
  625. for (int i=0;i<7;i++)
  626. {
  627. SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
  628. printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly);
  629. }
  630. std::vector<std::string> temp;
  631. SDL_itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf);
  632. SDL_itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf);
  633. SDL_itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf);
  634. printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,GEOR13,zwykly);
  635. temp.clear();
  636. //updateRect(&pos,screen);
  637. delete[] buf;
  638. }
  639. CInfoBar::CInfoBar()
  640. {
  641. toNextTick = mode = pom = -1;
  642. pos.x=605;
  643. pos.y=389;
  644. pos.w=194;
  645. pos.h=186;
  646. day = CDefHandler::giveDef("NEWDAY.DEF");
  647. week1 = CDefHandler::giveDef("NEWWEEK1.DEF");
  648. week2 = CDefHandler::giveDef("NEWWEEK2.DEF");
  649. week3 = CDefHandler::giveDef("NEWWEEK3.DEF");
  650. week4 = CDefHandler::giveDef("NEWWEEK4.DEF");
  651. }
  652. CInfoBar::~CInfoBar()
  653. {
  654. delete day;
  655. delete week1;
  656. delete week2;
  657. delete week3;
  658. delete week4;
  659. }
  660. void CInfoBar::draw(const CGObjectInstance * specific)
  661. {
  662. if ((mode>=0) && mode<5)
  663. {
  664. blitAnim(mode);
  665. return;
  666. }
  667. else if (mode==5)
  668. {
  669. mode = -1;
  670. if(!LOCPLINT->adventureInt->selection.selected)
  671. {
  672. if (LOCPLINT->adventureInt->heroList.items.size())
  673. {
  674. LOCPLINT->adventureInt->heroList.select(0);
  675. }
  676. }
  677. draw((const CGObjectInstance *)LOCPLINT->adventureInt->selection.selected);
  678. }
  679. if (!specific)
  680. specific = (const CGObjectInstance *)LOCPLINT->adventureInt->selection.selected;
  681. //TODO: to rzutowanie wyglada groznie, ale dziala. Ale nie powinno wygladac groznie.
  682. if(!specific)
  683. return;
  684. if(specific->ID == 34) //hero
  685. {
  686. if(graphics->heroWins.find(specific->subID)!=graphics->heroWins.end())
  687. blitAt(graphics->heroWins[specific->subID],pos.x,pos.y);
  688. }
  689. else if (specific->ID == 98)
  690. {
  691. const CGTownInstance * t = static_cast<const CGTownInstance*>(specific);
  692. if(graphics->townWins.find(t->identifier)!=graphics->townWins.end())
  693. blitAt(graphics->townWins[t->identifier],pos.x,pos.y);
  694. }
  695. //SDL_Surface * todr = LOCPLINT->infoWin(specific);
  696. //if (!todr)
  697. // return;
  698. //blitAt(todr,pos.x,pos.y);
  699. //SDL_FreeSurface(todr);
  700. }
  701. CDefHandler * CInfoBar::getAnim(int mode)
  702. {
  703. switch(mode)
  704. {
  705. case 0:
  706. return day;
  707. break;
  708. case 1:
  709. return week1;
  710. break;
  711. case 2:
  712. return week2;
  713. break;
  714. case 3:
  715. return week3;
  716. break;
  717. case 4:
  718. return week4;
  719. break;
  720. default:
  721. return NULL;
  722. break;
  723. }
  724. }
  725. void CInfoBar::blitAnim(int mode)//0 - day, 1 - week
  726. {
  727. CDefHandler * anim = NULL;
  728. std::stringstream txt;
  729. anim = getAnim(mode);
  730. if(mode) //new week animation
  731. {
  732. txt << CGI->generaltexth->allTexts[63] << " " << LOCPLINT->cb->getDate(2);
  733. }
  734. else //new day
  735. {
  736. txt << CGI->generaltexth->allTexts[64] << " " << LOCPLINT->cb->getDate(1);
  737. }
  738. blitAt(anim->ourImages[pom].bitmap,pos.x+9,pos.y+10);
  739. printAtMiddle(txt.str(),700,420,TNRB16,zwykly);
  740. if (pom == anim->ourImages.size()-1)
  741. toNextTick+=750;
  742. }
  743. void CInfoBar::newDay(int Day)
  744. {
  745. if(LOCPLINT->cb->getDate(1) != 1)
  746. {
  747. mode = 0; //showing day
  748. }
  749. else
  750. {
  751. switch(LOCPLINT->cb->getDate(2))
  752. {
  753. case 1:
  754. mode = 1;
  755. break;
  756. case 2:
  757. mode = 2;
  758. break;
  759. case 3:
  760. mode = 3;
  761. break;
  762. case 4:
  763. mode = 4;
  764. break;
  765. default:
  766. mode = -1;
  767. break;
  768. }
  769. }
  770. pom = 0;
  771. TimeInterested::activate();
  772. toNextTick = 500;
  773. blitAnim(mode);
  774. //blitAt(day->ourImages[pom].bitmap,pos.x+10,pos.y+10);
  775. }
  776. void CInfoBar::showComp(SComponent * comp, int time)
  777. {
  778. SDL_Surface * b = BitmapHandler::loadBitmap("ADSTATOT.bmp");
  779. blitAt(b,pos.x+8,pos.y+11);
  780. blitAt(comp->getImg(),pos.x+52,pos.y+54);
  781. printAtMiddle(comp->subtitle,pos.x+91,pos.y+158,GEOR13,zwykly);
  782. printAtMiddleWB(comp->description,pos.x+94,pos.y+31,GEOR13,26,zwykly);
  783. SDL_FreeSurface(b);
  784. TimeInterested::activate();
  785. mode = 6;
  786. toNextTick = time;
  787. }
  788. void CInfoBar::tick()
  789. {
  790. if((mode >= 0) && (mode < 5))
  791. {
  792. pom++;
  793. if (pom >= getAnim(mode)->ourImages.size())
  794. {
  795. TimeInterested::deactivate();
  796. toNextTick = -1;
  797. mode = 5;
  798. draw();
  799. return;
  800. }
  801. toNextTick = 150;
  802. blitAnim(mode);
  803. }
  804. else if (mode == 6)
  805. {
  806. TimeInterested::deactivate();
  807. toNextTick = -1;
  808. mode = 5;
  809. draw();
  810. }
  811. }
  812. CAdvMapInt::CAdvMapInt(int Player)
  813. :player(Player),
  814. statusbar(7,556),
  815. kingOverview(CGI->preth->zelp[293].first,CGI->preth->zelp[293].second,
  816. boost::bind(&CAdvMapInt::fshowOverview,this), 679, 196, "IAM002.DEF", false,NULL,true),
  817. underground(CGI->preth->zelp[294].first,CGI->preth->zelp[294].second,
  818. boost::bind(&CAdvMapInt::fswitchLevel,this), 711, 196, "IAM010.DEF", false, new std::vector<std::string>(1,std::string("IAM003.DEF")),true),
  819. questlog(CGI->preth->zelp[295].first,CGI->preth->zelp[295].second,
  820. boost::bind(&CAdvMapInt::fshowQuestlog,this), 679, 228, "IAM004.DEF", false,NULL,true),
  821. sleepWake(CGI->preth->zelp[296].first,CGI->preth->zelp[296].second,
  822. boost::bind(&CAdvMapInt::fsleepWake,this), 711, 228, "IAM005.DEF", false,NULL,true),
  823. moveHero(CGI->preth->zelp[297].first,CGI->preth->zelp[297].second,
  824. boost::bind(&CAdvMapInt::fmoveHero,this), 679, 260, "IAM006.DEF", false,NULL,true),
  825. spellbook(CGI->preth->zelp[298].first,CGI->preth->zelp[298].second,
  826. boost::bind(&CAdvMapInt::fshowSpellbok,this), 711, 260, "IAM007.DEF", false,NULL,true),
  827. advOptions(CGI->preth->zelp[299].first,CGI->preth->zelp[299].second,
  828. boost::bind(&CAdvMapInt::fadventureOPtions,this), 679, 292, "IAM008.DEF", false,NULL,true),
  829. sysOptions(CGI->preth->zelp[300].first,CGI->preth->zelp[300].second,
  830. boost::bind(&CAdvMapInt::fsystemOptions,this), 711, 292, "IAM009.DEF", false,NULL,true),
  831. nextHero(CGI->preth->zelp[301].first,CGI->preth->zelp[301].second,
  832. boost::bind(&CAdvMapInt::fnextHero,this), 679, 324, "IAM000.DEF", false,NULL,true),
  833. endTurn(CGI->preth->zelp[302].first,CGI->preth->zelp[302].second,
  834. boost::bind(&CAdvMapInt::fendTurn,this), 679, 356, "IAM001.DEF", false,NULL,true),
  835. townList(5,&genRect(192,48,747,196),747,196,747,372)
  836. {
  837. townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this);
  838. LOCPLINT->adventureInt=this;
  839. bg = BitmapHandler::loadBitmap("ADVMAP.bmp");
  840. graphics->blueToPlayersAdv(bg,player);
  841. scrollingLeft = false;
  842. scrollingRight = false;
  843. scrollingUp = false ;
  844. scrollingDown = false ;
  845. updateScreen = false;
  846. anim=0;
  847. animValHitCount=0; //animation frame
  848. heroAnim=0;
  849. heroAnimValHitCount=0; // hero animation frame
  850. heroList.init();
  851. heroList.genList();
  852. //townList.init();
  853. townList.genList();
  854. heroWindow = new CHeroWindow(this->player);
  855. gems.push_back(CDefHandler::giveDef("agemLL.def"));
  856. gems.push_back(CDefHandler::giveDef("agemLR.def"));
  857. gems.push_back(CDefHandler::giveDef("agemUL.def"));
  858. gems.push_back(CDefHandler::giveDef("agemUR.def"));
  859. }
  860. void CAdvMapInt::fshowOverview()
  861. {
  862. }
  863. void CAdvMapInt::fswitchLevel()
  864. {
  865. if(!CGI->mh->map->twoLevel)
  866. return;
  867. if (position.z)
  868. {
  869. position.z--;
  870. underground.curimg=0;
  871. underground.show();
  872. }
  873. else
  874. {
  875. underground.curimg=1;
  876. position.z++;
  877. underground.show();
  878. }
  879. updateScreen = true;
  880. minimap.draw();
  881. }
  882. void CAdvMapInt::fshowQuestlog()
  883. {
  884. }
  885. void CAdvMapInt::fsleepWake()
  886. {
  887. }
  888. void CAdvMapInt::fmoveHero()
  889. {
  890. if (selection.type!=HEROI_TYPE)
  891. return;
  892. if (!terrain.currentPath)
  893. return;
  894. CPath sended(*(terrain.currentPath)); //temporary path - engine will operate on it
  895. LOCPLINT->cb->moveHero( ((const CGHeroInstance*)LOCPLINT->adventureInt->selection.selected)->type->ID,&sended,1,0);
  896. }
  897. void CAdvMapInt::fshowSpellbok()
  898. {
  899. }
  900. void CAdvMapInt::fadventureOPtions()
  901. {
  902. }
  903. void CAdvMapInt::fsystemOptions()
  904. {
  905. }
  906. void CAdvMapInt::fnextHero()
  907. {
  908. }
  909. void CAdvMapInt::fendTurn()
  910. {
  911. LOCPLINT->makingTurn = false;
  912. }
  913. void CAdvMapInt::activate()
  914. {
  915. LOCPLINT->curint = this;
  916. LOCPLINT->statusbar = &statusbar;
  917. kingOverview.activate();
  918. underground.activate();
  919. questlog.activate();
  920. sleepWake.activate();
  921. moveHero.activate();
  922. spellbook.activate();
  923. sysOptions.activate();
  924. advOptions.activate();
  925. nextHero.activate();
  926. endTurn.activate();
  927. minimap.activate();
  928. heroList.activate();
  929. townList.activate();
  930. terrain.activate();
  931. show();
  932. }
  933. void CAdvMapInt::deactivate()
  934. {
  935. hide();
  936. }
  937. void CAdvMapInt::show()
  938. {
  939. blitAt(bg,0,0);
  940. kingOverview.show();
  941. underground.show();
  942. questlog.show();
  943. sleepWake.show();
  944. moveHero.show();
  945. spellbook.show();
  946. advOptions.show();
  947. sysOptions.show();
  948. nextHero.show();
  949. endTurn.show();
  950. minimap.draw();
  951. heroList.draw();
  952. townList.draw();
  953. update();
  954. resdatabar.draw();
  955. statusbar.show();
  956. infoBar.draw();
  957. CSDL_Ext::update(screen);
  958. }
  959. void CAdvMapInt::hide()
  960. {
  961. kingOverview.deactivate();
  962. underground.deactivate();
  963. questlog.deactivate();
  964. sleepWake.deactivate();
  965. moveHero.deactivate();
  966. spellbook.deactivate();
  967. advOptions.deactivate();
  968. sysOptions.deactivate();
  969. nextHero.deactivate();
  970. endTurn.deactivate();
  971. minimap.deactivate();
  972. heroList.deactivate();
  973. townList.deactivate();
  974. terrain.deactivate();
  975. if(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar)!=LOCPLINT->timeinterested.end())
  976. LOCPLINT->timeinterested.erase(std::find(LOCPLINT->timeinterested.begin(),LOCPLINT->timeinterested.end(),&infoBar));
  977. infoBar.mode=-1;
  978. }
  979. void CAdvMapInt::update()
  980. {
  981. terrain.show();
  982. blitAt(gems[2]->ourImages[LOCPLINT->playerID].bitmap,6,6);
  983. blitAt(gems[0]->ourImages[LOCPLINT->playerID].bitmap,6,508);
  984. blitAt(gems[1]->ourImages[LOCPLINT->playerID].bitmap,556,508);
  985. blitAt(gems[3]->ourImages[LOCPLINT->playerID].bitmap,556,6);
  986. //updateRect(&genRect(550,600,6,6));
  987. }
  988. void CAdvMapInt::selectionChanged()
  989. {
  990. const CGTownInstance *to = townList.items[townList.selected];
  991. centerOn(to->pos);
  992. selection.type = TOWNI_TYPE;
  993. selection.selected = to;
  994. terrain.currentPath = NULL;
  995. townList.draw();
  996. heroList.draw();
  997. infoBar.draw(NULL);
  998. }
  999. void CAdvMapInt::centerOn(int3 on)
  1000. {
  1001. on.x -= (LOCPLINT->adventureInt->terrain.tilesw/2);
  1002. on.y -= (LOCPLINT->adventureInt->terrain.tilesh/2);
  1003. if (on.x<0)
  1004. on.x=-(Woff/2);
  1005. else if((on.x+LOCPLINT->adventureInt->terrain.tilesw) > (CGI->mh->sizes.x))
  1006. on.x=CGI->mh->sizes.x-LOCPLINT->adventureInt->terrain.tilesw+(Woff/2);
  1007. if (on.y<0)
  1008. on.y = -(Hoff/2);
  1009. else if((on.y+LOCPLINT->adventureInt->terrain.tilesh) > (CGI->mh->sizes.y))
  1010. on.y = CGI->mh->sizes.y-LOCPLINT->adventureInt->terrain.tilesh+(Hoff/2);
  1011. LOCPLINT->adventureInt->position.x=on.x;
  1012. LOCPLINT->adventureInt->position.y=on.y;
  1013. LOCPLINT->adventureInt->position.z=on.z;
  1014. LOCPLINT->adventureInt->updateScreen=true;
  1015. updateMinimap=true;
  1016. }
  1017. CAdvMapInt::CurrentSelection::CurrentSelection()
  1018. {
  1019. type=-1;
  1020. selected=NULL;
  1021. }
  1022. void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * client)
  1023. {
  1024. if (down)
  1025. {
  1026. boost::algorithm::erase_all(text,"\"");
  1027. CSimpleWindow * temp = CMessage::genWindow(text,LOCPLINT->playerID);
  1028. temp->pos.x=300-(temp->pos.w/2);
  1029. temp->pos.y=300-(temp->pos.h/2);
  1030. temp->owner = client;
  1031. LOCPLINT->objsToBlit.push_back(temp);
  1032. }
  1033. else
  1034. {
  1035. for (int i=0;i<LOCPLINT->objsToBlit.size();i++)
  1036. {
  1037. //TODO: pewnie da sie to zrobic lepiej, ale nie chce mi sie. Wolajacy obiekt powinien informowac kogo spodziewa sie odwolac (null jesli down)
  1038. CSimpleWindow * pom = dynamic_cast<CSimpleWindow*>(LOCPLINT->objsToBlit[i]);
  1039. if (!pom)
  1040. continue;
  1041. if (pom->owner==client)
  1042. {
  1043. LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+(i));
  1044. delete pom;
  1045. }
  1046. }
  1047. }
  1048. }
  1049. int3 CAdvMapInt::verifyPos(int3 ver)
  1050. {
  1051. if (ver.x<0)
  1052. ver.x=0;
  1053. if (ver.y<0)
  1054. ver.y=0;
  1055. if (ver.z<0)
  1056. ver.z=0;
  1057. if (ver.x>=CGI->mh->sizes.x)
  1058. ver.x=CGI->mh->sizes.x-1;
  1059. if (ver.y>=CGI->mh->sizes.y)
  1060. ver.y=CGI->mh->sizes.y-1;
  1061. if (ver.z>=CGI->mh->sizes.z)
  1062. ver.z=CGI->mh->sizes.z-1;
  1063. return ver;
  1064. }