Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
pokemonstorageset.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
23
#include <QRandomGenerator>
24
25
#include "
./pokemonstorageset.h
"
26
#include "
./pokemonstoragebox.h
"
27
#include "
../../savefile.h
"
28
#include "
../../savefiletoolset.h
"
29
#include "
../../savefileiterator.h
"
30
31
PokemonStorageSet::PokemonStorageSet
(
SaveFile
* saveFile,
var16
boxesOffset,
svar8
skipInd)
32
{
33
for
(
var8
i = 0; i <
setMaxBoxes
; i++)
34
boxes
[i] =
new
PokemonStorageBox
;
35
36
load
(saveFile, boxesOffset, skipInd);
37
}
38
39
PokemonStorageSet::~PokemonStorageSet
()
40
{
41
for
(
var8
i = 0; i <
setMaxBoxes
; i++)
42
boxes
[i]->deleteLater();
43
}
44
45
void
PokemonStorageSet::load
(
SaveFile
* saveFile,
var16
boxesOffset,
svar8
skipInd)
46
{
47
reset
();
48
49
if
(saveFile ==
nullptr
)
50
return
;
51
52
for
(
var8
i = 0; i <
setMaxBoxes
; i++) {
53
54
// skipInd is signed (svar8, -1 == "skip nothing"); i is unsigned (var8). The
55
// `skipInd >= 0` guard means the cast is safe -- it just makes the signed/
56
// unsigned comparison explicit (clang-tidy bugprone-signed-char-misuse).
57
if
(skipInd >= 0 && i ==
static_cast<
var8
>
(skipInd))
58
continue
;
59
60
boxes
[i]->load(
61
saveFile,
62
(i * 0x462) + boxesOffset);
63
}
64
}
65
66
void
PokemonStorageSet::save
(
SaveFile
* saveFile,
var16
boxesOffset,
svar8
skipInd)
67
{
68
for
(
var8
i = 0; i <
setMaxBoxes
; i++) {
69
70
// skipInd is signed (svar8, -1 == "skip nothing"); i is unsigned (var8). The
71
// `skipInd >= 0` guard means the cast is safe -- it just makes the signed/
72
// unsigned comparison explicit (clang-tidy bugprone-signed-char-misuse).
73
if
(skipInd >= 0 && i ==
static_cast<
var8
>
(skipInd))
74
continue
;
75
76
boxes
[i]->save(
77
saveFile,
78
(i * 0x462) + boxesOffset);
79
}
80
}
81
82
void
PokemonStorageSet::reset
()
83
{
84
for
(
var8
i = 0; i <
setMaxBoxes
; i++)
85
boxes
[i]->
reset
();
86
}
87
88
void
PokemonStorageSet::randomize
(
PlayerBasics
* basics)
89
{
90
reset
();
91
92
for
(
var8
i = 0; i <
setMaxBoxes
; i++)
93
boxes
[i]->
randomize
(basics);
94
}
95
96
void
PokemonStorageSet::loadSpecific
(
SaveFile
* saveFile,
var16
offset,
var8
toBox)
97
{
98
boxes
[toBox]->load(
99
saveFile,
100
offset);
101
}
102
103
void
PokemonStorageSet::saveSpecific
(
SaveFile
* saveFile,
var16
offset,
var8
fromBox)
104
{
105
boxes
[fromBox]->save(
106
saveFile,
107
offset);
108
}
109
110
PokemonStorageBox
*
PokemonStorageSet::boxAt
(
int
ind)
111
{
112
return
boxes
[ind];
113
}
PlayerBasics
The trainer's headline values: name, ID, money, coins, badges, starter.
Definition
playerbasics.h:67
PokemonStorageBox
Holds contents of a single Pokemon storage box.
Definition
pokemonstoragebox.h:49
PokemonStorageSet::boxAt
PokemonStorageBox * boxAt(int ind)
Box at ind within this set.
Definition
pokemonstorageset.cpp:110
PokemonStorageSet::reset
void reset()
Empty all six boxes.
Definition
pokemonstorageset.cpp:82
PokemonStorageSet::randomize
void randomize(PlayerBasics *basics)
Fill the set with constrained random mons.
Definition
pokemonstorageset.cpp:88
PokemonStorageSet::loadSpecific
void loadSpecific(SaveFile *saveFile=nullptr, var16 offset=0, var8 toBox=0)
Load a specific box at a specific address into box toBox, overwriting it.
Definition
pokemonstorageset.cpp:96
PokemonStorageSet::save
void save(SaveFile *saveFile, var16 boxesOffset, svar8 skipInd=-1)
Auto load or save boxes 1-6 from a single address and skip a box if it's the current box.
Definition
pokemonstorageset.cpp:66
PokemonStorageSet::load
void load(SaveFile *saveFile=nullptr, var16 boxesOffset=0, svar8 skipInd=-1)
Auto load or save boxes 1-6 from a single address and skip a box if it's the current box.
Definition
pokemonstorageset.cpp:45
PokemonStorageSet::PokemonStorageSet
PokemonStorageSet(SaveFile *saveFile=nullptr, var16 boxesOffset=0, svar8 skipInd=-1)
Definition
pokemonstorageset.cpp:31
PokemonStorageSet::~PokemonStorageSet
virtual ~PokemonStorageSet()
Definition
pokemonstorageset.cpp:39
PokemonStorageSet::boxes
PokemonStorageBox * boxes[setMaxBoxes]
The six boxes (fixed-size; never grows/shrinks).
Definition
pokemonstorageset.h:76
PokemonStorageSet::saveSpecific
void saveSpecific(SaveFile *saveFile=nullptr, var16 offset=0, var8 fromBox=0)
Save box fromBox out to a specific address.
Definition
pokemonstorageset.cpp:103
SaveFile
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition
savefile.h:46
var8
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition
types.h:124
var16
var16e var16
Everyday 16-bit alias. Exact width to avoid the "fastest" widening bug.
Definition
types.h:125
svar8
svar8e svar8
Smaller Shorthand with most default assumptions.
Definition
types.h:109
pokemonstoragebox.h
pokemonstorageset.h
setMaxBoxes
constexpr var8 setMaxBoxes
Boxes per storage set (a save has two sets = 12 boxes).
Definition
pokemonstorageset.h:30
savefile.h
savefileiterator.h
savefiletoolset.h
projects
savefile
src
pse-savefile
expanded
fragments
pokemonstorageset.cpp
Generated by
1.17.0