summaryrefslogtreecommitdiffstats
path: root/pokemod/MapWarp.cpp
blob: 3b58b5edd8e755c0dfe2bc7600794937a0c4f9cb (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
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
/*
 * 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 "MapWarp.h"

// Pokemod includes
#include "Macros.h"
#include "Map.h"
#include "Pokemod.h"

const QStringList Pokemod::MapWarp::TypeStr = QStringList() << "Door/Stair" << "Warp Pad" << "Hole" << "Boundary";

Pokemod::MapWarp::MapWarp(const MapWarp& warp) :
        Object("MapWarp", warp.parent(), warp.id())
{
    *this = warp;
}

Pokemod::MapWarp::MapWarp(const Map* parent, const int id) :
        Object("MapWarp", parent, id),
        m_name(""),
        m_coordinate(0, 0),
        m_type(INT_MAX),
        m_toMap(INT_MAX),
        m_toWarp(INT_MAX),
        m_script("", "")
{
}

Pokemod::MapWarp::MapWarp(const MapWarp& warp, const Map* parent, const int id) :
        Object("MapWarp", parent, id)
{
    *this = warp;
}

Pokemod::MapWarp::MapWarp(const QDomElement& xml, const Map* parent, const int id) :
        Object("MapWarp", parent, id)
{
    LOAD_ID();
    load(xml);
}

void Pokemod::MapWarp::validate()
{
    TEST_BEGIN();
    if (m_name.isEmpty())
        emit(error("Name is empty"));
    TEST(setType, type);
    TEST(setToMap, toMap);
    TEST(setToWarp, toWarp);
    TEST_END();
}

void Pokemod::MapWarp::load(const QDomElement& xml)
{
    LOAD_BEGIN();
    LOAD(QString, name);
    LOAD(QPoint, coordinate);
    LOAD(int, type);
    LOAD(int, toMap);
    LOAD(int, toWarp);
    LOAD(Script, script);
}

QDomElement Pokemod::MapWarp::save() const
{
    SAVE_CREATE();
    SAVE(QString, name);
    SAVE(QPoint, coordinate);
    SAVE(int, type);
    SAVE(int, toMap);
    SAVE(int, toWarp);
    SAVE(Script, script);
    return xml;
}

void Pokemod::MapWarp::setName(const QString& name)
{
    CHECK(name);
}

void Pokemod::MapWarp::setCoordinate(const QPoint& coordinate)
{
    if ((qobject_cast<const Map*>(parent())->width() <= coordinate.x()) || (qobject_cast<const Map*>(parent())->height() <= coordinate.y()))
    {
        emit(error(bounds("coordinate")));
        return;
    }
    CHECK(coordinate);
}

void Pokemod::MapWarp::setType(const int type)
{
    if (End <= type)
    {
        emit(error(bounds("type")));
        return;
    }
    CHECK(type);
}

void Pokemod::MapWarp::setToMap(const int toMap)
{
    if (qobject_cast<const Pokemod*>(pokemod())->mapIndex(toMap) == INT_MAX)
    {
        emit(error(bounds("toMap")));
        return;
    }
    CHECK(toMap);
}

void Pokemod::MapWarp::setToWarp(const int toWarp)
{
    if (qobject_cast<const Pokemod*>(pokemod())->mapIndex(m_toMap) == INT_MAX)
    {
        emit(error(bounds("toMap")));
        return;
    }
    if (qobject_cast<const Pokemod*>(pokemod())->mapById(m_toMap)->warpIndex(toWarp) == INT_MAX)
    {
        emit(error(bounds("toWarp")));
        return;
    }
    CHECK(toWarp);
}

void Pokemod::MapWarp::setScript(const Script& script)
{
    CHECK(script);
}

QString Pokemod::MapWarp::name() const
{
    return m_name;
}

QPoint Pokemod::MapWarp::coordinate() const
{
    return m_coordinate;
}

int Pokemod::MapWarp::type() const
{
    return m_type;
}

int Pokemod::MapWarp::toMap() const
{
    return m_toMap;
}

int Pokemod::MapWarp::toWarp() const
{
    return m_toWarp;
}

Pokemod::Script Pokemod::MapWarp::script() const
{
    return m_script;
}

Pokemod::MapWarp& Pokemod::MapWarp::operator=(const MapWarp& rhs)
{
    if (this == &rhs)
        return *this;
    COPY(name);
    COPY(coordinate);
    COPY(type);
    COPY(toMap);
    COPY(toWarp);
    COPY(script);
    return *this;
}