aboutsummaryrefslogtreecommitdiff
path: root/engines/pegasus/neighborhood/caldoria/caldoria4dsystem.cpp
blob: 0494753661b33f7bd6fb1025a8ca7fa62d2ed487 (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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
/* 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.
 *
 * Additional copyright for this file:
 * Copyright (C) 1995-1997 Presto Studios, Inc.
 *
 * 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 "pegasus/pegasus.h"
#include "pegasus/ai/ai_area.h"
#include "pegasus/neighborhood/caldoria/caldoria.h"
#include "pegasus/neighborhood/caldoria/caldoria4dsystem.h"

namespace Pegasus {

static const TimeValue kSwitchableSlop = 3 * kCaldoriaFrameDuration;
// Two seconds - some slop
static const TimeValue kSwitchableDuration = kCaldoriaMovieScale * 2 - kSwitchableSlop;
// Twelve frames + some slop
static const TimeValue kNonswitchableDuration = kCaldoriaFrameDuration * 12 + kSwitchableSlop;

static const TimeValue kSwitchable1Start = 0;
static const TimeValue kSwitchable1Stop = kSwitchable1Start + kSwitchableDuration;

static const TimeValue kSwitchable2Start = kSwitchable1Stop + kNonswitchableDuration;
static const TimeValue kSwitchable2Stop = kSwitchable2Start + kSwitchableDuration;

static const TimeValue kSwitchable3Start = kSwitchable2Stop + kNonswitchableDuration;
static const TimeValue kSwitchable3Stop = kSwitchable3Start + kSwitchableDuration;

static const NotificationFlags kVidPhoneDoneFlag = 1;

static const TimeValue kRockMusicLoopIn = 0;
static const TimeValue kRockMusicLoopOut = 2088;

static const TimeValue kOrchestralMusicLoopIn = 2088;
static const TimeValue kOrchestralMusicLoopOut = 4985;

static const TimeValue kRhythmsMusicLoopIn = 4985;
static const TimeValue kRhythmsMusicLoopOut = 6824;

static const TimeValue kAcousticMusicLoopIn = 6824;
static const TimeValue kAcousticMusicLoopOut = 9387;

enum {
	k4DVideoMenu,
	k4DAudioMenu,
	k4DShuttingDown,

	// These constants are the exact frame numbers of the sprite movie.
	k4DRockChoice = 0,
	k4DOrchestralChoice,
	k4DRhythmsChoice,
	k4DAcousticChoice,
	k4DIslandChoice,
	k4DDesertChoice,
	k4DMountainChoice,

	k4DFirstVideoChoice = k4DIslandChoice
};

static const ExtraID s_transitionExtras0[3][3] = {
	{ 0xffffffff, k4DIsland0ToDesert0, k4DIsland0ToMountain0 },
	{ k4DDesert0ToIsland0, 0xffffffff, k4DDesert0ToMountain0 },
	{ k4DMountain0ToIsland0, k4DMountain0ToDesert0, 0xffffffff }
};

static const ExtraID s_transitionExtras1[3][3] = {
	{ 0xffffffff, k4DIsland1ToDesert0, k4DIsland1ToMountain0 },
	{ k4DDesert1ToIsland0, 0xffffffff, k4DDesert1ToMountain0 },
	{ k4DMountain1ToIsland0, k4DMountain1ToDesert0, 0xffffffff }
};

static const ExtraID s_transitionExtras2[3][3] = {
	{ 0xffffffff, k4DIsland2ToDesert0, k4DIsland2ToMountain0 },
	{ k4DDesert2ToIsland0, 0xffffffff, k4DDesert2ToMountain0 },
	{ k4DMountain2ToIsland0, k4DMountain2ToDesert0, 0xffffffff }
};

static const ExtraID s_shutDownExtras[3][3] = {
	{ 0xffffffff, k4DIsland1ToIsland0, k4DIsland2ToIsland0 },
	{ k4DDesert0ToIsland0, k4DDesert1ToIsland0, k4DDesert2ToIsland0 },
	{ k4DMountain0ToIsland0, k4DMountain1ToIsland0, k4DMountain2ToIsland0 }
};

Caldoria4DSystem::Caldoria4DSystem(Neighborhood *owner) : GameInteraction(kCaldoria4DInteractionID, owner),
		_4DSpritesMovie(kCaldoria4DSpritesID) {
	g_AIArea->lockAIOut();
}

Caldoria4DSystem::~Caldoria4DSystem() {
	g_AIArea->unlockAI();
}

void Caldoria4DSystem::openInteraction() {
	_whichMenu = k4DVideoMenu;
	_videoChoice = k4DIslandChoice;
	_audioChoice = k4DRockChoice;
	_clickedHotspotID = kNoHotSpotID;

	_4DSpritesMovie.initFromMovieFile("Images/Caldoria/4D Sprites", true);
	_4DSpritesMovie.moveElementTo(kCaldoria4DSpritesLeft, kCaldoria4DSpritesTop);
	_4DSpritesMovie.setDisplayOrder(k4DSpritesOrder);
	_4DSpritesMovie.startDisplaying();
	_4DSpritesMovie.show();

	_4DSpritesScale = _4DSpritesMovie.getScale();

	_neighborhoodNotification = _owner->getNeighborhoodNotification();
	_neighborhoodNotification->notifyMe(this, kExtraCompletedFlag, kExtraCompletedFlag);

	startIdling();
}

void Caldoria4DSystem::loopExtra(const ExtraID extraID) {
	ExtraTable::Entry extraEntry;

	_owner->getExtraEntry(extraID, extraEntry);
	_loopStart = extraEntry.movieStart;
	_owner->loopExtraSequence(extraID);
}

void Caldoria4DSystem::useIdleTime() {
	if (_whichMenu == k4DShuttingDown) {
		TimeValue movieTime = _owner->getNavMovie()->getTime() - _loopStart;
		ExtraID extraID;

		if (movieTime < kSwitchable1Stop)
			extraID = s_shutDownExtras[_videoChoice - k4DFirstVideoChoice][0];
		else if (movieTime >= kSwitchable2Start && movieTime < kSwitchable2Stop)
			extraID = s_shutDownExtras[_videoChoice - k4DFirstVideoChoice][1];
		else if (movieTime >= kSwitchable3Start && movieTime < kSwitchable3Stop)
			extraID = s_shutDownExtras[_videoChoice - k4DFirstVideoChoice][2];
		else
			extraID = 0xffffffff;

		if (extraID != 0xffffffff) {
			setSpritesMovie();
			_loopStart = 0;
			_owner->startExtraSequence(extraID, kExtraCompletedFlag, kFilterNoInput);
		}
	} else if (_clickedHotspotID != kNoHotSpotID) {
		TimeValue movieTime = _owner->getNavMovie()->getTime() - _loopStart;
		ExtraID extraID;

		if (movieTime < kSwitchable1Stop) {
			extraID = s_transitionExtras0[_videoChoice - k4DFirstVideoChoice][_clickedHotspotID - kCa4DChoice1SpotID];
			_clickedHotspotID = kNoHotSpotID;
		} else if (movieTime >= kSwitchable2Start && movieTime < kSwitchable2Stop) {
			extraID = s_transitionExtras1[_videoChoice - k4DFirstVideoChoice][_clickedHotspotID - kCa4DChoice1SpotID];
			_clickedHotspotID = kNoHotSpotID;
		} else if (movieTime >= kSwitchable3Start && movieTime < kSwitchable3Stop) {
			extraID = s_transitionExtras2[_videoChoice - k4DFirstVideoChoice][_clickedHotspotID - kCa4DChoice1SpotID];
			_clickedHotspotID = kNoHotSpotID;
		} else
			extraID = 0xffffffff;

		if (extraID != 0xffffffff) {
			switch (extraID) {
			case k4DDesert0ToIsland0:
			case k4DMountain0ToIsland0:
			case k4DDesert1ToIsland0:
			case k4DMountain1ToIsland0:
			case k4DDesert2ToIsland0:
			case k4DMountain2ToIsland0:
				_videoChoice = k4DIslandChoice;
				break;
			case k4DIsland0ToDesert0:
			case k4DMountain0ToDesert0:
			case k4DIsland1ToDesert0:
			case k4DMountain1ToDesert0:
			case k4DIsland2ToDesert0:
			case k4DMountain2ToDesert0:
				_videoChoice = k4DDesertChoice;
				break;
			case k4DDesert0ToMountain0:
			case k4DIsland0ToMountain0:
			case k4DIsland1ToMountain0:
			case k4DDesert1ToMountain0:
			case k4DIsland2ToMountain0:
			case k4DDesert2ToMountain0:
				_videoChoice = k4DMountainChoice;
				break;
			}

			setSpritesMovie();
			_loopStart = 0;
			_owner->startExtraSequence(extraID, kExtraCompletedFlag, kFilterNoInput);
		}
	}
}

void Caldoria4DSystem::initInteraction() {
	setSpritesMovie();

	_owner->loadLoopSound1("Sounds/Caldoria/Rock.aiff");
	loopExtra(k4DIslandLoop);
}

void Caldoria4DSystem::closeInteraction() {
	stopIdling();
	_neighborhoodNotification->cancelNotification(this);
	_4DSpritesMovie.releaseMovie();
	_owner->loadAmbientLoops();
}

void Caldoria4DSystem::setSpritesMovie() {
	if (_whichMenu == k4DShuttingDown)
		_4DSpritesMovie.setTime(_4DSpritesScale * k4DIslandChoice);
	else if (_whichMenu == k4DVideoMenu)
		_4DSpritesMovie.setTime(_4DSpritesScale * _videoChoice);
	else if (_whichMenu == k4DAudioMenu)
		_4DSpritesMovie.setTime(_4DSpritesScale * _audioChoice);

	_4DSpritesMovie.redrawMovieWorld();
}

void Caldoria4DSystem::handleInput(const Input &input, const Hotspot *cursorSpot) {
	if (input.downButtonAnyDown())
		return;
	if (input.anyDirectionInput())
		shutDown4DSystem();
	else
		GameInteraction::handleInput(input, cursorSpot);
}

void Caldoria4DSystem::activateHotspots() {
	GameInteraction::activateHotspots();
	if (_whichMenu == k4DAudioMenu)
		g_allHotspots.activateOneHotspot(kCa4DChoice4SpotID);
}

void Caldoria4DSystem::clickInHotspot(const Input &input, const Hotspot *spot) {
	switch (spot->getObjectID()) {
	case kCa4DVisualSpotID:
		if (_whichMenu == k4DAudioMenu) {
			_whichMenu = k4DVideoMenu;
			setSpritesMovie();
		}
		break;
	case kCa4DAudioSpotID:
		if (_whichMenu == k4DVideoMenu) {
			_whichMenu = k4DAudioMenu;
			setSpritesMovie();
		}
		break;
	case kCa4DChoice1SpotID:
		if (_whichMenu == k4DVideoMenu)
			makeIslandChoice();
		else if (_whichMenu == k4DAudioMenu)
			makeRockChoice();
		break;
	case kCa4DChoice2SpotID:
		if (_whichMenu == k4DVideoMenu)
			makeDesertChoice();
		else if (_whichMenu == k4DAudioMenu)
			makeOrchestralChoice();
		break;
	case kCa4DChoice3SpotID:
		if (_whichMenu == k4DVideoMenu)
			makeMountainChoice();
		else if (_whichMenu == k4DAudioMenu)
			makeRhythmsChoice();
		break;
	case kCa4DChoice4SpotID:
		if (_whichMenu == k4DAudioMenu)
			makeAcousticChoice();
		else
			_owner->playSpotSoundSync(kCaldoria4DBlankChoiceIn, kCaldoria4DBlankChoiceOut);
		break;
	default:
		GameInteraction::clickInHotspot(input, spot);
	}
}

void Caldoria4DSystem::receiveNotification(Notification *, const NotificationFlags) {
	if (_whichMenu == k4DShuttingDown) {
		_owner->requestDeleteCurrentInteraction();
	} else {
		uint32 extraID;

		switch (_videoChoice) {
		case k4DIslandChoice:
			extraID = k4DIslandLoop;
			break;
		case k4DDesertChoice:
			extraID = k4DDesertLoop;
			break;
		case k4DMountainChoice:
			extraID = k4DMountainLoop;
			break;
		default:
			extraID = 0xffffffff;
			break;
		}

		if (extraID != 0xffffffff)
			loopExtra(extraID);
	}
}

void Caldoria4DSystem::makeIslandChoice() {
	if (_videoChoice != k4DIslandChoice && _clickedHotspotID == kNoHotSpotID)
		_clickedHotspotID = kCa4DChoice1SpotID;
}

void Caldoria4DSystem::makeDesertChoice() {
	if (_videoChoice != k4DDesertChoice && _clickedHotspotID == kNoHotSpotID)
		_clickedHotspotID = kCa4DChoice2SpotID;
}

void Caldoria4DSystem::makeMountainChoice() {
	if (_videoChoice != k4DMountainChoice && _clickedHotspotID == kNoHotSpotID)
		_clickedHotspotID = kCa4DChoice3SpotID;
}

void Caldoria4DSystem::makeRockChoice() {
	if (_audioChoice != k4DRockChoice) {
		_audioChoice = k4DRockChoice;
		setSpritesMovie();
		_owner->loadLoopSound1("Sounds/Caldoria/Rock.aiff");
	}
}

void Caldoria4DSystem::makeOrchestralChoice() {
	if (_audioChoice != k4DOrchestralChoice) {
		_audioChoice = k4DOrchestralChoice;
		setSpritesMovie();
		_owner->loadLoopSound1("Sounds/Caldoria/Orchestral.aiff");
	}
}

void Caldoria4DSystem::makeRhythmsChoice() {
	if (_audioChoice != k4DRhythmsChoice) {
		_audioChoice = k4DRhythmsChoice;
		setSpritesMovie();
		_owner->loadLoopSound1("Sounds/Caldoria/Rhythms.aiff");
	}
}

void Caldoria4DSystem::makeAcousticChoice() {
	if (_audioChoice != k4DAcousticChoice) {
		_audioChoice = k4DAcousticChoice;
		setSpritesMovie();
		_owner->loadLoopSound1("Sounds/Caldoria/Acoustic.aiff");
	}
}

void Caldoria4DSystem::shutDown4DSystem() {
	_whichMenu = k4DShuttingDown;
}

} // End of namespace Pegasus