aboutsummaryrefslogtreecommitdiff
path: root/engines/avalanche/sequence.cpp
blob: d63532a4578489d7ccbfeaee94bd45a867e6108c (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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/* 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.
 *
 */

/*
 * This code is based on the original source code of Lord Avalot d'Argent version 1.3.
 * Copyright (c) 1994-1995 Mike, Mark and Thomas Thurman.
 */

/* SEQUENCE		The sequencer. */

#include "avalanche/avalanche.h"
#include "avalanche/sequence.h"

namespace Avalanche {

Sequence::Sequence(AvalancheEngine *vm) {
	_vm = vm;

	resetVariables();
}

void Sequence::resetVariables() {
	_flipToWhere = kRoomNowhere;
	_flipToPed = 0;
}

void Sequence::init(byte what) {
	_seq[0] = what;

	for (int i = 1; i < kSeqLength; i++)
		_seq[i] = 0;
}

void Sequence::add(byte what) {
	for (int16 i = 0; i < kSeqLength; i++) {
		if (_seq[i] == 0) {
			_seq[i] = what;
			return;
		}
	}
}

void Sequence::switchRoom(Room where, byte ped) {
	add(kNowFlip);

	_flipToWhere = where;
	_flipToPed = ped;
}

void Sequence::startTimer() {
	_vm->_timer->loseTimer(Timer::kReasonSequencer);
	_vm->_timer->addTimer(7, Timer::kProcSequence, Timer::kReasonSequencer);
}

void Sequence::startTimerImmobilized() {
	// They can't move.
	_vm->_userMovesAvvy = false;
	// And they're not moving now.
	_vm->_animation->stopWalking();
	// Apart from that, it's the same thing.
	startTimer();
}

void Sequence::shoveLeft() {
	for (uint i = 0; i < kSeqLength - 1; i++)
		_seq[i] = _seq[i + 1];
	_seq[kSeqLength - 1] = 0;
}

void Sequence::callSequencer() {
	byte curSeq = _seq[0];

	switch (curSeq) {
	case 0:
		// No more routines.
		return;
		break;
	case kNowFlip:
		// Flip room.
		_vm->_userMovesAvvy = true;
		_vm->flipRoom(_flipToWhere, _flipToPed);
		shoveLeft();
		break;
	}

	if (curSeq <= 176) {
		// Show a frame.
		_vm->_background->draw(-1, -1, curSeq - 1);
		shoveLeft();
	}

	// Make sure this PROC gets called again.
	startTimer();
}

void Sequence::startHallSeq(Room whither, byte ped) {
	init(1);
	add(2);
	switchRoom(whither, ped);
	startTimerImmobilized();
}

void Sequence::startOutsideSeq(Room whither, byte ped) {
	init(1);
	add(2);
	add(3);
	switchRoom(whither, ped);
	startTimerImmobilized();
}

void Sequence::startCardiffSeq(Room whither, byte ped) {
	init(1);
	add(5);
	switchRoom(whither, ped);
	startTimerImmobilized();
}

void Sequence::startNaughtyDukeSeq() {
	init(2);
	startTimer();
}

void Sequence::startGardenSeq() {
	init(2);
	add(1);
	add(3);
	startTimer();
}

void Sequence::startDuckSeq() {
	init(3);
	add(2);
	add(1);
	add(4);
	startTimer();
}

void Sequence::startLustiesSeq3(Room whither, byte ped) {
	init(4);
	add(5);
	add(6);
	switchRoom(whither, ped);
	startTimerImmobilized();
}

void Sequence::startMusicRoomSeq2(Room whither, byte ped) {
	init(5);
	add(6);
	switchRoom(whither, ped);
	startTimerImmobilized();
}

void Sequence::startGeidaLuteSeq() {
	init(5);
	// He falls asleep...
	add(6);
	// Not really closing, but we're using the same procedure.
	startTimer();
}

void Sequence::startMusicRoomSeq() {
	init(6);
	add(5);
	add(7);
	startTimer();
}

void Sequence::startWinSeq() {
	init(7);
	add(8);
	add(9);
	startTimer();
}

void Sequence::startCupboardSeq() {
	init(8);
	add(7);
	startTimer();
}

void Sequence::startLustiesSeq2(Room whither, byte ped) {
	init(8);
	add(9);
	switchRoom(whither, ped);
	startTimerImmobilized();
}

void Sequence::startCardiffSeq2() {
	init(1);
	if (_vm->_arrowInTheDoor)
		add(3);
	else
		add(2);

	if (_vm->_takenPen)
		_vm->_background->draw(-1, -1, 3);

	startTimer();
}

void Sequence::startDummySeq(Room whither, byte ped) {
	switchRoom(whither, ped);
	startTimerImmobilized();
}

void Sequence::synchronize(Common::Serializer &sz) {
	sz.syncBytes(_seq, kSeqLength);
	sz.syncAsByte(_flipToWhere);
	sz.syncAsByte(_flipToPed);
}
} // End of namespace Avalanche.