Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
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
31{
32 load(saveFile);
33}
34
36
37void 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);
48
49 starter = toolset->getByte(0x29C1);
51}
52
53void 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
62{
63 name = "";
65
66 starter = 0;
68}
69
71{
72 reset();
73
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)];
86}
QString randomExample()
A random string from the list.
NamesPlayer * player() const
The player-name source (backs player).
Definition names.cpp:35
static Names * inst()
< Random player-name source.
Definition names.cpp:29
static PokemonDB * inst()
< Number of species.
Definition pokemon.cpp:183
PokemonDBEntry * getIndAt(const QString &key) const
Species by name key (for QML).
Definition pokemon.cpp:199
static Random * inst()
< Convenience 50% coin flip (integer path), readable from QML.
Definition random.cpp:31
int rangeExclusive(const int start, const int end) const
Random integer in the half-open interval [start, end).
Definition random.cpp:53
void reset()
Blank the rival.
Definition rival.cpp:61
void save(SaveFile *saveFile)
Flatten the rival data to the save.
Definition rival.cpp:53
QString name
Definition rival.h:61
virtual ~Rival()
Definition rival.cpp:35
int starter
Definition rival.h:62
Rival(SaveFile *saveFile=nullptr)
< Rival's name.
Definition rival.cpp:30
protected::void nameChanged()
void starterChanged()
void randomize()
Randomize the rival's name/starter.
Definition rival.cpp:70
void load(SaveFile *saveFile=nullptr)
Expand the rival data from the save.
Definition rival.cpp:37
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.
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
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition types.h:124
var8 ind
Internal species index.
Definition pokemon.h:104