ScummVM API documentation
qd_counter.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_COUNTER_H
23 #define QDENGINE_QDCORE_QD_COUNTER_H
24 
25 #include "qdengine/parser/xml_fwd.h"
26 #include "qdengine/qdcore/qd_named_object_reference.h"
27 
28 namespace Common {
29 class WriteStream;
30 }
31 
32 namespace QDEngine {
33 
34 class qdGameObjectState;
35 
37 public:
40  explicit qdCounterElement(const qdGameObjectState *p, bool inc_value = true);
41 
42  bool operator == (const qdGameObjectState *p) const {
43  return _state == p;
44  }
45 
46  const qdGameObjectState *state() const {
47  return _state;
48  }
49  bool increment_value() const {
50  return _increment_value;
51  }
52 
53  bool init();
54  bool quant();
55 
56  bool load_script(const xml::tag *p);
57  bool save_script(Common::WriteStream &fh, int indent = 0) const;
58 
60  bool load_data(Common::SeekableReadStream &fh, int save_version);
62  bool save_data(Common::WriteStream &fh) const;
63 
64 private:
65 
66  qdNamedObjectReference _state_reference;
67  const qdGameObjectState *_state;
68  bool _last_state_status;
69  bool _increment_value;
70 };
71 
73 class qdCounter : public qdNamedObject {
74 public:
75  qdCounter();
76  ~qdCounter();
77 
79  enum {
81  POSITIVE_VALUE = 0x01
82  };
83 
84  int named_object_type() const {
85  return QD_NAMED_OBJECT_COUNTER;
86  }
87 
88  int value() const {
89  return _value;
90  }
91  void set_value(int value);
92  void add_value(int value_delta);
93 
94  int value_limit() const {
95  return _value_limit;
96  }
97  void set_value_limit(int limit) {
98  _value_limit = limit;
99  }
100 
102  const element_container_t &elements() const {
103  return _elements;
104  }
105 
107  bool add_element(const qdGameObjectState *p, bool inc_value = true);
108 
109  bool remove_element(const qdGameObjectState *p);
110  bool remove_element(int idx);
111 
112  void quant();
113 
114  void init();
115 
116  bool load_script(const xml::tag *p);
117  bool save_script(Common::WriteStream &fh, int indent = 0) const;
118 
120  bool load_data(Common::SeekableReadStream &fh, int save_version);
122  bool save_data(Common::WriteStream &fh) const;
123 
124 protected:
125 private:
126 
128  element_container_t _elements;
129 
131  int _value;
133 
136  int _value_limit;
137 };
138 
139 } // namespace QDEngine
140 
141 #endif // QDENGINE_QDCORE_QD_COUNTER_H
Definition: stream.h:77
Поименованный объект.
Definition: qd_named_object.h:70
Счетчик состояний.
Definition: qd_counter.h:73
Definition: stream.h:745
Состояние динамического объекта - базовый класс.
Definition: qd_game_object_state.h:91
Definition: qd_named_object_reference.h:35
XML тег.
Definition: xml_tag.h:33
Базовый класс для игровых ресурсов.
Definition: console.h:28
Definition: algorithm.h:29
Definition: qd_counter.h:36
int named_object_type() const
Возвращает тип объекта.
Definition: qd_counter.h:84