diff options
Diffstat (limited to 'pokemod/MapWarp.cpp')
| -rw-r--r-- | pokemod/MapWarp.cpp | 376 |
1 files changed, 177 insertions, 199 deletions
diff --git a/pokemod/MapWarp.cpp b/pokemod/MapWarp.cpp index 35d56de7..050b02e9 100644 --- a/pokemod/MapWarp.cpp +++ b/pokemod/MapWarp.cpp @@ -1,338 +1,316 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/MapWarp.cpp -// Purpose: Define a warp for a map -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Fri June 1 2007 20:46:23 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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 <http://www.gnu.org/licenses/>. -///////////////////////////////////////////////////////////////////////////// - +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Pokemod includes #include "Pokemod.h" #include "Dialog.h" #include "Map.h" + +// Header include #include "MapWarp.h" const QStringList MapWarp::TypeStr = QStringList() << "Door/Stair" << "Warp Pad" << "Hole" << "Boundary"; -MapWarp::MapWarp(const Pokemod* par, const int _id) : - Object("MapWarp", par, _id), - name(""), - coordinate(0, 0), - directionOut(-1), - warpType(-1), - isBiking(Flag::Ignore), - isFlash(Flag::Ignore), - isFoggy(Flag::Ignore), - toMap(-1), - toWarp(-1), - workingFlag(0, 0), - dialog(-1) +MapWarp::MapWarp(const Pokemod* pokemod, const int id) : + Object("MapWarp", pokemod, id), + m_name(""), + m_coordinate(0, 0), + m_directionOut(INT_MAX), + m_warpType(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) - from[i] = false; + m_from[i] = false; } -MapWarp::MapWarp(const Pokemod* par, const MapWarp& w, const int _id) : - Object("MapWarp", par, _id) +MapWarp::MapWarp(const Pokemod* pokemod, const MapWarp& warp, const int id) : + Object("MapWarp", pokemod, id) { - *this = w; + *this = warp; } -MapWarp::MapWarp(const Pokemod* par, const QString& fname, const int _id) : - Object("MapWarp", par, _id) +MapWarp::MapWarp(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("MapWarp", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool MapWarp::validate() const { bool valid = true; - pokemod->validationMsg(QString("------Warp \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("------Warp \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name is not defined"); + pokemod()->validationMsg("Name is not defined"); valid = false; } - if (!from[Pokemod::D_Up] && !from[Pokemod::D_Down] && !from[Pokemod::D_Left] && !from[Pokemod::D_Right]) + if (!m_from[Pokemod::D_Up] && !m_from[Pokemod::D_Down] && !m_from[Pokemod::D_Left] && !m_from[Pokemod::D_Right]) { - pokemod->validationMsg("No access from any direction"); + pokemod()->validationMsg("No access from any direction"); valid = false; } - if (Pokemod::D_End_None <= directionOut) + if (Pokemod::D_End_None <= m_directionOut) { - pokemod->validationMsg("Invalid direction out"); + pokemod()->validationMsg("Invalid direction out"); valid = false; } - if (End <= warpType) + if (End <= m_warpType) { - pokemod->validationMsg("Invalid type"); + pokemod()->validationMsg("Invalid type"); valid = false; } - if (pokemod->getMapIndex(toMap) != -1) + if (pokemod()->mapIndex(m_toMap) != INT_MAX) { - if (pokemod->getMapByID(toMap)->getWarpIndex(toWarp) == -1) + if (pokemod()->mapById(m_toMap)->warpIndex(m_toWarp) == INT_MAX) { - pokemod->validationMsg("Invalid destnation warp"); + pokemod()->validationMsg("Invalid destination warp"); valid = false; } } else { - pokemod->validationMsg("Invalid destination map"); + pokemod()->validationMsg("Invalid destination map"); valid = false; } - if (pokemod->getDialogIndex(dialog) == -1) + if (pokemod()->dialogIndex(m_dialog) == INT_MAX) { - pokemod->validationMsg("Invalid dialog"); + pokemod()->validationMsg("Invalid dialog"); valid = false; } return valid; } -void MapWarp::load(const QString& fname, const int _id) throw(Exception) +void MapWarp::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(id); int i; int j; - ini.getValue("name", name); + ini.getValue("name", m_name); ini.getValue("coordinate-x", i, 0); ini.getValue("coordinate-y", j, 0); - coordinate.set(i, j); - ini.getValue("from-up", from[Pokemod::D_Up], false); - ini.getValue("from-down", from[Pokemod::D_Down], false); - ini.getValue("from-left", from[Pokemod::D_Left], false); - ini.getValue("from-right", from[Pokemod::D_Right], false); - ini.getValue("directionOut", directionOut); - ini.getValue("warpType", warpType); - ini.getValue("isBiking", isBiking, false); - ini.getValue("isFlash", isFlash, false); - ini.getValue("isFoggy", isFoggy, false); - ini.getValue("toMap", toMap); - ini.getValue("toWarp", toWarp); + m_coordinate.set(i, j); + ini.getValue("from-up", m_from[Pokemod::D_Up], false); + ini.getValue("from-down", m_from[Pokemod::D_Down], false); + ini.getValue("from-left", m_from[Pokemod::D_Left], false); + ini.getValue("from-right", m_from[Pokemod::D_Right], false); + ini.getValue("directionOut", m_directionOut); + ini.getValue("warpType", m_warpType); + ini.getValue("isBiking", m_isBiking, false); + ini.getValue("isFlash", m_isFlash, false); + ini.getValue("isFoggy", m_isFoggy, false); + ini.getValue("toMap", m_toMap); + ini.getValue("toWarp", m_toWarp); ini.getValue("workingFlag-f", i, 0); ini.getValue("workingFlag-s", j, 0); - workingFlag.set(i, j); - ini.getValue("dialog", dialog); + m_workingFlag.set(i, j); + ini.getValue("dialog", m_dialog); } void MapWarp::save(const QString& map) const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("coordinate-x", coordinate.getX()); - ini.addField("coordinate-y", coordinate.getY()); - ini.addField("from-up", from[Pokemod::D_Up]); - ini.addField("from-down", from[Pokemod::D_Down]); - ini.addField("from-left", from[Pokemod::D_Left]); - ini.addField("from-right", from[Pokemod::D_Right]); - ini.addField("directionOut", directionOut); - ini.addField("warpType", warpType); - ini.addField("isBiking", isBiking); - ini.addField("isFlash", isFlash); - ini.addField("isFoggy", isFoggy); - ini.addField("toMap", toMap); - ini.addField("toWarp", toWarp); - ini.addField("workingFlag-f", workingFlag.getFlag()); - ini.addField("workingFlag-s", workingFlag.getStatus()); - ini.addField("dialog", dialog); - ini.save(QString("%1/map/%2/warp/%3.pini").arg(pokemod->getPath()).arg(map).arg(name)); -} - -void MapWarp::setName(const QString& n) -{ - name = n; + ini.addField("id", id()); + ini.addField("coordinate-x", m_coordinate.x()); + ini.addField("coordinate-y", m_coordinate.y()); + ini.addField("from-up", m_from[Pokemod::D_Up]); + ini.addField("from-down", m_from[Pokemod::D_Down]); + ini.addField("from-left", m_from[Pokemod::D_Left]); + ini.addField("from-right", m_from[Pokemod::D_Right]); + ini.addField("directionOut", m_directionOut); + ini.addField("warpType", m_warpType); + ini.addField("isBiking", m_isBiking); + ini.addField("isFlash", m_isFlash); + ini.addField("isFoggy", m_isFoggy); + ini.addField("toMap", m_toMap); + ini.addField("toWarp", m_toWarp); + ini.addField("workingFlag-f", m_workingFlag.flag()); + ini.addField("workingFlag-s", m_workingFlag.status()); + ini.addField("dialog", m_dialog); + ini.save(QString("%1/map/%2/warp/%3.pini").arg(pokemod()->path()).arg(map).arg(m_name)); +} + +void MapWarp::setName(const QString& name) +{ + m_name = name; } void MapWarp::setCoordinate(const int x, const int y) { - coordinate.set(x, y); -} - -void MapWarp::setCoordinateX(const int x) -{ - coordinate.setX(x); + m_coordinate.set(x, y); } -void MapWarp::setCoordinateY(const int y) +void MapWarp::setFrom(const int direction, const bool can) throw(BoundsException) { - coordinate.setY(y); + if (Pokemod::D_End <= direction) + throw(BoundsException(className(), "direction")); + m_from[direction] = can; } -void MapWarp::setFrom(const int d, const bool f) throw(BoundsException) +void MapWarp::setDirectionOut(const int directionOut) throw(BoundsException) { - if (Pokemod::D_End <= d) - throw(BoundsException(className, "direction")); - from[d] = f; + if (Pokemod::D_End <= directionOut) + throw(BoundsException(className(), "direction")); + m_directionOut = directionOut; } -void MapWarp::setDirectionOut(const int d) throw(BoundsException) +void MapWarp::setWarpType(const int warpType) throw(BoundsException) { - if (Pokemod::D_End <= d) - throw(BoundsException(className, "direction")); - directionOut = d; -} - -void MapWarp::setWarpType(const int w) throw(BoundsException) -{ - if (End <= w) - throw(BoundsException(className, "warpType")); - warpType = w; -} - -void MapWarp::setIsBiking(const int i) throw(BoundsException) -{ - if (Flag::End <= i) - throw(BoundsException(className, "isBiking")); - isBiking = i; -} - -void MapWarp::setIsFlash(const int i) throw(BoundsException) -{ - if (Flag::End <= i) - throw(BoundsException(className, "isFlash")); - isFlash = i; + if (End <= warpType) + throw(BoundsException(className(), "warpType")); + m_warpType = warpType; } -void MapWarp::setIsFoggy(const int i) throw(BoundsException) +void MapWarp::setIsBiking(const int isBiking) throw(BoundsException) { - if (Flag::End <= i) - throw(BoundsException(className, "isFoggy")); - isFoggy = i; + if (Flag::End <= isBiking) + throw(BoundsException(className(), "isBiking")); + m_isBiking = isBiking; } -void MapWarp::setToMap(const int t) throw(BoundsException) +void MapWarp::setIsFlash(const int isFlash) throw(BoundsException) { - if (pokemod->getMapIndex(t) == -1) - throw(BoundsException(className, "toMap")); - toMap = t; - toWarp = -1; + if (Flag::End <= isFlash) + throw(BoundsException(className(), "isFlash")); + m_isFlash = isFlash; } -void MapWarp::setToWarp(const int t) throw(BoundsException) +void MapWarp::setIsFoggy(const int isFoggy) throw(BoundsException) { - if (pokemod->getMapIndex(toMap) == -1) - throw(BoundsException(className, "toMap")); - if (pokemod->getMapByID(toMap)->getWarpIndex(t) == -1) - throw(BoundsException(className, "toWarp")); + if (Flag::End <= isFoggy) + throw(BoundsException(className(), "isFoggy")); + m_isFoggy = isFoggy; } -void MapWarp::setWorkingFlag(const int f, const int s) +void MapWarp::setToMap(const int toMap) throw(BoundsException) { - workingFlag.set(f, s); + if (pokemod()->mapIndex(toMap) == INT_MAX) + throw(BoundsException(className(), "toMap")); + m_toMap = toMap; + m_toWarp = INT_MAX; } -void MapWarp::setWorkingFlagFlag(const int f) +void MapWarp::setToWarp(const int toWarp) throw(BoundsException) { - workingFlag.setFlag(f); + if (pokemod()->mapIndex(m_toMap) == INT_MAX) + throw(BoundsException(className(), "toMap")); + if (pokemod()->mapById(m_toMap)->warpIndex(toWarp) == INT_MAX) + throw(BoundsException(className(), "toWarp")); + m_toWarp = toWarp; } -void MapWarp::setWorkingFlagStatus(const int s) +void MapWarp::setWorkingFlag(const int flag, const int status) { - workingFlag.setStatus(s); + m_workingFlag.set(flag, status); } -void MapWarp::setDialog(const int d) throw(BoundsException) +void MapWarp::setDialog(const int dialog) throw(BoundsException) { - if (pokemod->getDialogIndex(d) == -1) - throw(BoundsException(className, "dialog")); - dialog = d; + if (pokemod()->dialogIndex(dialog) == INT_MAX) + throw(BoundsException(className(), "dialog")); + m_dialog = dialog; } -QString MapWarp::getName() const +QString MapWarp::name() const { - return name; + return m_name; } -Point MapWarp::getCoordinate() const +Point MapWarp::coordinate() const { - return coordinate; + return m_coordinate; } -bool MapWarp::getFrom(const int d) const throw(BoundsException) +bool MapWarp::from(const int direction) const throw(BoundsException) { - if (Pokemod::D_End <= d) - throw(BoundsException(className, "direction")); - return from[d]; + if (Pokemod::D_End <= direction) + throw(BoundsException(className(), "direction")); + return m_from[direction]; } -int MapWarp::getDirectionOut() const +int MapWarp::directionOut() const { - return directionOut; + return m_directionOut; } -int MapWarp::getWarpType() const +int MapWarp::warpType() const { - return warpType; + return m_warpType; } -int MapWarp::getIsBiking() const +int MapWarp::isBiking() const { - return isBiking; + return m_isBiking; } -int MapWarp::getIsFlash() const +int MapWarp::isFlash() const { - return isFlash; + return m_isFlash; } -int MapWarp::getIsFoggy() const +int MapWarp::isFoggy() const { - return isFoggy; + return m_isFoggy; } -int MapWarp::getToMap() const +int MapWarp::toMap() const { - return toMap; + return m_toMap; } -int MapWarp::getToWarp() const +int MapWarp::toWarp() const { - return toWarp; + return m_toWarp; } -Flag MapWarp::getWorkingFlag() const +Flag MapWarp::workingFlag() const { - return workingFlag; + return m_workingFlag; } -int MapWarp::getDialog() const +int MapWarp::dialog() const { - return dialog; + return m_dialog; } MapWarp& MapWarp::operator=(const MapWarp& rhs) { if (this == &rhs) return *this; - name = rhs.name; - coordinate = rhs.coordinate; + m_name = rhs.m_name; + m_coordinate = rhs.m_coordinate; for (int i = 0; i < Pokemod::D_End; ++i) - from[i] = rhs.from[i]; - directionOut = rhs.directionOut; - warpType = rhs.warpType; - isBiking = rhs.isBiking; - isFlash = rhs.isFlash; - isFoggy = rhs.isFoggy; - toMap = rhs.toMap; - toWarp = rhs.toWarp; - workingFlag = rhs.workingFlag; - dialog = rhs.dialog; + m_from[i] = rhs.m_from[i]; + m_directionOut = rhs.m_directionOut; + m_warpType = rhs.m_warpType; + m_isBiking = rhs.m_isBiking; + m_isFlash = rhs.m_isFlash; + m_isFoggy = rhs.m_isFoggy; + m_toMap = rhs.m_toMap; + m_toWarp = rhs.m_toWarp; + m_workingFlag = rhs.m_workingFlag; + m_dialog = rhs.m_dialog; return *this; } |
