-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathscript_v5.cpp
More file actions
3935 lines (3518 loc) · 125 KB
/
script_v5.cpp
File metadata and controls
3935 lines (3518 loc) · 125 KB
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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "scumm/actor.h"
#include "scumm/charset.h"
#include "scumm/object.h"
#include "scumm/resource.h"
#include "scumm/scumm_v3.h"
#include "scumm/scumm_v5.h"
#include "scumm/sound.h"
#include "scumm/players/player_towns.h"
#include "scumm/util.h"
#include "scumm/verbs.h"
#include "common/savefile.h"
#include "common/config-manager.h"
namespace Scumm {
#define OPCODE(i, x) _opcodes[i]._OPCODE(ScummEngine_v5, x)
void ScummEngine_v5::setupOpcodes() {
/* 00 */
OPCODE(0x00, o5_stopObjectCode);
OPCODE(0x01, o5_putActor);
OPCODE(0x02, o5_startMusic);
OPCODE(0x03, o5_getActorRoom);
/* 04 */
OPCODE(0x04, o5_isGreaterEqual);
OPCODE(0x05, o5_drawObject);
OPCODE(0x06, o5_getActorElevation);
OPCODE(0x07, o5_setState);
/* 08 */
OPCODE(0x08, o5_isNotEqual);
OPCODE(0x09, o5_faceActor);
OPCODE(0x0a, o5_startScript);
OPCODE(0x0b, o5_getVerbEntrypoint);
/* 0C */
OPCODE(0x0c, o5_resourceRoutines);
OPCODE(0x0d, o5_walkActorToActor);
OPCODE(0x0e, o5_putActorAtObject);
OPCODE(0x0f, o5_getObjectState);
/* 10 */
OPCODE(0x10, o5_getObjectOwner);
OPCODE(0x11, o5_animateActor);
OPCODE(0x12, o5_panCameraTo);
OPCODE(0x13, o5_actorOps);
/* 14 */
OPCODE(0x14, o5_print);
OPCODE(0x15, o5_actorFromPos);
OPCODE(0x16, o5_getRandomNr);
OPCODE(0x17, o5_and);
/* 18 */
OPCODE(0x18, o5_jumpRelative);
OPCODE(0x19, o5_doSentence);
OPCODE(0x1a, o5_move);
OPCODE(0x1b, o5_multiply);
/* 1C */
OPCODE(0x1c, o5_startSound);
OPCODE(0x1d, o5_ifClassOfIs);
OPCODE(0x1e, o5_walkActorTo);
OPCODE(0x1f, o5_isActorInBox);
/* 20 */
OPCODE(0x20, o5_stopMusic);
OPCODE(0x21, o5_putActor);
OPCODE(0x22, o5_getAnimCounter);
OPCODE(0x23, o5_getActorY);
/* 24 */
OPCODE(0x24, o5_loadRoomWithEgo);
OPCODE(0x25, o5_pickupObject);
OPCODE(0x26, o5_setVarRange);
OPCODE(0x27, o5_stringOps);
/* 28 */
OPCODE(0x28, o5_equalZero);
OPCODE(0x29, o5_setOwnerOf);
OPCODE(0x2a, o5_startScript);
OPCODE(0x2b, o5_delayVariable);
/* 2C */
OPCODE(0x2c, o5_cursorCommand);
OPCODE(0x2d, o5_putActorInRoom);
OPCODE(0x2e, o5_delay);
// OPCODE(0x2f, o5_ifNotState);
/* 30 */
OPCODE(0x30, o5_matrixOps);
OPCODE(0x31, o5_getInventoryCount);
OPCODE(0x32, o5_setCameraAt);
OPCODE(0x33, o5_roomOps);
/* 34 */
OPCODE(0x34, o5_getDist);
OPCODE(0x35, o5_findObject);
OPCODE(0x36, o5_walkActorToObject);
OPCODE(0x37, o5_startObject);
/* 38 */
OPCODE(0x38, o5_isLessEqual);
OPCODE(0x39, o5_doSentence);
OPCODE(0x3a, o5_subtract);
OPCODE(0x3b, o5_getActorScale);
/* 3C */
OPCODE(0x3c, o5_stopSound);
OPCODE(0x3d, o5_findInventory);
OPCODE(0x3e, o5_walkActorTo);
OPCODE(0x3f, o5_drawBox);
/* 40 */
OPCODE(0x40, o5_cutscene);
OPCODE(0x41, o5_putActor);
OPCODE(0x42, o5_chainScript);
OPCODE(0x43, o5_getActorX);
/* 44 */
OPCODE(0x44, o5_isLess);
// OPCODE(0x45, o5_drawObject);
OPCODE(0x46, o5_increment);
OPCODE(0x47, o5_setState);
/* 48 */
OPCODE(0x48, o5_isEqual);
OPCODE(0x49, o5_faceActor);
OPCODE(0x4a, o5_startScript);
OPCODE(0x4b, o5_getVerbEntrypoint);
/* 4C */
OPCODE(0x4c, o5_soundKludge);
OPCODE(0x4d, o5_walkActorToActor);
OPCODE(0x4e, o5_putActorAtObject);
// OPCODE(0x4f, o5_ifState);
/* 50 */
// OPCODE(0x50, o5_pickupObjectOld);
OPCODE(0x51, o5_animateActor);
OPCODE(0x52, o5_actorFollowCamera);
OPCODE(0x53, o5_actorOps);
/* 54 */
OPCODE(0x54, o5_setObjectName);
OPCODE(0x55, o5_actorFromPos);
OPCODE(0x56, o5_getActorMoving);
OPCODE(0x57, o5_or);
/* 58 */
OPCODE(0x58, o5_beginOverride);
OPCODE(0x59, o5_doSentence);
OPCODE(0x5a, o5_add);
OPCODE(0x5b, o5_divide);
/* 5C */
// OPCODE(0x5c, o5_oldRoomEffect);
OPCODE(0x5d, o5_setClass);
OPCODE(0x5e, o5_walkActorTo);
OPCODE(0x5f, o5_isActorInBox);
/* 60 */
OPCODE(0x60, o5_freezeScripts);
OPCODE(0x61, o5_putActor);
OPCODE(0x62, o5_stopScript);
OPCODE(0x63, o5_getActorFacing);
/* 64 */
OPCODE(0x64, o5_loadRoomWithEgo);
OPCODE(0x65, o5_pickupObject);
OPCODE(0x66, o5_getClosestObjActor);
OPCODE(0x67, o5_getStringWidth);
/* 68 */
OPCODE(0x68, o5_isScriptRunning);
OPCODE(0x69, o5_setOwnerOf);
OPCODE(0x6a, o5_startScript);
OPCODE(0x6b, o5_debug);
/* 6C */
OPCODE(0x6c, o5_getActorWidth);
OPCODE(0x6d, o5_putActorInRoom);
OPCODE(0x6e, o5_stopObjectScript);
// OPCODE(0x6f, o5_ifNotState);
/* 70 */
OPCODE(0x70, o5_lights);
OPCODE(0x71, o5_getActorCostume);
OPCODE(0x72, o5_loadRoom);
OPCODE(0x73, o5_roomOps);
/* 74 */
OPCODE(0x74, o5_getDist);
OPCODE(0x75, o5_findObject);
OPCODE(0x76, o5_walkActorToObject);
OPCODE(0x77, o5_startObject);
/* 78 */
OPCODE(0x78, o5_isGreater);
OPCODE(0x79, o5_doSentence);
OPCODE(0x7a, o5_verbOps);
OPCODE(0x7b, o5_getActorWalkBox);
/* 7C */
OPCODE(0x7c, o5_isSoundRunning);
OPCODE(0x7d, o5_findInventory);
OPCODE(0x7e, o5_walkActorTo);
OPCODE(0x7f, o5_drawBox);
/* 80 */
OPCODE(0x80, o5_breakHere);
OPCODE(0x81, o5_putActor);
OPCODE(0x82, o5_startMusic);
OPCODE(0x83, o5_getActorRoom);
/* 84 */
OPCODE(0x84, o5_isGreaterEqual);
OPCODE(0x85, o5_drawObject);
OPCODE(0x86, o5_getActorElevation);
OPCODE(0x87, o5_setState);
/* 88 */
OPCODE(0x88, o5_isNotEqual);
OPCODE(0x89, o5_faceActor);
OPCODE(0x8a, o5_startScript);
OPCODE(0x8b, o5_getVerbEntrypoint);
/* 8C */
OPCODE(0x8c, o5_resourceRoutines);
OPCODE(0x8d, o5_walkActorToActor);
OPCODE(0x8e, o5_putActorAtObject);
OPCODE(0x8f, o5_getObjectState);
/* 90 */
OPCODE(0x90, o5_getObjectOwner);
OPCODE(0x91, o5_animateActor);
OPCODE(0x92, o5_panCameraTo);
OPCODE(0x93, o5_actorOps);
/* 94 */
OPCODE(0x94, o5_print);
OPCODE(0x95, o5_actorFromPos);
OPCODE(0x96, o5_getRandomNr);
OPCODE(0x97, o5_and);
/* 98 */
OPCODE(0x98, o5_systemOps);
OPCODE(0x99, o5_doSentence);
OPCODE(0x9a, o5_move);
OPCODE(0x9b, o5_multiply);
/* 9C */
OPCODE(0x9c, o5_startSound);
OPCODE(0x9d, o5_ifClassOfIs);
OPCODE(0x9e, o5_walkActorTo);
OPCODE(0x9f, o5_isActorInBox);
/* A0 */
OPCODE(0xa0, o5_stopObjectCode);
OPCODE(0xa1, o5_putActor);
OPCODE(0xa2, o5_getAnimCounter);
OPCODE(0xa3, o5_getActorY);
/* A4 */
OPCODE(0xa4, o5_loadRoomWithEgo);
OPCODE(0xa5, o5_pickupObject);
OPCODE(0xa6, o5_setVarRange);
OPCODE(0xa7, o5_dummy);
/* A8 */
OPCODE(0xa8, o5_notEqualZero);
OPCODE(0xa9, o5_setOwnerOf);
OPCODE(0xaa, o5_startScript);
OPCODE(0xab, o5_saveRestoreVerbs);
/* AC */
OPCODE(0xac, o5_expression);
OPCODE(0xad, o5_putActorInRoom);
OPCODE(0xae, o5_wait);
// OPCODE(0xaf, o5_ifNotState);
/* B0 */
OPCODE(0xb0, o5_matrixOps);
OPCODE(0xb1, o5_getInventoryCount);
OPCODE(0xb2, o5_setCameraAt);
OPCODE(0xb3, o5_roomOps);
/* B4 */
OPCODE(0xb4, o5_getDist);
OPCODE(0xb5, o5_findObject);
OPCODE(0xb6, o5_walkActorToObject);
OPCODE(0xb7, o5_startObject);
/* B8 */
OPCODE(0xb8, o5_isLessEqual);
OPCODE(0xb9, o5_doSentence);
OPCODE(0xba, o5_subtract);
OPCODE(0xbb, o5_getActorScale);
/* BC */
OPCODE(0xbc, o5_stopSound);
OPCODE(0xbd, o5_findInventory);
OPCODE(0xbe, o5_walkActorTo);
OPCODE(0xbf, o5_drawBox);
/* C0 */
OPCODE(0xc0, o5_endCutscene);
OPCODE(0xc1, o5_putActor);
OPCODE(0xc2, o5_chainScript);
OPCODE(0xc3, o5_getActorX);
/* C4 */
OPCODE(0xc4, o5_isLess);
// OPCODE(0xc5, o5_drawObject);
OPCODE(0xc6, o5_decrement);
OPCODE(0xc7, o5_setState);
/* C8 */
OPCODE(0xc8, o5_isEqual);
OPCODE(0xc9, o5_faceActor);
OPCODE(0xca, o5_startScript);
OPCODE(0xcb, o5_getVerbEntrypoint);
/* CC */
OPCODE(0xcc, o5_pseudoRoom);
OPCODE(0xcd, o5_walkActorToActor);
OPCODE(0xce, o5_putActorAtObject);
// OPCODE(0xcf, o5_ifState);
/* D0 */
// OPCODE(0xd0, o5_pickupObjectOld);
OPCODE(0xd1, o5_animateActor);
OPCODE(0xd2, o5_actorFollowCamera);
OPCODE(0xd3, o5_actorOps);
/* D4 */
OPCODE(0xd4, o5_setObjectName);
OPCODE(0xd5, o5_actorFromPos);
OPCODE(0xd6, o5_getActorMoving);
OPCODE(0xd7, o5_or);
/* D8 */
OPCODE(0xd8, o5_printEgo);
OPCODE(0xd9, o5_doSentence);
OPCODE(0xda, o5_add);
OPCODE(0xdb, o5_divide);
/* DC */
// OPCODE(0xdc, o5_oldRoomEffect);
OPCODE(0xdd, o5_setClass);
OPCODE(0xde, o5_walkActorTo);
OPCODE(0xdf, o5_isActorInBox);
/* E0 */
OPCODE(0xe0, o5_freezeScripts);
OPCODE(0xe1, o5_putActor);
OPCODE(0xe2, o5_stopScript);
OPCODE(0xe3, o5_getActorFacing);
/* E4 */
OPCODE(0xe4, o5_loadRoomWithEgo);
OPCODE(0xe5, o5_pickupObject);
OPCODE(0xe6, o5_getClosestObjActor);
OPCODE(0xe7, o5_getStringWidth);
/* E8 */
OPCODE(0xe8, o5_isScriptRunning);
OPCODE(0xe9, o5_setOwnerOf);
OPCODE(0xea, o5_startScript);
OPCODE(0xeb, o5_debug);
/* EC */
OPCODE(0xec, o5_getActorWidth);
OPCODE(0xed, o5_putActorInRoom);
OPCODE(0xee, o5_stopObjectScript);
// OPCODE(0xef, o5_ifNotState);
/* F0 */
OPCODE(0xf0, o5_lights);
OPCODE(0xf1, o5_getActorCostume);
OPCODE(0xf2, o5_loadRoom);
OPCODE(0xf3, o5_roomOps);
/* F4 */
OPCODE(0xf4, o5_getDist);
OPCODE(0xf5, o5_findObject);
OPCODE(0xf6, o5_walkActorToObject);
OPCODE(0xf7, o5_startObject);
/* F8 */
OPCODE(0xf8, o5_isGreater);
OPCODE(0xf9, o5_doSentence);
OPCODE(0xfa, o5_verbOps);
OPCODE(0xfb, o5_getActorWalkBox);
/* FC */
OPCODE(0xfc, o5_isSoundRunning);
OPCODE(0xfd, o5_findInventory);
OPCODE(0xfe, o5_walkActorTo);
OPCODE(0xff, o5_drawBox);
if (_game.id == GID_MONKEY && _game.platform == Common::kPlatformSegaCD && _language == Common::EN_ANY && enhancementEnabled(kEnhMinorBugFixes)) {
OPCODE(0x1a, o5_move_segafix);
}
}
int ScummEngine_v5::getVar() {
return readVar(fetchScriptWord());
}
int ScummEngine_v5::getVarOrDirectByte(byte mask) {
if (_opcode & mask)
return getVar();
return fetchScriptByte();
}
int ScummEngine_v5::getVarOrDirectWord(byte mask) {
if (_opcode & mask)
return getVar();
return fetchScriptWordSigned();
}
void ScummEngine_v5::getResultPos() {
int a;
_resultVarNumber = fetchScriptWord();
if (_resultVarNumber & 0x2000) {
a = fetchScriptWord();
if (a & 0x2000) {
_resultVarNumber += readVar(a & ~0x2000);
} else {
_resultVarNumber += a & 0xFFF;
}
_resultVarNumber &= ~0x2000;
}
}
void ScummEngine_v5::setResult(int value) {
writeVar(_resultVarNumber, value);
}
void ScummEngine_v5::jumpRelative(bool cond) {
// We explicitly call ScummEngine::fetchScriptWord()
// to make this method work also in v0, which overloads
// fetchScriptWord to only read bytes (which is the right thing
// to do for most opcodes, but not for jump offsets).
int16 offset = ScummEngine::fetchScriptWord();
if (!cond)
_scriptPointer += offset;
}
void ScummEngine_v5::o5_actorFollowCamera() {
actorFollowCamera(getVarOrDirectByte(0x80));
}
void ScummEngine_v5::o5_actorFromPos() {
int x, y;
getResultPos();
x = getVarOrDirectWord(PARAM_1);
y = getVarOrDirectWord(PARAM_2);
setResult(getActorFromPos(x, y));
}
void ScummEngine_v5::o5_actorOps() {
static const byte convertTable[20] =
{ 1, 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20 };
// WORKAROUND bug #2233 "MI2 FM-TOWNS: Elaine's mappiece directly flies to treehouse"
// There's extra code inserted in script 45 from room 45 that caused that behaviour,
// the code below just skips the extra script code. As confirmed by Aric Wilmunder,
// "the fishing pole puzzle had been removed for the Towns because vertical scrolling
// hadn't been implemented", but it appears to work nonetheless, which is what they
// also observed when doing the QA for the PC version.
if (_game.id == GID_MONKEY2 && _game.platform == Common::kPlatformFMTowns &&
currentScriptSlotIs(45) && _currentRoom == 45 &&
(_scriptPointer - _scriptOrgPointer == 0xA9) && enhancementEnabled(kEnhRestoredContent)) {
_scriptPointer += 0xCF - 0xA1;
writeVar(32811, 0); // clear bit 43
return;
}
int act = getVarOrDirectByte(PARAM_1);
Actor *a = derefActor(act, "o5_actorOps");
int i, j;
if (workaroundMonkey1JollyRoger(_opcode, a->_number)) {
stopObjectCode();
return;
}
while ((_opcode = fetchScriptByte()) != 0xFF) {
if (_game.features & GF_SMALL_HEADER)
_opcode = (_opcode & 0xE0) | convertTable[(_opcode & 0x1F) - 1];
switch (_opcode & 0x1F) {
case 0: /* dummy case */
getVarOrDirectByte(PARAM_1);
break;
case 1: // SO_COSTUME
i = getVarOrDirectByte(PARAM_1);
// WORKAROUND: In the VGA floppy version of Monkey
// Island 1, there are two different costumes for the
// captain Smirk close-up: 0 for when the game is run
// from floppies, and 76 for when the game is run from
// hard disk, I believe.
//
// Costume 0 doesn't have any cigar smoke, perhaps to
// cut down on disk access -- or, according to Aric
// Wilmunder, possibly because it "looked too 'cartoony'
// next to the higher-fidelity close-ups."
//
// But in the VGA CD version, only costume 0 is used
// and the close-up is missing the cigar smoke.
if (_game.id == GID_MONKEY && _currentRoom == 76 && act == 12 && i == 0 && enhancementEnabled(kEnhVisualChanges)) {
i = 76;
}
a->setActorCostume(i);
break;
case 2: // SO_STEP_DIST
i = getVarOrDirectByte(PARAM_1);
j = getVarOrDirectByte(PARAM_2);
a->setActorWalkSpeed(i, j);
break;
case 3: // SO_SOUND
a->_sound[0] = getVarOrDirectByte(PARAM_1);
break;
case 4: // SO_WALK_ANIMATION
a->_walkFrame = getVarOrDirectByte(PARAM_1);
break;
case 5: // SO_TALK_ANIMATION
a->_talkStartFrame = getVarOrDirectByte(PARAM_1);
a->_talkStopFrame = getVarOrDirectByte(PARAM_2);
break;
case 6: // SO_STAND_ANIMATION
a->_standFrame = getVarOrDirectByte(PARAM_1);
break;
case 7: // SO_ANIMATION
getVarOrDirectByte(PARAM_1);
getVarOrDirectByte(PARAM_2);
getVarOrDirectByte(PARAM_3);
break;
case 8: // SO_DEFAULT
a->initActor(0);
break;
case 9: // SO_ELEVATION
a->setElevation(getVarOrDirectWord(PARAM_1));
break;
case 10: // SO_ANIMATION_DEFAULT
a->_initFrame = 1;
a->_walkFrame = 2;
a->_standFrame = 3;
a->_talkStartFrame = 4;
a->_talkStopFrame = 5;
break;
case 11: // SO_PALETTE
i = getVarOrDirectByte(PARAM_1);
j = getVarOrDirectByte(PARAM_2);
assertRange(0, i, 31, "o5_actorOps: palette slot");
// WORKAROUND: In the corridors of Castle Brunwald,
// there is a 'continuity error' with the Nazi guards
// in the FM-TOWNS version. They still have their
// palette override from the EGA version, making them
// appear in gray there, although their uniforms are
// green when you fight them or meet them again in
// the zeppelin. The PC VGA version fixed this.
if (_game.id == GID_INDY3 && _game.platform == Common::kPlatformFMTowns &&
(a->_costume == 23 || a->_costume == 28 || a->_costume == 29) &&
(_currentRoom == 20 || _currentRoom == 28 || _currentRoom == 32) && enhancementEnabled(kEnhVisualChanges)) {
break;
}
// WORKAROUND: The smoke animation is the same as
// what's used for the voodoo lady's cauldron. But
// for some reason, the colors changed between the
// VGA floppy and CD versions. So when it tries to
// remap the colors, it uses the wrong indexes. The
// CD animation uses colors 1-3, where the floppy
// version uses 2, 3, and 9.
//
// So we have to adjust which colors are remapped. We
// also need to make sure they are remapped to the
// correct colors, because not only does the GUI occupy
// some colors, apparently the FM Towns version has a
// different palette altogether. So we look up the
// closest available color to the ones we want.
//
// We could use this to get back the original smoke
// colors for other scenes as well, but we currently do
// not. The Special Edition kept the new colors too.
if (_game.id == GID_MONKEY && _currentRoom == 76 && enhancementEnabled(kEnhVisualChanges)) {
if (i == 3)
i = 1;
else if (i == 9)
i = 3;
if (j == 3)
j = findClosestPaletteColor(_currentPalette, 256, 0, 171, 171);
else if (j == 7)
j = findClosestPaletteColor(_currentPalette, 256, 171, 171, 171);
}
// WORKAROUND for original bug. The original interpreter has a color fix for CGA mode which can be seen
// in Actor::setActorCostume(). Sometimes (e. g. when Bobbin walks out of the darkened tent) the actor
// colors are changed via script without taking into account the need to repeat the color fix.
if (_game.id == GID_LOOM && _renderMode == Common::kRenderCGA && act == 1) {
if (i == 6 && j == 6)
j = 5;
else if (i == 7 && j == 7)
j = 15;
else if (i == 8 && j == 8)
j = 0;
}
// Setting palette color 0 to 0 appears to be a way to
// reset the actor palette in the TurboGrafx-16 version
// of Loom. It's used in several places, but the only
// one where I can see any visible difference is when
// leaving the darkened tent.
if (_game.id == GID_LOOM && _game.platform == Common::kPlatformPCEngine && i == 0 && j == 0) {
for (int k = 0; k < 32; k++)
a->setPalette(k, 0xFF);
} else {
a->setPalette(i, j);
}
break;
case 12: // SO_TALK_COLOR
a->_talkColor = getVarOrDirectByte(PARAM_1);
break;
case 13: // SO_ACTOR_NAME
loadPtrToResource(rtActorName, a->_number, nullptr);
break;
case 14: // SO_INIT_ANIMATION
a->_initFrame = getVarOrDirectByte(PARAM_1);
break;
case 16: // SO_ACTOR_WIDTH
a->_width = getVarOrDirectByte(PARAM_1);
break;
case 17: // SO_ACTOR_SCALE
if (_game.version == 4) {
i = j = getVarOrDirectByte(PARAM_1);
} else {
i = getVarOrDirectByte(PARAM_1);
j = getVarOrDirectByte(PARAM_2);
}
a->_boxscale = i;
a->setScale(i, j);
break;
case 18: // SO_NEVER_ZCLIP
a->_forceClip = 0;
break;
case 19: // SO_ALWAYS_ZCLIP
a->_forceClip = getVarOrDirectByte(PARAM_1);
break;
case 20: // SO_IGNORE_BOXES
case 21: // SO_FOLLOW_BOXES
a->_ignoreBoxes = !(_opcode & 1);
a->_forceClip = 0;
if (a->isInCurrentRoom())
a->putActor();
break;
case 22: // SO_ANIMATION_SPEED
a->setAnimSpeed(getVarOrDirectByte(PARAM_1));
break;
case 23: // SO_SHADOW
a->_shadowMode = getVarOrDirectByte(PARAM_1);
break;
default:
error("o5_actorOps: default case %d", _opcode & 0x1F);
}
}
workaroundLoomHetchelDoubleHead(a, act);
}
void ScummEngine_v5::o5_setClass() {
int obj = getVarOrDirectWord(PARAM_1);
int cls;
while ((_opcode = fetchScriptByte()) != 0xFF) {
cls = getVarOrDirectWord(PARAM_1);
// WORKAROUND: In the CD versions of Monkey 1 with the full 256-color
// inventory, going at Stan's messes up the color of some objects, such
// as the "striking yellow color" of the flower from the forest, the
// rubber chicken, or Guybrush's trousers. The following palette fixes
// are taken from the Ultimate Talkie Edition.
if (_game.id == GID_MONKEY && _game.platform != Common::kPlatformFMTowns &&
_game.platform != Common::kPlatformSegaCD && _roomResource == 59 &&
currentScriptSlotIs(kScriptNumENCD) &&
obj == 915 && cls == 6 && _currentPalette[251 * 3] == 0 &&
enhancementEnabled(kEnhVisualChanges) && !(_game.features & GF_ULTIMATE_TALKIE)) {
// True as long as Guybrush isn't done with the voodoo recipe on the
// Sea Monkey. The Ultimate Talkie Edition probably does this as a way
// to limit this palette override to Part One; just copy this behavior.
if (_scummVars[260] < 8) {
setPalColor(245, 68, 68, 68); // gray
setPalColor(247, 252, 244, 0); // yellow
setPalColor(249, 112, 212, 0); // lime
}
setPalColor(251, 32, 84, 0); // green
}
// WORKAROUND bug #3099: Due to a script bug, the wrong opcode is
// used to test and set the state of various objects (e.g. the inside
// door (object 465) of the of the Hostel on Mars), when opening the
// Hostel door from the outside.
if (_game.id == GID_ZAK && _game.platform == Common::kPlatformFMTowns &&
currentScriptSlotIs(205) && _currentRoom == 185 &&
(cls == 0 || cls == 1)) {
putState(obj, cls);
} else if (cls == 0) {
// Class '0' means: clean all class data
_classData[obj] = 0;
if ((_game.features & GF_SMALL_HEADER) && objIsActor(obj)) {
Actor *a = derefActor(obj, "o5_setClass");
a->_ignoreBoxes = false;
a->_forceClip = 0;
}
} else
putClass(obj, cls, (cls & 0x80) ? true : false);
}
}
void ScummEngine_v5::o5_add() {
int a;
getResultPos();
a = getVarOrDirectWord(PARAM_1);
// WORKAROUND: In the Sega CD version of MI1, there are some cases
// where conversation options are invisible. This is because where it
// thinks it's increasing Var[229] by a number of pixels, it's actually
// increasing it by a number of lines, pushing the text off-screen.
//
// We fix this by changing Var[229] += 8 to Var[229] += 1.
if (_game.id == GID_MONKEY && _game.platform == Common::kPlatformSegaCD && _language == Common::EN_ANY && _resultVarNumber == 229 && a == 8 && enhancementEnabled(kEnhSubFmtCntChanges)) {
// Room 35 - Talking to the Men of Low Moral Fiber (pirates),
// telling them that the governor has been kidnapped. Two of
// the conversation options are off-screen.
//
// Room 19 - Talking to your crew aboard the ship. The last
// conversation option is off-screen.
if ((currentScriptSlotIs(216) && _currentRoom == 35) ||
(currentScriptSlotIs(204) && _currentRoom == 19))
a = 1;
}
// WORKAROUND bug #994: This works around a script bug in LoomCD. To
// understand the reasoning behind this, compare script 210 and 218 in
// room 20. Apparently they made a mistake when converting the absolute
// delays into relative ones.
if (_game.id == GID_LOOM && _game.version == 4 && currentScriptSlotIs(210) && _currentRoom == 20 && _resultVarNumber == 0x4000) {
switch (a) {
// Fix for the Var[250] == 11 case
case 138:
a = 145;
break;
case 324:
a = 324 - 138;
break;
// Fixes for the Var[250] == 14 case
case 130:
a = 170;
break;
case 342:
a = 342 - 130 + 15; // Small extra adjustment for the "OUCH"
break;
case 384:
a -= 342;
break;
case 564:
a -= 384;
break;
default:
break;
}
}
// WORKAROUND: The clock tower is controlled by two variables: 163 and
// 247 in the floppy VGA version, 164 and 248 in the CD version. I
// don't know about the EGA version, but this fix only concerns the
// CD version.
//
// Whenever you enter the room, the first variable is cleared. It is
// then set if you examine the clock tower. The second variable
// determines which description you see, e.g. "Ten o'clock.", "Hmm.
// Still ten o'clock.", etc.
//
// If the first variable was set, the second is incremented when you
// leave the room. That means that every time you examine the clock
// tower, you get a new description (there are three of them, with a
// random variation on the last one) but only if you've been away from
// the room in between.
//
// But in the CD version, someone has attempted to "fix" this behavior
// by always incrementing the second variable when the clock tower is
// examined. So you don't have to leave the room in between, and if
// you examine the clock tower once and then leave, the second variable
// is incremented twice so you'll never see the second description.
//
// We restore the old behavior by adding 0, not 1, to the second
// variable when examining the clock tower.
if (_game.id == GID_MONKEY && currentScriptSlotIs(210) && _currentRoom == 35 && _resultVarNumber == 248 && a == 1 && enhancementEnabled(kEnhRestoredContent)) {
a = 0;
}
setResult(readVar(_resultVarNumber) + a);
}
void ScummEngine_v5::o5_and() {
int a;
getResultPos();
a = getVarOrDirectWord(PARAM_1);
setResult(readVar(_resultVarNumber) & a);
}
void ScummEngine_v5::o5_animateActor() {
int act = getVarOrDirectByte(PARAM_1);
int anim = getVarOrDirectByte(PARAM_2);
// WORKAROUND bug #1265: This script calls animateCostume(86,255) and
// animateCostume(31,255), with 86 and 31 being script numbers used as
// (way out of range) actor numbers. This seems to be yet another script
// bug which the original engine let slip by.
// For more information about why this happens, see o5_getActorRoom().
if (!isValidActor(act)) {
return;
}
// WORKAROUND bug #1339: While on Mars, going outside without your helmet
// (or missing some other part of your "space suite" will cause your
// character to complain ("I can't breathe."). Unfortunately, this is
// coupled with an animate command, making it very difficult to return to
// safety (from where you came). The following hack works around this by
// ignoring that particular turn command.
if (_game.id == GID_ZAK && _currentRoom == 182 && anim == 246 &&
((_game.version < 3 && currentScriptSlotIs(82))
|| (_game.version == 3 && currentScriptSlotIs(131)))) {
return;
}
Actor *a = derefActor(act, "o5_animateActor");
a->animateActor(anim);
}
void ScummEngine_v5::o5_breakHere() {
// WORKAROUND: The English PC Engine version of Loom shows a Turbo
// Technologies loading screen. In the Mednafen emulator it's shown for
// about 10 seconds while the game is loading resources. ScummVM does
// that in the blink of an eye.
//
// Injecting the delay into the breakHere instruction seems like the
// least intrusive way of adding the delay. The script calls it a number
// of times, but only once from room 69.
if (_game.id == GID_LOOM && _game.platform == Common::kPlatformPCEngine && _language == Common::EN_ANY && currentScriptSlotIs(44) && _currentRoom == 69) {
vm.slot[_currentScript].delay = 120;
vm.slot[_currentScript].status = ssPaused;
}
updateScriptPtr();
_currentScript = 0xFF;
}
void ScummEngine_v5::o5_chainScript() {
int vars[NUM_SCRIPT_LOCAL];
int script;
int cur;
script = getVarOrDirectByte(PARAM_1);
getWordVararg(vars);
cur = _currentScript;
assert(cur != 0xFF);
vm.slot[cur].number = 0;
vm.slot[cur].status = ssDead;
_currentScript = 0xFF;
runScript(script, vm.slot[cur].freezeResistant, vm.slot[cur].recursive, vars);
}
void ScummEngine_v5::o5_cursorCommand() {
int i, j, k;
int table[32];
memset(table, 0, sizeof(table));
switch ((_opcode = fetchScriptByte()) & 0x1F) {
case 1: // SO_CURSOR_ON
_cursor.state = 1;
verbMouseOver(0);
break;
case 2: // SO_CURSOR_OFF
_cursor.state = (_game.id == GID_MONKEY && _game.platform == Common::kPlatformMacintosh) ? 1 : 0;
verbMouseOver(0);
break;
case 3: // SO_USERPUT_ON
_userPut = 1;
break;
case 4: // SO_USERPUT_OFF
_userPut = 0;
break;
case 5: // SO_CURSOR_SOFT_ON
_cursor.state++;
verbMouseOver(0);
break;
case 6: // SO_CURSOR_SOFT_OFF
_cursor.state--;
if (_game.id == GID_MONKEY && _game.platform == Common::kPlatformMacintosh && _cursor.state == 0)
_cursor.state = 1;
verbMouseOver(0);
break;
case 7: // SO_USERPUT_SOFT_ON
_userPut++;
break;
case 8: // SO_USERPUT_SOFT_OFF
_userPut--;
break;
case 10: // SO_CURSOR_IMAGE
i = getVarOrDirectByte(PARAM_1); // Cursor number
j = getVarOrDirectByte(PARAM_2); // Charset letter to use
redefineBuiltinCursorFromChar(i, j);
break;
case 11: // SO_CURSOR_HOTSPOT
i = getVarOrDirectByte(PARAM_1);
j = getVarOrDirectByte(PARAM_2);
k = getVarOrDirectByte(PARAM_3);
redefineBuiltinCursorHotspot(i, j, k);
break;
case 12: // SO_CURSOR_SET
i = getVarOrDirectByte(PARAM_1);
if (i >= 0 && i <= 3)
_currentCursor = i;
else
error("SO_CURSOR_SET: unsupported cursor id %d", i);
break;
case 13: // SO_CHARSET_SET
initCharset(getVarOrDirectByte(PARAM_1));
break;
case 14: /* unk */
if (_game.version == 3) {
/*int a = */ getVarOrDirectByte(PARAM_1);
/*int b = */ getVarOrDirectByte(PARAM_2);
// This is some kind of "init charset" opcode. However, we don't have to do anything
// in here, as our initCharset automatically calls loadCharset for GF_SMALL_HEADER,
// games if needed.
} else {
getWordVararg(table);
// WORKAROUND bug #13735 - "Inaccurate verb rendering in Monkey 1 FM-TOWNS"
// MI1 FM-Towns has a bug in the original interpreter which removes the shadow color from the verbs.
// getWordVararg() will generate a WORD table, but then - right here - it is accessed like a DWORD
// table. This is actually fixed in the original interpreters for MI2 and INDY4. It could be argued
// if we even want that "fixed", but it does lead to bug tickets in Monkey 1 FM-TOWNS") and the
// "fix" restores the original appearance (which - as per usual - is a matter of personal taste...).
// So let people make their own choice with the Enhancement setting.
int m = (_game.platform == Common::kPlatformFMTowns && _game.id == GID_MONKEY && !enhancementEnabled(kEnhVisualChanges)) ? 2 : 1;
for (i = 0; i < 16; i++)
_charsetColorMap[i] = _charsetData[_string[1]._default.charset][i] = (unsigned char)table[i * m];
}
break;
default:
break;
}
if (_game.version >= 4) {
VAR(VAR_CURSORSTATE) = _cursor.state;
VAR(VAR_USERPUT) = _userPut;
}
}
void ScummEngine_v5::o5_cutscene() {
int args[NUM_SCRIPT_LOCAL];
getWordVararg(args);
// WORKAROUND: In Indy 3, the cutscene where Indy and his father escape
// from the zeppelin with the biplane is missing the `[1]` parameter
// which disables the verb interface. For some reason, this only causes
// a problem on the FM-TOWNS version, though... also happens under UNZ.
if (_game.id == GID_INDY3 && _game.platform == Common::kPlatformFMTowns && _currentRoom == 80 && currentScriptSlotIs(201) && args[0] == 0 && enhancementEnabled(kEnhVisualChanges)) {
args[0] = 1;
}
beginCutscene(args);
}
void ScummEngine_v5::o5_endCutscene() {
if (workaroundMonkey1StorekeeperWaitTablesLine())
return;
endCutscene();
}
void ScummEngine_v5::o5_debug() {
int a = getVarOrDirectWord(PARAM_1);
debugC(DEBUG_GENERAL, "o5_debug(%d)", a);
}
void ScummEngine_v5::o5_decrement() {
getResultPos();
setResult(readVar(_resultVarNumber) - 1);
}
void ScummEngine_v5::o5_delay() {
int delay = fetchScriptByte();
delay |= fetchScriptByte() << 8;
delay |= fetchScriptByte() << 16;
assert(_currentScript != 0xFF);
vm.slot[_currentScript].delay = delay;
vm.slot[_currentScript].status = ssPaused;
o5_breakHere();
}
void ScummEngine_v5::o5_delayVariable() {
assert(_currentScript != 0xFF);
vm.slot[_currentScript].delay = getVar();
vm.slot[_currentScript].status = ssPaused;
o5_breakHere();
}
void ScummEngine_v5::o5_divide() {
int a;
getResultPos();
a = getVarOrDirectWord(PARAM_1);
if (a == 0) {
error("Divide by zero");
setResult(0);
} else
setResult(readVar(_resultVarNumber) / a);
}
void ScummEngine_v5::o5_doSentence() {