X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FPerformAttacks.cpp;h=fac7cdf855aa42a4c8422f38e5ebd715afd52608;hb=e1edc92c4fb834c8061118e89c0d7e239742b030;hp=15c4feba5ab0633cd0acf638ebc1aa0ea2b28d3e;hpb=9cfff98ffce0529c685fbd5aa52e213c295449a1;p=l2e.git diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp index 15c4feb..fac7cdf 100644 --- a/src/battle/states/PerformAttacks.cpp +++ b/src/battle/states/PerformAttacks.cpp @@ -10,13 +10,12 @@ #include "../BattleState.h" #include "../Hero.h" #include "../Monster.h" +#include "../TargetSelection.h" #include "../../app/Application.h" #include "../../app/Input.h" #include "../../common/Ikari.h" #include "../../common/Item.h" #include "../../common/Spell.h" -#include "../../geometry/operators.h" -#include "../../geometry/Point.h" #include "../../graphics/Animation.h" #include "../../graphics/Font.h" #include "../../graphics/Frame.h" @@ -25,35 +24,32 @@ using app::Application; using app::Input; -using geometry::Point; using geometry::Vector; using graphics::AnimationRunner; using std::vector; namespace battle { -void PerformAttacks::EnterState(Application &c, SDL_Surface *screen) { - ctrl = &c; +void PerformAttacks::OnEnterState(SDL_Surface *screen) { battle->CalculateAttackOrder(); numberAnimation.reserve(battle->MaxMonsters() > battle->NumHeroes() + 1 ? battle->MaxMonsters() : battle->NumHeroes() + 1); numberPosition.reserve(numberAnimation.size()); } -void PerformAttacks::ExitState(Application &c, SDL_Surface *screen) { +void PerformAttacks::OnExitState(SDL_Surface *screen) { battle->ClearAllAttacks(); - ctrl = 0; } -void PerformAttacks::ResumeState(Application &ctrl, SDL_Surface *screen) { +void PerformAttacks::OnResumeState(SDL_Surface *screen) { } -void PerformAttacks::PauseState(Application &ctrl, SDL_Surface *screen) { +void PerformAttacks::OnPauseState(SDL_Surface *screen) { } -void PerformAttacks::Resize(int width, int height) { +void PerformAttacks::OnResize(int width, int height) { } @@ -65,7 +61,7 @@ void PerformAttacks::HandleEvents(const Input &input) { battle->ApplyDamage(); battle->NextAttack(); if (battle->AttacksFinished()) { - ctrl->PopState(); + Ctrl().PopState(); return; } @@ -77,10 +73,10 @@ void PerformAttacks::HandleEvents(const Input &input) { targetAnimation = AnimationRunner(monster.MeleeAnimation()); moveAnimation = AnimationRunner(monster.AttackAnimation()); monster.SetAnimation(moveAnimation); - AddNumberAnimations(battle->MonsterAttackChoiceAt(battle->CurrentAttack().index).Selection()); + AddNumberAnimations(battle->MonsterAt(battle->CurrentAttack().index).GetAttackChoice().Selection()); } else { Hero &hero(battle->HeroAt(battle->CurrentAttack().index)); - const AttackChoice &ac(battle->AttackChoiceAt(battle->CurrentAttack().index)); + const AttackChoice &ac(battle->HeroAt(battle->CurrentAttack().index).GetAttackChoice()); switch (ac.GetType()) { case AttackChoice::SWORD: @@ -121,11 +117,17 @@ void PerformAttacks::HandleEvents(const Input &input) { moveAnimation.Clear(); break; } - hero.SetAnimation(moveAnimation); } if (titleBarText) titleBarTimer = GraphicsTimers().StartCountdown(850); - if (moveAnimation.Valid()) moveAnimation.Start(*this); + if (moveAnimation.Valid()) { + moveAnimation.Start(*this); + if (battle->CurrentAttack().isMonster) { + battle->MonsterAt(battle->CurrentAttack().index).SetAnimation(moveAnimation); + } else { + battle->HeroAt(battle->CurrentAttack().index).SetAnimation(moveAnimation); + } + } if (targetAnimation.Valid()) { targetAnimationTimer = GraphicsTimers().StartCountdown(150); } else { @@ -134,16 +136,16 @@ void PerformAttacks::HandleEvents(const Input &input) { } void PerformAttacks::AddNumberAnimations(const TargetSelection &ts) { - if (ts.TargetsEnemies()) { + if (ts.TargetsMonsters()) { for (int i(0); i < battle->MaxMonsters(); ++i) { 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 { @@ -151,11 +153,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()); } } } @@ -215,6 +217,7 @@ void PerformAttacks::Render(SDL_Surface *screen) { battle->RenderBackground(screen, offset); battle->RenderMonsters(screen, offset); battle->RenderHeroes(screen, offset); + battle->RenderCapsule(screen, offset); battle->RenderSmallHeroTags(screen, offset); RenderTitleBar(screen, offset); RenderNumbers(screen, offset); @@ -225,9 +228,9 @@ void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector &offs if (!titleBarText || !titleBarTimer.Running()) return; int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight()); - battle->Res().titleFrame->Draw(screen, Point(offset.X(), offset.Y()), battle->Width(), height); + battle->Res().titleFrame->Draw(screen, offset, battle->Width(), height); - Point textPosition( + Vector textPosition( (battle->Width() - (std::strlen(titleBarText) * battle->Res().titleFont->CharWidth())) / 2, battle->Res().titleFrame->BorderHeight()); battle->Res().titleFont->DrawString(titleBarText, screen, textPosition + offset); @@ -245,10 +248,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()); - const vector > &positions(ts.TargetsHeroes() ? battle->HeroesPositions() : battle->MonsterPositions()); - for (vector >::size_type i(0), end(positions.size()); i < end; ++i) { - if (ts.IsSelected(i)) { - targetAnimation.DrawCenter(screen, positions[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); + } } } }