Browse Source

cieniowanie i drobne poprawki

zawiera drobny błąd wyświetlania cienia (walnięta funkcja do flipowania)
mateuszb 18 years ago
parent
commit
4075ab1b92
10 changed files with 422 additions and 39 deletions
  1. 7 7
      CMT.cpp
  2. 4 4
      CSemiDefHandler.cpp
  3. 2 2
      CSemiDefHandler.h
  4. 2 2
      CSemiLodHandler.cpp
  5. 1 1
      CSemiLodHandler.h
  6. 83 7
      SDL_Extensions.cpp
  7. 8 5
      SDL_Extensions.h
  8. 3 3
      map.h
  9. 293 5
      mapHandler.cpp
  10. 19 3
      mapHandler.h

+ 7 - 7
CMT.cpp

@@ -188,7 +188,7 @@ void zerr(int ret)
 
 
 
-void SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B)
+/*void SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B)
 {
 	 Uint8 *p = (Uint8 *)ekran->pixels + y * ekran->pitch + x * ekran->format->BytesPerPixel;
 	 if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
@@ -204,7 +204,7 @@ void SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B)
 		  p[2] = R;
 	 }
 	 SDL_UpdateRect(ekran, x, y, 1, 1);
-}
+}*/
 int _tmain(int argc, _TCHAR* argv[])
 { 
 	int xx=0, yy=0, zz=0;
@@ -283,7 +283,7 @@ int _tmain(int argc, _TCHAR* argv[])
 		CObjectHandler * objh = new CObjectHandler;
 		objh->loadObjects();
 		cgi->objh = objh;
-		CAmbarCendamo * ac = new CAmbarCendamo("4gryf"); //4gryf
+		CAmbarCendamo * ac = new CAmbarCendamo("9gryf"); //4gryf
 		CMapHeader * mmhh = new CMapHeader(ac->bufor); //czytanie nag³ówka
 		cgi->ac = ac;
 		THC std::cout<<"Wczytywanie pliku: "<<tmh.getDif()<<std::endl;
@@ -291,17 +291,17 @@ int _tmain(int argc, _TCHAR* argv[])
 		THC std::cout<<"Rozpoznawianie pliku lacznie: "<<tmh.getDif()<<std::endl;
 		ac->loadDefs();
 		THC std::cout<<"Wczytywanie defow: "<<tmh.getDif()<<std::endl;
-		mapHandler * mh = new mapHandler();
+		CMapHandler * mh = new CMapHandler();
 		mh->reader = ac;
 		THC std::cout<<"Stworzenie mapHandlera: "<<tmh.getDif()<<std::endl;
 		mh->init();
 		THC std::cout<<"Inicjalizacja mapHandlera: "<<tmh.getDif()<<std::endl;
 		//SDL_Rect * sr = new SDL_Rect(); sr->h=64;sr->w=64;sr->x=0;sr->y=0;
-		SDL_Surface * teren = mh->terrainRect(xx,yy,32,24);
+		SDL_Surface * teren = mh->terrainRect(xx,yy,25,19);
 		THC std::cout<<"Przygotowanie terenu do wyswietlenia: "<<tmh.getDif()<<std::endl;
 		SDL_BlitSurface(teren,NULL,ekran,NULL);
 		SDL_FreeSurface(teren);
-		SDL_Flip(ekran);
+		SDL_UpdateRect(ekran, 0, 0, ekran->w, ekran->h);
 		THC std::cout<<"Wyswietlenie terenu: "<<tmh.getDif()<<std::endl;
 
 		//SDL_Surface * ss = ac->defs[0]->ourImages[0].bitmap;
@@ -428,7 +428,7 @@ int _tmain(int argc, _TCHAR* argv[])
 					SDL_Surface * help = mh->terrainRect(xx,yy,25,18,zz);
 					SDL_BlitSurface(help,NULL,ekran,NULL);
 					SDL_FreeSurface(help);
-					SDL_Flip(ekran);
+					SDL_UpdateRect(ekran, 0, 0, ekran->w, ekran->h);
 					updateScreen = false;
 				}
 				/////////

+ 4 - 4
CSemiDefHandler.cpp

@@ -58,7 +58,7 @@ std::string CSemiDefHandler::nameFromType (EterrainType typ)
 		}
 	}
 }
