X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FPerformAttacks.cpp;h=960eb6cf51fc5a0e8d12672844047f09f650e13b;hb=acc322b16b5f31cfbc350d4fccb457c7730287fd;hp=92e5185cf70488a5ce8baf9a330011ef7ba51934;hpb=0b11a24a8b08c49d6e4301573602fb6d01e7a8c8;p=l2e.git diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp index 92e5185..960eb6c 100644 --- a/src/battle/states/PerformAttacks.cpp +++ b/src/battle/states/PerformAttacks.cpp @@ -23,9 +23,22 @@ using std::vector; namespace battle { +PerformAttacks::PerformAttacks(Battle *battle, BattleState *parent) +: battle(battle) +, parent(parent) +, moveAnimation(0) +, targetAnimation(0) +, titleBarText(0) +, cursor(-1) { + +} + + void PerformAttacks::OnEnterState(SDL_Surface *screen) { battle->CalculateAttackOrder(); - numberAnimation.reserve(battle->MaxMonsters() > battle->NumHeroes() + 1 ? battle->MaxMonsters() : battle->NumHeroes() + 1); + numberAnimation.reserve(battle->MaxMonsters() > battle->NumHeroes() + 1 + ? battle->MaxMonsters() + : battle->NumHeroes() + 1); numberPosition.reserve(numberAnimation.size()); OnResize(screen->w, screen->h); } @@ -44,10 +57,10 @@ void PerformAttacks::OnPauseState(SDL_Surface *screen) { void PerformAttacks::OnResize(int width, int height) { - const Resources &res = battle->Res(); - framePosition = battle->ScreenOffset(); + const Resources &res = parent->Res(); + framePosition = parent->ScreenOffset(); frameSize = Vector( - battle->Width(), + parent->Width(), res.titleFrame->BorderHeight() * 2 + res.titleFont->CharHeight()); } @@ -64,15 +77,16 @@ void PerformAttacks::HandleEvents(const Input &input) { } battle->CalculateDamage(); + const Battle::Order &attack = battle->CurrentAttack(); - if (battle->CurrentAttack().IsMonster()) { - Monster &monster(battle->MonsterAt(battle->CurrentAttack().index)); + if (attack.IsMonster()) { + Monster &monster(battle->MonsterAt(attack.index)); titleBarText = monster.Name(); targetAnimation = AnimationRunner(monster.MeleeAnimation()); moveAnimation = AnimationRunner(monster.AttackAnimation()); monster.SetAnimation(moveAnimation); - AddNumberAnimations(battle->MonsterAt(battle->CurrentAttack().index).GetAttackChoice().Selection()); - } else if (battle->CurrentAttack().IsCapsule()) { + AddNumberAnimations(monster.GetAttackChoice().Selection()); + } else if (attack.IsCapsule()) { Capsule &capsule(battle->GetCapsule()); titleBarText = capsule.Name(); targetAnimation = AnimationRunner(capsule.MeleeAnimation()); @@ -80,8 +94,8 @@ void PerformAttacks::HandleEvents(const Input &input) { capsule.SetAnimation(moveAnimation); AddNumberAnimations(capsule.GetAttackChoice().Selection()); } else { - Hero &hero(battle->HeroAt(battle->CurrentAttack().index)); - const AttackChoice &ac(battle->HeroAt(battle->CurrentAttack().index).GetAttackChoice()); + Hero &hero(battle->HeroAt(attack.index)); + const AttackChoice &ac(hero.GetAttackChoice()); switch (ac.GetType()) { case AttackChoice::SWORD: @@ -126,16 +140,16 @@ void PerformAttacks::HandleEvents(const Input &input) { if (titleBarText) { titleBarTimer = GraphicsTimers().StartCountdown(850); - textPosition = battle->ScreenOffset() + Vector( - (battle->Width() - std::strlen(titleBarText) * battle->Res().titleFont->CharWidth()) / 2, - battle->Res().titleFrame->BorderHeight()); + textPosition = parent->ScreenOffset() + Vector( + (parent->Width() - std::strlen(titleBarText) * parent->Res().titleFont->CharWidth()) / 2, + parent->Res().titleFrame->BorderHeight()); } if (moveAnimation.Valid()) { moveAnimation.Start(*this); - if (battle->CurrentAttack().IsMonster()) { - battle->MonsterAt(battle->CurrentAttack().index).SetAnimation(moveAnimation); - } else if (battle->CurrentAttack().IsHero()) { - battle->HeroAt(battle->CurrentAttack().index).SetAnimation(moveAnimation); + if (attack.IsMonster()) { + battle->MonsterAt(attack.index).SetAnimation(moveAnimation); + } else if (attack.IsHero()) { + battle->HeroAt(attack.index).SetAnimation(moveAnimation); } else { battle->GetCapsule().SetAnimation(moveAnimation); } @@ -151,25 +165,25 @@ void PerformAttacks::AddNumberAnimations(const TargetSelection &ts) { 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)); + numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), parent->Res().numberAnimationPrototype, parent->Res().bigNumberSprite)); numberPosition.push_back( - battle->MonsterAt(i).Position() + battle->ScreenOffset()); + battle->MonsterAt(i).Position() + parent->ScreenOffset()); } else if (ts.IsGood(i)) { - numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().greenNumberSprite)); + numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), parent->Res().numberAnimationPrototype, parent->Res().greenNumberSprite)); numberPosition.push_back( - battle->MonsterAt(i).Position() + battle->ScreenOffset()); + battle->MonsterAt(i).Position() + parent->ScreenOffset()); } } } else { for (int i(0); i < battle->NumHeroes(); ++i) { if (ts.IsBad(i)) { - numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite)); + numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), parent->Res().numberAnimationPrototype, parent->Res().bigNumberSprite)); numberPosition.push_back( - battle->HeroAt(i).Position() + battle->ScreenOffset()); + battle->HeroAt(i).Position() + parent->ScreenOffset()); } else if (ts.IsGood(i)) { - numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().greenNumberSprite)); + numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), parent->Res().numberAnimationPrototype, parent->Res().greenNumberSprite)); numberPosition.push_back( - battle->HeroAt(i).Position() + battle->ScreenOffset()); + battle->HeroAt(i).Position() + parent->ScreenOffset()); } } } @@ -225,11 +239,11 @@ void PerformAttacks::UpdateWorld(Uint32 deltaT) { } void PerformAttacks::Render(SDL_Surface *screen) { - battle->RenderBackground(screen); - battle->RenderMonsters(screen); - battle->RenderHeroes(screen); - battle->RenderCapsule(screen); - battle->RenderSmallHeroTags(screen); + parent->RenderBackground(screen); + parent->RenderMonsters(screen); + parent->RenderHeroes(screen); + parent->RenderCapsule(screen); + parent->RenderSmallHeroTags(screen); RenderTitleBar(screen); RenderNumbers(screen); RenderTargetAnimation(screen); @@ -238,9 +252,9 @@ void PerformAttacks::Render(SDL_Surface *screen) { void PerformAttacks::RenderTitleBar(SDL_Surface *screen) const { if (!titleBarText || !titleBarTimer.Running()) return; - battle->Res().titleFrame->Draw(screen, framePosition, frameSize.X(), frameSize.Y()); + parent->Res().titleFrame->Draw(screen, framePosition, frameSize.X(), frameSize.Y()); - battle->Res().titleFont->DrawString(titleBarText, screen, textPosition); + parent->Res().titleFont->DrawString(titleBarText, screen, textPosition); } void PerformAttacks::RenderNumbers(SDL_Surface *screen) const { @@ -258,13 +272,13 @@ void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen) const { 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() + battle->ScreenOffset()); + targetAnimation.DrawCenter(screen, battle->HeroAt(i).Position() + parent->ScreenOffset()); } } } else { for (vector >::size_type i(0), end(battle->MaxMonsters()); i < end; ++i) { if (ts.IsSelected(i)) { - targetAnimation.DrawCenter(screen, battle->MonsterAt(i).Position() + battle->ScreenOffset()); + targetAnimation.DrawCenter(screen, battle->MonsterAt(i).Position() + parent->ScreenOffset()); } } }