/* * Copyright 2007-2009 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 "Map.h" // Sigmod includes #include "Game.h" #include "Macros.h" #include "MapEffect.h" #include "MapTile.h" #include "MapTrainer.h" #include "MapWarp.h" #include "MapWildList.h" // Qt includes #include using namespace Sigmod; Map::Map(const Map& map) : Object(map.parent(), map.id()), m_effects(this), m_tiles(this), m_trainers(this), m_warps(this), m_wildLists(this) { *this = map; } Map::Map(const Game* parent, const int id) : Object(parent, id), m_name(""), m_width(1), m_height(1), m_isWorld(false), m_effects(this), m_tiles(this), m_trainers(this), m_warps(this), m_wildLists(this) { } Map::Map(const Map& map, const Game* parent, const int id) : Object(parent, id), m_effects(this), m_tiles(this), m_trainers(this), m_warps(this), m_wildLists(this) { *this = map; } Map::Map(const QDomElement& xml, const Game* parent, const int id) : Object(parent, id), m_effects(this), m_tiles(this), m_trainers(this), m_warps(this), m_wildLists(this) { initXmlImport(xml, id); load(xml); } void Map::validate() { testBegin(); if (m_name.isEmpty()) emit(error("Name is empty")); TEST(width); TEST(height); QSet idChecker; QSet nameChecker; if (!m_effects.count()) emit(warning("There are no effects")); m_effects.validate(); for (int i = 0; i < m_effects.count(); ++i) { MapEffect* effect = m_effects.at(i); testSubclassValue(effect, effect->id(), "ID value", &idChecker); testSubclassValue(effect, effect->name(), "name", &nameChecker); } idChecker.clear(); nameChecker.clear(); if (!m_tiles.count()) emit(warning("There are no tiles")); m_tiles.validate(); for (int i = 0; i < m_tiles.count(); ++i) { MapTile* tile = m_tiles.at(i); testSubclassValue(tile, tile->id(), "ID value", &idChecker); } idChecker.clear(); if (!m_trainers.count()) emit(warning("There are no trainers")); m_trainers.validate(); for (int i = 0; i < m_trainers.count(); ++i) { MapTrainer* trainer = m_trainers.at(i); testSubclassValue(trainer, trainer->id(), "ID value", &idChecker); testSubclassValue(trainer, trainer->name(), "name", &nameChecker); } idChecker.clear(); nameChecker.clear(); if (!m_warps.count()) emit(error("There are no warps")); m_warps.validate(); for (int i = 0; i < m_warps.count(); ++i) { MapWarp* warp = m_warps.at(i); testSubclassValue(warp, warp->id(), "ID value", &idChecker); testSubclassValue(warp, warp->name(), "name", &nameChecker); } idChecker.clear(); if (!m_wildLists.count()) emit(warning("There are no wild lists")); m_wildLists.validate(); for (int i = 0; i < m_wildLists.count(); ++i) { MapWildList* wildList = m_wildLists.at(i); testSubclassValue(wildList, wildList->id(), "ID value", &idChecker); } testEnd(); } void Map::load(const QDomElement& xml) { clear(); loadValue(xml.firstChildElement("name"), &m_name); loadValue(xml.firstChildElement("width"), &m_width); loadValue(xml.firstChildElement("height"), &m_height); loadValue(xml.firstChildElement("isWorld"), &m_isWorld); m_effects.importXml(xml, "MapEffect"); m_tiles.importXml(xml, "MapTile"); m_trainers.importXml(xml, "MapTrainer"); m_warps.importXml(xml, "MapWarp"); m_wildLists.importXml(xml, "MapWildList"); } QDomElement Map::save() const { QDomElement xml = initXmlExport(); xml.appendChild(saveValue("name", m_name)); xml.appendChild(saveValue("width", m_width)); xml.appendChild(saveValue("height", m_height)); xml.appendChild(saveValue("isWorld", m_isWorld)); m_effects.exportXml(&xml); m_tiles.exportXml(&xml); m_trainers.exportXml(&xml); m_warps.exportXml(&xml); m_wildLists.exportXml(&xml); return xml; } SETTER(Map, QString&, Name, name) SETTER(Map, int, Width, width) SETTER(Map, int, Height, height) SETTER(Map, bool, IsWorld, isWorld) GETTER(Map, QString, name) GETTER(Map, int, width) GETTER(Map, int, height) GETTER(Map, bool, isWorld) const Map::Effects& Map::effects() const { return m_effects; } Map::Effects& Map::effects() { return m_effects; } const Map::Tiles& Map::tiles() const { return m_tiles; } Map::Tiles& Map::tiles() { return m_tiles; } const Map::Trainers& Map::trainers() const { return m_trainers; } Map::Trainers& Map::trainers() { return m_trainers; } const Map::Warps& Map::warps() const { return m_warps; } Map::Warps& Map::warps() { return m_warps; } const Map::WildLists& Map::wildLists() const { return m_wildLists; } Map::WildLists& Map::wildLists() { return m_wildLists; } CHECK(Map, QString&, name) CHECK_BOUNDS(Map, int, width, 1, INT_MAX) CHECK_BOUNDS(Map, int, height, 1, INT_MAX) CHECK(Map, bool, isWorld) Map& Map::operator=(const Map& rhs) { if (this == &rhs) return *this; clear(); m_name = rhs.m_name; m_width = rhs.m_width; m_height = rhs.m_height; m_isWorld = rhs.m_isWorld; m_effects = rhs.m_effects; m_tiles = rhs.m_tiles; m_trainers = rhs.m_trainers; m_warps = rhs.m_warps; m_wildLists = rhs.m_wildLists; return *this; } void Map::clear() { m_effects.clear(); m_tiles.clear(); m_trainers.clear(); m_warps.clear(); m_wildLists.clear(); Object::clear(); }