Browse Source

zaczytywanie kolejnych tekstów, drobne eksperymenty z odcieniami cieni i obiektami na mapie (defy! królestwo za defy! ;])

mateuszb 18 years ago
parent
commit
0428ea1f86
7 changed files with 172 additions and 44 deletions
  1. 7 2
      CAmbarCendamo.cpp
  2. 1 1
      CMT.cpp
  3. 55 1
      CPreGameTextHandler.cpp
  4. 7 0
      CPreGameTextHandler.h
  5. 54 1
      SDL_Extensions.cpp
  6. 1 0
      SDL_Extensions.h
  7. 47 39
      mapHandler.cpp

+ 7 - 2
CAmbarCendamo.cpp

@@ -4,6 +4,7 @@
 #include "CGameInfo.h"
 #include "CObjectHandler.h"
 #include "CCastleHandler.h"
+#include "SDL_Extensions.h"
 #include <set>
 
 unsigned int intPow(unsigned int a, unsigned int b)
@@ -405,8 +406,12 @@ void CAmbarCendamo::deh3m()
 		map.defy.push_back(vinya); // add this def to the vector
 
 		//testing - only fragment//////////////////////////////////////////////////////////////
-		//map.defy[idd].handler = new CSemiDefHandler();
-		//map.defy[idd].handler->openDef(map.defy[idd].name.c_str(), "H3sprite.lod");
+		/*map.defy[idd].handler = new CSemiDefHandler();
+		map.defy[idd].handler->openDef(map.defy[idd].name.c_str(), "H3sprite.lod");
+		for(int ff=0; ff<map.defy[idd].handler->ourImages.size(); ++ff) //adding shadows and transparency
+		{
+			map.defy[idd].handler->ourImages[ff].bitmap = CSDL_Ext::alphaTransform(map.defy[idd].handler->ourImages[ff].bitmap);
+		}//*/
 		//end fo testing - only fragment///////////////////////////////////////////////////////
 
 		//teceDef();

+ 1 - 1
CMT.cpp

@@ -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;

+ 55 - 1
CPreGameTextHandler.cpp

@@ -484,4 +484,58 @@ void CPreGameTextHandler::loadToIt(std::string &dest, std::string &src, int &ite
 			iter+=2;
 		}
 	}
-}
+	loadLossConditions();
+	loadVictoryConditions();
+}
+
+void CPreGameTextHandler::loadVictoryConditions()
+{
+	std::ifstream inp("H3bitmap.lod\\VCDESC.TXT", std::ios::in|std::ios::binary);
+	inp.seekg(0,std::ios::end); // na koniec
+	int andame = inp.tellg();  // read length
+	inp.seekg(0,std::ios::beg); // wracamy na poczatek
+	char * bufor = new char[andame]; // allocate memory 
+	inp.read((char*)bufor, andame); // read map file to buffer
+	inp.close();
+	std::string buf = std::string(bufor);
+	delete [andame] bufor;
+	int i=0; //buf iterator
+
+	for(int gg=0; gg<14; ++gg)
+	{
+		int befi=i;
+		for(i; i<andame; ++i)
+		{
+			if(buf[i]=='\r')
+				break;
+		}
+		victoryConditions[gg] = buf.substr(befi, i-befi);
+		i+=2;
+	}
+}
+
+void CPreGameTextHandler::loadLossConditions()
+{
+	std::ifstream inp("H3bitmap.lod\\LCDESC.TXT", std::ios::in|std::ios::binary);
+	inp.seekg(0,std::ios::end); // na koniec
+	int andame = inp.tellg();  // read length
+	inp.seekg(0,std::ios::beg); // wracamy na poczatek
+	char * bufor = new char[andame]; // allocate memory 
+	inp.read((char*)bufor, andame); // read map file to buffer
+	inp.close();
+	std::string buf = std::string(bufor);
+	delete [andame] bufor;
+	int i=0; //buf iterator
+
+	for(int gg=0; gg<4; ++gg)
+	{
+		int befi=i;
+		for(i; i<andame; ++i)
+		{
+			if(buf[i]=='\r')
+				break;
+		}
+		lossCondtions[gg] = buf.substr(befi, i-befi);
+		i+=2;
+	}
+}

+ 7 - 0
CPreGameTextHandler.h

