Browse Source

* small improvements
* probably working getting visitable objects at certain position (to be tested)

mateuszb 18 years ago
parent
commit
c18e4573f1
5 changed files with 57 additions and 2 deletions
  1. 20 2
      CCallback.cpp
  2. 21 0
      hch/CObjectHandler.cpp
  3. 3 0
      hch/CObjectHandler.h
  4. 12 0
      mapHandler.cpp
  5. 1 0
      mapHandler.h

+ 20 - 2
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; xd<CGI->ac->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; xd<xend; ++xd) //revealing part of map around heroes
 			{
-				for(int yd=0; yd<CGI->ac->map.height; ++yd)
+				for(int yd=ybeg; yd<yend; ++yd)
 				{
 					int deltaX = (hero->getPosition(false).x-xd)*(hero->getPosition(false).x-xd);
 					int deltaY = (hero->getPosition(false).y-yd)*(hero->getPosition(false).y-yd);

+ 21 - 0
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;
+}

+ 3 - 0
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
 };
 

+ 12 - 0
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; h<ttiles[pos.x][pos.y][pos.z].objects.size(); ++h)
+	{
+		CObjectInstance * curi = ttiles[pos.x][pos.y][pos.z].objects[h].first;
+		if(curi->visitableAt(curi->pos.x - pos.x, curi->pos.y - pos.y))
+			ret.push_back(curi);
+	}
+	return ret;
+}

+ 1 - 0
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<unsigned char> > > & visibilityMap = CGI->mh->visibility);
 	SDL_Surface * terrBitmap(int x, int y);