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 = 5;
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  NancyEngine(OSystem *syst, const NancyGameDescription *gd);
77  ~NancyEngine();
78 
79  static NancyEngine *create(GameType type, OSystem *syst, const NancyGameDescription *gd);
80 
81  void errorString(const char *buf_input, char *buf_output, int buf_output_size) override;
82  bool hasFeature(EngineFeature f) const override;
83 
84  Common::Error loadGameState(int slot) override;
85  Common::Error loadGameStream(Common::SeekableReadStream *stream) override;
86  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
87  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
88  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
89 
90  void secondChance();
91 
92  const char *getCopyrightString() const;
93  uint32 getGameFlags() const;
94  const char *getGameId() const;
95  GameType getGameType() const;
96  Common::Language getGameLanguage() const;
97  Common::Platform getPlatform() const;
98 
99  const StaticData &getStaticData() const;
100  const EngineData *getEngineData(const Common::String &name) const;
101  const Common::String getEventFlagName(uint flagID) const;
102 
103  void setState(NancyState::NancyState state, NancyState::NancyState overridePrevious = NancyState::kNone);
104  NancyState::NancyState getState() { return _gameFlow.curState; }
105  void setToPreviousState();
106 
107  void setMouseEnabled(bool enabled);
108 
109  void addDeferredLoader(Common::SharedPtr<DeferredLoader> &loaderPtr);
110 
111  // The first few games used 1/2 for false/true in
112  // inventory, logic conditions, and event flags
113  const byte _true;
114  const byte _false;
115 
116  // Managers
117  ResourceManager *_resource;
118  GraphicsManager *_graphics;
119  CursorManager *_cursor;
120  InputManager *_input;
121  SoundManager *_sound;
122 
123  Common::RandomSource *_randomSource;
124 
125  // Used to check whether we need to show the SaveDialog
126  bool _hasJustSaved;
127 
128 protected:
129  Common::Error run() override;
130  void pauseEngineIntern(bool pause) override;
131 
132 private:
133  struct GameFlow {
134  NancyState::NancyState curState = NancyState::kNone;
135  NancyState::NancyState prevState = NancyState::kNone;
136  NancyState::NancyState nextState = NancyState::kNone;
137  bool changingState = true;
138  };
139 
140  void bootGameEngine();
141 
142  State::State *getStateObject(NancyState::NancyState state) const;
143  void destroyState(NancyState::NancyState state) const;
144 
145  void preloadCals();
146  void readDatFile();
147  // Nancy12 onwards no longer ship their static data in nancy.dat; the values
148  // the engine still needs are provided here instead (see also the EVNT chunk).
149  void populateStaticData();
150 
151  Common::Error synchronize(Common::Serializer &serializer);
152 
153  bool isCompressed();
154 
155  StaticData _staticData;
157 
158  const byte _datFileMajorVersion;
159  const byte _datFileMinorVersion;
160 
161  GameFlow _gameFlow;
162  OSystem *_system;
163 
164  const NancyGameDescription *_gameDescription;
165 
166  Common::Array<Common::WeakPtr<DeferredLoader>> _deferredLoaderObjects;
167 };
168 
169 extern NancyEngine *g_nancy;
170 #define GetEngineData(s) (const s*)g_nancy->getEngineData(#s);
171 
172 } // End of namespace Nancy
173 
174 #endif // NANCY_H
Definition: commontypes.h:354
Definition: nancy.h:74
Definition: str.h:59
EngineFeature
Definition: engine.h:282
Definition: stream.h:77
Definition: error.h:81
Definition: array.h:52
Definition: cursor.h:32
Definition: graphics.h:36
Definition: random.h:44
Definition: stream.h:745
Definition: serializer.h:80
Definition: detection.h:73
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:35
Definition: system.h:166
Definition: ptr.h:159
Definition: engine.h:149
Platform
Definition: platform.h:93
Definition: actionmanager.h:32
Language
Definition: language.h:45