]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/states/PerformAttacks.cpp
reduced title bar time
[l2e.git] / src / battle / states / PerformAttacks.cpp
index 2a8f3a53b697a4aecb3e5270c4e7c65d4be69ff9..36b7b1630d41477fa23ba7055ed629ee39078a8c 100644 (file)
@@ -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,20 +61,24 @@ 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:
@@ -85,15 +90,7 @@ void PerformAttacks::HandleEvents(const Input &input) {
                                        targetAnimation = hero.MeleeAnimation();
                                }
                                moveAnimation = hero.AttackAnimation();
-
-                               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();
@@ -124,7 +121,7 @@ void PerformAttacks::HandleEvents(const Input &input) {
                }
        }
 
-       if (titleBarText) titleBarTimer = GraphicsTimers().StartCountdown(1500);
+       if (titleBarText) titleBarTimer = GraphicsTimers().StartCountdown(850);
        if (moveAnimation) moveAnimation->Start(*this);
        if (targetAnimation) {
                targetAnimationTimer = GraphicsTimers().StartCountdown(150);
@@ -133,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);
@@ -176,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) {
 
@@ -227,8 +240,7 @@ void PerformAttacks::RenderNumbers(SDL_Surface *screen, const Vector<int> &offse
 
 void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector<int> &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<Point<int> > &positions(ts.TargetsHeroes() ? battle->HeroesPositions() : battle->MonsterPositions());
        for (vector<Point<int> >::size_type i(0), end(positions.size()); i < end; ++i) {
                if (ts.IsSelected(i)) {