/
sequences_hof.cpp
3515 lines (2884 loc) · 94 KB
/
sequences_hof.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 "kyra/kyra_hof.h"
#include "kyra/screen_hof.h"
#include "kyra/screen_lol.h"
#include "kyra/resource.h"
#include "kyra/sound.h"
#include "kyra/sequences_hof.h"
#include "kyra/timer.h"
#include "common/system.h"
namespace Kyra {
enum SequenceID {
kSequenceNoLooping = -1,
kSequenceVirgin = 0,
kSequenceWestwood,
kSequenceTitle,
kSequenceOverview,
kSequenceLibrary,
kSequenceHand,
kSequencePoint,
kSequenceZanfaun,
kSequenceFunters,
kSequenceFerb,
kSequenceFish,
kSequenceFheep,
kSequenceFarmer,
kSequenceFuards,
kSequenceFirates,
kSequenceFrash,
kSequenceHoFDemoVirgin,
kSequenceHoFDemoWestwood,
kSequenceHoFDemoTitle,
kSequenceHoFDemoHill,
kSequenceHoFDemoOuthome,
kSequenceHoFDemoWharf,
kSequenceHoFDemoDinob,
kSequenceHoFDemoFisher,
// The following enums remain active even if LoL is disabled
kSequenceLoLDemoScene1,
kSequenceLoLDemoText1,
kSequenceLoLDemoScene2,
kSequenceLoLDemoText2,
kSequenceLoLDemoScene3,
kSequenceLoLDemoText3,
kSequenceLoLDemoScene4,
kSequenceLoLDemoText4,
kSequenceLoLDemoScene5,
kSequenceLoLDemoText5,
kSequenceLoLDemoScene6,
kSequenceArraySize
};
enum NestedSequenceID {
kNestedSequenceFiggle = 0,
kNestedSequenceOver1,
kNestedSequenceOver2,
kNestedSequenceForest,
kNestedSequenceDragon,
kNestedSequenceDarm,
kNestedSequenceLibrary2,
kNestedSequenceLibrary3,
kNestedSequenceMarco,
kNestedSequenceHand1a,
kNestedSequenceHand1b,
kNestedSequenceHand1c,
kNestedSequenceHand2,
kNestedSequenceHand3,
kNestedSequenceHand4,
kNestedSequenceHoFDemoWharf2,
kNestedSequenceHoFDemoDinob2,
kNestedSequenceHoFDemoWater,
kNestedSequenceHoFDemoBail,
kNestedSequenceHoFDemoDig,
kNestedSequenceArraySize
};
typedef int (SeqPlayer_HOF::*SeqProc)(WSAMovie_v2 *, int, int, int);
struct SeqPlayerConfig {
SeqPlayerConfig(const HoFSeqData *data, const SeqProc *callbacks, const SeqProc *nestedCallbacks) : seq(data->seq), seqProc(callbacks), numSeq(data->numSeq), nestedSeq(data->nestedSeq), nestedSeqProc(nestedCallbacks), numNestedSeq(data->numNestedSeq) {}
const HoFSequence *seq;
const SeqProc *seqProc;
int numSeq;
const HoFNestedSequence *nestedSeq;
const SeqProc *nestedSeqProc;
int numNestedSeq;
};
class SeqPlayer_HOF {
public:
SeqPlayer_HOF(KyraEngine_v1 *vm, Screen_v2 *screen, OSystem *system, bool startupSaveLoadable = false);
~SeqPlayer_HOF();
int play(SequenceID firstScene, SequenceID loopStartScene);
void pause(bool toggle);
static SeqPlayer_HOF *instance() { return _instance; }
private:
// Init
void setupCallbacks();
// Playback loop
void runLoop();
void playScenes();
bool checkAbortPlayback();
bool checkPlaybackStatus();
bool _abortRequested;
uint32 _pauseStart;
// Sequence transitions
void doTransition(int type);
void nestedFrameAnimTransition(int srcPage, int dstPage, int delaytime, int steps, int x, int y, int w, int h, int openClose, int directionFlags);
void nestedFrameFadeTransition(const char *cmpFile);
// Animations
void playAnimation(WSAMovie_v2 *wsaObj, int startFrame, int numFrames, int frameRate, int x, int y, const SeqProc callback, Palette *fadePal1, Palette *fadePal2, int fadeRate, bool restoreScreen);
void playDialogueAnimation(uint16 strID, uint16 soundID, int textColor, int textPosX, int textPosY, int textWidth, WSAMovie_v2 *wsaObj, int animStartFrame, int animLastFrame, int animPosX, int animPosY);
void startNestedAnimation(int animSlot, int sequenceID);
void closeNestedAnimation(int animSlot);
void unloadNestedAnimation(int animSlot);
void doNestedFrameTransition(int transitionType, int animSlot);
void updateAllNestedAnimations();
bool updateNestedAnimation(int animSlot);
struct AnimSlot {
SeqProc callback;
WSAMovie_v2 *movie;
const FrameControl *control;
int16 flags;
uint16 startFrame;
uint16 endFrame;
uint16 frameDelay;
uint32 nextFrame;
uint16 currentFrame;
uint16 lastFrame;
uint16 x;
uint16 y;
uint16 fadeInTransitionType;
uint16 fadeOutTransitionType;
};
AnimSlot _animSlots[8];
bool _updateAnimations;
uint32 _animDuration;
int _animCurrentFrame;
int _callbackCurrentFrame;
// The only reason to declare these here (instead of just locally) is being able to increase them after pausing the Engine
uint32 _specialAnimTimeOutTotal;
uint32 _specialAnimFrameTimeOut;
// Subtitles/Dialogue/Sound
void playSoundEffect(uint16 id, int16 vol);
void playSoundAndDisplaySubTitle(uint16 id);
void printFadingText(uint16 strID, int x, int y, const uint8 *colorMap, uint8 textcolor);
int displaySubTitle(uint16 strID, uint16 posX, uint16 posY, int duration, uint16 width);
void updateSubTitles();
char *preprocessString(const char *str, int width);
void waitForSubTitlesTimeout();
uint32 ticksTillSubTitlesTimeout();
void resetAllTextSlots();
void fadeOutMusic();
struct TextSlot {
uint16 strIndex;
uint16 x;
uint16 y;
uint16 width;
int32 duration;
uint32 startTime;
int16 textcolor;
};
TextSlot _textSlots[10];
char *_tempString;
uint8 _textColor[2];
uint8 _textColorMap[16];
int _textDuration[33];
const char *const *_sequenceStrings;
const char *const *_sequenceSoundList;
int _sequenceSoundListSize;
static const uint8 _textColorPresets[];
// HOF credits
void playHoFTalkieCredits();
void displayHoFTalkieScrollText(uint8 *data, const ScreenDim *d, int tempPage1, int tempPage2, int speed, int step, Screen::FontId fid1, Screen::FontId fid2, const uint8 *shapeData = 0, const char *const *specialData = 0);
bool _talkieFinaleExtraFlag;
// HOF+LOL demo specific
void updateDemoAdText(int bottom, int top);
ActiveItemAnim _hofDemoActiveItemAnim[5];
const HoFSeqItemAnimData *_hofDemoAnimData;
uint32 _fisherAnimCurTime;
int _scrollProgressCounter;
uint8 *_hofDemoShapeData;
uint8 *_hofDemoItemShapes[20];
// Misc
void delayTicks(uint32 ticks);
void delayUntil(uint32 dest);
void setCountDown(uint32 ticks);
bool countDownRunning();
uint32 _countDownRemainder;
uint32 _countDownLastUpdate;
enum SeqPlayerTargetInfo {
kHoF = 0,
kHoFDemo,
kLoLDemo
};
SeqPlayerTargetInfo _target;
int _firstScene, _loopStartScene, _curScene, _preventSkipBeforeScene, _lastScene;
bool _startupSaveLoadable, _isFinale, _preventLooping;
SeqPlayerConfig *_config;
MainMenu *_menu;
int _result;
bool _abortPlayback;
KyraEngine_v1 *_vm;
Screen_v2 *_screen;
// We might consider getting rid of Screen_HoF, since there are only 2 methods left in that class anyway
Screen_HoF *_screenHoF;
OSystem *_system;
static SeqPlayer_HOF *_instance;
private:
// Sequence specific callback functions
int cbHOF_westwood(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_title(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_overview(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_library(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_hand(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_point(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_zanfaun(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_over1(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_over2(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_forest(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_dragon(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_darm(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_library2(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_marco(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_hand1a(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_hand1b(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_hand1c(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_hand2(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_hand3(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_funters(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_ferb(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_fish(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_fheep(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_farmer(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_fuards(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_firates(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_frash(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOF_figgle(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOFDEMO_virgin(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOFDEMO_westwood(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOFDEMO_title(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOFDEMO_hill(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOFDEMO_outhome(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOFDEMO_wharf(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOFDEMO_dinob(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOFDEMO_fisher(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOFDEMO_wharf2(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOFDEMO_dinob2(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOFDEMO_water(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOFDEMO_bail(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbHOFDEMO_dig(WSAMovie_v2 *wsaObj, int x, int y, int frm);
#ifdef ENABLE_LOL
int cbLOLDEMO_scene1(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbLOLDEMO_scene2(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbLOLDEMO_scene3(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbLOLDEMO_scene4(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbLOLDEMO_scene5(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbLOLDEMO_text5(WSAMovie_v2 *wsaObj, int x, int y, int frm);
int cbLOLDEMO_scene6(WSAMovie_v2 *wsaObj, int x, int y, int frm);
#endif // ENABLE_LOL
};
SeqPlayer_HOF *SeqPlayer_HOF::_instance = 0;
SeqPlayer_HOF::SeqPlayer_HOF(KyraEngine_v1 *vm, Screen_v2 *screen, OSystem *system, bool startupSaveLoadable) : _vm(vm), _screen(screen), _system(system), _startupSaveLoadable(startupSaveLoadable) {
// We use a static pointer for pauseEngine functionality. Since we don't
// ever need more than one SeqPlayer_HOF object at the same time we keep
// this simple and just add an assert to detect typos, regressions, etc.
assert(_instance == 0);
memset(_animSlots, 0, sizeof(_animSlots));
memset(_textSlots, 0, sizeof(_textSlots));
memset(_hofDemoActiveItemAnim, 0, sizeof(_hofDemoActiveItemAnim));
_screenHoF = _vm->game() == GI_KYRA2 ? (Screen_HoF*)screen : 0;
_config = 0;
_result = 0;
_sequenceSoundList = 0;
_hofDemoAnimData = 0;
_hofDemoShapeData = 0;
_isFinale = false;
_preventLooping = false;
_menu = 0;
_abortRequested = false;
_pauseStart = 0;
_updateAnimations = false;
_animDuration = 0;
_animCurrentFrame = 0;
_callbackCurrentFrame = 0;
_abortPlayback = false;
_curScene = 0;
_preventSkipBeforeScene = -1;
_lastScene = 0;
_scrollProgressCounter = 0;
_fisherAnimCurTime = 0;
_tempString = new char[200];
_countDownRemainder = 0;
_countDownLastUpdate = 0;
int tempSize = 0;
_vm->resource()->unloadAllPakFiles();
_vm->resource()->loadPakFile(StaticResource::staticDataFilename());
const char *const *files = _vm->staticres()->loadStrings(k2SeqplayPakFiles, tempSize);
_vm->resource()->loadFileList(files, tempSize);
_sequenceStrings = _vm->staticres()->loadStrings(k2SeqplayStrings, tempSize);
uint8 multiplier = (_vm->gameFlags().platform == Common::kPlatformFMTowns || _vm->gameFlags().platform == Common::kPlatformPC98) ? 12 : 8;
for (int i = 0; i < MIN(33, tempSize); i++)
_textDuration[i] = (int) strlen(_sequenceStrings[i]) * multiplier;
if (_sequenceSoundList) {
for (int i = 0; i < _sequenceSoundListSize; i++) {
if (_sequenceSoundList[i])
delete[] _sequenceSoundList[i];
}
delete[] _sequenceSoundList;
_sequenceSoundList = 0;
}
const char *const *seqSoundList = _vm->staticres()->loadStrings(k2SeqplaySfxFiles, _sequenceSoundListSize);
// replace sequence talkie files with localized versions
const char *const *tlkfiles = _vm->staticres()->loadStrings(k2SeqplayTlkFiles, tempSize);
char **tmpSndLst = new char *[_sequenceSoundListSize];
for (int i = 0; i < _sequenceSoundListSize; i++) {
const int len = strlen(seqSoundList[i]);
tmpSndLst[i] = new char[len + 1];
tmpSndLst[i][0] = 0;
if (tlkfiles && len > 1) {
for (int ii = 0; ii < tempSize; ii++) {
if (strlen(tlkfiles[ii]) > 1 && !scumm_stricmp(&seqSoundList[i][1], &tlkfiles[ii][1]))
strcpy(tmpSndLst[i], tlkfiles[ii]);
}
}
if (tmpSndLst[i][0] == 0)
strcpy(tmpSndLst[i], seqSoundList[i]);
}
tlkfiles = seqSoundList = 0;
_vm->staticres()->unloadId(k2SeqplayTlkFiles);
_vm->staticres()->unloadId(k2SeqplaySfxFiles);
_sequenceSoundList = tmpSndLst;
if (_vm->gameFlags().platform == Common::kPlatformPC98)
_vm->sound()->loadSoundFile("SOUND.DAT");
_screen->loadFont(_screen->FID_GOLDFONT_FNT, "GOLDFONT.FNT");
_screen->setFont(_vm->gameFlags().lang == Common::JA_JPN ? Screen::FID_SJIS_FNT : Screen::FID_GOLDFONT_FNT);
if (_vm->gameFlags().isDemo && !_vm->gameFlags().isTalkie) {
if (_vm->game() == GI_KYRA2) {
_hofDemoAnimData = _vm->staticres()->loadHoFSeqItemAnimData(k2SeqplayShapeAnimData, tempSize);
uint8 *shp = _vm->resource()->fileData("ICONS.SHP", 0);
uint32 outsize = READ_LE_UINT16(shp + 4);
_hofDemoShapeData = new uint8[outsize];
Screen::decodeFrame4(shp + 10, _hofDemoShapeData, outsize);
for (int i = 0; i < 20; i++)
_hofDemoItemShapes[i] = _screen->getPtrToShape(_hofDemoShapeData, i);
delete[] shp;
}
} else {
const MainMenu::StaticData data = {
{ _sequenceStrings[97], _sequenceStrings[96], _sequenceStrings[95], _sequenceStrings[98], 0 },
{ 0x01, 0x04, 0x0C, 0x04, 0x00, 0xD7, 0xD6 },
{ 0xD8, 0xDA, 0xD9, 0xD8 },
(_vm->gameFlags().lang == Common::JA_JPN) ? Screen::FID_SJIS_FNT : Screen::FID_8_FNT, 240
};
_menu = new MainMenu(_vm);
_menu->init(data, MainMenu::Animation());
}
_instance = this;
}
SeqPlayer_HOF::~SeqPlayer_HOF() {
_instance = 0;
if (_sequenceSoundList) {
for (int i = 0; i < _sequenceSoundListSize; i++) {
if (_sequenceSoundList[i])
delete[] _sequenceSoundList[i];
}
delete[] _sequenceSoundList;
_sequenceSoundList = NULL;
}
delete[] _tempString;
delete[] _hofDemoShapeData;
delete _menu;
if (_vm->game() != GI_LOL)
_screen->setFont(_vm->gameFlags().lang == Common::JA_JPN ? Screen::FID_SJIS_FNT : Screen::FID_8_FNT);
}
int SeqPlayer_HOF::play(SequenceID firstScene, SequenceID loopStartScene) {
bool incompatibleData = false;
AudioResourceSet soundSet = kMusicIntro;
_firstScene = firstScene;
_loopStartScene = loopStartScene;
_preventLooping = false;
_result = 0;
if (firstScene >= kSequenceArraySize || firstScene < kSequenceVirgin || loopStartScene >= kSequenceArraySize || loopStartScene < kSequenceNoLooping) {
return 0;
} else if (firstScene >= kSequenceLoLDemoScene1) {
#ifndef ENABLE_LOL
error("SeqPlayer_HOF::play(): The Lands of Lore sub engine (including this non-interactive demo) has been disabled in this build");
#endif
incompatibleData = (_vm->game() != GI_LOL);
_firstScene -= kSequenceLoLDemoScene1;
if (loopStartScene != kSequenceNoLooping)
_loopStartScene -= kSequenceLoLDemoScene1;
_lastScene = kSequenceLoLDemoScene6 - kSequenceLoLDemoScene1;
_target = kLoLDemo;
_screen->_charWidth = 0;
} else if (firstScene >= kSequenceHoFDemoVirgin) {
incompatibleData = (_vm->game() != GI_KYRA2 || !_vm->gameFlags().isDemo || _vm->gameFlags().isTalkie);
_firstScene -= kSequenceHoFDemoVirgin;
if (loopStartScene != kSequenceNoLooping)
_loopStartScene -= kSequenceHoFDemoVirgin;
_lastScene = kSequenceHoFDemoFisher - kSequenceHoFDemoVirgin;
_target = kHoFDemo;
_screen->_charWidth = -2;
} else {
_isFinale = _preventLooping = firstScene > kSequenceZanfaun;
incompatibleData = (_vm->game() != GI_KYRA2 || (_vm->gameFlags().isDemo && (!_vm->gameFlags().isTalkie || _isFinale)));
_target = kHoF;
_screen->_charWidth = -2;
if (_isFinale) {
soundSet = kMusicFinale;
_lastScene = kSequenceFrash;
} else {
_lastScene = kSequenceZanfaun;
}
}
if (incompatibleData)
error("SeqPlayer_HOF::play(): Specified sequences do not match the available sequence data for this target");
_vm->sound()->selectAudioResourceSet(soundSet);
_vm->sound()->loadSoundFile(0);
setupCallbacks();
runLoop();
return _result;
}
void SeqPlayer_HOF::pause(bool toggle) {
if (toggle) {
_pauseStart = _system->getMillis();
} else {
uint32 pausedTime = _system->getMillis() - _pauseStart;
_pauseStart = 0;
_countDownLastUpdate += pausedTime;
_fisherAnimCurTime += pausedTime;
_specialAnimTimeOutTotal += pausedTime;
_specialAnimFrameTimeOut += pausedTime;
for (int i = 0; i < 10; i++) {
if (_textSlots[i].duration != -1)
_textSlots[i].startTime += pausedTime;
}
for (int i = 0; i < 8; i++) {
if (_animSlots[i].flags != -1)
_animSlots[i].nextFrame += pausedTime;
}
}
}
void SeqPlayer_HOF::setupCallbacks() {
#define SCB(x) &SeqPlayer_HOF::cbHOF_##x
static const SeqProc seqCallbacksHoF[] = { 0, SCB(westwood), SCB(title), SCB(overview), SCB(library), SCB(hand), SCB(point), SCB(zanfaun), SCB(funters), SCB(ferb), SCB(fish), SCB(fheep), SCB(farmer), SCB(fuards), SCB(firates), SCB(frash) };
static const SeqProc nestedSeqCallbacksHoF[] = { SCB(figgle), SCB(over1), SCB(over2), SCB(forest), SCB(dragon), SCB(darm), SCB(library2), SCB(library2), SCB(marco), SCB(hand1a), SCB(hand1b), SCB(hand1c), SCB(hand2), SCB(hand3), 0 };
#undef SCB
#define SCB(x) &SeqPlayer_HOF::cbHOFDEMO_##x
static const SeqProc seqCallbacksHoFDemo[] = { SCB(virgin), SCB(westwood), SCB(title), SCB(hill), SCB(outhome), SCB(wharf), SCB(dinob), SCB(fisher) };
static const SeqProc nestedSeqCallbacksHoFDemo[] = { SCB(wharf2), SCB(dinob2), SCB(water), SCB(bail), SCB(dig), 0 };
#undef SCB
#ifdef ENABLE_LOL
#define SCB(x) &SeqPlayer_HOF::cbLOLDEMO_##x
static const SeqProc seqCallbacksLoLDemo[] = { SCB(scene1), 0, SCB(scene2), 0, SCB(scene3), 0, SCB(scene4), 0, SCB(scene5), SCB(text5), SCB(scene6), 0 };
#undef SCB
#else
static const SeqProc seqCallbacksLoLDemo[] = { 0 };
#endif
static const SeqProc nestedSeqCallbacksLoLDemo[] = { 0 };
static const SeqProc *const seqCallbacks[] = { seqCallbacksHoF, seqCallbacksHoFDemo, seqCallbacksLoLDemo};
static const SeqProc *const nestedSeqCallbacks[] = { nestedSeqCallbacksHoF, nestedSeqCallbacksHoFDemo, nestedSeqCallbacksLoLDemo};
int tmpSize = 0;
delete _config;
_config = new SeqPlayerConfig(_vm->staticres()->loadHoFSequenceData(k2SeqplaySeqData, tmpSize), seqCallbacks[_target], nestedSeqCallbacks[_target]);
}
void SeqPlayer_HOF::runLoop() {
memset(_animSlots, 0, sizeof(_animSlots));
memset(_textSlots, 0, sizeof(_textSlots));
memset(_hofDemoActiveItemAnim, 0, sizeof(_hofDemoActiveItemAnim));
for (int i = 0; i < 8; ++i)
_animSlots[i].flags = -1;
_screen->clearPage(10);
_screen->clearPage(12);
_screen->hideMouse();
int oldPage = _screen->setCurPage(2);
for (int i = 0; i < 4; ++i)
_screen->getPalette(i).clear();
_updateAnimations = false;
_animCurrentFrame = 0;
_textColor[0] = _textColor[1] = 0;
_curScene = _firstScene;
do {
playScenes();
doTransition(0);
resetAllTextSlots();
fadeOutMusic();
_firstScene = ((!_startupSaveLoadable || _preventLooping) && _curScene >= _loopStartScene) ? kSequenceNoLooping : _loopStartScene;
} while (!_vm->shouldQuit() && _firstScene != kSequenceNoLooping);
checkPlaybackStatus();
for (int i = 0; i < 8; i++)
unloadNestedAnimation(i);
if (_vm->gameFlags().isDemo && !_vm->gameFlags().isTalkie)
_screen->fadeToBlack();
else if (!_isFinale && !_startupSaveLoadable)
_result = 1;
if (!_result)
delayTicks(75);
_screen->setCurPage(oldPage);
_screen->_charWidth = 0;
_screen->showMouse();
}
void SeqPlayer_HOF::playScenes() {
_vm->sound()->stopAllSoundEffects();
_curScene = _firstScene;
_screen->copyPalette(1, 0);
WSAMovie_v2 anim(_vm);
_abortRequested = false;
_scrollProgressCounter = 0;
while (!_vm->shouldQuit()) {
if (checkAbortPlayback())
if (checkPlaybackStatus())
break;
_callbackCurrentFrame = 0;
if (_curScene > _lastScene)
break;
const Kyra::HoFSequence &sq = _config->seq[_curScene];
if (sq.flags & 2) {
_screen->loadBitmap(sq.cpsFile, 2, 2, &_screen->getPalette(0));
_screen->setScreenPalette(_screen->getPalette(0));
} else {
_screen->setCurPage(2);
_screen->clearPage(2);
_screen->loadPalette("GOLDFONT.COL", _screen->getPalette(0));
}
if (_config->seqProc[_curScene] && !(_vm->gameFlags().isDemo && !_vm->gameFlags().isTalkie))
(this->*_config->seqProc[_curScene])(0, 0, 0, -1);
if (sq.flags & 1) {
anim.open(sq.wsaFile, 0, &_screen->getPalette(0));
if (!(sq.flags & 2))
anim.displayFrame(0, 2, sq.xPos, sq.yPos, 0x4000, 0, 0);
}
if (sq.flags & 4) {
int cp = _screen->setCurPage(2);
Screen::FontId cf = _screen->setFont(_vm->gameFlags().lang == Common::JA_JPN ? Screen::FID_SJIS_FNT : Screen::FID_GOLDFONT_FNT);
if (sq.stringIndex1 != -1)
_screen->printText(_sequenceStrings[sq.stringIndex1], (320 - _screen->getTextWidth(_sequenceStrings[sq.stringIndex1])) / 2, 100 - _screen->getFontHeight(), 1, 0);
if (sq.stringIndex2 != -1)
_screen->printText(_sequenceStrings[sq.stringIndex2], (320 - _screen->getTextWidth(_sequenceStrings[sq.stringIndex2])) / 2, 100, 1, 0);
_screen->setFont(cf);
_screen->setCurPage(cp);
}
_screen->copyPage(2, 12);
_screen->copyPage(0, 2);
_screen->copyPage(2, 10);
_screen->copyPage(12, 2);
doTransition(sq.fadeInTransitionType);
if (!(checkAbortPlayback() || _vm->shouldQuit() || _result)) {
_screen->copyPage(2, 0);
_screen->updateScreen();
}
if (sq.flags & 1) {
playAnimation(&anim, sq.startFrame, sq.numFrames, sq.duration, sq.xPos, sq.yPos, _config->seqProc[_curScene], &_screen->getPalette(1), &_screen->getPalette(0), 30, 0);
anim.close();
} else {
_animDuration = sq.duration;
setCountDown(_animDuration);
while (!checkAbortPlayback() && !_vm->shouldQuit() && (countDownRunning() || _updateAnimations)) {
uint32 endFrame = (_system->getMillis() + _vm->tickLength()) & ~(_vm->tickLength() - 1);
updateAllNestedAnimations();
if (_config->seqProc[_curScene])
(this->*_config->seqProc[_curScene])(0, 0, 0, 0);
updateSubTitles();
_screen->copyPage(2, 0);
_screen->updateScreen();
_screen->copyPage(12, 2);
do {
if (checkAbortPlayback())
if (checkPlaybackStatus())
break;
} while (_system->getMillis() < endFrame);
}
}
if (_config->seqProc[_curScene] && !(_vm->gameFlags().isDemo && !_vm->gameFlags().isTalkie))
(this->*_config->seqProc[_curScene])(0, 0, 0, -2);
uint32 textTimeOut = ticksTillSubTitlesTimeout();
setCountDown(sq.timeout < textTimeOut ? textTimeOut : sq.timeout);
while (!checkAbortPlayback() && !_vm->shouldQuit() && (countDownRunning() || _updateAnimations)) {
updateAllNestedAnimations();
_screen->copyPage(2, 0);
_screen->updateScreen();
_screen->copyPage(12, 2);
}
doTransition(sq.fadeOutTransitionType);
_curScene++;
}
resetAllTextSlots();
_vm->sound()->haltTrack();
_vm->sound()->voiceStop();
if ((!checkAbortPlayback() || _vm->shouldQuit()) && _vm->gameFlags().isDemo)
_curScene = -1;
}
bool SeqPlayer_HOF::checkAbortPlayback() {
Common::Event event;
if (_vm->skipFlag()) {
_abortRequested = true;
_vm->resetSkipFlag();
}
if (_abortRequested)
return true;
while (_system->getEventManager()->pollEvent(event)) {
switch (event.type) {
case Common::EVENT_KEYDOWN:
if (event.kbd.keycode == Common::KEYCODE_q && event.kbd.hasFlags(Common::KBD_CTRL)) {
_abortRequested = true;
_vm->quitGame();
return true;
} else if (event.kbd.keycode != Common::KEYCODE_ESCAPE && event.kbd.keycode != Common::KEYCODE_RETURN && event.kbd.keycode != Common::KEYCODE_SPACE) {
continue;
}
// fall through
case Common::EVENT_LBUTTONDOWN:
case Common::EVENT_RBUTTONDOWN:
case Common::EVENT_LBUTTONUP:
case Common::EVENT_RBUTTONUP:
_abortRequested = true;
return true;
default:
break;
}
}
return false;
}
bool SeqPlayer_HOF::checkPlaybackStatus() {
_updateAnimations = false;
if (_curScene <= _preventSkipBeforeScene || (_curScene == _loopStartScene && !_isFinale)) {
_abortRequested = false;
return false;
}
if (_loopStartScene == kSequenceNoLooping) {
doTransition(0);
fadeOutMusic();
_abortPlayback = true;
}
return true;
}
void SeqPlayer_HOF::doTransition(int type) {
for (int i = 0; i < 8; i++)
closeNestedAnimation(i);
switch (type) {
case 0:
_screen->fadeToBlack(36);
_screen->getPalette(0).clear();
_screen->getPalette(1).clear();
break;
case 1:
playSoundAndDisplaySubTitle(_vm->_rnd.getRandomBit());
_screen->getPalette(0).fill(0, 256, 0x3F);
_screen->fadePalette(_screen->getPalette(0), 16);
_screen->copyPalette(1, 0);
break;
case 3:
_screen->copyPage(2, 0);
_screen->fadePalette(_screen->getPalette(0), 16);
_screen->copyPalette(1, 0);
break;
case 4:
_screen->copyPage(2, 0);
_screen->fadePalette(_screen->getPalette(0), 36);
_screen->copyPalette(1, 0);
break;
case 5:
_screen->copyPage(2, 0);
break;
case 6:
// UNUSED
// seq_loadBLD("library.bld");
break;
case 7:
// UNUSED
// seq_loadBLD("marco.bld");
break;
case 8:
_screen->fadeToBlack(16);
_screen->getPalette(0).clear();
_screen->getPalette(1).clear();
delayTicks(120);
break;
case 9: {
Palette &pal = _screen->getPalette(0);
for (int i = 0; i < 255; i++)
pal.fill(i, 1, (pal[3 * i] + pal[3 * i + 1] + pal[3 * i + 2]) / 3);
pal.fill(255, 1, 0x3F);
_screen->fadePalette(pal, 64);
_screen->copyPalette(1, 0);
} break;
default:
break;
}
}
void SeqPlayer_HOF::nestedFrameAnimTransition(int srcPage, int dstPage, int delaytime, int steps, int x, int y, int w, int h, int openClose, int directionFlags) {
if (openClose) {
for (int i = 1; i < steps; i++) {
uint32 endtime = _system->getMillis() + delaytime * _vm->tickLength();
int w2 = (((w * 256) / steps) * i) / 256;
int h2 = (((h * 256) / steps) * i) / 256;
int ym = (directionFlags & 2) ? (h - h2) : 0;
int xm = (directionFlags & 1) ? (w - w2) : 0;
_screen->wsaFrameAnimationStep(0, 0, x + xm, y + ym, w, h, w2, h2, srcPage, dstPage, 0);
_screen->copyPage(dstPage, 6);
_screen->copyPage(dstPage, 0);
_screen->updateScreen();
_screen->copyPage(12, dstPage);
delayUntil(endtime);
}
_screen->wsaFrameAnimationStep(0, 0, x, y, w, h, w, h, srcPage, dstPage, 0);
_screen->copyPage(dstPage, 6);
_screen->copyPage(dstPage, 0);
_screen->updateScreen();
} else {
_screen->copyPage(12, dstPage);
for (int i = steps; i; i--) {
uint32 endtime = _system->getMillis() + delaytime * _vm->tickLength();
int w2 = (((w * 256) / steps) * i) / 256;
int h2 = (((h * 256) / steps) * i) / 256;
int ym = (directionFlags & 2) ? (h - h2) : 0;
int xm = (directionFlags & 1) ? (w - w2) : 0;
_screen->wsaFrameAnimationStep(0, 0, x + xm, y + ym, w, h, w2, h2, srcPage, dstPage, 0);
_screen->copyPage(dstPage, 6);
_screen->copyPage(dstPage, 0);
_screen->updateScreen();
_screen->copyPage(12, dstPage);
delayUntil(endtime);
}
}
}
void SeqPlayer_HOF::nestedFrameFadeTransition(const char *cmpFile) {
_screen->copyPage(10, 2);
_screen->copyPage(4, 10);
_screen->clearPage(6);
_screen->loadBitmap(cmpFile, 6, 6, 0);
_screen->copyPage(12, 4);
for (int i = 0; i < 3; i++) {
uint32 endtime = _system->getMillis() + 4 * _vm->tickLength();
assert(_screenHoF);
_screenHoF->cmpFadeFrameStep(4, 320, 200, 0, 0, 2, 320, 200, 0, 0, 320, 200, 6);
_screen->copyRegion(0, 0, 0, 0, 320, 200, 2, 0);
_screen->updateScreen();
delayUntil(endtime);
}
_screen->copyPage(4, 0);
_screen->updateScreen();
_screen->copyPage(4, 2);
_screen->copyPage(4, 6);
_screen->copyPage(10, 4);
}
void SeqPlayer_HOF::playAnimation(WSAMovie_v2 *wsaObj, int startFrame, int lastFrame, int frameRate, int x, int y, const SeqProc callback, Palette *fadePal1, Palette *fadePal2, int fadeRate, bool restoreScreen) {
bool finished = false;
uint32 startTime = _system->getMillis();
int origW = wsaObj ? wsaObj->width() : 0;
int origH = wsaObj ? wsaObj->height() : 0;
int drwX = x;
int drwY = y;
int drwW = origW;
int drwH = origH;
_animDuration = frameRate;
if (wsaObj) {
if (x < 0) {
drwW += x;
drwX = 0;
}
if (y < 0) {
drwH += y;
drwY = 0;
}
if (x + origW > 319)
origW = 320 - x;
if (y + origH > 199)
origW = 200 - y;
}
int8 frameStep = (startFrame > lastFrame) ? -1 : 1;
_animCurrentFrame = startFrame;
while (!_vm->shouldQuit() && !finished) {
if (checkAbortPlayback())
if (checkPlaybackStatus())
break;
setCountDown(_animDuration);
if (wsaObj || callback)
_screen->copyPage(12, 2);
int frameIndex = _animCurrentFrame;
if (wsaObj)
frameIndex %= wsaObj->frames();
if (callback)
(this->*callback)(wsaObj, x, y, frameIndex);
if (wsaObj)
wsaObj->displayFrame(frameIndex, 2, x, y, 0, 0, 0);
_screen->copyPage(2, 12);
updateAllNestedAnimations();
updateSubTitles();
if ((wsaObj || callback) && (!(checkAbortPlayback() || _vm->shouldQuit() || _result))) {