mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
* animations in battles seem to approximately work
This commit is contained in:
parent
670a408fab
commit
f3a1cd4ae5
@ -84,6 +84,7 @@ void CBattleAnimation::endAnim()
|
|||||||
it->first = NULL;
|
it->first = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBattleAnimation::isEarliest(bool perStackConcurrency)
|
bool CBattleAnimation::isEarliest(bool perStackConcurrency)
|
||||||
@ -96,7 +97,9 @@ bool CBattleAnimation::isEarliest(bool perStackConcurrency)
|
|||||||
if(perStackConcurrency && stAnim && thAnim && stAnim->stackID != thAnim->stackID)
|
if(perStackConcurrency && stAnim && thAnim && stAnim->stackID != thAnim->stackID)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(dynamic_cast<CReverseAnim *>(stAnim) && stAnim->stackID == thAnim->stackID)
|
CReverseAnim * revAnim = dynamic_cast<CReverseAnim *>(stAnim);
|
||||||
|
|
||||||
|
if(revAnim && stAnim->stackID == thAnim->stackID && revAnim->priority)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(it->first)
|
if(it->first)
|
||||||
@ -126,6 +129,9 @@ bool CReverseAnim::init()
|
|||||||
|
|
||||||
return false; //there is no such creature
|
return false; //there is no such creature
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!priority && !isEarliest(false))
|
||||||
|
return false;
|
||||||
|
|
||||||
owner->creAnims[stackID]->setType(8);
|
owner->creAnims[stackID]->setType(8);
|
||||||
|
|
||||||
@ -187,8 +193,8 @@ void CReverseAnim::endAnim()
|
|||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CReverseAnim::CReverseAnim(CBattleInterface * _owner, int stack, int dest)
|
CReverseAnim::CReverseAnim(CBattleInterface * _owner, int stack, int dest, bool _priority)
|
||||||
: CBattleStackAnimation(_owner, stack), partOfAnim(1), hex(dest), secondPartSetup(false)
|
: CBattleStackAnimation(_owner, stack), partOfAnim(1), hex(dest), secondPartSetup(false), priority(_priority)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,6 +215,8 @@ bool CDefenceAnim::init()
|
|||||||
{
|
{
|
||||||
if(dynamic_cast<CDefenceAnim *>(it->first))
|
if(dynamic_cast<CDefenceAnim *>(it->first))
|
||||||
continue;
|
continue;
|
||||||
|
if(dynamic_cast<CBattleAttack *>(it->first))
|
||||||
|
continue;
|
||||||
|
|
||||||
if(dynamic_cast<CReverseAnim *>(it->first))
|
if(dynamic_cast<CReverseAnim *>(it->first))
|
||||||
return false;
|
return false;
|
||||||
@ -226,12 +234,12 @@ bool CDefenceAnim::init()
|
|||||||
//reverse unit if necessary
|
//reverse unit if necessary
|
||||||
if((attacked->position > attacker->position) && owner->creDir[stackID] == true)
|
if((attacked->position > attacker->position) && owner->creDir[stackID] == true)
|
||||||
{
|
{
|
||||||
owner->pendingAnims.push_back(std::make_pair(new CReverseAnim(owner, stackID, attacked->position), false));
|
owner->pendingAnims.push_back(std::make_pair(new CReverseAnim(owner, stackID, attacked->position, true), false));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if ((attacked->position < attacker->position) && owner->creDir[stackID] == false)
|
else if ((attacked->position < attacker->position) && owner->creDir[stackID] == false)
|
||||||
{
|
{
|
||||||
owner->pendingAnims.push_back(std::make_pair(new CReverseAnim(owner, stackID, attacked->position), false));
|
owner->pendingAnims.push_back(std::make_pair(new CReverseAnim(owner, stackID, attacked->position, true), false));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//unit reversed
|
//unit reversed
|
||||||
@ -303,16 +311,16 @@ void CDefenceAnim::endAnim()
|
|||||||
const CStack * attacker = LOCPLINT->cb->battleGetStackByID(IDby, false);
|
const CStack * attacker = LOCPLINT->cb->battleGetStackByID(IDby, false);
|
||||||
const CStack * attacked = LOCPLINT->cb->battleGetStackByID(stackID, false);
|
const CStack * attacked = LOCPLINT->cb->battleGetStackByID(stackID, false);
|
||||||
|
|
||||||
//reverse unit if necessary
|
////reverse unit if necessary
|
||||||
if((attacked->position > attacker->position) && owner->creDir[stackID] == false)
|
//if((attacked->position > attacker->position) && owner->creDir[stackID] == false)
|
||||||
{
|
//{
|
||||||
owner->pendingAnims.push_back(std::make_pair(new CReverseAnim(owner, stackID, attacked->position), false));
|
// owner->pendingAnims.push_back(std::make_pair(new CReverseAnim(owner, stackID, attacked->position, true), false));
|
||||||
}
|
//}
|
||||||
else if ((attacked->position < attacker->position) && owner->creDir[stackID] == true)
|
//else if ((attacked->position < attacker->position) && owner->creDir[stackID] == true)
|
||||||
{
|
//{
|
||||||
owner->pendingAnims.push_back(std::make_pair(new CReverseAnim(owner, stackID, attacked->position), false));
|
// owner->pendingAnims.push_back(std::make_pair(new CReverseAnim(owner, stackID, attacked->position, true), false));
|
||||||
}
|
//}
|
||||||
//unit reversed
|
////unit reversed
|
||||||
|
|
||||||
CBattleAnimation::endAnim();
|
CBattleAnimation::endAnim();
|
||||||
|
|
||||||
@ -355,12 +363,12 @@ bool CBattleStackMoved::init()
|
|||||||
//reverse unit if necessary
|
//reverse unit if necessary
|
||||||
if((begPosition.first > endPosition.first) && owner->creDir[stackID] == true)
|
if((begPosition.first > endPosition.first) && owner->creDir[stackID] == true)
|
||||||
{
|
{
|
||||||
owner->pendingAnims.push_back(std::make_pair(new CReverseAnim(owner, stackID, curStackPos), false));
|
owner->pendingAnims.push_back(std::make_pair(new CReverseAnim(owner, stackID, curStackPos, true), false));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if ((begPosition.first < endPosition.first) && owner->creDir[stackID] == false)
|
else if ((begPosition.first < endPosition.first) && owner->creDir[stackID] == false)
|
||||||
{
|
{
|
||||||
owner->pendingAnims.push_back(std::make_pair(new CReverseAnim(owner, stackID, curStackPos), false));
|
owner->pendingAnims.push_back(std::make_pair(new CReverseAnim(owner, stackID, curStackPos, true), false));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,11 +564,6 @@ void CBattleMoveEnd::endAnim()
|
|||||||
CGI->curh->show();
|
CGI->curh->show();
|
||||||
CGI->soundh->stopSound(owner->moveSh);
|
CGI->soundh->stopSound(owner->moveSh);
|
||||||
|
|
||||||
if(movedStack && owner->creDir[stackID] != bool(movedStack->attackerOwned))
|
|
||||||
{
|
|
||||||
owner->pendingAnims.push_back(std::make_pair(new CReverseAnim(owner, stackID, destinationTile), false));
|
|
||||||
}
|
|
||||||
|
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -611,72 +614,6 @@ void CBattleAttack::nextFrame()
|
|||||||
}
|
}
|
||||||
else if(owner->creAnims[stackID]->onLastFrameInGroup())
|
else if(owner->creAnims[stackID]->onLastFrameInGroup())
|
||||||
{
|
{
|
||||||
const CStack* aStackp = LOCPLINT->cb->battleGetStackByID(stackID, false); //attacking stack
|
|
||||||
if(aStackp == NULL || owner->creAnims[stackID]->getType() == 5)
|
|
||||||
return;
|
|
||||||
|
|
||||||
bool reverse = false;
|
|
||||||
if(aStackp->attackerOwned)
|
|
||||||
{
|
|
||||||
if(aStackp->hasFeatureOfType(StackFeature::DOUBLE_WIDE))
|
|
||||||
{
|
|
||||||
switch(BattleInfo::mutualPosition(aStackp->position, dest)) //attack direction
|
|
||||||
{
|
|
||||||
case 5:
|
|
||||||
reverse = true;
|
|
||||||
break;
|
|
||||||
case -1:
|
|
||||||
if(posShiftDueToDist) //if reversing stack will make its position adjacent to dest
|
|
||||||
{
|
|
||||||
reverse = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else //else for if(aStackp->hasFeatureOfType(StackFeature::DOUBLE_WIDE))
|
|
||||||
{
|
|
||||||
switch(BattleInfo::mutualPosition(aStackp->position, dest)) //attack direction
|
|
||||||
{
|
|
||||||
case 0: case 4: case 5:
|
|
||||||
reverse = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else //if(aStackp->attackerOwned)
|
|
||||||
{
|
|
||||||
if(aStackp->hasFeatureOfType(StackFeature::DOUBLE_WIDE))
|
|
||||||
{
|
|
||||||
switch(BattleInfo::mutualPosition(aStackp->position, dest)) //attack direction
|
|
||||||
{
|
|
||||||
case 2:
|
|
||||||
reverse = true;
|
|
||||||
break;
|
|
||||||
case -1:
|
|
||||||
if(posShiftDueToDist) //if reversing stack will make its position adjacent to dest
|
|
||||||
{
|
|
||||||
reverse = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else //else for if(aStackp->hasFeatureOfType(StackFeature::DOUBLE_WIDE))
|
|
||||||
{
|
|
||||||
switch(BattleInfo::mutualPosition(aStackp->position, dest)) //attack direction
|
|
||||||
{
|
|
||||||
case 1: case 2: case 3:
|
|
||||||
reverse = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(reverse)
|
|
||||||
{
|
|
||||||
reversing = true;
|
|
||||||
owner->pendingAnims.push_back(std::make_pair(new CReverseAnim(owner, stackID, aStackp->position), false));
|
|
||||||
}
|
|
||||||
|
|
||||||
owner->creAnims[stackID]->setType(2);
|
owner->creAnims[stackID]->setType(2);
|
||||||
endAnim();
|
endAnim();
|
||||||
return; //execution of endAnim deletes this !!!
|
return; //execution of endAnim deletes this !!!
|
||||||
@ -785,14 +722,13 @@ bool CMeleeAttack::init()
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(reverse)
|
if( reverse && owner->creDir[stackID] == bool(aStack->attackerOwned) )
|
||||||
{
|
{
|
||||||
owner->pendingAnims.push_back(std::make_pair(new CReverseAnim(owner, stackID, aStack->position), false));
|
owner->pendingAnims.push_back(std::make_pair(new CReverseAnim(owner, stackID, aStack->position, true), false));
|
||||||
}
|
}
|
||||||
//reversed
|
//reversed
|
||||||
|
|
||||||
IDby = LOCPLINT->cb->battleGetStackByPos(dest, false)->ID;
|
IDby = LOCPLINT->cb->battleGetStackByPos(dest, false)->ID;
|
||||||
reversing = false;
|
|
||||||
shooting = false;
|
shooting = false;
|
||||||
posShiftDueToDist = reversedShift;
|
posShiftDueToDist = reversedShift;
|
||||||
|
|
||||||
@ -907,7 +843,6 @@ bool CShootingAnim::init()
|
|||||||
|
|
||||||
//attack aniamtion
|
//attack aniamtion
|
||||||
IDby = LOCPLINT->cb->battleGetStackByPos(dest, false)->ID;
|
IDby = LOCPLINT->cb->battleGetStackByPos(dest, false)->ID;
|
||||||
reversing = false;
|
|
||||||
posShiftDueToDist = 0;
|
posShiftDueToDist = 0;
|
||||||
shooting = true;
|
shooting = true;
|
||||||
|
|
||||||
@ -927,7 +862,7 @@ void CShootingAnim::nextFrame()
|
|||||||
{
|
{
|
||||||
CBattleMoveStart * anim = dynamic_cast<CBattleMoveStart *>(it->first);
|
CBattleMoveStart * anim = dynamic_cast<CBattleMoveStart *>(it->first);
|
||||||
CReverseAnim * anim2 = dynamic_cast<CReverseAnim *>(it->first);
|
CReverseAnim * anim2 = dynamic_cast<CReverseAnim *>(it->first);
|
||||||
if( (anim && anim->stackID == stackID) || (anim2 && anim2->stackID == stackID ) )
|
if( (anim && anim->stackID == stackID) || (anim2 && anim2->stackID == stackID && anim2->priority ) )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1406,6 +1341,7 @@ void CBattleInterface::show(SDL_Surface * to)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//delete anims
|
//delete anims
|
||||||
|
int preSize = pendingAnims.size();
|
||||||
for(std::list<std::pair<CBattleAnimation *, bool> >::iterator it = pendingAnims.begin(); it != pendingAnims.end(); ++it)
|
for(std::list<std::pair<CBattleAnimation *, bool> >::iterator it = pendingAnims.begin(); it != pendingAnims.end(); ++it)
|
||||||
{
|
{
|
||||||
if(it->first == NULL)
|
if(it->first == NULL)
|
||||||
@ -1416,6 +1352,20 @@ void CBattleInterface::show(SDL_Surface * to)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(preSize > 0 && pendingAnims.size() == 0)
|
||||||
|
{
|
||||||
|
//restoring good directions of stacks
|
||||||
|
std::map<int, CStack> stacks = LOCPLINT->cb->battleGetStacks();
|
||||||
|
|
||||||
|
for(std::map<int, CStack>::const_iterator it = stacks.begin(); it != stacks.end(); ++it)
|
||||||
|
{
|
||||||
|
if(creDir[it->second.ID] != bool(it->second.attackerOwned))
|
||||||
|
{
|
||||||
|
pendingAnims.push_back(std::make_pair(new CReverseAnim(this, it->second.ID, it->second.position, false), false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for(int b=0; b<BFIELD_SIZE; ++b) //showing dead stacks
|
for(int b=0; b<BFIELD_SIZE; ++b) //showing dead stacks
|
||||||
{
|
{
|
||||||
for(size_t v=0; v<stackDeadByHex[b].size(); ++v)
|
for(size_t v=0; v<stackDeadByHex[b].size(); ++v)
|
||||||
@ -2608,7 +2558,7 @@ void CBattleInterface::showAliveStack(int ID, const std::map<int, CStack> & stac
|
|||||||
int affectingSpeed = settings.animSpeed;
|
int affectingSpeed = settings.animSpeed;
|
||||||
if(animType == 1 || animType == 2) //standing stacks should not stand faster :)
|
if(animType == 1 || animType == 2) //standing stacks should not stand faster :)
|
||||||
affectingSpeed = 2;
|
affectingSpeed = 2;
|
||||||
if(animType == 3 || animType == 11 || animType == 12 || animType == 13) //defend & attack should be slower
|
if(animType == 3 || animType == 7 || animType == 8 || animType == 9 || animType == 10 || animType == 11 || animType == 12 || animType == 13) //defend & attack should be slower
|
||||||
affectingSpeed = 1;
|
affectingSpeed = 1;
|
||||||
bool incrementFrame = (animCount%(4/affectingSpeed)==0) && animType!=5 && animType!=20 && animType!=2;
|
bool incrementFrame = (animCount%(4/affectingSpeed)==0) && animType!=5 && animType!=20 && animType!=2;
|
||||||
|
|
||||||
|
@ -87,11 +87,12 @@ private:
|
|||||||
bool secondPartSetup;
|
bool secondPartSetup;
|
||||||
int hex;
|
int hex;
|
||||||
public:
|
public:
|
||||||
|
bool priority; //true - high, false - low
|
||||||
bool init();
|
bool init();
|
||||||
void nextFrame();
|
void nextFrame();
|
||||||
void endAnim();
|
void endAnim();
|
||||||
|
|
||||||
CReverseAnim(CBattleInterface * _owner, int stack, int dest);
|
CReverseAnim(CBattleInterface * _owner, int stack, int dest, bool _priority);
|
||||||
};
|
};
|
||||||
|
|
||||||
class CDefenceAnim : public CBattleStackAnimation
|
class CDefenceAnim : public CBattleStackAnimation
|
||||||
@ -158,7 +159,6 @@ class CBattleAttack : public CBattleStackAnimation
|
|||||||
protected:
|
protected:
|
||||||
int IDby; //attacked stack
|
int IDby; //attacked stack
|
||||||
int dest; //atacked hex
|
int dest; //atacked hex
|
||||||
bool reversing;
|
|
||||||
int posShiftDueToDist;
|
int posShiftDueToDist;
|
||||||
bool shooting;
|
bool shooting;
|
||||||
int group; //if shooting is true, print this animation group
|
int group; //if shooting is true, print this animation group
|
||||||
|
@ -1100,6 +1100,7 @@ void CPlayerInterface::actionFinished(const BattleAction* action)
|
|||||||
{
|
{
|
||||||
battleInt->pendingAnims.push_back(std::make_pair(new CBattleMoveEnd(battleInt, action->stackNumber, action->destinationTile), false));
|
battleInt->pendingAnims.push_back(std::make_pair(new CBattleMoveEnd(battleInt, action->stackNumber, action->destinationTile), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BattleAction CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack
|
BattleAction CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack
|
||||||
|
Loading…
Reference in New Issue
Block a user