/* * 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 "MapTrainer.h" // Sigmod includes #include "Macros.h" #include "Map.h" #include "MapTrainerTeamMember.h" #include "Rules.h" #include "Sigmod.h" // Qt includes #include Sigmod::MapTrainer::MapTrainer(const MapTrainer& trainer) : Object(trainer.parent(), trainer.id()) { *this = trainer; } Sigmod::MapTrainer::MapTrainer(const Map* parent, const int id) : Object(parent, id), m_name(""), m_trainerClass(INT_MAX), m_coordinate(0, 0), m_numberFight(1), m_script("", ""), m_leadTeamMember(INT_MAX) { } Sigmod::MapTrainer::MapTrainer(const MapTrainer& trainer, const Map* parent, const int id) : Object(parent, id) { *this = trainer; } Sigmod::MapTrainer::MapTrainer(const QDomElement& xml, const Map* parent, const int id) : Object(parent, id) { LOAD_ID(); load(xml); } Sigmod::MapTrainer::~MapTrainer() { clear(); } void Sigmod::MapTrainer::validate() { TEST_BEGIN(); if (m_name.isEmpty()) emit(error("Name is empty")); TEST(trainerClass); TEST(coordinate); TEST(numberFight); TEST(leadTeamMember); if (!teamMemberCount()) emit(error("There are no team members")); QSet idChecker; TEST_SUB_BEGIN(MapTrainerTeamMember, teamMembers); TEST_SUB("team member", id); TEST_SUB_END(); TEST_END(); } void Sigmod::MapTrainer::load(const QDomElement& xml) { LOAD_BEGIN(); LOAD(name); LOAD(trainerClass); LOAD(coordinate); LOAD(numberFight); LOAD(script); LOAD(leadTeamMember); LOAD_SUB(newTeamMember, MapTrainerTeamMember); LOAD(leadTeamMember); } QDomElement Sigmod::MapTrainer::save() const { SAVE_CREATE(); SAVE(name); SAVE(trainerClass); SAVE(coordinate); SAVE(numberFight); SAVE(script); SAVE(leadTeamMember); SAVE_SUB(MapTrainerTeamMember, teamMembers); return xml; } SETTER(MapTrainer, QString&, Name, name) SETTER(MapTrainer, int, TrainerClass, trainerClass) SETTER(MapTrainer, QPoint&, Coordinate, coordinate) SETTER(MapTrainer, int, NumberFight, numberFight) SETTER(MapTrainer, Sigcore::Script&, Script, script) SETTER(MapTrainer, int, LeadTeamMember, leadTeamMember) GETTER(MapTrainer, QString, name) GETTER(MapTrainer, int, trainerClass) GETTER(MapTrainer, QPoint, coordinate) GETTER(MapTrainer, int, numberFight) GETTER(MapTrainer, Sigcore::Script, script) GETTER(MapTrainer, int, leadTeamMember) CHECK(MapTrainer, QString&, name) CHECK_INDEX(MapTrainer, int, trainerClass, sigmod(), trainer) CHECK_BEGIN(MapTrainer, QPoint&, coordinate) const Map* map = qobject_cast(parent()); TBOUNDS_MOD(coordinate_x, 0, map->width() - 1, coordinate.x()) TBOUNDS_MOD(coordinate_y, 0, map->height() - 1, coordinate.y()) CHECK_END() CHECK_BOUNDS(MapTrainer, int, numberFight, 1, sigmod()->rules()->maxFight()) CHECK(MapTrainer, Sigcore::Script&, script) CHECK_BEGIN(MapTrainer, int, leadTeamMember) if (!teamMemberById(leadTeamMember)) { EBOUNDS_IDX(leadTeamMember); return false; } CHECK_END() SUBCLASS(MapTrainer, TeamMember, teamMember, teamMembers) Sigmod::MapTrainer& Sigmod::MapTrainer::operator=(const MapTrainer& rhs) { if (this == &rhs) return *this; clear(); COPY(name); COPY(trainerClass); COPY(coordinate); COPY(numberFight); COPY(script); COPY(leadTeamMember); COPY_SUB(MapTrainerTeamMember, teamMembers); return *this; } void Sigmod::MapTrainer::clear() { SUBCLASS_CLEAR(teamMembers); }