aboutsummaryrefslogtreecommitdiff
path: root/engines/pegasus/neighborhood/norad/alpha/ecrmonitor.cpp
blob: 1478a74744eea200fc3e33da628224927c855473 (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
/* 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/neighborhood/norad/constants.h"
#include "pegasus/neighborhood/norad/norad.h"
#include "pegasus/neighborhood/norad/alpha/ecrmonitor.h"

namespace Pegasus {

static const NotificationFlags kECRSection1FinishedFlag = 1;
static const NotificationFlags kECRPanFinishedFlag = kECRSection1FinishedFlag << 1;
static const NotificationFlags kECRSection2FinishedFlag = kECRPanFinishedFlag << 1;
static const NotificationFlags kECRNotificationFlags = kECRSection1FinishedFlag |
													kECRPanFinishedFlag |
													kECRSection2FinishedFlag;

static const TimeValue kSection1Start = 0;
static const TimeValue kSection1Stop = 25;
static const TimeValue kPanStart = 0;
static const TimeValue kPanStop = 20;
static const TimeValue kSection2Start = 26;
static const TimeValue kSection2Stop = 1000;

// Seems to be a good value for a 20 second pan.
enum {
	kPanPixelsPerFrame = 8
};

// Interesting times are in seconds.
static const TimeValue s_ECRInterestingTimes[] = {
	0, 1, 2, 10, 25, 26, 56, 64, 72, 80, 88, 94, 102, 108, 116, 999
};

// Index into s_ECRInterestingTimes of interesting time before security pan.
static const int kBeforePanTime = 3;

// Index into s_ECRInterestingTimes of interesting time after security pan.
static const int kAfterPanTime = 5;

NoradAlphaECRMonitor::NoradAlphaECRMonitor(Neighborhood *nextHandler) : GameInteraction(kNoradECRMonitorInteractionID, nextHandler),
		_ecrSlideShowNotification(kNoradECRNotificationID, (PegasusEngine *)g_engine), _ecrMovie(kECRSlideShowMovieID),
		_ecrPan(kECRPanID) {
}

void NoradAlphaECRMonitor::receiveNotification(Notification *, const NotificationFlags flags) {
	if (flags & kECRSection1FinishedFlag)
		ecrSection1Finished();
	else if (flags & kECRPanFinishedFlag)
		ecrPanFinished();
	else if (flags & kECRSection2FinishedFlag)
		ecrSection2Finished();
}

int NoradAlphaECRMonitor::findCurrentInterestingTime() {
	TimeValue time = _ecrMovie.getTime();
	TimeScale scale = _ecrMovie.getScale();

	for (int i = ARRAYSIZE(s_ECRInterestingTimes) - 1; i >= 0; i--)
		if (time >= s_ECRInterestingTimes[i] * scale)
			return i;

	return 0;
}

void NoradAlphaECRMonitor::skipToNextInterestingTime() {
	if (_ecrMovie.isRunning()) {
		int interestingTime = findCurrentInterestingTime();
		_ecrMovie.setTime(s_ECRInterestingTimes[interestingTime + 1] * _ecrMovie.getScale());
		_ecrMovie.redrawMovieWorld();
	} else if (_ecrPan.isRunning()) {
		_ecrPanCallBack.cancelCallBack();
		ecrPanFinished();
	}
}

void NoradAlphaECRMonitor::skipToPreviousInterestingTime() {
	if (_ecrPan.isRunning()) {
		_ecrPan.stop();
		_ecrPan.stopDisplaying();
		_ecrPanCallBack.cancelCallBack();

		_ecrMovieCallBack.setCallBackFlag(kECRSection1FinishedFlag);
		_ecrMovieCallBack.scheduleCallBack(kTriggerAtStop, 0, 0);

		TimeScale scale = _ecrMovie.getScale();
		_ecrMovie.setSegment(kSection1Start * scale, kSection1Stop * scale + 1);
		_ecrMovie.setTime(s_ECRInterestingTimes[kBeforePanTime] * scale);
		_ecrMovie.start();
	} else {
		int interestingTime = findCurrentInterestingTime();

		if (interestingTime == kAfterPanTime) {
			_ecrMovieCallBack.cancelCallBack();
			TimeScale scale = _ecrMovie.getScale();
			_ecrMovie.setSegment(kSection1Start * scale, kSection1Stop * scale + 1);
			_ecrMovie.setTime(kSection1Stop * scale);
			ecrSection1Finished();
		} else if (interestingTime == 0) {
			_ecrMovie.setTime(kSection1Start * _ecrMovie.getScale());
			_ecrMovie.redrawMovieWorld();
		} else {
			_ecrMovie.setTime(s_ECRInterestingTimes[interestingTime - 1] * _ecrMovie.getScale());
			_ecrMovie.redrawMovieWorld();
		}
	}
}

void NoradAlphaECRMonitor::handleInput(const Input &input, const Hotspot *cursorSpot) {
	if (isInteracting()) {
		if (input.rightButtonDown())
			skipToNextInterestingTime();
		else if (input.leftButtonDown())
			skipToPreviousInterestingTime();
		else
			InputHandler::handleInput(input, cursorSpot);
	} else {
		InputHandler::handleInput(input, cursorSpot);
	}
}

void NoradAlphaECRMonitor::ecrSection1Finished() {
	_ecrMovie.stop();
	_ecrPanCallBack.setNotification(&_ecrSlideShowNotification);
	_ecrPanCallBack.initCallBack(&_ecrPan, kCallBackAtExtremes);
	_ecrPanCallBack.setCallBackFlag(kECRPanFinishedFlag);
	_ecrSlideShowNotification.notifyMe(this, kECRNotificationFlags, kECRNotificationFlags);
	_ecrPanCallBack.scheduleCallBack(kTriggerAtStop, 0, 0);
	_ecrPan.startDisplaying();
	_ecrPan.show();

	TimeScale scale = _ecrPan.getScale();
	_ecrPan.setSegment(kPanStart * scale, kPanStop * scale);
	_ecrPan.setTime(0);
	_ecrPan.start();
}

void NoradAlphaECRMonitor::ecrPanFinished() {
	_ecrPan.stop();
	_ecrPan.stopDisplaying();
	_ecrMovieCallBack.setCallBackFlag(kECRSection2FinishedFlag);
	_ecrMovieCallBack.scheduleCallBack(kTriggerAtStop, 0, 0);

	TimeScale scale = _ecrMovie.getScale();
	_ecrMovie.setSegment(kSection2Start * scale, kSection2Stop * scale);
	_ecrMovie.start();
}

void NoradAlphaECRMonitor::ecrSection2Finished() {
	_ecrMovie.stop();
	_ecrMovie.stopDisplaying();
}

void NoradAlphaECRMonitor::openInteraction() {
	// Initialize the security pan.
	_ecrPan.initFromMovieFile("Images/Norad Alpha/Security Pan.pano");
	_ecrPan.initMaskFromPICTFile("Images/Norad Alpha/Security Pan Mask");
	_ecrPan.setBounds(Common::Rect(kECRPanLeft, kECRPanTop, kECRPanRight, kECRPanBottom));
	_ecrPan.setDisplayOrder(kECRPanOrder);
	_ecrPan.setScale(15); // 15 fps.

	// Begin the lame ECR slide show.
	// clone2727: I didn't say it :P
	_ecrMovie.initFromMovieFile("Images/Norad Alpha/ECR Monitor Movie");

	_ecrMovieCallBack.setNotification(&_ecrSlideShowNotification);
	_ecrMovieCallBack.initCallBack(&_ecrMovie, kCallBackAtExtremes);
	_ecrMovieCallBack.setCallBackFlag(kECRSection1FinishedFlag);

	_ecrSlideShowNotification.notifyMe(this, kECRNotificationFlags, kECRNotificationFlags);
	_ecrMovieCallBack.scheduleCallBack(kTriggerAtStop, 0, 0);

	_ecrMovie.moveElementTo(kECRSlideShowLeft, kECRSlideShowTop);
	_ecrMovie.setDisplayOrder(kECRMonitorOrder);
	_ecrMovie.startDisplaying();
	_ecrMovie.show();
	_ecrMovie.redrawMovieWorld();

	TimeScale scale = _ecrMovie.getScale();
	_ecrMovie.setSegment(kSection1Start * scale, kSection1Stop * scale + 1);

	_ecrMovie.start();
}

void NoradAlphaECRMonitor::closeInteraction() {
	_ecrMovieCallBack.releaseCallBack();
	_ecrMovie.stop();
	_ecrMovie.stopDisplaying();
	_ecrMovie.releaseMovie();
	_ecrMovieCallBack.releaseCallBack();

	_ecrPanCallBack.releaseCallBack();
	_ecrPan.stop();
	_ecrPan.stopDisplaying();
	_ecrPan.releasePanorama();
	_ecrPanCallBack.releaseCallBack();
}

} // End of namespace Pegasus