Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
worldtowns.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 <string.h>
24
25
#include "
./worldtowns.h
"
26
#include "
../../savefile.h
"
27
#include "
../../savefiletoolset.h
"
28
#include "
../../savefileiterator.h
"
29
#include <
pse-db/flydb.h
>
30
#include <
pse-common/random.h
>
31
32
WorldTowns::WorldTowns
(
SaveFile
* saveFile)
33
{
34
load
(saveFile);
35
}
36
37
WorldTowns::~WorldTowns
() {}
38
39
void
WorldTowns::load
(
SaveFile
* saveFile)
40
{
41
reset
();
42
43
if
(saveFile ==
nullptr
)
44
return
;
45
46
auto
toolset = saveFile->
toolset
;
47
48
auto
bits = toolset->
getBitField
(0x29B7,
townByteCount
);
49
50
for
(
var8
i = 0; i < bits.size() && i <
townCount
; i++)
51
visitedTowns
[i] = bits.at(i);
52
53
visitedTownsChanged
();
54
}
55
56
void
WorldTowns::save
(
SaveFile
* saveFile)
57
{
58
auto
toolset = saveFile->
toolset
;
59
60
QVector<bool> bits;
61
62
for
(
var8
i = 0; i <
townCount
; i++)
63
bits.append(
visitedTowns
[i]);
64
65
toolset->
setBitField
(0x29B7,
townByteCount
, bits);
66
}
67
68
int
WorldTowns::townsCount
()
69
{
70
return
townCount
;
71
}
72
73
bool
WorldTowns::townsAt
(
int
ind)
74
{
75
return
visitedTowns
[ind];
76
}
77
78
void
WorldTowns::townsSet
(
int
ind,
bool
val)
79
{
80
visitedTowns
[ind] = val;
81
visitedTownsChanged
();
82
}
83
84
void
WorldTowns::reset
()
85
{
86
memset(
visitedTowns
, 0,
townCount
);
87
visitedTownsChanged
();
88
}
89
90
void
WorldTowns::randomize
()
91
{
92
reset
();
93
94
// Enable Pallet Town because it's home and the starting point
95
visitedTowns
[0] =
true
;
96
97
// Randomly enable other towns except for Indigo and Saffron
98
// Indigo because it's the end and Saffron because it's the big connecting
99
// piece
100
for
(
var8
i = 1; i < 10; i++)
101
{
102
// Not saffron
103
if
(i == 7)
104
continue
;
105
106
// Give a 15% chance of enabling each town
107
visitedTowns
[i] =
Random::inst
()->
chanceSuccess
(15);
108
}
109
110
visitedTownsChanged
();
111
}
Random::chanceSuccess
bool chanceSuccess(const int percent) const
Did a percent chance succeed?
Definition
random.cpp:73
Random::inst
static Random * inst()
< Convenience 50% coin flip (integer path), readable from QML.
Definition
random.cpp:31
SaveFileToolset::setBitField
void setBitField(var16 addr, var16 size, QVector< bool > src)
Sets an entire bitfield from a vector of bools.
Definition
savefiletoolset.cpp:265
SaveFileToolset::getBitField
QVector< bool > getBitField(var16 addr, var16 size)
Gets an entire bitfield as a vector of bools.
Definition
savefiletoolset.cpp:242
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
WorldTowns::randomize
void randomize()
Randomize the visited flags.
Definition
worldtowns.cpp:90
WorldTowns::visitedTowns
bool visitedTowns[townCount]
Per-town visited (fly-unlocked) flags.
Definition
worldtowns.h:58
WorldTowns::townsAt
bool townsAt(int ind)
Is town ind visited (fly-unlocked)?
Definition
worldtowns.cpp:73
WorldTowns::~WorldTowns
virtual ~WorldTowns()
Definition
worldtowns.cpp:37
WorldTowns::WorldTowns
WorldTowns(SaveFile *saveFile=nullptr)
Definition
worldtowns.cpp:32
WorldTowns::load
void load(SaveFile *saveFile=nullptr)
Expand the visited-town flags from the save.
Definition
worldtowns.cpp:39
WorldTowns::townsSet
void townsSet(int ind, bool val)
Set/clear visited for town ind.
Definition
worldtowns.cpp:78
WorldTowns::save
void save(SaveFile *saveFile)
Flatten the visited-town flags to the save.
Definition
worldtowns.cpp:56
WorldTowns::townsCount
int townsCount()
Number of town flags (townCount).
Definition
worldtowns.cpp:68
WorldTowns::visitedTownsChanged
protected::void visitedTownsChanged()
WorldTowns::reset
void reset()
Clear all visited flags.
Definition
worldtowns.cpp:84
var8
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition
types.h:124
flydb.h
random.h
savefile.h
savefileiterator.h
savefiletoolset.h
worldtowns.h
townCount
constexpr var8 townCount
Towns tracked as fly destinations.
Definition
worldtowns.h:23
townByteCount
constexpr var8 townByteCount
5 bits of 16 unused
Definition
worldtowns.h:24
projects
savefile
src
pse-savefile
expanded
world
worldtowns.cpp
Generated by
1.17.0