///////////////////////////////////////////////////////////////////////////// // Name: pokemod/MapEffect.cpp // Purpose: Define an effect for a map // Author: Ben Boeckel // Modified by: Ben Boeckel // Created: Fri June 1 2007 20:23:15 // 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 . ///////////////////////////////////////////////////////////////////////////// #include "Pokemod.h" #include "Dialog.h" #include "MapEffect.h" const QStringList MapEffect::MapEffectStr = QStringList() << "Item" << "PC" << "Strength Block" << "Button" << "Slot Machine" << "Card Flip Game"; const QStringList MapEffect::PCTypeStr = QStringList() << "Item" << "Pokémon" << "PokéDex" << "Hall of Fame" << "All"; MapEffect::MapEffect(const Pokemod* par, const int _id) : Object("MapEffect", par, _id), name(""), coordinate(0, 0), existFlag(0, 0), skin(""), effect(-1), val1(-1), val2(-1), direction(-1), isGhost(false), canMove(false), dialog(-1) { } MapEffect::MapEffect(const Pokemod* par, const MapEffect& e, const int _id) : Object("MapEffect", par, _id) { *this = e; } MapEffect::MapEffect(const Pokemod* par, const QString& fname, const int _id) : Object("MapEffect", par, _id) { load(fname, _id); } bool MapEffect::validate() const { bool valid = true; pokemod->validationMsg(QString("------Effect \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); if (name == "") { pokemod->validationMsg("Name is not defined"); valid = false; } if (Flag::End <= existFlag.getStatus()) { pokemod->validationMsg("Invalid existence flag status"); valid = false; } if (!QFile::exists(getSkin())) { pokemod->validationMsg(QString("Skin not found")); valid = false; } if (effect < E_End) { bool ok = true; switch (effect) { case E_Item: if (pokemod->getItemIndex(val2) == -1) ok = false; break; case E_PC: if (PC_End <= val2) ok = false; break; case E_StrengthBlock: case E_Button: if (Flag::End <= val2) ok = false; break; } if (!ok) { pokemod->validationMsg("Invalid val2"); valid = false; } } else { pokemod->validationMsg("Invalid effect"); valid = false; } if (Pokemod::D_End_None <= direction) { pokemod->validationMsg("Invalid driection"); valid = false; } if (pokemod->getDialogIndex(dialog) == -1) { pokemod->validationMsg("Invalid dialog"); valid = false; } return valid; } void MapEffect::load(const QString& fname, const int _id) throw(Exception) { Ini ini(fname); if (_id == -1) ini.getValue("id", id); else id = _id; int i; int j; ini.getValue("name", name); ini.getValue("coordinate-x", i, 0); ini.getValue("coordinate-y", j, 0); coordinate.set(i, j); ini.getValue("existFlag-f", i, 0); ini.getValue("existFlag-s", j, 0); existFlag.set(i, j); ini.getValue("skin", skin); ini.getValue("effect", effect); ini.getValue("val1", val1); ini.getValue("val2", val2); ini.getValue("direction", direction); ini.getValue("isGhost", isGhost); ini.getValue("canMove", canMove); ini.getValue("dialog", dialog); } void MapEffect::save(const QString& map) const throw(Exception) { Ini ini; ini.addField("id", id); ini.addField("name", name); ini.addField("coordinate-x", coordinate.getX()); ini.addField("coordinate-y", coordinate.getY()); ini.addField("existFlag-f", existFlag.getFlag()); ini.addField("existFlag-s", existFlag.getStatus()); ini.addField("skin", skin); ini.addField("effect", effect); ini.addField("val1", val1); ini.addField("val2", val2); ini.addField("direction", direction); ini.addField("isGhost", isGhost); ini.addField("canMove", canMove); ini.addField("dialog", dialog); ini.save(QString("%1/map/%2/effect/%3.pini").arg(pokemod->getPath()).arg(map).arg(name)); } void MapEffect::setName(const QString& n) { name = n; } void MapEffect::setCoordinate(const int x, const int y) { coordinate.set(x, y); } void MapEffect::setCoordinateX(const int x) { coordinate.setX(x); } void MapEffect::setCoordinateY(const int y) { coordinate.setY(y); } void MapEffect::setExistFlag(const int f, const int s) { existFlag.set(f, s); } void MapEffect::setExistFlagFlag(const int f) { existFlag.setFlag(f); } void MapEffect::setExistFlagStatus(const int s) { existFlag.setStatus(s); } void MapEffect::setSkin(const QString& s) throw(Exception) { if (!QFile::exists(QString("%1/image/skin/%2.png").arg(pokemod->getPath()).arg(s))) throw(Exception(className, "skin does not exist")); skin = s; } void MapEffect::setEffect(const int e) throw(BoundsException) { if (E_End <= e) throw(BoundsException(className, "effect")); effect = e; val1 = -1; val2 = -1; } void MapEffect::setVal1(const int v1) throw(UnusedException) { if ((effect != E_StrengthBlock) && (effect != E_Button)) throw(UnusedException(className, "val1")); val1 = v1; } void MapEffect::setVal2(const int v2) throw(Exception) { switch (effect) { case E_Item: if (pokemod->getItemIndex(val2) == -1) throw(BoundsException(className, "val2")); break; case E_PC: if (PC_End <= val2) throw(BoundsException(className, "val2")); break; case E_StrengthBlock: case E_Button: if (Flag::End <= val2) throw(BoundsException(className, "val2")); break; default: throw(UnusedException(className, "val2")); break; } val2 = v2; } void MapEffect::setDirection(const int d) throw(BoundsException) { if (Pokemod::D_End_None <= d) throw(BoundsException(className, "direction")); direction = d; } void MapEffect::setIsGhost(const bool i) { isGhost = i; } void MapEffect::setCanMove(const bool c) { canMove = c; } void MapEffect::setDialog(const int d) throw(BoundsException) { if (pokemod->getDialogIndex(d) == -1) throw(BoundsException(className, "dialog")); dialog = d; } QString MapEffect::getName() const { return name; } Point MapEffect::getCoordinate() const { return coordinate; } Flag MapEffect::getExistFlag() const { return existFlag; } QString MapEffect::getSkin() const { return QString("%1/image/skin/%2.png").arg(pokemod->getPath()).arg(skin); } int MapEffect::getEffect() const { return effect; } int MapEffect::getVal1() const { return val1; } int MapEffect::getVal2() const { return val2; } int MapEffect::getDirection() const { return direction; } bool MapEffect::getIsGhost() const { return isGhost; } bool MapEffect::getCanMove() const { return canMove; } int MapEffect::getDialog() const { return dialog; } MapEffect& MapEffect::operator=(const MapEffect& rhs) { if (this == &rhs) return *this; name = rhs.name; coordinate = rhs.coordinate; existFlag = rhs.existFlag; skin = rhs.skin; effect = rhs.effect; val1 = rhs.val1; val2 = rhs.val2; direction = rhs.direction; isGhost = rhs.isGhost; canMove = rhs.canMove; dialog = rhs.dialog; return *this; }