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 
36 namespace Common {
37 class RandomSource;
38 class Serializer;
39 }
40 
55 namespace Nancy {
56 
57 static const int kSavegameVersion = 3;
58 
59 struct NancyGameDescription;
60 
61 class ResourceManager;
62 class IFF;
63 class InputManager;
64 class SoundManager;
65 class GraphicsManager;
66 class CursorManager;
67 class NancyConsole;
68 class DeferredLoader;
69 
70 namespace State {
71 class State;
72 }
73 
74 class NancyEngine : public Engine {
75 public:
76  friend class NancyConsole;
77 
78  NancyEngine(OSystem *syst, const NancyGameDescription *gd);
79  ~NancyEngine();
80 
81  static NancyEngine *create(GameType type, OSystem *syst, const NancyGameDescription *gd);
82 
83  void errorString(const char *buf_input, char *buf_output, int buf_output_size) override;
84  bool hasFeature(EngineFeature f) const override;
85 
86  Common::Error loadGameState(int slot) override;
87  Common::Error loadGameStream(Common::SeekableReadStream *stream) override;
88  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
89  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
90  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
91 
92  void secondChance();
93 
94  const char *getCopyrightString() const;
95  uint32 getGameFlags() const;
96  const char *getGameId() const;
97  GameType getGameType() const;
98  Common::Language getGameLanguage() const;
99  Common::Platform getPlatform() const;
100 
101  const StaticData &getStaticData() const;
102  const EngineData *getEngineData(const Common::String &name) const;
103 
104  void setState(NancyState::NancyState state, NancyState::NancyState overridePrevious = NancyState::kNone);
105  NancyState::NancyState getState() { return _gameFlow.curState; }
106  void setToPreviousState();
107 
108  void setMouseEnabled(bool enabled);
109 
110  void addDeferredLoader(Common::SharedPtr<DeferredLoader> &loaderPtr);
111 
112  // The first few games used 1/2 for false/true in
113  // inventory, logic conditions, and event flags
114  const byte _true;
115  const byte _false;
116 
117  // Managers
118  ResourceManager *_resource;
119  GraphicsManager *_graphics;
120  CursorManager *_cursor;
121  InputManager *_input;
122  SoundManager *_sound;
123 
124  Common::RandomSource *_randomSource;
125 
126  // Used to check whether we need to show the SaveDialog
127  bool _hasJustSaved;
128 
129 protected:
130  Common::Error run() override;
131  void pauseEngineIntern(bool pause) override;
132 
133 private:
134  struct GameFlow {
135  NancyState::NancyState curState = NancyState::kNone;
136  NancyState::NancyState prevState = NancyState::kNone;
137  NancyState::NancyState nextState = NancyState::kNone;
138  bool changingState = true;
139  };
140 
141  void bootGameEngine();
142 
143  State::State *getStateObject(NancyState::NancyState state) const;
144  void destroyState(NancyState::NancyState state) const;
145 
146  void preloadCals();
147  void readDatFile();
148 
149  Common::Error synchronize(Common::Serializer &serializer);
150 
151  bool isCompressed();
152 
153  StaticData _staticData;
155 
156  const byte _datFileMajorVersion;
157  const byte _datFileMinorVersion;
158 
159  GameFlow _gameFlow;
160  OSystem *_system;
161 
162  const NancyGameDescription *_gameDescription;
163 
164  Common::Array<Common::WeakPtr<DeferredLoader>> _deferredLoaderObjects;
165 };
166 
167 extern NancyEngine *g_nancy;
168 #define GetEngineData(s) (const s*)g_nancy->getEngineData(#s);
169 
170 } // End of namespace Nancy
171 
172 #endif // NANCY_H
Definition: commontypes.h:321
Definition: nancy.h:74
Definition: str.h:59
EngineFeature
Definition: engine.h:258
Definition: stream.h:77
Definition: error.h:81
Definition: array.h:52
Definition: cursor.h:34
Definition: graphics.h:37
Definition: random.h:44
Definition: stream.h:745
Definition: serializer.h:79
Definition: detection.h:49
Definition: hashmap.h:85
Definition: ustr.h:57
Definition: input.h:70
Definition: algorithm.h:29
Definition: sound.h:44
Definition: state.h:32
Definition: graphics.h:38
Definition: resource.h:36
Definition: enginedata.h:34
Definition: console.h:36
Definition: system.h:163
Definition: ptr.h:159
Definition: engine.h:144
Platform
Definition: platform.h:93
Definition: actionmanager.h:32
Language
Definition: language.h:45