bool MonsterAlive(int index) const;
bool CapsuleAlive() const;
+ std::vector<Hero>::iterator HeroesBegin() { return heroes.begin(); }
std::vector<Hero>::const_iterator HeroesBegin() const { return heroes.begin(); }
+ std::vector<Hero>::iterator HeroesEnd() { return heroes.end(); }
std::vector<Hero>::const_iterator HeroesEnd() const { return heroes.end(); }
Hero &HeroAt(int index);
const Hero &HeroAt(int index) const;
#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"
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());
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) {
}
}
#include "../../app/State.h"
+#include "../../common/Hero.h"
#include "../../math/Vector.h"
#include <string>
private:
void LoadResults();
+ void LoadResults(
+ const char *,
+ const std::vector<common::Hero::UpgradeInfo> &,
+ std::vector<std::string> &);
void RenderFrame(SDL_Surface *screen);
void RenderLines(SDL_Surface *screen);
using loader::FieldDescription;
using loader::Interpreter;
using loader::TypeDescription;
+using std::vector;
namespace common {
}
}
+void Capsule::AddExperience(int exp, vector<Hero::UpgradeInfo> &info) {
+ if (level > numLevels) {
+ // don't award any experience if at highest level
+ return;
+ }
+ int remain = exp;
+ while (remain >= NextLevel()) {
+ int added = NextLevel();
+ experience += added;
+ remain -= added;
+ ++level;
+
+ info.push_back(Hero::UpgradeInfo(Hero::UPGRADE_LVL, level));
+
+ // TODO: upgrade attributes and push info
+
+ if (level > numLevels) {
+ return;
+ }
+ }
+ experience += remain;
+}
+
+
void Capsule::UpgradeClass() {
++maxClass;
++curClass;
class Sprite;
}
+#include "Hero.h"
#include "../common/Stats.h"
#include "../math/Vector.h"
+#include <vector>
#include <SDL.h>
namespace common {
int Experience() const { return experience; }
int NextLevel() const;
+ void AddExperience(int, std::vector<Hero::UpgradeInfo> &);
+
graphics::Sprite *BattleSprite();
const graphics::Sprite *BattleSprite() const;
graphics::Animation *MeleeAnimation();
using loader::TypeDescription;
using map::Entity;
using std::memset;
+using std::vector;
namespace common {
}
}
+void Hero::AddExperience(int exp, vector<UpgradeInfo> &info) {
+ if (level > numLevels) {
+ // don't award any experience if at highest level
+ return;
+ }
+ int remain = exp;
+ while (remain >= NextLevel()) {
+ int added = NextLevel();
+ experience += added;
+ remain -= added;
+ ++level;
+
+ info.push_back(UpgradeInfo(UPGRADE_LVL, level));
+
+ // TODO: upgrade attributes and push info
+
+ if (level > numLevels) {
+ return;
+ }
+ }
+ experience += remain;
+}
+
bool Hero::CanEquip(const Item &item) const {
return useMask & item.HeroMask();
EQUIP_COUNT,
};
+ enum UpgradeType {
+ UPGRADE_LVL,
+ UPGRADE_MHP,
+ UPGRADE_MMP,
+ UPGRADE_ATK,
+ UPGRADE_DFP,
+ UPGRADE_STR,
+ UPGRADE_AGL,
+ UPGRADE_INT,
+ UPGRADE_GUT,
+ UPGRADE_MGR,
+ };
+
const char *Name() const { return name; }
Uint16 MaxHealth() const { return maxHealth; }
int Experience() const { return experience; }
int NextLevel() const;
+ struct UpgradeInfo {
+ UpgradeType type;
+ int amount;
+ UpgradeInfo(UpgradeType t, int a = 0)
+ : type(t), amount(a) { }
+ };
+ void AddExperience(int, std::vector<UpgradeInfo> &);
+
bool CanEquip(const Item &) const;
bool CanInvoke(const Spell &) const;
int level;
int experience;
+ // TODO: ladder should contain hp, mp, and stats mods.
int *levelLadder;
int numLevels;
gut: 6,
mgr: 6
},
- expReward: 2,
+ expReward: 8,
goldReward: 5,
attackAnimation: ComplexAnimation {
sprite: lizardSprite,