Browse Source

* hero is displayed in battle window
* battle console buttons added
* blit8bppAlphaTo24bpp bad working fixed (to be optimized)
* maybe something else

mateuszb 17 years ago
parent
commit
9b9a9b455f
8 changed files with 160 additions and 30 deletions
  1. 104 2
      CBattleInterface.cpp
  2. 15 0
      CBattleInterface.h
  3. 0 15
      CGameState.cpp
  4. 13 1
      CPlayerInterface.cpp
  5. 12 12
      SDL_Extensions.cpp
  6. 5 0
      hch/CLodHandler.cpp
  7. 10 0
      mapHandler.cpp
  8. 1 0
      mapHandler.h

+ 104 - 2
CBattleInterface.cpp

@@ -4,18 +4,25 @@
 #include "SDL_Extensions.h"
 #include "SDL_Extensions.h"
 #include "CAdvmapInterface.h"
 #include "CAdvmapInterface.h"
 #include "AdventureMapButton.h"
 #include "AdventureMapButton.h"
+#include "hch\CHeroHandler.h"
+#include "hch\CDefHandler.h"
+
+extern SDL_Surface * screen;
 
 
 CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2)
 CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2)
 {
 {
+	//preparing menu background and terrain
 	std::vector< std::string > & backref = CGI->mh->battleBacks[ CGI->mh->ttiles[tile.x][tile.y][tile.z].terType ];
 	std::vector< std::string > & backref = CGI->mh->battleBacks[ CGI->mh->ttiles[tile.x][tile.y][tile.z].terType ];
 	background = CGI->bitmaph->loadBitmap(backref[ rand() % backref.size()] );
 	background = CGI->bitmaph->loadBitmap(backref[ rand() % backref.size()] );
 	menu = CGI->bitmaph->loadBitmap("CBAR.BMP");
 	menu = CGI->bitmaph->loadBitmap("CBAR.BMP");
 	CSDL_Ext::blueToPlayersAdv(menu, hero1->tempOwner);
 	CSDL_Ext::blueToPlayersAdv(menu, hero1->tempOwner);
 
 
+	//blitting menu background and terrain
 	blitAt(background, 0, 0);
 	blitAt(background, 0, 0);
 	blitAt(menu, 0, 556);
 	blitAt(menu, 0, 556);
 	CSDL_Ext::update();
 	CSDL_Ext::update();
 	
 	
+	//preparing buttons
 	bOptions = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bOptionsf, 3, 561, "icm003.def", this, false, NULL, false);
 	bOptions = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bOptionsf, 3, 561, "icm003.def", this, false, NULL, false);
 	bSurrender = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bSurrenderf, 54, 561, "icm001.def", this, false, NULL, false);
 	bSurrender = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bSurrenderf, 54, 561, "icm001.def", this, false, NULL, false);
 	bFlee = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bFleef, 105, 561, "icm002.def", this, false, NULL, false);
 	bFlee = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bFleef, 105, 561, "icm002.def", this, false, NULL, false);
@@ -23,7 +30,48 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, i
 	bSpell = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bSpellf, 645, 561, "icm005.def", this, false, NULL, false);
 	bSpell = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bSpellf, 645, 561, "icm005.def", this, false, NULL, false);
 	bWait = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bWaitf, 696, 561, "icm006.def", this, false, NULL, false);
 	bWait = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bWaitf, 696, 561, "icm006.def", this, false, NULL, false);
 	bDefence = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bDefencef, 747, 561, "icm007.def", this, false, NULL, false);
 	bDefence = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bDefencef, 747, 561, "icm007.def", this, false, NULL, false);
