summaryrefslogtreecommitdiffstats
path: root/pokemod/MapEffect.cpp
blob: 14b50d8d38856cd1e000362d04068c91bd9e521b (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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/////////////////////////////////////////////////////////////////////////////
// Name:        pokemod/MapEffect.cpp
// Purpose:     Define an effect for a map
// Author:      Ben Boeckel
// Modified by: Ben Boeckel
// Created:     Fri June 1 2007 20:23:15
// Copyright:   ©2007 Nerdy Productions
// Licence:
//    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/>.
/////////////////////////////////////////////////////////////////////////////

#include "MapEffect.h"

const char* PokeGen::PokeMod::MapEffect::MapEffectStr[PokeGen::PokeMod::MapEffect::E_End] = {"Item", "PC", "Strength Block", "Button", "Rock Smash", "Slot Machine", "Card Flip Game"};
const char* PokeGen::PokeMod::MapEffect::PCTypeStr[PokeGen::PokeMod::MapEffect::PC_End] = {"Item", "Pokémon", "PokéDex", "Hall of Fame", "All"};

PokeGen::PokeMod::MapEffect::MapEffect(const Pokemod* par, const unsigned _id) :
        Object(_id, par),
        name(""),
        coordinate(0, 0),
        existFlag(0, 0),
        skin(""),
        effect(UINT_MAX),
        val1(UINT_MAX),
        val2(UINT_MAX),
        direction(UINT_MAX),
        isTransparent(false),
        canMove(false),
        dialog(UINT_MAX)
{
}

PokeGen::PokeMod::MapEffect::MapEffect(const Pokemod* par, Ini& ini, const unsigned _id) :
        Object(_id, par)
{
    ImportIni(ini, _id);
}

bool PokeGen::PokeMod::MapEffect::Validate()
{
    pokemod->ValidationMsg(QString("------Effect \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg);
    if (name == "")
    {
        pokemod->ValidationMsg("Name is not defined");
        isValid = false;
    }
    if (Flag::End <= existFlag.GetStatus())
    {
        pokemod->ValidationMsg("Invalid existence flag status");
        isValid = false;
    }
    if (!QFile(pokemod->GetPath() + "images/skins/" + skin + ".png").exists())
    {
        pokemod->ValidationMsg(QString("Skin not found"));
        isValid = false;
    }
    if (effect < E_End)
    {
        bool ok = true;
        switch (effect)
        {
            case E_Item:
                if (pokemod->GetItemByID(val2) == UINT_MAX)
                    ok = false;
                break;
            case E_PC:
                if (PC_End <= val2)
                    ok = false;
                break;
            case E_StrengthBlock:
            case E_Button:
                if (Flag::End <= val2)
                    ok = false;
        }
        if (!ok)
        {
            pokemod->ValidationMsg("Invalid val2");
            isValid = false;
        }
    }
    else
    {
        pokemod->ValidationMsg("Invalid effect");
        isValid = false;
    }
    if (D_End_None <= direction)
    {
        pokemod->ValidationMsg("Invalid driection");
        isValid = false;
    }
    if (pokemod->GetDialogByID(dialog) == UINT_MAX)
    {
        pokemod->ValidationMsg("Invalid dialog");
        isValid = false;
    }
    return isValid;
}

void PokeGen::PokeMod::MapEffect::ImportIni(Ini& ini, const unsigned _id)
{
    if (_id == UINT_MAX)
        ini.GetValue("id", id);
    else
        id = _id;
    unsigned i;
    unsigned j;
    ini.GetValue("name", name);
    ini.GetValue("coordinate-x", i, 0);
    ini.GetValue("coordinate-y", j, 0);
    coordinate.Set(i, j);
    ini.GetValue("existFlag-f", i, 0);
    ini.GetValue("existFlag-s", j, 0);
    existFlag.Set(i, j);
    ini.GetValue("skin", skin);
    ini.GetValue("effect", effect);
    ini.GetValue("val1", val1);
    ini.GetValue("val2", val2);
    ini.GetValue("direction", direction);
    ini.GetValue("isTransparent", isTransparent);
    ini.GetValue("canMove", canMove);
    ini.GetValue("dialog", dialog);
}

void PokeGen::PokeMod::MapEffect::ExportIni(QFile& fout, const QString& map) const
{
    Ini exMapEffect(map + "mapEffect");
    exMapEffect.AddField("id", id);
    exMapEffect.AddField("name", name);
    exMapEffect.AddField("coordinate-x", coordinate.GetX());
    exMapEffect.AddField("coordinate-y", coordinate.GetY());
    exMapEffect.AddField("existFlag-f", existFlag.GetFlag());
    exMapEffect.AddField("existFlag-s", existFlag.GetStatus());
    exMapEffect.AddField("skin", skin);
    exMapEffect.AddField("effect", effect);
    exMapEffect.AddField("val1", val1);
    exMapEffect.AddField("val2", val2);
    exMapEffect.AddField("direction", direction);
    exMapEffect.AddField("isTransparent", isTransparent);
    exMapEffect.AddField("canMove", canMove);
    exMapEffect.AddField("dialog", dialog);
    exMapEffect.Export(fout);
}

void PokeGen::PokeMod::MapEffect::SetName(const QString& n)
{
    name = n;
}

void PokeGen::PokeMod::MapEffect::SetCoordinate(const unsigned x, const unsigned y)
{
    coordinate.Set(x, y);
}

void PokeGen::PokeMod::MapEffect::SetCoordinateX(const unsigned x)
{
    coordinate.SetX(x);
}

void PokeGen::PokeMod::MapEffect::SetCoordinateY(const unsigned y)
{
    coordinate.SetY(y);
}

void PokeGen::PokeMod::MapEffect::SetExistFlag(const unsigned f, const unsigned s)
{
    existFlag.Set(f, s);
}

void PokeGen::PokeMod::MapEffect::SetExistFlagFlag(const unsigned f)
{
    existFlag.SetFlag(f);
}

bool PokeGen::PokeMod::MapEffect::SetExistFlagStatus(const unsigned s)
{
    if (s < Flag::End)
    {
        existFlag.SetStatus(s);
        return true;
    }
    return false;
}

bool PokeGen::PokeMod::MapEffect::SetSkin(const QString& s)
{
    int dirPos = s.lastIndexOf(PM_DEF_SEP);
    int extPos = s.lastIndexOf('.');
    if ((dirPos == -1) || (extPos == -1))
        return false;
    skin = s.mid(dirPos + 1, extPos - dirPos - 1);
    QFile file(pokemod->GetPath() + "images/skins/" + skin + ".png");
    if (file.exists() && !file.remove())
        return false;
    return QFile::copy(s, pokemod->GetPath() + "images/skins/" + skin + ".png");
}

bool PokeGen::PokeMod::MapEffect::SetEffect(const unsigned e)
{
    if (e < E_End)
    {
        effect = e;
        val1 = UINT_MAX;
        val2 = UINT_MAX;
    }
    return (effect == e);
}

bool PokeGen::PokeMod::MapEffect::SetVal1(const unsigned v1)
{
    switch (effect)
    {
        case E_StrengthBlock:
        case E_Button:
            val1 = v1;
            break;
    }
    return (val1 == v1);
}

bool PokeGen::PokeMod::MapEffect::SetVal2(const unsigned v2)
{
    switch (effect)
    {
        case E_Item:
            if (pokemod->GetItemByID(v2) != UINT_MAX)
                val2 = v2;
            break;
        case E_PC:
            if (v2 < PC_End)
                val2 = v2;
            break;
        case E_StrengthBlock:
        case E_Button:
            if (v2 < Flag::End)
                val2 = v2;
            break;
    }
    return (val2 == v2);
}

bool PokeGen::PokeMod::MapEffect::SetDirection(const unsigned d)
{
    if (d < D_End_None)
        direction = d;
    return (direction == d);
}

void PokeGen::PokeMod::MapEffect::SetIsTransparent(const bool i)
{
    isTransparent = i;
}

void PokeGen::PokeMod::MapEffect::SetCanMove(const bool c)
{
    canMove = c;
}

bool PokeGen::PokeMod::MapEffect::SetDialog(const unsigned d)
{
    if (pokemod->GetDialogByID(d) != UINT_MAX)
        dialog = d;
    return (dialog == d);
}

QString PokeGen::PokeMod::MapEffect::GetName() const
{
    return name;
}

PokeGen::Point PokeGen::PokeMod::MapEffect::GetCoordinate() const
{
    return coordinate;
}

unsigned PokeGen::PokeMod::MapEffect::GetCoordinateX() const
{
    return coordinate.GetX();
}

unsigned PokeGen::PokeMod::MapEffect::GetCoordinateY() const
{
    return coordinate.GetY();
}

PokeGen::Flag PokeGen::PokeMod::MapEffect::GetExistFlag() const
{
    return existFlag;
}

unsigned PokeGen::PokeMod::MapEffect::GetExistFlagFlag() const
{
    return existFlag.GetFlag();
}

unsigned PokeGen::PokeMod::MapEffect::GetExistFlagStatus() const
{
    return existFlag.GetStatus();
}

QString PokeGen::PokeMod::MapEffect::GetSkin() const
{
    return skin;
}

unsigned PokeGen::PokeMod::MapEffect::GetEffect() const
{
    return effect;
}

unsigned PokeGen::PokeMod::MapEffect::GetVal1() const
{
    return val1;
}

unsigned PokeGen::PokeMod::MapEffect::GetVal2() const
{
    return val2;
}

unsigned PokeGen::PokeMod::MapEffect::GetDirection() const
{
    return direction;
}

bool PokeGen::PokeMod::MapEffect::GetIsTransparent() const
{
    return isTransparent;
}

bool PokeGen::PokeMod::MapEffect::GetCanMove() const
{
    return canMove;
}

unsigned PokeGen::PokeMod::MapEffect::GetDialog() const
{
    return dialog;
}