-void CSemiDefHandler::openDef(std::string name, std::string lodName)
+void CSemiDefHandler::openDef(std::string name, std::string lodName, int dist)
 {
 	std::ifstream * is = new std::ifstream();
 	is -> open((lodName+"\\"+name).c_str(),std::ios::binary);
@@ -72,11 +72,11 @@ void CSemiDefHandler::openDef(std::string name, std::string lodName)
 	defName = defName.substr(gdzie+1, gdzie-defName.length());
 	delete is;
 
-	readFileList();
+	readFileList(dist);
 	loadImages(lodName);
 
 }
-void CSemiDefHandler::readFileList()
+void CSemiDefHandler::readFileList(int dist)
 {
 	howManyImgs = buforD[788];
 	int i = 800;
@@ -87,7 +87,7 @@ void CSemiDefHandler::readFileList()
 		{
 			temp+=buforD[i++];
 		}
-		i++;;
+		i+=dist; //by³o zwiêkszenie tylko o jedno
 		if (temp!="")
 		{
 			temp = temp.substr(0,temp.length()-4) + ".BMP";

+ 2 - 2
CSemiDefHandler.h

@@ -22,8 +22,8 @@ public:
 
 	static std::string nameFromType(EterrainType typ);
 	void openImg(const char *name);
-	void openDef(std::string name, std::string lodName);
-	void readFileList();
+	void openDef(std::string name, std::string lodName, int dist=1);
+	void readFileList(int dist = 1);
 	void loadImages(std::string path);
 };
 #endif // SEMIDEF_H

+ 2 - 2
CSemiLodHandler.cpp

@@ -4,9 +4,9 @@ void CSemiLodHandler::openLod(std::string path)
 {
 	ourName = path;
 };
-CSemiDefHandler * CSemiLodHandler::giveDef(std::string name)
+CSemiDefHandler * CSemiLodHandler::giveDef(std::string name, int dist)
 {
 	CSemiDefHandler * ret = new CSemiDefHandler();
-	ret->openDef(name, ourName);
+	ret->openDef(name, ourName, dist);
 	return ret;
 };

+ 1 - 1
CSemiLodHandler.h

@@ -7,7 +7,7 @@ class CSemiLodHandler
 public:
 	std::string ourName; // name of our lod
 	void openLod(std::string path);
-	CSemiDefHandler * giveDef(std::string name); //loads def from our lod
+	CSemiDefHandler * giveDef(std::string name, int dist=1); //loads def from our lod
 };
 
 #endif //CSEMILODHANDLER_H

+ 83 - 7
SDL_Extensions.cpp

@@ -1,6 +1,7 @@
 #include "stdafx.h"
 #include "SDL_Extensions.h"
 #include "SDL_TTF.h"
+#include <iostream>
 extern SDL_Surface * ekran;
 extern SDL_Color tytulowy, tlo, zwykly ;
 bool isItIn(const SDL_Rect * rect, int x, int y)
@@ -42,7 +43,7 @@ void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=ty
 	SDL_UpdateRect(dst,x,y,temp->w,temp->h);
 	SDL_FreeSurface(temp);
 }
