/* * 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 . */ // Pokemod includes #include "Pokemod.h" #include "Dialog.h" // Header include #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* pokemod, const int id) : Object("MapEffect", pokemod, id), m_name(""), m_coordinate(0, 0), m_existFlag(0, 0), m_skin(""), m_effect(INT_MAX), m_value1(INT_MAX), m_value2(INT_MAX), m_direction(INT_MAX), m_isGhost(false), m_canMove(false), m_dialog(INT_MAX) { } MapEffect::MapEffect(const Pokemod* pokemod, const MapEffect& effect, const int id) : Object("MapEffect", pokemod, id) { *this = effect; } MapEffect::MapEffect(const Pokemod* pokemod, const QString& fileName, const int id) : Object("MapEffect", pokemod, id) { load(fileName, id); } bool MapEffect::validate() const { bool valid = true; pokemod()->validationMsg(QString("------Effect \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); if (m_name == "") { pokemod()->validationMsg("Name is not defined"); valid = false; } if (Flag::End <= m_existFlag.status()) { pokemod()->validationMsg("Invalid existence flag status"); valid = false; } if (!QFile::exists(skin())) { pokemod()->validationMsg(QString("Skin not found")); valid = false; } if (m_effect < E_End) { bool ok = true; switch (m_effect) { case E_Item: if (pokemod()->itemIndex(m_value2) == INT_MAX) ok = false; break; case E_PC: if (PC_End <= m_value2) ok = false; break; case E_StrengthBlock: case E_Button: if (Flag::End <= m_value2) ok = false; break; } if (!ok) { pokemod()->validationMsg("Invalid val2"); valid = false; } } else { pokemod()->validationMsg("Invalid effect"); valid = false; } if (Pokemod::D_End_None <= m_direction) { pokemod()->validationMsg("Invalid driection"); valid = false; } if (pokemod()->dialogIndex(m_dialog) == INT_MAX) { pokemod()->validationMsg("Invalid dialog"); valid = false; } return valid; } void MapEffect::load(const QString& fileName, int id) throw(Exception) { Ini ini(fileName); if (id == INT_MAX) ini.getValue("id", id); setId(id); int i; int j; ini.getValue("name", m_name); ini.getValue("coordinate-x", i, 0); ini.getValue("coordinate-y", j, 0); m_coordinate.set(i, j); ini.getValue("existFlag-f", i, 0); ini.getValue("existFlag-s", j, 0); m_existFlag.set(i, j); ini.getValue("skin", m_skin); ini.getValue("effect", m_effect); ini.getValue("val1", m_value1); ini.getValue("val2", m_value2); ini.getValue("direction", m_direction); ini.getValue("isGhost", m_isGhost); ini.getValue("canMove", m_canMove); ini.getValue("dialog", m_dialog); } void MapEffect::save(const QString& map) const throw(Exception) { Ini ini; ini.addField("id", id()); ini.addField("name", m_name); ini.addField("coordinate-x", m_coordinate.x()); ini.addField("coordinate-y", m_coordinate.y()); ini.addField("existFlag-f", m_existFlag.flag()); ini.addField("existFlag-s", m_existFlag.status()); ini.addField("skin", m_skin); ini.addField("effect", m_effect); ini.addField("val1", m_value1); ini.addField("val2", m_value2); ini.addField("direction", m_direction); ini.addField("isGhost", m_isGhost); ini.addField("canMove", m_canMove); ini.addField("dialog", m_dialog); ini.save(QString("%1/map/%2/effect/%3.pini").arg(pokemod()->path()).arg(map).arg(m_name)); } void MapEffect::setName(const QString& name) { m_name = name; } void MapEffect::setCoordinate(const int x, const int y) { m_coordinate.set(x, y); } void MapEffect::setExistFlag(const int flag, const int status) { m_existFlag.set(flag, status); } void MapEffect::setSkin(const QString& skin) throw(Exception) { if (!QFile::exists(QString("%1/image/skin/%2.png").arg(pokemod()->path()).arg(skin))) throw(Exception(className(), "skin does not exist")); m_skin = skin; } void MapEffect::setEffect(const int effect) throw(BoundsException) { if (E_End <= effect) throw(BoundsException(className(), "effect")); m_effect = effect; m_value1 = INT_MAX; m_value2 = INT_MAX; } void MapEffect::setValue1(const int value1) throw(UnusedException) { if ((m_effect != E_StrengthBlock) && (m_effect != E_Button)) throw(UnusedException(className(), "val1")); m_value1 = value1; } void MapEffect::setValue2(const int value2) throw(Exception) { switch (m_effect) { case E_Item: if (pokemod()->itemIndex(value2) == INT_MAX) throw(BoundsException(className(), "val2")); break; case E_PC: if (PC_End <= value2) throw(BoundsException(className(), "val2")); break; case E_StrengthBlock: case E_Button: if (Flag::End <= value2) throw(BoundsException(className(), "val2")); break; default: throw(UnusedException(className(), "val2")); break; } m_value2 = value2; } void MapEffect::setDirection(const int direction) throw(BoundsException) { if (Pokemod::D_End_None <= direction) throw(BoundsException(className(), "direction")); m_direction = direction; } void MapEffect::setIsGhost(const bool isGhost) { m_isGhost = isGhost; } void MapEffect::setCanMove(const bool canMove) { m_canMove = canMove; } void MapEffect::setDialog(const int dialog) throw(BoundsException) { if (pokemod()->dialogIndex(dialog) == INT_MAX) throw(BoundsException(className(), "dialog")); m_dialog = dialog; } QString MapEffect::name() const { return m_name; } Point MapEffect::coordinate() const { return m_coordinate; } Flag MapEffect::existFlag() const { return m_existFlag; } QString MapEffect::skin() const { return QString("%1/image/skin/%2.png").arg(pokemod()->path()).arg(m_skin); } int MapEffect::effect() const { return m_effect; } int MapEffect::value1() const { return m_value1; } int MapEffect::value2() const { return m_value2; } int MapEffect::direction() const { return m_direction; } bool MapEffect::isGhost() const { return m_isGhost; } bool MapEffect::canMove() const { return m_canMove; } int MapEffect::dialog() const { return m_dialog; } MapEffect& MapEffect::operator=(const MapEffect& rhs) { if (this == &rhs) return *this; m_name = rhs.m_name; m_coordinate = rhs.m_coordinate; m_existFlag = rhs.m_existFlag; m_skin = rhs.m_skin; m_effect = rhs.m_effect; m_value1 = rhs.m_value1; m_value2 = rhs.m_value2; m_direction = rhs.m_direction; m_isGhost = rhs.m_isGhost; m_canMove = rhs.m_canMove; m_dialog = rhs.m_dialog; return *this; }