X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FPerformAttacks.cpp;h=238849b3f5da06638e04925fe5311d246e6a7783;hb=d2f44bfe5d159647431cee8ab29898bd3618d980;hp=498014a551d68b8fd81494989a8de44cc558a350;hpb=00b557a47e47d9410730d47d436f6158a3fb79f5;p=l2e.git diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp index 498014a..238849b 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,39 +61,36 @@ 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(); + AddNumberAnimations(battle->MonsterAttackChoiceAt(battle->CurrentAttack().index).Selection()); } 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()]); - } else { - numberPosition.push_back( - battle->HeroesPositions()[ac.Selection().SingleSelection()]); - } + AddNumberAnimations(ac.Selection()); break; case AttackChoice::MAGIC: titleBarText = ac.GetSpell()->Name(); @@ -132,6 +130,34 @@ void PerformAttacks::HandleEvents(const Input &input) { } } +void PerformAttacks::AddNumberAnimations(const TargetSelection &ts) { + if (ts.TargetsEnemies()) { + for (int i(0); i < battle->MaxMonsters(); ++i) { + if (ts.IsBad(i)) { + numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite)); + numberPosition.push_back( + battle->MonsterPositions()[i]); + } else if (ts.IsGood(i)) { + numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().greenNumberSprite)); + numberPosition.push_back( + battle->MonsterPositions()[i]); + } + } + } else { + for (int i(0); i < battle->NumHeroes(); ++i) { + if (ts.IsBad(i)) { + numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite)); + numberPosition.push_back( + battle->HeroesPositions()[i]); + } else if (ts.IsGood(i)) { + numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().greenNumberSprite)); + numberPosition.push_back( + battle->HeroesPositions()[i]); + } + } + } +} + void PerformAttacks::CheckAnimations() { if (targetAnimation && targetAnimationTimer.JustHit()) { targetAnimation->Start(*this); @@ -175,18 +201,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 +240,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)) {