-void CSDL_Ext::SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC)
+void CSDL_Ext::SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC, Uint8 A)
 {
      Uint8 *p = (Uint8 *)ekran->pixels + y * ekran->pitch + x * ekran->format->BytesPerPixel-myC;
      if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
@@ -63,10 +64,11 @@ void CSDL_Ext::SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G,
 ///**************/
 ///Reverses the toRot surface by the vertical axis
 ///**************/
-SDL_Surface * CSDL_Ext::rotate01(SDL_Surface * toRot)
+SDL_Surface * CSDL_Ext::rotate01(SDL_Surface * toRot, int myC)
 {
 	SDL_Surface * first = SDL_CreateRGBSurface(toRot->flags, toRot->w, toRot->h, toRot->format->BitsPerPixel, toRot->format->Rmask, toRot->format->Gmask, toRot->format->Bmask, toRot->format->Amask);
 	SDL_Surface * ret = SDL_ConvertSurface(first, toRot->format, toRot->flags);
+	//SDL_SetColorKey(ret, SDL_SRCCOLORKEY, toRot->format->colorkey);
 	for(int i=0; i<ret->w; ++i)
 	{
 		for(int j=0; j<ret->h; ++j)
@@ -75,11 +77,11 @@ SDL_Surface * CSDL_Ext::rotate01(SDL_Surface * toRot)
 				Uint8 *p = (Uint8 *)toRot->pixels + j * toRot->pitch + (ret->w - i - 1) * toRot->format->BytesPerPixel;
 				if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
 				{
-					CSDL_Ext::SDL_PutPixel(ret, i, j, p[0], p[1], p[2], 2);
+					CSDL_Ext::SDL_PutPixel(ret, i, j, p[0], p[1], p[2], myC);
 				}
 				else
 				{
-					CSDL_Ext::SDL_PutPixel(ret, i, j, p[2], p[1], p[0], 2);
+					CSDL_Ext::SDL_PutPixel(ret, i, j, p[2], p[1], p[0], myC);
 				}
 			}
 		}
@@ -91,6 +93,7 @@ SDL_Surface * CSDL_Ext::hFlip(SDL_Surface * toRot)
 {
 	SDL_Surface * first = SDL_CreateRGBSurface(toRot->flags, toRot->w, toRot->h, toRot->format->BitsPerPixel, toRot->format->Rmask, toRot->format->Gmask, toRot->format->Bmask, toRot->format->Amask);
 	SDL_Surface * ret = SDL_ConvertSurface(first, toRot->format, toRot->flags);
+	//SDL_SetColorKey(ret, SDL_SRCCOLORKEY, toRot->format->colorkey);
 	for(int i=0; i<ret->w; ++i)
 	{
 		for(int j=0; j<ret->h; ++j)
@@ -120,6 +123,7 @@ SDL_Surface * CSDL_Ext::rotate02(SDL_Surface * toRot)
 {
 	SDL_Surface * first = SDL_CreateRGBSurface(toRot->flags, toRot->h, toRot->w, toRot->format->BitsPerPixel, toRot->format->Rmask, toRot->format->Gmask, toRot->format->Bmask, toRot->format->Amask);
 	SDL_Surface * ret = SDL_ConvertSurface(first, toRot->format, toRot->flags);
+	//SDL_SetColorKey(ret, SDL_SRCCOLORKEY, toRot->format->colorkey);
 	for(int i=0; i<ret->w; ++i)
 	{
 		for(int j=0; j<ret->h; ++j)
@@ -148,6 +152,7 @@ SDL_Surface * CSDL_Ext::rotate03(SDL_Surface * toRot)
 {
 	SDL_Surface * first = SDL_CreateRGBSurface(toRot->flags, toRot->w, toRot->h, toRot->format->BitsPerPixel, toRot->format->Rmask, toRot->format->Gmask, toRot->format->Bmask, toRot->format->Amask);
 	SDL_Surface * ret = SDL_ConvertSurface(first, toRot->format, toRot->flags);
+	//SDL_SetColorKey(ret, SDL_SRCCOLORKEY, toRot->format->colorkey);
 	for(int i=0; i<ret->w; ++i)
 	{
 		for(int j=0; j<ret->h; ++j)
@@ -207,7 +212,7 @@ SDL_Cursor * CSDL_Ext::SurfaceToCursor(SDL_Surface *image, int hx, int hy)
 	return cursor;
 }
 
-Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, int x, int y)
+Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, int x, int y, bool colorByte)
 {
     int bpp = surface->format->BytesPerPixel;
     /* Here p is the address to the pixel we want to retrieve */
@@ -215,7 +220,12 @@ Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, int x, int y)
 
     switch(bpp) {
     case 1:
-        return *p;
+		if(colorByte)
+		{
+			return colorToUint32(surface->format->palette->colors+(*p));
+		}
+		else
+			return *p;
 
     case 2:
         return *(Uint16 *)p;
@@ -232,4 +242,70 @@ Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, int x, int y)
     default:
         return 0;       /* shouldn't happen, but avoids warnings */
     }
-}
+}
+
+SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src)
+{
+	Uint32 trans = SDL_MapRGBA(src->format, 0, 255, 255, 255);
+	//SDL_SetColorKey(src, SDL_SRCCOLORKEY, trans);
+	/*SDL_SetColorKey(src, 0, trans);
+	src = SDL_ConvertSurface(src, ekran->format, ekran->flags);
+	for(int i=0; i<src->w; ++i)
+	{
+		for(int j=0; j<src->h; ++j)
+		{
+			Uint8 cr, cg, cb, ca;
+			SDL_GetRGBA(SDL_GetPixel(src, i, j), src->format, &cr, &cg, &cb, &ca);
+			if(cr == 255 && cb == 255)
+			{
+				Uint32 aaaa=src->format->Amask;
+				Uint32 aaab=src->format->Bmask;
+				Uint32 aaag=src->format->Gmask;
+				Uint32 aaar=src->format->Rmask;
+				Uint32 put = cg << 24 | cr << 16 | ca << 8 | cb;
+				SDL_Rect rrr = genRect(1, 1, i, j);
+				SDL_FillRect(src, &rrr, put);
+			}
+		}
+	}*/
+	//SDL_UpdateRect(src, 0, 0, src->w, src->h);
+	SDL_SetColorKey(src, 0, trans);
+	src->flags|=SDL_SRCALPHA;
+	
+	if(src->format->BitsPerPixel == 8)
+	{
+		for(int yy=0; yy<src->format->palette->ncolors; ++yy)
+		{
+			SDL_Color cur = *(src->format->palette->colors+yy);
+			if(cur.r == 255 && cur.b == 255)
+			{
+				SDL_Color shadow;
+				shadow.b = shadow.g = shadow.r = 0;
+				shadow.unused = cur.g + 25; //25 is a scalable constans to make it nicer
+				SDL_SetColors(src, &shadow, yy, 1);
+			}
+			if(cur.g == 255 && cur.b == 255)
+			{
+				SDL_Color transp;
+				transp.b = transp.g = transp.r = 0;
+				transp.unused = 255;
+				SDL_SetColors(src, &transp, yy, 1);
+			}
+		}
+	}
+	SDL_UpdateRect(src, 0, 0, src->w, src->h);
+	return src;
+}
+
+Uint32 CSDL_Ext::colorToUint32(const SDL_Color * color)
+{
+	Uint32 ret = 0;
+	ret+=color->unused;
+	ret*=256;
+	ret+=color->b;
+	ret*=256;
+	ret+=color->g;
+	ret*=256;
+	ret+=color->r;
+	return ret;
+}

