]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/BattleState.h
added checks for vitory/defeat condition
[l2e.git] / src / battle / BattleState.h
index b491af862c99485c080c156836d3a2c9e7413b26..7d65c14a23d8a1d08890ac0d7c52a4512351287c 100644 (file)
@@ -19,6 +19,7 @@
 #include "../app/State.h"
 #include "../geometry/Point.h"
 #include "../geometry/Vector.h"
+#include "../graphics/Animation.h"
 #include "../graphics/Menu.h"
 
 #include <vector>
@@ -54,6 +55,7 @@ public:
        , moveMenu(res->moveIcons)
        , numHeroes(0)
        , activeHero(-1)
+       , attackCursor(-1)
        , ranAway(false) { }
 
 public:
@@ -102,6 +104,7 @@ public:
        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; }
 
@@ -115,16 +118,33 @@ 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();
 
+       bool Victory() const;
+       bool Defeat() const;
+
 public:
        geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
                return geometry::Vector<int>(
                                (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);
@@ -148,6 +168,8 @@ 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::Menu<const common::Spell *> spellMenus[4];
        graphics::Menu<const common::Item *> itemMenu;
@@ -159,6 +181,7 @@ private:
        AttackChoice attackChoices[4];
        int numHeroes;
        int activeHero;
+       int attackCursor;
        bool ranAway;
 
 };