/* * 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" // Sigmod includes #include "Macros.h" #include "Sigmod.h" // Qt includes #include Sigmod::Move::Move(const Move& move) : Object(move.parent(), move.id()) { *this = move; } Sigmod::Move::Move(const Sigmod* parent, const int id) : Object(parent, id), m_name(""), m_accuracy(1, 1), m_power(0), m_type(INT_MAX), m_special(false), m_powerPoints(0), m_priority(0), m_description(""), m_battleScript("", ""), m_worldScript("", ""), m_priorityScript("", "") { } Sigmod::Move::Move(const Move& move, const Sigmod* parent, const int id) : Object(parent, id) { *this = move; } Sigmod::Move::Move(const QDomElement& xml, const Sigmod* parent, const int id) : Object(parent, id) { LOAD_ID(); load(xml); } Sigmod::Move::~Move() { clear(); } void Sigmod::Move::validate() { TEST_BEGIN(); if (m_name.isEmpty()) emit(error("Name is empty")); TEST(setAccuracy, accuracy); TEST(setType, type); TEST(setPowerPoints, powerPoints); TEST_END(); } void Sigmod::Move::load(const QDomElement& xml) { LOAD_BEGIN(); LOAD(name); LOAD(accuracy); LOAD(power); LOAD(type); LOAD(special); LOAD(powerPoints); LOAD(priority); LOAD(description); LOAD(battleScript); LOAD(worldScript); LOAD(priorityScript); } QDomElement Sigmod::Move::save() const { SAVE_CREATE(); SAVE(name); SAVE(accuracy); SAVE(power); SAVE(type); SAVE(special); SAVE(powerPoints); SAVE(priority); SAVE(description); SAVE(battleScript); SAVE(worldScript); SAVE(priorityScript); return xml; } void Sigmod::Move::setName(const QString& name) { CHECK(name); } void Sigmod::Move::setAccuracy(const Fraction& accuracy) { if (!accuracy || (1 < accuracy)) emit(error(bounds("accuracy"))); else CHECK(accuracy); } void Sigmod::Move::setPower(const int power) { CHECK(power); } void Sigmod::Move::setType(const int type) { if (qobject_cast(sigmod())->typeIndex(type) == INT_MAX) emit(error(bounds("type"))); else CHECK(type); } void Sigmod::Move::setSpecial(const bool special) { CHECK(special); } void Sigmod::Move::setPowerPoints(const int powerPoints) { if (!powerPoints) emit(error(bounds("powerPoints"))); else CHECK(powerPoints); } void Sigmod::Move::setPriority(const int priority) { CHECK(priority); } void Sigmod::Move::setDescription(const QString& description) { CHECK(description); } void Sigmod::Move::setBattleScript(const Script& battleScript) { CHECK(battleScript); } void Sigmod::Move::setWorldScript(const Script& worldScript) { CHECK(worldScript); } void Sigmod::Move::setPriorityScript(const Script& priorityScript) { CHECK(priorityScript); } QString Sigmod::Move::name() const { return m_name; } Sigmod::Fraction Sigmod::Move::accuracy() const { return m_accuracy; } int Sigmod::Move::power() const { return m_power; } int Sigmod::Move::type() const { return m_type; } bool Sigmod::Move::special() const { return m_special; } int Sigmod::Move::powerPoints() const { return m_powerPoints; } int Sigmod::Move::priority() const { return m_priority; } QString Sigmod::Move::description() const { return m_description; } Sigmod::Script Sigmod::Move::battleScript() const { return m_battleScript; } Sigmod::Script Sigmod::Move::worldScript() const { return m_worldScript; } Sigmod::Script Sigmod::Move::priorityScript() const { return m_priorityScript; } Sigmod::Move& Sigmod::Move::operator=(const Move& rhs) { if (this == &rhs) return *this; COPY(name); COPY(accuracy); COPY(power); COPY(type); COPY(special); COPY(powerPoints); COPY(priority); COPY(description); COPY(battleScript); COPY(worldScript); COPY(priorityScript); return *this; }