aboutsummaryrefslogtreecommitdiff
path: root/engines/pegasus/neighborhood/norad/alpha/fillingstation.cpp
blob: 169f75f7d29975eb7866cb18b31f9a1f40b24c01 (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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
/* 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/items/inventory/airmask.h"
#include "pegasus/neighborhood/norad/constants.h"
#include "pegasus/neighborhood/norad/alpha/fillingstation.h"
#include "pegasus/neighborhood/norad/alpha/noradalpha.h"

namespace Pegasus {

static const NotificationFlags kFSPowerUpFinishedFlag = 1;
static const NotificationFlags kFSSplashFinishedFlag = kFSPowerUpFinishedFlag << 1;
static const NotificationFlags kFSIntakeWarningFinishedFlag = kFSSplashFinishedFlag << 1;
static const NotificationFlags kFSIntakeHiliteFinishedFlag = kFSIntakeWarningFinishedFlag << 1;
static const NotificationFlags kFSDispenseHiliteFinishedFlag = kFSIntakeHiliteFinishedFlag << 1;
static const NotificationFlags kFSArHiliteFinishedFlag = kFSDispenseHiliteFinishedFlag << 1;
static const NotificationFlags kFSCO2HiliteFinishedFlag = kFSArHiliteFinishedFlag << 1;
static const NotificationFlags kFSHeHiliteFinishedFlag = kFSCO2HiliteFinishedFlag << 1;
static const NotificationFlags kFSOHiliteFinishedFlag = kFSHeHiliteFinishedFlag << 1;
static const NotificationFlags kFSNHiliteFinishedFlag = kFSOHiliteFinishedFlag << 1;

static const NotificationFlags kFSNotificationFlags = kFSPowerUpFinishedFlag |
												kFSSplashFinishedFlag |
												kFSIntakeWarningFinishedFlag |
												kFSIntakeHiliteFinishedFlag |
												kFSDispenseHiliteFinishedFlag |
												kFSArHiliteFinishedFlag |
												kFSCO2HiliteFinishedFlag |
												kFSHeHiliteFinishedFlag |
												kFSOHiliteFinishedFlag |
												kFSNHiliteFinishedFlag;

static const int16 kNoState = 0;
static const int16 kMainMenu = 1;
static const int16 kWaitingForAttach = 2;
static const int16 kDispenseMenu = 3;
static const int16 kWaitingForDispense = 4;

// Dummy itemIDs
static const ItemID kCO2Item = 10000;
static const ItemID kHeItem = 10001;

// Interactive points.
static const TimeValue kFSPowerUpStartStart = 0;
static const TimeValue kFSPowerUpStartStop = 600;
static const TimeValue kFSSplashStart = 600;
static const TimeValue kFSSplashStop = 7800;
static const TimeValue kFSSplashIntakeStart = 7800;
static const TimeValue kFSSplashIntakeStop = 18600;

static const TimeValue kFSMainMenu = 18600;
static const TimeValue kFSIntakeHiliteStart = 19200;
static const TimeValue kFSIntakeHiliteStop = 19800;
static const TimeValue kFSDispenseHiliteStart = 19800;
static const TimeValue kFSDispenseHiliteStop = 20400;

static const TimeValue kFSDispenseMenu = 20400;

static const TimeValue kFSArHiliteStart = 21000;
static const TimeValue kFSArHiliteStop = 21600;
static const TimeValue kFSArAttach = 21600;
static const TimeValue kFSArFilledStart = 22200;
static const TimeValue kFSArFilledStop = 25200;
static const TimeValue kFSArIncompatibleStart = 25200;
static const TimeValue kFSArIncompatibleStop = 30000;

static const TimeValue kFSCO2HiliteStart = 30000;
static const TimeValue kFSCO2HiliteStop = 30600;
static const TimeValue kFSCO2Attach = 30600;
static const TimeValue kFSCO2FilledStart = 31200;
static const TimeValue kFSCO2FilledStop = 34200;
static const TimeValue kFSCO2IncompatibleStart = 34200;
static const TimeValue kFSCO2IncompatibleStop = 39000;

static const TimeValue kFSHeHiliteStart = 39000;
static const TimeValue kFSHeHiliteStop = 39600;
static const TimeValue kFSHeAttach = 39600;
static const TimeValue kFSHeFilledStart = 40200;
static const TimeValue kFSHeFilledStop = 43200;
static const TimeValue kFSHeIncompatibleStart = 43200;
static const TimeValue kFSHeIncompatibleStop = 48000;

static const TimeValue kFSOHiliteStart = 48000;
static const TimeValue kFSOHiliteStop = 48600;
static const TimeValue kFSOAttach = 48600;
static const TimeValue kFSOFilledStart = 49200;
static const TimeValue kFSOFilledStop = 52200;
static const TimeValue kFSOIncompatibleStart = 52200;
static const TimeValue kFSOIncompatibleStop = 57000;

static const TimeValue kFSNHiliteStart = 57000;
static const TimeValue kFSNHiliteStop = 57600;
static const TimeValue kFSNAttach = 57600;
static const TimeValue kFSNFilledStart = 58200;
static const TimeValue kFSNFilledStop = 61200;
static const TimeValue kFSNIncompatibleStart = 61200;
static const TimeValue kFSNIncompatibleStop = 66000;

static const TimeValue kFSIntakeMenu = 66000;
static const TimeValue kFSIntakeInProgressStart = 66600;
static const TimeValue kFSIntakeInProgressStop = 69600;

NoradAlphaFillingStation::NoradAlphaFillingStation(Neighborhood *owner) : GameInteraction(kNoradFillingStationInteractionID, owner),
		_rightSideMovie(kN01RightSideID), _rightSideNotification(kNoradFillingStationNotificationID, ((PegasusEngine *)g_engine)) {
	_state = kNoState;
}

void NoradAlphaFillingStation::openInteraction() {
	_rightSideMovie.initFromMovieFile("Images/Norad Alpha/N01W Right Side");
	_rightSideMovie.moveElementTo(kNoradAlpha01RightSideLeft, kNoradAlpha01RightSideTop);
	_rightSideMovie.setDisplayOrder(kN01RightSideOrder);
	_rightSideMovie.startDisplaying();
	_rightSideCallBack.setNotification(&_rightSideNotification);
	_rightSideCallBack.initCallBack(&_rightSideMovie, kCallBackAtExtremes);
	_rightSideCallBack.setCallBackFlag(kFSPowerUpFinishedFlag);
	_rightSideNotification.notifyMe(this, kFSNotificationFlags, kFSNotificationFlags);
	_rightSideCallBack.scheduleCallBack(kTriggerAtStop, 0, 0);
	_rightSideMovie.show();
	_rightSideMovie.redrawMovieWorld();
	_rightSideMovie.setSegment(kFSPowerUpStartStart, kFSPowerUpStartStop);
}

void NoradAlphaFillingStation::initInteraction() {
	allowInput(false);

	_rightSideMovie.setRate(2);
}

void NoradAlphaFillingStation::closeInteraction() {
	_rightSideMovie.stop();
	_rightSideMovie.stopDisplaying();
	_rightSideMovie.releaseMovie();
	_rightSideCallBack.releaseCallBack();
	((NoradAlpha *)getOwner())->turnOffFillingStation();
}

void NoradAlphaFillingStation::setStaticState(TimeValue time, int16 state) {
	_rightSideMovie.stop();
	_rightSideMovie.setSegment(0, _rightSideMovie.getDuration());
	_rightSideMovie.setTime(time);
	_rightSideMovie.redrawMovieWorld();
	_state = state;
	allowInput(true);
}

void NoradAlphaFillingStation::setSegmentState(TimeValue start, TimeValue stop, NotificationFlags flag, int16 state) {
	_rightSideMovie.stop();
	_rightSideMovie.setSegment(start, stop);
	_rightSideMovie.setTime(start);
	_rightSideCallBack.setCallBackFlag(flag);
	_rightSideCallBack.scheduleCallBack(kTriggerAtStop, 0, 0);
	_state = state;
	allowInput(false);
	_rightSideMovie.setRate(2);
}

void NoradAlphaFillingStation::powerUpFinished() {
	((NoradAlpha *)getOwner())->turnOnFillingStation();
	setSegmentState(kFSSplashStart, kFSSplashStop, kFSSplashFinishedFlag, kNoState);
}

void NoradAlphaFillingStation::splashFinished() {
	if (GameState.getNoradGassed())
		setSegmentState(kFSSplashIntakeStart, kFSSplashIntakeStop, kFSIntakeWarningFinishedFlag, kNoState);
	else
		intakeWarningFinished();
}

void NoradAlphaFillingStation::intakeWarningFinished() {
	setStaticState(kFSMainMenu, kMainMenu);
}

void NoradAlphaFillingStation::showIntakeInProgress(uint16 numSeconds) {
	if (numSeconds == 0) {
		setSegmentState(kFSIntakeInProgressStart, kFSIntakeInProgressStop, kFSIntakeWarningFinishedFlag, kNoState);
		Item *item = ((NoradAlpha *)getOwner())->getFillingItem();

		if (item->getObjectID() == kGasCanister) {
			GameState.setNoradGassed(true);
			((NoradAlpha *)getOwner())->loadAmbientLoops();
			getOwner()->restoreStriding(kNorad03, kEast, kAltNoradAlphaNormal);
		}
	} else {
		setSegmentState(kFSIntakeInProgressStart, kFSIntakeInProgressStart + _rightSideMovie.getScale() * numSeconds,
				kFSIntakeWarningFinishedFlag, kNoState);
	}
}

void NoradAlphaFillingStation::intakeHighlightFinished() {
	_rightSideMovie.stop();

	if (GameState.getNoradGassed()) {
		showIntakeInProgress(2);
	} else {
		Item *item = ((NoradAlpha *)getOwner())->getFillingItem();
		if (item)
			showIntakeInProgress(0);
		else
			setStaticState(kFSIntakeMenu, kWaitingForAttach);
	}
}

void NoradAlphaFillingStation::dispenseHighlightFinished() {
	setStaticState(kFSDispenseMenu, kDispenseMenu);
}

void NoradAlphaFillingStation::dispenseGas() {
	Item *item = ((NoradAlpha *)getOwner())->getFillingItem();

	if (item) {
		if (item->getObjectID() != _dispenseItemID)
			switch (_dispenseItemID) {
			case kArgonCanister:
				setSegmentState(kFSArIncompatibleStart, kFSArIncompatibleStop,
						kFSIntakeWarningFinishedFlag, kNoState);
				break;
			case kCO2Item:
				setSegmentState(kFSCO2IncompatibleStart, kFSCO2IncompatibleStop,
						kFSIntakeWarningFinishedFlag, kNoState);
				break;
			case kHeItem:
				setSegmentState(kFSHeIncompatibleStart, kFSHeIncompatibleStop,
						kFSIntakeWarningFinishedFlag, kNoState);
				break;
			case kAirMask:
				setSegmentState(kFSOIncompatibleStart, kFSOIncompatibleStop,
						kFSIntakeWarningFinishedFlag, kNoState);
				break;
			case kNitrogenCanister:
				setSegmentState(kFSNIncompatibleStart, kFSNIncompatibleStop,
						kFSIntakeWarningFinishedFlag, kNoState);
				break;
			}
		else {
			if (_dispenseItemID == kArgonCanister) {
				setSegmentState(kFSArFilledStart, kFSArFilledStop, kFSIntakeWarningFinishedFlag, kNoState);
				item->setItemState(kArgonFull);
				GameState.setScoringFilledArgonCanister(true);
			} else if (_dispenseItemID == kAirMask) {
				setSegmentState(kFSOFilledStart, kFSOFilledStop, kFSIntakeWarningFinishedFlag, kNoState);
				((AirMask *)item)->refillAirMask();
				GameState.setScoringFilledOxygenCanister(true);
			} else if (_dispenseItemID == kNitrogenCanister) {
				setSegmentState(kFSNFilledStart, kFSNFilledStop, kFSIntakeWarningFinishedFlag, kNoState);
				item->setItemState(kNitrogenFull);
			}
		}
	} else {
		switch (_dispenseItemID) {
		case kArgonCanister:
			setStaticState(kFSArAttach, kWaitingForDispense);
			break;
		case kCO2Item:
			setStaticState(kFSCO2Attach, kWaitingForDispense);
			break;
		case kHeItem:
			setStaticState(kFSHeAttach, kWaitingForDispense);
			break;
		case kAirMask:
			setStaticState(kFSOAttach, kWaitingForDispense);
			break;
		case kNitrogenCanister:
			setStaticState(kFSNAttach, kWaitingForDispense);
			break;
		}
	}
}

void NoradAlphaFillingStation::ArHighlightFinished() {
	_dispenseItemID = kArgonCanister;
	dispenseGas();
}

void NoradAlphaFillingStation::CO2HighlightFinished() {
	_dispenseItemID = kCO2Item;
	dispenseGas();
}

void NoradAlphaFillingStation::HeHighlightFinished() {
	_dispenseItemID = kHeItem;
	dispenseGas();
}

void NoradAlphaFillingStation::OHighlightFinished() {
	_dispenseItemID = kAirMask;
	dispenseGas();
}

void NoradAlphaFillingStation::NHighlightFinished() {
	_dispenseItemID = kNitrogenCanister;
	dispenseGas();
}

void NoradAlphaFillingStation::receiveNotification(Notification *, const NotificationFlags flags) {
	switch (flags) {
	case kFSPowerUpFinishedFlag:
		powerUpFinished();
		break;
	case kFSSplashFinishedFlag:
		splashFinished();
		break;
	case kFSIntakeWarningFinishedFlag:
		intakeWarningFinished();
		break;
	case kFSIntakeHiliteFinishedFlag:
		intakeHighlightFinished();
		break;
	case kFSDispenseHiliteFinishedFlag:
		dispenseHighlightFinished();
		break;
	case kFSArHiliteFinishedFlag:
		ArHighlightFinished();
		break;
	case kFSCO2HiliteFinishedFlag:
		CO2HighlightFinished();
		break;
	case kFSHeHiliteFinishedFlag:
		HeHighlightFinished();
		break;
	case kFSOHiliteFinishedFlag:
		OHighlightFinished();
		break;
	case kFSNHiliteFinishedFlag:
		NHighlightFinished();
		break;
	}
}

void NoradAlphaFillingStation::handleInput(const Input &input, const Hotspot *cursorSpot) {
	InputHandler::handleInput(input, cursorSpot);
}

void NoradAlphaFillingStation::clickInIntake() {
	setSegmentState(kFSIntakeHiliteStart, kFSIntakeHiliteStop, kFSIntakeHiliteFinishedFlag, kNoState);
}

void NoradAlphaFillingStation::clickInDispense() {
	setSegmentState(kFSDispenseHiliteStart, kFSDispenseHiliteStop, kFSDispenseHiliteFinishedFlag, kNoState);
}

void NoradAlphaFillingStation::clickInAr() {
	setSegmentState(kFSArHiliteStart, kFSArHiliteStop, kFSArHiliteFinishedFlag, kNoState);
}

void NoradAlphaFillingStation::clickInCO2() {
	setSegmentState(kFSCO2HiliteStart, kFSCO2HiliteStop, kFSCO2HiliteFinishedFlag, kNoState);
}

void NoradAlphaFillingStation::clickInHe() {
	setSegmentState(kFSHeHiliteStart, kFSHeHiliteStop, kFSHeHiliteFinishedFlag, kNoState);
}

void NoradAlphaFillingStation::clickInO() {
	setSegmentState(kFSOHiliteStart, kFSOHiliteStop, kFSOHiliteFinishedFlag, kNoState);
}

void NoradAlphaFillingStation::clickInN() {
	setSegmentState(kFSNHiliteStart, kFSNHiliteStop, kFSNHiliteFinishedFlag, kNoState);
}

void NoradAlphaFillingStation::clickInHotspot(const Input &input, const Hotspot *spot) {
	GameInteraction::clickInHotspot(input, spot);

	switch (spot->getObjectID()) {
	case kNorad01IntakeSpotID:
		clickInIntake();
		break;
	case kNorad01DispenseSpotID:
		clickInDispense();
		break;
	case kNorad01ArSpotID:
		clickInAr();
		break;
	case kNorad01CO2SpotID:
		clickInCO2();
		break;
	case kNorad01HeSpotID:
		clickInHe();
		break;
	case kNorad01OSpotID:
		clickInO();
		break;
	case kNorad01NSpotID:
		clickInN();
		break;
	}
}

void NoradAlphaFillingStation::activateHotspots() {
	GameInteraction::activateHotspots();

	switch (_state) {
	case kMainMenu:
		g_allHotspots.activateOneHotspot(kNorad01IntakeSpotID);
		g_allHotspots.activateOneHotspot(kNorad01DispenseSpotID);
		break;
	case kDispenseMenu:
		g_allHotspots.activateOneHotspot(kNorad01ArSpotID);
		g_allHotspots.activateOneHotspot(kNorad01CO2SpotID);
		g_allHotspots.activateOneHotspot(kNorad01HeSpotID);
		g_allHotspots.activateOneHotspot(kNorad01OSpotID);
		g_allHotspots.activateOneHotspot(kNorad01NSpotID);
		break;
	}
}

void NoradAlphaFillingStation::newFillingItem(Item *item) {
	switch (_state) {
	case kWaitingForAttach:
		if (item)
			showIntakeInProgress(0);
		break;
	case kWaitingForDispense:
		dispenseGas();
		break;
	default:
		break;
	}
}

} // End of namespace Pegasus