@@ -7,7 +7,9 @@ class CPreGameTextHandler //handles pre - game texts
 {
 public:
 	std::string mainNewGame, mainLoadGame, mainHighScores, mainCredits, mainQuit; //right - click texts in main menu
+
 	std::string ngSingleScenario, ngCampain, ngMultiplayer, ngTutorial, ngBack; //right - click texts in new game menu
+
 	std::string singleChooseScenario, singleSetAdvOptions, singleRandomMap, singleScenarioName, singleDescriptionTitle, singleDescriptionText, singleEasy, singleNormal, singleHard, singleExpert, singleImpossible; //main single scenario texts
 	std::string singleAllyFlag[8], singleEnemyFlag[8];
 	std::string singleViewHideScenarioList, singleViewHideAdvOptions, singlePlayRandom, singleChatDesc, singleMapDifficulty, singleRating, singleMapPossibleDifficulties, singleVicCon, singleLossCon;
@@ -30,10 +32,15 @@ public:
 	std::string multiGameNo [12];
 	std::string multiScrollGames, multiCancel;
 
+	std::string lossCondtions[4];
+	std::string victoryConditions[14];
+
 	std::string getTitle(std::string text);
 	std::string getDescr(std::string text);
 	void loadTexts();
 	void loadToIt(std::string & dest, std::string & src, int & iter, int mode = 0); //mode 0 - dump to tab, dest to tab, dump to eol //mode 1 - dump to tab, src to eol
+	void loadVictoryConditions();
+	void loadLossConditions();
 };
 
 

+ 54 - 1
SDL_Extensions.cpp

@@ -2,6 +2,7 @@
 #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)
@@ -305,7 +306,27 @@ SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src)
 			{
 				SDL_Color shadow;
 				shadow.b = shadow.g = shadow.r = 0;
-				shadow.unused = cur.g + 25; //25 is a scalable constans to make it nicer
+				switch(cur.g) //change this values; make diffrerent for objects and shadows (?)
+				{
+				case 0:
+					shadow.unused = 0+32;
+					break;
+				case 50:
+					shadow.unused = 50+32;
+					break;
+				case 100:
+					shadow.unused = 100+64;
+					break;
+				case 128:
+					shadow.unused = 128+64;
+					break;
+				case 150:
+					shadow.unused = 150+64;
+					break;
+				default:
+					shadow.unused = 255;
+					break;
+				}
 				SDL_SetColors(src, &shadow, yy, 1);
 			}
 			if(cur.g == 255 && cur.b == 255)
@@ -321,6 +342,38 @@ SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src)
 	return src;
 }
 
+SDL_Surface * CSDL_Ext::secondAlphaTransform(SDL_Surface * src, SDL_Surface * alpha)
+{
+	
+	Uint32 pompom[192][192];
+	for(int i=0; i<src->w; ++i)
+	{
+		for(int j=0; j<src->h; ++j)
+		{
+			pompom[i][j] = 0xffffffff - (SDL_GetPixel(src, i, j, true) & 0xff000000);
+		}
+	}
+	Uint32 pompom2[192][192];
+	for(int i=0; i<src->w; ++i)
+	{
+		for(int j=0; j<src->h; ++j)
+		{
+			pompom2[i][j] = pompom[i][j]>>24;
+		}
+	}
+	SDL_Surface * hide2 = SDL_ConvertSurface(src, alpha->format, SDL_SWSURFACE);
+	for(int i=0; i<hide2->w; ++i)
+	{
+		for(int j=0; j<hide2->h; ++j)
+		{
+			Uint32 * place = (Uint32*)( (Uint8*)hide2->pixels + j * hide2->pitch + i * hide2->format->BytesPerPixel);
+			(*place)&=pompom[i][j];
+			int ffgg=0;
+		}
+	}
+	return hide2;
+}
+
 Uint32 CSDL_Ext::colorToUint32(const SDL_Color * color)
 {
 	Uint32 ret = 0;

+ 1 - 0
SDL_Extensions.h

@@ -14,6 +14,7 @@ public:
 	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 (partial handling only; see examples of using for details)
+	static SDL_Surface * secondAlphaTransform(SDL_Surface * src, SDL_Surface * alpha); //alpha is a surface we want to blit src to
 	static Uint32 colorToUint32(const SDL_Color * color); //little endian only
 };
 

+ 47 - 39
mapHandler.cpp

