1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

New pack - BattleEffectTrigger for various one-shot effects with animation

This commit is contained in:
DjWarmonger
2011-10-08 13:02:58 +00:00
parent f4fc77ccb8
commit 0903d6037c
14 changed files with 167 additions and 70 deletions

View File

@@ -2631,47 +2631,6 @@ void CBattleInterface::stackRemoved(int stackID)
void CBattleInterface::stackActivated(const CStack * stack) //TODO: check it all before game state is changed due to abilities
{
//don't show animation when no HP is regenerated
if (stack->firstHPleft != stack->MaxHealth())
{
if( stack->hasBonusOfType(Bonus::HP_REGENERATION) || stack->hasBonusOfType(Bonus::FULL_HP_REGENERATION, 1))
{
displayEffect(74, stack->position);
CCS->soundh->playSound(soundBase::REGENER);
}
if( stack->hasBonusOfType(Bonus::FULL_HP_REGENERATION, 0))
{
displayEffect(74, stack->position);
CCS->soundh->playSound(soundBase::REGENER);
}
}
if(stack->hasBonusOfType(Bonus::MANA_DRAIN))
{
CGHeroInstance * enemy = NULL; //probably could be smarter and not duplicated
if (defendingHero)
if (defendingHero->myHero->tempOwner != stack->owner)
enemy = const_cast<CGHeroInstance *>(defendingHero->myHero);
if (attackingHero)
if (attackingHero->myHero->tempOwner != stack->owner)
enemy = const_cast<CGHeroInstance *>(attackingHero->myHero);
if (enemy)
{
ui32 manaDrained = stack->valOfBonuses(Bonus::MANA_DRAIN);
amin (manaDrained, enemy->mana);
if (manaDrained)
{
displayEffect(77, stack->position);
CCS->soundh->playSound(soundBase::MANADRAI);
}
}
}
if(stack->hasBonusOfType(Bonus::POISON))
{
displayEffect(67, stack->position);
CCS->soundh->playSound(soundBase::POISON);
}
//givenCommand = NULL;
stackToActivate = stack;
if(pendingAnims.size() == 0)
@@ -3546,6 +3505,38 @@ void CBattleInterface::displayEffect(ui32 effect, int destTile)
addNewAnim(new CSpellEffectAnim(this, effect, destTile));
}
void CBattleInterface::battleTriggerEffect(const BattleTriggerEffect & bte)
{
const CStack * stack = curInt->cb->battleGetStackByID(bte.stackID);
//don't show animation when no HP is regenerated
switch (bte.effect)
{
case Bonus::HP_REGENERATION:
if( stack->hasBonusOfType(Bonus::HP_REGENERATION) || stack->hasBonusOfType(Bonus::FULL_HP_REGENERATION, 1))
{
displayEffect(74, stack->position);
CCS->soundh->playSound(soundBase::REGENER);
}
if( stack->hasBonusOfType(Bonus::FULL_HP_REGENERATION, 0))
{
displayEffect(74, stack->position);
CCS->soundh->playSound(soundBase::REGENER);
}
break;
case Bonus::MANA_DRAIN:
displayEffect(77, stack->position);
CCS->soundh->playSound(soundBase::MANADRAI);
break;
case Bonus::POISON:
displayEffect(67, stack->position);
CCS->soundh->playSound(soundBase::POISON);
break;
default:
return;
}
//waitForAnims(); //fixme: freezes game :?
}
void CBattleInterface::setAnimSpeed(int set)
{
curInt->sysOpts.animSpeed = set;

View File

@@ -37,6 +37,7 @@ class CGTownInstance;
struct CatapultAttack;
class CBattleInterface;
struct CatapultProjectileInfo;
struct BattleTriggerEffect;
/// Small struct which contains information about the id of the attacked stack, the damage dealt,...
struct SStackAttackedInfo
@@ -569,6 +570,7 @@ public:
void battleStacksEffectsSet(const SetStackEffect & sse); //called when a specific effect is set to stacks
void castThisSpell(int spellID); //called when player has chosen a spell from spellbook
void displayEffect(ui32 effect, int destTile); //displays effect of a spell on the battlefield; affected: true - attacker. false - defender
void battleTriggerEffect(const BattleTriggerEffect & bte);
void setBattleCursor(const int myNumber); //really complex and messy
void endAction(const BattleAction* action);
void hideQueue();

View File

@@ -801,6 +801,10 @@ void CPlayerInterface::battleStacksEffectsSet( const SetStackEffect & sse )
boost::unique_lock<boost::recursive_mutex> un(*pim);
battleInt->battleStacksEffectsSet(sse);
}
void CPlayerInterface::battleTriggerEffect (const BattleTriggerEffect & bte)
{
battleInt->battleTriggerEffect(bte);
}
void CPlayerInterface::battleStacksAttacked(const std::vector<BattleStackAttacked> & bsa)
{
if(LOCPLINT != this)

View File

@@ -224,6 +224,7 @@ public:
void battleStackMoved(const CStack * stack, std::vector<THex> dest, int distance) OVERRIDE;
void battleSpellCast(const BattleSpellCast *sc) OVERRIDE;
void battleStacksEffectsSet(const SetStackEffect & sse) OVERRIDE; //called when a specific effect is set to stacks
void battleTriggerEffect(const BattleTriggerEffect & bte) OVERRIDE; //various one-shot effect
void battleStacksAttacked(const std::vector<BattleStackAttacked> & bsa) OVERRIDE;
void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side) OVERRIDE; //called by engine when battle starts; side=0 - left, side=1 - right
void battleStacksHealedRes(const std::vector<std::pair<ui32, ui32> > & healedStacks, bool lifeDrain, bool tentHeal, si32 lifeDrainFrom) OVERRIDE; //called when stacks are healed / resurrected

View File

@@ -587,6 +587,11 @@ void BattleSetActiveStack::applyCl( CClient *cl )
boost::thread( boost::bind(&CClient::waitForMoveAndSend, cl, playerToCall) );
}
void BattleTriggerEffect::applyCl(CClient * cl)
{
BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleTriggerEffect, *this);
}
void BattleResult::applyFirstCl( CClient *cl )
{
BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleEnd,this);