Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
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>
41#include <pse-common/random.h>
42
44{
45 audio = new AreaAudio;
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
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
75void 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
93void 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
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
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
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}
The current map's audio: which track plays, and a couple of music flags.
Definition areaaudio.h:35
Miscellaneous per-area flags: contrast, letter delay, playtime counting.
Definition areageneral.h:64
The fixed set of sprite picture-ids currently loaded into the map's VRAM.
Identity, size, pointers, and edge connections of the current map.
Definition areamap.h:44
Transient NPC/control/battle flags for the current map.
Definition areanpc.h:35
The player's position and movement/HM/battle/warp state on the map.
Definition areaplayer.h:55
Rate is how likely to encounter Pokemon higher number = higher chance A rate of 0 means no wild pokem...
Definition areapokemon.h:97
The current map's list of signs.
Definition areasign.h:38
The current map's list of sprites/NPCs.
Definition areasprites.h:39
The current map's tileset: which set, its behaviour type, and pointers.
Definition areatileset.h:38
The current map's warps, plus the live warp-transition state.
Definition areawarps.h:40
AreaPokemon * pokemon
Definition area.h:130
AreaNPC * npc
Definition area.h:128
AreaTileset * tileset
Definition area.h:133
void save(SaveFile *saveFile)
Flatten the whole area to the save.
Definition area.cpp:93
void reset()
Blank the whole area.
Definition area.cpp:108
AreaSprites * sprites
Definition area.h:132
AreaPlayer * player
Definition area.h:129
AreaAudio * audio
Definition area.h:124
AreaLoadedSprites * preloadedSprites
Definition area.h:125
AreaMap * map
Definition area.h:127
Area(SaveFile *saveFile=nullptr)
< Map music/audio settings.
Definition area.cpp:43
AreaSign * signs
Definition area.h:131
virtual ~Area()
Definition area.cpp:60
void setTo(MapDBEntry *map)
Reconfigure the area to map (the "place on any map" feature).
Definition area.cpp:155
void load(SaveFile *saveFile=nullptr)
Expand the whole area from the save.
Definition area.cpp:75
void randomize()
Randomize the area (constrained, playable).
Definition area.cpp:123
AreaGeneral * general
Definition area.h:126
AreaWarps * warps
Definition area.h:134
static MapsDB * inst()
< Number of maps.
Definition mapsdb.cpp:35
QScopedPointer< MapSearch, QScopedPointerDeleteLater > search() const
C++-owned finder (smart pointer).
Definition mapsdb.cpp:141
static Random * inst()
< Convenience 50% coin flip (integer path), readable from QML.
Definition random.cpp:31
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition savefile.h:46
One map's complete static definition – the root of the MapDBEntry family.
Definition mapdbentry.h:56