From: Daniel Karbach Date: Tue, 21 Aug 2012 20:24:24 +0000 (+0200) Subject: moved monster's position to Monster X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=9718062e6ed305d9f8f1674ff172079688e78088;p=l2e.git moved monster's position to Monster --- diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index aae4635..fe1b309 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -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 &offset) for (vector::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); } } } diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index f5268dd..654e147 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -109,7 +109,6 @@ public: int MaxHeroes() const { return 4; } int MaxMonsters() const { return monsters.size(); } - const std::vector > &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 > monsterPositions; std::vector monsters; std::vector attackOrder; Hero heroes[4]; diff --git a/src/battle/Monster.h b/src/battle/Monster.h index 232da8f..8338cb1 100644 --- a/src/battle/Monster.h +++ b/src/battle/Monster.h @@ -10,6 +10,7 @@ #include "AttackChoice.h" #include "Stats.h" +#include "../geometry/Point.h" #include "../graphics/Animation.h" #include @@ -61,6 +62,9 @@ public: const graphics::Animation *AttackAnimation() const { return attackAnimation; } const graphics::Animation *SpellAnimation() const { return spellAnimation; } + geometry::Point &Position() { return position; } + const geometry::Point &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 position; + AttackChoice attackChoice; Uint16 maxHealth, health; diff --git a/src/battle/TargetSelection.cpp b/src/battle/TargetSelection.cpp index b24772d..1906c2b 100644 --- a/src/battle/TargetSelection.cpp +++ b/src/battle/TargetSelection.cpp @@ -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; } } diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp index acb8194..4483179 100644 --- a/src/battle/states/PerformAttacks.cpp +++ b/src/battle/states/PerformAttacks.cpp @@ -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 &offse void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector &offset) const { if (!targetAnimation.Valid() || !targetAnimation.Running()) return; const TargetSelection &ts(battle->CurrentAttackAttackChoice().Selection()); - for (vector >::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 >::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 >::size_type i(0), end(battle->MaxMonsters()); i < end; ++i) { + if (ts.IsSelected(i)) { + targetAnimation.DrawCenter(screen, battle->MonsterAt(i).Position() + offset); + } } } } diff --git a/src/battle/states/SelectTarget.cpp b/src/battle/states/SelectTarget.cpp index 2583857..591da67 100644 --- a/src/battle/states/SelectTarget.cpp +++ b/src/battle/states/SelectTarget.cpp @@ -95,8 +95,8 @@ void SelectTarget::RenderCursors(SDL_Surface *screen, const geometry::Vector indicatorOffset(cursorOffset + Vector(cursorIcon->Width() / 8, cursorIcon->Height() / -8)); vector > positions; if (selection->TargetsEnemies()) { - for (vector >::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) {