]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/states/VictoryState.cpp
put stat increments in level ladder
[l2e.git] / src / battle / states / VictoryState.cpp
index dca0bf2ee3da96bc727be6ee793c8fd58246007b..e2cc99fb27cc3e7799d0dde3728958c4a1f45538 100644 (file)
@@ -5,9 +5,10 @@
 #include "../Hero.h"
 #include "../../app/Application.h"
 #include "../../app/Input.h"
+#include "../../common/Capsule.h"
 #include "../../common/GameConfig.h"
 #include "../../common/GameState.h"
-#include "../../common/Hero.h"
+#include "../../common/Upgrade.h"
 #include "../../math/Vector.h"
 #include "../../graphics/Font.h"
 #include "../../graphics/Frame.h"
@@ -16,6 +17,8 @@
 
 using app::Application;
 using app::Input;
+using common::GameState;
+using common::Upgrade;
 using graphics::Font;
 using graphics::Frame;
 using math::Vector;
@@ -30,6 +33,7 @@ void VictoryState::OnEnterState(SDL_Surface *screen) {
 }
 
 void VictoryState::LoadResults() {
+       // TODO: localization
        lines.clear();
 
        std::stringstream s;
@@ -40,19 +44,64 @@ void VictoryState::LoadResults() {
        s << "Gets " << battle->GoldReward() << " gold";
        lines.push_back(s.str());
 
-       for (std::vector<Hero>::const_iterator
-                       i(battle->HeroesBegin()), end(battle->HeroesEnd());
+       lines.push_back("");
+
+       GameState &state = *parent->Game().state;
+       vector<Upgrade> upgrade;
+       battle->ApplyRewards(state, upgrade);
+       for (std::vector<Upgrade>::const_iterator
+                       i(upgrade.begin()), end(upgrade.end());
                        i != end; ++i) {
-               if (i->Health() <= 0) continue;
-               const common::Hero &hero = i->Master();
-               s.str("");
-               s << hero.Name() << " next level " << hero.NextLevel();
-               lines.push_back(s.str());
+               LoadResult(*i, lines);
        }
 
        lines.push_back("");
        s.str("");
-       s << parent->Game().state->money << " gold";
+       s << state.money << " gold";
+       lines.push_back(s.str());
+}
+
+void VictoryState::LoadResult(
+               const Upgrade &u,
+               vector<string> &lines) {
+       std::stringstream s;
+       switch (u.GetType()) {
+               case Upgrade::LEVEL_UP:
+                       s << u.Name() << " levels up.";
+                       break;
+               case Upgrade::MAX_HEALTH:
+                       s << "Max. HP increases by " << u.Amount();
+                       break;
+               case Upgrade::MAX_MAGIC:
+                       s << "Max. MP increases by " << u.Amount();
+                       break;
+               case Upgrade::ATTACK:
+                       s << "ATP increases by " << u.Amount();
+                       break;
+               case Upgrade::DEFENSE:
+                       s << "DFP increases by " << u.Amount();
+                       break;
+               case Upgrade::STRENGTH:
+                       s << "STR increases by " << u.Amount();
+                       break;
+               case Upgrade::AGILITY:
+                       s << "AGL increases by " << u.Amount();
+                       break;
+               case Upgrade::INTELLIGENCE:
+                       s << "INT increases by " << u.Amount();
+                       break;
+               case Upgrade::GUT:
+                       s << "GUT increases by " << u.Amount();
+                       break;
+               case Upgrade::MAGIC_RESISTANCE:
+                       s << "MGR increases by " << u.Amount();
+                       break;
+               case Upgrade::LEVEL_NEXT:
+                       s << u.Name() << " next level " << u.Amount();
+                       break;
+               default:
+                       s << "unknown upgrade type " << u.GetType();
+       }
        lines.push_back(s.str());
 }
 
@@ -88,20 +137,30 @@ void VictoryState::HandleEvents(const Input &input) {
                ++cursor;
                timer = GraphicsTimers().StartInterval(150);
        } else if (input.IsDown(Input::ACTION_A)
-                       && timer.JustHit()
-                       && timer.Iteration() > 3) {
-               ++cursor;
+                       && timer.JustHit()) {
+               if (timer.Iteration() > 3) {
+                       ++cursor;
+                       stalling = false;
+               } else {
+                       stalling = true;
+               }
        } else if (input.JustPressed(Input::SHOULDER_LEFT)) {
                ++cursor;
                timer = GraphicsTimers().StartInterval(150);
        } else if (input.IsDown(Input::SHOULDER_LEFT)
-                       && timer.JustHit()
-                       && timer.Iteration() > 3) {
-               ++cursor;
+                       && timer.JustHit()) {
+               if (timer.Iteration() > 3) {
+                       ++cursor;
+                       stalling = false;
+               } else {
+                       stalling = true;
+               }
        }
-       if (!input.IsDown(Input::ACTION_A)
+       if (timer.JustHit()
+                       && !input.IsDown(Input::ACTION_A)
                        && !input.IsDown(Input::SHOULDER_LEFT)) {
                timer.Clear();
+               stalling = false;
        }
        if (cursor >= int(lines.size())) {
                Ctrl().PopState(); // pop self
@@ -128,10 +187,30 @@ void VictoryState::RenderFrame(SDL_Surface *screen) {
 void VictoryState::RenderLines(SDL_Surface *screen) {
        // naive implementation
        const Font &font = *parent->Res().normalFont;
+       const Vector<int> lineBreak = Vector<int>(
+                       0, font.CharHeight() * 5 / 4);
+       const int start = cursor > 7 ? cursor - 8 : 0;
        Vector<int> position = textPosition;
-       for (int i = 0; i <= cursor && i < int(lines.size()); ++i) {
+
+       int end = cursor + 1;
+
+       if (start > 0) {
+               if (timer.Running() && !stalling) {
+                       --end;
+                       position += lineBreak;
+                       const int correction = timer.IterationElapsed();
+                       if (correction > 0) {
+               //              ++start;
+                               position.Y() -= lineBreak.Y() * correction / timer.TargetTime();
+                       }
+               }
+       }
+
+       if (end > int(lines.size())) end = lines.size();
+
+       for (int i = start; i < end; ++i) {
                font.DrawString(lines[i].c_str(), screen, position);
-               position.Y() += font.CharHeight();
+               position += lineBreak;
        }
 }