]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/BattleState.h
apply damage indicated by attack selection
[l2e.git] / src / battle / BattleState.h
index 77e2b5dbdfa214db81bcd6a8f1313b18e05ce49f..45c43f9c70a27387e20cc65b48fb9a39033fc0d9 100644 (file)
@@ -19,8 +19,8 @@
 #include "../app/State.h"
 #include "../geometry/Point.h"
 #include "../geometry/Vector.h"
+#include "../graphics/Animation.h"
 #include "../graphics/Menu.h"
-#include "../graphics/SimpleAnimation.h"
 
 #include <vector>
 #include <SDL.h>
@@ -55,6 +55,7 @@ public:
        , moveMenu(res->moveIcons)
        , numHeroes(0)
        , activeHero(-1)
+       , attackCursor(-1)
        , ranAway(false) { }
 
 public:
@@ -97,15 +98,13 @@ public:
        Monster &MonsterAt(int index) { return monsters[index]; }
        const Monster &MonsterAt(int index) const { return monsters[index]; }
 
-       graphics::SimpleAnimation &HeroAnimationAt(int index) { return heroAnimations[index]; }
-       const graphics::SimpleAnimation &HeroAnimationAt(int index) const { return heroAnimations[index]; }
-
        const HeroTag &HeroTagAt(int index) const { return heroTags[index]; }
        const geometry::Point<int> &HeroTagPositionAt(int index) const { return heroTagPositions[index]; }
 
        bool HasChosenAttackType() const { return attackChoices[activeHero].GetType() != AttackChoice::UNDECIDED; }
        AttackChoice &ActiveHeroAttackChoice() { return attackChoices[activeHero]; }
        const AttackChoice &ActiveHeroAttackChoice() const { return attackChoices[activeHero]; }
+       AttackChoice &AttackChoiceAt(int index) { return attackChoices[index]; }
        const AttackChoice &AttackChoiceAt(int index) const { return attackChoices[index]; }
        bool AttackSelectionDone() const { return activeHero >= numHeroes; }
 
@@ -119,6 +118,20 @@ public:
        bool HeroPositionOccupied(int index) const { return index >= 0 && index < numHeroes; }
 
        void SetRunaway() { ranAway = true; }
+
+       struct Order {
+               Order(int index, bool isMonster)
+               : index(index), isMonster(isMonster) { }
+               int index;
+               bool isMonster;
+       };
+
+       void CalculateAttackOrder();
+       void NextAttack();
+       bool AttacksFinished() const { return attackCursor >= int(attackOrder.size()); }
+       void CalculateDamage();
+       void ApplyDamage();
+       const Order &CurrentAttack() const { return attackOrder[attackCursor]; };
        void ClearAllAttacks();
 
 public:
@@ -127,8 +140,8 @@ public:
                                (screen->w - background->w) / 2,
                                (screen->h - background->h) / 2);
        }
-       int BackgroundWidth() const { return background->w; }
-       int BackgroundHeight() const { return background->h; }
+       int Width() const { return background->w; }
+       int Height() const { return background->h; }
 
        void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
        void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
@@ -152,8 +165,9 @@ private:
        std::vector<geometry::Point<int> > monsterPositions;
        std::vector<geometry::Point<int> > heroesPositions;
        std::vector<Monster> monsters;
+       std::vector<AttackChoice> monsterAttacks;
+       std::vector<Order> attackOrder;
        Hero heroes[4];
-       graphics::SimpleAnimation heroAnimations[4];
        graphics::Menu<const common::Spell *> spellMenus[4];
        graphics::Menu<const common::Item *> itemMenu;
        graphics::Menu<const common::Item *> ikariMenus[4];
@@ -164,6 +178,7 @@ private:
        AttackChoice attackChoices[4];
        int numHeroes;
        int activeHero;
+       int attackCursor;
        bool ranAway;
 
 };