/* * 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 Pokemod* 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 Pokemod* parent, const int id) : Object("Tile", parent, id) { *this = tile; } Tile::Tile(const QDomElement& xml, const Pokemod* parent, const int id) : Object("Tile", parent, id) { load(xml, id); } void Tile::validate() { if (m_name.isEmpty()) emit(error("Name is empty")); TEST(setSprite, sprite); TEST(setWildChance, wildChance); TEST(setHmType, hmType); TEST(setUnder, under); TEST(setForceType, forceType); TEST(setForceDirection, forceDirection); } 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) { if (sprite.size() != QSize(64, 64)) { emit(error(size("sprite"))); return; } m_sprite = sprite; } void Tile::setFrom(const int direction, const bool state) { if (Pokemod::D_End <= direction) { emit(error(bounds("direction"))); return; } m_from[direction] = state; } void Tile::setWildChance(const Fraction& wildChance) { if (1 < wildChance) { emit(error(bounds("wildChance"))); return; } m_wildChance = wildChance; } void Tile::setHmType(const int hmType) { if (Pokemod::HM_End <= hmType) { emit(error(bounds("hmType"))); return; } if (((hmType == Pokemod::HM_Waterfall) || (hmType == Pokemod::HM_RockClimb)) && (!m_from[Pokemod::D_Up] || !m_from[Pokemod::D_Down])) { emit(error("Accessibility for HM type")); return; } m_hmType = hmType; m_under = INT_MAX; } void Tile::setUnder(const int under) { if (m_hmType != INT_MAX) { if ((m_hmType != Pokemod::HM_Whirlpool) || (m_hmType != Pokemod::HM_Cut) || (m_hmType != Pokemod::HM_RockSmash)) { emit(warning(unused("under"))); return; } if ((under == id()) || (static_cast(pokemod())->tileIndex(under) == INT_MAX)) { emit(error(bounds("under"))); return; } } m_under = under; } void Tile::setForceType(const int forceType) { if (End <= forceType) { emit(error(bounds("forceType"))); return; } m_forceType = forceType; } void Tile::setForceDirection(const int forceDirection) { if (m_forceType != INT_MAX) { if (m_forceType == Stop) { emit(warning(unused("forceDirection"))); return; } if (Pokemod::D_End <= forceDirection) { emit(error(bounds("forceDirection"))); return; } } m_forceDirection = forceDirection; } QString Tile::name() const { return m_name; } QPixmap Tile::sprite() const { return m_sprite; } bool Tile::from(const int direction) const { if (Pokemod::D_End <= direction) { emit(warning(bounds("direction"))); return false; } 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; }