1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "startrek/startrek.h"
24
25 namespace StarTrek {
26
playIntro()27 void StarTrekEngine::playIntro() {
28 // TODO: .MT audio file
29
30 initStarfieldPosition();
31 initStarfield(10, 20, 309, 169, 128);
32
33 SharedPtr<Bitmap> fakeStarfieldBitmap(new StubBitmap(0, 0));
34 _starfieldSprite.bitmap = fakeStarfieldBitmap;
35 initStarfieldSprite(&_starfieldSprite, fakeStarfieldBitmap, _starfieldRect);
36
37 //delR3(&_enterpriseR3); // TODO: uncomment
38
39 R3 planetR3 = R3();
40 planetR3.matrix = initMatrix();
41 planetR3.field1e = 3;
42 planetR3.funcPtr1 = 0;
43 planetR3.funcPtr2 = 0;
44 planetR3.bitmapOffset = 0;
45
46 _gfx->clearScreenAndPriBuffer();
47 _gfx->fadeoutScreen();
48 _gfx->loadPalette("gold");
49 _gfx->setBackgroundImage(_gfx->loadBitmap("goldlogo"));
50 _sound->playVoc("logo");
51 _gfx->copyBackgroundScreen();
52 _system->updateScreen();
53 _system->delayMillis(10);
54 _gfx->fadeinScreen();
55
56 uint32 clockTicks = _clockTicks;
57
58 Sprite subtitleSprite;
59 _gfx->addSprite(&subtitleSprite);
60 subtitleSprite.setXYAndPriority(0, 0, 12);
61 subtitleSprite.bitmap = _gfx->loadBitmap("blank");
62 subtitleSprite.drawPriority2 = 16;
63
64 int index = 12;
65 while (index >= 0) {
66 Common::String file = Common::String::format("credit%02d.shp", index);
67 // TODO: This loads the file, but does not do anything with the resulting data, so
68 // this is just for caching it?
69 // Remember to deal with similar commented function calls below, too.
70 //loadFileWithParams(file, false, true, false);
71 index -= 1;
72 }
73
74 //loadFileWithParams("legal.bmp", false, true, false);
75
76 index = 6;
77 while (index >= 0) {
78 Common::String file = Common::String::format("tittxt%02d.bmp", index);
79 //loadFileWithParams(file, false, true, false);
80 index -= 1;
81 }
82
83 //loadFileWithParams("planet.shp", false, true, false);
84
85 index = 6;
86 while (index >= 0) {
87 Common::String file = Common::String::format("ent%d3.r3s", index);
88 //loadFileWithParams(file, false, true, false);
89 index -= 1;
90 }
91
92 // TODO: kirkintr
93
94 clockTicks += 540;
95
96 while (_clockTicks < clockTicks && _sound->isMidiPlaying()) {
97 waitForNextTick(true);
98 }
99
100 // TODO: MT audio file
101
102 _gfx->fadeoutScreen();
103 _gfx->loadPalette("bridge");
104 _gfx->clearScreenAndPriBuffer();
105 _sound->loadMusicFile("title");
106 clockTicks = _clockTicks;
107
108 int32 starfieldZoomSpeed = 0;
109 int16 frame = 0;
110 bool buttonPressed = false;
111
112 while (frame != 0x180 || (_sound->isMidiPlaying() && !buttonPressed)) {
113 if (!buttonPressed) {
114 TrekEvent event;
115 while (popNextEvent(&event, false)) {
116 if (event.type == TREKEVENT_KEYDOWN) {
117 _gfx->fadeoutScreen();
118 buttonPressed = true;
119 } else if (event.type == TREKEVENT_TICK)
120 break;
121 }
122 }
123
124 switch (frame) {
125 case 0:
126 starfieldZoomSpeed = 10;
127 playMidiMusicTracks(MIDITRACK_0, -1);
128 _byte_45b3c = 0;
129 break;
130
131 case 30:
132 _sound->playVoc("kirkintr");
133 loadSubtitleSprite(0, &subtitleSprite);
134 break;
135
136 case 36:
137 loadSubtitleSprite(1, &subtitleSprite);
138 break;
139
140 case 42: // Enterprise moves toward camera
141 loadSubtitleSprite(-1, &subtitleSprite);
142 addR3(&_enterpriseR3);
143 _enterpriseR3.field1e = 2;
144 initIntroR3ObjectToMove(&_enterpriseR3, 330, 5000, 0, 0, 18);
145 break;
146
147 case 60: // Enterprise moves away from camera
148 initIntroR3ObjectToMove(&_enterpriseR3, 0, 0, 30, 5000, 6);
149 break;
150
151 case 66: // Cut to scene with planet
152 loadSubtitleSprite(2, &subtitleSprite);
153 planetR3.field22 = 2000;
154 planetR3.field24 = 10000 / _starfieldPointDivisor;
155 planetR3.shpFile = SharedPtr<Common::MemoryReadStreamEndian>(loadFile("planet.shp"));
156 initIntroR3ObjectToMove(&planetR3, 6, 10000, 6, 10000, 0);
157 addR3(&planetR3);
158 initIntroR3ObjectToMove(&_enterpriseR3, -15, 250, 15, 500, 18);
159 starfieldZoomSpeed = 0;
160 break;
161
162 case 186:
163 delR3(&_enterpriseR3);
164 // TODO: the rest
165 break;
166
167 case 366:
168 planetR3.shpFile.reset();
169 delR3(&planetR3);
170 break;
171
172 case 378:
173 _gfx->delSprite(&subtitleSprite);
174 _byte_45b3c = 1;
175 break;
176 }
177
178 if (!buttonPressed) {
179 updateStarfieldAndShips(false);
180 _gfx->drawAllSprites();
181 _gfx->incPaletteFadeLevel();
182 clockTicks += 3;
183
184 while (_clockTicks < clockTicks)
185 waitForNextTick();
186 }
187
188 _starfieldPosition.z += starfieldZoomSpeed;
189
190 frame++;
191 if (frame >= 0x186)
192 frame = 0x186;
193 }
194
195 _gfx->fadeoutScreen();
196 _gfx->delSprite(&_starfieldSprite);
197 // TODO: the rest
198 }
199
initIntroR3ObjectToMove(R3 * r3,int16 srcAngle,int16 srcDepth,int16 destAngle,int16 destDepth,int16 ticks)200 void StarTrekEngine::initIntroR3ObjectToMove(R3 *r3, int16 srcAngle, int16 srcDepth, int16 destAngle, int16 destDepth, int16 ticks) {
201 Fixed8 a1 = Fixed8::fromRaw((srcAngle << 8) / 90);
202 Fixed8 a2 = Fixed8::fromRaw((destAngle << 8) / 90);
203
204 r3->pos.x = sin(a1).multToInt(srcDepth) + _starfieldPosition.x;
205 r3->pos.z = cos(a1).multToInt(srcDepth) + _starfieldPosition.z;
206 r3->pos.y = 0;
207
208 int32 deltaX = sin(a2).multToInt(destDepth) + _starfieldPosition.x - r3->pos.x;
209 int32 deltaZ = cos(a2).multToInt(destDepth) + _starfieldPosition.z - r3->pos.z;
210 debug("Z: %d, %d", r3->pos.z - _starfieldPosition.z, cos(a2).multToInt(destDepth));
211
212 Angle angle = atan2(deltaX, deltaZ);
213 r3->matrix = initSpeedMatrixForXZMovement(angle, initMatrix());
214
215 debugCN(5, kDebugSpace, "initIntroR3ObjectToMove: pos %x,%x,%x; ", r3->pos.x, r3->pos.y, r3->pos.z);
216
217 if (ticks != 0) {
218 debugC(5, kDebugSpace, "speed %x,%x,%x\n", r3->speed.x, r3->speed.y, r3->speed.z);
219 r3->speed.x = deltaX / ticks;
220 r3->speed.z = deltaZ / ticks;
221 r3->speed.y = 0;
222 } else {
223 debugC(5, kDebugSpace, "speed 0\n");
224 r3->speed.x = 0;
225 r3->speed.z = 0;
226 r3->speed.y = 0;
227 }
228 }
229
loadSubtitleSprite(int index,Sprite * sprite)230 void StarTrekEngine::loadSubtitleSprite(int index, Sprite *sprite) {
231 if (_showSubtitles) {
232 if (index == -1)
233 sprite->setBitmap(_gfx->loadBitmap("blank"));
234 else {
235 Common::String file = Common::String::format("tittxt%02d", index);
236 sprite->setBitmap(_gfx->loadBitmap(file));
237 }
238 }
239 }
240
241 } // End of namespace StarTrek
242