1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* support for RETURN_AFTER_STRIKE feature

This commit is contained in:
mateuszb 2009-09-16 10:59:56 +00:00
parent ba25f5c807
commit 80b5126cf5
3 changed files with 29 additions and 21 deletions

View File

@ -609,7 +609,6 @@ void CBattleAttack::nextFrame()
if(owner->creAnims[stackID]->getFrame() == 0)
{
const CStack * aStack = LOCPLINT->cb->battleGetStackByID(stackID, false); //attacking stack
if(shooting)
{
// TODO: I see that we enter this function twice with
@ -618,24 +617,24 @@ void CBattleAttack::nextFrame()
// that is fixed. Once done, we can get rid of
// sh
if (sh == -1)
sh = CGI->soundh->playSound(aStack->creature->sounds.shoot);
sh = CGI->soundh->playSound(attackingStack->creature->sounds.shoot);
owner->creAnims[stackID]->setType(group);
}
else
{
// TODO: see comment above
if (sh == -1)
sh = CGI->soundh->playSound(aStack->creature->sounds.attack);
sh = CGI->soundh->playSound(attackingStack->creature->sounds.attack);
static std::map<int, int> dirToType = boost::assign::map_list_of (0, 11)(1, 11)(2, 12)(3, 13)(4, 13)(5, 12);
int type; //dependent on attack direction
if(aStack->hasFeatureOfType(StackFeature::DOUBLE_WIDE))
if(attackingStack->hasFeatureOfType(StackFeature::DOUBLE_WIDE))
{
type = dirToType[ BattleInfo::mutualPosition(aStack->position + posShiftDueToDist, dest) ]; //attack direction
type = dirToType[ BattleInfo::mutualPosition(attackingStackPosBeforeReturn + posShiftDueToDist, dest) ]; //attack direction
}
else //else for if(aStack->hasFeatureOfType(StackFeature::DOUBLE_WIDE))
{
type = BattleInfo::mutualPosition(aStack->position, dest);
type = BattleInfo::mutualPosition(attackingStackPosBeforeReturn, dest);
}
owner->creAnims[stackID]->setType(type);
}
@ -657,6 +656,8 @@ CBattleAttack::CBattleAttack(CBattleInterface * _owner, int _stackID, int _dest)
: CBattleStackAnimation(_owner, _stackID), sh(-1), dest(_dest)
{
attackedStack = LOCPLINT->cb->battleGetStackByPos(_dest, false);
attackingStack = LOCPLINT->cb->battleGetStackByID(_stackID, false);
attackingStackPosBeforeReturn = attackingStack->position;
}
////melee attack
@ -671,9 +672,7 @@ bool CMeleeAttack::init()
// return false;
//}
const CStack * aStack = LOCPLINT->cb->battleGetStackByID(stackID, false); //attacking stack
if(!aStack || owner->creAnims[stackID]->getType() == 5)
if(!attackingStack || owner->creAnims[stackID]->getType() == 5)
{
endAnim();
@ -681,32 +680,32 @@ bool CMeleeAttack::init()
}
int reversedShift = 0; //shift of attacking stack's position due to reversing
if(aStack->attackerOwned)
if(attackingStack->attackerOwned)
{
if(aStack->hasFeatureOfType(StackFeature::DOUBLE_WIDE) && BattleInfo::mutualPosition(aStack->position, dest) == -1)
if(attackingStack->hasFeatureOfType(StackFeature::DOUBLE_WIDE) && BattleInfo::mutualPosition(attackingStackPosBeforeReturn, dest) == -1)
{
if(BattleInfo::mutualPosition(aStack->position + (aStack->attackerOwned ? -1 : 1), dest) >= 0) //if reversing stack will make its position adjacent to dest
if(BattleInfo::mutualPosition(attackingStackPosBeforeReturn + (attackingStack->attackerOwned ? -1 : 1), dest) >= 0) //if reversing stack will make its position adjacent to dest
{
reversedShift = (aStack->attackerOwned ? -1 : 1);
reversedShift = (attackingStack->attackerOwned ? -1 : 1);
}
}
}
else //if(astack->attackerOwned)
{
if(aStack->hasFeatureOfType(StackFeature::DOUBLE_WIDE) && BattleInfo::mutualPosition(aStack->position, dest) == -1)
if(attackingStack->hasFeatureOfType(StackFeature::DOUBLE_WIDE) && BattleInfo::mutualPosition(attackingStackPosBeforeReturn, dest) == -1)
{
if(BattleInfo::mutualPosition(aStack->position + (aStack->attackerOwned ? -1 : 1), dest) >= 0) //if reversing stack will make its position adjacent to dest
if(BattleInfo::mutualPosition(attackingStackPosBeforeReturn + (attackingStack->attackerOwned ? -1 : 1), dest) >= 0) //if reversing stack will make its position adjacent to dest
{
reversedShift = (aStack->attackerOwned ? -1 : 1);
reversedShift = (attackingStack->attackerOwned ? -1 : 1);
}
}
}
//reversing stack if necessary
if(isToReverse(aStack->position, dest, owner->creDir[stackID], attackedStack->hasFeatureOfType(StackFeature::DOUBLE_WIDE), owner->creDir[attackedStack->ID]))
if(isToReverse(attackingStackPosBeforeReturn, dest, owner->creDir[stackID], attackedStack->hasFeatureOfType(StackFeature::DOUBLE_WIDE), owner->creDir[attackedStack->ID]))
{
owner->addNewAnim(new CReverseAnim(owner, stackID, aStack->position, true));
owner->addNewAnim(new CReverseAnim(owner, stackID, attackingStackPosBeforeReturn, true));
return false;
}
//reversed
@ -717,14 +716,14 @@ bool CMeleeAttack::init()
static const int mutPosToGroup[] = {11, 11, 12, 13, 13, 12};
int mutPos = BattleInfo::mutualPosition(aStack->position + reversedShift, dest);
int mutPos = BattleInfo::mutualPosition(attackingStackPosBeforeReturn + reversedShift, dest);
switch(mutPos) //attack direction
{
case 0: case 1: case 2: case 3: case 4: case 5:
group = mutPosToGroup[mutPos];
break;
default:
tlog1<<"Critical Error! Wrong dest in stackAttacking! dest: "<<dest<<" attacking stack pos: "<<aStack->position<<" reversed shift: "<<reversedShift<<std::endl;
tlog1<<"Critical Error! Wrong dest in stackAttacking! dest: "<<dest<<" attacking stack pos: "<<attackingStackPosBeforeReturn<<" reversed shift: "<<reversedShift<<std::endl;
}
return true;
@ -762,7 +761,7 @@ bool CShootingAnim::init()
if( !CBattleAttack::checkInitialConditions() )
return false;
const CStack * shooter = LOCPLINT->cb->battleGetStackByID(stackID, false);
const CStack * shooter = attackingStack;
if(!shooter || owner->creAnims[stackID]->getType() == 5)
{

View File

@ -164,6 +164,8 @@ protected:
int group; //if shooting is true, print this animation group
int sh; // temporary sound handler
const CStack * attackedStack;
const CStack * attackingStack;
int attackingStackPosBeforeReturn; //for stacks with return_after_strike feature
public:
void nextFrame();

View File

@ -2444,6 +2444,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
case 6: //walk or attack
{
sendAndApply(&StartAction(ba)); //start movement and attack
int startingPos = gs->curB->getStack(ba.stackNumber)->position;
int distance = moveStack(ba.stackNumber, ba.destinationTile);
CStack *curStack = gs->curB->getStack(ba.stackNumber),
*stackAtEnd = gs->curB->getStackT(ba.additionalInfo);
@ -2526,6 +2527,12 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
prepareAttack(bat, curStack, stackAtEnd, 0);
sendAndApply(&bat);
}
//return
if(curStack->hasFeatureOfType(StackFeature::RETURN_AFTER_STRIKE))
{
moveStack(ba.stackNumber, startingPos);
}
sendAndApply(&EndAction());
break;
}