aboutsummaryrefslogtreecommitdiff
path: root/engines/pegasus/neighborhood/norad/subplatform.cpp
blob: 2665ab4ec59748e799946f24ca3e74bad0a0b4c7 (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 - 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/gamestate.h"
#include "pegasus/pegasus.h"
#include "pegasus/ai/ai_area.h"
#include "pegasus/neighborhood/norad/norad.h"
#include "pegasus/neighborhood/norad/subplatform.h"
#include "pegasus/neighborhood/norad/alpha/noradalpha.h"

namespace Pegasus {

// As usual, times here are in seconds.

const TimeValue kNormalSplashStart = 0;
const TimeValue kNormalSplashStop = 5;

const TimeValue kPrepSubStart = 5;
const TimeValue kPrepSubStop = 15;

const TimeValue kPrepIncompleteStart = 15;
const TimeValue kPrepIncompleteStop = 19;

const TimeValue kDamagedStart = 19;
const TimeValue kDamagedStop = 28;

const tNotificationFlags kNormalSplashFinished = 1;
const tNotificationFlags kPrepSubFinished = kNormalSplashFinished << 1;
const tNotificationFlags kPrepIncompleteFinished = kPrepSubFinished << 1;
const tNotificationFlags kDamagedFinished = kPrepIncompleteFinished << 1;

const tNotificationFlags kPlatformNotificationFlags = kNormalSplashFinished |
														kPrepSubFinished |
														kPrepIncompleteFinished |
														kDamagedFinished;

const uint16 kSubPreppedBit = (1 << 0);
const uint16 kWaitingForPlayerBit = (1 << 1);

SubPlatform::SubPlatform(Neighborhood *handler) : GameInteraction(kNoradSubPlatformInteractionID, handler),
		_platformMovie(kPlatformMonitorID), _platformNotification(kNoradSubPlatformNotificationID, (PegasusEngine *)g_engine) {
	_neighborhoodNotification = handler->getNeighborhoodNotification();
}

void SubPlatform::openInteraction() {
	_stateBits = 0;

	// TODO: These next two lines seem unused?
	if (GameState.getNoradSubPrepState() == kSubPrepped)
		_stateBits |= kSubPreppedBit;

	_stateBits |= kWaitingForPlayerBit;
	_platformMovie.initFromMovieFile("Images/Norad Alpha/Platform Monitor Movie");
	_platformMovie.setVolume(((PegasusEngine *)g_engine)->getSoundFXLevel());
	_platformMovie.moveElementTo(kNoradPlatformLeft, kNoradPlatformTop);
	_platformScale = _platformMovie.getScale();
	_platformMovie.setDisplayOrder(kPlatformOrder);
	_platformMovie.startDisplaying();
	_platformCallBack.setNotification(&_platformNotification);
	_platformCallBack.initCallBack(&_platformMovie, kCallBackAtExtremes);
	
	_platformNotification.notifyMe(this, kPlatformNotificationFlags, kPlatformNotificationFlags);
}

void SubPlatform::initInteraction() {
	_neighborhoodNotification->notifyMe(this, kExtraCompletedFlag, kExtraCompletedFlag);
}

void SubPlatform::closeInteraction() {
	_platformNotification.cancelNotification(this);
	_platformCallBack.releaseCallBack();
	_neighborhoodNotification->cancelNotification(this);
}

void SubPlatform::setSoundFXLevel(const uint16 fxLevel) {
	_platformMovie.setVolume(fxLevel);
}

void SubPlatform::receiveNotification(Notification *notification, const tNotificationFlags flags) {
	FaderMoveSpec loop1Spec, loop2Spec;
	ExtraTable::Entry entry;

	Norad *owner = (Norad *)getOwner();

	if (notification == &_platformNotification) {
		switch (flags) {
		case kNormalSplashFinished:
			_platformMovie.stop();
			switch (GameState.getNoradSubPrepState()) {
			case kSubNotPrepped:
				_platformMovie.setSegment(kPrepIncompleteStart * _platformScale, kPrepIncompleteStop * _platformScale);
				_platformMovie.setTime(kPrepIncompleteStart * _platformScale);
				_platformCallBack.setCallBackFlag(kPrepIncompleteFinished);
				_platformCallBack.scheduleCallBack(kTriggerAtStop, 0, 0);
				_platformMovie.start();
				break;
			case kSubPrepped:
				_platformMovie.setSegment(kPrepSubStart * _platformScale, kPrepSubStop * _platformScale);
				_platformMovie.setTime(kPrepSubStart * _platformScale);
				_platformCallBack.setCallBackFlag(kPrepSubFinished);
				_platformCallBack.scheduleCallBack(kTriggerAtStop, 0, 0);
				owner->startExtraSequence(kNorad19PrepSub, 0, kFilterNoInput);
				_platformMovie.start();
				break;
			case kSubDamaged:
				// Shouldn't happen.
				break;
			}
			break;
		case kPrepSubFinished:
			_platformMovie.stop();
			_platformMovie.stopDisplaying();

			owner->getExtraEntry(kNorad19ExitToSub, entry);
				
			loop1Spec.makeTwoKnotFaderSpec(kNoradAlphaMovieScale, 0, kNoradWarningVolume,
					entry.movieEnd - entry.movieStart, 0);
			loop1Spec.insertFaderKnot(4560, kNoradWarningVolume);
			loop1Spec.insertFaderKnot(5080, 0);
				
			loop2Spec.makeTwoKnotFaderSpec(kNoradAlphaMovieScale, 0, kNoradSuckWindVolume,
					entry.movieEnd - entry.movieStart, 0);
			loop1Spec.insertFaderKnot(4560, kNoradSuckWindVolume);
			loop1Spec.insertFaderKnot(5080, 0);

			owner->startExtraSequence(kNorad19ExitToSub, kExtraCompletedFlag, kFilterNoInput);

			owner->startLoop1Fader(loop1Spec);
			owner->startLoop2Fader(loop2Spec);
			break;
		case kPrepIncompleteFinished:
			((NoradAlpha *)owner)->setSubPrepFailed(true);
			g_AIArea->checkMiddleArea();
			// Fall through...
		case kDamagedFinished:
			_platformMovie.stop();
			_platformMovie.hide();
			_stateBits |= kWaitingForPlayerBit;
			allowInput(true);
			break;
		}
	} else if (notification == _neighborhoodNotification) {
		allowInput(true);
		((PegasusEngine *)g_engine)->jumpToNewEnvironment(kNoradSubChaseID, kNoRoomID, kNoDirection);
		GameState.setScoringEnteredSub(true);
	}
}

void SubPlatform::activateHotspots() {
	if (_stateBits & kWaitingForPlayerBit)
		g_allHotspots.activateOneHotspot(kNorad19ActivateMonitorSpotID);

	GameInteraction::activateHotspots();
}

void SubPlatform::clickInHotspot(const Input &input, const Hotspot *spot) {	
	if (spot->getObjectID() == kNorad19ActivateMonitorSpotID) {
		if (GameState.getNoradSubPrepState() == kSubDamaged) {
			_platformMovie.setSegment(kDamagedStart * _platformScale, kDamagedStop * _platformScale);
			_platformMovie.setTime(kDamagedStart * _platformScale);
			_platformCallBack.setCallBackFlag(kDamagedFinished);
		} else {
			_platformMovie.setSegment(kNormalSplashStart * _platformScale, kNormalSplashStop * _platformScale);
			_platformMovie.setTime(kNormalSplashStart * _platformScale);
			_platformCallBack.setCallBackFlag(kNormalSplashFinished);
		}

		_platformCallBack.scheduleCallBack(kTriggerAtStop, 0, 0);

		_platformMovie.show();
		_platformMovie.start();
		_platformMovie.redrawMovieWorld();

		_stateBits &= ~kWaitingForPlayerBit;
		
		allowInput(false);
	} else {
		GameInteraction::clickInHotspot(input, spot);
	}
}

} // End of namespace Pegasus