diff --git a/client/CAdvmapInterface.cpp b/client/CAdvmapInterface.cpp index 608d0fc38..1d7777867 100644 --- a/client/CAdvmapInterface.cpp +++ b/client/CAdvmapInterface.cpp @@ -1461,16 +1461,16 @@ void CAdvMapInt::show(SDL_Surface *to) || SDL_GetKeyState(NULL)[SDLK_RCTRL] ) { - if( (scrollingDir & LEFT) && (position.x>-Woff) ) + if( (scrollingDir & LEFT) && (position.x>-CGI->mh->frame.left) ) position.x--; - if( (scrollingDir & RIGHT) && (position.x < CGI->mh->map->width - terrain.tilesw + Woff) ) + if( (scrollingDir & RIGHT) && (position.x < CGI->mh->map->width - terrain.tilesw + CGI->mh->frame.right) ) position.x++; - if( (scrollingDir & UP) && (position.y>-Hoff) ) + if( (scrollingDir & UP) && (position.y>-CGI->mh->frame.top) ) position.y--; - if( (scrollingDir & DOWN) && (position.y < CGI->mh->map->height - terrain.tilesh + Hoff) ) + if( (scrollingDir & DOWN) && (position.y < CGI->mh->map->height - terrain.tilesh + CGI->mh->frame.bottom) ) position.y++; if(scrollingDir) diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 5f75f531a..b5bf996a3 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -1024,14 +1024,14 @@ void CPlayerInterface::handleEvent(SDL_Event *sEvent) int3 CPlayerInterface::repairScreenPos(int3 pos) { - if(pos.x<=-Woff) - pos.x = -Woff+1; - if(pos.y<=-Hoff) - pos.y = -Hoff+1; - if(pos.x>CGI->mh->map->width - this->adventureInt->terrain.tilesw + Woff) - pos.x = CGI->mh->map->width - this->adventureInt->terrain.tilesw + Woff; - if(pos.y>CGI->mh->map->height - this->adventureInt->terrain.tilesh + Hoff) - pos.y = CGI->mh->map->height - this->adventureInt->terrain.tilesh + Hoff; + if(pos.x<=-CGI->mh->frame.left) + pos.x = -CGI->mh->frame.left+1; + if(pos.y<=-CGI->mh->frame.top) + pos.y = -CGI->mh->frame.top+1; + if(pos.x>CGI->mh->map->width - this->adventureInt->terrain.tilesw + CGI->mh->frame.right) + pos.x = CGI->mh->map->width - this->adventureInt->terrain.tilesw + CGI->mh->frame.right; + if(pos.y>CGI->mh->map->height - this->adventureInt->terrain.tilesh + CGI->mh->frame.bottom) + pos.y = CGI->mh->map->height - this->adventureInt->terrain.tilesh + CGI->mh->frame.bottom; return pos; } void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val) @@ -1736,4 +1736,4 @@ const CGHeroInstance * CPlayerInterface::getWHero( int pos ) if(pos < 0 || pos >= wanderingHeroes.size()) return NULL; return wanderingHeroes[pos]; -} \ No newline at end of file +} diff --git a/mapHandler.cpp b/mapHandler.cpp index 18babf488..305f7873c 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -15,6 +15,7 @@ #include "hch/CObjectHandler.h" #include "lib/map.h" #include "hch/CDefHandler.h" +#include "client/CConfigHandler.h" /* * mapHandler.cpp, part of VCMI engine @@ -204,17 +205,20 @@ void CMapHandler::roadsRiverTerrainInit() sizes.x = CGI->mh->map->width; sizes.y = CGI->mh->map->height; sizes.z = CGI->mh->map->twoLevel+1; - ttiles.resize(CGI->mh->map->width,Woff); - for (int i=0-Woff;imh->map->width, frame.left, frame.right); + for (int i=0-frame.left;imh->map->height,Hoff); + ttiles[i].resize(CGI->mh->map->height, frame.top, frame.bottom); } - for (int i=0-Woff;imh->map->height+Hoff;j++) - ttiles[i][j].resize(CGI->mh->map->twoLevel+1,0); + for (int j=0-frame.top;j<(int)CGI->mh->map->height+frame.bottom;j++) + ttiles[i][j].resize(CGI->mh->map->twoLevel+1, 0, 0); } + // Draw the map for (int i=0; iwidth; i++) //jest po szeroko�ci { for (int j=0; jheight;j++) //po wysoko�ci @@ -311,9 +315,9 @@ void CMapHandler::borderAndTerrainBitmapInit() delete hlp; } - for (int i=0-Woff; iwidth+Woff; i++) //jest po szeroko�ci + for (int i=0-frame.left; iwidth+frame.right; i++) //jest po szeroko�ci { - for (int j=0-Hoff; jheight+Hoff;j++) //po wysoko�ci + for (int j=0-frame.top; jheight+frame.bottom;j++) //po wysoko�ci { for(int k=0; k<=map->twoLevel; ++k) { @@ -398,9 +402,9 @@ void CMapHandler::initObjectRects() std::pair toAdd = std::make_pair(map->objects[f],cr); if( (map->objects[f]->pos.x + fx - bitmap->w/32+1) >= 0 - && (map->objects[f]->pos.x + fx - bitmap->w/32+1) < ttiles.size() - Woff + && (map->objects[f]->pos.x + fx - bitmap->w/32+1) < ttiles.size() - frame.right && (map->objects[f]->pos.y + fy - bitmap->h/32+1) >= 0 - && (map->objects[f]->pos.y + fy - bitmap->h/32+1) < ttiles[0].size() - Hoff + && (map->objects[f]->pos.y + fy - bitmap->h/32+1) < ttiles[0].size() - frame.bottom ) { //TerrainTile2 & curt = @@ -414,9 +418,9 @@ void CMapHandler::initObjectRects() } //for(int fx=0; fxw/32; ++fx) }//if curd } // for(int f=0; fobjects.size(); ++f) - for(int ix=0; ixac.tilesW-1) / 2; + frame.right = (conf.go()->ac.tilesW) / 2; + frame.top = (conf.go()->ac.tilesH-1) / 2; + frame.bottom = (conf.go()->ac.tilesH) / 2; + std::ifstream ifs("config/townsDefs.txt"); int ccc; ifs>>ccc; @@ -531,9 +546,9 @@ void CMapHandler::init() SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, std::vector< std::vector< std::vector > > * visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect, int moveX, int moveY, bool smooth) { int srx, sry; - - // Temporarily disable smoothing as it is source of crashes - smooth = false; + + // Temporarily disable smoothing as it is source of crashes + smooth = false; if(!otherHeroAnim) heroAnim = anim; //the same, as it should be @@ -551,12 +566,16 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, SDL_GetClipRect(su, &prevClip); if(extRect) SDL_SetClipRect(su, extRect); //preventing blitting outside of that rect - if (((dx+x)>((map->width+Woff)) || (dy+y)>((map->height+Hoff))) || ((x<-Woff)||(y<-Hoff) ) ) - throw std::string("terrainRect: out of range"); - dx += smooth?1:0; dy += smooth?1:0; + // Sanity check - TODO: fails if smooth mode + if (dx+x > map->width+frame.right || + dy+y > map->height+frame.bottom || + x<-frame.left || + y<-frame.right) + throw std::string("terrainRect: out of range"); + ////printing terrain srx = (moveX <= 0 ? 0 : -1) * 32; if (smooth) @@ -1234,7 +1253,7 @@ bool CMapHandler::printObject(const CGObjectInstance *obj) cr.x = fx*32; cr.y = fy*32; std::pair toAdd = std::make_pair(obj, cr); - if((obj->pos.x + fx - bitmap->w/32+1)>=0 && (obj->pos.x + fx - bitmap->w/32+1)pos.y + fy - bitmap->h/32+1)>=0 && (obj->pos.y + fy - bitmap->h/32+1)pos.x + fx - bitmap->w/32+1)>=0 && (obj->pos.x + fx - bitmap->w/32+1)pos.y + fy - bitmap->h/32+1)>=0 && (obj->pos.y + fy - bitmap->h/32+1)h/32; ++fy) { - if((obj->pos.x + fx - bitmap->w/32+1)>=0 && (obj->pos.x + fx - bitmap->w/32+1)pos.y + fy - bitmap->h/32+1)>=0 && (obj->pos.y + fy - bitmap->h/32+1)pos.x + fx - bitmap->w/32+1)>=0 && (obj->pos.x + fx - bitmap->w/32+1)pos.y + fy - bitmap->h/32+1)>=0 && (obj->pos.y + fy - bitmap->h/32+1) > & ctile = ttiles[obj->pos.x + fx - bitmap->w/32+1][obj->pos.y + fy - bitmap->h/32+1][obj->pos.z].objects; for(size_t dd=0; dd < ctile.size(); ++dd) @@ -1448,6 +1467,7 @@ CMapHandler::~CMapHandler() CMapHandler::CMapHandler() { + frame.left = frame.right = frame.top = frame.bottom = 0; fullHide = NULL; partialHide = NULL; } diff --git a/mapHandler.h b/mapHandler.h index c612ad4d0..f5cc72ed9 100644 --- a/mapHandler.h +++ b/mapHandler.h @@ -4,9 +4,6 @@ #include #include -const int Woff = 14; //width of map's frame -const int Hoff = 10; - /* * mapHandler.h, part of VCMI engine * @@ -48,15 +45,15 @@ public: int offset; std::vector inver; PseudoV(){}; - PseudoV(std::vector &src, int rest, int Offset, const T& fill) + PseudoV(std::vector &src, int rest, int before, int after, const T& fill) { - inver.resize(Offset*2+rest); - offset=Offset; - for(int i=0; i > > ttiles; //informations about map tiles - int3 sizes; //map size (x - width, y - height, z - number of levels) + int3 sizes; //map size (x = width, y = height, z = number of levels) Mapa * map; + + // size of each side of the frame around the whole map + struct { + int left; + int right; + int top; + int bottom; + } frame; + std::set usedHeroes; CDefHandler * fullHide; //for Fog of War CDefHandler * partialHide; //for For of War