mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
* support for RETURN_AFTER_STRIKE feature
This commit is contained in:
parent
ba25f5c807
commit
80b5126cf5
@ -609,7 +609,6 @@ void CBattleAttack::nextFrame()
|
|||||||
|
|
||||||
if(owner->creAnims[stackID]->getFrame() == 0)
|
if(owner->creAnims[stackID]->getFrame() == 0)
|
||||||
{
|
{
|
||||||
const CStack * aStack = LOCPLINT->cb->battleGetStackByID(stackID, false); //attacking stack
|
|
||||||
if(shooting)
|
if(shooting)
|
||||||
{
|
{
|
||||||
// TODO: I see that we enter this function twice with
|
// 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
|
// that is fixed. Once done, we can get rid of
|
||||||
// sh
|
// sh
|
||||||
if (sh == -1)
|
if (sh == -1)
|
||||||
sh = CGI->soundh->playSound(aStack->creature->sounds.shoot);
|
sh = CGI->soundh->playSound(attackingStack->creature->sounds.shoot);
|
||||||
owner->creAnims[stackID]->setType(group);
|
owner->creAnims[stackID]->setType(group);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO: see comment above
|
// TODO: see comment above
|
||||||
if (sh == -1)
|
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);
|
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
|
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))
|
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);
|
owner->creAnims[stackID]->setType(type);
|
||||||
}
|
}
|
||||||
@ -657,6 +656,8 @@ CBattleAttack::CBattleAttack(CBattleInterface * _owner, int _stackID, int _dest)
|
|||||||
: CBattleStackAnimation(_owner, _stackID), sh(-1), dest(_dest)
|
: CBattleStackAnimation(_owner, _stackID), sh(-1), dest(_dest)
|
||||||
{
|
{
|
||||||
attackedStack = LOCPLINT->cb->battleGetStackByPos(_dest, false);
|
attackedStack = LOCPLINT->cb->battleGetStackByPos(_dest, false);
|
||||||
|
attackingStack = LOCPLINT->cb->battleGetStackByID(_stackID, false);
|
||||||
|
attackingStackPosBeforeReturn = attackingStack->position;
|
||||||
}
|
}
|
||||||
|
|
||||||
////melee attack
|
////melee attack
|
||||||
@ -671,9 +672,7 @@ bool CMeleeAttack::init()
|
|||||||
// return false;
|
// return false;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
const CStack * aStack = LOCPLINT->cb->battleGetStackByID(stackID, false); //attacking stack
|
if(!attackingStack || owner->creAnims[stackID]->getType() == 5)
|
||||||
|
|
||||||
if(!aStack || owner->creAnims[stackID]->getType() == 5)
|
|
||||||
{
|
{
|
||||||
endAnim();
|
endAnim();
|
||||||
|
|
||||||
@ -681,32 +680,32 @@ bool CMeleeAttack::init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
int reversedShift = 0; //shift of attacking stack's position due to reversing
|
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)
|
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
|
//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;
|
return false;
|
||||||
}
|
}
|
||||||
//reversed
|
//reversed
|
||||||
@ -717,14 +716,14 @@ bool CMeleeAttack::init()
|
|||||||
|
|
||||||
static const int mutPosToGroup[] = {11, 11, 12, 13, 13, 12};
|
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
|
switch(mutPos) //attack direction
|
||||||
{
|
{
|
||||||
case 0: case 1: case 2: case 3: case 4: case 5:
|
case 0: case 1: case 2: case 3: case 4: case 5:
|
||||||
group = mutPosToGroup[mutPos];
|
group = mutPosToGroup[mutPos];
|
||||||
break;
|
break;
|
||||||
default:
|
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;
|
return true;
|
||||||
@ -762,7 +761,7 @@ bool CShootingAnim::init()
|
|||||||
if( !CBattleAttack::checkInitialConditions() )
|
if( !CBattleAttack::checkInitialConditions() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const CStack * shooter = LOCPLINT->cb->battleGetStackByID(stackID, false);
|
const CStack * shooter = attackingStack;
|
||||||
|
|
||||||
if(!shooter || owner->creAnims[stackID]->getType() == 5)
|
if(!shooter || owner->creAnims[stackID]->getType() == 5)
|
||||||
{
|
{
|
||||||
|
@ -164,6 +164,8 @@ protected:
|
|||||||
int group; //if shooting is true, print this animation group
|
int group; //if shooting is true, print this animation group
|
||||||
int sh; // temporary sound handler
|
int sh; // temporary sound handler
|
||||||
const CStack * attackedStack;
|
const CStack * attackedStack;
|
||||||
|
const CStack * attackingStack;
|
||||||
|
int attackingStackPosBeforeReturn; //for stacks with return_after_strike feature
|
||||||
public:
|
public:
|
||||||
void nextFrame();
|
void nextFrame();
|
||||||
|
|
||||||
|
@ -2444,6 +2444,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
|
|||||||
case 6: //walk or attack
|
case 6: //walk or attack
|
||||||
{
|
{
|
||||||
sendAndApply(&StartAction(ba)); //start movement and attack
|
sendAndApply(&StartAction(ba)); //start movement and attack
|
||||||
|
int startingPos = gs->curB->getStack(ba.stackNumber)->position;
|
||||||
int distance = moveStack(ba.stackNumber, ba.destinationTile);
|
int distance = moveStack(ba.stackNumber, ba.destinationTile);
|
||||||
CStack *curStack = gs->curB->getStack(ba.stackNumber),
|
CStack *curStack = gs->curB->getStack(ba.stackNumber),
|
||||||
*stackAtEnd = gs->curB->getStackT(ba.additionalInfo);
|
*stackAtEnd = gs->curB->getStackT(ba.additionalInfo);
|
||||||
@ -2526,6 +2527,12 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
|
|||||||
prepareAttack(bat, curStack, stackAtEnd, 0);
|
prepareAttack(bat, curStack, stackAtEnd, 0);
|
||||||
sendAndApply(&bat);
|
sendAndApply(&bat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//return
|
||||||
|
if(curStack->hasFeatureOfType(StackFeature::RETURN_AFTER_STRIKE))
|
||||||
|
{
|
||||||
|
moveStack(ba.stackNumber, startingPos);
|
||||||
|
}
|
||||||
sendAndApply(&EndAction());
|
sendAndApply(&EndAction());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user