-	//bOptions->activate();
+	bConsoleUp = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bConsoleUpf, 624, 561, "ComSlide.def", this, false, NULL, false);
+	bConsoleDown = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bConsoleDownf, 624, 580, "ComSlide.def", this, false, NULL, false);
+	bConsoleDown->bitmapOffset = 2;
+	
+	//loading hero animations
+	if(hero1) // attacking hero
+	{
+		attackingHero = new CBattleHero;
+		attackingHero->dh = CGI->spriteh->giveDef( CGI->mh->battleHeroes[hero1->type->heroType] );
+		for(int i=0; i<attackingHero->dh->ourImages.size(); ++i) //transforming images
+		{
+			attackingHero->dh->ourImages[i].bitmap = CSDL_Ext::alphaTransform(attackingHero->dh->ourImages[i].bitmap);
+		}
+		attackingHero->dh->alphaTransformed = true;
+		attackingHero->phase = 0;
+		attackingHero->image = 0;
+		attackingHero->pos = genRect(attackingHero->dh->ourImages[0].bitmap->h, attackingHero->dh->ourImages[0].bitmap->w, 0, 0);
+		//CSDL_Ext::blit8bppAlphaTo24bpp(attackingHero->ourImages[0].bitmap, &attackingHero->ourImages[0].bitmap->clip_rect, screen, &genRect(attackingHero->ourImages[0].bitmap->h, attackingHero->ourImages[0].bitmap->w, 0, 0));
+	}
+	else
+	{
+		attackingHero = NULL;
+	}
+	if(hero2) // defending hero
+	{
+		defendingHero = new CBattleHero;
+		defendingHero->dh = CGI->spriteh->giveDef( CGI->mh->battleHeroes[hero2->type->heroType] );
+		for(int i=0; i<defendingHero->dh->ourImages.size(); ++i) //transforming and flipping images
+		{
+			defendingHero->dh->ourImages[i].bitmap = CSDL_Ext::rotate01(defendingHero->dh->ourImages[i].bitmap);
+			defendingHero->dh->ourImages[i].bitmap = CSDL_Ext::alphaTransform(defendingHero->dh->ourImages[i].bitmap);
+		}
+		defendingHero->dh->alphaTransformed = true;
+		defendingHero->phase = 0;
+		defendingHero->image = 0;
+		defendingHero->pos = genRect(defendingHero->dh->ourImages[0].bitmap->h, defendingHero->dh->ourImages[0].bitmap->w, 650, 0);
+		//CSDL_Ext::blit8bppAlphaTo24bpp(defendingHero->ourImages[0].bitmap, &defendingHero->ourImages[0].bitmap->clip_rect, screen, &genRect(defendingHero->ourImages[0].bitmap->h, defendingHero->ourImages[0].bitmap->w, 650, 0));
+	}
+	else
+	{
+		defendingHero = NULL;
+	}
 }
 }
 
 
 CBattleInterface::~CBattleInterface()
 CBattleInterface::~CBattleInterface()
@@ -37,6 +85,11 @@ CBattleInterface::~CBattleInterface()
 	delete bSpell;
 	delete bSpell;
 	delete bWait;
 	delete bWait;
 	delete bDefence;
 	delete bDefence;
+	delete bConsoleUp;
+	delete bConsoleDown;
+
+	delete attackingHero;
+	delete defendingHero;
 }
 }
 
 
 void CBattleInterface::activate()
 void CBattleInterface::activate()
@@ -48,6 +101,8 @@ void CBattleInterface::activate()
 	bSpell->activate();
 	bSpell->activate();
 	bWait->activate();
 	bWait->activate();
 	bDefence->activate();
 	bDefence->activate();
+	bConsoleUp->activate();
+	bConsoleDown->activate();
 }
 }
 
 
 void CBattleInterface::deactivate()
 void CBattleInterface::deactivate()
@@ -59,13 +114,35 @@ void CBattleInterface::deactivate()
 	bSpell->deactivate();
 	bSpell->deactivate();
 	bWait->deactivate();
 	bWait->deactivate();
 	bDefence->deactivate();
 	bDefence->deactivate();
