ScummVM API documentation
qd_game_object.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_H
23#define QDENGINE_QDCORE_QD_GAME_OBJECT_H
24
25#include "qdengine/parser/xml_fwd.h"
26#include "qdengine/system/input/mouse_input.h"
27#include "qdengine/system/graphics/gr_screen_region.h"
28#include "qdengine/qdcore/qd_named_object.h"
29
30namespace Common {
31class WriteStream;
32}
33
34namespace QDEngine {
35
36const int QD_OBJ_MOVING_FLAG = 0x01;
37const int QD_OBJ_HIDDEN_FLAG = 0x02;
38const int QD_OBJ_INVERSE_PERSPECTIVE_FLAG = 0x04;
39const int QD_OBJ_SHOW_NAME_FLAG = 0x08;
40const int QD_OBJ_NO_SCALE_FLAG = 0x10;
41const int QD_OBJ_SCREEN_COORDS_FLAG = 0x20;
42const int QD_OBJ_NON_PLAYER_PERSONAGE_FLAG = 0x40;
43const int QD_OBJ_HAS_BOUND_FLAG = 0x80;
44const int QD_OBJ_DISABLE_MOVEMENT_FLAG = 0x100;
45const int QD_OBJ_DISABLE_MOUSE_FLAG = 0x200;
46const int QD_OBJ_IS_IN_TRIGGER_FLAG = 0x400;
47const int QD_OBJ_STATE_CHANGE_FLAG = 0x800;
48const int QD_OBJ_IS_IN_INVENTORY_FLAG = 0x1000;
49const int QD_OBJ_KEYBOARD_CONTROL_FLAG = 0x2000;
50const int QD_OBJ_FIXED_SCREEN_COORDS_FLAG = 0x4000;
51
54public:
56 qdGameObject(const qdGameObject &obj);
58
59 qdGameObject &operator = (const qdGameObject &obj);
60
61 void set_parallax_offset(int offs_x, int offs_y) {
62 _parallax_offset.x = offs_x;
63 _parallax_offset.y = offs_y;
64 }
65 const Vect2i &get_parallax_offset() const {
66 return _parallax_offset;
67 }
68
69 virtual void redraw(int offs_x = 0, int offs_y = 0) const = 0;
70 virtual void debug_redraw() const = 0;
71 virtual void draw_contour(uint32 color) const = 0;
72 virtual void draw_shadow(int offs_x, int offs_y, uint32 color, int alpha) const = 0;
73
74 virtual bool need_redraw() const {
75 return false;
76 }
77 virtual void post_redraw() { }
78
79 virtual const grScreenRegion last_screen_region() const {
80 return grScreenRegion_EMPTY;
81 }
82 virtual grScreenRegion screen_region() const {
83 return grScreenRegion(grScreenRegion_EMPTY);
84 }
85
86 virtual bool mouse_handler(int x, int y, mouseDispatcher::mouseEvent ev) = 0;
87 virtual bool hit(int x, int y) const = 0;
88
89 const Vect2i &screen_pos() const {
90 return _screen_r;
91 }
92 virtual bool update_screen_pos();
93 virtual Vect2s screen_size() const = 0;
94
95 float screen_depth() const {
96 return _screen_depth;
97 }
98
99 virtual bool is_visible() const {
100 return !check_flag(QD_OBJ_HIDDEN_FLAG);
101 }
102
103 const Vect3f &R() const {
104 return _r;
105 }
106 void set_pos(const Vect3f &rr) {
107 _r = rr;
108 }
109
110 virtual bool load_script(const xml::tag *p) = 0;
111 virtual bool save_script(Common::WriteStream &fh, int indent = 0) const = 0;
112
113 virtual bool load_resources() {
114 return true;
115 };
116 virtual void free_resources() { };
117
119 virtual bool init();
120
121 virtual void quant(float dt);
122
123 virtual bool init_grid_zone() {
124 return false;
125 }
126 virtual bool toggle_grid_zone(bool make_walkable = false) {
127 return false;
128 }
129 virtual bool save_grid_zone() {
130 return false;
131 }
132 virtual bool restore_grid_zone() {
133 return false;
134 }
135 virtual bool set_grid_zone_attributes(int attr) const {
136 return false;
137 }
138 virtual bool drop_grid_zone_attributes(int attr) const {
139 return false;
140 }
141
143 virtual bool get_debug_info(Common::String &buf) const {
144 return true;
145 }
146
148 bool load_data(Common::SeekableReadStream &fh, int saveVersion);
151
152 const Vect2i &get_screen_R() const {
153 return _screen_r;
154 }
155
156 void setTempPosInList(uint pos) { _tempPosInList = pos; }
157 uint tempPosInList() const { return _tempPosInList; }
158
159 Common::String flag2str(int flags) const;
160
161protected:
162
163 virtual bool load_script_body(const xml::tag *p);
164 virtual bool save_script_body(Common::WriteStream &fh, int indent = 0) const;
165
166 void set_screen_R(const Vect2i &v) {
167 _screen_r = v;
168 }
169
170private:
171
172 Vect3f _r;
173 Vect2i _parallax_offset;
174
175 Vect2i _screen_r;
176 float _screen_depth;
177 uint _tempPosInList;
178};
179
180#ifdef __QD_DEBUG_ENABLE__
181inline bool qdbg_is_object(const qdNamedObject *obj, const char *scene_name, const char *object_name) {
182 if (dynamic_cast<const qdGameObject * >(obj)) {
183 if (obj->name() && !strcmp(object_name, obj->name())) {
184 if (!scene_name || (obj->owner() && obj->owner()->name() && !strcmp(obj->owner()->name(), scene_name)))
185 return true;
186 }
187 }
188
189 return false;
190}
191#else
192inline bool qdbg_is_object(const qdNamedObject *, const char *, const char *) {
193 return false;
194}
195#endif
196
197} // namespace QDEngine
198
199#endif // QDENGINE_QDCORE_QD_GAME_OBJECT_H
Definition: stream.h:745
Definition: str.h:59
Definition: stream.h:77
Definition: xmath.h:268
Definition: xmath.h:419
Definition: xmath.h:533
Прямоугольная область на экране.
Definition: gr_screen_region.h:31
mouseEvent
События.
Definition: mouse_input.h:41
Базовый класс для игровых объектов.
Definition: qd_game_object.h:53
virtual bool get_debug_info(Common::String &buf) const
Копирует в буфер отладочную информацию для вывода на экран в отладочном режиме.
Definition: qd_game_object.h:143
bool load_data(Common::SeekableReadStream &fh, int saveVersion)
Загрузка данных из сэйва.
virtual bool init()
Инициализация объекта, вызывается при старте и перезапуске игры.
bool save_data(Common::WriteStream &fh) const
Запись данных в сэйв.
Поименованный объект.
Definition: qd_named_object.h:70
bool check_flag(int fl) const
Возвращает true, если установлен флаг fl.
Definition: qd_named_object.h:99
int flags() const
Возвращает значение флагов объекта.
Definition: qd_named_object.h:108
XML тег.
Definition: xml_tag.h:33
Definition: algorithm.h:29
Базовый класс для игровых ресурсов.
Definition: console.h:28