diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2007-11-22 20:18:43 +0000 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2007-11-22 20:18:43 +0000 |
commit | 4cc4d62d084bc3002e35f6bd15a73f22157114e4 (patch) | |
tree | e492df521e068e0cd726382d0c08a939858196f2 /pokemod/Move.cpp | |
parent | 83f4b43f63960ba30e38cf5bb53cd98ae738ef74 (diff) | |
download | sigen-4cc4d62d084bc3002e35f6bd15a73f22157114e4.tar.gz sigen-4cc4d62d084bc3002e35f6bd15a73f22157114e4.tar.xz sigen-4cc4d62d084bc3002e35f6bd15a73f22157114e4.zip |
[FIX] classes more usable
[FIX] Matrix class
[ADD] pokemod/Rules.{h, cpp}
[FIX] coding style cleaned up
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@28 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Move.cpp')
-rw-r--r-- | pokemod/Move.cpp | 382 |
1 files changed, 234 insertions, 148 deletions
diff --git a/pokemod/Move.cpp b/pokemod/Move.cpp index 68749cac..e0d813ae 100644 --- a/pokemod/Move.cpp +++ b/pokemod/Move.cpp @@ -25,8 +25,8 @@ const char* PokeGen::PokeMod::Move::TargetStr[PokeGen::PokeMod::Move::T_End] = {"Player", "Enemy", "Both", "Random"}; const char* PokeGen::PokeMod::Move::ChoiceStr[PokeGen::PokeMod::Move::C_End] = {"Player", "Enemy", "Random"}; -PokeGen::PokeMod::Move::Move(const Pokemod* par, const unsigned _id) : - Object(_id, par), +PokeGen::PokeMod::Move::Move(const Pokemod& par, const unsigned _id) : + Object(par, _id), name(""), accuracy(1, 1), power(0), @@ -36,310 +36,396 @@ PokeGen::PokeMod::Move::Move(const Pokemod* par, const unsigned _id) : target(UINT_MAX), targetChoice(UINT_MAX), ignoreAccuracy(false), - ignoreFlinch(false), + canFlinch(false), + canRandom(false), + canSnatch(false), sound(false), description("") { } -PokeGen::PokeMod::Move::Move(const Pokemod* par, Ini& ini, const unsigned _id) : - Object(_id, par) +PokeGen::PokeMod::Move::Move(const Pokemod& par, const Move& m, const unsigned _id) : + Object(par, _id) { - ImportIni(ini, _id); + *this = m; } -bool PokeGen::PokeMod::Move::Validate() +PokeGen::PokeMod::Move::Move(const Pokemod& par, const QString& fname, const unsigned _id) : + Object(par, _id) { - pokemod->ValidationMsg(QString("---Move \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); + load(fname, _id); +} + +bool PokeGen::PokeMod::Move::validate() const +{ + bool valid = true; + pokemod.validationMsg(QString("---Move \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); if (name == "") { - pokemod->ValidationMsg("Name is not defined"); - isValid = ""; + pokemod.validationMsg("Name is not defined"); + valid = ""; } - accuracy.Reduce(); - if (pokemod->GetTypeByID(type) == UINT_MAX) + if (pokemod.getTypeByID(type) == UINT_MAX) { - pokemod->ValidationMsg("Invalid type"); - isValid = false; + pokemod.validationMsg("Invalid type"); + valid = false; } if (!powerPoints) { - pokemod->ValidationMsg("Invalid number of power points"); - isValid = false; + pokemod.validationMsg("Invalid number of power points"); + valid = false; } if (T_End <= target) { - pokemod->ValidationMsg("Invalid target"); - isValid = false; + pokemod.validationMsg("Invalid target"); + valid = false; } - if (!target || (pokemod->GetMaxFight() << (target == T_Both)) < numTargets) + if (!target || (pokemod.getRules().getMaxFight() << (target == T_Both)) < numTargets) { - pokemod->ValidationMsg("Invalid number of targets"); - isValid = false; + pokemod.validationMsg("Invalid number of targets"); + valid = false; } if (C_End <= targetChoice) { - pokemod->ValidationMsg("Invalid target choice"); - isValid = false; + pokemod.validationMsg("Invalid target choice"); + valid = false; } - if (GetEffectCount()) + if (getEffectCount()) { QMap<unsigned, unsigned> idChecker; - for (QList<MoveEffect>::Iterator i = effects.begin(); i != effects.end(); ++i) + for (QListIterator<MoveEffect> i(effects); i.hasNext(); i.next()) { - if (!i->IsValid()) - isValid = false; - ++idChecker[i->GetId()]; + if (!i.peekNext().isValid()) + valid = false; + ++idChecker[i.peekNext().getId()]; } - for (QMap<unsigned, unsigned>::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i) + for (QMapIterator<unsigned, unsigned> i(idChecker); i.hasNext(); i.next()) { if (1 < i.value()) { - pokemod->ValidationMsg(QString("There are %1 effects with id %2").arg(i.value()).arg(i.key())); - isValid = false; + pokemod.validationMsg(QString("There are %1 effects with id %2").arg(i.value()).arg(i.key())); + valid = false; } } } else { - pokemod->ValidationMsg("There are no effects"); - isValid = false; + pokemod.validationMsg("There are no effects"); + valid = false; } - return isValid; + return valid; +} + +unsigned PokeGen::PokeMod::Move::getNewId() const +{ + unsigned i = 0; + for (; (i < getEffectCount()) && (getEffectByID(i) != UINT_MAX); ++i) + ; + return i; } -void PokeGen::PokeMod::Move::ImportIni(Ini& ini, const unsigned _id) +void PokeGen::PokeMod::Move::load(const QString& fname, const unsigned _id) { + Ini ini(fname); if (_id == UINT_MAX) - ini.GetValue("id", id); + ini.getValue("id", id); else id = _id; unsigned i; unsigned j; - ini.GetValue("name", name); - ini.GetValue("accuracy-n", i, 1); - ini.GetValue("accuracy-d", j, 1); - accuracy.Set(i, j); - ini.GetValue("power", power, 0); - ini.GetValue("type", type); - ini.GetValue("special", special, false); - ini.GetValue("powerPoints", powerPoints, 1); - ini.GetValue("target", target); - ini.GetValue("numTargets", numTargets, 0); - ini.GetValue("targetChoice", targetChoice); - ini.GetValue("ignoreAccuracy", ignoreAccuracy, false); - ini.GetValue("ignoreFlinch", ignoreFlinch, false); - ini.GetValue("sound", sound, false); - ini.GetValue("description", description, ""); -} - -void PokeGen::PokeMod::Move::ExportIni(QFile& fout) const -{ - Ini exMove("Move"); - exMove.AddField("id", id); - exMove.AddField("name", name); - exMove.AddField("accuracy-n", accuracy.GetNum()); - exMove.AddField("accuracy-d", accuracy.GetDenom()); - exMove.AddField("power", power); - exMove.AddField("type", type); - exMove.AddField("special", special); - exMove.AddField("powerPoints", powerPoints); - exMove.AddField("target", target); - exMove.AddField("numTargets", numTargets); - exMove.AddField("targetChoice", targetChoice); - exMove.AddField("ignoreAccuracy", ignoreAccuracy); - exMove.AddField("ignoreFlinch", ignoreFlinch); - exMove.AddField("sound", sound); - exMove.AddField("description", description); - for (QList<MoveEffect>::ConstIterator i = effects.begin(); i != effects.end(); ++i) - i->ExportIni(fout, name); -} - -void PokeGen::PokeMod::Move::SetName(const QString& n) + ini.getValue("name", name); + ini.getValue("accuracy-n", i, 1); + ini.getValue("accuracy-d", j, 1); + accuracy.set(i, j); + ini.getValue("power", power, 0); + ini.getValue("type", type); + ini.getValue("special", special, false); + ini.getValue("powerPoints", powerPoints, 1); + ini.getValue("target", target); + ini.getValue("numTargets", numTargets, 0); + ini.getValue("targetChoice", targetChoice); + ini.getValue("ignoreAccuracy", ignoreAccuracy, false); + ini.getValue("canFlinch", canFlinch, false); + ini.getValue("canRandom", canRandom, false); + ini.getValue("canSnatch", canSnatch, false); + ini.getValue("sound", sound, false); + ini.getValue("description", description, ""); + QStringList path = pokemod.getPath().split('/'); + path.removeLast(); + QDir fdir(path.join("/")); + effects.clear(); + if (fdir.cd("effect")) + { + for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) + newEffect(i.next()); + } +} + +void PokeGen::PokeMod::Move::save() const +{ + Ini ini; + ini.addField("id", id); + ini.addField("name", name); + ini.addField("accuracy-n", accuracy.getNum()); + ini.addField("accuracy-d", accuracy.getDenom()); + ini.addField("power", power); + ini.addField("type", type); + ini.addField("special", special); + ini.addField("powerPoints", powerPoints); + ini.addField("target", target); + ini.addField("numTargets", numTargets); + ini.addField("targetChoice", targetChoice); + ini.addField("ignoreAccuracy", ignoreAccuracy); + ini.addField("canFlinch", canFlinch); + ini.addField("canRandom", canRandom); + ini.addField("canSnatch", canSnatch); + ini.addField("sound", sound); + ini.addField("description", description); + ini.save(QString("%1/move/%2/data.pini").arg(pokemod.getPath()).arg(name)); + for (QListIterator<MoveEffect> i(effects); i.hasNext(); ) + i.next().save(name); +} + +void PokeGen::PokeMod::Move::setName(const QString& n) { name = n; } -bool PokeGen::PokeMod::Move::SetAccuracy(const unsigned n, const unsigned d) +void PokeGen::PokeMod::Move::setAccuracy(const unsigned n, const unsigned d) { - return accuracy.Set(n, d); + accuracy.set(n, d); } -bool PokeGen::PokeMod::Move::SetAccuracyNum(const unsigned n) +void PokeGen::PokeMod::Move::setAccuracyNum(const unsigned n) { - return accuracy.SetNum(n); + accuracy.setNum(n); } -bool PokeGen::PokeMod::Move::SetAccuracyDenom(const unsigned d) +void PokeGen::PokeMod::Move::setAccuracyDenom(const unsigned d) { - return accuracy.SetDenom(d); + accuracy.setDenom(d); } -bool PokeGen::PokeMod::Move::SetType(const unsigned t) +void PokeGen::PokeMod::Move::setType(const unsigned t) { - if (pokemod->GetTypeByID(t) != UINT_MAX) - type = t; - return (type == t); + if (pokemod.getTypeByID(t) == UINT_MAX) + throw("Move: type out-of-bounds"); + type = t; } -void PokeGen::PokeMod::Move::SetSpecial(const bool s) +void PokeGen::PokeMod::Move::setSpecial(const bool s) { special = s; } -bool PokeGen::PokeMod::Move::SetPowerPoints(const unsigned p) +void PokeGen::PokeMod::Move::setPowerPoints(const unsigned p) { - if (p) - powerPoints = p; - return (powerPoints == p); + if (!p) + throw("Move: powerPoints out-of-bounds"); + powerPoints = p; } -bool PokeGen::PokeMod::Move::SetTarget(const unsigned t) +void PokeGen::PokeMod::Move::setTarget(const unsigned t) { - if (t < T_End) - target = t; - return (target == t); + if (T_End <= t) + throw("Move: target out-of-bounds"); + target = t; } -bool PokeGen::PokeMod::Move::SetNumTargets(const unsigned n) +void PokeGen::PokeMod::Move::setNumTargets(const unsigned n) { - if (n && (n <= pokemod->GetMaxFight() << 1)) - numTargets = n; - return (numTargets == n); + if (!n || ((pokemod.getRules().getMaxFight() << 1) < n)) + throw("Move: numTargets out-of-bounds"); + numTargets = n; } -bool PokeGen::PokeMod::Move::SetTargetChoice(const unsigned t) +void PokeGen::PokeMod::Move::setTargetChoice(const unsigned t) { - if (t < C_End) - targetChoice = t; - return (targetChoice == t); + if (C_End <= t) + throw("Move: targetChoice out-of-bounds"); + targetChoice = t; } -void PokeGen::PokeMod::Move::SetIgnoreAccuracy(const bool i) +void PokeGen::PokeMod::Move::setIgnoreAccuracy(const bool i) { ignoreAccuracy = i; } -void PokeGen::PokeMod::Move::SetIgnoreFlinch(const bool i) +void PokeGen::PokeMod::Move::setCanFlinch(const bool c) +{ + canFlinch = c; +} + +void PokeGen::PokeMod::Move::setCanRandom(const bool c) { - ignoreFlinch = i; + canRandom = c; } -void PokeGen::PokeMod::Move::SetSound(const bool s) +void PokeGen::PokeMod::Move::setCanSnatch(const bool c) +{ + canSnatch = c; +} + +void PokeGen::PokeMod::Move::setSound(const bool s) { sound = s; } -QString PokeGen::PokeMod::Move::GetName() const +QString PokeGen::PokeMod::Move::getName() const { return name; } -PokeGen::Frac PokeGen::PokeMod::Move::GetAccuracy() const +PokeGen::Frac PokeGen::PokeMod::Move::getAccuracy() const { return accuracy; } -unsigned PokeGen::PokeMod::Move::GetAccuracyNum() const +unsigned PokeGen::PokeMod::Move::getAccuracyNum() const { - return accuracy.GetNum(); + return accuracy.getNum(); } -unsigned PokeGen::PokeMod::Move::GetAccuracyDenom() const +unsigned PokeGen::PokeMod::Move::getAccuracyDenom() const { - return accuracy.GetDenom(); + return accuracy.getDenom(); } -unsigned PokeGen::PokeMod::Move::GetType() const +unsigned PokeGen::PokeMod::Move::getType() const { return type; } -bool PokeGen::PokeMod::Move::GetSpecial() const +bool PokeGen::PokeMod::Move::getSpecial() const { return special; } -unsigned PokeGen::PokeMod::Move::GetPowerPoints() const +unsigned PokeGen::PokeMod::Move::getPowerPoints() const { return powerPoints; } -unsigned PokeGen::PokeMod::Move::GetTarget() const +unsigned PokeGen::PokeMod::Move::getTarget() const { return target; } -unsigned PokeGen::PokeMod::Move::GetNumTargets() const +unsigned PokeGen::PokeMod::Move::getNumTargets() const { return numTargets; } -unsigned PokeGen::PokeMod::Move::GetTargetChoice() const +unsigned PokeGen::PokeMod::Move::getTargetChoice() const { return targetChoice; } -bool PokeGen::PokeMod::Move::GetIgnoreAccuracy() const +bool PokeGen::PokeMod::Move::getIgnoreAccuracy() const { return ignoreAccuracy; } -bool PokeGen::PokeMod::Move::GetIgnoreFlinch() const +bool PokeGen::PokeMod::Move::getCanFlinch() const +{ + return canFlinch; +} + +bool PokeGen::PokeMod::Move::getCanRandom() const { - return ignoreFlinch; + return canRandom; } -bool PokeGen::PokeMod::Move::GetSound() const +bool PokeGen::PokeMod::Move::getCanSnatch() const +{ + return canSnatch; +} + +bool PokeGen::PokeMod::Move::getSound() const { return sound; } -QString PokeGen::PokeMod::Move::GetDescription() const +QString PokeGen::PokeMod::Move::getDescription() const { return description; } -const PokeGen::PokeMod::MoveEffect* PokeGen::PokeMod::Move::GetEffect(unsigned i) const +const PokeGen::PokeMod::MoveEffect& PokeGen::PokeMod::Move::getEffect(const unsigned i) const +{ + if (getEffectCount() <= i) + throw("Move: out-of-bounds"); + return effects.at(i); +} + +PokeGen::PokeMod::MoveEffect& PokeGen::PokeMod::Move::getEffect(const unsigned i) { - if (i < GetEffectCount()) - return &effects[i]; - return NULL; + if (getEffectCount() <= i) + throw("Move: out-of-bounds"); + return effects[i]; } -unsigned PokeGen::PokeMod::Move::GetEffectByID(unsigned _id) const +unsigned PokeGen::PokeMod::Move::getEffectByID(const unsigned _id) const { - for (unsigned i = 0; i < GetEffectCount(); ++i) + for (unsigned i = 0; i < getEffectCount(); ++i) { - if (effects[i].GetId() == _id) + if (effects[i].getId() == _id) return i; } return UINT_MAX; } -unsigned PokeGen::PokeMod::Move::GetEffectCount() const +unsigned PokeGen::PokeMod::Move::getEffectCount() const { return effects.size(); } -const PokeGen::PokeMod::MoveEffect* PokeGen::PokeMod::Move::NewEffect(Ini* const ini) +PokeGen::PokeMod::MoveEffect& PokeGen::PokeMod::Move::newEffect() { - unsigned i = 0; - for (; (i < GetEffectCount()) && (GetEffectByID(i) != UINT_MAX); ++i) - ; - MoveEffect newEffect(pokemod, i); - if (ini) - newEffect.ImportIni(*ini); - effects.append(newEffect); - return &effects[GetEffectCount() - 1]; + effects.append(MoveEffect(pokemod, getNewId())); + return effects[getEffectCount() - 1]; } -bool PokeGen::PokeMod::Move::DeleteEffect(unsigned i) +PokeGen::PokeMod::MoveEffect& PokeGen::PokeMod::Move::newEffect(const QString& fname) { - if (i < GetEffectCount()) - { - effects.erase(effects.begin() + i); - return true; - } - return false; + effects.append(MoveEffect(pokemod, fname, getNewId())); + return effects[getEffectCount() - 1]; +} + +PokeGen::PokeMod::MoveEffect& PokeGen::PokeMod::Move::newEffect(const MoveEffect& e) +{ + effects.append(MoveEffect(pokemod, e, getNewId())); + return effects[getEffectCount() - 1]; +} + +void PokeGen::PokeMod::Move::deleteEffect(const unsigned i) +{ + if (getEffectCount() <= i) + throw("Move: out-of-bounds"); + effects.removeAt(i); +} + +PokeGen::PokeMod::Move& PokeGen::PokeMod::Move::operator=(const Move& rhs) +{ + if (this == &rhs) + return *this; + name = rhs.name; + accuracy = rhs.accuracy; + power = rhs.power; + type = rhs.type; + special = rhs.special; + powerPoints = rhs.powerPoints; + target = rhs.target; + numTargets = rhs.numTargets; + targetChoice = rhs.targetChoice; + ignoreAccuracy = rhs.ignoreAccuracy; + canFlinch = rhs.canFlinch; + canRandom = rhs.canRandom; + canSnatch = rhs.canSnatch; + sound = rhs.sound; + description = rhs.description; + effects.clear(); + for (unsigned i = 0; i < rhs.getEffectCount(); ++i) + newEffect(rhs.getEffect(i)); + return *this; } |