]> git.localhorst.tv Git - l2e.git/commitdiff
moved monsters' attack choices to Monster
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 Aug 2012 19:32:27 +0000 (21:32 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 Aug 2012 19:32:27 +0000 (21:32 +0200)
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/Monster.h

index 720d70802c161b22a0cc451fd6db89d419713538..649470e894dd20e9db70c690a02d39cc938c15ac 100644 (file)
@@ -190,10 +190,9 @@ void BattleState::CalculateAttackOrder() {
        }
        for (vector<Monster>::size_type i(0), end(monsters.size()); i < end; ++i) {
                attackOrder.push_back(Order(i, true));
+               MonsterAt(i).GetAttackChoice() = AttackChoice(this);
        }
        std::sort(attackOrder.begin(), attackOrder.end(), OrderCompare(this));
-
-       monsterAttacks.resize(monsters.size(), AttackChoice(this));
 }
 
 void BattleState::NextAttack() {
@@ -218,7 +217,7 @@ bool BattleState::AttacksFinished() const {
 }
 
 void BattleState::CalculateDamage() {
-       AttackChoice &ac(CurrentAttack().isMonster ? monsterAttacks[CurrentAttack().index] : HeroAt(CurrentAttack().index).GetAttackChoice());
+       AttackChoice &ac(CurrentAttack().isMonster ? MonsterAt(CurrentAttack().index).GetAttackChoice() : HeroAt(CurrentAttack().index).GetAttackChoice());
        if (ac.GetType() == AttackChoice::DEFEND) return;
 
        if (CurrentAttack().isMonster) {
@@ -294,7 +293,7 @@ Uint16 BattleState::CalculateDamage(const Stats &attacker, const Stats &defender
 
 void BattleState::ApplyDamage() {
        if (attackCursor < 0) return;
-       AttackChoice &ac(CurrentAttack().isMonster ? monsterAttacks[CurrentAttack().index] : HeroAt(CurrentAttack().index).GetAttackChoice());
+       AttackChoice &ac(CurrentAttack().isMonster ? MonsterAt(CurrentAttack().index).GetAttackChoice() : HeroAt(CurrentAttack().index).GetAttackChoice());
        TargetSelection &ts(ac.Selection());
        if (ts.TargetsEnemies()) {
                for (int i(0); i < MaxMonsters(); ++i) {
@@ -319,7 +318,7 @@ void BattleState::ApplyDamage() {
 
 AttackChoice &BattleState::CurrentAttackAttackChoice() {
        if (CurrentAttack().isMonster) {
-               return monsterAttacks[CurrentAttack().index];
+               return MonsterAt(CurrentAttack().index).GetAttackChoice();
        } else {
                return HeroAt(CurrentAttack().index).GetAttackChoice();
        }
@@ -328,11 +327,13 @@ AttackChoice &BattleState::CurrentAttackAttackChoice() {
 void BattleState::ClearAllAttacks() {
        attackCursor = -1;
        activeHero = -1;
-       for (int i(0); i < numHeroes; ++i) {
-               heroes[i].GetAttackChoice() = AttackChoice(this);
+       for (int i(0); i < NumHeroes(); ++i) {
+               HeroAt(i).GetAttackChoice() = AttackChoice(this);
+       }
+       for (int i(0); i < MaxMonsters(); ++i) {
+               MonsterAt(i).GetAttackChoice() = AttackChoice(this);
        }
        attackOrder.clear();
-       monsterAttacks.clear();
 }
 
 
index a64ea0e3306baf9f90431c00ed23dd8771de467a..daf2c49124a7432c9b5847f81699d35601df63e5 100644 (file)
@@ -107,8 +107,8 @@ public:
        const geometry::Point<int> &HeroTagPositionAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroTagPositions[index]; }
 
        bool HasChosenAttackType() const { return ActiveHero().GetAttackChoice().GetType() != AttackChoice::UNDECIDED; }
-       AttackChoice &MonsterAttackChoiceAt(int index) { assert(index >= 0 && index < MaxMonsters()); return monsterAttacks[index]; }
-       const AttackChoice &MonsterAttackChoiceAt(int index) const { assert(index >= 0 && index < MaxMonsters()); return monsterAttacks[index]; }
+       AttackChoice &MonsterAttackChoiceAt(int index) { assert(index >= 0 && index < MaxMonsters()); return monsters[index].GetAttackChoice(); }
+       const AttackChoice &MonsterAttackChoiceAt(int index) const { assert(index >= 0 && index < MaxMonsters()); return monsters[index].GetAttackChoice(); }
        bool AttackSelectionDone() const { return activeHero >= numHeroes; }
 
        int NumHeroes() const { return numHeroes; }
@@ -172,7 +172,6 @@ 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::Item *> itemMenu;
index 0891a2d246c5f4451518e1312ba990317a5cdcf1..232da8fae99bd9f705229bc5684400eb0a49b78d 100644 (file)
@@ -8,6 +8,7 @@
 #ifndef BATTLE_MONSTER_H_
 #define BATTLE_MONSTER_H_
 
+#include "AttackChoice.h"
 #include "Stats.h"
 #include "../graphics/Animation.h"
 
@@ -76,6 +77,9 @@ public:
        void SetAttackAnimation(const graphics::Animation *a) { attackAnimation = a; }
        void SetSpellAnimation(const graphics::Animation *a) { spellAnimation = a; }
 
+       AttackChoice &GetAttackChoice() { return attackChoice; }
+       const AttackChoice &GetAttackChoice() const { return attackChoice; }
+
 private:
        const char *name;
        graphics::Sprite *sprite;
@@ -89,6 +93,8 @@ private:
 
        graphics::AnimationRunner animation;
 
+       AttackChoice attackChoice;
+
        Uint16 maxHealth, health;
        Uint16 maxMana, mana;