/* * 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 "MapWarp.h" // Pokemod includes #include "Macros.h" #include "Map.h" #include "Pokemod.h" const QStringList Pokemod::MapWarp::TypeStr = QStringList() << "Door/Stair" << "Warp Pad" << "Hole" << "Boundary"; Pokemod::MapWarp::MapWarp(const MapWarp& warp) : Object("MapWarp", warp.parent(), warp.id()) { *this = warp; } Pokemod::MapWarp::MapWarp(const Map* parent, const int id) : Object("MapWarp", parent, id), m_name(""), m_coordinate(0, 0), m_type(INT_MAX), m_toMap(INT_MAX), m_toWarp(INT_MAX), m_script("", "") { } Pokemod::MapWarp::MapWarp(const MapWarp& warp, const Map* parent, const int id) : Object("MapWarp", parent, id) { *this = warp; } Pokemod::MapWarp::MapWarp(const QDomElement& xml, const Map* parent, const int id) : Object("MapWarp", parent, id) { LOAD_ID(); load(xml); } void Pokemod::MapWarp::validate() { TEST_BEGIN(); if (m_name.isEmpty()) emit(error("Name is empty")); TEST(setType, type); TEST(setToMap, toMap); TEST(setToWarp, toWarp); TEST_END(); } void Pokemod::MapWarp::load(const QDomElement& xml) { LOAD_BEGIN(); LOAD(QString, name); LOAD(QPoint, coordinate); LOAD(int, type); LOAD(int, toMap); LOAD(int, toWarp); LOAD(Script, script); } QDomElement Pokemod::MapWarp::save() const { SAVE_CREATE(); SAVE(QString, name); SAVE(QPoint, coordinate); SAVE(int, type); SAVE(int, toMap); SAVE(int, toWarp); SAVE(Script, script); return xml; } void Pokemod::MapWarp::setName(const QString& name) { CHECK(name); } void Pokemod::MapWarp::setCoordinate(const QPoint& coordinate) { if ((static_cast(parent())->width() <= coordinate.x()) || (static_cast(parent())->height() <= coordinate.y())) { emit(error(bounds("coordinate"))); return; } CHECK(coordinate); } void Pokemod::MapWarp::setType(const int type) { if (End <= type) { emit(error(bounds("type"))); return; } CHECK(type); } void Pokemod::MapWarp::setToMap(const int toMap) { if (static_cast(pokemod())->mapIndex(toMap) == INT_MAX) { emit(error(bounds("toMap"))); return; } CHECK(toMap); } void Pokemod::MapWarp::setToWarp(const int toWarp) { if (static_cast(pokemod())->mapIndex(m_toMap) == INT_MAX) { emit(error(bounds("toMap"))); return; } if (static_cast(pokemod())->mapById(m_toMap)->warpIndex(toWarp) == INT_MAX) { emit(error(bounds("toWarp"))); return; } CHECK(toWarp); } void Pokemod::MapWarp::setScript(const Script& script) { CHECK(script); } QString Pokemod::MapWarp::name() const { return m_name; } QPoint Pokemod::MapWarp::coordinate() const { return m_coordinate; } int Pokemod::MapWarp::type() const { return m_type; } int Pokemod::MapWarp::toMap() const { return m_toMap; } int Pokemod::MapWarp::toWarp() const { return m_toWarp; } Pokemod::Script Pokemod::MapWarp::script() const { return m_script; } Pokemod::MapWarp& Pokemod::MapWarp::operator=(const MapWarp& rhs) { if (this == &rhs) return *this; COPY(name); COPY(coordinate); COPY(type); COPY(toMap); COPY(toWarp); COPY(script); return *this; }