Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Toggle main menu visibility
Loading...
Searching...
No Matches
rival.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
21
22
#include "
./rival.h
"
23
#include "
../savefile.h
"
24
#include "
../savefiletoolset.h
"
25
#include "
../savefileiterator.h
"
26
#include <
pse-db/names.h
>
27
#include <
pse-db/pokemon.h
>
28
#include <
pse-common/random.h
>
29
30
Rival::Rival
(
SaveFile
* saveFile)
31
{
32
load
(saveFile);
33
}
34
35
Rival::~Rival
() {}
36
37
void
Rival::load
(
SaveFile
* saveFile)
38
{
39
reset
();
40
41
if
(saveFile ==
nullptr
)
42
return
;
43
44
auto
toolset = saveFile->
toolset
;
45
46
name
= toolset->getStr(0x25F6, 0xB, 7+1);
47
nameChanged
();
48
49
starter
= toolset->getByte(0x29C1);
50
starterChanged
();
51
}
52
53
void
Rival::save
(
SaveFile
* saveFile)
54
{
55
auto
toolset = saveFile->
toolset
;
56
57
toolset->
setStr
(0x25F6, 0xB, 7+1,
name
);
58
toolset->setByte(0x29C1,
starter
);
59
}
60
61
void
Rival::reset
()
62
{
63
name
=
""
;
64
nameChanged
();
65
66
starter
= 0;
67
starterChanged
();
68
}
69
70
void
Rival::randomize
()
71
{
72
reset
();
73
74
name
=
Names::inst
()->
player
()->
randomExample
();
75
nameChanged
();
76
77
var8
starters[3] = {
78
PokemonDB::inst
()->
getIndAt
(
"Charmander"
)->
ind
,
79
PokemonDB::inst
()->
getIndAt
(
"Squirtle"
)->
ind
,
80
PokemonDB::inst
()->
getIndAt
(
"Bulbasaur"
)->
ind
81
};
82
83
// Get a random starter
84
starter
= starters[
Random::inst
()->
rangeExclusive
(0, 3)];
85
starterChanged
();
86
}
AbstractRandomString::randomExample
QString randomExample()
A random string from the list.
Definition
abstractrandomstring.cpp:80
Names::player
NamesPlayer * player() const
The player-name source (backs player).
Definition
names.cpp:35
Names::inst
static Names * inst()
< Random player-name source.
Definition
names.cpp:29
PokemonDB::inst
static PokemonDB * inst()
< Number of species.
Definition
pokemon.cpp:183
PokemonDB::getIndAt
PokemonDBEntry * getIndAt(const QString &key) const
Species by name key (for QML).
Definition
pokemon.cpp:199
Random::inst
static Random * inst()
< Convenience 50% coin flip (integer path), readable from QML.
Definition
random.cpp:31
Random::rangeExclusive
int rangeExclusive(const int start, const int end) const
Random integer in the half-open interval [start, end).
Definition
random.cpp:53
Rival::reset
void reset()
Blank the rival.
Definition
rival.cpp:61
Rival::save
void save(SaveFile *saveFile)
Flatten the rival data to the save.
Definition
rival.cpp:53
Rival::name
QString name
Definition
rival.h:61
Rival::~Rival
virtual ~Rival()
Definition
rival.cpp:35
Rival::starter
int starter
Definition
rival.h:62
Rival::Rival
Rival(SaveFile *saveFile=nullptr)
< Rival's name.
Definition
rival.cpp:30
Rival::nameChanged
protected::void nameChanged()
Rival::starterChanged
void starterChanged()
Rival::randomize
void randomize()
Randomize the rival's name/starter.
Definition
rival.cpp:70
Rival::load
void load(SaveFile *saveFile=nullptr)
Expand the rival data from the save.
Definition
rival.cpp:37
SaveFileToolset::setStr
void setStr(var16 addr, var16 size, var8 maxLen, QString str)
Sets a string to the sav file, converted from UTF-8 to in-game font encoding.
Definition
savefiletoolset.cpp:97
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
var8
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition
types.h:124
names.h
pokemon.h
random.h
rival.h
savefile.h
savefileiterator.h
savefiletoolset.h
PokemonDBEntry::ind
var8 ind
Internal species index.
Definition
pokemon.h:104
projects
savefile
src
pse-savefile
expanded
rival.cpp
Generated by
1.17.0