/* * 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 "Dialog.h" #include "Map.h" #include "Pokemod.h" const QStringList MapWarp::TypeStr = QStringList() << "Door/Stair" << "Warp Pad" << "Hole" << "Boundary"; MapWarp::MapWarp(const MapWarp& warp) : Object("MapWarp", warp.parent(), warp.id()) { *this = warp; } MapWarp::MapWarp(const Map* parent, const int id) : Object("MapWarp", parent, id), m_name(""), m_coordinate(0, 0), m_directionOut(INT_MAX), m_type(INT_MAX), m_isBiking(Flag::Ignore), m_isFlash(Flag::Ignore), m_isFoggy(Flag::Ignore), m_toMap(INT_MAX), m_toWarp(INT_MAX), m_workingFlag(0, 0), m_dialog(INT_MAX) { for (int i = 0; i < Pokemod::D_End; ++i) m_from[i] = false; } MapWarp::MapWarp(const MapWarp& warp, const Map* parent, const int id) : Object("MapWarp", parent, id) { *this = warp; } MapWarp::MapWarp(const QDomElement& xml, const Map* parent, const int id) : Object("MapWarp", parent, id) { load(xml, id); } void MapWarp::validate() { if (m_name.isEmpty()) emit(error("Name is empty")); if (!m_from[Pokemod::D_Up] && !m_from[Pokemod::D_Down] && !m_from[Pokemod::D_Left] && !m_from[Pokemod::D_Right]) emit(error("No access from any direction")); TEST(setDirectionOut, directionOut); TEST(setType, type); TEST(setToMap, toMap); TEST(setToWarp, toWarp); TEST(setDialog, dialog); } void MapWarp::load(const QDomElement& xml, int id) { LOAD_ID(); LOAD(QString, name); LOAD(Point, coordinate); LOAD_ARRAY(bool, from, Pokemod::D_End); LOAD(int, directionOut); LOAD(int, type); LOAD(bool, isBiking); LOAD(bool, isFlash); LOAD(bool, isFoggy); LOAD(int, toMap); LOAD(int, toWarp); LOAD(Flag, workingFlag); LOAD(int, dialog); } QDomElement MapWarp::save() const { SAVE_CREATE(); SAVE(QString, name); SAVE(Point, coordinate); SAVE_ARRAY(bool, from, Pokemod::D_End); SAVE(int, directionOut); SAVE(int, type); SAVE(bool, isBiking); SAVE(bool, isFlash); SAVE(bool, isFoggy); SAVE(int, toMap); SAVE(int, toWarp); SAVE(Flag, workingFlag); SAVE(int, dialog); return xml; } void MapWarp::setName(const QString& name) { m_name = name; emit(changed()); } void MapWarp::setCoordinate(const Point& coordinate) { if ((static_cast(parent())->width() <= coordinate.x()) || (static_cast(parent())->height() <= coordinate.y())) { emit(error(bounds("coordinate"))); return; } m_coordinate = coordinate; emit(changed()); } void MapWarp::setFrom(const int direction, const bool can) { if (Pokemod::D_End <= direction) { emit(error(bounds("direction"))); return; } m_from[direction] = can; emit(changed()); } void MapWarp::setDirectionOut(const int directionOut) { if (Pokemod::D_End <= directionOut) { emit(error(bounds("direction"))); return; } m_directionOut = directionOut; emit(changed()); } void MapWarp::setType(const int type) { if (End <= type) { emit(error(bounds("type"))); return; } m_type = type; emit(changed()); } void MapWarp::setIsBiking(const int isBiking) { if (Flag::End <= isBiking) { emit(error(bounds("isBiking"))); return; } m_isBiking = isBiking; emit(changed()); } void MapWarp::setIsFlash(const int isFlash) { if (Flag::End <= isFlash) { emit(error(bounds("isFlash"))); return; } m_isFlash = isFlash; emit(changed()); } void MapWarp::setIsFoggy(const int isFoggy) { if (Flag::End <= isFoggy) { emit(error(bounds("isFoggy"))); return; } m_isFoggy = isFoggy; emit(changed()); } void MapWarp::setToMap(const int toMap) { if (static_cast(pokemod())->mapIndex(toMap) == INT_MAX) { emit(error(bounds("toMap"))); return; } m_toMap = toMap; m_toWarp = INT_MAX; emit(changed()); } void 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; } m_toWarp = toWarp; emit(changed()); } void MapWarp::setWorkingFlag(const Flag& workingFlag) { m_workingFlag = workingFlag; emit(changed()); } void MapWarp::setDialog(const int dialog) { if (static_cast(pokemod())->dialogIndex(dialog) == INT_MAX) { emit(error(bounds("dialog"))); return; } m_dialog = dialog; emit(changed()); } QString MapWarp::name() const { return m_name; } Point MapWarp::coordinate() const { return m_coordinate; } bool MapWarp::from(const int direction) const { if (Pokemod::D_End <= direction) { emit(warning(bounds("direction"))); return false; } return m_from[direction]; } int MapWarp::directionOut() const { return m_directionOut; } int MapWarp::type() const { return m_type; } int MapWarp::isBiking() const { return m_isBiking; } int MapWarp::isFlash() const { return m_isFlash; } int MapWarp::isFoggy() const { return m_isFoggy; } int MapWarp::toMap() const { return m_toMap; } int MapWarp::toWarp() const { return m_toWarp; } Flag MapWarp::workingFlag() const { return m_workingFlag; } int MapWarp::dialog() const { return m_dialog; } MapWarp& MapWarp::operator=(const MapWarp& rhs) { if (this == &rhs) return *this; COPY(name); COPY(coordinate); COPY_ARRAY(from, Pokemod::D_End); COPY(directionOut); COPY(type); COPY(isBiking); COPY(isFlash); COPY(isFoggy); COPY(toMap); COPY(toWarp); COPY(workingFlag); COPY(dialog); return *this; }