aboutsummaryrefslogtreecommitdiff
path: root/engines/lastexpress/game/object.cpp
blob: 31da650b9a2d26af3df52e97885fbeb77c24c3df (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
104
105
106
107
/* 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.
 *
 */

#include "lastexpress/game/object.h"

#include "lastexpress/game/entities.h"
#include "lastexpress/game/logic.h"
#include "lastexpress/game/scenes.h"
#include "lastexpress/game/state.h"

#include "lastexpress/lastexpress.h"

namespace LastExpress {

Common::String Objects::Object::toString() {
	return Common::String::format("{ %s - %d - %d - %d - %d }", ENTITY_NAME(entity), status, windowCursor, handleCursor, model);
}

Objects::Objects(LastExpressEngine *engine) : _engine(engine) {}

const Objects::Object Objects::get(ObjectIndex index) const {
	if (index >= kObjectMax)
		error("[Objects::get] Invalid object index (%d)", index);

	return _objects[index];
}

void Objects::update(ObjectIndex index, EntityIndex entity, ObjectLocation status, CursorStyle windowCursor, CursorStyle handleCursor) {
	if (index >= kObjectMax)
		return;

	Object *object = &_objects[index];

	// Store original location
	ObjectLocation original_status = object->status;

	// Update entity
	object->entity = entity;
	object->status = status;

	if (windowCursor != kCursorKeepValue || handleCursor != kCursorKeepValue) {
		if (windowCursor != kCursorKeepValue)
			object->windowCursor = windowCursor;
		if (handleCursor != kCursorKeepValue)
			object->handleCursor = handleCursor;

		getLogic()->updateCursor();
	}

	getFlags()->flag_3 = true;

	// Compartments
	if (original_status != status && (original_status == kObjectLocation2 || status == kObjectLocation2)) {
		if ((index >= kObjectCompartment1 && index <= kObjectCompartment8)
		   || (index >= kObjectCompartmentA && index <= kObjectCompartmentF)) {
			getScenes()->updateDoorsAndClock();
		}
	}
}

void Objects::updateModel(ObjectIndex index, ObjectModel model) {
	if (index >= kObjectMax)
		return;

	_objects[index].model = model;
}

//////////////////////////////////////////////////////////////////////////
// Serializable
//////////////////////////////////////////////////////////////////////////
void Objects::saveLoadWithSerializer(Common::Serializer &s) {
	for (int i = 0; i < ARRAYSIZE(_objects); i++)
		_objects[i].saveLoadWithSerializer(s);
}

//////////////////////////////////////////////////////////////////////////
// toString
//////////////////////////////////////////////////////////////////////////
Common::String Objects::toString() {
	Common::String ret = "";

	for (int i = 0; i < ARRAYSIZE(_objects); i++)
		ret += Common::String::format("%d : %s\n", i, _objects[i].toString().c_str());

	return ret;
}

} // End of namespace LastExpress