]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/states/VictoryState.cpp
feed victory messages from upgrade
[l2e.git] / src / battle / states / VictoryState.cpp
index c1e5ea422c646826c12ca0aa34b46540230dc115..409f0846aa380b4a8153f53a12aaa287f616cda6 100644 (file)
@@ -8,7 +8,6 @@
 #include "../../common/Capsule.h"
 #include "../../common/GameConfig.h"
 #include "../../common/GameState.h"
-#include "../../common/Hero.h"
 #include "../../math/Vector.h"
 #include "../../graphics/Font.h"
 #include "../../graphics/Frame.h"
@@ -43,11 +42,15 @@ void VictoryState::LoadResults() {
 
        lines.push_back("");
 
-       for (std::vector<Hero>::const_iterator
+       vector<common::Hero::UpgradeInfo> upgrade;
+       for (std::vector<Hero>::iterator
                        i(battle->HeroesBegin()), end(battle->HeroesEnd());
                        i != end; ++i) {
                if (i->Health() <= 0) continue;
-               const common::Hero &hero = i->Master();
+               upgrade.clear();
+               common::Hero &hero = i->Master();
+               hero.AddExperience(battle->ExpReward(), upgrade);
+               LoadResults(hero.Name(), upgrade, lines);
                s.str("");
                s << hero.Name() << " next level " << hero.NextLevel();
                lines.push_back(s.str());
@@ -68,6 +71,54 @@ void VictoryState::LoadResults() {
        lines.push_back(s.str());
 }
 
+void VictoryState::LoadResults(
+               const char *who,
+               const vector<common::Hero::UpgradeInfo> &upgrade,
+               vector<string> &lines) {
+       std::stringstream s;
+       for (vector<common::Hero::UpgradeInfo>::const_iterator
+                       i(upgrade.begin()), end(upgrade.end());
+                       i != end; ++i) {
+               s.str("");
+               switch (i->type) {
+                       case common::Hero::UPGRADE_LVL:
+                               s << who << " levels up.";
+                               break;
+                       case common::Hero::UPGRADE_MHP:
+                               s << "Max. HP increases by " << i->amount;
+                               break;
+                       case common::Hero::UPGRADE_MMP:
+                               s << "Max. MP increases by " << i->amount;
+                               break;
+                       case common::Hero::UPGRADE_ATK:
+                               s << "ATK increases by " << i->amount;
+                               break;
+                       case common::Hero::UPGRADE_DFP:
+                               s << "DFP increases by " << i->amount;
+                               break;
+                       case common::Hero::UPGRADE_STR:
+                               s << "STR increases by " << i->amount;
+                               break;
+                       case common::Hero::UPGRADE_AGL:
+                               s << "AGL increases by " << i->amount;
+                               break;
+                       case common::Hero::UPGRADE_INT:
+                               s << "INT increases by " << i->amount;
+                               break;
+                       case common::Hero::UPGRADE_GUT:
+                               s << "GUT increases by " << i->amount;
+                               break;
+                       case common::Hero::UPGRADE_MGR:
+                               s << "MGR increases by " << i->amount;
+                               break;
+                       default:
+                               s << "There's an error in common::Hero::"
+                                               "AddExperience()";
+               }
+               lines.push_back(s.str());
+       }
+}
+
 void VictoryState::OnExitState(SDL_Surface *screen) {
 
 }
@@ -100,20 +151,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
@@ -140,10 +201,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;
        }
 }