+	bConsoleUp->deactivate();
+	bConsoleDown->deactivate();
 }
 }
 
 
 void CBattleInterface::show(SDL_Surface * to)
 void CBattleInterface::show(SDL_Surface * to)
 {
 {
+	if(!to) //"evaluating" to
+		to = screen;
+
+	//showing background
 	blitAt(background, 0, 0, to);
 	blitAt(background, 0, 0, to);
-	blitAt(menu, 0, 556, to);
+	//blitAt(menu, 0, 556, to);
+
+	//showing buttons
 	bOptions->show(to);
 	bOptions->show(to);
+	bSurrender->show(to);
+	bFlee->show(to);
+	bAutofight->show(to);
+	bSpell->show(to);
+	bWait->show(to);
+	bDefence->show(to);
+	bConsoleUp->show(to);
+	bConsoleDown->show(to);
+
+	//showing hero animations
+	attackingHero->show(to);
+	defendingHero->show(to);
+
+	CSDL_Ext::update();
 }
 }
 
 
 void CBattleInterface::bOptionsf()
 void CBattleInterface::bOptionsf()
@@ -103,3 +180,28 @@ void CBattleInterface::bConsoleUpf()
 void CBattleInterface::bConsoleDownf()
 void CBattleInterface::bConsoleDownf()
 {
 {
 }
 }
+
+void CBattleHero::show(SDL_Surface *to)
+{
+	int tick=-1;
+	for(int i=0; i<dh->ourImages.size(); ++i)
+	{
+		if(dh->ourImages[i].groupNumber==phase)
+			++tick;
+		if(tick==image)
+		{
+			CSDL_Ext::blit8bppAlphaTo24bpp(dh->ourImages[i].bitmap, NULL, to, &pos);
+			++image;
+			if(dh->ourImages[i+1].groupNumber!=phase) //back to appropriate frame
+			{
+				image = 0;
+			}
+			break;
+		}
+	}
+}
+
+CBattleHero::~CBattleHero()
+{
+	delete dh;
+}

+ 15 - 0
CBattleInterface.h

@@ -4,18 +4,33 @@
 
 
 class CCreatureSet;
 class CCreatureSet;
 class CGHeroInstance;
 class CGHeroInstance;
+class CDefHandler;
 template <typename T> class AdventureMapButton;
 template <typename T> class AdventureMapButton;
 
 
+class CBattleHero : public IShowable, public CIntObject
+{
+public:
+	CDefHandler * dh;
+	int phase;
+	int image;
+	void show(SDL_Surface * to);
+	~CBattleHero(); //d-tor
+};
+
 class CBattleInterface : public IActivable, public IShowable
 class CBattleInterface : public IActivable, public IShowable
 {
 {
 private:
 private:
 	SDL_Surface * background, * menu;
 	SDL_Surface * background, * menu;
 	AdventureMapButton<CBattleInterface> * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell,
 	AdventureMapButton<CBattleInterface> * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell,
 		* bWait, * bDefence, * bConsoleUp, * bConsoleDown;
 		* bWait, * bDefence, * bConsoleUp, * bConsoleDown;
+	CBattleHero * attackingHero, * defendingHero;
+
 public:
 public:
 	CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2);
 	CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2);
 	~CBattleInterface();
 	~CBattleInterface();
 
 
+	//std::vector<TimeInterested*> timeinterested; //animation handling
+
 	//button handle funcs:
 	//button handle funcs:
 	void bOptionsf();
 	void bOptionsf();
 	void bSurrenderf();
 	void bSurrenderf();

+ 0 - 15
CGameState.cpp

@@ -26,21 +26,6 @@ public:
 	}
 	}
 } cmpst ;
 } cmpst ;
 
 
