ScummVM API documentation
decoderpuzzle.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_ACTION_DECODERPUZZLE_H
23 #define NANCY_ACTION_DECODERPUZZLE_H
24 
25 #include "engines/nancy/commontypes.h"
26 #include "engines/nancy/movieplayer.h"
27 #include "engines/nancy/action/puzzlerecord.h"
28 
29 namespace Nancy {
30 
31 struct DecoderData;
32 
33 namespace Action {
34 
35 // Keyboard decoding puzzle, new in Nancy14 (AR 182). Keystrokes collect into a
36 // pending sequence; when it matches the typed half of a substitution, the other
37 // half is appended to the decoded line. A sequence that is still a prefix of some
38 // substitution keeps collecting; one that matches nothing - as does Enter, or
39 // overflowing the line - wipes both buffers and plays the carriage-return
40 // animation. Solved once the line equals one of the target words.
41 //
42 // Each scene using it holds two records, one with the substitution table and one
43 // with none (every keystroke emits a random letter); they share the decoded line
44 // through the puzzle data.
45 class DecoderPuzzle : public PuzzleRecord {
46 public:
47  DecoderPuzzle() : PuzzleRecord(7) {}
48  virtual ~DecoderPuzzle() {}
49 
50  void init() override;
51  void onPause(bool paused) override;
52 
53  void readData(Common::SeekableReadStream &stream) override;
54  void execute() override;
55  void handleInput(NancyInput &input) override;
56 
57  bool isViewportRelative() const override { return true; }
58 
59 protected:
60  Common::String getRecordTypeName() const override { return "DecoderPuzzle"; }
61 
62  // One entry of the substitution table: typing `keys` emits `output`.
63  struct Substitution {
64  Common::String keys;
65  Common::String output;
66  };
67 
68  static bool isAcceptedKey(byte key);
69 
70  DecoderData *getPuzzleData() const;
71 
72  // Consumes the pending sequence. True if it produced output; sets noMatch
73  // when the sequence cannot lead to any substitution.
74  bool decodePending(bool &noMatch);
75  void checkSolved();
76  void beginReset();
77  void redraw();
78 
79  // -- File data --
80  byte _saveOutput = 0; // 0x3d
81  byte _restoreOutput = 0; // 0x3e
82  uint16 _fontID = 0; // 0x3f
83  int32 _textX = 0; // 0x41
84  int32 _textY = 0; // 0x45, text baseline
85 
86  Common::Array<Common::String> _words; // target words, uppercased
87  Common::Array<Substitution> _substitutions; // empty = emit random letters
88  int16 _maxLength = 0; // 0x5d
89 
90  RandomSoundBlock _typeSound; // 0x6f, keystroke
91  RandomSoundBlock _decodeSound; // 0xc5, substitution resolved
92 
93  Common::Path _resetMovieName; // 0x11b, carriage-return animation
94  Common::Rect _resetMovieRect; // 0x11f
95  RandomSoundBlock _resetSound; // 0x12f, plays while it runs
96 
97  RandomSoundBlock _solveSoundBlock; // 0x185, plays before the scene change
98 
99  // -- Runtime state --
100  MoviePlayer _resetMovie;
101 
102  Common::String _output; // the decoded line
103  Common::String _pending; // keys typed since the last substitution
104  byte _pendingKey = 0;
105  bool _hasPendingKey = false;
106  bool _decodeSoundPending = false;
107  bool _resetting = false;
108  bool _solved = false;
109  bool _exitRequested = false;
110 };
111 
112 } // End of namespace Action
113 } // End of namespace Nancy
114 
115 #endif // NANCY_ACTION_DECODERPUZZLE_H
Definition: str.h:59
Definition: movieplayer.h:56
Definition: rect.h:536
Definition: path.h:52
Definition: stream.h:745
Definition: input.h:41
Definition: commontypes.h:324
Definition: puzzlerecord.h:37
Definition: decoderpuzzle.h:45
Definition: puzzledata.h:530
Definition: decoderpuzzle.h:63
Definition: actionmanager.h:32