Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
area.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2020 Twilight
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
23
#include "
./area.h
"
24
#include "
./areaaudio.h
"
25
#include "
./arealoadedsprites.h
"
26
#include "
./areageneral.h
"
27
#include "
./areamap.h
"
28
#include "
./areanpc.h
"
29
#include "
./areaplayer.h
"
30
#include "
./areapokemon.h
"
31
#include "
./areasign.h
"
32
#include "
./areasprites.h
"
33
#include "
./areatileset.h
"
34
#include "
./areawarps.h
"
35
#include "
../../savefile.h
"
36
#include <
pse-db/mapsdb.h
>
37
#include <
pse-db/entries/mapdbentry.h
>
38
#include <
pse-db/entries/mapdbentrywarpin.h
>
39
#include <
pse-db/entries/mapdbentrysprite.h
>
40
#include <
pse-db/util/mapsearch.h
>
41
#include <
pse-common/random.h
>
42
43
Area::Area
(
SaveFile
* saveFile)
44
{
45
audio
=
new
AreaAudio
;
46
preloadedSprites
=
new
AreaLoadedSprites
;
47
general
=
new
AreaGeneral
;
48
map
=
new
AreaMap
;
49
npc
=
new
AreaNPC
;
50
player
=
new
AreaPlayer
;
51
pokemon
=
new
AreaPokemon
;
52
signs
=
new
AreaSign
;
53
sprites
=
new
AreaSprites
;
54
tileset
=
new
AreaTileset
;
55
warps
=
new
AreaWarps
;
56
57
load
(saveFile);
58
}
59
60
Area::~Area
()
61
{
62
audio
->deleteLater();
63
preloadedSprites
->deleteLater();
64
general
->deleteLater();
65
map
->deleteLater();
66
npc
->deleteLater();
67
player
->deleteLater();
68
pokemon
->deleteLater();
69
signs
->deleteLater();
70
sprites
->deleteLater();
71
tileset
->deleteLater();
72
warps
->deleteLater();
73
}
74
75
void
Area::load
(
SaveFile
* saveFile)
76
{
77
if
(saveFile ==
nullptr
)
78
return
reset
();
79
80
audio
->load(saveFile);
81
preloadedSprites
->load(saveFile);
82
general
->load(saveFile);
83
map
->load(saveFile);
84
npc
->load(saveFile);
85
player
->load(saveFile);
86
pokemon
->load(saveFile);
87
signs
->load(saveFile);
88
sprites
->load(saveFile);
89
tileset
->load(saveFile);
90
warps
->load(saveFile);
91
}
92
93
void
Area::save
(
SaveFile
* saveFile)
94
{
95
audio
->save(saveFile);
96
preloadedSprites
->save(saveFile);
97
general
->save(saveFile);
98
map
->save(saveFile);
99
npc
->save(saveFile);
100
player
->save(saveFile);
101
pokemon
->save(saveFile);
102
signs
->save(saveFile);
103
sprites
->save(saveFile);
104
tileset
->save(saveFile);
105
warps
->save(saveFile);
106
}
107
108
void
Area::reset
()
109
{
110
audio
->reset();
111
preloadedSprites
->reset();
112
general
->reset();
113
map
->reset();
114
npc
->reset();
115
player
->reset();
116
pokemon
->reset();
117
signs
->reset();
118
sprites
->reset();
119
tileset
->reset();
120
warps
->reset();
121
}
122
123
void
Area::randomize
()
124
{
125
// A Gameboy area is much more complicated to randomize and get right
126
// so that it's playable
127
// Pre-pick a random area here and pass to other area classes who need it
128
129
// Grab a random "good" map, a good map to throw the player on
130
auto
map
=
MapsDB::inst
()->
search
()->isGood()->pickRandom();
131
132
// Now pick out a random warp in and use those coordinates for the player
133
// coordinates
134
auto
warpIn =
map
->getWarpIn().at(
Random::inst
()->rangeExclusive(0,
map
->getWarpIn().size()));
135
136
// X & Y coordinates to place player
137
int
x = warpIn->getX();
138
int
y = warpIn->getY();
139
140
// Do the individual area randomizations and pass along map data where needed
141
audio
->randomize();
142
general
->randomize();
143
npc
->randomize();
144
pokemon
->randomize();
145
146
preloadedSprites
->randomize(
map
, x, y);
147
this->
map
->randomize(
map
, x, y);
148
player
->randomize(x, y);
149
signs
->randomize(
map
);
150
sprites
->randomize(
map
->getSprites());
151
tileset
->loadFromData(
map
,
true
);
152
warps
->randomize(
map
);
153
}
154
155
void
Area::setTo
(
MapDBEntry
*
map
)
156
{
157
// Now pick out a random warp in and use those coordinates for the player
158
// coordinates
159
auto
warpIn = (
map
==
nullptr
||
map
->getWarpIn().size() == 0)
160
? nullptr
161
:
map
->getWarpIn().at(
Random::inst
()->rangeExclusive(0,
map
->getWarpIn().size()));
162
163
// X & Y coordinates to place player
164
int
x = (warpIn ==
nullptr
)
165
? 0
166
: warpIn->getX();
167
168
int
y = (warpIn ==
nullptr
)
169
? 0
170
: warpIn->getY();
171
172
// Do the individual area randomizations and pass along map data where needed
173
audio
->setTo(
map
);
174
general
->setTo(
map
);
175
npc
->setTo(
map
);
176
pokemon
->setTo(
map
);
177
preloadedSprites
->setTo(
map
, x, y);
178
this->map->setTo(
map
, x, y);
179
player
->setTo(
map
, x, y);
180
signs
->setTo(
map
);
181
sprites
->setTo(
map
);
182
tileset
->loadFromData(
map
,
false
);
183
warps
->setTo(
map
);
184
}
area.h
areaaudio.h
areageneral.h
arealoadedsprites.h
areamap.h
areanpc.h
areaplayer.h
areapokemon.h
areasign.h
areasprites.h
areatileset.h
areawarps.h
AreaAudio
The current map's audio: which track plays, and a couple of music flags.
Definition
areaaudio.h:35
AreaGeneral
Miscellaneous per-area flags: contrast, letter delay, playtime counting.
Definition
areageneral.h:64
AreaLoadedSprites
The fixed set of sprite picture-ids currently loaded into the map's VRAM.
Definition
arealoadedsprites.h:40
AreaMap
Identity, size, pointers, and edge connections of the current map.
Definition
areamap.h:44
AreaNPC
Transient NPC/control/battle flags for the current map.
Definition
areanpc.h:35
AreaPlayer
The player's position and movement/HM/battle/warp state on the map.
Definition
areaplayer.h:55
AreaPokemon
Rate is how likely to encounter Pokemon higher number = higher chance A rate of 0 means no wild pokem...
Definition
areapokemon.h:97
AreaSign
The current map's list of signs.
Definition
areasign.h:38
AreaSprites
The current map's list of sprites/NPCs.
Definition
areasprites.h:39
AreaTileset
The current map's tileset: which set, its behaviour type, and pointers.
Definition
areatileset.h:38
AreaWarps
The current map's warps, plus the live warp-transition state.
Definition
areawarps.h:40
Area::pokemon
AreaPokemon * pokemon
Definition
area.h:130
Area::npc
AreaNPC * npc
Definition
area.h:128
Area::tileset
AreaTileset * tileset
Definition
area.h:133
Area::save
void save(SaveFile *saveFile)
Flatten the whole area to the save.
Definition
area.cpp:93
Area::reset
void reset()
Blank the whole area.
Definition
area.cpp:108
Area::sprites
AreaSprites * sprites
Definition
area.h:132
Area::player
AreaPlayer * player
Definition
area.h:129
Area::audio
AreaAudio * audio
Definition
area.h:124
Area::preloadedSprites
AreaLoadedSprites * preloadedSprites
Definition
area.h:125
Area::map
AreaMap * map
Definition
area.h:127
Area::Area
Area(SaveFile *saveFile=nullptr)
< Map music/audio settings.
Definition
area.cpp:43
Area::signs
AreaSign * signs
Definition
area.h:131
Area::~Area
virtual ~Area()
Definition
area.cpp:60
Area::setTo
void setTo(MapDBEntry *map)
Reconfigure the area to map (the "place on any map" feature).
Definition
area.cpp:155
Area::load
void load(SaveFile *saveFile=nullptr)
Expand the whole area from the save.
Definition
area.cpp:75
Area::randomize
void randomize()
Randomize the area (constrained, playable).
Definition
area.cpp:123
Area::general
AreaGeneral * general
Definition
area.h:126
Area::warps
AreaWarps * warps
Definition
area.h:134
MapsDB::inst
static MapsDB * inst()
< Number of maps.
Definition
mapsdb.cpp:35
MapsDB::search
QScopedPointer< MapSearch, QScopedPointerDeleteLater > search() const
C++-owned finder (smart pointer).
Definition
mapsdb.cpp:141
Random::inst
static Random * inst()
< Convenience 50% coin flip (integer path), readable from QML.
Definition
random.cpp:31
SaveFile
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition
savefile.h:46
mapdbentry.h
mapdbentrysprite.h
mapdbentrywarpin.h
mapsdb.h
mapsearch.h
random.h
savefile.h
MapDBEntry
One map's complete static definition – the root of the MapDBEntry family.
Definition
mapdbentry.h:56
projects
savefile
src
pse-savefile
expanded
area
area.cpp
Generated by
1.17.0