+ 8 - 5
SDL_Extensions.h

@@ -5,13 +5,16 @@
 class CSDL_Ext
 {
 public:
-	static void SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC=0); //myC influences the start of reading pixels
-	static SDL_Surface * rotate01(SDL_Surface * toRot);
+	static void SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC=0, Uint8 A = 255); //myC influences the start of reading pixels
+	static SDL_Surface * rotate01(SDL_Surface * toRot, int myC = 2); //vertical flip
 	static SDL_Surface * hFlip(SDL_Surface * toRot); //horizontal flip
-	static SDL_Surface * rotate02(SDL_Surface * toRot);
-	static SDL_Surface * rotate03(SDL_Surface * toRot);
+	static SDL_Surface * rotate02(SDL_Surface * toRot); //rotate 90 degrees left
+	static SDL_Surface * rotate03(SDL_Surface * toRot); //rotate 180 degrees
 	static SDL_Cursor * SurfaceToCursor(SDL_Surface *image, int hx, int hy);
-	static Uint32 SDL_GetPixel(SDL_Surface *surface, int x, int y);
+	static Uint32 SDL_GetPixel(SDL_Surface *surface, int x, int y, bool colorByte = false);
+	static SDL_Color SDL_GetPixelColor(SDL_Surface *surface, int x, int y);
+	static SDL_Surface * alphaTransform(SDL_Surface * src); //adds transparency and shadows
+	static Uint32 colorToUint32(const SDL_Color * color); //little endian only
 };
 
 #endif // SDL_EXTENSIONS_H

+ 3 - 3
map.h

@@ -1,5 +1,5 @@
-#ifndef MAPD
-#define MAPD
+#ifndef MAPD_H
+#define MAPD_H
 
 #include <string>
 #include <vector>
@@ -205,4 +205,4 @@ public:
 };
 
 
-#endif //MAPD
+#endif //MAPD_H

+ 293 - 5
mapHandler.cpp

@@ -4,10 +4,45 @@
 #include "SDL_rotozoom.h"
 #include "SDL_Extensions.h"
 #include "CGameInfo.h"
+#include "stdlib.h"
 
 extern SDL_Surface * ekran;
