ScummVM API documentation
character.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 CHARACTER_H
23 #define CHARACTER_H
24 
25 #include "common/hashmap.h"
26 #include "common/ptr.h"
27 #include "common/rect.h"
28 #include "common/scummsys.h"
29 
30 namespace Common {
31 class SeekableReadStream;
32 class ReadStream;
33 class WriteStream;
34 } // namespace Common
35 namespace Graphics {
36 struct Surface;
37 class ManagedSurface;
38 } // namespace Graphics
39 
40 namespace AGDS {
41 
42 class AGDSEngine;
43 class Object;
44 using ObjectPtr = Common::SharedPtr<Object>;
45 class Animation;
46 using AnimationPtr = Common::SharedPtr<Animation>;
47 
48 class Character {
50  AGDSEngine *_engine;
51  ObjectPtr _object;
52  AnimationPtr _animation;
53  FogPtr _fog;
54  bool _jokes;
55  Common::String _name;
56  Common::String _processName;
57  Common::Point _pos;
58  Common::Point _animationPos;
59  bool _enabled;
60  bool _visible;
61  bool _stopped;
62  bool _shown;
63  int _phase;
64  int _frames;
65  int _direction;
66  int _jokesDirection;
67  int _movementDirections;
68  int _fogMinZ, _fogMaxZ;
69 
70  struct AnimationDescription {
71  struct Frame {
72  int x, y;
73  uint w, h;
74  };
75 
76  Common::String filename;
77  Common::Array<Frame> frames;
78  };
80  const AnimationDescription *_description;
81 
82  bool animate(int direction, int speed, bool jokes);
83  Common::Point animationPosition() const;
84 
85 public:
86  Character(AGDSEngine *engine, const Common::String &name);
87  ~Character();
88 
89  void associate(const Common::String &name);
90 
91  const AnimationDescription *animationDescription(uint index) const {
92  auto it = _animations.find(index);
93  return it != _animations.end() ? &it->_value : nullptr;
94  }
95 
96  const Common::String &name() const {
97  return _name;
98  }
99 
100  const ObjectPtr &object() const {
101  return _object;
102  }
103 
104  void load(Common::SeekableReadStream &stream);
105  void loadState(Common::ReadStream &stream);
106  void saveState(Common::WriteStream &stream) const;
107 
108  void enable(bool enabled = true) {
109  _enabled = enabled;
110  }
111 
112  void visible(bool visible);
113  bool visible() const {
114  return _visible && _shown;
115  }
116 
117  bool active() const {
118  return _enabled && _visible;
119  }
120 
121  bool animate(Common::Point pos, int direction, int speed);
122 
123  void stop();
124  void leave(const Common::String &processName);
125 
126  int phase() const {
127  return _jokes ? _phase : -1;
128  }
129  void phase(int phase) {
130  _phase = phase;
131  }
132 
133  void position(Common::Point pos) {
134  _pos = pos;
135  }
136 
137  Common::Point position() const {
138  return _pos;
139  }
140  bool pointIn(Common::Point pos) const;
141 
142  void notifyProcess(const Common::String &processName);
143  bool moveTo(const Common::String &processName, Common::Point dst, int direction);
144  void pointTo(const Common::String &processName, Common::Point dst);
145 
146  bool direction(int dir);
147 
148  int direction() const {
149  return _jokes ? _jokesDirection : _direction;
150  }
151 
152  void tick(bool reactivate);
153  void paint(Graphics::Surface &backbuffer, Common::Point pos) const;
154 
155  int getDirectionForMovement(Common::Point delta);
156 
157  int z() const;
158 
159  void reset();
160  void setFog(Graphics::ManagedSurface *surface, int minZ, int maxZ);
161 };
162 
163 } // End of namespace AGDS
164 
165 #endif /* AGDS_CHARACTER_H */
Definition: managed_surface.h:51
Definition: str.h:59
Definition: surface.h:67
Definition: stream.h:77
Definition: character.h:48
Definition: stream.h:745
Definition: agds.h:58
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: rect.h:144
Definition: stream.h:385
Definition: agds.h:81