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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
/*
* 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/>.
*/
// Header include
#include "MapTrainerTeamMember.h"
// Sigmod includes
#include "Item.h"
#include "Macros.h"
#include "MapTrainer.h"
#include "Rules.h"
#include "Sigmod.h"
#include "Species.h"
#include "SpeciesMove.h"
// Qt includes
#include <QtCore/QSet>
Sigmod::MapTrainerTeamMember::MapTrainerTeamMember(const MapTrainerTeamMember& teamMember) :
Object(teamMember.parent(), teamMember.id())
{
*this = teamMember;
}
Sigmod::MapTrainerTeamMember::MapTrainerTeamMember(const MapTrainer* parent, const int id) :
Object(parent, id),
m_species(INT_MAX),
m_level(INT_MAX)
{
}
Sigmod::MapTrainerTeamMember::MapTrainerTeamMember(const MapTrainerTeamMember& teamMember, const MapTrainer* parent, const int id) :
Object(parent, id)
{
*this = teamMember;
}
Sigmod::MapTrainerTeamMember::MapTrainerTeamMember(const QDomElement& xml, const MapTrainer* parent, const int id) :
Object(parent, id)
{
LOAD_ID();
load(xml);
}
void Sigmod::MapTrainerTeamMember::validate()
{
TEST_BEGIN();
TEST(species);
TEST(level);
if (sigmod()->rules()->maxAbilities() < m_ability.size())
emit(error("Too many abilities"));
TEST_LIST(ability);
if (sigmod()->rules()->maxHeldItems() < m_item.size())
emit(error("Too many held items"));
TEST_LIST(item);
if (sigmod()->rules()->maxMoves() < m_move.size())
emit(error("Too many moves"));
TEST_LIST(move);
if (sigmod()->rules()->maxNatures() < m_nature.size())
emit(error("Too many natures"));
TEST_LIST(nature);
TEST_END();
}
void Sigmod::MapTrainerTeamMember::load(const QDomElement& xml)
{
LOAD_BEGIN();
LOAD(species);
LOAD(level);
LOAD_LIST(ability);
LOAD_LIST(item);
LOAD_LIST(move);
LOAD_LIST(nature);
}
QDomElement Sigmod::MapTrainerTeamMember::save() const
{
SAVE_CREATE();
SAVE(species);
SAVE(level);
SAVE_LIST(ability);
SAVE_LIST(item);
SAVE_LIST(move);
SAVE_LIST(nature);
return xml;
}
SETTER(MapTrainerTeamMember, int, Species, species)
SETTER(MapTrainerTeamMember, int, Level, level)
SETTER_LIST_LIMIT(MapTrainerTeamMember, Ability, ability, sigmod()->rules()->maxAbilities(), "Cannot have anymore abilities")
void Sigmod::MapTrainerTeamMember::setItem(const int item, const bool state)
{
if (itemCheck(item) && state && !m_item.contains(item))
{
if (m_item.size() < sigmod()->rules()->maxHeldItems())
{
if (checkWeight(item))
{
m_item.append(item);
emit(changed());
}
else
ERROR("Cannot carry that much weight");
}
else
ERROR("Cannot hold any more items");
}
else if (m_item.contains(item))
{
m_item.removeAll(item);
emit(changed());
}
}
void Sigmod::MapTrainerTeamMember::setMove(const int move, const bool state)
{
if (moveCheck(move) && state && !m_move.contains(move))
{
const Species* species = sigmod()->speciesById(move);
for (int i = 0; i < species->moveCount(); ++i)
{
const SpeciesMove* speciesMove = species->move(i);
if (speciesMove->move() == move)
{
if (m_move.size() < sigmod()->rules()->maxMoves())
{
m_move.append(move);
emit(changed());
}
else
ERROR("Cannot know any more moves");
}
}
ERROR("Cannot learn the move");
}
else if (m_move.contains(move))
{
m_move.removeAll(move);
emit(changed());
}
}
SETTER_LIST_LIMIT(MapTrainerTeamMember, Nature, nature, sigmod()->rules()->maxNatures(), "Cannot have anymore natures")
GETTER(MapTrainerTeamMember, int, species)
GETTER(MapTrainerTeamMember, int, level)
GETTER_LIST(MapTrainerTeamMember, ability)
GETTER_LIST(MapTrainerTeamMember, item)
GETTER_LIST(MapTrainerTeamMember, move)
GETTER_LIST(MapTrainerTeamMember, nature)
CHECK_INDEX(MapTrainerTeamMember, int, species, sigmod(), species)
CHECK_BOUNDS(MapTrainerTeamMember, int, level, 1, sigmod()->rules()->maxLevel())
CHECK_INDEX(MapTrainerTeamMember, int, ability, sigmod(), ability)
CHECK_INDEX(MapTrainerTeamMember, int, item, sigmod(), item)
CHECK_INDEX(MapTrainerTeamMember, int, move, sigmod(), move)
CHECK_INDEX(MapTrainerTeamMember, int, nature, sigmod(), nature)
Sigmod::MapTrainerTeamMember& Sigmod::MapTrainerTeamMember::operator=(const MapTrainerTeamMember& rhs)
{
if (this == &rhs)
return *this;
COPY(species);
COPY(level);
COPY(ability);
COPY(item);
COPY(move);
COPY(nature);
return *this;
}
bool Sigmod::MapTrainerTeamMember::checkWeight(const int item)
{
const Species* species = sigmod()->speciesById(m_species);
if (!species)
return true;
int totalWeight = sigmod()->itemById(item)->weight();
foreach (int itemId, m_item)
{
const Item* item = sigmod()->itemById(itemId);
if (!item)
totalWeight += item->weight();
}
return (totalWeight <= species->maxHoldWeight());
}
|