diff options
Diffstat (limited to 'sigencore/Creature.cpp')
| -rw-r--r-- | sigencore/Creature.cpp | 221 |
1 files changed, 113 insertions, 108 deletions
diff --git a/sigencore/Creature.cpp b/sigencore/Creature.cpp index d276f797..9e9ef34d 100644 --- a/sigencore/Creature.cpp +++ b/sigencore/Creature.cpp @@ -39,10 +39,15 @@ // C includes #include <cmath> -QMap<Sigencore::Creature::StyleLevel, long long> Sigencore::Creature::m_expCache; +using namespace Sigcore; +using namespace Sigmod; +using namespace Sigscript; +using namespace Sigencore; -Sigencore::Creature::Creature(Sigscript::SpeciesWrapper* species, const int level, Containment* containment, const bool suppressInitialization) : - Sigscript::Config(containment), +QMap<Creature::StyleLevel, long long> Creature::m_expCache; + +Creature::Creature(SpeciesWrapper* species, const int level, Containment* containment, const bool suppressInitialization) : + Config(containment), m_game(containment->game()), m_containment(containment), m_species(species), @@ -51,33 +56,33 @@ Sigencore::Creature::Creature(Sigscript::SpeciesWrapper* species, const int leve m_levelExp(calcLevelExperience(species->growth(), level)), m_id(QUuid::createUuid()) { - for (int i = 0; i < (Sigmod::ST_SpecialDefense - Sigmod::ST_HP + 1); ++i) + for (int i = 0; i < (ST_SpecialDefense - ST_HP + 1); ++i) { m_dv[i] = -1; m_statExp[i] = -1; } - for (int i = 0; i < (Sigmod::ST_SpecialDefense - Sigmod::ST_Attack + 1); ++i) + for (int i = 0; i < (ST_SpecialDefense - ST_Attack + 1); ++i) m_stages[i] = 0; if (!suppressInitialization) completeData(); } -Sigencore::Creature::~Creature() +Creature::~Creature() { // TODO } -QUuid Sigencore::Creature::id() const +QUuid Creature::id() const { return m_id; } -Sigscript::GameWrapper* Sigencore::Creature::game() const +GameWrapper* Creature::game() const { return m_game; } -bool Sigencore::Creature::setContainment(Containment* containment) +bool Creature::setContainment(Containment* containment) { if (m_containment && m_containment->removeMember(this)) { @@ -87,32 +92,32 @@ bool Sigencore::Creature::setContainment(Containment* containment) return false; } -Sigencore::Containment* Sigencore::Creature::containment() const +Containment* Creature::containment() const { return m_containment; } -Sigscript::SpeciesWrapper* Sigencore::Creature::species() const +SpeciesWrapper* Creature::species() const { return m_species; } -void Sigencore::Creature::setName(const QString& name) +void Creature::setName(const QString& name) { m_name = name; emit(nameChanged(m_name)); } -QString Sigencore::Creature::name() const +QString Creature::name() const { return m_name; } -bool Sigencore::Creature::setGender(const Gender gender) +bool Creature::setGender(const Gender gender) { if (!m_game->rules()->genderAllowed()) return false; - const Sigcore::Fraction genderFactor = m_species->genderFactor(); + const Fraction genderFactor = m_species->genderFactor(); switch (gender) { case Male: @@ -135,12 +140,12 @@ bool Sigencore::Creature::setGender(const Gender gender) return true; } -Sigencore::Creature::Gender Sigencore::Creature::gender() const +Creature::Gender Creature::gender() const { return m_gender; } -bool Sigencore::Creature::setLevel(const int level) +bool Creature::setLevel(const int level) { if ((level <= 0) || (m_game->rules()->maxLevel() < level)) return false; @@ -151,17 +156,17 @@ bool Sigencore::Creature::setLevel(const int level) return true; } -bool Sigencore::Creature::giveLevels(const int levels) +bool Creature::giveLevels(const int levels) { return setLevel(m_level + levels); } -int Sigencore::Creature::level() const +int Creature::level() const { return m_level; } -int Sigencore::Creature::calcLevel(const Sigmod::Species::Style growth, const long long levelExp) +int Creature::calcLevel(const Species::Style growth, const long long levelExp) { int level = -1; while (calcLevelExperience(growth, level + 1) < levelExp) @@ -169,7 +174,7 @@ int Sigencore::Creature::calcLevel(const Sigmod::Species::Style growth, const lo return level; } -bool Sigencore::Creature::setLevelExperience(const long long levelExp) +bool Creature::setLevelExperience(const long long levelExp) { if (levelExp < 0) return false; @@ -186,17 +191,17 @@ bool Sigencore::Creature::setLevelExperience(const long long levelExp) return true; } -bool Sigencore::Creature::giveLevelExperience(const long long levelExp) +bool Creature::giveLevelExperience(const long long levelExp) { return setLevelExperience(m_levelExp + levelExp); } -long long Sigencore::Creature::levelExperience() const +long long Creature::levelExperience() const { return m_levelExp; } -long long Sigencore::Creature::calcLevelExperience(const Sigmod::Species::Style growth, const int level) +long long Creature::calcLevelExperience(const Species::Style growth, const int level) { if (m_expCache.contains(StyleLevel(growth, level))) return m_expCache[StyleLevel(growth, level)]; @@ -205,7 +210,7 @@ long long Sigencore::Creature::calcLevelExperience(const Sigmod::Species::Style long long exp = -1; switch (growth) { - case Sigmod::Species::Fluctuating: + case Species::Fluctuating: if (level <= 15) exp = cube * ((24 + (level + 1) / 3) / 50.); else if (level <= 35) @@ -218,19 +223,19 @@ long long Sigencore::Creature::calcLevelExperience(const Sigmod::Species::Style else exp = 5 * cube / 3; break; - case Sigmod::Species::Fading: + case Species::Fading: exp = 6 * cube / 5 - 15 * square + 100 * level - 140; break; - case Sigmod::Species::Slow: + case Species::Slow: exp = 5 * cube / 4; break; - case Sigmod::Species::Normal: + case Species::Normal: exp = cube; break; - case Sigmod::Species::Fast: + case Species::Fast: exp = 4 * cube / 5; break; - case Sigmod::Species::Erratic: + case Species::Erratic: { const double p[] = {0.000, 0.008, 0.014}; if (level <= 50) @@ -254,9 +259,9 @@ long long Sigencore::Creature::calcLevelExperience(const Sigmod::Species::Style return exp; } -bool Sigencore::Creature::setCurrentHp(const int hp) +bool Creature::setCurrentHp(const int hp) { - if ((hp < 0) || (statValue(Sigmod::ST_HP) < hp)) + if ((hp < 0) || (statValue(ST_HP) < hp)) return false; m_currentHp = hp; emit(currentHpChanged(m_currentHp)); @@ -265,51 +270,51 @@ bool Sigencore::Creature::setCurrentHp(const int hp) return true; } -bool Sigencore::Creature::changeCurrentHp(const int hp) +bool Creature::changeCurrentHp(const int hp) { return setCurrentHp(m_currentHp + hp); } -int Sigencore::Creature::currentHp() const +int Creature::currentHp() const { return m_currentHp; } -bool Sigencore::Creature::setDv(const Sigmod::Stat stat, const int dv) +bool Creature::setDv(const Stat stat, const int dv) { - if ((stat == Sigmod::ST_SpecialDefense) && !(m_game->rules()->specialSplit() && m_game->rules()->specialDVSplit())) + if ((stat == ST_SpecialDefense) && !(m_game->rules()->specialSplit() && m_game->rules()->specialDVSplit())) return false; m_dv[stat] = dv; emit(dvChanged(stat, dv)); return true; } -int Sigencore::Creature::dv(const Sigmod::Stat stat) const +int Creature::dv(const Stat stat) const { - if ((stat == Sigmod::ST_Accuracy) || (stat == Sigmod::ST_Evasion)) + if ((stat == ST_Accuracy) || (stat == ST_Evasion)) return false; - Sigmod::Stat actualStat = stat; - if (stat == Sigmod::ST_SpecialDefense) + Stat actualStat = stat; + if (stat == ST_SpecialDefense) { if (m_game->rules()->specialSplit() && m_game->rules()->specialDVSplit()) - actualStat = Sigmod::ST_Special; + actualStat = ST_Special; else return false; } int dv; - if (valueOfType(QString("stat-dv-%1").arg((m_game->rules()->specialSplit() ? Sigmod::StatGSCStr : Sigmod::StatRBYStr)[actualStat]), &dv) && (dv < (m_game->rules()->specialDVSplit() ? 32 : 16))) + if (valueOfType(QString("stat-dv-%1").arg((m_game->rules()->specialSplit() ? StatGSCStr : StatRBYStr)[actualStat]), &dv) && (dv < (m_game->rules()->specialDVSplit() ? 32 : 16))) return dv; return m_dv[actualStat]; } -bool Sigencore::Creature::setStatExperience(const Sigmod::Stat stat, const long long statExp) +bool Creature::setStatExperience(const Stat stat, const long long statExp) { - if ((stat == Sigmod::ST_Accuracy) || (stat == Sigmod::ST_Evasion) || ((stat == Sigmod::ST_SpecialDefense) && !m_game->rules()->specialSplit())) + if ((stat == ST_Accuracy) || (stat == ST_Evasion) || ((stat == ST_SpecialDefense) && !m_game->rules()->specialSplit())) return false; if (m_game->rules()->effortValuesAllowed()) { int evSum = statExp; - for (int i = Sigmod::ST_HP; i <= (m_game->rules()->specialSplit() ? Sigmod::ST_Special : Sigmod::ST_SpecialDefense); ++i) + for (int i = ST_HP; i <= (m_game->rules()->specialSplit() ? ST_Special : ST_SpecialDefense); ++i) { if (i != stat) evSum += m_statExp[i]; @@ -322,30 +327,30 @@ bool Sigencore::Creature::setStatExperience(const Sigmod::Stat stat, const long return true; } -bool Sigencore::Creature::giveStatExperience(const Sigmod::Stat stat, const long long statExp) +bool Creature::giveStatExperience(const Stat stat, const long long statExp) { return setStatExperience(stat, m_statExp[stat] + statExp); } -long long Sigencore::Creature::statExperience(const Sigmod::Stat stat) const +long long Creature::statExperience(const Stat stat) const { long long exp = m_statExp[stat]; - valueOfType(QString("stat-experience-%1").arg((m_game->rules()->specialSplit() ? Sigmod::StatGSCStr : Sigmod::StatRBYStr)[stat]), &exp); + valueOfType(QString("stat-experience-%1").arg((m_game->rules()->specialSplit() ? StatGSCStr : StatRBYStr)[stat]), &exp); return exp; } -int Sigencore::Creature::statValue(const Sigmod::Stat stat) const +int Creature::statValue(const Stat stat) const { - Sigcore::Fraction multiplier; - if (stat != Sigmod::ST_HP) + Fraction multiplier; + if (stat != ST_HP) { - foreach (Sigscript::NatureWrapper* nature, m_natures) + foreach (NatureWrapper* nature, m_natures) multiplier *= nature->stat(stat); } return calcStat(m_game, stat, m_level, m_species->baseStat(stat), dv(stat), statExperience(stat), multiplier); } -int Sigencore::Creature::calcStat(Sigscript::GameWrapper* game, const Sigmod::Stat stat, const int level, const int baseStat, const int dv, const int statExp, const Sigcore::Fraction& multiplier) +int Creature::calcStat(GameWrapper* game, const Stat stat, const int level, const int baseStat, const int dv, const int statExp, const Fraction& multiplier) { int statValue = statExp; if (!game->rules()->effortValuesAllowed() && statValue) @@ -357,36 +362,36 @@ int Sigencore::Creature::calcStat(Sigscript::GameWrapper* game, const Sigmod::St else statValue += dv; statValue *= double(level) / game->rules()->maxLevel(); - if (stat == Sigmod::ST_HP) + if (stat == ST_HP) statValue += 10 + level; else statValue += 5; return statValue * multiplier; } -void Sigencore::Creature::recalcStats() +void Creature::recalcStats() { // FIXME? - recalcStat(Sigmod::ST_HP); - recalcStat(Sigmod::ST_Attack); - recalcStat(Sigmod::ST_Defense); - recalcStat(Sigmod::ST_Speed); + recalcStat(ST_HP); + recalcStat(ST_Attack); + recalcStat(ST_Defense); + recalcStat(ST_Speed); if (m_game->rules()->specialSplit()) { - recalcStat(Sigmod::ST_SpecialAttack); - recalcStat(Sigmod::ST_SpecialDefense); + recalcStat(ST_SpecialAttack); + recalcStat(ST_SpecialDefense); } else - recalcStat(Sigmod::ST_Special); + recalcStat(ST_Special); } -void Sigencore::Creature::recalcStat(const Sigmod::Stat stat) +void Creature::recalcStat(const Stat stat) { // FIXME? emit(statValueChanged(stat, statValue(stat))); } -bool Sigencore::Creature::addAbility(Sigscript::AbilityWrapper* ability) +bool Creature::addAbility(AbilityWrapper* ability) { if ((m_abilities.size() < m_game->rules()->maxAbilities()) && !m_abilities.contains(ability)) { @@ -397,7 +402,7 @@ bool Sigencore::Creature::addAbility(Sigscript::AbilityWrapper* ability) return false; } -bool Sigencore::Creature::removeAbility(Sigscript::AbilityWrapper* ability) +bool Creature::removeAbility(AbilityWrapper* ability) { if (m_abilities.contains(ability)) { @@ -408,17 +413,17 @@ bool Sigencore::Creature::removeAbility(Sigscript::AbilityWrapper* ability) return false; } -QList<Sigscript::AbilityWrapper*> Sigencore::Creature::abilities() const +QList<AbilityWrapper*> Creature::abilities() const { return m_abilities; } -bool Sigencore::Creature::hasAbility(Sigscript::AbilityWrapper* ability) const +bool Creature::hasAbility(AbilityWrapper* ability) const { return m_abilities.contains(ability); } -bool Sigencore::Creature::addItems(Sigscript::ItemWrapper* item, const int count, const bool allOrNothing) +bool Creature::addItems(ItemWrapper* item, const int count, const bool allOrNothing) { const int addWeight = count * item->weight(); int end = 0; @@ -459,35 +464,35 @@ bool Sigencore::Creature::addItems(Sigscript::ItemWrapper* item, const int count return count - end; } -QList<Sigscript::ItemWrapper*> Sigencore::Creature::items() const +QList<ItemWrapper*> Creature::items() const { return m_items.keys(); } -int Sigencore::Creature::itemWeight() const +int Creature::itemWeight() const { int weight = 0; - QList<Sigscript::ItemWrapper*> items = m_items.keys(); - foreach (Sigscript::ItemWrapper* curItem, items) + QList<ItemWrapper*> items = m_items.keys(); + foreach (ItemWrapper* curItem, items) weight += curItem->weight() * m_items[curItem]; return weight; } -int Sigencore::Creature::itemCount() const +int Creature::itemCount() const { int count = 0; - QList<Sigscript::ItemWrapper*> items = m_items.keys(); - foreach (Sigscript::ItemWrapper* curItem, items) + QList<ItemWrapper*> items = m_items.keys(); + foreach (ItemWrapper* curItem, items) count += m_items[curItem]; return count; } -int Sigencore::Creature::hasItem(Sigscript::ItemWrapper* item) const +int Creature::hasItem(ItemWrapper* item) const { return m_items.count(item); } -bool Sigencore::Creature::addMove(Sigscript::MoveWrapper* move) +bool Creature::addMove(MoveWrapper* move) { bool canLearn = false; for (int i = 0; !canLearn && (i < m_species->moveCount()); ++i) @@ -504,7 +509,7 @@ bool Sigencore::Creature::addMove(Sigscript::MoveWrapper* move) return false; } -bool Sigencore::Creature::removeMove(Sigscript::MoveWrapper* move) +bool Creature::removeMove(MoveWrapper* move) { if (m_moves.contains(move) && (1 < m_moves.size())) { @@ -515,17 +520,17 @@ bool Sigencore::Creature::removeMove(Sigscript::MoveWrapper* move) return false; } -QList<Sigscript::MoveWrapper*> Sigencore::Creature::moves() const +QList<MoveWrapper*> Creature::moves() const { return m_moves; } -bool Sigencore::Creature::hasMove(Sigscript::MoveWrapper* move) const +bool Creature::hasMove(MoveWrapper* move) const { return m_moves.contains(move); } -bool Sigencore::Creature::addNature(Sigscript::NatureWrapper* nature) +bool Creature::addNature(NatureWrapper* nature) { if ((m_natures.size() < m_game->rules()->maxNatures()) && !m_natures.contains(nature)) { @@ -536,7 +541,7 @@ bool Sigencore::Creature::addNature(Sigscript::NatureWrapper* nature) return false; } -bool Sigencore::Creature::removeNature(Sigscript::NatureWrapper* nature) +bool Creature::removeNature(NatureWrapper* nature) { if (m_natures.contains(nature)) { @@ -547,17 +552,17 @@ bool Sigencore::Creature::removeNature(Sigscript::NatureWrapper* nature) return false; } -QList<Sigscript::NatureWrapper*> Sigencore::Creature::natures() const +QList<NatureWrapper*> Creature::natures() const { return m_natures; } -bool Sigencore::Creature::hasNature(Sigscript::NatureWrapper* nature) const +bool Creature::hasNature(NatureWrapper* nature) const { return m_natures.contains(nature); } -bool Sigencore::Creature::addStatus(Sigscript::StatusWrapper* status) +bool Creature::addStatus(StatusWrapper* status) { if (!m_status.contains(status)) { @@ -568,7 +573,7 @@ bool Sigencore::Creature::addStatus(Sigscript::StatusWrapper* status) return false; } -bool Sigencore::Creature::removeStatus(Sigscript::StatusWrapper* status) +bool Creature::removeStatus(StatusWrapper* status) { if (m_status.contains(status)) { @@ -579,17 +584,17 @@ bool Sigencore::Creature::removeStatus(Sigscript::StatusWrapper* status) return false; } -QList<Sigscript::StatusWrapper*> Sigencore::Creature::status() const +QList<StatusWrapper*> Creature::status() const { return m_status; } -bool Sigencore::Creature::hasStatus(Sigscript::StatusWrapper* status) const +bool Creature::hasStatus(StatusWrapper* status) const { return m_status.contains(status); } -void Sigencore::Creature::completeData() +void Creature::completeData() { // TODO if (!m_name.isEmpty()) @@ -610,37 +615,37 @@ void Sigencore::Creature::completeData() emit(initialized()); } -void Sigencore::Creature::completeStats() +void Creature::completeStats() { if (m_game->rules()->specialSplit() && m_game->rules()->specialDVSplit()) { - for (int i = Sigmod::ST_HP; i <= Sigmod::ST_SpecialDefense; ++i) + for (int i = ST_HP; i <= ST_SpecialDefense; ++i) m_dv[i] = qrand() & 31; } else { - for (int i = Sigmod::ST_Attack; i <= Sigmod::ST_Special; ++i) + for (int i = ST_Attack; i <= ST_Special; ++i) m_dv[i] = qrand() & 15; - m_dv[Sigmod::ST_HP] = ((m_dv[Sigmod::ST_Attack] & 1) << 3) + ((m_dv[Sigmod::ST_Defense] & 1) << 2) + ((m_dv[Sigmod::ST_Speed] & 1) << 1) + (m_dv[Sigmod::ST_Special] & 1); + m_dv[ST_HP] = ((m_dv[ST_Attack] & 1) << 3) + ((m_dv[ST_Defense] & 1) << 2) + ((m_dv[ST_Speed] & 1) << 1) + (m_dv[ST_Special] & 1); } } -void Sigencore::Creature::completeAbilities() +void Creature::completeAbilities() { - Sigcore::Hat<Sigscript::AbilityWrapper*> abilityHat = m_species->abilityHat(); + Hat<AbilityWrapper*> abilityHat = m_species->abilityHat(); while ((m_abilities.size() < game()->rules()->maxAbilities()) && abilityHat.count()) addAbility(abilityHat.takeAndClear()); } -void Sigencore::Creature::completeItems() +void Creature::completeItems() { - Sigcore::Hat<Sigscript::ItemWrapper*> itemHat = m_species->itemHat(); + Hat<ItemWrapper*> itemHat = m_species->itemHat(); int i = 0; while ((i < m_game->rules()->maxHeldItems()) && itemHat.count()) { if (m_species->itemChance().poll()) { - Sigscript::ItemWrapper* item = itemHat.pick(); + ItemWrapper* item = itemHat.pick(); if (addItems(item, 1)) ++i; else @@ -651,12 +656,12 @@ void Sigencore::Creature::completeItems() } } -void Sigencore::Creature::completeMoves() +void Creature::completeMoves() { - QMap<int, Sigscript::MoveWrapper*> moves; + QMap<int, MoveWrapper*> moves; for (int i = 0; i < m_species->moveCount(); ++i) { - Sigscript::SpeciesMoveWrapper* move = m_species->move(i); + SpeciesMoveWrapper* move = m_species->move(i); const int level = move->level(); if ((0 <= level) && (level <= m_level)) moves[level] = move->move(); @@ -664,18 +669,18 @@ void Sigencore::Creature::completeMoves() // TODO: give the moves to the creature } -void Sigencore::Creature::completeNatures() +void Creature::completeNatures() { - Sigcore::Hat<Sigscript::NatureWrapper*> natureHat = game()->natureHat(); + Hat<NatureWrapper*> natureHat = game()->natureHat(); while ((m_natures.size() < m_game->rules()->maxNatures()) && natureHat.count()) addNature(natureHat.takeAndClear()); } -void Sigencore::Creature::makeConnections() +void Creature::makeConnections() { connect(this, SIGNAL(levelChanged(int)), SLOT(recalcStats())); - connect(this, SIGNAL(natureAdded(Sigscript::NatureWrapper*)), SLOT(recalcStats())); - connect(this, SIGNAL(natureRemoved(Sigscript::NatureWrapper*)), SLOT(recalcStats())); - connect(this, SIGNAL(dvChanged(Sigmod::Stat, int)), SLOT(recalcStat(Sigmod::Stat))); - connect(this, SIGNAL(statExperienceChanged(Sigmod::Stat, long long)), SLOT(recalcStat(Sigmod::Stat))); + connect(this, SIGNAL(natureAdded(NatureWrapper*)), SLOT(recalcStats())); + connect(this, SIGNAL(natureRemoved(NatureWrapper*)), SLOT(recalcStats())); + connect(this, SIGNAL(dvChanged(Stat, int)), SLOT(recalcStat(Stat))); + connect(this, SIGNAL(statExperienceChanged(Stat, long long)), SLOT(recalcStat(Stat))); } |
