ScummVM API documentation
qd_game_object_animated.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 QDENGINE_QDCORE_QD_GAME_OBJECT_ANIMATED_H
23#define QDENGINE_QDCORE_QD_GAME_OBJECT_ANIMATED_H
24
25#include "qdengine/parser/xml_fwd.h"
26#include "qdengine/qdcore/qd_animation.h"
27#include "qdengine/qdcore/qd_coords_animation.h"
28#include "qdengine/qdcore/qd_game_object.h"
29#include "qdengine/qdcore/qd_game_object_state.h"
30
31namespace QDEngine {
32
34
38public:
39 enum StateStatus {
40 STATE_INACTIVE,
41 STATE_QUEUED,
42 STATE_ACTIVE,
43 STATE_DONE
44 };
45
49
50 qdGameObjectAnimated &operator = (const qdGameObjectAnimated &obj);
51
52 int named_object_type() const {
53 return QD_NAMED_OBJECT_ANIMATED_OBJ;
54 }
55
57 virtual const Vect3f &bound(bool perspective_correction = true) const;
58
60 bool auto_bound();
62 virtual float radius() const;
64 void set_bound(const Vect3f &b);
66 bool has_bound() const {
67 if (check_flag(QD_OBJ_HAS_BOUND_FLAG)) return true;
68 if (_cur_state != -1 && _states[_cur_state]->has_bound()) return true;
69 return false;
70 }
72 void draw_bound() const;
73 void draw_bound(Vect3f r, Vect3f const &bound, int const color) const;
75 bool inters_with_bound(Vect3f bnd, Vect3f cen, bool perspective_correction = true) const;
76
78 int cur_state() const {
79 return _cur_state;
80 }
82 void set_cur_state(int st) {
83 _cur_state = st;
84 }
86 int max_state() const {
87 return _states.size();
88 }
91
94
96 bool is_state_active(const char *state_name) const;
98 bool was_state_active(const char *state_name) const;
99
101 bool is_state_active(const qdGameObjectState *p) const {
102 if (_cur_state != -1 && _states[_cur_state] == p)
103 return true;
104
105 return false;
106 }
107
109 bool was_state_previous(const char *state_name) const;
112 return (_last_state == p);
113 }
114
116 bool was_state_active(const qdGameObjectState *p) const {
118 }
119
120 bool is_state_waiting(const qdGameObjectState *p) const {
121 if (_queued_state == p) return true;
122 return false;
123 }
124
125 bool is_state_waiting(const char *state_name) const;
126
129 return _states;
130 }
131
133 virtual bool can_change_state(const qdGameObjectState *state = NULL) const;
134
135 qdGameObjectState *get_state(const char *state_name);
136 qdGameObjectState *get_state(int state_index);
137 qdGameObjectState *get_cur_state() {
138 return get_state(cur_state());
139 }
140
141 const qdGameObjectState *get_state(const char *state_name) const;
142 const qdGameObjectState *get_state(int state_index) const;
143 const qdGameObjectState *get_cur_state() const {
144 return get_state(cur_state());
145 }
146
147 void set_queued_state(qdGameObjectState *st) {
148 _queued_state = st;
149 }
150
151 qdGameObjectState *queued_state() {
152 return _queued_state;
153 }
154 const qdGameObjectState *queued_state() const {
155 return _queued_state;
156 }
157
158 void merge_states(qdGameObjectAnimated *p);
159 void split_states(qdGameObjectAnimated *p);
160
161 StateStatus state_status(const qdGameObjectState *p) const;
162
163 bool add_state(qdGameObjectState *p);
164 bool insert_state(int iBefore, qdGameObjectState *p);
165 qdGameObjectState *remove_state(int state_num);
166 bool remove_state(qdGameObjectState *p);
167
168 virtual void set_state(int st);
169 virtual void set_state(qdGameObjectState *p);
170 void restore_state();
171
172 bool has_camera_mode() const;
173 const qdCameraMode &camera_mode() const;
174
176 int num_directions() const;
177
178 const Vect3f &default_R() const {
179 return _default_r;
180 }
181 void set_default_pos(const Vect3f &r) {
182 _default_r = r;
183 }
184
185 void set_default_state();
186 virtual qdGameObjectState *get_default_state();
187 virtual const qdGameObjectState *get_default_state() const;
188
189 qdGameObjectState *get_inventory_state();
190 qdGameObjectState *get_mouse_state();
191 qdGameObjectState *get_mouse_hover_state();
192
193 bool update_screen_pos();
194
195 // Animation
196 qdAnimation *get_animation() {
197 return &_animation;
198 }
199 const qdAnimation *get_animation() const {
200 return &_animation;
201 }
202
203 void set_animation(qdAnimation *p, const qdAnimationInfo *inf = NULL);
204 void set_animation_info(qdAnimationInfo *inf);
205 Vect2s screen_size() const {
206 return Vect2s(_animation.size_x(), _animation.size_y());
207 }
208
209 void set_screen_rotation(float target_angle, float speed);
210 float screen_rotation() const;
211
212 void set_screen_scale(const Vect2f &scale, const Vect2f &speed);
213 const Vect2f &screen_scale() const;
214
215 bool has_screen_transform() const {
216 return _current_transform();
217 }
218
219 // Inventory
220 int inventory_type() const {
221 return _inventory_type;
222 }
223 void set_inventory_type(int tp) {
224 _inventory_type = tp;
225 }
226
227 // Logic
228 bool hit(int x, int y) const;
229 bool mouse_handler(int x, int y, mouseDispatcher::mouseEvent ev);
230 void quant(float dt);
233
234 // Redraw
235 void redraw(int offs_x = 0, int offs_y = 0) const;
236 bool need_redraw() const;
237
238 void post_redraw();
239 void draw_shadow(int offs_x, int offs_y, uint32 color, int alpha) const;
240
242
243 void debug_redraw() const;
244 void draw_contour(uint32 color) const;
245 void draw_grid_zone(const Vect2s sz) const;
246
247 int mouse_cursor_ID() const;
248
249 bool load_script(const xml::tag *p);
250 bool save_script(Common::WriteStream &fh, int indent = 0) const;
251
253 bool load_data(Common::SeekableReadStream &fh, int save_version);
256
257 bool load_resources();
258 void free_resources();
259
261 bool init();
262
263 bool is_visible() const;
264
265 const Vect2s &grid_size() const {
266 return _grid_size;
267 }
268
269 bool init_grid_zone();
270 virtual bool toggle_grid_zone(bool make_walkable = false);
271 bool save_grid_zone();
272 bool restore_grid_zone();
273 bool set_grid_zone_attributes(int attr) const;
274 bool check_grid_zone_attributes(int attr) const;
275 bool drop_grid_zone_attributes(int attr) const;
276 bool set_grid_zone_attributes(const Vect2f &r, int attr) const;
277 bool check_grid_zone_attributes(const Vect2f &r, int attr) const;
278 bool drop_grid_zone_attributes(const Vect2f &r, int attr) const;
279
280 const char *inventory_name() const {
281 return _inventory_name.c_str();
282 }
283 void set_inventory_name(const char *name) {
284 if (name)
285 _inventory_name = name;
286 else
287 _inventory_name.clear();
288 }
289 bool has_inventory_name() const {
290 return !_inventory_name.empty();
291 }
292
293 const grScreenRegion last_screen_region() const {
294 return _last_screen_region;
295 }
296 virtual grScreenRegion screen_region() const;
297
298 int inventory_cell_index() const {
299 return _inventory_cell_index;
300 }
301 void set_inventory_cell_index(int idx) {
302 _inventory_cell_index = idx;
303 }
304
305 int last_chg_time() const {
306 return _last_chg_time;
307 }
308 void set_last_chg_time(int time) {
309 _last_chg_time = time;
310 }
311 int idle_time() const;
312
313 int shadow_color() const;
314 int shadow_alpha() const;
315 void set_shadow(uint32 color, int alpha) {
316 _shadow_color = color;
317 _shadow_alpha = alpha;
318 }
319 void clear_shadow() {
320 set_shadow(0, QD_NO_SHADOW_ALPHA);
321 }
322
323protected:
324
325 bool load_script_body(const xml::tag *p);
326 bool save_script_body(Common::WriteStream &fh, int indent = 0) const;
327
328 void set_last_state(qdGameObjectState *p) {
330 _last_state = p;
331 }
332
333 void set_last_inventory_state(qdGameObjectState *p) {
335 _last_inventory_state = p;
336 }
337
338private:
339
340 int _cur_state;
341 qdGameObjectStateVector _states;
342
343 qdGameObjectState *_queued_state;
344 qdGameObjectState *_last_inventory_state;
345
346 int _inventory_type;
347
348 qdAnimation _animation;
349
350 Vect3f _bound;
351 float _radius;
352
353 Vect3f _default_r;
354
355 Vect3f _grid_r;
356 Vect2s _grid_size;
357
358 Common::String _inventory_name;
359
360 qdScreenTransform _current_transform;
361 qdScreenTransform _target_transform;
362 qdScreenTransform _transform_speed;
363
364 qdScreenTransform _last_transform;
365
366 qdGameObjectState *_last_state;
367
369 int _inventory_cell_index;
370
371 const qdAnimationFrame *_last_frame;
372 grScreenRegion _last_screen_region;
373 float _last_screen_depth;
374
375 uint32 _lastShadowColor;
376 int _lastShadowAlpha;
377
379 int _last_chg_time;
380
382 uint32 _shadow_color;
384 int _shadow_alpha;
385
386 void clear_states();
387};
388
389} // namespace QDEngine
390
391#endif // QDENGINE_QDCORE_QD_GAME_OBJECT_ANIMATED_H
size_type size() const
Definition: array.h:316
Definition: stream.h:745
Definition: str.h:59
Definition: stream.h:77
Definition: xmath.h:117
Definition: xmath.h:419
Definition: xmath.h:533
mouseEvent
События.
Definition: mouse_input.h:41
Dynamic object.
Definition: qd_game_object_animated.h:37
void set_bound(const Vect3f &b)
Устанавливает баунд объекта.
bool has_bound() const
Возвращает true, если у объекта выставлен баунд.
Definition: qd_game_object_animated.h:66
int named_object_type() const
Возвращает тип объекта.
Definition: qd_game_object_animated.h:52
bool get_debug_info(Common::String &buf) const
Копирует в буфер отладочную информацию для вывода на экран в отладочном режиме.
bool is_state_active(const char *state_name) const
Возвращает true, если состояние с именем state_name активно.
int num_directions() const
Возвращает количество имеющихся у объекта направлений.
bool is_state_active(const qdGameObjectState *p) const
Возвращает true, если состояние state активно.
Definition: qd_game_object_animated.h:101
bool was_state_previous(const char *state_name) const
Возвращает true, если состояние с именем state_name было активно перед активным в данный момент состо...
int max_state() const
Возвращает количество состояний объекта.
Definition: qd_game_object_animated.h:86
int cur_state() const
Возвращает номер текущего состояния объекта.
Definition: qd_game_object_animated.h:78
bool save_data(Common::WriteStream &fh) const
Запись данных в сэйв.
bool load_data(Common::SeekableReadStream &fh, int save_version)
Загрузка данных из сэйва.
void draw_bound() const
Отрисовка баунда (для отладки).
bool auto_bound()
Устанавливает баунд объекта по текущему состоянию.
virtual bool can_change_state(const qdGameObjectState *state=NULL) const
Возвращает true, если объект в данный момент может менять состояние.
bool was_state_active(const char *state_name) const
Возвращает true, если состояние с именем state_name было активировано.
bool was_state_previous(const qdGameObjectState *p) const
Возвращает true, если состояние p было активно перед активным в данный момент состоянием.
Definition: qd_game_object_animated.h:111
const qdGameObjectStateVector & state_vector() const
Возвращает состояния объекта.
Definition: qd_game_object_animated.h:128
bool init()
Инициализация объекта, вызывается при старте и перезапуске игры.
int get_state_index(const qdGameObjectState *p) const
Возвращает номер состояния или -1 если не может такое состояние найти.
bool was_state_active(const qdGameObjectState *p) const
Возвращает true, если состояние state было активировано.
Definition: qd_game_object_animated.h:116
void set_states_owner()
Установка владельца состояний.
bool handle_state_end()
Обработка окончания текущего состояния.
virtual float radius() const
Возвращает радиус объекта.
virtual const Vect3f & bound(bool perspective_correction=true) const
Возвращает баунд объекта.
void set_cur_state(int st)
Устанавливает номер текущего состояния объекта.
Definition: qd_game_object_animated.h:82
bool inters_with_bound(Vect3f bnd, Vect3f cen, bool perspective_correction=true) const
Пересекается ли баунд, расположенный в точке с заданным баундом с центром в cen.
Базовый класс для игровых объектов.
Definition: qd_game_object.h:53
Состояние динамического объекта - базовый класс.
Definition: qd_game_object_state.h:91
@ QD_OBJ_STATE_FLAG_WAS_ACTIVATED
Состояние уже было активировано.
Definition: qd_game_object_state.h:139
@ QD_OBJ_STATE_FLAG_INVENTORY
Состояние для инвентори.
Definition: qd_game_object_state.h:106
@ QD_OBJ_STATE_FLAG_MOUSE_HOVER_STATE
Включать состояние, когда мышь над объектом в инвентори.
Definition: qd_game_object_state.h:149
@ QD_OBJ_STATE_FLAG_MOUSE_STATE
Включать состояние, когда объект взят на мышь.
Definition: qd_game_object_state.h:147
const char * name() const
Возвращает имя объекта.
Definition: qd_named_object_base.h:40
bool check_flag(int fl) const
Возвращает true, если установлен флаг fl.
Definition: qd_named_object.h:99
XML тег.
Definition: xml_tag.h:33
Базовый класс для игровых ресурсов.
Definition: console.h:28