}
void VictoryState::LoadResults() {
+ // TODO: localization
lines.clear();
std::stringstream s;
s << "Max. MP increases by " << u.Amount();
break;
case Upgrade::ATTACK:
- s << "ATK increases by " << u.Amount();
+ s << "ATP increases by " << u.Amount();
break;
case Upgrade::DEFENSE:
s << "DFP increases by " << u.Amount();
case Upgrade::GUT:
s << "GUT increases by " << u.Amount();
break;
- case Upgrade::MAGIC_RSISTANCE:
+ case Upgrade::MAGIC_RESISTANCE:
s << "MGR increases by " << u.Amount();
break;
case Upgrade::LEVEL_NEXT:
#include "Capsule.h"
#include "Item.h"
+#include "LevelUp.h"
#include "Spell.h"
-#include "Stats.h"
#include "Upgrade.h"
#include "../graphics/Animation.h"
#include "../graphics/Sprite.h"
int Capsule::NextLevel() const {
int levelOffset(Level() - 1);
if (levelOffset < numLevels) {
- return levelLadder[levelOffset] - Experience();
+ return levelLadder[levelOffset].Experience() - Experience();
} else {
return 0;
}
}
int remain = exp;
while (remain >= NextLevel()) {
+ const LevelUp &lup = levelLadder[level - 1];
int added = NextLevel();
experience += added;
remain -= added;
++level;
+ maxHealth += lup.MaxHealth();
+ stats += lup;
info.push_back(Upgrade(name, Upgrade::LEVEL_UP, level));
- // TODO: upgrade attributes and push info
+ if (lup.MaxHealth() > 0) {
+ info.push_back(Upgrade(name, Upgrade::MAX_HEALTH, lup.MaxHealth()));
+ }
+ if (lup.Attack() > 0) {
+ info.push_back(Upgrade(name, Upgrade::ATTACK, lup.Attack()));
+ }
+ if (lup.Defense() > 0) {
+ info.push_back(Upgrade(name, Upgrade::DEFENSE, lup.Defense()));
+ }
+ if (lup.Strength() > 0) {
+ info.push_back(Upgrade(name, Upgrade::STRENGTH, lup.Strength()));
+ }
+ if (lup.Agility() > 0) {
+ info.push_back(Upgrade(name, Upgrade::AGILITY, lup.Agility()));
+ }
+ if (lup.Intelligence() > 0) {
+ info.push_back(Upgrade(name, Upgrade::INTELLIGENCE, lup.Intelligence()));
+ }
+ if (lup.Gut() > 0) {
+ info.push_back(Upgrade(name, Upgrade::GUT, lup.Gut()));
+ }
+ if (lup.MagicResistance() > 0) {
+ info.push_back(Upgrade(name, Upgrade::MAGIC_RESISTANCE, lup.MagicResistance()));
+ }
if (level > numLevels) {
info.push_back(Upgrade(
td.AddField("level", FieldDescription(((char *)&c.level) - ((char *)&c), Interpreter::NUMBER_ID));
td.AddField("experience", FieldDescription(((char *)&c.experience) - ((char *)&c), Interpreter::NUMBER_ID));
- td.AddField("ladder", FieldDescription(((char *)&c.levelLadder) - ((char *)&c), Interpreter::NUMBER_ID).SetAggregate());
+ td.AddField("ladder", FieldDescription(((char *)&c.levelLadder) - ((char *)&c), LevelUp::TYPE_ID).SetAggregate());
td.AddField("classes", FieldDescription(((char *)&c.classes) - ((char *)&c), Class::TYPE_ID).SetAggregate());
td.AddField("class", FieldDescription(((char *)&c.curClass) - ((char *)&c), Interpreter::NUMBER_ID));
namespace common {
class Item;
+ class LevelUp;
class Upgrade;
}
namespace graphics {
class Sprite;
}
-#include "../common/Stats.h"
+#include "Stats.h"
#include "../math/Vector.h"
#include <vector>
int level;
int experience;
- int *levelLadder;
+ LevelUp *levelLadder;
int numLevels;
Class *classes;
#include "Hero.h"
#include "Item.h"
+#include "LevelUp.h"
#include "Spell.h"
#include "Upgrade.h"
#include "../graphics/Animation.h"
int Hero::NextLevel() const {
int levelOffset(Level() - 1);
if (levelOffset < numLevels) {
- return levelLadder[levelOffset] - Experience();
+ return levelLadder[levelOffset].Experience() - Experience();
} else {
return 0;
}
}
int remain = exp;
while (remain >= NextLevel()) {
+ const LevelUp &lup = levelLadder[level - 1];
int added = NextLevel();
experience += added;
remain -= added;
++level;
+ maxHealth += lup.MaxHealth();
+ maxMana += lup.MaxMagic();
+ stats += lup;
info.push_back(Upgrade(name, Upgrade::LEVEL_UP, level));
- // TODO: upgrade attributes and push info
+ if (lup.MaxHealth() > 0) {
+ info.push_back(Upgrade(name, Upgrade::MAX_HEALTH, lup.MaxHealth()));
+ }
+ if (lup.MaxMagic() > 0) {
+ info.push_back(Upgrade(name, Upgrade::MAX_MAGIC, lup.MaxMagic()));
+ }
+ if (lup.Attack() > 0) {
+ info.push_back(Upgrade(name, Upgrade::ATTACK, lup.Attack()));
+ }
+ if (lup.Defense() > 0) {
+ info.push_back(Upgrade(name, Upgrade::DEFENSE, lup.Defense()));
+ }
+ if (lup.Strength() > 0) {
+ info.push_back(Upgrade(name, Upgrade::STRENGTH, lup.Strength()));
+ }
+ if (lup.Agility() > 0) {
+ info.push_back(Upgrade(name, Upgrade::AGILITY, lup.Agility()));
+ }
+ if (lup.Intelligence() > 0) {
+ info.push_back(Upgrade(name, Upgrade::INTELLIGENCE, lup.Intelligence()));
+ }
+ if (lup.Gut() > 0) {
+ info.push_back(Upgrade(name, Upgrade::GUT, lup.Gut()));
+ }
+ if (lup.MagicResistance() > 0) {
+ info.push_back(Upgrade(name, Upgrade::MAGIC_RESISTANCE, lup.MagicResistance()));
+ }
if (level > numLevels) {
info.push_back(Upgrade(
td.AddField("stats", FieldDescription(((char *)&h.stats) - ((char *)&h), Stats::TYPE_ID));
td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), Interpreter::NUMBER_ID));
- td.AddField("ladder", FieldDescription(((char *)&h.levelLadder) - ((char *)&h), Interpreter::NUMBER_ID).SetAggregate());
+ td.AddField("ladder", FieldDescription(((char *)&h.levelLadder) - ((char *)&h), LevelUp::TYPE_ID).SetAggregate());
td.AddField("useMask", FieldDescription(((char *)&h.useMask) - ((char *)&h), Interpreter::NUMBER_ID));
namespace common {
class Item;
+ class LevelUp;
class Spell;
class Upgrade;
}
int level;
int experience;
- // TODO: ladder should contain hp, mp, and stats mods.
- int *levelLadder;
+ LevelUp *levelLadder;
int numLevels;
int useMask;
--- /dev/null
+#include "LevelUp.h"
+
+#include "../loader/Interpreter.h"
+#include "../loader/TypeDescription.h"
+
+using loader::FieldDescription;
+using loader::Interpreter;
+using loader::TypeDescription;
+
+
+namespace common {
+
+LevelUp::LevelUp()
+: Stats()
+, experience(0)
+, maxHealth(0)
+, maxMagic(0) {
+
+}
+
+
+void LevelUp::CreateTypeDescription() {
+ LevelUp l;
+ Stats *s = &l;
+
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "LevelUp"));
+ td.SetDescription("Describes the requirements and benefits of a levelup.");
+ td.SetConstructor(&Construct);
+ td.SetSize(sizeof(LevelUp));
+ td.AddSupertype(Stats::TYPE_ID, ((char *)s) - ((char *)&l));
+
+ td.AddField("exp", FieldDescription(((char *)&l.experience) - ((char *)&l), Interpreter::NUMBER_ID).SetDescription("reuired experience points"));
+ td.AddField("maxHP", FieldDescription(((char *)&l.maxHealth) - ((char *)&l), Interpreter::NUMBER_ID).SetDescription("increase in maximum health points"));
+ td.AddField("maxMP", FieldDescription(((char *)&l.maxMagic) - ((char *)&l), Interpreter::NUMBER_ID).SetDescription("increas in maximum magic points"));
+
+ AddFields(td, l, ((char *)s) - ((char *)&l));
+}
+
+void LevelUp::Construct(void *data) {
+ new (data) LevelUp;
+}
+
+}
--- /dev/null
+#ifndef COMMON_LEVELUP_H_
+#define COMMON_LEVELUP_H_
+
+#include "Stats.h"
+
+
+namespace common {
+
+struct LevelUp
+: public Stats {
+
+public:
+ static const int TYPE_ID = 309;
+
+public:
+ LevelUp();
+
+public:
+ int Experience() const { return experience; }
+ int MaxHealth() const { return maxHealth; }
+ int MaxMagic() const { return maxMagic; }
+
+ static void CreateTypeDescription();
+ static void Construct(void *);
+
+private:
+ int experience;
+ int maxHealth;
+ int maxMagic;
+
+};
+
+}
+
+#endif
td.SetConstructor(&Construct);
td.SetSize(sizeof(Stats));
- td.AddField("atp", FieldDescription(((char *)&s.attack) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("attack points"));
- td.AddField("dfp", FieldDescription(((char *)&s.defense) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("defense points"));
- td.AddField("str", FieldDescription(((char *)&s.strength) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("strength"));
- td.AddField("agl", FieldDescription(((char *)&s.agility) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("agility"));
- td.AddField("int", FieldDescription(((char *)&s.intelligence) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("intelligence"));
- td.AddField("gut", FieldDescription(((char *)&s.gut) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("gut (ikari factor)"));
- td.AddField("mgr", FieldDescription(((char *)&s.magicResistance) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("magic resistance"));
+ AddFields(td, s, 0);
+}
+
+void Stats::AddFields(TypeDescription &td, const Stats &s, std::ptrdiff_t offset) {
+ td.AddField("atp", FieldDescription(((char *)&s.attack) - ((char *)&s) - offset, Interpreter::NUMBER_ID).SetDescription("attack points"));
+ td.AddField("dfp", FieldDescription(((char *)&s.defense) - ((char *)&s) - offset, Interpreter::NUMBER_ID).SetDescription("defense points"));
+ td.AddField("str", FieldDescription(((char *)&s.strength) - ((char *)&s) - offset, Interpreter::NUMBER_ID).SetDescription("strength"));
+ td.AddField("agl", FieldDescription(((char *)&s.agility) - ((char *)&s) - offset, Interpreter::NUMBER_ID).SetDescription("agility"));
+ td.AddField("int", FieldDescription(((char *)&s.intelligence) - ((char *)&s) - offset, Interpreter::NUMBER_ID).SetDescription("intelligence"));
+ td.AddField("gut", FieldDescription(((char *)&s.gut) - ((char *)&s) - offset, Interpreter::NUMBER_ID).SetDescription("gut (ikari factor)"));
+ td.AddField("mgr", FieldDescription(((char *)&s.magicResistance) - ((char *)&s) - offset, Interpreter::NUMBER_ID).SetDescription("magic resistance"));
}
void Stats::Construct(void *data) {
#ifndef COMMON_STATS_H_
#define COMMON_STATS_H_
+namespace loader {
+ class TypeDescription;
+}
+
+#include <memory>
#include <SDL.h>
namespace common {
static void CreateTypeDescription();
static void Construct(void *);
+public:
+ Stats &operator +=(const Stats &other) {
+ attack += other.attack;
+ defense += other.defense;
+ strength += other.strength;
+ agility += other.agility;
+ intelligence += other.intelligence;
+ magicResistance += other.magicResistance;
+ gut += other.gut;
+ return *this;
+ }
+
+protected:
+ static void AddFields(loader::TypeDescription &, const Stats &, std::ptrdiff_t offset);
+
private:
int attack;
int defense;
inline Stats operator +(const Stats &lhs, const Stats &rhs) {
- return Stats(
- lhs.Attack() + rhs.Attack(),
- lhs.Defense() + rhs.Defense(),
- lhs.Strength() + rhs.Strength(),
- lhs.Agility() + rhs.Agility(),
- lhs.Intelligence() + rhs.Intelligence(),
- lhs.Gut() + rhs.Gut(),
- lhs.MagicResistance() + rhs.MagicResistance());
+ Stats temp(lhs);
+ temp = rhs;
+ return temp;
}
}
AGILITY,
INTELLIGENCE,
GUT,
- MAGIC_RSISTANCE,
+ MAGIC_RESISTANCE,
LEVEL_NEXT,
};
#include "common/Ikari.h"
#include "common/Inventory.h"
#include "common/Item.h"
+#include "common/LevelUp.h"
#include "common/Script.h"
#include "common/Spell.h"
#include "common/Stats.h"
common::Hero::CreateTypeDescription();
common::Ikari::CreateTypeDescription();
common::Item::CreateTypeDescription();
+ common::LevelUp::CreateTypeDescription();
common::Stats::CreateTypeDescription();
common::Spell::CreateTypeDescription();
common::TargetingMode::CreateTypeDescription();
gut: 100,
mgr: 10
},
- ladder: [
- 10
+ ladder: [ LevelUp
+ // insensible test data
+ { exp: 10, maxHP: 5, maxMP: 3, atp: 2, str: 1 }
],
useMask: maskMaxim,
attackAnimation: ComplexAnimation {