summaryrefslogtreecommitdiffstats
path: root/pokemod/SpeciesMove.cpp
blob: 5b24b48359a1b92c67a94a7024b0ebafc571212d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com>
 * 
 * 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 <http://www.gnu.org/licenses/>.
 */

// Pokemod includes
#include "Pokemod.h"

// Header include
#include "SpeciesMove.h"

SpeciesMove::SpeciesMove(const Pokemod* pokemod, const int id) :
        Object("SpeciesMove", pokemod, id),
        m_move(INT_MAX),
        m_level(0),
        m_wild(0)
{
}

SpeciesMove::SpeciesMove(const Pokemod* pokemod, const SpeciesMove& move, const int id) :
        Object("SpeciesMove", pokemod, id)
{
    *this = move;
}

SpeciesMove::SpeciesMove(const Pokemod* pokemod, const QDomElement& xml, const int id) :
        Object("SpeciesMove", pokemod, id)
{
    load(xml, id);
}

bool SpeciesMove::validate() const
{
    bool valid = true;
    pokemod()->validationMsg(QString("------Move with id %1---").arg(id()), Pokemod::V_Msg);
    if (pokemod()->moveIndex(m_move) == INT_MAX)
    {
        pokemod()->validationMsg("Invalid move");
        valid = false;
    }
    if (m_level < pokemod()->rules()->maxLevel())
    {
        pokemod()->validationMsg("Invalid level");
        valid = false;
    }
    if (m_wild < pokemod()->rules()->maxLevel())
    {
        pokemod()->validationMsg("Invalid wild level");
        valid = false;
    }
    return valid;
}

void SpeciesMove::load(const QDomElement& xml, int id)
{
    LOAD_ID();
    LOAD(int, move);
    LOAD(int, level);
    LOAD(int, wild);
}

QDomElement SpeciesMove::save() const
{
    SAVE_CREATE();
    SAVE(int, move);
    SAVE(int, level);
    SAVE(int, wild);
    return xml;
}

void SpeciesMove::setMove(const int move) throw(BoundsException)
{
    if (pokemod()->moveIndex(move) == INT_MAX)
        throw(BoundsException(className(), "move"));
    m_move = move;
}

void SpeciesMove::setLevel(const int level) throw(BoundsException)
{
    if (pokemod()->rules()->maxLevel() <= level)
        throw(BoundsException(className(), "level"));
    m_level = level;
}

void SpeciesMove::setWild(const int wild) throw(BoundsException)
{
    if (pokemod()->rules()->maxLevel() <= wild)
        throw(BoundsException(className(), "wild"));
    m_wild = wild;
}

int SpeciesMove::move() const
{
    return m_move;
}

int SpeciesMove::level() const
{
    return m_level;
}

int SpeciesMove::wild() const
{
    return m_wild;
}

SpeciesMove& SpeciesMove::operator=(const SpeciesMove& rhs)
{
    if (this == &rhs)
        return *this;
    COPY(move);
    COPY(level);
    COPY(wild);
    return *this;
}