/* * Copyright 2007-2008 Ben Boeckel * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ // Header include #include "Move.h" // Pokemod includes #include "Macros.h" #include "Pokemod.h" // Qt includes #include Pokemod::Move::Move(const Move& move) : Object("Move", move.parent(), move.id()) { *this = move; } Pokemod::Move::Move(const Pokemod* parent, const int id) : Object("Move", parent, id), m_name(""), m_accuracy(1, 1), m_power(0), m_type(INT_MAX), m_special(false), m_overworld(false), m_powerPoints(0), m_priority(0), m_description(""), m_script("", "") { } Pokemod::Move::Move(const Move& move, const Pokemod* parent, const int id) : Object("Move", parent, id) { *this = move; } Pokemod::Move::Move(const QDomElement& xml, const Pokemod* parent, const int id) : Object("Move", parent, id) { LOAD_ID(); load(xml); } Pokemod::Move::~Move() { clear(); } void Pokemod::Move::validate() { TEST_BEGIN(); if (m_name.isEmpty()) emit(error("Name is empty")); TEST(setType, type); TEST(setPowerPoints, powerPoints); TEST_END(); } void Pokemod::Move::load(const QDomElement& xml) { LOAD_BEGIN(); LOAD(QString, name); LOAD(Fraction, accuracy); LOAD(int, power); LOAD(int, type); LOAD(bool, special); LOAD(bool, overworld); LOAD(int, powerPoints); LOAD(int, priority); LOAD(QString, description); LOAD(Script, script); } QDomElement Pokemod::Move::save() const { SAVE_CREATE(); SAVE(QString, name); SAVE(Fraction, accuracy); SAVE(int, power); SAVE(int, type); SAVE(bool, special); SAVE(bool, overworld); SAVE(int, powerPoints); SAVE(int, priority); SAVE(QString, description); SAVE(Script, script); return xml; } void Pokemod::Move::setName(const QString& name) { CHECK(name); } void Pokemod::Move::setAccuracy(const Fraction& accuracy) { if (1 < accuracy) { emit(error(bounds("accuracy"))); return; } CHECK(accuracy); } void Pokemod::Move::setPower(const int power) { CHECK(power); } void Pokemod::Move::setType(const int type) { if (static_cast(pokemod())->typeIndex(type) == INT_MAX) { emit(error(bounds("type"))); return; } CHECK(type); } void Pokemod::Move::setSpecial(const bool special) { CHECK(special); } void Pokemod::Move::setOverworld(const bool overworld) { CHECK(overworld); } void Pokemod::Move::setPowerPoints(const int powerPoints) { if (!powerPoints) { emit(error(bounds("powerPoints"))); return; } CHECK(powerPoints); } void Pokemod::Move::setPriority(const int priority) { CHECK(priority); } void Pokemod::Move::setDescription(const QString& description) { CHECK(description); } void Pokemod::Move::setScript(const Script& script) { CHECK(script); } QString Pokemod::Move::name() const { return m_name; } Pokemod::Fraction Pokemod::Move::accuracy() const { return m_accuracy; } int Pokemod::Move::power() const { return m_power; } int Pokemod::Move::type() const { return m_type; } bool Pokemod::Move::special() const { return m_special; } bool Pokemod::Move::overworld() const { return m_overworld; } int Pokemod::Move::powerPoints() const { return m_powerPoints; } int Pokemod::Move::priority() const { return m_priority; } QString Pokemod::Move::description() const { return m_description; } Pokemod::Script Pokemod::Move::script() const { return m_script; } Pokemod::Move& Pokemod::Move::operator=(const Move& rhs) { if (this == &rhs) return *this; COPY(name); COPY(accuracy); COPY(power); COPY(type); COPY(special); COPY(overworld); COPY(powerPoints); COPY(priority); COPY(description); COPY(script); return *this; }