| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 | 
							- #include "CBattleInterface.h"
 
- #include "CGameInfo.h"
 
- #include "hch\CLodHandler.h"
 
- #include "SDL_Extensions.h"
 
- #include "CAdvmapInterface.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) : printCellBorders(true)
 
- {
 
- 	//preparing menu background and terrain
 
- 	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()] );
 
- 	menu = CGI->bitmaph->loadBitmap("CBAR.BMP");
 
- 	CSDL_Ext::blueToPlayersAdv(menu, hero1->tempOwner);
 
- 	//blitting menu background and terrain
 
- 	blitAt(background, 0, 0);
 
- 	blitAt(menu, 0, 556);
 
- 	CSDL_Ext::update();
 
- 	
 
- 	//preparing buttons
 
- 	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);
 
- 	bFlee = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bFleef, 105, 561, "icm002.def", this, false, NULL, false);
 
- 	bAutofight  = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bAutofightf, 157, 561, "icm004.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);
 
- 	bDefence = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bDefencef, 747, 561, "icm007.def", this, false, NULL, false);
 
- 	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(CGI->mh->battleHeroes[hero1->type->heroType], 0, 0, false, hero1->tempOwner);
 
- 		attackingHero->pos = genRect(attackingHero->dh->ourImages[0].bitmap->h, attackingHero->dh->ourImages[0].bitmap->w, -40, 0);
 
- 	}
 
- 	else
 
- 	{
 
- 		attackingHero = NULL;
 
- 	}
 
- 	if(hero2) // defending hero
 
- 	{
 
- 		defendingHero = new CBattleHero(CGI->mh->battleHeroes[hero2->type->heroType], 0, 0, true, hero2->tempOwner);
 
- 		defendingHero->pos = genRect(defendingHero->dh->ourImages[0].bitmap->h, defendingHero->dh->ourImages[0].bitmap->w, 690, 0);
 
- 	}
 
- 	else
 
- 	{
 
- 		defendingHero = NULL;
 
- 	}
 
- 	//preparing cells and hexes
 
- 	cellBorder = CGI->bitmaph->loadBitmap("CCELLGRD.BMP");
 
- 	cellBorder = CSDL_Ext::alphaTransform(cellBorder);
 
- 	cellShade = CGI->bitmaph->loadBitmap("CCELLSHD.BMP");
 
- 	cellShade = CSDL_Ext::alphaTransform(cellShade);
 
- }
 
- CBattleInterface::~CBattleInterface()
 
- {
 
- 	SDL_FreeSurface(background);
 
- 	SDL_FreeSurface(menu);
 
- 	delete bOptions;
 
- 	delete bSurrender;
 
- 	delete bFlee;
 
- 	delete bAutofight;
 
- 	delete bSpell;
 
- 	delete bWait;
 
- 	delete bDefence;
 
- 	delete bConsoleUp;
 
- 	delete bConsoleDown;
 
- 	delete attackingHero;
 
- 	delete defendingHero;
 
- 	SDL_FreeSurface(cellBorder);
 
- 	SDL_FreeSurface(cellShade);
 
- }
 
- void CBattleInterface::activate()
 
- {
 
- 	bOptions->activate();
 
- 	bSurrender->activate();
 
- 	bFlee->activate();
 
- 	bAutofight->activate();
 
- 	bSpell->activate();
 
- 	bWait->activate();
 
- 	bDefence->activate();
 
- 	bConsoleUp->activate();
 
- 	bConsoleDown->activate();
 
- }
 
- void CBattleInterface::deactivate()
 
- {
 
- 	bOptions->deactivate();
 
- 	bSurrender->deactivate();
 
- 	bFlee->deactivate();
 
- 	bAutofight->deactivate();
 
- 	bSpell->deactivate();
 
- 	bWait->deactivate();
 
- 	bDefence->deactivate();
 
- 	bConsoleUp->deactivate();
 
- 	bConsoleDown->deactivate();
 
- }
 
- void CBattleInterface::show(SDL_Surface * to)
 
