Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
worldgeneral.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 "
./worldgeneral.h
"
24
#include "
../../savefile.h
"
25
#include "
../../savefiletoolset.h
"
26
#include "
../../savefileiterator.h
"
27
#include <
pse-db/mapsdb.h
>
28
#include <
pse-db/entries/mapdbentry.h
>
29
#include <
pse-db/util/mapsearch.h
>
30
#include <
pse-common/random.h
>
31
32
WorldGeneral::WorldGeneral
(
SaveFile
* saveFile)
33
{
34
options
=
new
Options
;
35
letterDelay
=
new
LetterDelay
;
36
load
(saveFile);
37
}
38
39
WorldGeneral::~WorldGeneral
() {
40
options
->deleteLater();
41
letterDelay
->deleteLater();
42
}
43
44
void
WorldGeneral::load
(
SaveFile
* saveFile)
45
{
46
reset
();
47
48
if
(saveFile ==
nullptr
)
49
return
;
50
51
auto
toolset = saveFile->
toolset
;
52
53
// Bits 0-3 [max 15]
54
options
->textSlowness = toolset->getByte(0x2601) & 0b00001111;
55
options
->textSlownessChanged();
56
57
options
->battleStyleSet = toolset->getBit(0x2601, 1, 6);
58
options
->battleStyleSetChanged();
59
60
options
->battleAnimOff = toolset->getBit(0x2601, 1, 7);
61
options
->battleAnimOffChanged();
62
63
letterDelay
->normalDelay = toolset->getBit(0x2604, 1, 0);
64
letterDelay
->normalDelayChanged();
65
66
letterDelay
->dontDelay = toolset->getBit(0x2604, 1, 1);
67
letterDelay
->dontDelayChanged();
68
69
lastBlackoutMap
= toolset->getByte(0x29C5);
70
lastBlackoutMapChanged
();
71
72
lastMap
= toolset->getByte(0x2611);
73
lastMapChanged
();
74
}
75
76
void
WorldGeneral::save
(
SaveFile
* saveFile)
77
{
78
auto
toolset = saveFile->
toolset
;
79
80
toolset->
setByte
(0x2601,
options
->textSlowness);
81
toolset->setBit(0x2601, 1, 6,
options
->battleStyleSet);
82
toolset->setBit(0x2601, 1, 7,
options
->battleAnimOff);
83
84
toolset->setBit(0x2604, 1, 0,
letterDelay
->normalDelay);
85
toolset->setBit(0x2604, 1, 1,
letterDelay
->dontDelay);
86
87
toolset->setByte(0x29C5,
lastBlackoutMap
);
88
toolset->setByte(0x2611,
lastMap
);
89
}
90
91
void
WorldGeneral::reset
()
92
{
93
lastBlackoutMap
= 0;
94
lastBlackoutMapChanged
();
95
96
lastMap
= 0;
97
lastMapChanged
();
98
99
options
->textSlowness = 0;
100
options
->textSlownessChanged();
101
102
options
->battleStyleSet =
false
;
103
options
->battleStyleSetChanged();
104
105
options
->battleAnimOff =
false
;
106
options
->battleAnimOffChanged();
107
108
letterDelay
->normalDelay =
false
;
109
letterDelay
->normalDelayChanged();
110
111
letterDelay
->dontDelay =
false
;
112
letterDelay
->dontDelayChanged();
113
}
114
115
void
WorldGeneral::randomize
()
116
{
117
reset
();
118
119
// Map-dependent randomization disabled until the map randomizer is set up. These
120
// pick random maps via MapsDB search, but the type/city searches can come back
121
// empty (e.g. isType("Outdoor") matches 0 maps), so pickRandom() returns null and
122
// getInd() crashes. Left at the reset() default (0) so the rest of the world
123
// randomizes cleanly. Re-enable alongside the map randomizer. (Twilight-authorised,
124
// 2026-06-07.)
125
// lastBlackoutMap = MapsDB::inst()->search()->isGood()->isCity()->pickRandom()->getInd();
126
// lastBlackoutMapChanged();
127
// lastMap = MapsDB::inst()->search()->isGood()->isType("Outdoor")->pickRandom()->getInd();
128
// lastMapChanged();
129
130
// Options (text speed / battle style / battle animations / letter delay) and the
131
// last/blackout maps above are part of the Options and Maps screens, which aren't
132
// set up yet, so we don't randomize them until those screens exist. After reset()
133
// they're left at defaults. Re-enable with the Options/Maps screens.
134
// (Twilight-authorised, 2026-06-07.)
135
// options->textSlowness = Random::inst()->rangeInclusive(0, 15);
136
// options->textSlownessChanged();
137
// options->battleStyleSet = Random::inst()->chanceSuccess(20);
138
// options->battleStyleSetChanged();
139
// options->battleAnimOff = Random::inst()->chanceSuccess(20);
140
// options->battleAnimOffChanged();
141
// letterDelay->normalDelay = Random::inst()->chanceSuccess(90);
142
// letterDelay->normalDelayChanged();
143
// letterDelay->dontDelay = Random::inst()->chanceSuccess(10);
144
// letterDelay->dontDelayChanged();
145
}
LetterDelay
The text letter-printing delay flags (paired with the Options text speed).
Definition
worldgeneral.h:50
Options
In-game Options menu settings (text speed, battle style, animations).
Definition
worldgeneral.h:29
SaveFileToolset::setByte
void setByte(var16 addr, var8 val)
Simply sets a byte.
Definition
savefiletoolset.cpp:237
SaveFile
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition
savefile.h:46
SaveFile::toolset
SaveFileToolset * toolset
Tools to operate directly on the raw sav file data.
Definition
savefile.h:117
WorldGeneral::lastMap
int lastMap
Definition
worldgeneral.h:102
WorldGeneral::WorldGeneral
WorldGeneral(SaveFile *saveFile=nullptr)
< Map a blackout returns you to.
Definition
worldgeneral.cpp:32
WorldGeneral::~WorldGeneral
virtual ~WorldGeneral()
Definition
worldgeneral.cpp:39
WorldGeneral::letterDelay
LetterDelay * letterDelay
Definition
worldgeneral.h:104
WorldGeneral::lastBlackoutMap
int lastBlackoutMap
Definition
worldgeneral.h:101
WorldGeneral::lastBlackoutMapChanged
protected::void lastBlackoutMapChanged()
WorldGeneral::load
void load(SaveFile *saveFile=nullptr)
Expand general world settings from the save.
Definition
worldgeneral.cpp:44
WorldGeneral::randomize
void randomize()
Randomize these settings.
Definition
worldgeneral.cpp:115
WorldGeneral::save
void save(SaveFile *saveFile)
Flatten general world settings to the save.
Definition
worldgeneral.cpp:76
WorldGeneral::options
Options * options
Definition
worldgeneral.h:103
WorldGeneral::lastMapChanged
void lastMapChanged()
WorldGeneral::reset
void reset()
Blank these settings.
Definition
worldgeneral.cpp:91
mapdbentry.h
mapsdb.h
mapsearch.h
random.h
savefile.h
savefileiterator.h
savefiletoolset.h
worldgeneral.h
projects
savefile
src
pse-savefile
expanded
world
worldgeneral.cpp
Generated by
1.17.0