ScummVM API documentation
shovelmeasurepuzzle.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_SHOVELMEASUREPUZZLE_H
23 #define NANCY_ACTION_SHOVELMEASUREPUZZLE_H
24 
25 #include "engines/nancy/commontypes.h"
26 #include "engines/nancy/action/puzzlerecord.h"
27 
28 namespace Nancy {
29 namespace Action {
30 
31 // Nancy17 cemetery plot. A shovel is turned and moved over a grid, with the arrow
32 // keys and Enter or with the buttons on screen. A measuring tape shows how many
33 // steps there are, in the direction the shovel faces, to the end of one of the
34 // stretches of the path that has to be followed; with no such end ahead the tape
35 // shows a number that means nothing. Leaving the path too many times in a row
36 // loses, getting to its end wins.
38 public:
40  virtual ~ShovelMeasurePuzzle() {}
41 
42  void init() override;
43 
44  void readData(Common::SeekableReadStream &stream) override;
45  void execute() override;
46  void handleInput(NancyInput &input) override;
47 
48  bool isViewportRelative() const override { return true; }
49 
50 protected:
51  Common::String getRecordTypeName() const override { return "ShovelMeasurePuzzle"; }
52 
53  enum Direction {
54  kNorth,
55  kSouth,
56  kEast,
57  kWest,
58  kNumDirections,
59  kNoDirection = -1
60  };
61 
62  enum Command {
63  kNoCommand,
64  kFace,
65  kStep
66  };
67 
68  struct Cell {
69  bool isValid = false;
70  bool endsStretch[kNumDirections] = { false, false, false, false };
71  };
72 
73  // A stretch of the path
74  struct Stretch {
75  Direction direction = kNorth;
76  Common::Point from;
77  Common::Point to;
78  };
79 
80  enum Outcome {
81  kNone,
82  kWon,
83  kLost,
84  kExited
85  };
86 
87  static Direction readDirection(Common::SeekableReadStream &stream);
88  static Common::Point getNeighbor(const Common::Point &pos, Direction direction);
89  // Clockwise, in radians
90  static double getAngle(Direction direction);
91 
92  bool isValidCell(const Common::Point &pos) const;
93  Cell &getCell(const Common::Point &pos) { return _cells[pos.y * _numColumns + pos.x]; }
94  const Cell &getCell(const Common::Point &pos) const { return _cells[pos.y * _numColumns + pos.x]; }
95  Common::Point getCellCenter(const Common::Point &pos) const;
96 
97  void face(Direction direction);
98  void step();
99  void finishMove();
100  void updateMeasure();
101 
102  // Draws a picture turned clockwise around a point of its own, which goes to a point on screen
103  void drawRotated(const Common::Rect &src, const Common::Point &srcPivot, const Common::Point &destPivot, double angle);
104  void redraw();
105 
106  // -- File data --
107  uint16 _buttonCursor = 0;
108  int32 _maxWrongSteps = 0;
109  uint32 _moveTime = 0; // in milliseconds
110 
111  Common::Rect _directionButtons[kNumDirections];
112  Common::Rect _dialSrc;
113  Common::Rect _dialDest;
114  Common::Point _dialPivot; // relative to the dial
115  Common::Rect _stepPressedSrc;
116  Common::Rect _stepButton;
117 
118  Common::Point _startPos;
119  Direction _startDirection = kNorth;
120 
121  Common::Rect _shovelSrc;
122  Common::Rect _tapeDest;
123  // The pictures of the tape being pulled out to each length
125  uint _maxMeasure = 0;
126 
127  Common::Rect _firstCell;
128  Common::Point _cellSpacing;
129  int _numColumns = 0;
130  int _numRows = 0;
131  Common::Array<Cell> _cells;
133 
134  RandomSoundBlock _turnSound;
135  RandomSoundBlock _stepSound;
136  RandomSoundBlock _winSound;
137  SceneChangeWithFlag _loseScene;
138  RandomSoundBlock _loseSound;
139 
140  // -- Runtime --
141  Common::Point _pos;
142  Common::Point _targetPos;
143  Direction _direction = kNorth;
144  Direction _targetDirection = kNorth;
145  Command _move = kNoCommand;
146  uint32 _moveStartTime = 0;
147 
148  uint _measure = 0;
149  uint _shownMeasure = 0;
150  // Where the tape last showed a meaningless number from; counting stops there
151  Common::Point _lastGuessPos;
152 
153  uint _currentStretch = 0;
154  int32 _numWrongSteps = 0;
155  Outcome _outcome = kNone;
156 };
157 
158 } // End of namespace Action
159 } // End of namespace Nancy
160 
161 #endif // NANCY_ACTION_SHOVELMEASUREPUZZLE_H
Definition: str.h:59
Definition: array.h:52
Definition: rect.h:536
Definition: stream.h:745
Definition: shovelmeasurepuzzle.h:37
Definition: input.h:41
Definition: commontypes.h:206
T y
Definition: rect.h:49
Definition: commontypes.h:324
T x
Definition: rect.h:48
Definition: rect.h:144
Definition: puzzlerecord.h:37
Definition: shovelmeasurepuzzle.h:74
Definition: actionmanager.h:32
Definition: shovelmeasurepuzzle.h:68