-void mapHandler::init()
+void CMapHandler::init()
 {
+	fullHide = CGameInfo::mainObj->sspriteh->giveDef("TSHRC.DEF", 2);
+	partialHide = CGameInfo::mainObj->sspriteh->giveDef("TSHRE.DEF", 2);
+
+	for(int i=0; i<partialHide->ourImages.size(); ++i)
+	{
+		//CSDL_Ext::alphaTransform(partialHide->ourImages[i].bitmap);
+	}
+
+	visibility.resize(reader->map.width+8);
+	for(int gg=0; gg<reader->map.width+8; ++gg)
+	{
+		visibility[gg].resize(reader->map.height+8);
+		for(int jj=0; jj<reader->map.height+8; ++jj)
+			visibility[gg][jj] = true;
+	}
+	undVisibility.resize(reader->map.width+8);
+	for(int gg=0; gg<reader->map.width+8; ++gg)
+	{
+		undVisibility[gg].resize(reader->map.height+8);
+		for(int jj=0; jj<reader->map.height+8; ++jj)
+			undVisibility[gg][jj] = true;
+	}
+
+	visibility[6][7] = false;
+	undVisibility[5][7] = false;
+	visibility[7][7] = false;
+	visibility[6][8] = false;
+	visibility[6][6] = false;
+	//visibility[5][6] = false;
+	//visibility[7][8] = false;
+	visibility[5][8] = false;
+	visibility[7][6] = false;
+	visibility[6][9] = false;
+
 	terrainBitmap = new SDL_Surface **[reader->map.width+8];
 	for (int ii=0;ii<reader->map.width+8;ii++)
 		terrainBitmap[ii] = new SDL_Surface*[reader->map.height+8]; // allocate memory 
@@ -203,11 +238,12 @@ void mapHandler::init()
 					catch (...)
 					{	continue;	}
 				}
-			}
-		}
-	}
+			} //end of internal for
+		} //end of external for
+	} //end of if
 }
-SDL_Surface * mapHandler::terrainRect(int x, int y, int dx, int dy, int level)
+
+SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level)
 {
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
     int rmask = 0xff000000;
@@ -220,6 +256,7 @@ SDL_Surface * mapHandler::terrainRect(int x, int y, int dx, int dy, int level)
     int bmask = 0x00ff0000;
     int amask = 0xff000000;
 #endif
+
 	SDL_Surface * su = SDL_CreateRGBSurface(SDL_SWSURFACE, dx*32, dy*32, 32,
                                    rmask, gmask, bmask, amask);
 	if (((dx+x)>((reader->map.width+8)) || (dy+y)>((reader->map.height+8))) || ((x<0)||(y<0) ) )
@@ -233,12 +270,263 @@ SDL_Surface * mapHandler::terrainRect(int x, int y, int dx, int dy, int level)
 			sr->x=bx*32;
 			sr->h=sr->w=32;
 			if (!level)
+			{
 				SDL_BlitSurface(terrainBitmap[bx+x][by+y],NULL,su,sr);
+				if( bx+x>3 && by+y>3 && bx+x<visibility.size()-3 && by+y<visibility[0].size()-3 && !visibility[bx+x][by+y])
+				{
+					SDL_Surface * hide = CSDL_Ext::alphaTransform(getVisBitmap(bx+x, by+y, visibility));
+					Uint32 pompom[32][32];
+					for(int i=0; i<hide->w; ++i)
+					{
+						for(int j=0; j<hide->h; ++j)
+						{
+							pompom[i][j] = 0xffffffff - (CSDL_Ext::SDL_GetPixel(hide, i, j, true) & 0xff000000);
+						}
+					}
+					hide = SDL_ConvertSurface(hide, su->format, SDL_SWSURFACE);
+					for(int i=0; i<hide->w; ++i)
+					{
+						for(int j=0; j<hide->h; ++j)
+						{
+							Uint32 * place = (Uint32*)( (Uint8*)hide->pixels + j * hide->pitch + i * hide->format->BytesPerPixel);
+							(*place)&=pompom[i][j];
+						}
+					}
+					SDL_BlitSurface(hide, NULL, su, sr);
+				}
+			}
 			else 
+			{
 				SDL_BlitSurface(undTerrainBitmap[bx+x][by+y],NULL,su,sr);
+				if( bx+x>3 && by+y>3 && bx+x<undVisibility.size()-3 && by+y<undVisibility[0].size()-3 && !undVisibility[bx+x][by+y])
+				{
+					SDL_Surface * hide = CSDL_Ext::alphaTransform(getVisBitmap(bx+x, by+y, undVisibility));
+					Uint32 pompom[32][32];
+					for(int i=0; i<hide->w; ++i)
+					{
+						for(int j=0; j<hide->h; ++j)
+						{
+							pompom[i][j] = 0xffffffff - (CSDL_Ext::SDL_GetPixel(hide, i, j, true) & 0xff000000);
+						}
+					}
+					hide = SDL_ConvertSurface(hide, su->format, SDL_SWSURFACE);
+					for(int i=0; i<hide->w; ++i)
+					{
+						for(int j=0; j<hide->h; ++j)
+						{
+							Uint32 * place = (Uint32*)( (Uint8*)hide->pixels + j * hide->pitch + i * hide->format->BytesPerPixel);
+							(*place)&=pompom[i][j];
+						}
+					}
+					SDL_BlitSurface(hide, NULL, su, sr);
+				}
+			}
 			delete sr;
 			//SDL_BlitSurface(su,NULL,ekran,NULL);SDL_Flip(ekran);
 		}
 	}
 	return su;
 }
