Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
areaplayer.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 "areaplayer.h"
23#include "../../savefile.h"
26#include <pse-common/random.h>
27#include <pse-db/mapsdb.h>
28
30{
31 load(saveFile);
32}
33
35
37{
38 reset();
39
40 if(saveFile == nullptr)
41 return;
42
43 auto toolset = saveFile->toolset;
44
45 yCoord = toolset->getByte(0x260D);
47
48 xCoord = toolset->getByte(0x260E);
50
51 yBlockCoord = toolset->getByte(0x260F);
53
54 xBlockCoord = toolset->getByte(0x2610);
56
57 yOffsetSinceLastSpecialWarp = toolset->getByte(0x278E);
59
60 xOffsetSinceLastSpecialWarp = toolset->getByte(0x278F);
62
63 playerMoveDir = toolset->getByte(0x27D4);
65
66 playerLastStopDir = toolset->getByte(0x27D5);
68
69 playerCurDir = toolset->getByte(0x27D6);
71
72 walkBikeSurf = toolset->getByte(0x29AC);
74
75 playerJumpingYScrnCoords = toolset->getByte(0x29C0);
77
78 strengthOutsideBattle = toolset->getBit(0x29D4, 1, 0);
80
81 surfingAllowed = toolset->getBit(0x29D4, 1, 1);
83
84 usedCardKey = toolset->getBit(0x29D4, 1, 7);
86
87 isBattle = toolset->getBit(0x29D9, 1, 6);
89
90 isTrainerBattle = toolset->getBit(0x29D9, 1, 7);
92
93 noBattles = toolset->getBit(0x29DA, 1, 4);
95
96 battleEndedOrBlackout = toolset->getBit(0x29DA, 1, 5);
98
99 usingLinkCable = toolset->getBit(0x29DA, 1, 6);
101
102 flyOutofBattle = toolset->getBit(0x29DF, 1, 7);
104
105 standingOnDoor = toolset->getBit(0x29E2, 1, 0);
107
108 movingThroughDoor = toolset->getBit(0x29E2, 1, 1);
110
111 standingOnWarp = toolset->getBit(0x29E2, 1, 2);
113
114 finalLedgeJumping = toolset->getBit(0x29E2, 1, 6);
116
117 spinPlayer = toolset->getBit(0x29E2, 1, 7);
119}
120
122{
123 auto toolset = saveFile->toolset;
124
125 toolset->setByte(0x260D, yCoord);
126 toolset->setByte(0x260E, xCoord);
127 toolset->setByte(0x260F, yBlockCoord);
128 toolset->setByte(0x2610, xBlockCoord);
129 toolset->setByte(0x278E, yOffsetSinceLastSpecialWarp);
130 toolset->setByte(0x278F, xOffsetSinceLastSpecialWarp);
131 toolset->setByte(0x27D4, playerMoveDir);
132 toolset->setByte(0x27D5, playerLastStopDir);
133 toolset->setByte(0x27D6, playerCurDir);
134 toolset->setByte(0x29AC, walkBikeSurf);
135 toolset->setByte(0x29C0, playerJumpingYScrnCoords);
136 toolset->setBit(0x29D4, 1, 0, strengthOutsideBattle);
137 toolset->setBit(0x29D4, 1, 1, surfingAllowed);
138 toolset->setBit(0x29D4, 1, 7, usedCardKey);
139 toolset->setBit(0x29D9, 1, 6, isBattle);
140 toolset->setBit(0x29D9, 1, 7, isTrainerBattle);
141 toolset->setBit(0x29DA, 1, 4, noBattles);
142 toolset->setBit(0x29DA, 1, 5, battleEndedOrBlackout);
143 toolset->setBit(0x29DA, 1, 6, usingLinkCable);
144 toolset->setBit(0x29DF, 1, 7, flyOutofBattle);
145 toolset->setBit(0x29E2, 1, 0, standingOnDoor);
146 toolset->setBit(0x29E2, 1, 1, movingThroughDoor);
147 toolset->setBit(0x29E2, 1, 2, standingOnWarp);
148 toolset->setBit(0x29E2, 1, 6, finalLedgeJumping);
149 toolset->setBit(0x29E2, 1, 7, spinPlayer);
150}
151
153{
154 playerMoveDir = 0;
156
159
160 playerCurDir = 0;
162
163 yCoord = 0;
165
166 xCoord = 0;
168
169 yBlockCoord = 0;
171
172 xBlockCoord = 0;
174
177
178 strengthOutsideBattle = false;
180
181 surfingAllowed = false;
183
184 flyOutofBattle = false;
186
187 isBattle = false;
189
190 isTrainerBattle = false;
192
193 noBattles = false;
195
196 battleEndedOrBlackout = false;
198
201
204
205 standingOnDoor = false;
207
208 movingThroughDoor = false;
210
211 standingOnWarp = false;
213
214 walkBikeSurf = 0;
216
217 finalLedgeJumping = false;
219
220 spinPlayer = false;
222
223 usedCardKey = false;
225
226 usingLinkCable = false;
228}
229
230void AreaPlayer::randomize(int x, int y)
231{
232 // Keep most of them resetted
233 reset();
234
235 // Have player be stationary
238
239 // Determine facing and last stop directions
244
249
250 yCoord = y;
252
253 xCoord = x;
255
256 yBlockCoord = (y % 2) ? 0 : 1;
258
259 xBlockCoord = (x % 2) ? 0 : 1;
261}
262
263void AreaPlayer::setTo(MapDBEntry* map, int x, int y)
264{
265 Q_UNUSED(map)
266 randomize(x, y);
267}
void load(SaveFile *saveFile=nullptr)
Expand the player state from the save.
void walkBikeSurfChanged()
void yOffsetSinceLastSpecialWarpChanged()
bool surfingAllowed
Definition areaplayer.h:150
void xCoordChanged()
void standingOnWarpChanged()
bool noBattles
Definition areaplayer.h:156
bool usedCardKey
Definition areaplayer.h:174
void playerLastStopDirChanged()
virtual ~AreaPlayer()
void noBattlesChanged()
int playerMoveDir
Move direction (raw bits per the table above).
Definition areaplayer.h:132
void playerCurDirChanged()
AreaPlayer(SaveFile *saveFile=nullptr)
< Current move direction (raw bits; see field note).
void xBlockCoordChanged()
void playerJumpingYScrnCoordsChanged()
void standingOnDoorChanged()
protected::void playerMoveDirChanged()
bool finalLedgeJumping
Definition areaplayer.h:172
int yBlockCoord
Definition areaplayer.h:144
void yBlockCoordChanged()
void randomize(int x, int y)
Randomize, placing the player at (x,y).
void xOffsetSinceLastSpecialWarpChanged()
void isBattleChanged()
void reset()
Blank the player state.
bool isBattle
Definition areaplayer.h:154
int yOffsetSinceLastSpecialWarp
Definition areaplayer.h:160
void finalLedgeJumpingChanged()
int walkBikeSurf
Movement mode: 0x00 walking, 0x01 biking, 0x02 surfing.
Definition areaplayer.h:171
void flyOutofBattleChanged()
bool spinPlayer
Definition areaplayer.h:173
bool flyOutofBattle
Definition areaplayer.h:151
void strengthOutsideBattleChanged()
void yCoordChanged()
bool movingThroughDoor
Definition areaplayer.h:163
void surfingAllowedChanged()
void spinPlayerChanged()
int xOffsetSinceLastSpecialWarp
Definition areaplayer.h:161
int playerLastStopDir
the direction in which the player was moving before the player last stopped
Definition areaplayer.h:135
bool battleEndedOrBlackout
Definition areaplayer.h:157
void isTrainerBattleChanged()
void usedCardKeyChanged()
int playerCurDir
if the player is moving, the current direction if the player is not moving, the last the direction in...
Definition areaplayer.h:139
bool usingLinkCable
Definition areaplayer.h:175
int xBlockCoord
Definition areaplayer.h:145
bool strengthOutsideBattle
Definition areaplayer.h:149
bool standingOnWarp
Definition areaplayer.h:164
void save(SaveFile *saveFile)
Flatten the player state to the save.
void setTo(MapDBEntry *map, int x, int y)
Place the player on map at (x,y).
void movingThroughDoorChanged()
void usingLinkCableChanged()
bool standingOnDoor
Definition areaplayer.h:162
void battleEndedOrBlackoutChanged()
int playerJumpingYScrnCoords
Definition areaplayer.h:146
bool isTrainerBattle
Definition areaplayer.h:155
int rangeInclusive(const int start, const int end) const
Random integer in the closed interval [start, end].
Definition random.cpp:42
static Random * inst()
< Convenience 50% coin flip (integer path), readable from QML.
Definition random.cpp:31
void setByte(var16 addr, var8 val)
Simply sets a byte.
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
One map's complete static definition – the root of the MapDBEntry family.
Definition mapdbentry.h:56