/* * 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 "MapEffect.h" // Pokemod includes #include "Dialog.h" #include "Map.h" #include "Pokemod.h" // Qt includes #include const QStringList MapEffect::EffectStr = 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 MapEffect& effect) : Object("MapEffect", effect.parent(), effect.id()) { *this = effect; } MapEffect::MapEffect(const Map* parent, const int id) : Object("MapEffect", parent, id), m_name(""), m_coordinate(0, 0), m_existFlag(0, 0), m_skin(192, 128), 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 MapEffect& effect, const Map* parent, const int id) : Object("MapEffect", parent, id) { *this = effect; } MapEffect::MapEffect(const QDomElement& xml, const Map* parent, const int id) : Object("MapEffect", parent, id) { load(xml, id); } void MapEffect::validate() { if (m_name.isEmpty()) emit(error("Name is empty")); TEST(setCoordinate, coordinate); TEST(setSkin, skin); TEST(setEffect, effect); TEST(setValue1, value1); TEST(setValue2, value2); TEST(setDirection, direction); TEST(setDialog, dialog); } void MapEffect::load(const QDomElement& xml, int id) { LOAD_ID(); LOAD(QString, name); LOAD(Point, coordinate); LOAD(Flag, existFlag); LOAD(QPixmap, skin); LOAD(int, effect); LOAD(int, value1); LOAD(int, value2); LOAD(int, direction); LOAD(bool, isGhost); LOAD(bool, canMove); LOAD(int, dialog); } QDomElement MapEffect::save() const { SAVE_CREATE(); SAVE(QString, name); SAVE(Point, coordinate); SAVE(Flag, existFlag); SAVE(QPixmap, skin); SAVE(int, effect); SAVE(int, value1); SAVE(int, value2); SAVE(int, direction); SAVE(bool, isGhost); SAVE(bool, canMove); SAVE(int, dialog); return xml; } void MapEffect::setName(const QString& name) { m_name = name; emit(changed()); } void MapEffect::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 MapEffect::setExistFlag(const Flag& existFlag) { m_existFlag = existFlag; emit(changed()); } void MapEffect::setSkin(const QPixmap& skin) { if (skin.size() != QSize(192, 128)) { emit(error(size("skin"))); return; } m_skin = skin; emit(changed()); } void MapEffect::setEffect(const int effect) { if (E_End <= effect) { emit(error(bounds("effect"))); return; } m_effect = effect; m_value1 = INT_MAX; m_value2 = INT_MAX; emit(changed()); } void MapEffect::setValue1(const int value1) { if ((m_effect != E_Button) && (m_effect != E_StrengthBlock)) { emit(warning(unused("val1"))); return; } m_value1 = value1; emit(changed()); } void MapEffect::setValue2(const int value2) { switch (m_effect) { case E_Item: if (static_cast(pokemod())->itemIndex(value2) == INT_MAX) { emit(error(bounds("val2"))); return; } break; case E_PC: if (PC_End <= value2) { emit(error(bounds("val2"))); return; } break; case E_StrengthBlock: case E_Button: if (Flag::End <= value2) { emit(error(bounds("val2"))); return; } break; default: emit(warning(unused("val2"))); return; } m_value2 = value2; emit(changed()); } void MapEffect::setDirection(const int direction) { if (Pokemod::D_End_None <= direction) { emit(error(bounds("direction"))); return; } m_direction = direction; emit(changed()); } void MapEffect::setIsGhost(const bool isGhost) { m_isGhost = isGhost; emit(changed()); } void MapEffect::setCanMove(const bool canMove) { m_canMove = canMove; emit(changed()); } void MapEffect::setDialog(const int dialog) { if (static_cast(pokemod())->dialogIndex(dialog) == INT_MAX) { emit(error(bounds("dialog"))); return; } m_dialog = dialog; emit(changed()); } QString MapEffect::name() const { return m_name; } Point MapEffect::coordinate() const { return m_coordinate; } Flag MapEffect::existFlag() const { return m_existFlag; } QPixmap MapEffect::skin() const { return 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; COPY(name); COPY(coordinate); COPY(existFlag); COPY(skin); COPY(effect); COPY(value1); COPY(value2); COPY(direction); COPY(isGhost); COPY(canMove); COPY(dialog); return *this; }