mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
battle improvements
This commit is contained in:
parent
7b88f4a70b
commit
d106fdcf2a
@ -13,7 +13,7 @@ extern SDL_Surface * screen;
|
|||||||
SDL_Surface * CBattleInterface::cellBorder, * CBattleInterface::cellShade;
|
SDL_Surface * CBattleInterface::cellBorder, * CBattleInterface::cellShade;
|
||||||
|
|
||||||
CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2)
|
CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2)
|
||||||
: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2)
|
: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0)
|
||||||
{
|
{
|
||||||
//initializing armies
|
//initializing armies
|
||||||
this->army1 = army1;
|
this->army1 = army1;
|
||||||
@ -142,6 +142,7 @@ void CBattleInterface::deactivate()
|
|||||||
|
|
||||||
void CBattleInterface::show(SDL_Surface * to)
|
void CBattleInterface::show(SDL_Surface * to)
|
||||||
{
|
{
|
||||||
|
++animCount;
|
||||||
if(!to) //"evaluating" to
|
if(!to) //"evaluating" to
|
||||||
to = screen;
|
to = screen;
|
||||||
|
|
||||||
@ -162,7 +163,7 @@ void CBattleInterface::show(SDL_Surface * to)
|
|||||||
//printing hovered cell
|
//printing hovered cell
|
||||||
for(int b=0; b<187; ++b)
|
for(int b=0; b<187; ++b)
|
||||||
{
|
{
|
||||||
if(bfield[b].hovered)
|
if(bfield[b].strictHovered && bfield[b].hovered)
|
||||||
{
|
{
|
||||||
int x = 14 + ((b/17)%2==0 ? 22 : 0) + 44*(b%17);
|
int x = 14 + ((b/17)%2==0 ? 22 : 0) + 44*(b%17);
|
||||||
int y = 86 + 42 * (b/17);
|
int y = 86 + 42 * (b/17);
|
||||||
@ -194,7 +195,7 @@ void CBattleInterface::show(SDL_Surface * to)
|
|||||||
for(std::map<int, CCreatureAnimation*>::iterator j=creAnims.begin(); j!=creAnims.end(); ++j)
|
for(std::map<int, CCreatureAnimation*>::iterator j=creAnims.begin(); j!=creAnims.end(); ++j)
|
||||||
{
|
{
|
||||||
std::pair <int, int> coords = CBattleHex::getXYUnitAnim(stacks[j->first].position, stacks[j->first].owner == attackingHeroInstance->tempOwner);
|
std::pair <int, int> coords = CBattleHex::getXYUnitAnim(stacks[j->first].position, stacks[j->first].owner == attackingHeroInstance->tempOwner);
|
||||||
j->second->nextFrame(to, coords.first, coords.second, stacks[j->first].owner == attackingHeroInstance->tempOwner);
|
j->second->nextFrame(to, coords.first, coords.second, stacks[j->first].owner == attackingHeroInstance->tempOwner, animCount%2==0);
|
||||||
}
|
}
|
||||||
//units shown
|
//units shown
|
||||||
|
|
||||||
@ -343,11 +344,13 @@ std::pair<int, int> CBattleHex::getXYUnitAnim(int hexNum, bool attacker)
|
|||||||
void CBattleHex::activate()
|
void CBattleHex::activate()
|
||||||
{
|
{
|
||||||
Hoverable::activate();
|
Hoverable::activate();
|
||||||
|
MotionInterested::activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBattleHex::deactivate()
|
void CBattleHex::deactivate()
|
||||||
{
|
{
|
||||||
Hoverable::activate();
|
Hoverable::deactivate();
|
||||||
|
MotionInterested::deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBattleHex::hover(bool on)
|
void CBattleHex::hover(bool on)
|
||||||
@ -356,6 +359,21 @@ void CBattleHex::hover(bool on)
|
|||||||
Hoverable::hover(on);
|
Hoverable::hover(on);
|
||||||
}
|
}
|
||||||
|
|
||||||
CBattleHex::CBattleHex() : myNumber(-1), accesible(true), hovered(false)
|
CBattleHex::CBattleHex() : myNumber(-1), accesible(true), hovered(false), strictHovered(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CBattleHex::mouseMoved(SDL_MouseMotionEvent &sEvent)
|
||||||
|
{
|
||||||
|
if(CBattleInterface::cellShade)
|
||||||
|
{
|
||||||
|
if(CSDL_Ext::SDL_GetPixel(CBattleInterface::cellShade, sEvent.x-pos.x, sEvent.y-pos.y) == 0) //hovered pixel is outside hex
|
||||||
|
{
|
||||||
|
strictHovered = false;
|
||||||
|
}
|
||||||
|
else //hovered pixel is inside hex
|
||||||
|
{
|
||||||
|
strictHovered = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -22,18 +22,19 @@ public:
|
|||||||
~CBattleHero(); //d-tor
|
~CBattleHero(); //d-tor
|
||||||
};
|
};
|
||||||
|
|
||||||
class CBattleHex : public Hoverable
|
class CBattleHex : public Hoverable, public MotionInterested
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
unsigned int myNumber;
|
unsigned int myNumber;
|
||||||
bool accesible;
|
bool accesible;
|
||||||
//CStack * ourStack;
|
//CStack * ourStack;
|
||||||
bool hovered;
|
bool hovered, strictHovered;
|
||||||
static std::pair<int, int> getXYUnitAnim(int hexNum, bool attacker); //returns (x, y) of left top corner of animation
|
static std::pair<int, int> getXYUnitAnim(int hexNum, bool attacker); //returns (x, y) of left top corner of animation
|
||||||
//for user interactions
|
//for user interactions
|
||||||
void hover (bool on);
|
void hover (bool on);
|
||||||
void activate();
|
void activate();
|
||||||
void deactivate();
|
void deactivate();
|
||||||
|
void mouseMoved (SDL_MouseMotionEvent & sEvent);
|
||||||
CBattleHex();
|
CBattleHex();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -52,6 +53,7 @@ private:
|
|||||||
CCreatureSet * army1, * army2; //fighting armies
|
CCreatureSet * army1, * army2; //fighting armies
|
||||||
CGHeroInstance * attackingHeroInstance, * defendingHeroInstance;
|
CGHeroInstance * attackingHeroInstance, * defendingHeroInstance;
|
||||||
std::map< int, CCreatureAnimation * > creAnims; //animations of creatures from fighting armies (order like in BattleInfo's stacks)
|
std::map< int, CCreatureAnimation * > creAnims; //animations of creatures from fighting armies (order like in BattleInfo's stacks)
|
||||||
|
unsigned char animCount;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2); //c-tor
|
CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2); //c-tor
|
||||||
|
@ -114,7 +114,7 @@ void CBuildingRect::mouseMoved (SDL_MouseMotionEvent & sEvent)
|
|||||||
{
|
{
|
||||||
if(area)
|
if(area)
|
||||||
{
|
{
|
||||||
if(CSDL_Ext::SDL_GetPixel(area,sEvent.x-pos.x,sEvent.y-pos.y) == 0) //najechany piksel jest poza polem
|
if(CSDL_Ext::SDL_GetPixel(area,sEvent.x-pos.x,sEvent.y-pos.y) == 0) //hovered pixel is inside this building
|
||||||
{
|
{
|
||||||
if(LOCPLINT->castleInt->hBuild == this)
|
if(LOCPLINT->castleInt->hBuild == this)
|
||||||
{
|
{
|
||||||
@ -122,11 +122,11 @@ void CBuildingRect::mouseMoved (SDL_MouseMotionEvent & sEvent)
|
|||||||
LOCPLINT->statusbar->clear();
|
LOCPLINT->statusbar->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else //w polu
|
else //inside the area of this building
|
||||||
{
|
{
|
||||||
if(LOCPLINT->castleInt->hBuild) //jakis budynek jest zaznaczony
|
if(LOCPLINT->castleInt->hBuild) //a building is hovered
|
||||||
{
|
{
|
||||||
if((*LOCPLINT->castleInt->hBuild)<(*this)) //ustawiamy sie, jesli jestesmy na wierzchu
|
if((*LOCPLINT->castleInt->hBuild)<(*this)) //set if we are on top
|
||||||
{
|
{
|
||||||
LOCPLINT->castleInt->hBuild = this;
|
LOCPLINT->castleInt->hBuild = this;
|
||||||
if(CGI->buildh->buildings[str->townID][str->ID] && CGI->buildh->buildings[str->townID][str->ID]->name.length())
|
if(CGI->buildh->buildings[str->townID][str->ID] && CGI->buildh->buildings[str->townID][str->ID]->name.length())
|
||||||
@ -135,7 +135,7 @@ void CBuildingRect::mouseMoved (SDL_MouseMotionEvent & sEvent)
|
|||||||
LOCPLINT->statusbar->print(str->name);
|
LOCPLINT->statusbar->print(str->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else //nie ma budynku, wiec damy nasz
|
else //no building hovered
|
||||||
{
|
{
|
||||||
LOCPLINT->castleInt->hBuild = this;
|
LOCPLINT->castleInt->hBuild = this;
|
||||||
if(CGI->buildh->buildings[str->townID][str->ID] && CGI->buildh->buildings[str->townID][str->ID]->name.length())
|
if(CGI->buildh->buildings[str->townID][str->ID] && CGI->buildh->buildings[str->townID][str->ID]->name.length())
|
||||||
|
@ -1876,16 +1876,16 @@ 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;
|
unsigned char showCount = 0;
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
++av;
|
++showCount;
|
||||||
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);
|
||||||
}
|
}
|
||||||
if(av%3==0)
|
if(showCount%2==0)
|
||||||
for(int i=0;i<objsToBlit.size();i++)
|
for(int i=0;i<objsToBlit.size();i++)
|
||||||
objsToBlit[i]->show();
|
objsToBlit[i]->show();
|
||||||
//SDL_Flip(ekran);
|
//SDL_Flip(ekran);
|
||||||
|
@ -743,34 +743,42 @@ int CCreatureAnimation::readNormalNr (int pos, int bytCon, unsigned char * str,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker)
|
int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker, bool incrementFrame)
|
||||||
{
|
{
|
||||||
if(dest->format->BytesPerPixel<3)
|
if(dest->format->BytesPerPixel<3)
|
||||||
return -1; //not enough depth
|
return -1; //not enough depth
|
||||||
|
|
||||||
//increasing frame numer
|
//increasing frame numer
|
||||||
int SIndex = curFrame++;
|
int SIndex = -1;
|
||||||
if(type!=-1)
|
if(incrementFrame)
|
||||||
{
|
{
|
||||||
if(SEntries[curFrame].group!=type) //rewind
|
SIndex = curFrame++;
|
||||||
|
if(type!=-1)
|
||||||
{
|
{
|
||||||
int j=-1; //first frame in displayed group
|
if(SEntries[curFrame].group!=type) //rewind
|
||||||
for(int g=0; g<SEntries.size(); ++g)
|
|
||||||
{
|
{
|
||||||
if(SEntries[g].group==type && j==-1)
|
int j=-1; //first frame in displayed group
|
||||||
|
for(int g=0; g<SEntries.size(); ++g)
|
||||||
{
|
{
|
||||||
j = g;
|
if(SEntries[g].group==type && j==-1)
|
||||||
break;
|
{
|
||||||
|
j = g;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if(curFrame!=-1)
|
||||||
|
curFrame = j;
|
||||||
}
|
}
|
||||||
if(curFrame!=-1)
|
}
|
||||||
curFrame = j;
|
else
|
||||||
|
{
|
||||||
|
if(curFrame>=frames)
|
||||||
|
curFrame = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(curFrame>=frames)
|
SIndex = curFrame;
|
||||||
curFrame = 0;
|
|
||||||
}
|
}
|
||||||
//frame number increased
|
//frame number increased
|
||||||
|
|
||||||
@ -781,8 +789,6 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
|
|||||||
TotalRowLength, // dlugosc przeczytanego segmentu
|
TotalRowLength, // dlugosc przeczytanego segmentu
|
||||||
NextSpriteOffset, RowAdd;
|
NextSpriteOffset, RowAdd;
|
||||||
unsigned char SegmentType, SegmentLength;
|
unsigned char SegmentType, SegmentLength;
|
||||||
|
|
||||||
std::string FTemp;
|
|
||||||
|
|
||||||
i=BaseOffset=SEntries[SIndex].offset;
|
i=BaseOffset=SEntries[SIndex].offset;
|
||||||
int prSize=readNormalNr(i,4,FDef);i+=4;
|
int prSize=readNormalNr(i,4,FDef);i+=4;
|
||||||
@ -819,8 +825,7 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
|
|||||||
{
|
{
|
||||||
for (int i=0;i<TopMargin;i++)
|
for (int i=0;i<TopMargin;i++)
|
||||||
{
|
{
|
||||||
for (int j=0;j<FullWidth+add;j++)
|
ftcp+=FullWidth+add;
|
||||||
ftcp++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RLEntries = new int[SpriteHeight];
|
RLEntries = new int[SpriteHeight];
|
||||||
@ -833,8 +838,7 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
|
|||||||
BaseOffset=BaseOffsetor+RLEntries[i];
|
BaseOffset=BaseOffsetor+RLEntries[i];
|
||||||
if (LeftMargin>0)
|
if (LeftMargin>0)
|
||||||
{
|
{
|
||||||
for (int j=0;j<LeftMargin;j++)
|
ftcp+=LeftMargin;
|
||||||
ftcp++;
|
|
||||||
}
|
}
|
||||||
TotalRowLength=0;
|
TotalRowLength=0;
|
||||||
do
|
do
|
||||||
@ -846,6 +850,7 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
|
|||||||
for (int k=0;k<=SegmentLength;k++)
|
for (int k=0;k<=SegmentLength;k++)
|
||||||
{
|
{
|
||||||
((char*)(hlps->pixels))[ftcp++]=FDef[BaseOffset+k];
|
((char*)(hlps->pixels))[ftcp++]=FDef[BaseOffset+k];
|
||||||
|
//putPixel(dest, ftcp++, palette[FDef[BaseOffset+k]], FDef[BaseOffset+k]);
|
||||||
if ((TotalRowLength+k+1)>=SpriteWidth)
|
if ((TotalRowLength+k+1)>=SpriteWidth)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -857,6 +862,7 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
|
|||||||
for (int k=0;k<SegmentLength+1;k++)
|
for (int k=0;k<SegmentLength+1;k++)
|
||||||
{
|
{
|
||||||
((char*)(hlps->pixels))[ftcp++]=SegmentType;
|
((char*)(hlps->pixels))[ftcp++]=SegmentType;
|
||||||
|
//putPixel(dest, ftcp++, palette[SegmentType], SegmentType);
|
||||||
}
|
}
|
||||||
TotalRowLength+=SegmentLength+1;
|
TotalRowLength+=SegmentLength+1;
|
||||||
}
|
}
|
||||||
@ -864,24 +870,18 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
|
|||||||
RowAdd=SpriteWidth-TotalRowLength;
|
RowAdd=SpriteWidth-TotalRowLength;
|
||||||
if (RightMargin>0)
|
if (RightMargin>0)
|
||||||
{
|
{
|
||||||
for (int j=0;j<RightMargin;j++)
|
ftcp+=RightMargin;
|
||||||
ftcp++;
|
|
||||||
}
|
}
|
||||||
if (add>0)
|
if (add>0)
|
||||||
{
|
{
|
||||||
for (int j=0;j<add+RowAdd;j++)
|
ftcp+=add+RowAdd;
|
||||||
ftcp++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete [] RLEntries;
|
delete [] RLEntries;
|
||||||
RLEntries = NULL;
|
RLEntries = NULL;
|
||||||
if (BottomMargin>0)
|
if (BottomMargin>0)
|
||||||
{
|
{
|
||||||
for (int i=0;i<BottomMargin;i++)
|
ftcp += BottomMargin * (FullWidth+add);
|
||||||
{
|
|
||||||
for (int j=0;j<FullWidth+add;j++)
|
|
||||||
ftcp++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!attacker)
|
if(!attacker)
|
||||||
@ -941,3 +941,14 @@ CCreatureAnimation::~CCreatureAnimation()
|
|||||||
if (RLEntries)
|
if (RLEntries)
|
||||||
delete [] RLEntries;
|
delete [] RLEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCreatureAnimation::putPixel(SDL_Surface * dest, const int & ftcp, const BMPPalette & color, const unsigned char & palc)
|
||||||
|
{
|
||||||
|
if(palc!=0)
|
||||||
|
{
|
||||||
|
Uint8 * p = (Uint8*)dest->pixels + ftcp*3 ;
|
||||||
|
p[0] = color.R;
|
||||||
|
p[1] = color.G;
|
||||||
|
p[2] = color.B;
|
||||||
|
}
|
||||||
|
}
|
@ -82,6 +82,7 @@ private:
|
|||||||
char id[2];
|
char id[2];
|
||||||
std::string defName, curDir;
|
std::string defName, curDir;
|
||||||
int readNormalNr (int pos, int bytCon, unsigned char * str=NULL, bool cyclic=false);
|
int readNormalNr (int pos, int bytCon, unsigned char * str=NULL, bool cyclic=false);
|
||||||
|
void putPixel(SDL_Surface * dest, const int & ftcp, const BMPPalette & color, const unsigned char & palc);
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
|
|
||||||
@ -96,7 +97,7 @@ public:
|
|||||||
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
|
||||||
|
|
||||||
int nextFrame(SDL_Surface * dest, int x, int y, bool attacker); //0 - success, any other - error //print next
|
int nextFrame(SDL_Surface * dest, int x, int y, bool attacker, bool incrementFrame = true); //0 - success, any other - error //print next
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //CCREATUREHANDLER_H
|
#endif //CCREATUREHANDLER_H
|
Loading…
x
Reference in New Issue
Block a user