- {
 
- 	if(!to) //"evaluating" to
 
- 		to = screen;
 
- 	//showing background
 
- 	blitAt(background, 0, 0, to);
 
- 	if(printCellBorders) //printing cell borders
 
- 	{
 
- 		for(int i=0; i<11; ++i) //rows
 
- 		{
 
- 			for(int j=0; j<15; ++j) //columns
 
- 			{
 
- 				int x = 58 + (i%2==0 ? 22 : 0) + 44*j;
 
- 				int y = 86 + 42 * i;
 
- 				CSDL_Ext::blit8bppAlphaTo24bpp(cellBorder, NULL, to, &genRect(cellBorder->h, cellBorder->w, x, y));
 
- 			}
 
- 		}
 
- 	}
 
- 	//showing menu background
 
- 	blitAt(menu, 0, 556, to);
 
- 	//showing buttons
 
- 	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::bSurrenderf()
 
- {
 
- }
 
- void CBattleInterface::bFleef()
 
- {
 
- }
 
- void CBattleInterface::bAutofightf()
 
- {
 
- }
 
- void CBattleInterface::bSpellf()
 
- {
 
- }
 
- void CBattleInterface::bWaitf()
 
- {
 
- }
 
- void CBattleInterface::bDefencef()
 
- {
 
- }
 
- void CBattleInterface::bConsoleUpf()
 
- {
 
- }
 
- 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)
 
- 		{
 
- 			SDL_Rect posb = pos;
 
- 			CSDL_Ext::blit8bppAlphaTo24bpp(dh->ourImages[i].bitmap, NULL, to, &posb);
 
- 			++image;
 
- 			if(dh->ourImages[i+1].groupNumber!=phase) //back to appropriate frame
 
- 			{
 
- 				image = 0;
 
- 			}
 
- 			break;
 
- 		}
 
- 	}
 
- 	if(flip)
 
- 	{
 
- 		CSDL_Ext::blit8bppAlphaTo24bpp(flag->ourImages[flagAnim].bitmap, NULL, screen, &genRect(flag->ourImages[flagAnim].bitmap->h, flag->ourImages[flagAnim].bitmap->w, 752, 39));
 
- 	}
 
- 	else
 
- 	{
 
- 		CSDL_Ext::blit8bppAlphaTo24bpp(flag->ourImages[flagAnim].bitmap, NULL, screen, &genRect(flag->ourImages[flagAnim].bitmap->h, flag->ourImages[flagAnim].bitmap->w, 31, 39));
 
- 	}
 
- 	++flagAnimCount;
 
- 	if(flagAnimCount%4==0)
 
- 	{
 
- 		++flagAnim;
 
- 		flagAnim %= flag->ourImages.size();
 
- 	}
 
- }
 
- CBattleHero::CBattleHero(std::string defName, int phaseG, int imageG, bool flipG, unsigned char player): phase(phaseG), image(imageG), flip(flipG), flagAnim(0)
 
- {
 
- 	dh = CGI->spriteh->giveDef( defName );
 
- 	for(int i=0; i<dh->ourImages.size(); ++i) //transforming images
 
- 	{
 
- 		if(flip)
 
- 			dh->ourImages[i].bitmap = CSDL_Ext::rotate01(dh->ourImages[i].bitmap); 
 
- 		dh->ourImages[i].bitmap = CSDL_Ext::alphaTransform(dh->ourImages[i].bitmap);
 
- 	}
 
- 	dh->alphaTransformed = true;
 
- 	if(flip)
 
- 		flag = CGI->spriteh->giveDef("CMFLAGR.DEF");
 
- 	else
 
- 		flag = CGI->spriteh->giveDef("CMFLAGL.DEF");
 
- 	for(int i=0; i<flag->ourImages.size(); ++i)
 
- 	{
 
- 		flag->ourImages[i].bitmap = CSDL_Ext::alphaTransform(flag->ourImages[i].bitmap);
 
- 		CSDL_Ext::blueToPlayersAdv(flag->ourImages[i].bitmap, player);
 
- 	}
 
- }
 
- CBattleHero::~CBattleHero()
 
- {
 
- 	delete dh;
 
- 	delete flag;
 
- }
 
 
  |