Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
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"
29
31{
32 load(saveFile);
33}
34
36
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
52}
53
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
67{
68 return tradeCount;
69}
70
72{
73 return completedTrades[ind];
74}
75
76void WorldTrades::tradesSet(int ind, bool val)
77{
78 completedTrades[ind] = val;
80}
81
87
88// Don't randomize or complete any trades
90 reset();
91}
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 save(SaveFile *saveFile)
Flatten the trade flags to the save.
protected::void completedTradesChanged()
WorldTrades(SaveFile *saveFile=nullptr)
void randomize()
Randomize the trade flags.
void tradesSet(int ind, bool val)
Set/clear completed for trade ind.
void load(SaveFile *saveFile=nullptr)
Expand the trade flags from the save.
bool completedTrades[tradeCount]
Per-trade completed flags.
Definition worldtrades.h:58
virtual ~WorldTrades()
int tradesCount()
Number of trade flags (tradeCount).
bool tradesAt(int ind)
Is trade ind completed?
void reset()
Clear all trade flags.
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition types.h:124
constexpr var8 tradeCount
In-game NPC trades tracked.
Definition worldtrades.h:23
constexpr var8 tradeByteCount
6 of 16 bits unused
Definition worldtrades.h:24