mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
another piece of battles (and CCreatureAnimation)
This commit is contained in:
parent
ffd3742e3d
commit
4236c65512
@ -11,6 +11,20 @@ extern SDL_Surface * screen;
|
|||||||
|
|
||||||
CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2) : printCellBorders(true)
|
CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2) : printCellBorders(true)
|
||||||
{
|
{
|
||||||
|
//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);
|
||||||
|
}
|
||||||
//preparing menu background and terrain
|
//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()] );
|
||||||
@ -80,6 +94,11 @@ CBattleInterface::~CBattleInterface()
|
|||||||
|
|
||||||
SDL_FreeSurface(cellBorder);
|
SDL_FreeSurface(cellBorder);
|
||||||
SDL_FreeSurface(cellShade);
|
SDL_FreeSurface(cellShade);
|
||||||
|
|
||||||
|
for(int g=0; g<creAnim1.size(); ++g)
|
||||||
|
delete creAnim1[g];
|
||||||
|
for(int g=0; g<creAnim2.size(); ++g)
|
||||||
|
delete creAnim2[g];
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBattleInterface::activate()
|
void CBattleInterface::activate()
|
||||||
@ -142,8 +161,16 @@ void CBattleInterface::show(SDL_Surface * to)
|
|||||||
bConsoleDown->show(to);
|
bConsoleDown->show(to);
|
||||||
|
|
||||||
//showing hero animations
|
//showing hero animations
|
||||||
attackingHero->show(to);
|
if(attackingHero)
|
||||||
defendingHero->show(to);
|
attackingHero->show(to);
|
||||||
|
if(defendingHero)
|
||||||
|
defendingHero->show(to);
|
||||||
|
|
||||||
|
//showing units //a lot of work...
|
||||||
|
|
||||||
|
creAnim1[0]->nextFrame(to, -94, -139);
|
||||||
|
|
||||||
|
//units shown
|
||||||
|
|
||||||
CSDL_Ext::update();
|
CSDL_Ext::update();
|
||||||
}
|
}
|
||||||
@ -211,8 +238,8 @@ void CBattleHero::show(SDL_Surface *to)
|
|||||||
{
|
{
|
||||||
CSDL_Ext::blit8bppAlphaTo24bpp(flag->ourImages[flagAnim].bitmap, NULL, screen, &genRect(flag->ourImages[flagAnim].bitmap->h, flag->ourImages[flagAnim].bitmap->w, 31, 39));
|
CSDL_Ext::blit8bppAlphaTo24bpp(flag->ourImages[flagAnim].bitmap, NULL, screen, &genRect(flag->ourImages[flagAnim].bitmap->h, flag->ourImages[flagAnim].bitmap->w, 31, 39));
|
||||||
}
|
}
|
||||||
++flagAnimCount;
|
//++flagAnimCount;
|
||||||
if(flagAnimCount%4==0)
|
//if(flagAnimCount%4==0)
|
||||||
{
|
{
|
||||||
++flagAnim;
|
++flagAnim;
|
||||||
flagAnim %= flag->ourImages.size();
|
flagAnim %= flag->ourImages.size();
|
||||||
|
@ -41,6 +41,8 @@ private:
|
|||||||
* bWait, * bDefence, * bConsoleUp, * bConsoleDown;
|
* bWait, * bDefence, * bConsoleUp, * bConsoleDown;
|
||||||
CBattleHero * attackingHero, * defendingHero;
|
CBattleHero * attackingHero, * defendingHero;
|
||||||
SDL_Surface * cellBorder, * cellShade;
|
SDL_Surface * cellBorder, * cellShade;
|
||||||
|
CCreatureSet * army1, * army2; //fighting armies
|
||||||
|
std::vector< CCreatureAnimation * > creAnim1, creAnim2; //animations of creatures from fighting armies
|
||||||
public:
|
public:
|
||||||
CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2); //c-tor
|
CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2); //c-tor
|
||||||
~CBattleInterface(); //d-tor
|
~CBattleInterface(); //d-tor
|
||||||
|
@ -1873,15 +1873,18 @@ void CPlayerInterface::actionFinished(Action action)//occurs AFTER every action
|
|||||||
|
|
||||||
void CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack
|
void CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack
|
||||||
{
|
{
|
||||||
|
unsigned int av=0;
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
|
++av;
|
||||||
SDL_Event sEvent;
|
SDL_Event sEvent;
|
||||||
while (SDL_PollEvent(&sEvent)) //wait for event...
|
while (SDL_PollEvent(&sEvent)) //wait for event...
|
||||||
{
|
{
|
||||||
LOCPLINT->handleEvent(&sEvent);
|
LOCPLINT->handleEvent(&sEvent);
|
||||||
}
|
}
|
||||||
for(int i=0;i<objsToBlit.size();i++)
|
if(av%3==0)
|
||||||
objsToBlit[i]->show();
|
for(int i=0;i<objsToBlit.size();i++)
|
||||||
|
objsToBlit[i]->show();
|
||||||
//SDL_Flip(ekran);
|
//SDL_Flip(ekran);
|
||||||
CSDL_Ext::update(ekran);
|
CSDL_Ext::update(ekran);
|
||||||
|
|
||||||
|
@ -337,26 +337,69 @@ void CCreatureHandler::loadCreatures()
|
|||||||
boost::assign::insert(bigImgs)(i-2,smi->ourImages[i].bitmap);
|
boost::assign::insert(bigImgs)(i-2,smi->ourImages[i].bitmap);
|
||||||
}
|
}
|
||||||
delete smi;
|
delete smi;
|
||||||
|
//
|
||||||
|
|
||||||
|
//loading unit animation def names
|
||||||
|
std::ifstream inp("config/CREDEFS.TXT", std::ios::in | std::ios::binary); //this file is not in lod
|
||||||
|
inp.seekg(0,std::ios::end); // na koniec
|
||||||
|
int andame2 = inp.tellg(); // read length
|
||||||
|
inp.seekg(0,std::ios::beg); // wracamy na poczatek
|
||||||
|
char * bufor = new char[andame2]; // allocate memory
|
||||||
|
inp.read((char*)bufor, andame2); // read map file to buffer
|
||||||
|
inp.close();
|
||||||
|
buf = std::string(bufor);
|
||||||
|
delete [andame2] bufor;
|
||||||
|
|
||||||
|
i = 0; //buf iterator
|
||||||
|
hmcr = 0;
|
||||||
|
for(i; i<andame2; ++i) //omitting rubbish
|
||||||
|
{
|
||||||
|
if(buf[i]=='\r')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i+=2;
|
||||||
|
for(int s=0; s<creatures.size()-16; ++s)
|
||||||
|
{
|
||||||
|
int befi=i;
|
||||||
|
std::string rub;
|
||||||
|
for(i; i<andame2; ++i)
|
||||||
|
{
|
||||||
|
if(buf[i]==' ')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
rub = buf.substr(befi, i-befi);
|
||||||
|
++i;
|
||||||
|
|
||||||
|
befi=i;
|
||||||
|
for(i; i<andame2; ++i)
|
||||||
|
{
|
||||||
|
if(buf[i]=='\r')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::string defName = buf.substr(befi, i-befi);
|
||||||
|
creatures[s].animDefName = defName;
|
||||||
|
}
|
||||||
|
loadAnimationInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCreatureHandler::loadAnimationInfo()
|
void CCreatureHandler::loadAnimationInfo()
|
||||||
{
|
{
|
||||||
//std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("CRANIM.TXT");
|
std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("CRANIM.TXT");
|
||||||
//int andame = buf.size();
|
int andame = buf.size();
|
||||||
//int i=0; //buf iterator
|
int i=0; //buf iterator
|
||||||
//hmcr=0;
|
int hmcr=0;
|
||||||
//for(i; i<andame; ++i)
|
for(i; i<andame; ++i)
|
||||||
//{
|
{
|
||||||
// if(buf[i]=='\r')
|
if(buf[i]=='\r')
|
||||||
// ++hmcr;
|
++hmcr;
|
||||||
// if(hmcr==2)
|
if(hmcr==2)
|
||||||
// break;
|
break;
|
||||||
//}
|
}
|
||||||
//i+=2;
|
i+=2;
|
||||||
//for(int dd=0; dd<creatures.size(); ++dd)
|
for(int dd=0; dd<creatures.size()-16; ++dd)
|
||||||
//{
|
{
|
||||||
// loadUnitAnimInfo(creatures[dd], buf, i);
|
loadUnitAnimInfo(creatures[dd], buf, i);
|
||||||
//}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -568,9 +611,31 @@ void CCreatureAnimation::setType(int type)
|
|||||||
{
|
{
|
||||||
this->type = type;
|
this->type = type;
|
||||||
curFrame = 0;
|
curFrame = 0;
|
||||||
|
if(type!=-1)
|
||||||
|
{
|
||||||
|
if(SEntries[curFrame].group!=type) //rewind
|
||||||
|
{
|
||||||
|
int j=-1; //first frame in displayed group
|
||||||
|
for(int g=0; g<SEntries.size(); ++g)
|
||||||
|
{
|
||||||
|
if(SEntries[g].group==type && j==-1)
|
||||||
|
{
|
||||||
|
j = g;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(curFrame!=-1)
|
||||||
|
curFrame = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(curFrame>=frames)
|
||||||
|
curFrame = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CCreatureAnimation::CCreatureAnimation(std::string name)
|
CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL), RWEntries(NULL)
|
||||||
{
|
{
|
||||||
//load main file
|
//load main file
|
||||||
std::string data2 = CGI->spriteh->getTextFile(name);
|
std::string data2 = CGI->spriteh->getTextFile(name);
|
||||||
@ -683,8 +748,28 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y)
|
|||||||
return -1; //not enough depth
|
return -1; //not enough depth
|
||||||
|
|
||||||
int SIndex = curFrame++; //TODO: finish
|
int SIndex = curFrame++; //TODO: finish
|
||||||
if(curFrame>=frames)
|
if(type!=-1)
|
||||||
curFrame = 0;
|
{
|
||||||
|
if(SEntries[curFrame].group!=type) //rewind
|
||||||
|
{
|
||||||
|
int j=-1; //first frame in displayed group
|
||||||
|
for(int g=0; g<SEntries.size(); ++g)
|
||||||
|
{
|
||||||
|
if(SEntries[g].group==type && j==-1)
|
||||||
|
{
|
||||||
|
j = g;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(curFrame!=-1)
|
||||||
|
curFrame = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(curFrame>=frames)
|
||||||
|
curFrame = 0;
|
||||||
|
}
|
||||||
|
|
||||||
long BaseOffset,
|
long BaseOffset,
|
||||||
SpriteWidth, SpriteHeight, //format sprite'a
|
SpriteWidth, SpriteHeight, //format sprite'a
|
||||||
@ -839,3 +924,12 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CCreatureAnimation::~CCreatureAnimation()
|
||||||
|
{
|
||||||
|
delete [] FDef;
|
||||||
|
if (RWEntries)
|
||||||
|
delete [] RWEntries;
|
||||||
|
if (RLEntries)
|
||||||
|
delete [] RLEntries;
|
||||||
|
}
|
||||||
|
@ -19,6 +19,7 @@ public:
|
|||||||
int level; // 0 - unknown
|
int level; // 0 - unknown
|
||||||
std::string abilityText; //description of abilities
|
std::string abilityText; //description of abilities
|
||||||
std::string abilityRefs; //references to abilities, in textformat
|
std::string abilityRefs; //references to abilities, in textformat
|
||||||
|
std::string animDefName;
|
||||||
int idNumber;
|
int idNumber;
|
||||||
|
|
||||||
///animation info
|
///animation info
|
||||||
@ -90,7 +91,7 @@ private:
|
|||||||
int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1])
|
int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1])
|
||||||
public:
|
public:
|
||||||
CCreatureAnimation(std::string name); //c-tor
|
CCreatureAnimation(std::string name); //c-tor
|
||||||
//~CCreatureAnimation(); //d-tor //not necessery ATM
|
~CCreatureAnimation(); //d-tor //not necessery ATM
|
||||||
|
|
||||||
void setType(int type); //sets type of animation and cleares framecount
|
void setType(int type); //sets type of animation and cleares framecount
|
||||||
int getType() const; //returns type of animation
|
int getType() const; //returns type of animation
|
||||||
|
Loading…
Reference in New Issue
Block a user