-int battleEventThread(void * pointer)
-{
-	while(true)
-	{
-		SDL_Event sEvent;
-		while (SDL_PollEvent(&sEvent))  //wait for event...
-		{
-			LOCPLINT->handleEvent(&sEvent);
-		}
-		CSDL_Ext::update();
-		SDL_Delay(100);
-	}
-	return 0;
-}
-
 void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2)
 void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2)
 {
 {
 	curB = new BattleInfo();
 	curB = new BattleInfo();

+ 13 - 1
CPlayerInterface.cpp

@@ -1884,7 +1884,19 @@ void CPlayerInterface::activeStack(int stackID) //called when it's turn of that
 			objsToBlit[i]->show();
 			objsToBlit[i]->show();
 		//SDL_Flip(ekran);
 		//SDL_Flip(ekran);
 		CSDL_Ext::update(ekran);
 		CSDL_Ext::update(ekran);
-		SDL_Delay(5); //give time for other apps
+		
+		/*timeHandler th;
+		th.getDif();
+		int tv = th.getDif();
+		for (int i=0;i<((CBattleInterface*)this->curint)->timeinterested.size();i++)
+		{
+			if (timeinterested[i]->toNextTick>=0)
+				timeinterested[i]->toNextTick-=tv;
+			if (timeinterested[i]->toNextTick<0)
+				timeinterested[i]->tick();
+		}*/
+
+		SDL_Delay(1); //give time for other apps
 		SDL_framerateDelay(mainFPSmng);
 		SDL_framerateDelay(mainFPSmng);
 	}
 	}
 }
 }

+ 12 - 12
SDL_Extensions.cpp

@@ -597,12 +597,12 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Su
 							case 255:
 							case 255:
 								break;
 								break;
 							default:
 							default:
-								p[0] = ((((Uint32)tbc.r-(Uint32)p[0])*(Uint32)tbc.unused) >> 8 + p[0]) & 0xFF;
-								p[1] = ((((Uint32)tbc.g-(Uint32)p[1])*(Uint32)tbc.unused) >> 8 + p[1]) & 0xFF;
-								p[2] = ((((Uint32)tbc.b-(Uint32)p[2])*(Uint32)tbc.unused) >> 8 + p[2]) & 0xFF;
-								//p[0] = ((Uint32)tbc.unused*(Uint32)p[0] + (Uint32)tbc.r*(Uint32)(255-tbc.unused))>>8; //red 
-								//p[1] = ((Uint32)tbc.unused*(Uint32)p[1] + (Uint32)tbc.g*(Uint32)(255-tbc.unused))>>8; //green 
-								//p[2] = ((Uint32)tbc.unused*(Uint32)p[2] + (Uint32)tbc.b*(Uint32)(255-tbc.unused))>>8; //blue 
+								//p[0] = ((((Uint32)tbc.r-(Uint32)p[0])*(Uint32)tbc.unused) >> 8 + p[0]) & 0xFF;
+								//p[1] = ((((Uint32)tbc.g-(Uint32)p[1])*(Uint32)tbc.unused) >> 8 + p[1]) & 0xFF;
+								//p[2] = ((((Uint32)tbc.b-(Uint32)p[2])*(Uint32)tbc.unused) >> 8 + p[2]) & 0xFF;
+								p[0] = ((Uint32)tbc.unused*(Uint32)p[0] + (Uint32)tbc.r*(Uint32)(255-tbc.unused))>>8; //red 
+								p[1] = ((Uint32)tbc.unused*(Uint32)p[1] + (Uint32)tbc.g*(Uint32)(255-tbc.unused))>>8; //green 
+								p[2] = ((Uint32)tbc.unused*(Uint32)p[2] + (Uint32)tbc.b*(Uint32)(255-tbc.unused))>>8; //blue 
 								break;
 								break;
 						}
 						}
 					}
 					}
@@ -630,12 +630,12 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Su
 							case 255:
 							case 255:
 								break;
 								break;
 							default:
 							default:
