Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
item.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
#include "
./item.h
"
23
#include "
../../savefile.h
"
24
#include "
../../savefiletoolset.h
"
25
#include "
../../savefileiterator.h
"
26
#include <
pse-db/itemsdb.h
>
27
#include <
pse-db/entries/itemdbentry.h
>
28
#include <
pse-common/random.h
>
29
30
Item::Item
(
SaveFileIterator
* it)
31
{
32
if
(it ==
nullptr
) {
33
reset
();
34
return
;
35
}
36
37
ind
= it->
getByte
();
38
amount
= it->
getByte
();
39
makeConnect
();
40
}
41
42
Item::Item
(
var8
ind
,
var8
amount
)
43
{
44
load
(
ind
,
amount
);
45
makeConnect
();
46
}
47
48
Item::Item
(
bool
random)
49
{
50
load
(random);
51
makeConnect
();
52
}
53
54
Item::Item
(QString name,
var8
amount
)
55
{
56
load
(name,
amount
);
57
makeConnect
();
58
}
59
60
void
Item::makeConnect
()
61
{
62
connect(
this
, &
Item::indChanged
,
this
, &
Item::itemChanged
);
63
connect(
this
, &
Item::amountChanged
,
this
, &
Item::itemChanged
);
64
}
65
66
Item::~Item
() {}
67
68
void
Item::save
(
SaveFileIterator
* it)
69
{
70
it->
setByte
(
ind
);
71
it->
setByte
(
amount
);
72
}
73
74
void
Item::reset
()
75
{
76
ind
= 0;
77
indChanged
();
78
79
amount
= 0;
80
amountChanged
();
81
}
82
83
void
Item::randomize
()
84
{
85
auto
tmp =
ItemsDB::inst
()->
getStore
().at(
Random::inst
()->rangeExclusive(0,
ItemsDB::inst
()->getStoreSize()));
86
87
// No Glitch or Items only gotten once in the game
88
while
(tmp->getGlitch() || tmp->getOnce())
89
tmp =
ItemsDB::inst
()->
getStore
().at(
Random::inst
()->rangeExclusive(0,
ItemsDB::inst
()->getStoreSize()));
90
91
ind
= tmp->getInd();
92
indChanged
();
93
94
amount
=
Random::inst
()->
rangeInclusive
(1, 5);
// Between 1 and 5 of them
95
amountChanged
();
96
}
97
98
ItemDBEntry
*
Item::toItem
()
99
{
100
auto
tmp =
ItemsDB::inst
()->
getIndAt
(QString::number(
ind
));
101
return
tmp;
102
}
103
104
bool
Item::canSell
()
105
{
106
auto
el =
toItem
();
107
108
if
(el ==
nullptr
)
109
return
false
;
110
else
111
return
el->canSell();
112
}
113
114
int
Item::buyPriceOneMoney
()
115
{
116
auto
el =
toItem
();
117
118
if
(el ==
nullptr
)
119
return
0;
120
else
121
return
el->buyPriceMoney();
122
}
123
124
int
Item::buyPriceOneCoins
()
125
{
126
auto
el =
toItem
();
127
128
if
(el ==
nullptr
)
129
return
0;
130
else
131
return
el->buyPriceCoins();
132
}
133
134
int
Item::sellPriceOneMoney
()
135
{
136
auto
el =
toItem
();
137
138
if
(el ==
nullptr
)
139
return
0;
140
else
141
return
el->sellPriceMoney();
142
}
143
144
int
Item::sellPriceOneCoins
()
145
{
146
auto
el =
toItem
();
147
148
if
(el ==
nullptr
)
149
return
0;
150
else
151
return
el->sellPriceCoins();
152
}
153
154
int
Item::buyPriceAllMoney
()
155
{
156
return
buyPriceOneMoney
() *
amount
;
157
}
158
159
int
Item::buyPriceAllCoins
()
160
{
161
return
buyPriceOneCoins
() *
amount
;
162
}
163
164
int
Item::sellPriceAllMoney
()
165
{
166
return
sellPriceOneMoney
() *
amount
;
167
}
168
169
int
Item::sellPriceAllCoins
()
170
{
171
return
sellPriceOneCoins
() *
amount
;
172
}
173
174
int
Item::getAmount
()
175
{
176
return
amount
;
177
}
178
179
void
Item::setAmount
(
int
val)
180
{
181
amount
= val;
182
if
(
amount
< 1)
183
amount
= 1;
184
else
if
(
amount
> 99)
185
amount
= 99;
186
}
187
188
void
Item::load
(
int
ind
,
int
amount
)
189
{
190
this->ind =
ind
;
191
this->amount =
amount
;
192
}
193
194
void
Item::load
(
bool
random)
195
{
196
if
(!random) {
197
reset
();
198
return
;
199
}
200
201
randomize
();
202
}
203
204
void
Item::load
(QString name,
int
amount
)
205
{
206
auto
tmp =
ItemsDB::inst
()->
getIndAt
(name);
207
if
(tmp !=
nullptr
)
208
ind
= tmp->getInd();
209
210
this->amount =
amount
;
211
}
Item::ind
int ind
Item index (backs property).
Definition
item.h:106
Item::~Item
virtual ~Item()
Definition
item.cpp:66
Item::makeConnect
void makeConnect()
Wire up internal signal connections.
Definition
item.cpp:60
Item::sellPriceOneMoney
int sellPriceOneMoney()
Definition
item.cpp:134
Item::reset
void reset()
Blank this slot.
Definition
item.cpp:74
Item::amount
int amount
Item amount (max 99 in Gen 1; backs property).
Definition
item.h:109
Item::amountChanged
void amountChanged()
Item::getAmount
int getAmount()
Current amount (backs property READ).
Definition
item.cpp:174
Item::buyPriceOneCoins
int buyPriceOneCoins()
Definition
item.cpp:124
Item::sellPriceAllMoney
int sellPriceAllMoney()
Definition
item.cpp:164
Item::randomize
void randomize()
Randomize this slot.
Definition
item.cpp:83
Item::load
void load(int ind, int amount)
Set from an index + amount.
Definition
item.cpp:188
Item::sellPriceOneCoins
int sellPriceOneCoins()
Definition
item.cpp:144
Item::indChanged
protected::void indChanged()
Item::buyPriceAllCoins
int buyPriceAllCoins()
Definition
item.cpp:159
Item::sellPriceAllCoins
int sellPriceAllCoins()
Definition
item.cpp:169
Item::Item
Item(SaveFileIterator *it=nullptr)
< Item index (into the items DB).
Definition
item.cpp:30
Item::setAmount
void setAmount(int val)
Set amount (backs property WRITE; clamped to the Gen 1 max).
Definition
item.cpp:179
Item::canSell
bool canSell()
Whether the item may be sold.
Definition
item.cpp:104
Item::buyPriceOneMoney
int buyPriceOneMoney()
Definition
item.cpp:114
Item::buyPriceAllMoney
int buyPriceAllMoney()
Definition
item.cpp:154
Item::itemChanged
void itemChanged()
Item::save
void save(SaveFileIterator *it)
Given an iterator, saves 2 bytes: index and amount.
Definition
item.cpp:68
Item::toItem
ItemDBEntry * toItem()
Resolve ind to its DB entry.
Definition
item.cpp:98
ItemsDB::getIndAt
ItemDBEntry * getIndAt(const QString val) const
Item by name key (for QML).
Definition
itemsdb.cpp:66
ItemsDB::getStore
const QVector< ItemDBEntry * > getStore() const
All items.
Definition
itemsdb.cpp:43
ItemsDB::inst
static ItemsDB * inst()
< Number of items.
Definition
itemsdb.cpp:37
Random::rangeInclusive
int rangeInclusive(const int start, const int end) const
Random integer in the closed interval [start, end].
Definition
random.cpp:42
Random::inst
static Random * inst()
< Convenience 50% coin flip (integer path), readable from QML.
Definition
random.cpp:31
SaveFileIterator
A moving cursor over a SaveFile, layering auto-advancing reads/writes on top of SaveFileToolset.
Definition
savefileiterator.h:42
SaveFileIterator::setByte
void setByte(var8 val, var16 padding=0)
Write a byte at the cursor; advances.
Definition
savefileiterator.cpp:173
SaveFileIterator::getByte
var8 getByte(var16 padding=0)
Read a byte at the cursor; advances.
Definition
savefileiterator.cpp:166
var8
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition
types.h:124
item.h
itemdbentry.h
itemsdb.h
random.h
savefile.h
savefileiterator.h
savefiletoolset.h
ItemDBEntry
One item's static data: name/flags, pricing, and where it's used.
Definition
itemdbentry.h:46
projects
savefile
src
pse-savefile
expanded
fragments
item.cpp
Generated by
1.17.0