aboutsummaryrefslogtreecommitdiff
path: root/engines/gob/mult_v1.cpp
blob: 72328c42cf2d87b4f6414d9abddd652c63c091cb (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
202
203
204
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2004 Ivan Dubrov
 * Copyright (C) 2004-2006 The ScummVM project
 *
 * 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 "gob/gob.h"
#include "gob/mult.h"
#include "gob/game.h"
#include "gob/scenery.h"
#include "gob/global.h"
#include "gob/inter.h"

namespace Gob {

Mult_v1::Mult_v1(GobEngine *vm) : Mult(vm) {
}

void Mult_v1::loadMult(int16 resId) {
	char animCount;
	char staticCount;
	int16 palIndex;
	int16 i, j;

	_sndSlotsCount = 0;
	_frameStart = 0;
	_multData = _vm->_game->loadExtData(resId, 0, 0);
	_dataPtr = _multData;

	staticCount = _dataPtr[0];
	animCount = _dataPtr[1];
	_dataPtr += 2;
	staticCount++;
	animCount++;

	for (i = 0; i < staticCount; i++, _dataPtr += 14) {
		_staticIndices[i] = _vm->_scenery->loadStatic(1);

		if (_staticIndices[i] >= 100) {
			_staticIndices[i] -= 100;
			_staticLoaded[i] = 1;
		} else {
			_staticLoaded[i] = 0;
		}
	}

	for (i = 0; i < animCount; i++, _dataPtr += 14) {
		_animIndices[i] = _vm->_scenery->loadAnim(1);

		if (_animIndices[i] >= 100) {
			_animIndices[i] -= 100;
			_animLoaded[i] = 1;
		} else {
			_animLoaded[i] = 0;
		}
	}

	_frameRate = READ_LE_UINT16(_dataPtr);
	_dataPtr += 2;

	_staticKeysCount = READ_LE_UINT16(_dataPtr);
	_dataPtr += 2;

	_staticKeys = new Mult_StaticKey[_staticKeysCount];
	for (i = 0; i < _staticKeysCount; i++, _dataPtr += 4) {
		_staticKeys[i].frame = (int16)READ_LE_UINT16(_dataPtr);
		_staticKeys[i].layer = (int16)READ_LE_UINT16(_dataPtr + 2);
	}

	for (j = 0; j < 4; j++) {
		_animKeysCount[j] = READ_LE_UINT16(_dataPtr);
		_dataPtr += 2;

		_animKeys[j] = new Mult_AnimKey[_animKeysCount[j]];
		for (i = 0; i < _animKeysCount[j]; i++, _dataPtr += 10) {
			_animKeys[j][i].frame = (int16)READ_LE_UINT16(_dataPtr);
			_animKeys[j][i].layer = (int16)READ_LE_UINT16(_dataPtr + 2);
			_animKeys[j][i].posX = (int16)READ_LE_UINT16(_dataPtr + 4);
			_animKeys[j][i].posY = (int16)READ_LE_UINT16(_dataPtr + 6);
			_animKeys[j][i].order = (int16)READ_LE_UINT16(_dataPtr + 8);
		}
	}

	for (palIndex = 0; palIndex < 5; palIndex++) {
		for (i = 0; i < 16; i++) {
			_fadePal[palIndex][i].red = _dataPtr[0];
			_fadePal[palIndex][i].green = _dataPtr[1];
			_fadePal[palIndex][i].blue = _dataPtr[2];
			_dataPtr += 3;
		}
	}

	_palFadeKeysCount = READ_LE_UINT16(_dataPtr);
	_dataPtr += 2;
	_palFadeKeys = new Mult_PalFadeKey[_palFadeKeysCount];

	for (i = 0; i < _palFadeKeysCount; i++, _dataPtr += 7) {
		_palFadeKeys[i].frame = (int16)READ_LE_UINT16(_dataPtr);
		_palFadeKeys[i].fade = (int16)READ_LE_UINT16(_dataPtr + 2);
		_palFadeKeys[i].palIndex = (int16)READ_LE_UINT16(_dataPtr + 4);
		_palFadeKeys[i].flag = *(_dataPtr + 6);
	}

	_palKeysCount = READ_LE_UINT16(_dataPtr);
	_dataPtr += 2;

	_palKeys = new Mult_PalKey[_palKeysCount];
	for (i = 0; i < _palKeysCount; i++, _dataPtr += 80) {
		_palKeys[i].frame = (int16)READ_LE_UINT16(_dataPtr);
		_palKeys[i].cmd = (int16)READ_LE_UINT16(_dataPtr + 2);
		_palKeys[i].rates[0] = (int16)READ_LE_UINT16(_dataPtr + 4);
		_palKeys[i].rates[1] = (int16)READ_LE_UINT16(_dataPtr + 6);
		_palKeys[i].rates[2] = (int16)READ_LE_UINT16(_dataPtr + 8);
		_palKeys[i].rates[3] = (int16)READ_LE_UINT16(_dataPtr + 10);
		_palKeys[i].unknown0 = (int16)READ_LE_UINT16(_dataPtr + 12);
		_palKeys[i].unknown1 = (int16)READ_LE_UINT16(_dataPtr + 14);
		memcpy(_palKeys[i].subst, _dataPtr + 16, 64);
	}

	_textKeysCount = READ_LE_UINT16(_dataPtr);
	_dataPtr += 2;
	_textKeys = new Mult_TextKey[_textKeysCount];

	for (i = 0; i < _textKeysCount; i++, _dataPtr += 28) {
		_textKeys[i].frame = (int16)READ_LE_UINT16(_dataPtr);
		_textKeys[i].cmd = (int16)READ_LE_UINT16(_dataPtr + 2);
		for (int k = 0; k < 9; ++k)
			_textKeys[i].unknown0[k] = (int16)READ_LE_UINT16(_dataPtr + 4 + (k * 2));
		_textKeys[i].index = (int16)READ_LE_UINT16(_dataPtr + 22);
		_textKeys[i].unknown1[0] = (int16)READ_LE_UINT16(_dataPtr + 24);
		_textKeys[i].unknown1[1] = (int16)READ_LE_UINT16(_dataPtr + 26);
	}

	_sndKeysCount = READ_LE_UINT16(_dataPtr);
	_dataPtr += 2;

	_sndKeys = new Mult_SndKey[_sndKeysCount];
	for (i = 0; i < _sndKeysCount; i++) {
		_sndKeys[i].frame = (int16)READ_LE_UINT16(_dataPtr);
		_sndKeys[i].cmd = (int16)READ_LE_UINT16(_dataPtr + 2);
		_sndKeys[i].freq = (int16)READ_LE_UINT16(_dataPtr + 4);
		_sndKeys[i].channel = (int16)READ_LE_UINT16(_dataPtr + 6);
		_sndKeys[i].repCount = (int16)READ_LE_UINT16(_dataPtr + 8);
		_sndKeys[i].resId = (int16)READ_LE_UINT16(_dataPtr + 10);
		_sndKeys[i].soundIndex = (int16)READ_LE_UINT16(_dataPtr + 12);

		_sndKeys[i].soundIndex = -1;
		_sndKeys[i].resId = -1;
		_dataPtr += 36;
		switch (_sndKeys[i].cmd) {
		case 1:
		case 4:
			_sndKeys[i].resId = READ_LE_UINT16(_vm->_global->_inter_execPtr);

			for (j = 0; j < i; j++) {
				if (_sndKeys[i].resId ==
				    _sndKeys[j].resId) {
					_sndKeys[i].soundIndex =
					    _sndKeys[j].soundIndex;
					_vm->_global->_inter_execPtr += 2;
					break;
				}
			}
			if (i == j) {
				_vm->_inter->loadSound(19 - _sndSlotsCount);
				_sndKeys[i].soundIndex =
				    19 - _sndSlotsCount;
				_sndSlotsCount++;
			}
			break;

		case 3:
			_vm->_global->_inter_execPtr += 6;
			break;

		case 5:
			_vm->_global->_inter_execPtr += _sndKeys[i].freq * 2;
			break;
		}
	}
}

void Mult_v1::setMultData(uint16 multindex) {
	error("Switching mults not supported for Gob1");
}

} // End of namespace Gob