Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
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"
29#include <pse-db/flydb.h>
30#include <pse-common/random.h>
31
33{
34 load(saveFile);
35}
36
38
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
54}
55
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
69{
70 return townCount;
71}
72
74{
75 return visitedTowns[ind];
76}
77
78void WorldTowns::townsSet(int ind, bool val)
79{
80 visitedTowns[ind] = val;
82}
83
85{
86 memset(visitedTowns, 0, townCount);
88}
89
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
108 }
109
111}
bool chanceSuccess(const int percent) const
Did a percent chance succeed?
Definition random.cpp:73
static Random * inst()
< Convenience 50% coin flip (integer path), readable from QML.
Definition random.cpp:31
void setBitField(var16 addr, var16 size, QVector< bool > src)
Sets an entire bitfield from a vector of bools.
QVector< bool > getBitField(var16 addr, var16 size)
Gets an entire bitfield as a vector of bools.
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition savefile.h:46
SaveFileToolset * toolset
Tools to operate directly on the raw sav file data.
Definition savefile.h:117
void randomize()
Randomize the visited flags.
bool visitedTowns[townCount]
Per-town visited (fly-unlocked) flags.
Definition worldtowns.h:58
bool townsAt(int ind)
Is town ind visited (fly-unlocked)?
virtual ~WorldTowns()
WorldTowns(SaveFile *saveFile=nullptr)
void load(SaveFile *saveFile=nullptr)
Expand the visited-town flags from the save.
void townsSet(int ind, bool val)
Set/clear visited for town ind.
void save(SaveFile *saveFile)
Flatten the visited-town flags to the save.
int townsCount()
Number of town flags (townCount).
protected::void visitedTownsChanged()
void reset()
Clear all visited flags.
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition types.h:124
constexpr var8 townCount
Towns tracked as fly destinations.
Definition worldtowns.h:23
constexpr var8 townByteCount
5 bits of 16 unused
Definition worldtowns.h:24