ScummVM API documentation
nancy.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef NANCY_H
23#define NANCY_H
24
25#include "common/file.h"
26#include "common/str.h"
27#include "common/ptr.h"
28
29#include "engines/engine.h"
30
31#include "nancy/detection.h"
32#include "nancy/time.h"
33#include "nancy/commontypes.h"
34#include "nancy/enginedata.h"
35
36namespace Common {
37class RandomSource;
38class Serializer;
39}
40
65namespace Nancy {
66
67// Save game version history:
68// - 1: Initial version
69// - 2: Conditional dialogue and hints moved to nancy.dat
70// - 3: Puzzle data stored as lazily initialized PuzzleData objects
71// - 4: Journal entries sync their scene ID (Nancy9+)
72// - 5: Nancy10 taskbar notification badges persisted
73// - 6: Nancy12 timers reworked
74// - 7: Nancy10 unnamed notebook task event flags added
75// - 8: Nancy12 DrivingPuzzle fuel state persisted
76// - 9: RippedLetterPuzzle stores its scene ID and tried flag
77// - 10: Nancy14/15 inventory arrays hold 49 items instead of 50
78// - 11: Nancy12+ TableData holds 100 single values instead of 30, and
79// the Nancy14/15 player clock only holds the time of the current
80// day, with the day itself stored separately
81// - 12: QuizPuzzle slots are keyed by a 32-bit id, and the Nancy15
82// protagonists each carry their own cell phone
83static const int kSavegameVersion = 12;
84
85struct NancyGameDescription;
86
87class ResourceManager;
88class IFF;
89class InputManager;
90class SoundManager;
91class GraphicsManager;
92class CursorManager;
93class NancyConsole;
94class DeferredLoader;
95class MoviePlayer;
96
97namespace State {
98class State;
99}
100
101class NancyEngine : public Engine {
102public:
103 NancyEngine(OSystem *syst, const NancyGameDescription *gd);
104 ~NancyEngine();
105
106 static NancyEngine *create(GameType type, OSystem *syst, const NancyGameDescription *gd);
107
108 void errorString(const char *buf_input, char *buf_output, int buf_output_size) override;
109 bool hasFeature(EngineFeature f) const override;
110
111 Common::Error loadGameState(int slot) override;
113 Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
114 bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
115 bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
116
117 void secondChance();
118
119 const char *getCopyrightString() const;
120 uint32 getGameFlags() const;
121 const char *getGameId() const;
122 GameType getGameType() const;
123 Common::Language getGameLanguage() const;
124 Common::Platform getPlatform() const;
125
126 const StaticData &getStaticData() const;
127 const EngineData *getEngineData(const Common::String &name) const;
128 const Common::String getEventFlagName(uint flagID) const;
129
130 // Nancy15+ lets the player alternate between several protagonists, each of whom
131 // carries their own copy of the popup UI. Swaps the engine data describing it to
132 // the given PCUI character's, and returns whether anything actually changed.
133 // Scene::reloadPlayerCharacterUI() rebuilds the widgets themselves.
134 bool setPlayerCharacter(uint characterIndex);
135 uint getPlayerCharacter() const { return _playerCharacter; }
136
137 // Adds the texts of a text file to the autotext
138 void addAutotext(const Common::Path &name);
139
140 // A character's "design" is the look their UI wears; it names the CIF tree
141 // everything is loaded from. Nancy's can be changed on the Design Select
142 // screen, and defaults to the character's PCUI entry.
143 Common::String getPlayerCharacterDesign(uint characterIndex) const;
144 void setPlayerCharacterDesign(uint characterIndex, const Common::String &designName);
145
146 // Whether setPlayerCharacter() would actually have to load anything
147 bool playerCharacterNeedsReload(uint characterIndex) const;
148
149 void setState(NancyState::NancyState state, NancyState::NancyState overridePrevious = NancyState::kNone);
150 NancyState::NancyState getState() { return _gameFlow.curState; }
151 NancyState::NancyState getPreviousState() const { return _gameFlow.prevState; }
152 void setToPreviousState();
153
154 void setMouseEnabled(bool enabled);
155
156 void addDeferredLoader(Common::SharedPtr<DeferredLoader> &loaderPtr);
157
158 // The first few games used 1/2 for false/true in
159 // inventory, logic conditions, and event flags
160 const byte _true;
161 const byte _false;
162
163 // Managers
164 ResourceManager *_resource;
165 GraphicsManager *_graphics;
166 CursorManager *_cursor;
167 InputManager *_input;
168 SoundManager *_sound;
169
170 Common::RandomSource *_randomSource;
171
172 // All loaded movies, for MoviePlayer::findLoadedMovie().
173 Common::Array<MoviePlayer *> _loadedMovies;
174
175 // Used to check whether we need to show the SaveDialog
176 bool _hasJustSaved;
177
178protected:
179 Common::Error run() override;
180 void pauseEngineIntern(bool pause) override;
181
182private:
183 struct GameFlow {
184 NancyState::NancyState curState = NancyState::kNone;
185 NancyState::NancyState prevState = NancyState::kNone;
186 NancyState::NancyState nextState = NancyState::kNone;
187 bool changingState = true;
188 };
189
190 void bootGameEngine();
191#ifdef ENABLE_NANCY_V4
192 void bootScriptedGameEngine(); // Nancy19+
193#endif
194
195 State::State *getStateObject(NancyState::NancyState state) const;
196 void destroyState(NancyState::NancyState state) const;
197
198 void preloadCals();
199 void readDatFile();
200 // Nancy12 onwards no longer ship their static data in nancy.dat; the values
201 // the engine still needs are provided here instead (see also the EVNT chunk).
202 void populateStaticData();
203
204 Common::Error synchronize(Common::Serializer &serializer);
205
206 StaticData _staticData;
208
209 // Nancy15+ active player character, the CIF tree their UI came from, and
210 // each character's chosen design (empty = their PCUI default)
211 uint _playerCharacter = 0;
212 Common::String _playerCharacterTree;
213 Common::String _playerCharacterDesigns[kMaxPlayerCharacters];
214
215 const byte _datFileMajorVersion;
216 const byte _datFileMinorVersion;
217
218 GameFlow _gameFlow;
219 OSystem *_system;
220
221 const NancyGameDescription *_gameDescription;
222
223 Common::Array<Common::WeakPtr<DeferredLoader>> _deferredLoaderObjects;
224};
225
226extern NancyEngine *g_nancy;
227#define GetEngineData(s) (const s*)g_nancy->getEngineData(#s);
228
229} // End of namespace Nancy
230
231#endif // NANCY_H
Definition: array.h:52
Definition: error.h:81
Definition: hashmap.h:85
Definition: path.h:52
Definition: random.h:44
Definition: stream.h:745
Definition: serializer.h:80
Definition: ptr.h:159
Definition: str.h:59
Definition: ustr.h:57
Definition: stream.h:77
Definition: engine.h:149
EngineFeature
Definition: engine.h:282
Definition: graphics.h:38
Definition: nancy.h:101
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave=false) override
void errorString(const char *buf_input, char *buf_output, int buf_output_size) override
void pauseEngineIntern(bool pause) override
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Common::Error loadGameState(int slot) override
bool hasFeature(EngineFeature f) const override
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
Common::Error run() override
Definition: state.h:32
Definition: system.h:166
Language
Definition: language.h:45
Platform
Definition: platform.h:93
Definition: algorithm.h:29
Definition: actionmanager.h:32
Definition: enginedata.h:35
Definition: detection.h:69
Definition: commontypes.h:388