ScummVM API documentation
qd_trigger_element.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_TRIGGER_ELEMENT_H
23 #define QDENGINE_QDCORE_QD_TRIGGER_ELEMENT_H
24 
25 #include "qdengine/parser/xml_fwd.h"
26 #include "qdengine/qdcore/qd_named_object.h"
27 #include "qdengine/qdcore/qd_named_object_reference.h"
28 
29 namespace Common {
30 class WriteStream;
31 }
32 
33 namespace QDEngine {
34 
35 class qdTriggerElement;
36 class qdTriggerLink;
37 
38 typedef qdTriggerElement *qdTriggerElementPtr;
39 typedef qdTriggerElement const *qdTriggerElementConstPtr;
40 
42 
46 public:
48  enum LinkStatus {
52 
57 
60  LINK_DONE
61  };
62 
63  qdTriggerLink(qdTriggerElementPtr p, int tp = 0);
64  qdTriggerLink();
65  ~qdTriggerLink() { }
66 
68  LinkStatus status() const {
69  return _status;
70  }
73  _status = st;
74  }
75 
77  int type() const {
78  return _type;
79  }
81  void set_type(int _t) {
82  _type = _t;
83  }
84 
86  qdTriggerElementPtr const &element() const {
87  return _element;
88  }
90  void set_element(qdTriggerElementPtr const &el) {
91  _element = el;
92  }
93 
95  int element_ID() const {
96  return _element_ID;
97  }
99 
102  bool set_element_ID(int id) {
103  if (!_element) {
104  _element_ID = id;
105  return true;
106  }
107  return false;
108  }
109 
110  bool operator == (qdTriggerElementConstPtr e) const {
111  return (_element == e);
112  }
113 
115  void activate();
117  void deactivate();
118 
120  void toggle_auto_restart(bool state) {
121  _auto_restart = state;
122  }
124  bool auto_restart() const {
125  return _auto_restart;
126  }
127 
128  bool load_script(const xml::tag *p);
129  bool save_script(Common::WriteStream &fh, int indent = 0) const;
130 
131  Common::String toString();
132 
133 private:
135  int _type;
137  qdTriggerElementPtr _element;
139  int _element_ID;
140 
142  LinkStatus _status;
143 
145  bool _auto_restart;
146 
147 };
148 
150 
153 public:
156  ~qdTriggerElement();
157 
158  enum {
159  ROOT_ID = -1,
160  INVALID_ID = -2
161  };
162 
163  enum ElementStatus {
164  TRIGGER_EL_INACTIVE,
165  TRIGGER_EL_WAITING,
166  TRIGGER_EL_WORKING,
167  TRIGGER_EL_DONE
168  };
169 
170 
171  qdTriggerLink *find_child_link(qdTriggerElementConstPtr ptrChild);
172  qdTriggerLink *find_child_link(int child_id);
173 
174  qdTriggerLink *find_parent_link(qdTriggerElementConstPtr ptrParent);
175  qdTriggerLink *find_parent_link(int parent_id);
176 
178  bool is_active() const {
179  return _is_active;
180  }
182  void make_active(bool v) {
183  _is_active = v;
184  }
185 
187 
191  bool debug_set_active();
193 
196  bool debug_set_done();
198 
201  bool debug_set_inactive();
202 
203  bool check_external_conditions(int link_type);
204  bool check_internal_conditions();
205 
206  ElementStatus status() const {
207  return _status;
208  }
209  void set_status(ElementStatus st);
210 // void set_status(ElementStatus st){ _status = st; }
211 
212  int ID() const {
213  return _ID;
214  }
215  void set_id(int id) {
216  _ID = id;
217  }
218 
219  qdNamedObject *object() const {
220  return _object;
221  }
222  bool add_object_trigger_reference();
223  bool clear_object_trigger_references();
224 
225  bool retrieve_object(const qdNamedObjectReference &ref);
226  bool retrieve_link_elements(qdTriggerChain *p);
227 
228  qdTriggerLinkList &parents() {
229  return _parents;
230  }
231  qdTriggerLinkList &children() {
232  return _children;
233  }
234 
235  const qdTriggerLinkList &parents() const {
236  return _parents;
237  }
238  const qdTriggerLinkList &children() const {
239  return _children;
240  }
241 
242  bool is_parent(qdTriggerElementConstPtr p);
243  bool is_child(qdTriggerElementConstPtr p);
244 
245  bool add_parent(qdTriggerElementPtr p, int link_type = 0);
246  bool add_child(qdTriggerElementPtr p, int link_type = 0, bool auto_restart = false);
247 
248  bool remove_parent(qdTriggerElementPtr p);
249  bool remove_child(qdTriggerElementPtr p);
250 
251  bool set_child_link_status(qdTriggerElementConstPtr child, qdTriggerLink::LinkStatus st);
252  bool set_parent_link_status(qdTriggerElementConstPtr parent, qdTriggerLink::LinkStatus st);
253 
254  bool load_script(const xml::tag *p);
255  bool save_script(Common::WriteStream &fh, int indent = 0) const;
256 
258  bool load_data(Common::SeekableReadStream &fh, int save_version);
260  bool save_data(Common::WriteStream &fh) const;
261 
262  bool quant(float dt);
263 
264  void reset();
265  void deactivate(const qdNamedObject *ignore_object = NULL);
266 
267 private:
268 
270  enum ElementStatusSpecial {
272  TRIGGER_EL_INACTIVE_ALL,
274  TRIGGER_EL_DONE_ALL
275  };
276 
277  int _ID;
278 
279  ElementStatus _status;
280 
282  bool _is_active;
283 
284  qdNamedObject *_object;
285 
286  qdTriggerLinkList _parents;
287  qdTriggerLinkList _children;
288 
289  bool load_links_script(const xml::tag *p, bool load_parents);
290 
291  bool activate_links(qdTriggerElementPtr child);
292  bool deactivate_links(qdTriggerElementPtr child);
293 
294  bool deactivate_link(qdTriggerElementPtr child);
295  bool conditions_quant(int link_type);
296  void start();
297 };
298 
300 
301 } // namespace QDEngine
302 
303 #endif // QDENGINE_QDCORE_QD_TRIGGER_ELEMENT_H
bool is_active() const
Возвращает true, если элемент помечен как активный для отладочной проверки.
Definition: qd_trigger_element.h:178
Definition: str.h:59
Definition: stream.h:77
Поименованный объект.
Definition: qd_named_object.h:70
Definition: stream.h:745
Definition: qd_trigger_chain.h:34
Definition: qd_named_object_reference.h:35
XML тег.
Definition: xml_tag.h:33
Базовый класс для игровых ресурсов.
Definition: console.h:28
Definition: algorithm.h:29
void make_active(bool v)
Помечает элемент как активный (или неактивный) для отладочной проверки.
Definition: qd_trigger_element.h:182
Элемент триггера.
Definition: qd_trigger_element.h:152