mirror of
https://github.com/vcmi/vcmi.git
synced 2025-05-29 22:57:49 +02:00
* magic arrow flight animation (full hit animation will be later as it should be implemented via support for AC format)
* fixed bug with dying unit * minor things
This commit is contained in:
parent
9d099e8c54
commit
9a8e009862
@ -387,7 +387,7 @@ void CBattleInterface::show(SDL_Surface * to)
|
|||||||
{
|
{
|
||||||
for(int v=0; v<stackAliveByHex[b].size(); ++v)
|
for(int v=0; v<stackAliveByHex[b].size(); ++v)
|
||||||
{
|
{
|
||||||
creAnims[stackAliveByHex[b][v]]->nextFrame(to, creAnims[stackAliveByHex[b][v]]->pos.x, creAnims[stackAliveByHex[b][v]]->pos.y, creDir[stackAliveByHex[b][v]], (animCount%(4/animSpeed)==0) && creAnims[stackAliveByHex[b][v]]->getType()!=0 && creAnims[stackAliveByHex[b][v]]->getType()!=20 && creAnims[stackAliveByHex[b][v]]->getType()!=21, stackAliveByHex[b][v]==activeStack); //increment always when moving, never if stack died
|
creAnims[stackAliveByHex[b][v]]->nextFrame(to, creAnims[stackAliveByHex[b][v]]->pos.x, creAnims[stackAliveByHex[b][v]]->pos.y, creDir[stackAliveByHex[b][v]], (animCount%(4/animSpeed)==0) && creAnims[stackAliveByHex[b][v]]->getType()!=0 && creAnims[stackAliveByHex[b][v]]->getType()!=5 && creAnims[stackAliveByHex[b][v]]->getType()!=20 && creAnims[stackAliveByHex[b][v]]->getType()!=21, stackAliveByHex[b][v]==activeStack); //increment always when moving, never if stack died
|
||||||
//printing amount
|
//printing amount
|
||||||
if(stacks[stackAliveByHex[b][v]].amount > 0) //don't print if stack is not alive
|
if(stacks[stackAliveByHex[b][v]].amount > 0) //don't print if stack is not alive
|
||||||
{
|
{
|
||||||
@ -660,7 +660,7 @@ void CBattleInterface::stackRemoved(CStack stack)
|
|||||||
creAnims.erase(stack.ID);
|
creAnims.erase(stack.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBattleInterface::stackKilled(int ID, int dmg, int killed, int IDby, bool byShooting)
|
void CBattleInterface::stackKilled(int ID, int dmg, int killed, int IDby, bool byShooting, ui32 effects)
|
||||||
{
|
{
|
||||||
if(creAnims[ID]->getType() != 2)
|
if(creAnims[ID]->getType() != 2)
|
||||||
{
|
{
|
||||||
@ -691,17 +691,22 @@ void CBattleInterface::stackKilled(int ID, int dmg, int killed, int IDby, bool b
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
creAnims[ID]->setType(5); //death
|
creAnims[ID]->setType(5); //death
|
||||||
int firstFrame = creAnims[ID]->getFrame();
|
//int firstFrame = creAnims[ID]->getFrame();
|
||||||
for(int i=0; creAnims[ID]->getFrame() != creAnims[ID]->framesInGroup(5) + firstFrame - 1; ++i)
|
int increments = 0;
|
||||||
|
while(increments < creAnims[ID]->framesInGroup(5)-1)
|
||||||
{
|
{
|
||||||
if((animCount%(4/animSpeed))==0)
|
if((animCount%(4/animSpeed))==0)
|
||||||
|
{
|
||||||
creAnims[ID]->incrementFrame();
|
creAnims[ID]->incrementFrame();
|
||||||
|
++increments;
|
||||||
|
}
|
||||||
show();
|
show();
|
||||||
CSDL_Ext::update();
|
CSDL_Ext::update();
|
||||||
SDL_framerateDelay(LOCPLINT->mainFPSmng);
|
SDL_framerateDelay(LOCPLINT->mainFPSmng);
|
||||||
}
|
}
|
||||||
|
|
||||||
printConsoleAttacked(ID, dmg, killed, IDby);
|
if(effects == 0)
|
||||||
|
printConsoleAttacked(ID, dmg, killed, IDby);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBattleInterface::stackActivated(int number)
|
void CBattleInterface::stackActivated(int number)
|
||||||
@ -827,7 +832,7 @@ void CBattleInterface::stackMoved(int number, int destHex, bool endMoving)
|
|||||||
creAnims[number]->pos.y = coords.second;
|
creAnims[number]->pos.y = coords.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBattleInterface::stackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting)
|
void CBattleInterface::stackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting, ui32 effects)
|
||||||
{
|
{
|
||||||
while(creAnims[ID]->getType() != 2 || (attackingInfo && attackingInfo->IDby == IDby))
|
while(creAnims[ID]->getType() != 2 || (attackingInfo && attackingInfo->IDby == IDby))
|
||||||
{
|
{
|
||||||
@ -871,7 +876,8 @@ void CBattleInterface::stackIsAttacked(int ID, int dmg, int killed, int IDby, bo
|
|||||||
}
|
}
|
||||||
creAnims[ID]->setType(2);
|
creAnims[ID]->setType(2);
|
||||||
|
|
||||||
printConsoleAttacked(ID, dmg, killed, IDby);
|
if(effects == 0)
|
||||||
|
printConsoleAttacked(ID, dmg, killed, IDby);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBattleInterface::stackAttacking(int ID, int dest)
|
void CBattleInterface::stackAttacking(int ID, int dest)
|
||||||
@ -1191,6 +1197,60 @@ void CBattleInterface::battleFinished(const BattleResult& br)
|
|||||||
resWindow->activate();
|
resWindow->activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CBattleInterface::spellCasted(SpellCasted * sc)
|
||||||
|
{
|
||||||
|
switch(sc->id)
|
||||||
|
{
|
||||||
|
case 15: //magic arrow
|
||||||
|
{
|
||||||
|
//initial variables
|
||||||
|
std::vector< std::string > anims;
|
||||||
|
anims.push_back("C20SPX0.DEF"); anims.push_back("C20SPX1.DEF"); anims.push_back("C20SPX2.DEF"); anims.push_back("C20SPX3.DEF"); anims.push_back("C20SPX4.DEF");
|
||||||
|
std::string animToDisplay;
|
||||||
|
std::pair<int, int> srccoord = sc->side ? std::make_pair(770, 60) : std::make_pair(30, 60);
|
||||||
|
std::pair<int, int> destcoord = CBattleHex::getXYUnitAnim(sc->tile, !sc->side, LOCPLINT->cb->battleGetStackByPos(sc->tile)->creature); //position attacked by arrow
|
||||||
|
destcoord.first += 250; destcoord.second += 240;
|
||||||
|
|
||||||
|
//animation angle
|
||||||
|
float angle = atan2(float(destcoord.first - srccoord.first), float(destcoord.second - srccoord.second));
|
||||||
|
|
||||||
|
//choosign animation by angle
|
||||||
|
if(angle > 1.50)
|
||||||
|
animToDisplay = anims[0];
|
||||||
|
else if(angle > 1.20)
|
||||||
|
animToDisplay = anims[1];
|
||||||
|
else if(angle > 0.90)
|
||||||
|
animToDisplay = anims[2];
|
||||||
|
else if(angle > 0.60)
|
||||||
|
animToDisplay = anims[3];
|
||||||
|
else
|
||||||
|
animToDisplay = anims[4];
|
||||||
|
|
||||||
|
//displaying animation
|
||||||
|
int steps = sqrt((float)((destcoord.first - srccoord.first)*(destcoord.first - srccoord.first) + (destcoord.second - srccoord.second) * (destcoord.second - srccoord.second))) / 40;
|
||||||
|
if(steps <= 0)
|
||||||
|
steps = 1;
|
||||||
|
|
||||||
|
CDefHandler * animDef = CDefHandler::giveDef(animToDisplay);
|
||||||
|
|
||||||
|
int dx = (destcoord.first - srccoord.first - animDef->ourImages[0].bitmap->w)/steps, dy = (destcoord.second - srccoord.second - animDef->ourImages[0].bitmap->h)/steps;
|
||||||
|
|
||||||
|
for(int g=0; g<steps; ++g)
|
||||||
|
{
|
||||||
|
show();
|
||||||
|
SDL_Rect & srcr = animDef->ourImages[g%animDef->ourImages.size()].bitmap->clip_rect;
|
||||||
|
SDL_Rect dstr = genRect(srcr.h, srcr.w, srccoord.first + g*dx, srccoord.second + g*dy);
|
||||||
|
SDL_BlitSurface(animDef->ourImages[g%animDef->ourImages.size()].bitmap, &srcr, screen, &dstr);
|
||||||
|
CSDL_Ext::update();
|
||||||
|
SDL_framerateDelay(LOCPLINT->mainFPSmng);
|
||||||
|
}
|
||||||
|
|
||||||
|
int b=0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CBattleInterface::castThisSpell(int spellID)
|
void CBattleInterface::castThisSpell(int spellID)
|
||||||
{
|
{
|
||||||
BattleAction * ba = new BattleAction;
|
BattleAction * ba = new BattleAction;
|
||||||
|
@ -12,6 +12,7 @@ class AdventureMapButton;
|
|||||||
class CHighlightableButton;
|
class CHighlightableButton;
|
||||||
class CHighlightableButtonsGroup;
|
class CHighlightableButtonsGroup;
|
||||||
struct BattleResult;
|
struct BattleResult;
|
||||||
|
struct SpellCasted;
|
||||||
template <typename T> struct CondSh;
|
template <typename T> struct CondSh;
|
||||||
|
|
||||||
class CBattleInterface;
|
class CBattleInterface;
|
||||||
@ -209,15 +210,16 @@ public:
|
|||||||
//call-ins
|
//call-ins
|
||||||
void newStack(CStack stack); //new stack appeared on battlefield
|
void newStack(CStack stack); //new stack appeared on battlefield
|
||||||
void stackRemoved(CStack stack); //stack disappeared from batlefiled
|
void stackRemoved(CStack stack); //stack disappeared from batlefiled
|
||||||
void stackKilled(int ID, int dmg, int killed, int IDby, bool byShooting); //stack has been killed (but corpses remain)
|
void stackKilled(int ID, int dmg, int killed, int IDby, bool byShooting, ui32 effects = 0); //stack has been killed (but corpses remain); effects - additional optional spell effect (AC format)
|
||||||
void stackActivated(int number); //active stack has been changed
|
void stackActivated(int number); //active stack has been changed
|
||||||
void stackMoved(int number, int destHex, bool endMoving); //stack with id number moved to destHex
|
void stackMoved(int number, int destHex, bool endMoving); //stack with id number moved to destHex
|
||||||
void stackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting); //called when stack id attacked by stack with id IDby
|
void stackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting, ui32 effects = 0); //called when stack id attacked by stack with id IDby; effects - additional optional spell effect (AC format)
|
||||||
void stackAttacking(int ID, int dest); //called when stack with id ID is attacking something on hex dest
|
void stackAttacking(int ID, int dest); //called when stack with id ID is attacking something on hex dest
|
||||||
void newRound(int number); //caled when round is ended; number is the number of round
|
void newRound(int number); //caled when round is ended; number is the number of round
|
||||||
void hexLclicked(int whichOne); //hex only call-in
|
void hexLclicked(int whichOne); //hex only call-in
|
||||||
void stackIsShooting(int ID, int dest); //called when stack with id ID is shooting to hex dest
|
void stackIsShooting(int ID, int dest); //called when stack with id ID is shooting to hex dest
|
||||||
void battleFinished(const BattleResult& br); //called when battle is finished - battleresult window should be printed
|
void battleFinished(const BattleResult& br); //called when battle is finished - battleresult window should be printed
|
||||||
|
void spellCasted(SpellCasted * sc); //called when a hero casts a spell
|
||||||
void castThisSpell(int spellID); //called when player has chosen a spell from spellbook
|
void castThisSpell(int spellID); //called when player has chosen a spell from spellbook
|
||||||
|
|
||||||
friend class CBattleHex;
|
friend class CBattleHex;
|
||||||
|
@ -89,7 +89,6 @@ void CConsoleHandler::setColor(int level)
|
|||||||
int CConsoleHandler::run()
|
int CConsoleHandler::run()
|
||||||
{
|
{
|
||||||
char buffer[500];
|
char buffer[500];
|
||||||
std::string readed;
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
std::cin.getline(buffer, 500);
|
std::cin.getline(buffer, 500);
|
||||||
|
@ -2137,10 +2137,15 @@ void CPlayerInterface::battleStackMoved(int ID, int dest)
|
|||||||
void CPlayerInterface::battleSpellCasted(SpellCasted *sc)
|
void CPlayerInterface::battleSpellCasted(SpellCasted *sc)
|
||||||
{
|
{
|
||||||
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
||||||
|
battleInt->spellCasted(sc);
|
||||||
}
|
}
|
||||||
void CPlayerInterface::battleStackAttacked(BattleStackAttacked * bsa)
|
void CPlayerInterface::battleStackAttacked(BattleStackAttacked * bsa)
|
||||||
{
|
{
|
||||||
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
boost::unique_lock<boost::recursive_mutex> un(*pim);
|
||||||
|
if(bsa->killed())
|
||||||
|
battleInt->stackKilled(bsa->stackAttacked, bsa->damageAmount, bsa->killedAmount, -1, false, bsa->effect);
|
||||||
|
else
|
||||||
|
battleInt->stackIsAttacked(bsa->stackAttacked, bsa->damageAmount, bsa->killedAmount, -1, false, bsa->effect);
|
||||||
}
|
}
|
||||||
void CPlayerInterface::battleAttack(BattleAttack *ba)
|
void CPlayerInterface::battleAttack(BattleAttack *ba)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user