/
riven_external.cpp
2753 lines (2295 loc) · 85.3 KB
/
riven_external.cpp
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* 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/cursors.h"
#include "mohawk/graphics.h"
#include "mohawk/riven.h"
#include "mohawk/riven_external.h"
#include "mohawk/sound.h"
#include "mohawk/video.h"
#include "gui/message.h"
#include "common/events.h"
#include "common/system.h"
namespace Mohawk {
static const uint32 kDomeSliderDefaultState = 0x01F00000;
static const uint32 kDomeSliderSlotCount = 25;
RivenExternal::RivenExternal(MohawkEngine_Riven *vm) : _vm(vm) {
setupCommands();
_sliderState = kDomeSliderDefaultState;
}
RivenExternal::~RivenExternal() {
for (uint32 i = 0; i < _externalCommands.size(); i++)
delete _externalCommands[i];
_externalCommands.clear();
}
void RivenExternal::setupCommands() {
// aspit (Main Menu, Books, Setup) external commands
COMMAND(xastartupbtnhide);
COMMAND(xasetupcomplete);
COMMAND(xaatrusopenbook);
COMMAND(xaatrusbookback);
COMMAND(xaatrusbookprevpage);
COMMAND(xaatrusbooknextpage);
COMMAND(xacathopenbook);
COMMAND(xacathbookback);
COMMAND(xacathbookprevpage);
COMMAND(xacathbooknextpage);
COMMAND(xtrapbookback);
COMMAND(xatrapbookclose);
COMMAND(xatrapbookopen);
COMMAND(xarestoregame);
COMMAND(xadisablemenureturn);
COMMAND(xaenablemenureturn);
COMMAND(xalaunchbrowser);
COMMAND(xadisablemenuintro);
COMMAND(xaenablemenuintro);
COMMAND(xademoquit);
COMMAND(xaexittomain);
// bspit (Bookmaking Island) external commands
COMMAND(xblabopenbook);
COMMAND(xblabbookprevpage);
COMMAND(xblabbooknextpage);
COMMAND(xsoundplug);
COMMAND(xbchangeboiler);
COMMAND(xbupdateboiler);
COMMAND(xbsettrap);
COMMAND(xbcheckcatch);
COMMAND(xbait);
COMMAND(xbfreeytram);
COMMAND(xbaitplate);
COMMAND(xbisland190_opencard);
COMMAND(xbisland190_resetsliders);
COMMAND(xbisland190_slidermd);
COMMAND(xbisland190_slidermw);
COMMAND(xbscpbtn);
COMMAND(xbisland_domecheck);
COMMAND(xvalvecontrol);
COMMAND(xbchipper);
// gspit (Garden Island) external commands
COMMAND(xgresetpins);
COMMAND(xgrotatepins);
COMMAND(xgpincontrols);
COMMAND(xgisland25_opencard);
COMMAND(xgisland25_resetsliders);
COMMAND(xgisland25_slidermd);
COMMAND(xgisland25_slidermw);
COMMAND(xgscpbtn);
COMMAND(xgisland1490_domecheck);
COMMAND(xgplateau3160_dopools);
COMMAND(xgwt200_scribetime);
COMMAND(xgwt900_scribe);
COMMAND(xgplaywhark);
COMMAND(xgrviewer);
COMMAND(xgwharksnd);
COMMAND(xglview_prisonoff);
COMMAND(xglview_villageoff);
COMMAND(xglviewer);
COMMAND(xglview_prisonon);
COMMAND(xglview_villageon);
// jspit (Jungle Island) external commands
COMMAND(xreseticons);
COMMAND(xicon);
COMMAND(xcheckicons);
COMMAND(xtoggleicon);
COMMAND(xjtunnel103_pictfix);
COMMAND(xjtunnel104_pictfix);
COMMAND(xjtunnel105_pictfix);
COMMAND(xjtunnel106_pictfix);
COMMAND(xvga1300_carriage);
COMMAND(xjdome25_resetsliders);
COMMAND(xjdome25_slidermd);
COMMAND(xjdome25_slidermw);
COMMAND(xjscpbtn);
COMMAND(xjisland3500_domecheck);
COMMAND(xhandlecontroldown);
COMMAND(xhandlecontrolmid);
COMMAND(xhandlecontrolup);
COMMAND(xjplaybeetle_550);
COMMAND(xjplaybeetle_600);
COMMAND(xjplaybeetle_950);
COMMAND(xjplaybeetle_1050);
COMMAND(xjplaybeetle_1450);
COMMAND(xjlagoon700_alert);
COMMAND(xjlagoon800_alert);
COMMAND(xjlagoon1500_alert);
COMMAND(xschool280_playwhark);
COMMAND(xjschool280_resetleft);
COMMAND(xjschool280_resetright);
COMMAND(xjatboundary);
// ospit (Gehn's Office) external commands
COMMAND(xorollcredittime);
COMMAND(xbookclick);
COMMAND(xooffice30_closebook);
COMMAND(xobedroom5_closedrawer);
COMMAND(xogehnopenbook);
COMMAND(xogehnbookprevpage);
COMMAND(xogehnbooknextpage);
COMMAND(xgwatch);
// pspit (Prison Island) external commands
COMMAND(xpisland990_elevcombo);
COMMAND(xpscpbtn);
COMMAND(xpisland290_domecheck);
COMMAND(xpisland25_opencard);
COMMAND(xpisland25_resetsliders);
COMMAND(xpisland25_slidermd);
COMMAND(xpisland25_slidermw);
// rspit (Rebel Age) external commands
COMMAND(xrshowinventory);
COMMAND(xrhideinventory);
COMMAND(xrcredittime);
COMMAND(xrwindowsetup);
// tspit (Temple Island) external commands
COMMAND(xtexterior300_telescopedown);
COMMAND(xtexterior300_telescopeup);
COMMAND(xtisland390_covercombo);
COMMAND(xtatrusgivesbooks);
COMMAND(xtchotakesbook);
COMMAND(xthideinventory);
COMMAND(xt7500_checkmarbles);
COMMAND(xt7600_setupmarbles);
COMMAND(xt7800_setup);
COMMAND(xdrawmarbles);
COMMAND(xtakeit);
COMMAND(xtscpbtn);
COMMAND(xtisland4990_domecheck);
COMMAND(xtisland5056_opencard);
COMMAND(xtisland5056_resetsliders);
COMMAND(xtisland5056_slidermd);
COMMAND(xtisland5056_slidermw);
COMMAND(xtatboundary);
// Common external commands
COMMAND(xflies);
}
void RivenExternal::runCommand(uint16 argc, uint16 *argv) {
Common::String externalCommandName = _vm->getName(ExternalCommandNames, argv[0]);
for (uint16 i = 0; i < _externalCommands.size(); i++)
if (externalCommandName == _externalCommands[i]->desc) {
debug(0, "Running Riven External Command \'%s\'", externalCommandName.c_str());
(this->*(_externalCommands[i]->proc)) (argv[1], argv[1] ? argv + 2 : NULL);
return;
}
error("Unknown external command \'%s\'", externalCommandName.c_str());
}
void RivenExternal::runDemoBoundaryDialog() {
GUI::MessageDialog dialog("Exploration beyond this point available only within the full version of\n"
"the game.");
dialog.runModal();
}
void RivenExternal::runEndGame(uint16 video, uint32 delay) {
_vm->_sound->stopAllSLST();
_vm->_video->playMovieRiven(video);
runCredits(video, delay);
}
void RivenExternal::runCredits(uint16 video, uint32 delay) {
// Initialize our credits state
_vm->_cursor->hideCursor();
_vm->_gfx->beginCredits();
uint nextCreditsFrameStart = 0;
VideoHandle videoHandle = _vm->_video->findVideoHandleRiven(video);
while (!_vm->shouldQuit() && _vm->_gfx->getCurCreditsImage() <= 320) {
if (_vm->_video->getCurFrame(videoHandle) >= (int32)_vm->_video->getFrameCount(videoHandle) - 1) {
if (nextCreditsFrameStart == 0) {
// Set us up to start after delay ms
nextCreditsFrameStart = _vm->_system->getMillis() + delay;
} else if (_vm->_system->getMillis() >= nextCreditsFrameStart) {
// the first two frames stay on for 5 seconds
// the rest of the scroll updates happen at 30Hz
if (_vm->_gfx->getCurCreditsImage() < 304)
nextCreditsFrameStart = _vm->_system->getMillis() + 5000;
else
nextCreditsFrameStart = _vm->_system->getMillis() + 1000 / 30;
_vm->_gfx->updateCredits();
}
} else if (_vm->_video->updateMovies())
_vm->_system->updateScreen();
Common::Event event;
while (_vm->_system->getEventManager()->pollEvent(event))
;
_vm->_system->delayMillis(10);
}
_vm->setGameOver();
}
void RivenExternal::runDomeButtonMovie() {
// This command just plays the video of the button moving down and up.
_vm->_video->playMovieBlockingRiven(2);
}
void RivenExternal::runDomeCheck() {
// Check if we clicked while the golden frame was showing
VideoHandle video = _vm->_video->findVideoHandleRiven(1);
assert(video != NULL_VID_HANDLE);
int32 curFrame = _vm->_video->getCurFrame(video);
int32 frameCount = _vm->_video->getFrameCount(video);
// The final frame of the video is the 'golden' frame (double meaning: the
// frame that is the magic one is the one with the golden symbol) but we
// give a 3 frame leeway in either direction.
if (frameCount - curFrame < 3 || curFrame < 3)
_vm->_vars["domecheck"] = 1;
}
void RivenExternal::resetDomeSliders(uint16 soundId, uint16 startHotspot) {
// The rightmost slider should move left until it finds the next slider,
// then those two continue until they find the third slider. This continues
// until all five sliders have returned their starting slots.
byte slidersFound = 0;
for (uint32 i = 0; i < kDomeSliderSlotCount; i++) {
if (_sliderState & (1 << i)) {
// A slider occupies this spot. Increase the number of sliders we
// have found, but we're not doing any moving this iteration.
slidersFound++;
} else {
// Move all the sliders we have found over one slot
for (byte j = 0; j < slidersFound; j++) {
_sliderState &= ~(1 << (i - j - 1));
_sliderState |= 1 << (i - j);
}
// If we have at least one found slider, it has now moved
// so we should redraw and play a tick sound
if (slidersFound) {
_vm->_sound->playSound(soundId);
drawDomeSliders(startHotspot);
_vm->_system->delayMillis(100);
}
}
}
// Sanity checks - the slider count should always be 5 and we should end up at
// the default state after moving them all over.
assert(slidersFound == 5);
assert(_sliderState == kDomeSliderDefaultState);
}
void RivenExternal::checkDomeSliders(uint16 resetSlidersHotspot, uint16 openDomeHotspot) {
// Let's see if we're all matched up...
if (_vm->_vars["adomecombo"] == _sliderState) {
// Set the button hotspot to the open dome hotspot
_vm->_hotspots[resetSlidersHotspot].enabled = false;
_vm->_hotspots[openDomeHotspot].enabled = true;
} else {
// Set the button hotspot to the reset sliders hotspot
_vm->_hotspots[resetSlidersHotspot].enabled = true;
_vm->_hotspots[openDomeHotspot].enabled = false;
}
}
void RivenExternal::checkSliderCursorChange(uint16 startHotspot) {
// Set the cursor based on _sliderState and what hotspot we're over
for (uint16 i = 0; i < kDomeSliderSlotCount; i++) {
if (_vm->_hotspots[i + startHotspot].rect.contains(_vm->_system->getEventManager()->getMousePos())) {
if (_sliderState & (1 << (24 - i)))
_vm->_cursor->setCursor(kRivenOpenHandCursor);
else
_vm->_cursor->setCursor(kRivenMainCursor);
_vm->_system->updateScreen();
break;
}
}
}
void RivenExternal::dragDomeSlider(uint16 soundId, uint16 resetSlidersHotspot, uint16 openDomeHotspot, uint16 startHotspot) {
int16 foundSlider = -1;
for (uint16 i = 0; i < kDomeSliderSlotCount; i++) {
if (_vm->_hotspots[i + startHotspot].rect.contains(_vm->_system->getEventManager()->getMousePos())) {
// If the slider is not at this hotspot, we can't do anything else
if (!(_sliderState & (1 << (24 - i))))
return;
foundSlider = i;
break;
}
}
// We're not over any slider
if (foundSlider < 0)
return;
// We've clicked down, so show the closed hand cursor
_vm->_cursor->setCursor(kRivenClosedHandCursor);
_vm->_system->updateScreen();
bool done = false;
while (!done) {
Common::Event event;
while (_vm->_system->getEventManager()->pollEvent(event)) {
switch (event.type) {
case Common::EVENT_MOUSEMOVE:
if (foundSlider < 24 && !(_sliderState & (1 << (23 - foundSlider))) && _vm->_hotspots[foundSlider + startHotspot + 1].rect.contains(event.mouse)) {
// We've moved the slider right one space
_sliderState &= ~(_sliderState & (1 << (24 - foundSlider)));
foundSlider++;
_sliderState |= 1 << (24 - foundSlider);
// Now play a click sound and redraw
_vm->_sound->playSound(soundId);
drawDomeSliders(startHotspot);
} else if (foundSlider > 0 && !(_sliderState & (1 << (25 - foundSlider))) && _vm->_hotspots[foundSlider + startHotspot - 1].rect.contains(event.mouse)) {
// We've moved the slider left one space
_sliderState &= ~(_sliderState & (1 << (24 - foundSlider)));
foundSlider--;
_sliderState |= 1 << (24 - foundSlider);
// Now play a click sound and redraw
_vm->_sound->playSound(soundId);
drawDomeSliders(startHotspot);
} else
_vm->_system->updateScreen(); // A normal update for the cursor
break;
case Common::EVENT_LBUTTONUP:
done = true;
break;
default:
break;
}
}
_vm->_system->delayMillis(10);
}
// Check to see if we have the right combination
checkDomeSliders(resetSlidersHotspot, openDomeHotspot);
}
void RivenExternal::drawDomeSliders(uint16 startHotspot) {
Common::Rect dstAreaRect = Common::Rect(200, 250, 420, 319);
// On pspit, the rect is different by two pixels
// (alternatively, we could just use hotspot 3 here, but only on pspit is there a hotspot for this)
if (_vm->getCurStack() == pspit)
dstAreaRect.translate(-2, 0);
// Find out bitmap id
uint16 bitmapId = _vm->findResourceID(ID_TBMP, "*sliders*");
for (uint16 i = 0; i < kDomeSliderSlotCount; i++) {
Common::Rect srcRect = _vm->_hotspots[startHotspot + i].rect;
srcRect.translate(-dstAreaRect.left, -dstAreaRect.top); // Adjust the rect so it's in the destination area
Common::Rect dstRect = _vm->_hotspots[startHotspot + i].rect;
if (_sliderState & (1 << (24 - i)))
_vm->_gfx->drawImageRect(bitmapId, srcRect, dstRect);
else
_vm->_gfx->drawImageRect(bitmapId + 1, srcRect, dstRect);
}
_vm->_gfx->updateScreen();
}
// ------------------------------------------------------------------------------------
// aspit (Main Menu, Books, Setup) external commands
// ------------------------------------------------------------------------------------
void RivenExternal::xastartupbtnhide(uint16 argc, uint16 *argv) {
// The original game hides the start/setup buttons depending on an ini entry.
// It's safe to ignore this command.
}
void RivenExternal::xasetupcomplete(uint16 argc, uint16 *argv) {
// The original game sets an ini entry to disable the setup button and use the
// start button only. It's safe to ignore this part of the command.
_vm->_sound->stopSound();
_vm->changeToCard(1);
}
void RivenExternal::xaatrusopenbook(uint16 argc, uint16 *argv) {
// Get the variable
uint32 &page = _vm->_vars["aatruspage"];
// Set hotspots depending on the page
if (page == 1) {
_vm->_hotspots[1].enabled = false;
_vm->_hotspots[2].enabled = false;
_vm->_hotspots[3].enabled = true;
} else {
_vm->_hotspots[1].enabled = true;
_vm->_hotspots[2].enabled = true;
_vm->_hotspots[3].enabled = false;
}
// Draw the image of the page
_vm->_gfx->drawPLST(page);
}
void RivenExternal::xaatrusbookback(uint16 argc, uint16 *argv) {
// Return to where we were before entering the book
_vm->changeToStack(_vm->_vars["returnstackid"]);
_vm->changeToCard(_vm->_vars["returncardid"]);
}
void RivenExternal::xaatrusbookprevpage(uint16 argc, uint16 *argv) {
// Get the page variable
uint32 &page = _vm->_vars["aatruspage"];
// Decrement the page if it's not the first page
if (page == 1)
return;
page--;
// Play the page turning sound
if (_vm->getFeatures() & GF_DEMO)
_vm->_sound->playSound(4);
else
_vm->_sound->playSound(3);
// Now update the screen :)
_vm->_gfx->scheduleTransition(1);
_vm->_gfx->updateScreen();
}
void RivenExternal::xaatrusbooknextpage(uint16 argc, uint16 *argv) {
// Get the page variable
uint32 &page = _vm->_vars["aatruspage"];
// Increment the page if it's not the last page
if (((_vm->getFeatures() & GF_DEMO) && page == 6) || page == 10)
return;
page++;
// Play the page turning sound
if (_vm->getFeatures() & GF_DEMO)
_vm->_sound->playSound(5);
else
_vm->_sound->playSound(4);
// Now update the screen :)
_vm->_gfx->scheduleTransition(0);
_vm->_gfx->updateScreen();
}
void RivenExternal::xacathopenbook(uint16 argc, uint16 *argv) {
// Get the variable
uint32 page = _vm->_vars["acathpage"];
// Set hotspots depending on the page
if (page == 1) {
_vm->_hotspots[1].enabled = false;
_vm->_hotspots[2].enabled = false;
_vm->_hotspots[3].enabled = true;
} else {
_vm->_hotspots[1].enabled = true;
_vm->_hotspots[2].enabled = true;
_vm->_hotspots[3].enabled = false;
}
// Draw the image of the page
_vm->_gfx->drawPLST(page);
// Draw the white page edges
if (page > 1 && page < 5)
_vm->_gfx->drawPLST(50);
else if (page > 5)
_vm->_gfx->drawPLST(51);
if (page == 28) {
// Draw the telescope combination
// The images for the numbers are tBMP's 13 through 17.
// The start point is at (156, 247)
uint32 teleCombo = _vm->_vars["tcorrectorder"];
static const uint16 kNumberWidth = 32;
static const uint16 kNumberHeight = 25;
static const uint16 kDstX = 156;
static const uint16 kDstY = 247;
for (byte i = 0; i < 5; i++) {
uint16 offset = (getComboDigit(teleCombo, i) - 1) * kNumberWidth;
Common::Rect srcRect = Common::Rect(offset, 0, offset + kNumberWidth, kNumberHeight);
Common::Rect dstRect = Common::Rect(i * kNumberWidth + kDstX, kDstY, (i + 1) * kNumberWidth + kDstX, kDstY + kNumberHeight);
_vm->_gfx->drawImageRect(i + 13, srcRect, dstRect);
}
}
}
void RivenExternal::xacathbookback(uint16 argc, uint16 *argv) {
// Return to where we were before entering the book
_vm->changeToStack(_vm->_vars["returnstackid"]);
_vm->changeToCard(_vm->_vars["returncardid"]);
}
void RivenExternal::xacathbookprevpage(uint16 argc, uint16 *argv) {
// Get the variable
uint32 &page = _vm->_vars["acathpage"];
// Increment the page if it's not the first page
if (page == 1)
return;
page--;
// Play the page turning sound
_vm->_sound->playSound(5);
// Now update the screen :)
_vm->_gfx->scheduleTransition(3);
_vm->_gfx->updateScreen();
}
void RivenExternal::xacathbooknextpage(uint16 argc, uint16 *argv) {
// Get the variable
uint32 &page = _vm->_vars["acathpage"];
// Increment the page if it's not the last page
if (page == 49)
return;
page++;
// Play the page turning sound
_vm->_sound->playSound(6);
// Now update the screen :)
_vm->_gfx->scheduleTransition(2);
_vm->_gfx->updateScreen();
}
void RivenExternal::xtrapbookback(uint16 argc, uint16 *argv) {
// Return to where we were before entering the book
_vm->_vars["atrap"] = 0;
_vm->changeToStack(_vm->_vars["returnstackid"]);
_vm->changeToCard(_vm->_vars["returncardid"]);
}
void RivenExternal::xatrapbookclose(uint16 argc, uint16 *argv) {
// Close the trap book
_vm->_vars["atrap"] = 0;
// Play the page turning sound
_vm->_sound->playSound(8);
_vm->refreshCard();
}
void RivenExternal::xatrapbookopen(uint16 argc, uint16 *argv) {
// Open the trap book
_vm->_vars["atrap"] = 1;
// Play the page turning sound
_vm->_sound->playSound(9);
_vm->refreshCard();
}
void RivenExternal::xarestoregame(uint16 argc, uint16 *argv) {
// Launch the load game dialog
_vm->runLoadDialog();
}
void RivenExternal::xadisablemenureturn(uint16 argc, uint16 *argv) {
// This function would normally enable the Windows menu item for
// returning to the main menu. Ctrl+r will do this instead.
// The original also had this shortcut.
}
void RivenExternal::xaenablemenureturn(uint16 argc, uint16 *argv) {
// This function would normally enable the Windows menu item for
// returning to the main menu. Ctrl+r will do this instead.
// The original also had this shortcut.
}
void RivenExternal::xalaunchbrowser(uint16 argc, uint16 *argv) {
// Well, we can't launch a browser for obvious reasons ;)
// The original text is as follows (for reference):
// If you have an auto-dial configured connection to the Internet,
// please select YES below.
//
// America Online and CompuServe users may experience difficulty. If
// you find that you are unable to connect, please quit the Riven
// Demo, launch your browser and type in the following URL:
//
// www.redorb.com/buyriven
//
// Would you like to attempt to make the connection?
//
// [YES] [NO]
GUI::MessageDialog dialog("At this point, the Riven Demo would\n"
"ask if you would like to open a web browser\n"
"to bring you to the Red Orb store to buy\n"
"the game. ScummVM cannot do that and\n"
"the site no longer exists.");
dialog.runModal();
}
void RivenExternal::xadisablemenuintro(uint16 argc, uint16 *argv) {
// This function would normally enable the Windows menu item for
// playing the intro. Ctrl+p will play the intro movies instead.
// The original also had this shortcut.
// Hide the "exit" button here
_vm->_gfx->hideInventory();
}
void RivenExternal::xaenablemenuintro(uint16 argc, uint16 *argv) {
// This function would normally enable the Windows menu item for
// playing the intro. Ctrl+p will play the intro movies instead.
// The original also had this shortcut.
// Show the "exit" button here
_vm->_gfx->showInventory();
}
void RivenExternal::xademoquit(uint16 argc, uint16 *argv) {
// Exactly as it says on the tin. In the demo, this function quits.
_vm->setGameOver();
}
void RivenExternal::xaexittomain(uint16 argc, uint16 *argv) {
// One could potentially implement this function, but there would be no
// point. This function is only used in the demo's aspit card 9 update
// screen script. However, card 9 is not accessible from the game without
// jumping to the card and there's nothing going on in the card so it
// never gets called. There's also no card 9 in the full game, so the
// functionality of this card was likely removed before release. The
// demo executable references some other external commands relating to
// setting and getting the volume, as well as drawing the volume. I'd
// venture to guess that this would have been some sort of options card
// replaced with the Windows/Mac API in the final product.
//
// Yeah, this function is just dummied and holds a big comment ;)
}
// ------------------------------------------------------------------------------------
// bspit (Bookmaking Island) external commands
// ------------------------------------------------------------------------------------
void RivenExternal::xblabopenbook(uint16 argc, uint16 *argv) {
// Get the variable
uint32 page = _vm->_vars["blabpage"];
// Draw the image of the page based on the blabbook variable
_vm->_gfx->drawPLST(page);
if (page == 14) {
// Draw the dome combination
// The images for the numbers are tBMP's 364 through 368
// The start point is at (240, 82)
uint32 domeCombo = _vm->_vars["adomecombo"];
static const uint16 kNumberWidth = 32;
static const uint16 kNumberHeight = 24;
static const uint16 kDstX = 240;
static const uint16 kDstY = 82;
byte numCount = 0;
for (int bitPos = 24; bitPos >= 0; bitPos--) {
if (domeCombo & (1 << bitPos)) {
uint16 offset = (24 - bitPos) * kNumberWidth;
Common::Rect srcRect = Common::Rect(offset, 0, offset + kNumberWidth, kNumberHeight);
Common::Rect dstRect = Common::Rect(numCount * kNumberWidth + kDstX, kDstY, (numCount + 1) * kNumberWidth + kDstX, kDstY + kNumberHeight);
_vm->_gfx->drawImageRect(numCount + 364, srcRect, dstRect);
numCount++;
}
}
assert(numCount == 5); // Sanity check
}
}
void RivenExternal::xblabbookprevpage(uint16 argc, uint16 *argv) {
// Get the page variable
uint32 &page = _vm->_vars["blabpage"];
// Decrement the page if it's not the first page
if (page == 1)
return;
page--;
// Play the page turning sound
_vm->_sound->playSound(22);
// Now update the screen :)
_vm->_gfx->scheduleTransition(1);
_vm->_gfx->updateScreen();
}
void RivenExternal::xblabbooknextpage(uint16 argc, uint16 *argv) {
// Get the page variable
uint32 &page = _vm->_vars["blabpage"];
// Increment the page if it's not the last page
if (page == 22)
return;
page++;
// Play the page turning sound
_vm->_sound->playSound(23);
// Now update the screen :)
_vm->_gfx->scheduleTransition(0);
_vm->_gfx->updateScreen();
}
void RivenExternal::xsoundplug(uint16 argc, uint16 *argv) {
if (_vm->_vars["bheat"] != 0)
_vm->_sound->playSLST(1, _vm->getCurCard());
else if (_vm->_vars["bcratergg"] != 0)
_vm->_sound->playSLST(2, _vm->getCurCard());
else
_vm->_sound->playSLST(3, _vm->getCurCard());
}
void RivenExternal::xbchangeboiler(uint16 argc, uint16 *argv) {
uint32 heat = _vm->_vars["bheat"];
uint32 water = _vm->_vars["bblrwtr"];
uint32 platform = _vm->_vars["bblrgrt"];
// Stop any background videos
_vm->_video->stopVideos();
if (argv[0] == 1) {
// Water is filling/draining from the boiler
if (water == 0) {
if (platform == 1)
_vm->_video->activateMLST(12, _vm->getCurCard());
else
_vm->_video->activateMLST(10, _vm->getCurCard());
} else if (heat == 1) {
if (platform == 1)
_vm->_video->activateMLST(22, _vm->getCurCard());
else
_vm->_video->activateMLST(19, _vm->getCurCard());
} else {
if (platform == 1)
_vm->_video->activateMLST(16, _vm->getCurCard());
else
_vm->_video->activateMLST(13, _vm->getCurCard());
}
} else if (argv[0] == 2 && water != 0) {
if (heat == 1) {
// Turning on the heat
if (platform == 1)
_vm->_video->activateMLST(23, _vm->getCurCard());
else
_vm->_video->activateMLST(20, _vm->getCurCard());
} else {
// Turning off the heat
if (platform == 1)
_vm->_video->activateMLST(18, _vm->getCurCard());
else
_vm->_video->activateMLST(15, _vm->getCurCard());
}
} else if (argv[0] == 3) {
if (platform == 1) {
// Lowering the platform
if (water == 1) {
if (heat == 1)
_vm->_video->activateMLST(24, _vm->getCurCard());
else
_vm->_video->activateMLST(17, _vm->getCurCard());
} else
_vm->_video->activateMLST(11, _vm->getCurCard());
} else {
// Raising the platform
if (water == 1) {
if (heat == 1)
_vm->_video->activateMLST(21, _vm->getCurCard());
else
_vm->_video->activateMLST(14, _vm->getCurCard());
} else
_vm->_video->activateMLST(9, _vm->getCurCard());
}
}
if (argc > 1)
_vm->_sound->playSLST(argv[1], _vm->getCurCard());
else if (argv[0] == 2)
_vm->_sound->playSLST(1, _vm->getCurCard());
_vm->_cursor->setCursor(kRivenHideCursor);
_vm->_video->playMovieBlockingRiven(11);
}
void RivenExternal::xbupdateboiler(uint16 argc, uint16 *argv) {
if (_vm->_vars["bheat"] != 0) {
if (_vm->_vars["bblrgrt"] == 0) {
_vm->_video->activateMLST(8, _vm->getCurCard());
_vm->_video->playMovieRiven(8);
} else {
_vm->_video->activateMLST(7, _vm->getCurCard());
_vm->_video->playMovieRiven(7);
}
} else {
_vm->_video->disableMovieRiven(7);
_vm->_video->disableMovieRiven(8);
}
}
static void ytramTrapTimer(MohawkEngine_Riven *vm) {
// Remove this timer
vm->removeTimer();
// Check if we've caught a Ytram
vm->_externalScriptHandler->checkYtramCatch(true);
}
void RivenExternal::xbsettrap(uint16 argc, uint16 *argv) {
// Set the Ytram trap
// We can catch the Ytram between 10 seconds and 3 minutes from now
uint32 timeUntilCatch = _vm->_rnd->getRandomNumberRng(10, 60 * 3) * 1000;
_vm->_vars["bytramtime"] = timeUntilCatch + _vm->getTotalPlayTime();
// And set the timer too
_vm->installTimer(&ytramTrapTimer, timeUntilCatch);
}
void RivenExternal::checkYtramCatch(bool playSound) {
// Check if we've caught a Ytram
uint32 &ytramTime = _vm->_vars["bytramtime"];
// If the trap still has not gone off, reinstall our timer
// This is in case you set the trap, walked away, and returned
if (_vm->getTotalPlayTime() < ytramTime) {
_vm->installTimer(&ytramTrapTimer, ytramTime - _vm->getTotalPlayTime());
return;
}
// Increment the movie per catch (max = 3)
uint32 &ytramMovie = _vm->_vars["bytram"];
ytramMovie++;
if (ytramMovie > 3)
ytramMovie = 3;
// Reset variables
_vm->_vars["bytrapped"] = 1;
_vm->_vars["bbait"] = 0;
_vm->_vars["bytrap"] = 0;
ytramTime = 0;
// Play the capture sound, if requested
if (playSound)
_vm->_sound->playSound(33);
}
void RivenExternal::xbcheckcatch(uint16 argc, uint16 *argv) {
// Just pass our parameter along...
checkYtramCatch(argv[0] != 0);
}
void RivenExternal::xbait(uint16 argc, uint16 *argv) {
// Set the cursor to the pellet
_vm->_cursor->setCursor(kRivenPelletCursor);
_vm->_system->updateScreen();
// Loop until the player lets go (or quits)
Common::Event event;
bool mouseDown = true;
while (mouseDown) {
while (_vm->_system->getEventManager()->pollEvent(event)) {
if (event.type == Common::EVENT_LBUTTONUP)
mouseDown = false;
else if (event.type == Common::EVENT_MOUSEMOVE)
_vm->_system->updateScreen();
else if (event.type == Common::EVENT_QUIT || event.type == Common::EVENT_RTL)
return;
}
_vm->_system->delayMillis(10); // Take it easy on the CPU
}
// Set back the cursor
_vm->_cursor->setCursor(kRivenMainCursor);
_vm->_system->updateScreen();
// Set the bait if we put it on the plate
if (_vm->_hotspots[9].rect.contains(_vm->_system->getEventManager()->getMousePos())) {
_vm->_vars["bbait"] = 1;
_vm->_gfx->drawPLST(4);
_vm->_gfx->updateScreen();
_vm->_hotspots[3].enabled = false; // Disable bait hotspot
_vm->_hotspots[9].enabled = true; // Enable baitplate hotspot
}
}
void RivenExternal::xbfreeytram(uint16 argc, uint16 *argv) {
// Play a random Ytram movie after freeing it
uint16 mlstId;
switch (_vm->_vars["bytram"]) {
case 1:
mlstId = 11;
break;
case 2:
mlstId = 12;
break;
default:
mlstId = _vm->_rnd->getRandomNumberRng(13, 15);
break;
}
// Activate the MLST and play the video
_vm->_video->activateMLST(mlstId, _vm->getCurCard());
_vm->_video->playMovieBlockingRiven(11);
// Now play the second movie
_vm->_video->activateMLST(mlstId + 5, _vm->getCurCard());
_vm->_video->playMovieBlockingRiven(12);
}
void RivenExternal::xbaitplate(uint16 argc, uint16 *argv) {
// Remove the pellet from the plate and put it in your hand
_vm->_gfx->drawPLST(3);
_vm->_cursor->setCursor(kRivenPelletCursor);
_vm->_gfx->updateScreen();
// Loop until the player lets go (or quits)
Common::Event event;
bool mouseDown = true;
while (mouseDown) {
while (_vm->_system->getEventManager()->pollEvent(event)) {
if (event.type == Common::EVENT_LBUTTONUP)
mouseDown = false;
else if (event.type == Common::EVENT_MOUSEMOVE)
_vm->_system->updateScreen();
else if (event.type == Common::EVENT_QUIT || event.type == Common::EVENT_RTL)
return;
}
_vm->_system->delayMillis(10); // Take it easy on the CPU
}
// Set back the cursor