]> git.localhorst.tv Git - l2e.git/commitdiff
moved monster's position to Monster
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 Aug 2012 20:24:24 +0000 (22:24 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 Aug 2012 20:24:24 +0000 (22:24 +0200)
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/Monster.h
src/battle/TargetSelection.cpp
src/battle/states/PerformAttacks.cpp
src/battle/states/SelectTarget.cpp

index aae4635be3687bf578533a925778cc20ef0e7f4b..fe1b309a3a65b36543de7d8585290f6503b9139f 100644 (file)
@@ -78,7 +78,6 @@ void BattleState::Resize(int w, int h) {
 
 
 void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
-       monstersLayout->CalculatePositions(background->w, background->h, monsterPositions);
        for (int i(0); i < 4; ++i) {
                heroes[i].Position() = heroesLayout->CalculatePosition(i, background->w, background->h);
                heroes[i].SpellMenu() = res->spellMenuPrototype;
@@ -89,6 +88,10 @@ void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
                smallHeroTags[i] = SmallHeroTag(this, i);
        }
 
+       for (int i(0); i < int(monsters.size()); ++i) {
+               monsters[i].Position() = monstersLayout->CalculatePosition(i, background->w, background->h);
+       }
+
        int tagHeight(attackTypeMenu.Height());
        int tagWidth(attackTypeMenu.Width() * 2 + attackTypeMenu.Width() / 2);
        int xOffset((Width() - 2 * tagWidth) / 2);
@@ -369,9 +372,9 @@ void BattleState::RenderMonsters(SDL_Surface *screen, const Vector<int> &offset)
        for (vector<Monster>::size_type i(0), end(monsters.size()); i < end; ++i) {
                if (MonsterPositionOccupied(i)) {
                        if (monsters[i].GetAnimation().Running()) {
-                               monsters[i].GetAnimation().DrawCenter(screen, monsterPositions[i] + offset);
+                               monsters[i].GetAnimation().DrawCenter(screen, monsters[i].Position() + offset);
                        } else {
-                               monsters[i].Sprite()->DrawCenter(screen, monsterPositions[i] + offset);
+                               monsters[i].Sprite()->DrawCenter(screen, monsters[i].Position() + offset);
                        }
                }
        }
index f5268dda931b1403745f6f15dc6709ddac5f6cf2..654e147d8ed60a677be4107f314dbc41783413aa 100644 (file)
@@ -109,7 +109,6 @@ public:
        int MaxHeroes() const { return 4; }
        int MaxMonsters() const { return monsters.size(); }
 
-       const std::vector<geometry::Point<int> > &MonsterPositions() const { return monsterPositions; }
        bool MonsterPositionOccupied(int index) { return index >= 0 && index < int(monsters.size()) && monsters[index].Health() > 0; }
        bool HeroPositionOccupied(int index) const { return index >= 0 && index < numHeroes; }
 
@@ -162,7 +161,6 @@ private:
        AttackTypeMenu attackTypeMenu;
        MoveMenu moveMenu;
        // TODO: combine all data about heros or monsters
-       std::vector<geometry::Point<int> > monsterPositions;
        std::vector<Monster> monsters;
        std::vector<Order> attackOrder;
        Hero heroes[4];
index 232da8fae99bd9f705229bc5684400eb0a49b78d..8338cb18e59f8e6836c0fb6c617e280ff9f74a2f 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "AttackChoice.h"
 #include "Stats.h"
+#include "../geometry/Point.h"
 #include "../graphics/Animation.h"
 
 #include <SDL.h>
@@ -61,6 +62,9 @@ public:
        const graphics::Animation *AttackAnimation() const { return attackAnimation; }
        const graphics::Animation *SpellAnimation() const { return spellAnimation; }
 
+       geometry::Point<int> &Position() { return position; }
+       const geometry::Point<int> &Position() const { return position; }
+
 // temporary setters until loader is implemented
 public:
        void SetName(const char *n) { name = n; }
@@ -93,6 +97,8 @@ private:
 
        graphics::AnimationRunner animation;
 
+       geometry::Point<int> position;
+
        AttackChoice attackChoice;
 
        Uint16 maxHealth, health;
index b24772d55937820732ad0b356f76ab5b13c55cf3..1906c2bb7960ac4b1804300c34d8d498fb3cf8fc 100644 (file)
@@ -13,7 +13,7 @@ namespace battle {
 
 TargetSelection::TargetSelection(BattleState *battle, bool multiple, bool atEnemy)
 : battle(battle)
-, selected(battle ? ((int)battle->MonsterPositions().size() > battle->NumHeroes() ? (int)battle->MonsterPositions().size() : battle->NumHeroes()) : 0, State())
+, selected(battle ? (battle->MaxMonsters() > battle->NumHeroes() ? battle->MaxMonsters() : battle->NumHeroes()) : 0, State())
 , selection(-1)
 , cursor(0)
 , multiple(multiple)
@@ -59,9 +59,9 @@ void TargetSelection::MoveUp() {
 
 void TargetSelection::MoveRight() {
        if (TargetsEnemies()) {
-               cursor = (cursor + 1) % battle->MonsterPositions().size();
+               cursor = (cursor + 1) % battle->MaxMonsters();
                while (!battle->MonsterPositionOccupied(cursor)) {
-                       cursor = (cursor + 1) % battle->MonsterPositions().size();
+                       cursor = (cursor + 1) % battle->MaxMonsters();
                }
        } else {
                cursor = (cursor + 1) % battle->NumHeroes();
@@ -81,7 +81,7 @@ void TargetSelection::MoveDown() {
 
 void TargetSelection::MoveLeft() {
        if (TargetsEnemies()) {
-               cursor = (cursor + battle->MonsterPositions().size() - 1) % battle->MonsterPositions().size();
+               cursor = (cursor + battle->MaxMonsters() - 1) % battle->MaxMonsters();
                FindNextEnemy();
        } else {
                cursor = (cursor + battle->NumHeroes() - 1) % battle->NumHeroes();
@@ -91,7 +91,7 @@ void TargetSelection::MoveLeft() {
 void TargetSelection::FindNextEnemy() {
        int start(cursor);
        while (!battle->MonsterPositionOccupied(cursor)) {
-               cursor = (cursor + battle->MonsterPositions().size() - 1) % battle->MonsterPositions().size();
+               cursor = (cursor + battle->MaxMonsters() - 1) % battle->MaxMonsters();
                if (cursor == start) break;
        }
 }
index acb8194746ee46a7bb675882f603a8038e054411..44831791d2c749695cc83716d099178c6f552f67 100644 (file)
@@ -145,11 +145,11 @@ void PerformAttacks::AddNumberAnimations(const TargetSelection &ts) {
                        if (ts.IsBad(i)) {
                                numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite));
                                numberPosition.push_back(
-                                               battle->MonsterPositions()[i]);
+                                               battle->MonsterAt(i).Position());
                        } else if (ts.IsGood(i)) {
                                numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().greenNumberSprite));
                                numberPosition.push_back(
-                                               battle->MonsterPositions()[i]);
+                                               battle->MonsterAt(i).Position());
                        }
                }
        } else {
@@ -251,9 +251,17 @@ void PerformAttacks::RenderNumbers(SDL_Surface *screen, const Vector<int> &offse
 void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
        if (!targetAnimation.Valid() || !targetAnimation.Running()) return;
        const TargetSelection &ts(battle->CurrentAttackAttackChoice().Selection());
-       for (vector<Point<int> >::size_type i(0), end(ts.TargetsHeroes() ? battle->NumHeroes() : battle->MaxMonsters()); i < end; ++i) {
-               if (ts.IsSelected(i)) {
-                       targetAnimation.DrawCenter(screen, (ts.TargetsHeroes() ? battle->HeroAt(i).Position() : battle->MonsterPositions()[i]) + offset);
+       if (ts.TargetsHeroes()) {
+               for (vector<Point<int> >::size_type i(0), end(battle->NumHeroes()); i < end; ++i) {
+                       if (ts.IsSelected(i)) {
+                               targetAnimation.DrawCenter(screen, battle->HeroAt(i).Position() + offset);
+                       }
+               }
+       } else {
+               for (vector<Point<int> >::size_type i(0), end(battle->MaxMonsters()); i < end; ++i) {
+                       if (ts.IsSelected(i)) {
+                               targetAnimation.DrawCenter(screen, battle->MonsterAt(i).Position() + offset);
+                       }
                }
        }
 }
index 25838571162f0aa45e58ff88012063ce0024ade6..591da6753972350cf1eb9f0f44041a8df2023368 100644 (file)
@@ -95,8 +95,8 @@ void SelectTarget::RenderCursors(SDL_Surface *screen, const geometry::Vector<int
        Vector<int> indicatorOffset(cursorOffset + Vector<int>(cursorIcon->Width() / 8, cursorIcon->Height() / -8));
        vector<Point<int> > positions;
        if (selection->TargetsEnemies()) {
-               for (vector<Point<int> >::const_iterator i(battle->MonsterPositions().begin()), end(battle->MonsterPositions().end()); i != end; ++i) {
-                       positions.push_back(*i);
+               for (int i(0), end(battle->MaxMonsters()); i < end; ++i) {
+                       positions.push_back(battle->MonsterAt(i).Position());
                }
        } else {
                for (int i(0), end(battle->NumHeroes()); i < end; ++i) {