aboutsummaryrefslogtreecommitdiff
path: root/engines/cryomni3d/objects.h
blob: d680b6a72881593053829dbe160f44c11d5f2b4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#ifndef CRYOMNI3D_OBJECTS_H
#define CRYOMNI3D_OBJECTS_H

#include "common/array.h"
#include "common/func.h"
#include "common/str.h"

#include "cryomni3d/sprites.h"

namespace CryOmni3D {

class Object {
public:
	typedef Common::Functor0<void> *ViewCallback;

	Object() : _valid(false), _idCA(-1), _idCl(-1), _idSA(-1), _idSl(-1), _idOBJ(-1),
		_viewCallback(nullptr) {}

	Object(const Sprites &sprites, uint idCA, uint idOBJ) : _idCA(idCA),
		_idCl(sprites.calculateSpriteId(idCA, 1)), _idSA(sprites.calculateSpriteId(idCA, 2)),
		_idSl(sprites.calculateSpriteId(idCA, 3)),
		_valid(true), _idOBJ(idOBJ), _viewCallback(nullptr) {}

	~Object() { delete _viewCallback; }

	uint valid() const { return _valid; }
	uint idCA() const { return _idCA; }
	uint idCl() const { return _idCl; }
	uint idSA() const { return _idSA; }
	uint idSl() const { return _idSl; }
	uint idOBJ() const { return _idOBJ; }
	ViewCallback viewCallback() const { return _viewCallback; }
	// Takes ownership of the pointer
	void setViewCallback(ViewCallback callback) { _viewCallback = callback; }

	void rename(uint newIdOBJ) { _idOBJ = newIdOBJ; }

private:
	uint _idOBJ;
	uint _idCA;
	uint _idCl;
	uint _idSA;
	uint _idSl;
	bool _valid;
	ViewCallback _viewCallback;
};

class Objects : public Common::Array<Object> {
public:
	Object *findObjectByNameID(uint nameID);
	Object *findObjectByIconID(uint iconID);
private:
};

class Inventory : public Common::Array<Object *> {
public:
	Inventory() : _selectedObject(nullptr), _changeCallback(nullptr) { }
	~Inventory() { delete _changeCallback; }
	void init(uint count, Common::Functor1<uint, void> *changeCallback) { _changeCallback = changeCallback; resize(count); }

	void clear();
	void add(Object *);
	void remove(uint position);
	void removeByNameID(uint nameID);
	void removeByIconID(uint iconID);
	bool inInventoryByNameID(uint nameID) const;
	bool inInventoryByIconID(uint iconID) const;

	Object *selectedObject() const { return _selectedObject; }
	void setSelectedObject(Object *obj) { _selectedObject = obj; }
	void deselectObject() { _selectedObject = nullptr; }

private:
	Object *_selectedObject;
	Common::Functor1<uint, void> *_changeCallback;
};

} // End of namespace CryOmni3D

#endif