2008-02-25 01:06:27 +02:00
|
|
|
#include "CBattleInterface.h"
|
2008-02-26 20:01:26 +02:00
|
|
|
#include "CGameInfo.h"
|
|
|
|
#include "hch\CLodHandler.h"
|
|
|
|
#include "SDL_Extensions.h"
|
|
|
|
#include "CAdvmapInterface.h"
|
|
|
|
#include "AdventureMapButton.h"
|
2008-03-03 21:41:10 +02:00
|
|
|
#include "hch\CHeroHandler.h"
|
|
|
|
#include "hch\CDefHandler.h"
|
|
|
|
|
|
|
|
extern SDL_Surface * screen;
|
2008-02-25 01:06:27 +02:00
|
|
|
|
2008-03-04 19:25:58 +02:00
|
|
|
CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2) : printCellBorders(true)
|
2008-02-25 01:06:27 +02:00
|
|
|
{
|
2008-03-05 19:01:41 +02:00
|
|
|
//initializing armies
|
|
|
|
this->army1 = army1;
|
|
|
|
this->army2 = army2;
|
|
|
|
for(std::map<int,std::pair<CCreature*,int> >::iterator i=army1->slots.begin(); i!=army1->slots.end(); ++i)
|
|
|
|
{
|
|
|
|
//creAnim1.push_back(new CCreatureAnimation(i->second.first->animDefName));
|
|
|
|
creAnim1.push_back(new CCreatureAnimation(i->second.first->animDefName));
|
|
|
|
creAnim1[creAnim1.size()-1]->setType(2);
|
|
|
|
}
|
|
|
|
for(std::map<int,std::pair<CCreature*,int> >::iterator i=army2->slots.begin(); i!=army2->slots.end(); ++i)
|
|
|
|
{
|
|
|
|
creAnim2.push_back(new CCreatureAnimation(i->second.first->animDefName));
|
|
|
|
creAnim2[creAnim2.size()-1]->setType(2);
|
|
|
|
}
|
2008-03-03 21:41:10 +02:00
|
|
|
//preparing menu background and terrain
|
2008-02-26 20:01:26 +02:00
|
|
|
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);
|
|
|
|
|
2008-03-03 21:41:10 +02:00
|
|
|
//blitting menu background and terrain
|
2008-02-26 20:01:26 +02:00
|
|
|
blitAt(background, 0, 0);
|
|
|
|
blitAt(menu, 0, 556);
|
|
|
|
CSDL_Ext::update();
|
|
|
|
|
2008-03-03 21:41:10 +02:00
|
|
|
//preparing buttons
|
2008-02-26 20:01:26 +02:00
|
|
|
bOptions = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bOptionsf, 3, 561, "icm003.def", this, false, NULL, false);
|
2008-03-01 13:49:25 +02:00
|
|
|
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);
|
2008-03-03 21:41:10 +02:00
|
|
|
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
|
|
|
|
{
|
2008-03-04 19:25:58 +02:00
|
|
|
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);
|
2008-03-03 21:41:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
attackingHero = NULL;
|
|
|
|
}
|
|
|
|
if(hero2) // defending hero
|
|
|
|
{
|
2008-03-04 19:25:58 +02:00
|
|
|
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);
|
2008-03-03 21:41:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
defendingHero = NULL;
|
|
|
|
}
|
2008-03-04 19:25:58 +02:00
|
|
|
|
|
|
|
//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);
|
2008-02-25 01:06:27 +02:00
|
|
|
}
|
2008-02-26 20:01:26 +02:00
|
|
|
|
|
|
|
CBattleInterface::~CBattleInterface()
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(background);
|
|
|
|
SDL_FreeSurface(menu);
|
2008-03-01 13:49:25 +02:00
|
|
|
delete bOptions;
|
|
|
|
delete bSurrender;
|
|
|
|
delete bFlee;
|
|
|
|
delete bAutofight;
|
|
|
|
delete bSpell;
|
|
|
|
delete bWait;
|
|
|
|
delete bDefence;
|
2008-03-03 21:41:10 +02:00
|
|
|
delete bConsoleUp;
|
|
|
|
delete bConsoleDown;
|
|
|
|
|
|
|
|
delete attackingHero;
|
|
|
|
delete defendingHero;
|
2008-03-04 19:25:58 +02:00
|
|
|
|
|
|
|
SDL_FreeSurface(cellBorder);
|
|
|
|
SDL_FreeSurface(cellShade);
|
2008-03-05 19:01:41 +02:00
|
|
|
|
|
|
|
for(int g=0; g<creAnim1.size(); ++g)
|
|
|
|
delete creAnim1[g];
|
|
|
|
for(int g=0; g<creAnim2.size(); ++g)
|
|
|
|
delete creAnim2[g];
|
2008-02-26 20:01:26 +02:00
|
|
|
}
|
|
|
|
|
2008-02-25 01:06:27 +02:00
|
|
|
void CBattleInterface::activate()
|
|
|
|
{
|
2008-02-26 20:01:26 +02:00
|
|
|
bOptions->activate();
|
2008-03-01 13:49:25 +02:00
|
|
|
bSurrender->activate();
|
|
|
|
bFlee->activate();
|
|
|
|
bAutofight->activate();
|
|
|
|
bSpell->activate();
|
|
|
|
bWait->activate();
|
|
|
|
bDefence->activate();
|
2008-03-03 21:41:10 +02:00
|
|
|
bConsoleUp->activate();
|
|
|
|
bConsoleDown->activate();
|
2008-02-25 01:06:27 +02:00
|
|
|
}
|
2008-02-26 20:01:26 +02:00
|
|
|
|
2008-02-25 01:06:27 +02:00
|
|
|
void CBattleInterface::deactivate()
|
|
|
|
{
|
2008-02-26 20:01:26 +02:00
|
|
|
bOptions->deactivate();
|
2008-03-01 13:49:25 +02:00
|
|
|
bSurrender->deactivate();
|
|
|
|
bFlee->deactivate();
|
|
|
|
bAutofight->deactivate();
|
|
|
|
bSpell->deactivate();
|
|
|
|
bWait->deactivate();
|
|
|
|
bDefence->deactivate();
|
2008-03-03 21:41:10 +02:00
|
|
|
bConsoleUp->deactivate();
|
|
|
|
bConsoleDown->deactivate();
|
2008-02-26 20:01:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBattleInterface::show(SDL_Surface * to)
|
|
|
|
{
|
2008-03-03 21:41:10 +02:00
|
|
|
if(!to) //"evaluating" to
|
|
|
|
to = screen;
|
|
|
|
|
|
|
|
//showing background
|
2008-02-26 20:01:26 +02:00
|
|
|
blitAt(background, 0, 0, to);
|
2008-03-04 19:25:58 +02:00
|
|
|
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);
|
2008-03-03 21:41:10 +02:00
|
|
|
|
|
|
|
//showing buttons
|
2008-02-26 20:01:26 +02:00
|
|
|
bOptions->show(to);
|
2008-03-03 21:41:10 +02:00
|
|
|
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
|
2008-03-05 19:01:41 +02:00
|
|
|
if(attackingHero)
|
|
|
|
attackingHero->show(to);
|
|
|
|
if(defendingHero)
|
|
|
|
defendingHero->show(to);
|
|
|
|
|
|
|
|
//showing units //a lot of work...
|
2008-03-08 17:23:04 +02:00
|
|
|
switch(creAnim1.size()) //for attacker
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
creAnim1[0]->nextFrame(to, -116, 71, true); //6
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
creAnim1[0]->nextFrame(to, -94, -55, true); //3
|
|
|
|
creAnim1[1]->nextFrame(to, -94, 197, true); //9
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
creAnim1[0]->nextFrame(to, -94, -55, true); //3
|
|
|
|
creAnim1[1]->nextFrame(to, -116, 71, true); //6
|
|
|
|
creAnim1[2]->nextFrame(to, -94, 197, true); //9
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
creAnim1[0]->nextFrame(to, -94, -139, true); //1
|
|
|
|
creAnim1[1]->nextFrame(to, -94, 29, true); //5
|
|
|
|
creAnim1[2]->nextFrame(to, -94, 113, true); //7
|
|
|
|
creAnim1[3]->nextFrame(to, -94, 281, true); //11
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
creAnim1[0]->nextFrame(to, -94, -139, true); //1
|
|
|
|
creAnim1[1]->nextFrame(to, -94, -55, true); //3
|
|
|
|
creAnim1[2]->nextFrame(to, -116, 71, true); //6
|
|
|
|
creAnim1[3]->nextFrame(to, -94, 197, true); //9
|
|
|
|
creAnim1[4]->nextFrame(to, -94, 281, true); //11
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
creAnim1[0]->nextFrame(to, -94, -139, true); //1
|
|
|
|
creAnim1[1]->nextFrame(to, -94, -55, true); //3
|
|
|
|
creAnim1[2]->nextFrame(to, -94, 29, true); //5
|
|
|
|
creAnim1[3]->nextFrame(to, -94, 113, true); //7
|
|
|
|
creAnim1[4]->nextFrame(to, -94, 197, true); //9
|
|
|
|
creAnim1[5]->nextFrame(to, -94, 281, true); //11
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
creAnim1[0]->nextFrame(to, -94, -139, true); //1
|
|
|
|
creAnim1[1]->nextFrame(to, -94, -55, true); //3
|
|
|
|
creAnim1[2]->nextFrame(to, -94, 29, true); //5
|
|
|
|
creAnim1[3]->nextFrame(to, -116, 71, true); //6
|
|
|
|
creAnim1[4]->nextFrame(to, -94, 113, true); //7
|
|
|
|
creAnim1[5]->nextFrame(to, -94, 197, true); //9
|
|
|
|
creAnim1[6]->nextFrame(to, -94, 281, true); //11
|
|
|
|
break;
|
|
|
|
default: //fault
|
|
|
|
break;
|
|
|
|
//creAnim1[0]->nextFrame(to, -94, -139);
|
|
|
|
}
|
|
|
|
switch(creAnim2.size()) //for defender
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
creAnim2[0]->nextFrame(to, 441, 71, false); //6
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
creAnim2[0]->nextFrame(to, 463, -55, false); //3
|
|
|
|
creAnim2[1]->nextFrame(to, 463, 197, false); //9
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
creAnim2[0]->nextFrame(to, 463, -55, false); //3
|
|
|
|
creAnim2[1]->nextFrame(to, 441, 71, false); //6
|
|
|
|
creAnim2[2]->nextFrame(to, 463, 197, false); //9
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
creAnim2[0]->nextFrame(to, 463, -139, false); //1
|
|
|
|
creAnim2[1]->nextFrame(to, 463, 29, false); //5
|
|
|
|
creAnim2[2]->nextFrame(to, 463, 113, false); //7
|
|
|
|
creAnim2[3]->nextFrame(to, 463, 281, false); //11
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
creAnim2[0]->nextFrame(to, 463, -139, false); //1
|
|
|
|
creAnim2[1]->nextFrame(to, 463, -55, false); //3
|
|
|
|
creAnim2[2]->nextFrame(to, 441, 71, false); //6
|
|
|
|
creAnim2[3]->nextFrame(to, 463, 197, false); //9
|
|
|
|
creAnim2[4]->nextFrame(to, 463, 281, false); //11
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
creAnim2[0]->nextFrame(to, 463, -139, false); //1
|
|
|
|
creAnim2[1]->nextFrame(to, 463, -55, false); //3
|
|
|
|
creAnim2[2]->nextFrame(to, 463, 29, false); //5
|
|
|
|
creAnim2[3]->nextFrame(to, 463, 113, false); //7
|
|
|
|
creAnim2[4]->nextFrame(to, 463, 197, false); //9
|
|
|
|
creAnim2[5]->nextFrame(to, 463, 281, false); //11
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
creAnim2[0]->nextFrame(to, 463, -139, false); //1
|
|
|
|
creAnim2[1]->nextFrame(to, 463, -55, false); //3
|
|
|
|
creAnim2[2]->nextFrame(to, 463, 29, false); //5
|
|
|
|
creAnim2[3]->nextFrame(to, 441, 71, false); //6
|
|
|
|
creAnim2[4]->nextFrame(to, 463, 113, false); //7
|
|
|
|
creAnim2[5]->nextFrame(to, 463, 197, false); //9
|
|
|
|
creAnim2[6]->nextFrame(to, 463, 281, false); //11
|
|
|
|
break;
|
|
|
|
default: //fault
|
|
|
|
break;
|
|
|
|
//creAnim2[0]->nextFrame(to, 463, -139);
|
|
|
|
}
|
2008-03-05 19:01:41 +02:00
|
|
|
|
|
|
|
//units shown
|
2008-03-03 21:41:10 +02:00
|
|
|
|
|
|
|
CSDL_Ext::update();
|
2008-02-26 20:01:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBattleInterface::bOptionsf()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBattleInterface::bSurrenderf()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBattleInterface::bFleef()
|
|
|
|
{
|
2008-03-06 18:42:34 +02:00
|
|
|
for(int i=0; i<LOCPLINT->objsToBlit.size(); ++i)
|
|
|
|
{
|
|
|
|
if( dynamic_cast<CBattleInterface*>( LOCPLINT->objsToBlit[i] ) )
|
|
|
|
{
|
|
|
|
LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
deactivate();
|
|
|
|
|
|
|
|
LOCPLINT->adventureInt->activate();
|
|
|
|
delete this;
|
2008-02-26 20:01:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBattleInterface::bAutofightf()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBattleInterface::bSpellf()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBattleInterface::bWaitf()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBattleInterface::bDefencef()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBattleInterface::bConsoleUpf()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBattleInterface::bConsoleDownf()
|
|
|
|
{
|
|
|
|
}
|
2008-03-03 21:41:10 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2008-03-04 19:25:58 +02:00
|
|
|
SDL_Rect posb = pos;
|
|
|
|
CSDL_Ext::blit8bppAlphaTo24bpp(dh->ourImages[i].bitmap, NULL, to, &posb);
|
2008-03-03 21:41:10 +02:00
|
|
|
++image;
|
|
|
|
if(dh->ourImages[i+1].groupNumber!=phase) //back to appropriate frame
|
|
|
|
{
|
|
|
|
image = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-03-04 19:25:58 +02:00
|
|
|
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));
|
|
|
|
}
|
2008-03-05 19:01:41 +02:00
|
|
|
//++flagAnimCount;
|
|
|
|
//if(flagAnimCount%4==0)
|
2008-03-04 19:25:58 +02:00
|
|
|
{
|
|
|
|
++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);
|
|
|
|
}
|
2008-03-03 21:41:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CBattleHero::~CBattleHero()
|
|
|
|
{
|
|
|
|
delete dh;
|
2008-03-04 19:25:58 +02:00
|
|
|
delete flag;
|
2008-03-03 21:41:10 +02:00
|
|
|
}
|