Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
pokemonparty.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 "pokemonparty.h"
23#include "../../savefile.h"
26
28 var16 offset,
29 var16 nicknameStartOffset,
30 var16 otNameStartOffset,
31 var8 index)
32{
33 load(saveFile, offset, nicknameStartOffset, otNameStartOffset, index);
35}
36
38
40 var16 offset,
41 var16 nicknameStartOffset,
42 var16 otNameStartOffset,
43 var8 index,
44 var8 recordSize)
45{
46 Q_UNUSED(recordSize)
47
48 reset();
49
50 if(saveFile == nullptr) {
51 return nullptr;
52 }
53
54 auto it = PokemonBox::load(saveFile,
55 offset,
56 nicknameStartOffset,
57 otNameStartOffset,
58 index,
59 0x2C);
60
61 level = it->getByte();
63
64 maxHP = it->getWord();
66
67 attack = it->getWord();
69
70 defense = it->getWord();
72
73 speed = it->getWord();
75
76 special = it->getWord();
78
79 delete it;
80 return nullptr;
81}
82
84 var16 offset,
85 svar32 speciesStartOffset,
86 var16 nicknameStartOffset,
87 var16 otNameStartOffset,
88 var8 index,
89 var8 recordSize)
90{
91 Q_UNUSED(recordSize)
92
93 auto it = PokemonBox::save(saveFile,
94 offset,
95 speciesStartOffset,
96 nicknameStartOffset,
97 otNameStartOffset,
98 index,
99 0x2C);
100
101 it->setByte(level);
102 it->setWord(maxHP);
103 it->setWord(attack);
104 it->setWord(defense);
105 it->setWord(speed);
106 it->setWord(special);
107
108 // There's nothing after this, delete it to prevent memory leak and returl a
109 // nullptr
110 delete it;
111 return nullptr;
112}
113
115{
117
118 maxHP = 0;
119 maxHPChanged();
120
121 attack = 0;
123
124 defense = 0;
126
127 speed = 0;
128 speedChanged();
129
130 special = 0;
132}
133
135{
136 // We can't randomize these stats, they're just cached pre-gen stats
137 // Tell the base class to randomize it's data
138 PokemonBox::randomize(basics);
139
140 // After that we need to re-gen these stats to reflect base class
141 regenStats();
142}
143
145{
146 if(!isValidBool())
147 return;
148
149 maxHP = hpStat();
150 maxHPChanged();
151
152 attack = atkStat();
154
155 defense = defStat();
157
158 speed = spdStat();
159 speedChanged();
160
161 special = spStat();
163}
164
165void PokemonParty::update(bool resetHp, bool resetExp, bool resetType, bool resetCatchRate, bool correctMoves)
166{
167 PokemonBox::update(resetHp, resetExp, resetType, resetCatchRate, correctMoves);
168 regenStats();
169}
170
172{
174 regenStats();
175}
176
178{
179 return false;
180}
181
183{
184 auto ret = new PokemonBox;
185 ret->copyFrom(data);
186 data->deleteLater();
187
188 return ret;
189}
190
192{
193 auto ret = new PokemonParty;
194 ret->copyFrom(data);
195 data->deleteLater();
196
197 return ret;
198}
199
201{
202 auto ret = new PokemonBox;
203 ret->copyFrom(this);
204 return ret;
205}
The trainer's headline values: name, ID, money, coins, badges, starter.
void levelChanged()
bool isValidBool()
Convenience bool form of isValid().
virtual void randomize(PlayerBasics *basics=nullptr)
Randomize this Pokemon (constrained).
int spdStat()
Computed Speed stat.
int spStat()
Computed Special stat.
virtual void update(bool resetHp=false, bool resetExp=false, bool resetType=false, bool resetCatchRate=false, bool correctMoves=false)
Recompute derived stats.
virtual SaveFileIterator * save(SaveFile *saveFile=nullptr, var16 startOffset=0, svar32 speciesStartOffset=0, var16 nicknameStartOffset=0, var16 otNameStartOffset=0, var8 index=0, var8 recordSize=0x21)
Flatten one Pokemon back to the save.
void resetExp()
Reset EXP to the current level's baseline.
void correctMoves()
Repair move/PP inconsistencies.
void statChanged()
virtual SaveFileIterator * load(SaveFile *saveFile=nullptr, var16 startOffset=0, var16 nicknameStartOffset=0, var16 otNameStartOffset=0, var8 index=0, var8 recordSize=0x21)
Expand one Pokemon from the save.
virtual void copyFrom(PokemonBox *pkmn)
Deep-copy another mon's values into this one.
int atkStat()
Computed Attack stat.
int defStat()
Computed Defense stat.
PokemonBox(SaveFile *saveFile=nullptr, var16 startOffset=0, var16 nicknameStartOffset=0, var16 otNameStartOffset=0, var8 index=0, var8 recordSize=0x21)
< Species id (raw save value).
virtual void reset()
Blank this Pokemon.
virtual void reset() override
Blank, including stored stats.
PokemonParty(SaveFile *saveFile=nullptr, var16 offset=0, var16 nicknameStartOffset=0, var16 otNameStartOffset=0, var8 index=0)
< Stored max HP.
virtual void randomize(PlayerBasics *basics=nullptr) override
Randomize, then regen stats.
virtual void copyFrom(PokemonBox *pkmn) override
Copy values from another mon (box or party).
virtual bool isBoxMon() override
False – this is a party mon.
void defenseChanged()
virtual void update(bool resetHp=false, bool resetExp=false, bool resetType=false, bool resetCatchRate=false, bool correctMoves=false) override
Recompute; also refreshes stored stats.
PokemonBox * toBoxData()
This mon as a plain box record.
static PokemonParty * convertToParty(PokemonBox *data)
New party mon from a box record (regenerates stats).
static PokemonBox * convertToBox(PokemonParty *data)
New box record from a party mon (drops stored stats).
virtual ~PokemonParty()
void regenStats()
Recompute the five stored stats from species/level/DVs/EVs.
virtual SaveFileIterator * load(SaveFile *saveFile=nullptr, var16 offset=0, var16 nicknameStartOffset=0, var16 otNameStartOffset=0, var8 index=0, var8 recordSize=0x2C) override
Expand a party record (record size defaults to the party's 0x2C).
void attackChanged()
void speedChanged()
void specialChanged()
protected::void maxHPChanged()
virtual SaveFileIterator * save(SaveFile *saveFile, var16 offset, svar32 speciesStartOffset, var16 nicknameStartOffset, var16 otNameStartOffset, var8 index, var8 recordSize=0x2C) override
Flatten a party record back to the save.
A moving cursor over a SaveFile, layering auto-advancing reads/writes on top of SaveFileToolset.
One loaded save: the raw 32 KB bytes, their expanded object tree, and the tools that move between the...
Definition savefile.h:46
svar32e svar32
Signed, exactly 32-bit (shorthand for svar32e).
Definition types.h:111
var8e var8
Everyday 8-bit alias. Exact (not "fastest") to dodge the pointer-width bug noted above.
Definition types.h:124
var16e var16
Everyday 16-bit alias. Exact width to avoid the "fastest" widening bug.
Definition types.h:125