#include "../Battle.h"
#include "../BattleState.h"
#include "../Hero.h"
+#include "../Resources.h"
#include "../../app/Application.h"
#include "../../app/Input.h"
#include "../../common/Capsule.h"
#include "../../common/GameConfig.h"
#include "../../common/GameState.h"
+#include "../../common/Upgrade.h"
#include "../../math/Vector.h"
+#include "../../graphics/ColorFade.h"
#include "../../graphics/Font.h"
#include "../../graphics/Frame.h"
+#include <iomanip>
#include <sstream>
using app::Application;
using app::Input;
+using common::GameState;
+using common::Upgrade;
+using graphics::ColorFade;
using graphics::Font;
using graphics::Frame;
using math::Vector;
+using std::left;
+using std::right;
+using std::setfill;
+using std::setw;
using std::string;
+using std::stringstream;
using std::vector;
namespace battle {
}
void VictoryState::LoadResults() {
+ const Resources &res = parent->Res();
lines.clear();
- std::stringstream s;
- s << "Gets " << battle->ExpReward() << " EXP";
+ stringstream s;
+ s << res.victoryGetsText << ' '
+ << battle->ExpReward() << ' '
+ << res.victoryExpText << '.';
lines.push_back(s.str());
s.str("");
- s << "Gets " << battle->GoldReward() << " gold";
+ s << res.victoryGetsText << ' '
+ << battle->GoldReward() << ' '
+ << res.victoryGoldText << '.';
lines.push_back(s.str());
lines.push_back("");
- vector<common::Hero::UpgradeInfo> upgrade;
- for (std::vector<Hero>::iterator
- i(battle->HeroesBegin()), end(battle->HeroesEnd());
+ GameState &state = *parent->Game().state;
+ vector<Upgrade> upgrade;
+ battle->ApplyRewards(state, upgrade);
+ for (vector<Upgrade>::const_iterator
+ i(upgrade.begin()), end(upgrade.end());
i != end; ++i) {
- if (i->Health() <= 0) continue;
- 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());
+ LoadResult(*i, lines);
}
- if (battle->HasCapsule()) {
- const Capsule &capsule = battle->GetCapsule();
- if (capsule.Health() > 0) {
- s.str("");
- s << capsule.Name() << " next level " << capsule.Master().NextLevel();
- lines.push_back(s.str());
- }
- }
+ s.str("");
+ s << state.money << ' ' << res.victoryGoldText;
+ string goldStr = s.str();
lines.push_back("");
s.str("");
- s << parent->Game().state->money << " gold";
+ s << right << setw(28) << setfill(' ') << goldStr;
lines.push_back(s.str());
}
-void VictoryState::LoadResults(
- const char *who,
- const vector<common::Hero::UpgradeInfo> &upgrade,
+void VictoryState::LoadResult(
+ const Upgrade &u,
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());
+ const Resources &res = parent->Res();
+ stringstream s;
+ switch (u.GetType()) {
+ case Upgrade::LEVEL_UP:
+ s << left << setw(6) << setfill(' ') << u.Name()
+ << res.victoryLevelUpText << '.';
+ break;
+ case Upgrade::MAX_HEALTH:
+ s << res.victoryMHPText << ' '
+ << res.victoryUpgradeText << ' '
+ << u.Amount() << '.';
+ break;
+ case Upgrade::MAX_MAGIC:
+ s << res.victoryMMPText << ' '
+ << res.victoryUpgradeText << ' '
+ << u.Amount() << '.';
+ break;
+ case Upgrade::ATTACK:
+ s << res.victoryATPText << ' '
+ << res.victoryUpgradeText << ' '
+ << u.Amount() << '.';
+ break;
+ case Upgrade::DEFENSE:
+ s << res.victoryDFPText << ' '
+ << res.victoryUpgradeText << ' '
+ << u.Amount() << '.';
+ break;
+ case Upgrade::STRENGTH:
+ s << res.victorySTRText << ' '
+ << res.victoryUpgradeText << ' '
+ << u.Amount() << '.';
+ break;
+ case Upgrade::AGILITY:
+ s << res.victoryAGLText << ' '
+ << res.victoryUpgradeText << ' '
+ << u.Amount() << '.';
+ break;
+ case Upgrade::INTELLIGENCE:
+ s << res.victoryINTText << ' '
+ << res.victoryUpgradeText << ' '
+ << u.Amount() << '.';
+ break;
+ case Upgrade::GUT:
+ s << res.victoryGUTText << ' '
+ << res.victoryUpgradeText << ' '
+ << u.Amount() << '.';
+ break;
+ case Upgrade::MAGIC_RESISTANCE:
+ s << res.victoryMGRText << ' '
+ << res.victoryUpgradeText << ' '
+ << u.Amount() << '.';
+ break;
+ case Upgrade::LEVEL_NEXT:
+ s << setw(7) << setfill(' ')
+ << left << u.Name() << ' '
+ << res.victoryNextLevelText
+ << ' ' << u.Amount();
+ break;
+ default:
+ s << "unknown upgrade type " << u.GetType();
}
+ lines.push_back(s.str());
}
void VictoryState::OnExitState(SDL_Surface *screen) {
stalling = false;
}
if (cursor >= int(lines.size())) {
- Ctrl().PopState(); // pop self
+ timer.Clear();
+ ColorFade *fade = new ColorFade(this, 0, 650);
+ fade->SetLeadInTime(150);
+ fade->SetDoublePop();
+ Ctrl().PushState(fade);
}
}
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;
+ int start = cursor > 7 ? cursor - 8 : 0;
Vector<int> position = textPosition;
int end = cursor + 1;
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();
+ if (end > int(lines.size())) {
+ end = lines.size();
+ }
+ if (start > int(lines.size()) - 9) {
+ start = lines.size() - 9;
+ }
for (int i = start; i < end; ++i) {
font.DrawString(lines[i].c_str(), screen, position);