+
+SDL_Surface * CMapHandler::terrBitmap(int x, int y)
+{
+	return terrainBitmap[x+4][y+4];
+}
+
+SDL_Surface * CMapHandler::undTerrBitmap(int x, int y)
+{
+	return undTerrainBitmap[x+4][y+4];
+}
+
+SDL_Surface * CMapHandler::getVisBitmap(int x, int y, std::vector< std::vector<bool> > & visibility)
+{
+	if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && !visibility[x+1][y+1] && !visibility[x+1][y-1] && !visibility[x-1][y+1])
+	{
+		return fullHide->ourImages[rand()%fullHide->ourImages.size()].bitmap; //fully hidden
+	}
+	else if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && visibility[x+1][y+1] && !visibility[x+1][y-1] && !visibility[x-1][y+1])
+	{
+		return partialHide->ourImages[22].bitmap; //visible right bottom corner
+	}
+	else if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && !visibility[x+1][y+1] && visibility[x+1][y-1] && !visibility[x-1][y+1])
+	{
+		return partialHide->ourImages[15].bitmap; //visible right top corner
+	}
+	else if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && !visibility[x+1][y+1] && !visibility[x+1][y-1] && visibility[x-1][y+1])
+	{
+		return CSDL_Ext::rotate01(partialHide->ourImages[22].bitmap); //visible left bottom corner
+	}
+	else if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && !visibility[x+1][y+1] && !visibility[x+1][y-1] && !visibility[x-1][y+1])
+	{
+		return CSDL_Ext::rotate01(partialHide->ourImages[15].bitmap); //visible left top corner
+	}
+	else if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1] && visibility[x-1][y-1] && !visibility[x+1][y+1] && visibility[x+1][y-1] && !visibility[x-1][y+1])
+	{
+		return partialHide->ourImages[rand()%2].bitmap; //visible top
+	}
+	else if(visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && visibility[x+1][y+1] && !visibility[x+1][y-1] && visibility[x-1][y+1])
+	{
+		return partialHide->ourImages[4+rand()%2].bitmap; //visble bottom
+	}
+	else if(!visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && !visibility[x+1][y+1] && !visibility[x+1][y-1] && visibility[x-1][y+1])
+	{
+		return CSDL_Ext::rotate01(partialHide->ourImages[2+rand()%2].bitmap); //visible left
+	}
+	else if(!visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && visibility[x+1][y+1] && visibility[x+1][y-1] && !visibility[x-1][y+1])
+	{
+		return partialHide->ourImages[2+rand()%2].bitmap; //visible right
+	}
+	else if(visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1])
+	{
+		return partialHide->ourImages[12+2*(rand()%2)].bitmap; //visible bottom, right - bottom, right; left top corner hidden
+	}
+	else if(!visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1] && !visibility[x-1][y+1])
+	{
+		return partialHide->ourImages[13].bitmap; //visible right, right - top; left bottom corner hidden
+	}
+	else if(!visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && visibility[x][y-1] && !visibility[x+1][y+1])
+	{
+		return CSDL_Ext::rotate01(partialHide->ourImages[13].bitmap); //visible top, top - left, left; right bottom corner hidden
+	}
+	else if(visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && !visibility[x][y-1]  && !visibility[x+1][y-1])
+	{
+		return CSDL_Ext::rotate01(partialHide->ourImages[12+2*(rand()%2)].bitmap); //visible left, left - bottom, bottom; right top corner hidden
+	}
+	else if(visibility[x][y+1] && visibility[x+1][y] && visibility[x-1][y] && visibility[x][y-1] && visibility[x-1][y-1] && visibility[x+1][y+1] && visibility[x+1][y-1] && visibility[x-1][y+1])
+	{
+		return partialHide->ourImages[10].bitmap; //visible left, right, bottom and top
+	}
+	if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && visibility[x+1][y+1] && visibility[x+1][y-1] && !visibility[x-1][y+1])
+	{
+		return partialHide->ourImages[16].bitmap; //visible right corners
+	}
+	if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && !visibility[x+1][y+1] && visibility[x+1][y-1] && !visibility[x-1][y+1])
+	{
+		return partialHide->ourImages[18].bitmap; //visible top corners
+	}
+	if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && !visibility[x+1][y+1] && !visibility[x+1][y-1] && visibility[x-1][y+1])
+	{
+		return CSDL_Ext::rotate01(partialHide->ourImages[16].bitmap); //visible left corners
+	}
+	if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && visibility[x+1][y+1] && !visibility[x+1][y-1] && visibility[x-1][y+1])
+	{
+		return CSDL_Ext::hFlip(partialHide->ourImages[18].bitmap); //visible bottom corners
+	}
+	if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && !visibility[x+1][y+1] && visibility[x+1][y-1] && visibility[x-1][y+1])
+	{
+		return partialHide->ourImages[17].bitmap; //visible right - top and bottom - left corners
+	}
+	if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && visibility[x+1][y+1] && !visibility[x+1][y-1] && !visibility[x-1][y+1])
+	{
+		return CSDL_Ext::hFlip(partialHide->ourImages[17].bitmap); //visible top - left and bottom - right corners
+	}
+	if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && visibility[x+1][y+1] && visibility[x+1][y-1] && visibility[x-1][y+1])
+	{
+		return partialHide->ourImages[19].bitmap; //visible corners without left top
+	}
+	if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && visibility[x+1][y+1] && visibility[x+1][y-1] && !visibility[x-1][y+1])
+	{
+		return partialHide->ourImages[20].bitmap; //visible corners without left bottom
+	}
+	if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && !visibility[x+1][y+1] && visibility[x+1][y-1] && visibility[x-1][y+1])
+	{
+		return CSDL_Ext::rotate01(partialHide->ourImages[20].bitmap); //visible corners without right bottom
+	}
+	if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && visibility[x+1][y+1] && !visibility[x+1][y-1] && visibility[x-1][y+1])
+	{
+		return CSDL_Ext::rotate01(partialHide->ourImages[19].bitmap); //visible corners without right top
+	}
+	if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && visibility[x+1][y+1] && visibility[x+1][y-1] && visibility[x-1][y+1])
+	{
+		return partialHide->ourImages[21].bitmap; //visible all corners only
+	}
+	if(visibility[x][y+1] && visibility[x+1][y] && visibility[x-1][y] && !visibility[x][y-1])
+	{
+		return partialHide->ourImages[6].bitmap; //hidden top
+	}
+	if(visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && visibility[x][y-1])
+	{
+		return partialHide->ourImages[7].bitmap; //hidden right
+	}
+	if(!visibility[x][y+1] && visibility[x+1][y] && visibility[x-1][y] && visibility[x][y-1])
+	{
+		return partialHide->ourImages[8].bitmap; //hidden bottom
+	}
+	if(visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1])
+	{
+		return CSDL_Ext::rotate01(partialHide->ourImages[6].bitmap); //hidden left
+	}
+	if(!visibility[x][y+1] && visibility[x+1][y] && visibility[x-1][y] && visibility[x][y-1])
+	{
+		return partialHide->ourImages[9].bitmap; //hidden top and bottom
+	}
+	if(visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1])
+	{
+		return partialHide->ourImages[29].bitmap;  //hidden left and right
+	}
+	if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1] && visibility[x+1][y+1] && !visibility[x-1][y+1])
+	{
+		return partialHide->ourImages[24].bitmap; //visible top and right bottom corner
+	}
+	if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1] && !visibility[x+1][y+1] && visibility[x-1][y+1])
+	{
+		return CSDL_Ext::rotate01(partialHide->ourImages[24].bitmap); //visible top and left bottom corner
+	}
+	if(!visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1] && visibility[x+1][y+1] && visibility[x-1][y+1])
+	{
+		return partialHide->ourImages[33].bitmap; //visible top and bottom corners
+	}
+	if(!visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && !visibility[x][y-1] && !visibility[x+1][y+1] && visibility[x+1][y-1])
+	{
+		return CSDL_Ext::rotate01(partialHide->ourImages[26].bitmap); //visible left and right top corner
+	}
+	if(!visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && !visibility[x][y-1] && visibility[x+1][y+1] && !visibility[x+1][y-1])
+	{
+		return CSDL_Ext::rotate01(partialHide->ourImages[25].bitmap); //visible left and right bottom corner
+	}
+	if(!visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && !visibility[x][y-1] && visibility[x+1][y+1] && visibility[x+1][y-1])
+	{
+		return partialHide->ourImages[32].bitmap; //visible left and right corners
+	}
+	if(visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && !visibility[x+1][y-1])
+	{
+		return CSDL_Ext::rotate01(partialHide->ourImages[30].bitmap); //visible bottom and left top corner
+	}
+	if(visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && visibility[x+1][y-1])
+	{
+		return partialHide->ourImages[30].bitmap; //visible bottom and right top corner
+	}
+	if(visibility[x][y+1] && !visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && visibility[x+1][y-1])
+	{
+		return partialHide->ourImages[31].bitmap; //visible bottom and top corners
+	}
+	if(!visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && !visibility[x-1][y-1] && visibility[x-1][y+1])
+	{
+		return partialHide->ourImages[25].bitmap; //visible right and left bottom corner
+	}
+	if(!visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && !visibility[x-1][y+1])
+	{
+		return partialHide->ourImages[26].bitmap; //visible right and left top corner
+	}
+	if(!visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1] && visibility[x-1][y+1])
+	{
+		return CSDL_Ext::rotate01(partialHide->ourImages[32].bitmap); //visible right and left cornres
+	}
+	if(visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && !visibility[x][y-1] && visibility[x-1][y-1])
+	{
+		return partialHide->ourImages[28].bitmap; //visible bottom, right - bottom, right; left top corner visible
+	}
+	else if(!visibility[x][y+1] && visibility[x+1][y] && !visibility[x-1][y] && visibility[x][y-1] && visibility[x-1][y+1])
+	{
+		return partialHide->ourImages[27].bitmap; //visible right, right - top; left bottom corner visible
+	}
+	else if(!visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && visibility[x][y-1] && visibility[x+1][y+1])
+	{
+		return CSDL_Ext::rotate01(partialHide->ourImages[27].bitmap); //visible top, top - left, left; right bottom corner visible
+	}
+	else if(visibility[x][y+1] && !visibility[x+1][y] && visibility[x-1][y] && !visibility[x][y-1]  && visibility[x+1][y-1])
+	{
+		return CSDL_Ext::rotate01(partialHide->ourImages[28].bitmap); //visible left, left - bottom, bottom; right top corner visible
+	}
+	return fullHide->ourImages[0].bitmap; //this case should never happen, but it is better to hide too much than reveal it....
+}

+ 19 - 3
mapHandler.h

@@ -1,11 +1,27 @@
+#ifndef MAPHANDLER_H
+#define MAPHANDLER_H
+
 #include "CAmbarCendamo.h"
-class mapHandler
+#include "CSemiDefHandler.h"
+#include "CGameInfo.h"
+
+class CMapHandler
 {
 public:
 	CAmbarCendamo * reader;
 	SDL_Surface *** terrainBitmap;
 	SDL_Surface *** undTerrainBitmap; // used only if there is underground level
 	SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0);
-	SDL_Surface mirrorImage(SDL_Surface *src);
+	SDL_Surface * terrBitmap(int x, int y);
+	SDL_Surface * undTerrBitmap(int x, int y);
+	CSemiDefHandler * fullHide;
+	CSemiDefHandler * partialHide;
+
+	std::vector< std::vector<bool> > visibility; //true means that pointed place is visible
+	std::vector< std::vector<bool> > undVisibility; //true means that pointed place is visible
+	SDL_Surface mirrorImage(SDL_Surface *src); //what is this??
+	SDL_Surface * getVisBitmap(int x, int y, std::vector< std::vector<bool> > & visibility);
 	void init();
-};
+};
+
+#endif //MAPHANDLER_H