ScummVM API documentation
objects.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 CRYOMNI3D_OBJECTS_H
23#define CRYOMNI3D_OBJECTS_H
24
25#include "common/array.h"
26#include "common/func.h"
27#include "common/str.h"
28
29#include "cryomni3d/sprites.h"
30
31namespace CryOmni3D {
32
33class Object {
34public:
36
37 Object() : _valid(false), _idCA(uint(-1)), _idCl(uint(-1)), _idSA(uint(-1)), _idSl(uint(-1)),
38 _idOBJ(uint(-1)),
39 _viewCallback(nullptr) {}
40
41 Object(const Sprites &sprites, uint id_CA, uint id_OBJ) : _idCA(id_CA),
42 _idCl(sprites.calculateSpriteId(id_CA, 1)), _idSA(sprites.calculateSpriteId(id_CA, 2)),
43 _idSl(sprites.calculateSpriteId(id_CA, 3)),
44 _valid(true), _idOBJ(id_OBJ), _viewCallback(nullptr) {}
45
46 ~Object() { delete _viewCallback; }
47
48 uint valid() const { return _valid; }
49 uint idCA() const { return _idCA; }
50 uint idCl() const { return _idCl; }
51 uint idSA() const { return _idSA; }
52 uint idSl() const { return _idSl; }
53 uint idOBJ() const { return _idOBJ; }
54 ViewCallback viewCallback() const { return _viewCallback; }
55 // Takes ownership of the pointer
56 void setViewCallback(ViewCallback callback) { _viewCallback = callback; }
57
58 void rename(uint newIdOBJ) { _idOBJ = newIdOBJ; }
59
60private:
61 uint _idOBJ;
62 uint _idCA;
63 uint _idCl;
64 uint _idSA;
65 uint _idSl;
66 bool _valid;
67 ViewCallback _viewCallback;
68};
69
70class Objects : public Common::Array<Object> {
71public:
72 Object *findObjectByNameID(uint nameID);
73 Object *findObjectByIconID(uint iconID);
74private:
75};
76
77class Inventory : public Common::Array<Object *> {
78public:
79 Inventory() : _selectedObject(nullptr), _changeCallback(nullptr) { }
80 ~Inventory() { delete _changeCallback; }
81 void init(uint count, Common::Functor1<uint, void> *changeCallback) { _changeCallback = changeCallback; resize(count); }
82
83 void clear();
84 void add(Object *);
85 void remove(uint position);
86 void removeByNameID(uint nameID);
87 void removeByIconID(uint iconID);
88 bool inInventoryByNameID(uint nameID) const;
89 bool inInventoryByIconID(uint iconID) const;
90
91 Object *selectedObject() const { return _selectedObject; }
92 void setSelectedObject(Object *obj) { _selectedObject = obj; }
93 void deselectObject() { _selectedObject = nullptr; }
94
95private:
96 Object *_selectedObject;
97 Common::Functor1<uint, void> *_changeCallback;
98};
99
100} // End of namespace CryOmni3D
101
102#endif
103
Definition: array.h:52
void resize(size_type newSize)
Definition: array.h:412
Definition: objects.h:77
Definition: objects.h:33
Definition: objects.h:70
Definition: sprites.h:40
Definition: cryomni3d.h:62