diff --git a/CCallback.cpp b/CCallback.cpp index e16189839..8e014a23f 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -107,9 +107,27 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) { //performing move hero->movement-=CGI->mh->getCost(stpos, endpos, hero); - for(int xd=0; xdac->map.width; ++xd) //revealing part of map around heroes + int heroSight = hero->getSightDistance(); + + int xbeg = stpos.x - heroSight - 2; + if(xbeg < 0) + xbeg = 0; + + int xend = stpos.x + heroSight + 2; + if(xend >= CGI->ac->map.width) + xend = CGI->ac->map.width - 1; + + int ybeg = stpos.y - heroSight - 2; + if(ybeg < 0) + ybeg = 0; + + int yend = stpos.y + heroSight + 2; + if(yend >= CGI->ac->map.height) + yend = CGI->ac->map.height - 1; + + for(int xd=xbeg; xdac->map.height; ++yd) + for(int yd=ybeg; ydgetPosition(false).x-xd)*(hero->getPosition(false).x-xd); int deltaY = (hero->getPosition(false).y-yd)*(hero->getPosition(false).y-yd); diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 7905d91d2..ef36a49d5 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -4,6 +4,8 @@ #include "CGeneralTextHandler.h" #include "CLodHandler.h" #include "CAmbarCendamo.h" +#include "mapHandler.h" +#include "CDefObjInfoHandler.h" void CObjectHandler::loadObjects() { @@ -42,3 +44,22 @@ bool CObjectInstance::operator <(const CObjectInstance &cmp) const return true; return false; } + +int CObjectInstance::getWidth() const +{ + return CGI->mh->reader->map.defy[defNumber].handler->ourImages[0].bitmap->w/32; +} + +int CObjectInstance::getHeight() const +{ + return CGI->mh->reader->map.defy[defNumber].handler->ourImages[0].bitmap->h/32; +} + +bool CObjectInstance::visitableAt(int x, int y) const +{ + if(x<0 || y<0 || x>=getWidth() || y>=getHeight()) + return false; + if((CGI->dobjinfo->objs[defObjInfoNumber].visitMap[y] >> (7-x)) & 1) + return true; + return false; +} diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 76f41540c..d59d5c440 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -301,6 +301,9 @@ public: bool isStanding; //true if is standing, flase if is moving unsigned char flagPrinted; //true if flag has been printed //number of print hits unsigned char owner; //if 254, object cannot have owner; if it has, it equal to owner's ID (or 255, when no owner) + int getWidth() const; //returns width of object graphic in tiles + int getHeight() const; //returns height of object graphic in tiles + bool visitableAt(int x, int y) const; //returns true if ibject is visitable at location (x, y) form left top tile of image (x, y in tiles) bool operator<(const CObjectInstance & cmp) const; //screen printing priority comparing }; diff --git a/mapHandler.cpp b/mapHandler.cpp index c19bf731d..b4bd33382 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -1367,3 +1367,15 @@ std::vector < std::string > CMapHandler::getObjDescriptions(int3 pos) } return ret; } + +std::vector < CObjectInstance * > CMapHandler::getVisitableObjs(int3 pos) +{ + std::vector < CObjectInstance * > ret; + for(int h=0; hvisitableAt(curi->pos.x - pos.x, curi->pos.y - pos.y)) + ret.push_back(curi); + } + return ret; +} diff --git a/mapHandler.h b/mapHandler.h index 6741c98ca..057ba1647 100644 --- a/mapHandler.h +++ b/mapHandler.h @@ -79,6 +79,7 @@ public: int getCost(int3 & a, int3 & b, const CHeroInstance * hero); std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position + std::vector< CObjectInstance * > getVisitableObjs(int3 pos); //returns vector of visitable objects at certain position void init(); SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, PseudoV< PseudoV< PseudoV > > & visibilityMap = CGI->mh->visibility); SDL_Surface * terrBitmap(int x, int y);