aboutsummaryrefslogtreecommitdiff
path: root/engines/m4/actor.cpp
blob: ce8574a13436c83a05c217fe04f666462ff7e49e (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/* 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.
 *
 * $URL$
 * $Id$
 *
 */

#include "common/system.h"
#include "common/array.h"
#include "m4/actor.h"
#include "m4/m4_views.h"
#include "m4/assets.h"

namespace M4 {

#define WALKER_BURGER "Wilbur0%i"	// wilbur, with a number denoting his current direction

Actor::Actor(MadsM4Engine *vm) : _vm(vm) {
	_scaling = 100;
	_direction = 5;
	_walkerSprites.resize(10);
	loadWalkers();
}

Actor::~Actor() {
	unloadWalkers();
}

int Actor::getWalkerWidth() { return _walkerSprites[kFacingSouth]->getFrame(0)->width(); }
int Actor::getWalkerHeight() { return _walkerSprites[kFacingSouth]->getFrame(0)->height(); }

void Actor::placeWalkerSpriteAt(int spriteNum, int x, int y) {
	if (_direction < 1 || _direction > 9) {
		warning("Direction is %i, fixing", _direction);
		_direction = 1;		// TODO: this is a temporary fix
	}
	SpriteInfo info;
	info.sprite = _walkerSprites[_direction]->getFrame(spriteNum);
	info.hotX = info.hotY = 0;
	info.width = info.sprite->width();
	info.height = info.sprite->height();
	info.scaleX = info.scaleY = _scaling;
	info.palette = _walkerSprites[_direction]->getPalette();
	info.inverseColorTable = _m4Vm->scene()->getInverseColorTable();

	_vm->_scene->drawSprite(x, y, info, Common::Rect(640, 400));
}

void Actor::loadWalkers() {
	for (uint8 i = 1; i < 10; i++) {
		if (i == 6)
			continue;	// walker sprite 6 is unused
		loadWalkerDirection(i);
	}
}

void Actor::loadWalkerDirection(uint8 direction) {
	char name[20];
	Common::SeekableReadStream *walkerS;

	if (_vm->getGameType() == GType_Burger) {
		sprintf(name, WALKER_BURGER, direction);
	} else {
		//warning("Actor::loadWalkerDirection: unspecified walker type, not loading walker");
		// TODO: Master Lu walkers
		return;
	}

	walkerS = _vm->res()->get(name);
	_walkerSprites.insert_at(direction, new SpriteAsset(_vm, walkerS, walkerS->size(), name));
	_vm->res()->toss(name);
}

void Actor::unloadWalkers() {
	for (uint8 i = 9; i > 0; i--) {
		if (i == 6)
			continue;	// walker sprite 6 is unused
		SpriteAsset *tempSprite = _walkerSprites[i];
		_walkerSprites.remove_at(i);
		delete tempSprite;
	}
}

void Actor::setWalkerPalette() {
	_vm->_palette->setPalette(_walkerSprites[kFacingSouthEast]->getPalette(), 0,
							  _walkerSprites[kFacingSouthEast]->getColorCount());
}

Inventory::Inventory(MadsM4Engine *vm) : _vm(vm) {
}

Inventory::~Inventory() {
	_inventory.clear();
}

void Inventory::registerObject(char* name, int32 scene, int32 icon) {
	InventoryObject *newObject = new InventoryObject();
	int newObjectIndex = 0;

	// Capitalize registered inventory object names
	str_upper(name);

	newObject->name = strdup(name);
	newObject->scene = scene;
	newObject->icon = icon;

	newObjectIndex = _inventory.size();

	_inventory.push_back(newObject);

	if (scene == BACKPACK)
		addToBackpack(newObjectIndex);
}

void Inventory::moveObject(char* name, int32 scene) {
	uint i = 0;

	for (i = 0; i < _inventory.size(); i++) {
		if (!scumm_stricmp(_inventory[i]->name, name)) {
			if (_inventory[i]->scene == BACKPACK && scene != BACKPACK)
				removeFromBackpack(i);

			_inventory[i]->scene = scene;

			if (scene == BACKPACK)
				addToBackpack(i);

			return;
		}
	}
}

void Inventory::addToBackpack(uint32 objectIndex) {
	_m4Vm->scene()->getInterface()->inventoryAdd(_inventory[objectIndex]->name, "", _inventory[objectIndex]->icon);
}

void Inventory::removeFromBackpack(uint32 objectIndex) {
	_m4Vm->scene()->getInterface()->inventoryRemove(_inventory[objectIndex]->name);
}

bool Inventory::isInCurrentScene(char* name) {
	return (getScene(name) == _vm->_scene->getCurrentScene());
}

int Inventory::getScene(char* name) {
	uint i = 0;

	for (i = 0; i < _inventory.size(); i++) {
		if (!scumm_stricmp(_inventory[i]->name, name))
			return _inventory[i]->scene;
	}
	return UNKNOWN_OBJECT;
}

int Inventory::getIcon(char* name) {
	uint i = 0;

	for (i = 0; i < _inventory.size(); i++) {
		if (!scumm_stricmp(_inventory[i]->name, name))
			return _inventory[i]->icon;
	}
	return UNKNOWN_OBJECT;
}

int Inventory::getIndex(char* name) {
	uint i = 0;

	for (i = 0; i < _inventory.size(); i++) {
		if (!scumm_stricmp(_inventory[i]->name, name))
			return i;
	}
	return UNKNOWN_OBJECT;
}

void Inventory::clear() {
	for (uint i = 0; i < _inventory.size(); i++) {
		delete _inventory[i]->name;
		delete _inventory[i];
		_inventory.remove_at(i);
	}
}

} // End of namespace M4