@@ -109,7 +109,6 @@ void CMapHandler::init()
 						continue;
 					else
 					{
-						SDL_Surface * n;
 						int ktora = reader->map.terrain[i-4][j-4].terview;
 						terrainBitmap[i][j] = reader->defs[k]->ourImages[ktora].bitmap;
 						//TODO: odwracanie	
@@ -208,7 +207,6 @@ void CMapHandler::init()
 							continue;
 						else
 						{
-							SDL_Surface * n;
 							int ktora = reader->map.undergroungTerrain[i-4][j-4].terview;
 							undTerrainBitmap[i][j] = reader->defs[k]->ourImages[ktora].bitmap;
 							//TODO: odwracanie	
@@ -261,6 +259,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level)
                                    rmask, gmask, bmask, amask);
 	if (((dx+x)>((reader->map.width+8)) || (dy+y)>((reader->map.height+8))) || ((x<0)||(y<0) ) )
 		throw new std::string("Poza zakresem");
+	////printing terrain
 	for (int bx=0; bx<dx; bx++)
 	{
 		for (int by=0; by<dy; by++)
@@ -272,61 +271,70 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level)
 			if (!level)
 			{
 				SDL_BlitSurface(terrainBitmap[bx+x][by+y],NULL,su,sr);
+			}
+			else 
+			{
+				SDL_BlitSurface(undTerrainBitmap[bx+x][by+y],NULL,su,sr);
+			}
+			delete sr;
+		}
+	}
+	////terrain printed; printing objects
+	/*
+	for (int bx=0; bx<dx; bx++)
+	{
+		for (int by=0; by<dy; by++)
+		{
+			for(int gg=0; gg<CGameInfo::mainObj->objh->objInstances.size(); ++gg)
+			{
+				if(CGameInfo::mainObj->objh->objInstances[gg].x == bx+x-4 && CGameInfo::mainObj->objh->objInstances[gg].y == by+y-4 && CGameInfo::mainObj->objh->objInstances[gg].z == level)
+				{
+					SDL_Rect * sr = new SDL_Rect;
+					sr->h=sr->w=192;
+					sr->x = (bx)*32 - CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[0].bitmap->w + 32;
+					sr->y = (by)*32 - CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[0].bitmap->h + 32;
+					SDL_Surface * s2 = CSDL_Ext::secondAlphaTransform(CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[0].bitmap, su);
+					SDL_BlitSurface(s2, NULL, su, sr);
+					SDL_FreeSurface(s2);
+					delete sr;
+				}
+			}
+		}
+	}//*/
+	////objects printed, printing shadow
+	for (int bx=0; bx<dx; bx++)
+	{
+		for (int by=0; by<dy; by++)
+		{
+			SDL_Rect * sr = new SDL_Rect;
+			sr->y=by*32;
+			sr->x=bx*32;
+			sr->h=sr->w=32;
+			if (!level)
+			{
+				
 				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 = 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);
-						}
-					}
-					SDL_Surface * hide2 = SDL_ConvertSurface(hide, su->format, SDL_SWSURFACE);
-					for(int i=0; i<hide2->w; ++i)
-					{
-						for(int j=0; j<hide2->h; ++j)
-						{
-							Uint32 * place = (Uint32*)( (Uint8*)hide2->pixels + j * hide2->pitch + i * hide2->format->BytesPerPixel);
-							(*place)&=pompom[i][j];
-						}
-					}
+					SDL_Surface * hide2 = CSDL_Ext::secondAlphaTransform(hide, su);
 					SDL_BlitSurface(hide2, NULL, su, sr);
 					SDL_FreeSurface(hide2);
 				}
 			}
-			else 
+			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 = 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);
-						}
-					}
-					SDL_Surface * hide2 = SDL_ConvertSurface(hide, su->format, SDL_SWSURFACE);
-					for(int i=0; i<hide2->w; ++i)
-					{
-						for(int j=0; j<hide2->h; ++j)
-						{
-							Uint32 * place = (Uint32*)( (Uint8*)hide2->pixels + j * hide2->pitch + i * hide2->format->BytesPerPixel);
-							(*place)&=pompom[i][j];
-						}
-					}
+					SDL_Surface * hide2 = CSDL_Ext::secondAlphaTransform(hide, su);
 					SDL_BlitSurface(hide2, NULL, su, sr);
 					SDL_FreeSurface(hide2);
 				}
 			}
 			delete sr;
-			//SDL_BlitSurface(su,NULL,ekran,NULL);SDL_Flip(ekran);
 		}
 	}
+	////shadow printed
 	return su;
 }