X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FPerformAttacks.cpp;h=10fb8bb11294c6f0f517d1def1efd528cbd86cbb;hb=d4609ba1798d82cce128b5985d60cb212b760246;hp=498014a551d68b8fd81494989a8de44cc558a350;hpb=00b557a47e47d9410730d47d436f6158a3fb79f5;p=l2e.git diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp index 498014a..10fb8bb 100644 --- a/src/battle/states/PerformAttacks.cpp +++ b/src/battle/states/PerformAttacks.cpp @@ -33,12 +33,13 @@ namespace battle { void PerformAttacks::EnterState(Application &c, SDL_Surface *screen) { ctrl = &c; - battle->WriteOrder(order); + battle->CalculateAttackOrder(); numberAnimation.reserve(battle->MaxMonsters() > battle->NumHeroes() + 1 ? battle->MaxMonsters() : battle->NumHeroes() + 1); numberPosition.reserve(numberAnimation.size()); } void PerformAttacks::ExitState(Application &c, SDL_Surface *screen) { + battle->ClearAllAttacks(); ctrl = 0; } @@ -60,38 +61,52 @@ void PerformAttacks::HandleEvents(const Input &input) { CheckAnimations(); if (HasAnimationsRunning()) return; ResetAnimation(); - AdvanceCursor(); - if (Finished()) { - battle->ClearAllAttacks(); + battle->ApplyDamage(); + battle->NextAttack(); + if (battle->AttacksFinished()) { ctrl->PopState(); return; } - if (order[cursor].isMonster) { - const Monster &monster(battle->MonsterAt(order[cursor].index)); + battle->CalculateDamage(); + + if (battle->CurrentAttack().isMonster) { + Monster &monster(battle->MonsterAt(battle->CurrentAttack().index)); titleBarText = monster.Name(); - moveAnimation = 0; + moveAnimation = monster.AttackAnimation(); + targetAnimation = monster.MeleeAnimation(); + // TODO: add number animations } else { - Hero &hero(battle->HeroAt(order[cursor].index)); - const AttackChoice &ac(battle->AttackChoiceAt(order[cursor].index)); + Hero &hero(battle->HeroAt(battle->CurrentAttack().index)); + const AttackChoice &ac(battle->AttackChoiceAt(battle->CurrentAttack().index)); switch (ac.GetType()) { case AttackChoice::SWORD: if (hero.HasWeapon()) { titleBarText = hero.Weapon()->Name(); + targetAnimation = hero.Weapon()->AttackAnimation(); } else { titleBarText = "Melee attack!"; + targetAnimation = hero.MeleeAnimation(); } moveAnimation = hero.AttackAnimation(); - targetAnimation = hero.MeleeAnimation(); - numberAnimation.push_back(NumberAnimation(15, battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite)); if (ac.Selection().TargetsEnemies()) { - numberPosition.push_back( - battle->MonsterPositions()[ac.Selection().SingleSelection()]); + for (int i(0); i < battle->MaxMonsters(); ++i) { + if (ac.Selection().IsSelected(i)) { + numberAnimation.push_back(NumberAnimation(ac.Selection().GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite)); + numberPosition.push_back( + battle->MonsterPositions()[i]); + } + } } else { - numberPosition.push_back( - battle->HeroesPositions()[ac.Selection().SingleSelection()]); + for (int i(0); i < battle->NumHeroes(); ++i) { + if (ac.Selection().IsSelected(i)) { + numberAnimation.push_back(NumberAnimation(ac.Selection().GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite)); + numberPosition.push_back( + battle->HeroesPositions()[i]); + } + } } break; case AttackChoice::MAGIC: @@ -175,18 +190,6 @@ void PerformAttacks::ResetAnimation() { numberPosition.clear(); } -void PerformAttacks::AdvanceCursor() { - ++cursor; - while (cursor < int(order.size())) { - if (order[cursor].isMonster) { - if (battle->MonsterAt(order[cursor].index).Health() > 0) break; - } else { - if (battle->HeroAt(order[cursor].index).Health() > 0) break; - } - ++cursor; - } -} - void PerformAttacks::UpdateWorld(float deltaT) { @@ -226,8 +229,7 @@ void PerformAttacks::RenderNumbers(SDL_Surface *screen, const Vector &offse void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector &offset) const { if (!targetAnimation || !targetAnimation->Running()) return; - if (order[cursor].isMonster) return; // no monsters for now - const TargetSelection &ts(battle->AttackChoiceAt(order[cursor].index).Selection()); + const TargetSelection &ts(battle->CurrentAttackAttackChoice().Selection()); const vector > &positions(ts.TargetsHeroes() ? battle->HeroesPositions() : battle->MonsterPositions()); for (vector >::size_type i(0), end(positions.size()); i < end; ++i) { if (ts.IsSelected(i)) {