aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk/myst_stacks/dni.cpp
blob: 3eb3c40cbba0d20e927c54aabb38bc3d28615fa1 (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
/* 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.
 *
 */

#include "mohawk/myst.h"
#include "mohawk/cursors.h"
#include "mohawk/graphics.h"
#include "mohawk/myst_areas.h"
#include "mohawk/sound.h"
#include "mohawk/video.h"
#include "mohawk/myst_stacks/dni.h"

#include "common/system.h"

namespace Mohawk {
namespace MystStacks {

Dni::Dni(MohawkEngine_Myst *vm) :
		MystScriptParser(vm) {
	setupOpcodes();
	_notSeenAtrus = true;
}

Dni::~Dni() {
}

#define OPCODE(op, x) _opcodes.push_back(new MystOpcode(op, (OpcodeProcMyst) &Dni::x, #x))

void Dni::setupOpcodes() {
	// "Stack-Specific" Opcodes
	OPCODE(100, NOP);
	OPCODE(101, o_handPage);

	// "Init" Opcodes
	OPCODE(200, o_atrus_init);

	// "Exit" Opcodes
	OPCODE(300, NOP);
}

#undef OPCODE

void Dni::disablePersistentScripts() {
	_atrusRunning = false;
	_waitForLoop = false;
	_atrusLeft = false;
}

void Dni::runPersistentScripts() {
	if (_atrusRunning)
		atrus_run();

	if (_waitForLoop)
		loopVideo_run();

	if (_atrusLeft)
		atrusLeft_run();
}

uint16 Dni::getVar(uint16 var) {
	switch(var) {
	case 0: // Atrus Gone (from across room)
		return _globals.ending == 2;
	case 1: // Myst Book Status
		if (_globals.ending != 4)
			return _globals.ending == 3;
		else
			return 2; // Linkable
	case 2: // Music Type
		if (_notSeenAtrus) {
			_notSeenAtrus = false;
			return _globals.ending != 4 && _globals.heldPage != 13;
		} else
			return 2;
	default:
		return MystScriptParser::getVar(var);
	}
}

void Dni::o_handPage(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	debugC(kDebugScript, "Opcode %d: Hand page to Atrus", op);
	// Used in Card 5014 (Atrus)

	// Find Atrus movie
	VideoHandle atrus = _vm->_video->findVideoHandle(_video);

	// Good ending and Atrus asked to give page
	if (_globals.ending == 1 && _vm->_video->getTime(atrus) > (uint)Audio::Timestamp(0, 6801, 600).msecs()) {
		_globals.ending = 2;
		_globals.heldPage = 0;
		_vm->setMainCursor(kDefaultMystCursor);

		// Play movie end (atrus leaving)
		_vm->_video->setVideoBounds(atrus, Audio::Timestamp(0, 14813, 600), _vm->_video->getDuration(atrus));
		_vm->_video->setVideoLooping(atrus, false);

		_atrusLeft = true;
		_waitForLoop = false;
		_atrusLeftTime = _vm->_system->getMillis();
	}
}

void Dni::atrusLeft_run() {
	if (_vm->_system->getMillis() > _atrusLeftTime + 63333) {
		_video = _vm->wrapMovieFilename("atrus2", kDniStack);
		VideoHandle atrus = _vm->_video->playMovie(_video, 215, 77);
		_vm->_video->setVideoBounds(atrus, Audio::Timestamp(0, 0, 600), Audio::Timestamp(0, 98000, 600));

		_waitForLoop = true;
		_loopStart = 73095;
		_loopEnd = 98000;

		// Good ending
		_globals.ending = 4;
		_globals.bluePagesInBook = 63;
		_globals.redPagesInBook = 63;

		_atrusLeft = false;
	}
}

void Dni::loopVideo_run() {
	if (!_vm->_video->isVideoPlaying()) {
		VideoHandle atrus = _vm->_video->playMovie(_video, 215, 77);
		_vm->_video->setVideoBounds(atrus, Audio::Timestamp(0, _loopStart, 600), Audio::Timestamp(0, _loopEnd, 600));
		_vm->_video->setVideoLooping(atrus, true);

		_waitForLoop = false;
	}
}

void Dni::atrus_run() {
	if (_globals.ending == 2) {
		// Wait for atrus to come back
		_atrusLeft = true;
	} else if (_globals.ending == 1) {
		// Atrus asking for page
		if (!_vm->_video->isVideoPlaying()) {
			_video = _vm->wrapMovieFilename("atr1page", kDniStack);
			VideoHandle atrus = _vm->_video->playMovie(_video, 215, 77, true);
			_vm->_video->setVideoBounds(atrus, Audio::Timestamp(0, 7388, 600), Audio::Timestamp(0, 14700, 600));
		}
	} else if (_globals.ending != 3 && _globals.ending != 4) {
		if (_globals.heldPage == 13) {
			_video = _vm->wrapMovieFilename("atr1page", kDniStack);
			VideoHandle atrus = _vm->_video->playMovie(_video, 215, 77);
			_vm->_video->setVideoBounds(atrus, Audio::Timestamp(0, 0, 600), Audio::Timestamp(0, 14700, 600));

			_waitForLoop = true;
			_loopStart = 7388;
			_loopEnd = 14700;

			// Wait for page
			_globals.ending = 1;

		} else {
			_video = _vm->wrapMovieFilename("atr1nopg", kDniStack);
			VideoHandle atrus = _vm->_video->playMovie(_video, 215, 77);
			_vm->_video->setVideoBounds(atrus, Audio::Timestamp(0, 0, 600), Audio::Timestamp(0, 46175, 600));

			_waitForLoop = true;
			_loopStart = 30656;
			_loopEnd = 46175;

			// Bad ending
			_globals.ending = 3;
		}
	} else if (!_vm->_video->isVideoPlaying()) {
		_vm->_video->playMovie(_vm->wrapMovieFilename("atrwrite", kDniStack), 215, 77, true);
	}
}

void Dni::o_atrus_init(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
	debugC(kDebugScript, "Opcode %d: Atrus init", op);

	_atrusRunning = true;
}

} // End of namespace MystStacks
} // End of namespace Mohawk