Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
warpdata.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
22#include "warpdata.h"
23#include "../../savefile.h"
26#include <pse-db/mapsdb.h>
31#include <pse-common/random.h>
32
34{
35 load(saveFile, index);
36}
37
39{
40 load(warp);
41}
42
44
45void WarpData::load(SaveFile* saveFile, var8 index)
46{
47 reset();
48
49 if(saveFile == nullptr)
50 return;
51
52 auto it = saveFile->iterator()->offsetTo((0x4 * index) + 0x265B);
53
54 y = it->getByte();
55 yChanged();
56
57 x = it->getByte();
58 xChanged();
59
60 destWarp = it->getByte();
62
63 destMap = it->getByte();
65
66 delete it;
67}
68
70{
71 x = warp->getX();
72 xChanged();
73
74 y = warp->getY();
75 yChanged();
76
77 destMap = warp->getToMap()->getInd();
79
80 destWarp = warp->getWarp();
82}
83
84void WarpData::save(SaveFile* saveFile, var8 index)
85{
86 auto it = saveFile->iterator()->offsetTo((0x4 * index) + 0x265B);
87
88 it->setByte(y);
89 it->setByte(x);
90 it->setByte(destWarp);
91 it->setByte(destMap);
92
93 delete it;
94}
95
97{
98 y = 0;
99 yChanged();
100
101 x = 0;
102 xChanged();
103
104 destWarp = 0;
106
107 destMap = 0;
109}
110
112 reset();
113
114 // Grab a non-outdoor map
115 // The game can get kind of weird and crash if you warp to an outdoor map
116 // directly instead of "returning" outdoors using "Last Map"
117 auto map = MapsDB::inst()->search()->isGood()->notType("Outdoor")->pickRandom();
118 auto mapWarps = map->getWarpIn();
119
120 // Switch out warp to a random non-outdoor warp
121 destMap = map->getInd();
123
124 destWarp = Random::inst()->rangeExclusive(0, mapWarps.size());
126
127 y = mapWarps[destWarp]->getY();
128 yChanged();
129
130 x = mapWarps[destWarp]->getX();
131 xChanged();
132}
133
135{
136 return MapsDB::inst()->getIndAt(QString::number(destMap));
137}
static MapsDB * inst()
< Number of maps.
Definition mapsdb.cpp:35
QScopedPointer< MapSearch, QScopedPointerDeleteLater > search() const
C++-owned finder (smart pointer).
Definition mapsdb.cpp:141
MapDBEntry * getIndAt(const QString val) const
Map by name key (for QML).
Definition mapsdb.cpp:155
static Random * inst()
< Convenience 50% coin flip (integer path), readable from QML.
Definition random.cpp:31
int rangeExclusive(const int start, const int end) const
Random integer in the half-open interval [start, end).
Definition random.cpp:53
void setByte(var8 val, var16 padding=0)
Write a byte at the cursor; advances.
SaveFileIterator * offsetTo(var16 val)
Move the cursor to an absolute offset. Returns this for chaining.
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition savefile.h:46
SaveFileIterator * iterator()
Returns a unique iterator that's setup to iterate over the raw sav file data.
Definition savefile.cpp:53
void load(SaveFile *saveFile=nullptr, var8 index=0)
Expand warp index from the save.
Definition warpdata.cpp:45
WarpData(SaveFile *saveFile=nullptr, var8 index=0)
< Warp tile Y.
Definition warpdata.cpp:33
int destMap
Definition warpdata.h:69
int x
Definition warpdata.h:67
void reset()
Blank this warp.
Definition warpdata.cpp:96
virtual ~WarpData()
Definition warpdata.cpp:43
void randomize()
Randomize this warp.
Definition warpdata.cpp:111
void save(SaveFile *saveFile, var8 index)
Flatten warp index to the save.
Definition warpdata.cpp:84
void destMapChanged()
void xChanged()
MapDBEntry * toMap()
The destination map's DB entry.
Definition warpdata.cpp:134
void destWarpChanged()
int y
Definition warpdata.h:66
int destWarp
Definition warpdata.h:68
protected::void yChanged()
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition types.h:124
A warp-out point: a tile that warps the player to another map.
int getX() const
< Warp-out tile X.
MapDBEntry * getToMap() const
One map's complete static definition – the root of the MapDBEntry family.
Definition mapdbentry.h:56
int getInd() const