CAdvmapInterface.cpp 30 KB

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