-								//p[2] = ((Uint32)tbc.unused*(Uint32)p[2] + (Uint32)tbc.r*(Uint32)(255-tbc.unused))>>8; //red 
-								//p[1] = ((Uint32)tbc.unused*(Uint32)p[1] + (Uint32)tbc.g*(Uint32)(255-tbc.unused))>>8; //green 
-								//p[0] = ((Uint32)tbc.unused*(Uint32)p[0] + (Uint32)tbc.b*(Uint32)(255-tbc.unused))>>8; //blue 
-								p[2] = ((((Uint32)tbc.r-(Uint32)p[2])*(Uint32)tbc.unused) >> 8 + p[2]) & 0xFF;
-								p[1] = ((((Uint32)tbc.g-(Uint32)p[1])*(Uint32)tbc.unused) >> 8 + p[1]) & 0xFF;
-								p[0] = ((((Uint32)tbc.b-(Uint32)p[0])*(Uint32)tbc.unused) >> 8 + p[0]) & 0xFF;
+								p[2] = ((Uint32)tbc.unused*(Uint32)p[2] + (Uint32)tbc.r*(Uint32)(255-tbc.unused))>>8; //red 
+								p[1] = ((Uint32)tbc.unused*(Uint32)p[1] + (Uint32)tbc.g*(Uint32)(255-tbc.unused))>>8; //green 
+								p[0] = ((Uint32)tbc.unused*(Uint32)p[0] + (Uint32)tbc.b*(Uint32)(255-tbc.unused))>>8; //blue 
+								//p[2] = ((((Uint32)tbc.r-(Uint32)p[2])*(Uint32)tbc.unused) >> 8 + p[2]) & 0xFF;
+								//p[1] = ((((Uint32)tbc.g-(Uint32)p[1])*(Uint32)tbc.unused) >> 8 + p[1]) & 0xFF;
+								//p[0] = ((((Uint32)tbc.b-(Uint32)p[0])*(Uint32)tbc.unused) >> 8 + p[0]) & 0xFF;
 								break;
 								break;
 						}
 						}
 					}
 					}

+ 5 - 0
hch/CLodHandler.cpp

@@ -377,6 +377,11 @@ CDefHandler * CLodHandler::giveDef(std::string defName)
 {
 {
 	std::transform(defName.begin(), defName.end(), defName.begin(), (int(*)(int))toupper);
 	std::transform(defName.begin(), defName.end(), defName.begin(), (int(*)(int))toupper);
 	Entry * ourEntry = entries.znajdz(Entry(defName));
 	Entry * ourEntry = entries.znajdz(Entry(defName));
+	if(!ourEntry) //nothing's been found
+	{
+		std::cerr<<"No def: "<<defName;
+		throw(std::string("Bad def name!"));
+	}
 	CDefHandler * ret;
 	CDefHandler * ret;
 	fseek(FLOD, ourEntry->offset, 0);
 	fseek(FLOD, ourEntry->offset, 0);
 	unsigned char * outp;
 	unsigned char * outp;

+ 10 - 0
mapHandler.cpp

@@ -828,6 +828,16 @@ void CMapHandler::init()
 			bback>>battleBacks[i][f];
 			bback>>battleBacks[i][f];
 		}
 		}
 	}
 	}
+
+	//initializing battle hero animation
+	std::ifstream bher("config/battleHeroes.txt");
+	int numberofh;
+	bher>>numberofh;
+	battleHeroes.resize(numberofh);
+	for(int i=0; i<numberofh; ++i) //9 - number of terrains battle can be fought on
+	{
+		bher>>battleHeroes[i];
+	}
 }
 }
 
 
 SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect)
 SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect)

+ 1 - 0
mapHandler.h

@@ -74,6 +74,7 @@ public:
 	std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase)
 	std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase)
 	std::map<int, CGDefInfo*> villages, forts, capitols;
 	std::map<int, CGDefInfo*> villages, forts, capitols;
 	std::vector< std::vector< std::string > > battleBacks; //battleBacks[terType] - vector of possible names for certain terrain type
 	std::vector< std::vector< std::string > > battleBacks; //battleBacks[terType] - vector of possible names for certain terrain type
+	std::vector< std::string > battleHeroes; //battleHeroes[hero type] - name of def that has hero animation for battle
 
 
 	PseudoV< PseudoV< PseudoV<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
 	PseudoV< PseudoV< PseudoV<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile