]> git.localhorst.tv Git - l2e.git/commitdiff
moved hero position to Hero
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 Aug 2012 20:15:08 +0000 (22:15 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 Aug 2012 20:15:08 +0000 (22:15 +0200)
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/Hero.h
src/battle/PartyLayout.h
src/battle/states/PerformAttacks.cpp

index 649470e894dd20e9db70c690a02d39cc938c15ac..aae4635be3687bf578533a925778cc20ef0e7f4b 100644 (file)
@@ -79,8 +79,8 @@ void BattleState::Resize(int w, int h) {
 
 void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
        monstersLayout->CalculatePositions(background->w, background->h, monsterPositions);
-       heroesLayout->CalculatePositions(background->w, background->h, heroesPositions);
        for (int i(0); i < 4; ++i) {
+               heroes[i].Position() = heroesLayout->CalculatePosition(i, background->w, background->h);
                heroes[i].SpellMenu() = res->spellMenuPrototype;
                heroes[i].UpdateSpellMenu();
                heroes[i].IkariMenu() = res->ikariMenuPrototype;
@@ -381,10 +381,10 @@ void BattleState::RenderHeroes(SDL_Surface *screen, const Vector<int> &offset) {
        assert(screen);
        for (int i(0); i < numHeroes; ++i) {
                if (heroes[i].GetAnimation().Running()) {
-                       heroes[i].GetAnimation().DrawCenter(screen, heroesPositions[i] + offset);
+                       heroes[i].GetAnimation().DrawCenter(screen, heroes[i].Position() + offset);
                } else {
                        int row(heroes[i].Health() > 0 ? 0 : 2);
-                       heroes[i].Sprite()->DrawCenter(screen, heroesPositions[i] + offset, 1, row);
+                       heroes[i].Sprite()->DrawCenter(screen, heroes[i].Position() + offset, 1, row);
                }
        }
 }
index 4a07f8e7396ab1fe8c41f2bc0b6e8ac973a39b9b..f5268dda931b1403745f6f15dc6709ddac5f6cf2 100644 (file)
@@ -111,7 +111,6 @@ public:
 
        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; }
-       const std::vector<geometry::Point<int> > &HeroesPositions() const { return heroesPositions; }
        bool HeroPositionOccupied(int index) const { return index >= 0 && index < numHeroes; }
 
        void SetRunaway() { ranAway = true; }
@@ -164,7 +163,6 @@ private:
        MoveMenu moveMenu;
        // TODO: combine all data about heros or monsters
        std::vector<geometry::Point<int> > monsterPositions;
-       std::vector<geometry::Point<int> > heroesPositions;
        std::vector<Monster> monsters;
        std::vector<Order> attackOrder;
        Hero heroes[4];
index 44d0b4d0c3372dc9a4f320965c4cf3f06b757b72..74449026f93efe706ac469222d895e6194808517 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "AttackChoice.h"
 #include "Stats.h"
+#include "../geometry/Point.h"
 #include "../graphics/Animation.h"
 #include "../graphics/Menu.h"
 
@@ -87,6 +88,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; }
+
        graphics::Menu<const common::Spell *> &SpellMenu() { return spellMenu; }
        const graphics::Menu<const common::Spell *> &SpellMenu() const { return spellMenu; }
        graphics::Menu<const common::Item *> &IkariMenu() { return ikariMenu; }
@@ -143,6 +147,8 @@ private:
 
        graphics::AnimationRunner animation;
 
+       geometry::Point<int> position;
+
        graphics::Menu<const common::Spell *> spellMenu;
        graphics::Menu<const common::Item *> ikariMenu;
 
index d16f2bdd6eb678212b60e1c098cdbdc3b2777f87..684413964d096b77b352f5e31840d97acc47c65e 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "../geometry/Point.h"
 
+#include <cassert>
 #include <vector>
 #include <SDL.h>
 
@@ -33,6 +34,14 @@ public:
                                        ));
                }
        }
+       template<class U>
+       geometry::Point<U> CalculatePosition(std::vector<geometry::Point<Uint8> >::size_type index, U width, U height) const {
+               assert(index >= 0 && index < positions.size());
+               return geometry::Point<U>(
+                               positions[index].X() * width / 255,
+                               positions[index].Y() * height / 223
+                               );
+       }
 
 public:
        void AddPosition(const geometry::Point<Uint8> &p) {
index 78e197077724629db3b4bca5c5f64d09a39ff9c4..acb8194746ee46a7bb675882f603a8038e054411 100644 (file)
@@ -157,11 +157,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->HeroesPositions()[i]);
+                                               battle->HeroAt(i).Position());
                        } else if (ts.IsGood(i)) {
                                numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().greenNumberSprite));
                                numberPosition.push_back(
-                                               battle->HeroesPositions()[i]);
+                                               battle->HeroAt(i).Position());
                        }
                }
        }
@@ -251,10 +251,9 @@ 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());
-       const vector<Point<int> > &positions(ts.TargetsHeroes() ? battle->HeroesPositions() : battle->MonsterPositions());
-       for (vector<Point<int> >::size_type i(0), end(positions.size()); i < end; ++i) {
+       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, positions[i] + offset);
+                       targetAnimation.DrawCenter(screen, (ts.TargetsHeroes() ? battle->HeroAt(i).Position() : battle->MonsterPositions()[i]) + offset);
                }
        }
 }