Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
Loading...
Searching...
No Matches
worldevents.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
23#include <QRandomGenerator>
24#include <string.h>
25
26#include "./worldevents.h"
27#include "../../savefile.h"
30#include <pse-db/eventsdb.h>
32
34{
35 load(saveFile);
36}
37
39
41{
42 return eventCount;
43}
44
46{
47 return completedEvents[ind];
48}
49
50void WorldEvents::eventsSet(int ind, bool val)
51{
52 completedEvents[ind] = val;
54}
55
57{
58 reset();
59
60 if(saveFile == nullptr)
61 return;
62
63 auto toolset = saveFile->toolset;
64
65 for(var16 i = 0; i < EventsDB::inst()->getStoreSize(); i++) {
66 auto event = EventsDB::inst()->getStore().at(i);
67 completedEvents[i] = toolset->getBit(event->getByte(), 1, event->getBit());
68 }
69
71}
72
74{
75 auto toolset = saveFile->toolset;
76
77 for(var16 i = 0; i < EventsDB::inst()->getStoreSize(); i++) {
78 auto event = EventsDB::inst()->getStore().at(i);
79 toolset->setBit(event->getByte(), 1, event->getBit(), completedEvents[i]);
80 }
81}
82
88
89// Competed world events is too complicated to make happen randomly right now
90// Furthermore we do want the player to still play the game fully when
91// randomized
93 reset();
94}
int getStoreSize() const
Event count.
Definition eventsdb.cpp:51
const QVector< EventDBEntry * > getStore() const
All event definitions.
Definition eventsdb.cpp:41
static EventsDB * inst()
< Number of event definitions.
Definition eventsdb.cpp:35
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
void reset()
Clear every event.
void eventsSet(int ind, bool val)
Set/clear event ind.
void load(SaveFile *saveFile=nullptr)
Expand all event bits from the save.
bool eventsAt(int ind)
Is event ind set?
protected::void completedEventsChanged()
WorldEvents(SaveFile *saveFile=nullptr)
void randomize()
Randomize the event flags.
void save(SaveFile *saveFile)
Flatten all event bits to the save.
bool completedEvents[eventCount]
One flag per known story event.
Definition worldevents.h:60
int eventsCount()
Number of event flags (eventCount).
virtual ~WorldEvents()
var16e var16
Everyday 16-bit alias. Exact width to avoid the "fastest" widening bug.
Definition types.h:125
constexpr var16 eventCount
Number of known story-event flags (scattered across the save).
Definition worldevents.h:26