From: Daniel Karbach Date: Tue, 21 Aug 2012 19:32:27 +0000 (+0200) Subject: moved monsters' attack choices to Monster X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=8967f42789c619df6e5874f5c6a9ea4b6b6c33db;p=l2e.git moved monsters' attack choices to Monster --- diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index 720d708..649470e 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -190,10 +190,9 @@ void BattleState::CalculateAttackOrder() { } for (vector::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(); } diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index a64ea0e..daf2c49 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -107,8 +107,8 @@ public: const geometry::Point &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 > monsterPositions; std::vector > heroesPositions; std::vector monsters; - std::vector monsterAttacks; std::vector attackOrder; Hero heroes[4]; graphics::Menu itemMenu; diff --git a/src/battle/Monster.h b/src/battle/Monster.h index 0891a2d..232da8f 100644 --- a/src/battle/Monster.h +++ b/src/battle/Monster.h @@ -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;