Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
worldtrades.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 "
./worldtrades.h
"
26
#include "
../../savefile.h
"
27
#include "
../../savefiletoolset.h
"
28
#include "
../../savefileiterator.h
"
29
30
WorldTrades::WorldTrades
(
SaveFile
* saveFile)
31
{
32
load
(saveFile);
33
}
34
35
WorldTrades::~WorldTrades
() {}
36
37
void
WorldTrades::load
(
SaveFile
* saveFile)
38
{
39
reset
();
40
41
if
(saveFile ==
nullptr
)
42
return
;
43
44
auto
toolset = saveFile->
toolset
;
45
46
auto
bits = toolset->
getBitField
(0x29E3,
tradeByteCount
);
47
48
for
(
var8
i = 0; i < bits.size() && i <
tradeCount
; i++)
49
completedTrades
[i] = bits.at(i);
50
51
completedTradesChanged
();
52
}
53
54
void
WorldTrades::save
(
SaveFile
* saveFile)
55
{
56
auto
toolset = saveFile->
toolset
;
57
58
QVector<bool> bits;
59
60
for
(
var8
i = 0; i <
tradeCount
; i++)
61
bits.append(
completedTrades
[i]);
62
63
toolset->
setBitField
(0x29E3,
tradeByteCount
, bits);
64
}
65
66
int
WorldTrades::tradesCount
()
67
{
68
return
tradeCount
;
69
}
70
71
bool
WorldTrades::tradesAt
(
int
ind)
72
{
73
return
completedTrades
[ind];
74
}
75
76
void
WorldTrades::tradesSet
(
int
ind,
bool
val)
77
{
78
completedTrades
[ind] = val;
79
completedTradesChanged
();
80
}
81
82
void
WorldTrades::reset
()
83
{
84
memset(
completedTrades
, 0,
tradeCount
);
85
completedTradesChanged
();
86
}
87
88
// Don't randomize or complete any trades
89
void
WorldTrades::randomize
() {
90
reset
();
91
}
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
WorldTrades::save
void save(SaveFile *saveFile)
Flatten the trade flags to the save.
Definition
worldtrades.cpp:54
WorldTrades::completedTradesChanged
protected::void completedTradesChanged()
WorldTrades::WorldTrades
WorldTrades(SaveFile *saveFile=nullptr)
Definition
worldtrades.cpp:30
WorldTrades::randomize
void randomize()
Randomize the trade flags.
Definition
worldtrades.cpp:89
WorldTrades::tradesSet
void tradesSet(int ind, bool val)
Set/clear completed for trade ind.
Definition
worldtrades.cpp:76
WorldTrades::load
void load(SaveFile *saveFile=nullptr)
Expand the trade flags from the save.
Definition
worldtrades.cpp:37
WorldTrades::completedTrades
bool completedTrades[tradeCount]
Per-trade completed flags.
Definition
worldtrades.h:58
WorldTrades::~WorldTrades
virtual ~WorldTrades()
Definition
worldtrades.cpp:35
WorldTrades::tradesCount
int tradesCount()
Number of trade flags (tradeCount).
Definition
worldtrades.cpp:66
WorldTrades::tradesAt
bool tradesAt(int ind)
Is trade ind completed?
Definition
worldtrades.cpp:71
WorldTrades::reset
void reset()
Clear all trade flags.
Definition
worldtrades.cpp:82
var8
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition
types.h:124
savefile.h
savefileiterator.h
savefiletoolset.h
worldtrades.h
tradeCount
constexpr var8 tradeCount
In-game NPC trades tracked.
Definition
worldtrades.h:23
tradeByteCount
constexpr var8 tradeByteCount
6 of 16 bits unused
Definition
worldtrades.h:24
projects
savefile
src
pse-savefile
expanded
world
worldtrades.cpp
Generated by
1.17.0