/* * 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 "Tile.h" // Pokemod includes #include "Pokemod.h" // Qt includes #include const QStringList Tile::ForceStr = QStringList() << "Slip" << "Stop" << "Force" << "Push"; Tile::Tile(const Tile& tile) : Object("Tile", tile.parent(), tile.id()) { *this = tile; } Tile::Tile(const Object* parent, const int id) : Object("Tile", parent, id), m_name(""), m_sprite(64, 64), m_wildChance(1, 1), m_hmType(INT_MAX), m_under(INT_MAX), m_forceType(INT_MAX), m_forceDirection(INT_MAX) { for (int i = 0; i < Pokemod::D_End; ++i) m_from[i] = false; } Tile::Tile(const Tile& tile, const Object* parent, const int id) : Object("Tile", parent, id) { *this = tile; } Tile::Tile(const QDomElement& xml, const Object* parent, const int id) : Object("Tile", parent, id) { load(xml, id); } bool Tile::validate() const { // TODO: validate // bool valid = true; // static_cast(pokemod())->validationMsg(QString("---Tile \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); // if (m_name == "") // { // static_cast(pokemod())->validationMsg("Name is not defined"); // valid = false; // } // if ((m_hmType == Pokemod::HM_Waterfall) && (!m_from[Pokemod::D_Up] || !m_from[Pokemod::D_Down])) // { // static_cast(pokemod())->validationMsg("A waterfall tile must be accessible from above and below"); // valid = false; // } // else if ((m_hmType == Pokemod::HM_Whirlpool) && ((m_under == id()) || (static_cast(pokemod())->tileIndex(m_under) == INT_MAX) || (static_cast(pokemod())->tileById(m_under)->hmType() != Pokemod::HM_Surf) || (static_cast(pokemod())->tileById(m_under)->hmType() != Pokemod::HM_Dive))) // { // static_cast(pokemod())->validationMsg("Invalid under tile"); // valid = false; // } // else if ((m_hmType == Pokemod::HM_Whirlpool) && ((m_under == id()) || (static_cast(pokemod())->tileIndex(m_under) == INT_MAX) || (static_cast(pokemod())->tileById(m_under)->hmType() != Pokemod::HM_End))) // { // static_cast(pokemod())->validationMsg("Invalid under tile"); // valid = false; // } // else if ((m_hmType == Pokemod::HM_RockClimb) && (!m_from[Pokemod::D_Up] || !m_from[Pokemod::D_Down])) // { // static_cast(pokemod())->validationMsg("A rock climb tile must be accessible from above and below"); // valid = false; // } // if (m_forceType < End) // { // if (((m_forceType == Slip) || (m_forceType == Force) || (m_forceType == Push)) && (Pokemod::D_End <= m_forceDirection)) // { // static_cast(pokemod())->validationMsg("Invalid force direction"); // valid = false; // } // } // else // { // static_cast(pokemod())->validationMsg("Invalid force type"); // valid = false; // } // return valid; } void Tile::load(const QDomElement& xml, int id) { LOAD_ID(); LOAD(QString, name); LOAD(QPixmap, sprite); LOAD_ARRAY(bool, from, Pokemod::D_End); LOAD(Fraction, wildChance); LOAD(int, hmType); LOAD(int, under); LOAD(int, forceType); LOAD(int, forceDirection); } QDomElement Tile::save() const { SAVE_CREATE(); SAVE(QString, name); SAVE(QPixmap, sprite); SAVE_ARRAY(bool, from, Pokemod::D_End); SAVE(Fraction, wildChance); SAVE(int, hmType); SAVE(int, under); SAVE(int, forceType); SAVE(int, forceDirection); return xml; } void Tile::setName(const QString& name) { m_name = name; } void Tile::setSprite(const QPixmap& sprite) throw(SizeException) { if (sprite.size() != QSize(64, 64)) error("sprte"); m_sprite = sprite; } void Tile::setFrom(const int direction, const bool state) throw(BoundsException) { if (Pokemod::D_End <= direction) error("direction"); m_from[direction] = state; } void Tile::setWildChance(const Fraction& wildChance) throw(BoundsException) { if (1 < wildChance) error("wildChance"); m_wildChance = wildChance; } void Tile::setHMType(const int hmType) throw(BoundsException) { if (Pokemod::HM_End <= hmType) error("hmType"); m_hmType = hmType; m_under = INT_MAX; } void Tile::setUnder(const int under) throw(Exception) { if (m_hmType != INT_MAX) { if ((m_hmType != Pokemod::HM_Whirlpool) || (m_hmType != Pokemod::HM_Cut) || (m_hmType != Pokemod::HM_RockSmash)) error("under"); if ((under == id()) || (static_cast(pokemod())->tileIndex(under) == INT_MAX)) error("under"); } m_under = under; } void Tile::setForceType(const int forceType) throw(BoundsException) { if (End <= forceType) error("forceType"); m_forceType = forceType; } void Tile::setForceDirection(const int forceDirection) throw(Exception) { if (m_forceType != INT_MAX) { if (m_forceType == Stop) error("forceDirection"); if (Pokemod::D_End <= forceDirection) error("forceDirection"); } m_forceDirection = forceDirection; } QString Tile::name() const { return m_name; } QPixmap Tile::sprite() const { return m_sprite; } bool Tile::from(const int direction) const throw(BoundsException) { if (Pokemod::D_End <= direction) warning("direction"); return m_from[direction]; } Fraction Tile::wildChance() const { return m_wildChance; } int Tile::hmType() const { return m_hmType; } int Tile::under() const { return m_under; } int Tile::forceType() const { return m_forceType; } int Tile::forceDirection() const { return m_forceDirection; } Tile& Tile::operator=(const Tile& rhs) { if (this == &rhs) return *this; COPY(name); COPY_ARRAY(from, Pokemod::D_End); COPY(wildChance); COPY(hmType); COPY(under); COPY(forceType); COPY(forceDirection); return *this; }